Ale*_*lex 3 c linux assembly system-calls linux-kernel
我正在研究Linux内核,目前我尝试实现自己的系统调用.
在内核代码中,它看起来如下:
asmlinkage long sys_my_syscall()
{
printk("My system call\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我用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);
}
Run Code Online (Sandbox Code Playgroud)
但它返回了价值-14 EFAULT.
我究竟做错了什么?
设置: Linux内核3.4,ARCH x86_64
对于64位系统,Linux系统调用ABI与i*86完全不同,除非有一层兼容性.这可能会有所帮助:http: //callumscode.com/blog/3
我还在eglibc中找到了syscall源代码,它看起来确实不同:http://www.eglibc.org/cgi-bin/viewvc.cgi/trunk/libc/sysdeps/unix/sysv/linux/x86_64/syscall.S ?视图=标记
所以它似乎int $0x80不适用于x86_64 Linux内核,你需要使用它syscall.
| 归档时间: |
|
| 查看次数: |
1559 次 |
| 最近记录: |