more: Jollen 的 Embedded Linux 教育訓練

« System Call 專題討論, #5:0x80 軟體中斷 | Home | LPI 發佈新的 recertification 規定:未來 LPIC 證照將不再終生有效 »

System Call 專題討論, #6:unistd.h(x86)

jollen 發表於 December 1, 2006 4:52 PM

unistd.h 是一個重要的標頭檔,裡頭是 system call 編號的定義;另外,linux/arch/i386/kernel/entry.S 則是每一個 system call 的進入點,也就是 system call table(位於 .data section)。

unistd.h也定義了處理不同參數個數的 system call handler,在這個標頭檔裡可以看到處理 0~6個參數的 handler(_syscall0~_syscall6)。例如以下是處理 1 個參數的handler:

#define _syscall1(type,name,type1,arg1) \
type name(type1 arg1) \
{ \
long __res; \
__asm__ volatile ("int $0x80" \
	: "=a" (__res) \
	: "0" (__NR_##name),"b" ((long)(arg1))); \
__syscall_return(type,__res); \
}

type, name分別為 system call的傳回值型別與函數名稱,例如呼叫 fork(),則此巨集展開後會變:

int fork(type 1 arg1)
{
…
}

 

--jollen

引用通告

如果您想引用這篇文章到您的Blog,
請複製下面的鏈接,並放置到您發表文章的相應界面中。

http://blog.jollen.org/mt-tb.cgi/253

評論 (1)

我在解決一個 module 編譯問題的 Internet research 過程中, 意外逛到你的 blog, good stuffs.

If you are not aware of this, this is for your information:

Syscall macros (along with other macros) 已經被 remove 掉了. Please see http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.20.y.git;a=commit;h=f5738ceed46782aea7663d62cb6398eb05fc4ce0

這也正好是我遇到的問題, 請問你知道 remove 的原因以及 work around for modules?

ps. my apology in advance if my response (and questions) is not the kind you would like to receive. thank you anyway. cheers.

發表一個評論

(您發表的意見將被立即接受,但需要一點時間與後端伺服器做同步,您的留言才會顯示在網站上。為避免 spam 攻撃,按「發表」後請輸入帳號密碼。使用者帳號:「nospam」、密碼:「nospam」。)

Top | 授權條款 | Jollen's Forum: Blog 評論、討論與搜尋
Copyright(c) 2006 www.jollen.org