1 for the pg_dir and some for pg_tables
ss0 set to kernel stack segment (0x10) to be sure?
esp0 set to top of the newly allocated kernel_stack_page
cr3 set by copy_page_tables() to point to newly
allocated page directory.
ldt = _LDT(task_nr) creates new ldt descriptor.
descriptors set in gdt for new tss and ldt.
The remaining registers are inherited from parent.
The processes end up sharing their code and data segments (although
they have separate local desctriptor tables, the entries point
to the same segments). The stack and data pages will be copied when
the parent or child writes to them (copy-on-write).
Memory-related work done by exec():
1 page for exec header entire file for omagic
1 page or more for stack (MAX_ARG_PAGES)
clear_page_tables() used to remove old pages.
change_ldt() sets the descriptors in the new LDT
ldt = code base=0x00, limit=TASK_SIZE
ldt = data base=0x00, limit=TASK_SIZE
These segments are DPL=3, P=1, S=1, G=1. type=a (code) or 2 (data)
Up to MAX_ARG_PAGES dirty pages of argv and envp are
allocated and stashed at the top of the data segment for the newly
created user stack.
Set the instruction pointer of the caller eip = ex.a_entry
Set the stack pointer of the caller to the stack just created
(esp = stack pointer)
These will be popped off the stack when the caller resumes.
Interrupts and traps are handled within the context of the current task.
In particular, the page directory of the current process is used in
address translation. The segments, however, are kernel segments so that all
linear addresses point into kernel memory. For example, assume a user
process invokes a system call and the kernel wants to access a
variable at address 0x01. The linear address is 0xc0000001 (using
kernel segments) and the physical address is 0x01. The later is
because the process' page directory maps this range exactly as
The kernel space (0xc0000000 + high_memory) is mapped by the
kernel page tables which are themselves part of the RESERVED memory.
They are therefore shared by all processes. During a fork
copy_page_tables() treats RESERVED page tables differently. It sets
pointers in the process page directories to point to kernel page
tables and does not actually allocate new page tables as it does
normally. As an example the kernel_stack_page (which sits
somewhere in the kernel space) does not need an associated
page_table allocated in the process' pg_dir to map it.
The interrupt instruction sets the stack pointer and stack segment from
the privilege 0 values saved in the tss of the current task.
Note that the kernel stack is a really fragmented object -- it's not
a single object, but rather a bunch of stack frames each allocated when a
process is created, and released when it exits. The kernel stack should
never grow so rapidly within a process context that it extends below the