Linux的系统调用 [英] Linux System call

查看:164
本文介绍了Linux的系统调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够得到系统的执行要求调用和它在内核的处理。
但是,一些事情还没有明确的给我。在进入SWI程序中,内核保存
用户模式堆栈寄存器。现在的问题是 -


  1. 谁的筹码是什么呢? (SWI作为处理和相应的系统调用程序需要堆栈帧时工作)


  2. 如果是内核自己的堆栈,从哪里得到的堆栈中分配..?即将开始使用当前的堆栈?
    如果是,则当前可以是可能在内核时刻正在执行的任何过程。这难道不是穷尽当前的堆栈?


  3. 如果它使用当前正在执行的用户进程在SWI处理程序堆栈,那么这将是其内核现在将访问用户地址空间。
    这可能吗?作为内核的可寻址内存为1GB范围内(如1:3内核到用户地址空间比在4GB RAM内存系统中使用)。



解决方案

大多数ARM模式有一个独立的堆栈。复位处理后的堆栈通常设立不久。从弓/ ARM /内核/ setup.c中:

  / *
 *设置为叠加重入异常处理程序
 * /
__asm​​__(
MSR cpsr_c%1 \\ n \\ t的
加SP%0%2 \\ n \\ t的
MSR cpsr_c%3 \\ n \\ t的
加SP%0%4 \\ n \\ t的
MSR cpsr_c,5%\\ n \\ t的
加SP%0%6 \\ n \\ t的
MSR cpsr_c,7%
    :
    :R(STK)
      I(PSR_F_BIT | PSR_I_BIT | IRQ_MODE)
      I(offsetof(结构栈,IRQ [0]))
      I(PSR_F_BIT | PSR_I_BIT | ABT_MODE)
      I(offsetof(结构栈,ABT [0]))
      I(PSR_F_BIT | PSR_I_BIT | UND_MODE)
      I(offsetof(结构栈,北达科[0]))
      I(PSR_F_BIT | PSR_I_BIT | SVC_MODE)
    R14);

P.S。 SVC是为了什么被称为SWI当前的名称。

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).

解决方案

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.

这篇关于Linux的系统调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆