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
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
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
A Process’s Files
A Process’s Virtual Memory
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
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