3

I'm trying to add new (dummy) system call to linux kernel.

1) I added the system call code under linux-source/kernel/myfile.c and updated the Makefile accordingly.

2) Updated syscall.h, unistd.h and entry.S files to reflect the new system call (pedagogictime(int flag,struct timeval *time))

Then compiled the kernel and installed and rebooted the image.

When I run: cat /proc/kallsyms | grep "pedag", this is the output I'm getting

0000000000000000 T sys_pedagogictime 0000000000000000 d event_exit__pedagogictime 0000000000000000 d event_enter__pedagogictime 0000000000000000 d __syscall_meta_pedagogictime 0000000000000000 d types_pedagogictime 0000000000000000 d args__pedagogictime 0000000000000000 t trace_init_flags_enter__pedagogictime 0000000000000000 t trace_init_flags_exit__pedagogictime 0000000000000000 t __event_exit__pedagogictime 0000000000000000 t __event_enter__pedagogictime 0000000000000000 t __p_syscall_meta__pedagogictime 0000000000000000 t __initcall_trace_init_flags_exit__pedagogictimeearly 0000000000000000 t __initcall_trace_init_flags_enter__pedagogictimeearly

which means the system call is registered correctly.

In my user space program, I'm writing:

#define __NR_pedagogictime 1326 //1326 is my system call number
struct timeval *now = (struct timeval *)malloc(sizeof(struct timeval));

    long ret = syscall(__NR_pedagogictime,0,now);
    if(ret)
            perror("syscall ");

But I'm getting the error:

"syscall : Function not implemented"

I would really appreciate any help about this. Thanks.

Edit:

Btw, the assembly code for the syscall() looks like this (if it helps):

    movl    $6, %esi
    movl    $1326, %edi
    movl    $0, %eax
    call    syscall
    cltq
3
  • 1
    Why did you choose 1326 as the syscall number? Jun 28, 2012 at 4:16
  • Because the last system call in the file natty-source/arch/ia64/include/asm/unistd.h has the number 1325, so I incremented mine by one.
    – Chandan
    Jun 29, 2012 at 0:54
  • 1
    I doubt you have ia64, you are probably on x86_64 which is quite different. Jun 29, 2012 at 1:24

1 Answer 1

3

You've chosen the wrong syscall number. Take a look at how the kernel checks the syscall number limits here. For example (x86, 32bit):

496 ENTRY(system_call)
497         RING0_INT_FRAME                 # can't unwind into user space anyway
498         pushl_cfi %eax                  # save orig_eax
499         SAVE_ALL
500         GET_THREAD_INFO(%ebp)
501                                         # system call tracing in operation / emulation
502         testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
503         jnz syscall_trace_entry
504         cmpl $(nr_syscalls), %eax
505         jae syscall_badsys
506 syscall_call:
507         call *sys_call_table(,%eax,4)
508         movl %eax,PT_EAX(%esp)          # store the return value

So, you can see that this code compares %eax (syscall number) and nr_syscalls (sys_call_table size). Above or equal leads to syscall_badsys.

You'll need to modify the arch/x86/include/asm/unistd_32.h header too.

3
  • Yes, that was my thought as well. I suspect this is x86_64 though from the address lengths and the pattern of assembly used. There used to be a warning in unistd_64.h about not having gaps in the syscall table; there's a huge re-organization in linux 3.something but I expect gaps are still problematic, and 1326 seems suspiciously high. Jun 28, 2012 at 6:17
  • Okay. I got what you're saying. Since the system calls start at 1024 in that file: "natty-source/arch/ia64/include/asm/unistd.h", mine was getting the number 1326. When I changed it to 303, it started working. Thanks very much. But if I simply use the symbolic constant __NR_pedagogictime (as defined in unistd.h as 1326 and unistd_64.h as 303) in my program, it is not able to resolve the symbol. Any reason for this?
    – Chandan
    Jun 29, 2012 at 0:57
  • @ChandanApsangi, you probably are using the system's /usr/include with the constants filched from the distribution's kernel, not your doctored version. Just #define it in your code, so you don't mess up your system.
    – vonbrand
    Feb 5, 2013 at 4:32

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.