日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

转载 linux内核 asmlinkage宏

發(fā)布時間:2024/9/20 linux 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 转载 linux内核 asmlinkage宏 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

轉(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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。