Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 'errno 38: function not implemented' while making a system call

I'm trying to write a system call in Linux. I modified the unistd.h, syscall_32.tbl and sys.c as follows respectively:

/*
#define __NR3264_fadvise64 223
__SC_COMP(__NR3264_fadvise64, sys_fadvise64_64, compat_sys_fadvise64_64)
*/
#define __NR_zslhello 223
__SYSCALL(__NR_zslhello, sys_zslhello)

223 i386 zslhello sys_zslhello

asmlinkage int sys_zslhello(int ret)
{
    printk("Hello, my syscall!\n");
    return ret;
}

After compiling the kernel, I use syscall(223, 10000);, the return value is -1, and the errno is 38, i.e., the function is not implemented. Do you have any ideas about this?

like image 900
zijuexiansheng Avatar asked May 07 '14 11:05

zijuexiansheng


1 Answers

This is because the syscall was not implemented as the name suggests. Probably in your case your machine is a 64-bit one. So you have to change the file syscall_64.tbl not syscall_32.tbl.

In the last line of the file where the common syscalls are defined add a line

x common zslhello sys_zslhello

Where x is 1 plus the last value in common area. This is how a snippet of my syscall_64.tbl looks like.

330 common  pkey_alloc      sys_pkey_alloc
331 common  pkey_free       sys_pkey_free

#
# x32-specific system call numbers start at 512 to avoid cache impact
# for native 64-bit operation.
#
512 x32 rt_sigaction        compat_sys_rt_sigaction
513 x32 rt_sigreturn        sys32_x32_rt_sigreturn

In my case x is 332. Cheers!

like image 81
Ilaya Raja S Avatar answered Nov 07 '22 22:11

Ilaya Raja S