Linux系统调用宏展开笔记
不知道从哪个版本的内核开始,系统调用变成宏了。在2.6.38的内核里面追踪了一下,以SYSCALL_DEFINE1为例:
SYSCALL_DEFINE1(name,...)展开sys_name,后面的数字,若为1则是一个参数,若为2则为2个参数
具体的宏,展开跟踪流程如下:
#define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
|
v
#define SYSCALL_DEFINEx(x, sname, ...) \
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
|
v
#define __SYSCALL_DEFINEx(x, name, ...) \
asmlinkage long sys##name(__SC_DECL##x(__VA_ARGS__))
\
\
#define __SC_DECL1(t1, a1) t1 a1
拿一个例子来对照一下:
SYSCALL_DEFINE1(brk, unsigned long, brk)
|
v
SYSCALL_DEFINE1(1, _brk, unsigned long, brk)
|
v
__SYSCALL_DEFINE1(1, _brk, unsigned long ,brk)
|
v
asmlinkage long sys_brk(unsigned long brk)
SYSCALL_DEFINE1(brk, unsigned long, brk)---> long sys_brk(unsigned long brk)
{
unsigned long rlim, retval;
unsigned long newbrk, oldbrk;
struct mm_struct *mm = current->mm;
unsigned long min_brk;
......
retval = mm->brk;
up_write(&mm->mmap_sem);
return retval;
}
评论
发表评论