【发布时间】:2012-10-09 09:05:43
【问题描述】:
我正在研究 Linux 内核,目前我正在尝试实现自己的系统调用。
在内核代码中如下所示:
asmlinkage long sys_my_syscall()
{
printk("My system call\n");
return 0;
}
如果我用 systemcall() 函数调用它,它可以正常工作,但我找到了另一种方法:
int my_syscall(void)
{
long __res;
__asm__ volatile (
"movl $312, %%eax;"
"int $0x80;"
"movl %%eax, %0;"
: "=m" (__res)
:
: "%eax"
);
if ((unsigned long) (__res) >= (unsigned long) (-125)) {
errno = -(__res);
__res = -1;
}
return (int)(__res);
}
但它返回值-14EFAULT。
我做错了什么?
设置: Linux 内核 3.4,ARCH x86_64
【问题讨论】:
-
我建议在 glibc 源代码中查找
systemcall()源代码 - 它可能会显示出差异。 -
你的系统是 64 位的吗?如果是这样,也许您需要使用 %rax 寄存器?您的 sn-p 是 32 位汇编语言。
-
见stackoverflow.com/questions/3730064/…,对于64位应用程序你不能使用
int 0x80
标签: c linux assembly linux-kernel system-calls