linux内核栈传递和寄存器传递,Linux系统调用的参数传递方式

先引用一段:

“仔细看一下有asmlinkage的地方通常是系统调用的函数,因为在系统调用中,寄存器从用户空间传过来后SAVE_ALL压入堆栈,接着调用相应的系统调用函数,这样系统调用函数一定要保证是通过堆栈传递参数的

转贴一段:

The asmlinkage tag is one other thing that we should observe about this simple function. This is a #define for some gcc magic that tells the compiler that the function should not expect to find any of its arguments in registers (a common optimization), but only on the CPU's stack. Recall our earlier assertion that system_call consumes its first argument, the system call number, and allows up to four more arguments that are passed along to the real system call. system_call achieves this feat simply by leaving its other arguments (which were passed to it in registers) on the stack. All system calls are marked with the asmlinkage tag, so they all look to the stack for arguments. Of course, in sys_ni_syscall's case, this doesn't make any difference, because sys_ni_syscall doesn't take any arguments, but it's an issue for most other system calls. And, because you'll be seeing asmlinkage in front of many other functions, I thought you should know what it was about.”

我的问题是,系统调用的参数传递方式是不是把参数(不一定满4个)放进寄存器里,然后把对应的寄存器压栈,INT X,实际上又把X压栈,下陷后CPU取出了X后找到了对应服务程序,那个服务程序才取出栈中的参数?

也就是说是把参数放到寄存器里,再放到栈中来传递的?

是的话它是把四个寄存器一下全压栈还是按需要压栈?

为什么不直接放到栈中?为什么必须经过寄存器?为什么不能分批把参数放进一个寄存器一次一次压栈?

|

系统调用是在内核中执行的,参数只能压入内核栈

在进入内核之前压栈只是压入用户态栈,所以需要寄存器传递

int x是用户态和内核态的分界线

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值