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)
{
…
}
Tags: