什么是“asmlinkage修饰符意味着? [英] What is the 'asmlinkage' modifier meant for?

查看:117
本文介绍了什么是“asmlinkage修饰符意味着?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读,它是用于实现在Linux系统调用的功能。
例如:

I have read that it is used for functions that implement system calls in Linux. For example:

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

和它告诉编译器在栈上传递的所有函数参数。但是,这不是已经是这样了?函数的参数一般只将它们推堆栈传递。抑或是我们指的是通过寄存器传递函数参数在这里?

and that it tells the compiler to pass all function arguments on the stack. But isn't that already the case? Function arguments are generally passed by pushing them on stack only. Or is it that we are referring to passing function arguments through registers here?

推荐答案

有一个 FAQ

该asmlinkage标签是我们应该遵守有关的另一件事
  这个简单的功能。这是一些神奇的海湾合作​​委员会,告诉使用#define
  该函数不应该期望发现任何编译器的
  寄存器参数(一个常见的​​优化),但仅在CPU的
  堆叠。回想一下我们前面的说法,即system_call的消耗其
  第一个参数,系统调用号,并允许最多四个多
  被一起真正的系统调用传递的参数。 system_call的
  实现这一壮举仅仅通过其留下其他参数(这是
  传递给它在寄存器)栈上。所有的系统调用都标
  与asmlinkage标签,所以他们都看向了堆栈参数。
  当然,在 sys_ni_syscall 的情况下,这并没有什么差别,
  因为 sys_ni_syscall 不带任何参数,但它是一个问题
  对于大多数其他系统调用。而且,因为你将看到 asmlinkage
  在许多其他功能方面,我想你应该知道这是什么
  是怎么回事。

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.

这篇关于什么是“asmlinkage修饰符意味着?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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