作者andytzeng (Ya-Shiuan)
看板LinuxDev
标题Re: [问题] 请问关於System Call的问题
时间Sat Jan 13 12:54:40 2007
※ 引述《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