13
Process Execution Rex Chen OS Lab ,NCTU

Process Execution Rex Chen OS Lab ,NCTU

  • Upload
    kioshi

  • View
    26

  • Download
    0

Embed Size (px)

DESCRIPTION

Process Execution Rex Chen OS Lab ,NCTU. execve(). do_execve() struct binprm is used to store all the data about the file prepare_binprm(). suid sgid sticky. owner group other. type(4 bits). u. g. s. r. w. x. r. w. x. r. w. x. Bits-fileds of i_mode. - PowerPoint PPT Presentation

Citation preview

Page 1: Process   Execution Rex Chen  OS Lab ,NCTU

Process Execution

Rex Chen OS Lab ,NCTU

Page 2: Process   Execution Rex Chen  OS Lab ,NCTU

execve()

• do_execve()

• struct binprm is used to store all the data about the file

• prepare_binprm()

w x r w x r w xg s rutype(4 bits)

Bits-fileds of i_mode

suid sgid stickyowner group other

Page 3: Process   Execution Rex Chen  OS Lab ,NCTU

Bits-fileds of i_mode

• type: file type, may be IFREG(regular file), IFDIR(directory), IFBLK(block device), IFCHR(character device)

• suid and sgid flags apply to executable file when a user execute the file, if the suid is set, the kernel sets the user’s effective UID to that the owner of the file.

Page 4: Process   Execution Rex Chen  OS Lab ,NCTU

do_execve()

• read_exec() : read the first 128 bytes

• copy_string()

• search_binary_handler()

Page 5: Process   Execution Rex Chen  OS Lab ,NCTU

Setup binary format

• binfmt_setup()

• register_binfmt()

• unregister_binfmt()

Page 6: Process   Execution Rex Chen  OS Lab ,NCTU

Binary format

Registered Binary Formats

Page 7: Process   Execution Rex Chen  OS Lab ,NCTU

binfmt_aout.c

• demand loading

• do_laod_aout_binary()

• flush_old_exec() : release the process’s memory, which still contains the old program

• do_mmap(): virtual areas for a process can be set up using this function

Page 8: Process   Execution Rex Chen  OS Lab ,NCTU

binfmt_aout.c

• struct exec

• {

• unsigned long a_info; /* Use macros N_MAGIC, etc for access */

• unsigned a_text; /* length of text, in bytes */

• unsigned a_data; /* length of data, in bytes */

• unsigned a_bss; /* length of uninitialized data area for file, in bytes */

• unsigned a_syms; /* length of symbol table data in file, in bytes */

• unsigned a_entry; /* start address */

• unsigned a_trsize; /* length of relocation info for text, in bytes */

• unsigned a_drsize; /* length of relocation info for data, in bytes */

• };

Page 9: Process   Execution Rex Chen  OS Lab ,NCTU

binfmt_aout.c

• /* Code indicating object file or impure executable. */

• #define OMAGIC 0407

• /* Code indicating pure executable. */

• #define NMAGIC 0410

• /* Code indicating demand-paged executable. */

• #define ZMAGIC 0413

• /* This indicates a demand-paged executable with the header in the text.

• The first page is unmapped to help trap NULL pointer references */

• #define QMAGIC 0314

• /* Code indicating core file. */

• #define CMAGIC 0421

Page 10: Process   Execution Rex Chen  OS Lab ,NCTU

A Process’s Files

Page 11: Process   Execution Rex Chen  OS Lab ,NCTU

A Process’s Virtual Memory

Page 12: Process   Execution Rex Chen  OS Lab ,NCTU

Pages move into main memory

Executale file

mainmemory

text and

Initialized data

uninitialized data pages zero-filled on first access

stack and heap pages

allocation on first access

Page 13: Process   Execution Rex Chen  OS Lab ,NCTU

Process address spaceper-process kernel stack

env stringsargv strings

user stack

uninitialized data(bss)

data

code(text)

0

initialized data

symbol table

code(text)

a.out header

a.out magic number

process memory-resident image

env_start

arg_startstart_stack

brk

end_data

end_code

start_codeexecutable-filedisk image