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