gpt4 book ai didi

c - 'asmlinkage' 修饰符是什么意思?

转载 作者:太空狗 更新时间:2023-10-29 16:21:09 26 4
gpt4 key购买 nike

我读到它用于在 Linux 中实现系统调用的函数。例如:

asmlinkage long sys_getjiffies( void )
{
return (long)get_jiffies_64();
}

并且它告诉编译器将所有函数参数传递到堆栈上。但这不已经是这样了吗?函数参数通常通过仅将它们压入堆栈来传递。还是我们在这里指的是通过寄存器传递函数参数?

最佳答案

有一个 FAQ :

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.

It is also used to allow calling a function from assembly files.

关于c - 'asmlinkage' 修饰符是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10459688/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com