130 likes | 219 Views
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.
E N D
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
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.
do_execve() • read_exec() : read the first 128 bytes • copy_string() • search_binary_handler()
Setup binary format • binfmt_setup() • register_binfmt() • unregister_binfmt()
Binary format Registered Binary Formats
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
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 */ • };
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
Pages move into main memory uninitialized data pages zero-filled on first access main memory text and Executale file Initialized data stack and heap pages allocation on first access
Process address space per-process kernel stack env strings env_start process memory- resident image argv strings arg_start user stack start_stack brk uninitialized data(bss) symbol table end_data data initialized data end_code executable-file disk image code(text) code(text) start_code a.out header 0 a.out magic number