转载 linux内核 asmlinkage宏
轉載http://blog.chinaunix.net/uid-7390305-id-2057287.html
?
看一下/usr/include/asm/linkage.h里面的定義:
#define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
其中 __attribute__是關鍵字,是gcc的C語言擴展。
__attribute__機制是GNU C的一大特色,它可以設置函數屬性、變量屬性和類型屬性等。可以通過它們向編譯器提供更多數據,幫助編譯器執行優化等。
__attribute__((regparm(0))):告訴gcc編譯器該函數不需要通過任何寄存器來傳遞參數,參數只是通過堆棧來傳遞。
__attribute__((regparm(3))):告訴gcc編譯器這個函數可以通過寄存器傳遞多達3個的參數,這3個寄存器依次為EAX、EDX 和 ECX。更多的參數才通過堆棧傳遞。這樣可以減少一些入棧出棧操作,因此調用比較快。
asmlinkage大都用在系統調用中。有一些情況下是需要明確的告訴編譯器,我們是使用stack來傳遞參數的,比如X86中的系統調用,是先將參數壓入stack以后調用sys_*函數的,所以所有的sys_*函數都有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.
linux內核 asmlinkage宏
轉載于:https://www.cnblogs.com/pingandezhufu/p/4368598.html
總結
以上是生活随笔為你收集整理的转载 linux内核 asmlinkage宏的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何用cocoapods 来管理项目中的
- 下一篇: Hyper-V下的Linux虚拟机网卡丢