本文共 935 字,大约阅读时间需要 3 分钟。
转自:http://crquan.blogbus.com/logs/5618102.html
syscall调用接口从2.6.19开始移到应用层,原来内核中使用_syscallN宏的方式来声明函数原型的方法不再有效:
如声明:
_syscall1(int, sysinfo, struct sysinfo *, info);
不再需要,而是在程序中需要的时候直接调用:
int syscall(int number, ...);
- 第一个number是后面要接的参数个数,不是该系统调用的参数个数;(注:关于这个number,man手册上说的是: syscall() performs the system call whose assembly language interface has the specified number with the specified arguments. Symbolic constants for system calls can be found in the header file <sys/syscall.h>.)
- number后面顺序接上该系统调用的所有参数即可
相应头文件包含也改变为
于是调用sysinfo就变为:
struct sysinfo s_info; syscall(2, __NR_sysinfo, &s_info);
可见新的调用方式变得更为简洁了。
References:
- http://lxr.linux.no/source/include/asm-i386/unistd.h
- http://lxr.linux.no/source/include/asm-i386/unistd.h?v=2.6.18
- http://www.kernel.org/pub/linux/kernel/v2.6/snapshots/patch-2.6.19-git13.log
- commit f5738ceed46782aea7663d62cb6398eb05fc4ce0 of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
转载地址:http://mbemb.baihongyu.com/