Linux系统调用 [英] Linux System call

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

问题描述

我能够执行系统调用调用并在内核中进行处理.但我还不清楚一些事情.进入 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. 是谁的筹码?(因为 swi 处理和相应的系统调用例程需要堆栈帧来处理)

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

如果是Kernel自己的栈,从哪里得到栈分配..?它会开始使用当前的堆栈吗?如果是,那么 current 可以是当时内核中可能正在执行的任何进程.这不会耗尽当前的堆栈吗?

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?

如果它在 swi 处理程序中使用当前正在执行的用户进程的堆栈,那么这将是内核现在将访问的用户地址空间.这可能吗?由于内核可寻址内存在 1GB 以内(如果在 4GB RAM 内存系统中使用 1: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).

推荐答案

大多数 ARM 模式都有单独的堆栈.堆栈通常在重置处理程序后不久设置.来自 arch/arm/kernel/setup.c:

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");

附言SVC 是所谓的 SWI 的当前名称.

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

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

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