ARM64 kernel stack, user stack, register context

1. kernel stack allocation, i.e. thread_info allocation is assigned (the default is 2 pages) in do_fork-> dup_task_struct in, and assigned to task_struct-> stack;

2. The user stack allocation of two ways: First, pthread create good will advance mmap assign user stack, passed do_fork-> copy_thread, user stack starting address will be assigned to pt_regs-> sp; the second is when the fork, borrowed from parent thread stack process, if ret_from_user after calling the exec-> do_execuveat_common-> exe_binprm-> search_binary_handler-> load_elf_binary-> set_arg_pages, reassign user stack, then call start_thread configuration pt_regs;

3. The registers in the kernel mode (SVC mode) context storage location: thread members task_struct of type struct thread_struct;

4. register the user mode (non-exception mode) context storage position: bottom of the kernel stack. Can thus acquired (task_pt_regs (task_struck)): stack member struct task_struct point struct thread_info, thread_info is the start address of the kernel stack, thread_info + kernel stack of fixed size (2 page), that is, the end address struct pt_regs, pt_regs i.e. a position register for storing the user mode context;

5. thread_info members directed task task_struct structure;

In summary, as long as the task_struct know, you can know the start address of the kernel stack (i.e. thread_info = task_struct-> stack), but also know the context of the kernel mode register (i.e. task_struct-> thread-> context); at the same time, also know a user mode context register (i.e. task_struct-> stack + kthread_stack_size-sizeof (pt_regs)), so that the user know the current address of the stack (i.e. pt_regs-> sp)

 

Guess you like

Origin www.cnblogs.com/zengjianrong/p/11974351.html