6.5 linux

来源:互联网 发布:易语言自动刷图源码 编辑:程序博客网 时间:2024/06/04 19:52

Process descriptors handling

process in Kernel Mode access a stack contained in the Kernel data segement.

Kernel control paths make little us  of the stack , only a few thousand bytes of kernel stack are required.

when stack and thread_info are contained in a single page frame ---->the kernel uses a few additional stacks to avoid the overflows caused by deeply nested interrupts and exception.

two data structure are stored in the 2-page (8KB) memory area.

The thread_info resides at the beginning of the memory area. 

The stack grows downward from the end.

The esp register is the CPU stack pointer, which is used to address the stack's top location.

when it was switching from user mode to kernel mode, the kernel stack of a process is always empty.esp register points to the byte immediately followitng the stack.The value of the esp is decreased as soon as date is written into the stack.

The thread_info structure is stored starting at address 0x15fa000 and the stack is stored starting at address 0x15fc000.

the kernel uses the  alloc_thread_info and free_thread_info macros to allocate and release the memory area stroing a thread_info and a kernel stack.

Identifying the current process

If the thread_union structure is 8KB 2^13 bytes long, the kernel masks out the 13 least significant bits of esp to obtain the base address of the thread_info 

if the thread_info structure 4KB long, the kernel masks out he 12 least significant bits of esp .

(his is one by the current _thread_info)

after executing,p contains the thread_info structure pointer of the process running on the CPU that execute the instruction. 

the kernel makes use of the current macro, which is essentially equivalent to current_thread_info()->task.

after executing , pcontains the process descriptor pointer of the process running on the CPU.

the current macro often appears in kernel code as a prefix to fields of the process descriptor.e.g. current->pid returns the process ID of the process currently running.

Doubly linked list 

a set of primitive operations must be implemented: initializing the list, inserting ,deleting,scannning the list and son on.

list_head data structure whose only fields next and prev represent the forward and back pointer of a generic doubly linked list element.

the pointers in a lis_head field  store the addresses of other list_head fields rather than the addresses of the whole data structures in which the list _head fields structure is included.

list_add(n,p)

list_add_tail(n,p)

list_del(p)

list_empty(p)

list_entry(p,t,m)

list_for_each(p,h)

list_for_each_entry(p,h,m)

0 0
原创粉丝点击