Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad address when adding a system call

I have downloaded kernel 2.6.38-5 and want to add a system call. I did the following:

  1. I have added my system call to system call table;

    <src folder>/arc/x86/kernel/syscall_table_32.S
    
    .long sys_mycall
    
  2. I have added the system call number;

    <src folder>/include/asm-generic/unistd.h
    
    #define __NR_mycall 244
    __SYSCALL(__NR_mycall, sys_mycall)
    
  3. I have added the prototype to syscalls.h;

    <src follder>/include/linux/syscalls.h
    
    asmlinkage long sys_mycall(long input);
    
  4. And, here is my system call;

    asmlinkage long sys_mycall(long input) {
        return (input * 2);
    }
    
  5. I have edited the Makefiles too.

Now after compilation, when I use it via syscall() it gives me BAD ADDRESS with errno set to 14.

What should I do?

like image 376
Majid Azimi Avatar asked May 14 '11 16:05

Majid Azimi


1 Answers

On x86, system call number 244 is already taken by get_thread_area(), which takes as first argument a pointer to a struct user_desc:

int get_thread_area(struct user_desc *u_info);

You are passing a number instead of a pointer, the kernel is trying to interpret it as a pointer, it's determining that it points outside of your process, and returning -EFAULT.

like image 111
ninjalj Avatar answered Oct 06 '22 18:10

ninjalj