I am studying the Linux kernel and at the moment I try to implement my own system call.
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);
}
But it returns the value -14
EFAULT
.
What am I doing wrong?
Setup: Linux kernel 3.4, ARCH x86_64
systemcall()
source in glibc source code - it may show the difference. – Dmytro Sirenkoint 0x80
– nos