Linux System call

╄→гoц情女王★ 提交于 2019-12-07 10:39:11

问题


I am able to get the execution of system calls invocation and it's processing in Kernel. But few things are not yet clear to me. Upon entering the swi routine, the Kernel saves the User mode registers on stack. The question is-

  1. Who's stack is it? (As swi handling and the corresponding system call routine needs the stack frame to work upon)

  2. If it is Kernel's own stack, from where will get the stack allocated..? Will it start using the current's stack? If yes, then current can be any process that might be executing at that moment in kernel. Does this not exhaust current's stack?

  3. If it uses the currently executing User process's stack in swi handler, then this will be User address space which kernel will now be accessing. Is this possible? As the kernel addressable memory is within 1GB (if 1:3 Kernel-to-User address space ratio is used in a 4GB RAM memory system).


回答1:


Most ARM modes have a separate stack. The stacks are usually set up shortly after reset handler. From arch/arm/kernel/setup.c:

/*
 * setup stacks for re-entrant exception handlers
 */
__asm__ (
"msr    cpsr_c, %1\n\t"
"add    sp, %0, %2\n\t"
"msr    cpsr_c, %3\n\t"
"add    sp, %0, %4\n\t"
"msr    cpsr_c, %5\n\t"
"add    sp, %0, %6\n\t"
"msr    cpsr_c, %7"
    :
    : "r" (stk),
      "I" (PSR_F_BIT | PSR_I_BIT | IRQ_MODE),
      "I" (offsetof(struct stack, irq[0])),
      "I" (PSR_F_BIT | PSR_I_BIT | ABT_MODE),
      "I" (offsetof(struct stack, abt[0])),
      "I" (PSR_F_BIT | PSR_I_BIT | UND_MODE),
      "I" (offsetof(struct stack, und[0])),
      "I" (PSR_F_BIT | PSR_I_BIT | SVC_MODE)
    : "r14");

P.S. SVC is the current name for what was called SWI.




回答2:


It is true that the stack is specific to ARM modes.

This is the fast syscall return path. We do as little as possible here, and this includes saving r0 back into the SVC stack.

The above lines are quoted in entry-common.S. So the stack is SVC stack. (Note: swi is replaced by svc).



来源:https://stackoverflow.com/questions/11257186/linux-system-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!