Linux内核系统调用调用以" INT 0x80的" [英] Linux Kernel systemcall call with an "int 0x80"

查看:352
本文介绍了Linux内核系统调用调用以" INT 0x80的"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习Linux内核,并在那一刻我尝试实现自己的系统调用。

I am studying the Linux kernel and at the moment I try to implement my own system call.

在内核code,它看起来如下:

In the kernel code it looks the following:

asmlinkage long sys_my_syscall()
{
     printk("My system call\n");
     return 0;
}

如果我把它与它的工作原理罚款系统调用()的功能,但我已经找到另一种方式:

If I call it with a systemcall() function it works fine, but I have found another one way:

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);
}

但是,返回值 -14 EFAULT

我在做什么错了?

设置: Linux内核3.4,ARCH x86_64的

Setup: Linux kernel 3.4, ARCH x86_64

推荐答案

对于64位系统,Linux系统调用ABI完全不同,我* 86 1除非有兼容层。
这可能会帮助:
HTTP://callums$c$c.com/blog/3

For 64-bit systems the Linux system call ABI is completely different from i*86 one unless there's a layer of compatibility. This may help: http://callumscode.com/blog/3

我还发现在eglibc系统调用源,它看起来的确不同:
<一href=\"http://www.eglibc.org/cgi-bin/viewvc.cgi/trunk/libc/sysdeps/unix/sysv/linux/x86_64/syscall.S?view=markup\" rel=\"nofollow\">http://www.eglibc.org/cgi-bin/viewvc.cgi/trunk/libc/sysdeps/unix/sysv/linux/x86_64/syscall.S?view=markup

I also found the syscall source in the eglibc, it looks different indeed: http://www.eglibc.org/cgi-bin/viewvc.cgi/trunk/libc/sysdeps/unix/sysv/linux/x86_64/syscall.S?view=markup

因此​​,它看起来像 INT $ 0x80的为x86_64的Linux内核不工作,你需要使用系统调用代替

So it looks like int $0x80 does not work for x86_64 Linux kernels, you need to use syscall instead.

这篇关于Linux内核系统调用调用以&QUOT; INT 0x80的&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆