看板 LinuxDev 關於我們 聯絡資訊
※ 引述《roylee17 (把我id還我阿......)》之銘言: : 嗯嗯,我試了也一樣... : asm/unistd.h 裡的 _syscallN macro 現在已經被 #ifdef __KERNEL__ 包住了 : 所以一般的 user program 是看不到的 : 用 syscall 試試吧 : #include <linux/unistd.h> : - #include <errno.h> : - extern int errno; : - #define __NR_mysyscall 253 // 如果有寫在 unistd.h 就不用了 : - static inline _syscall1(int, mysyscall, int, n); : + #include <sys/syscall.h> : + int mysyscall( int n){ : + return syscall( __NR_mysyscall, n); : + } : int main() : { : mysyscall(0); : return 0; : } _syscallx 的用法,在之前的確是將 syscall 包成 macro 的用法,好處 是可以將 syscall function 的 prototype 由 _syscallx series macro 轉換以一個 user defined function 包起來.. 比方說 static inline _syscall1(int, mysyscall, int, n); 就會變成 static inline int mysyscall(int n) { return syscall(__NR_mysyscall, n); }; 可以讓 compiler 檢查 call mysyscall 的 prototype 是否正確 但現在部分的 linux distribution (如 FC6) 已經正式讓 _syscallx 進入歷史 以後不再提供了,所以就得乖乖的用 syscall 來呼叫 system call -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.135.188.188