views:

245

answers:

1

i try to write a system call. I followed these steps:

linux/arch/x86/kernel/syscall_table_32.S ----> . long sys mycall

linux/include/linux/syscalls.h --------> asmlinkage int sys mycall (int i , int j );

linux/arch/x86/include/asm/unistd_32.h ----> #define NR mycall 333

I changed linux/Makefile to core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ mycall/

I created a directory, called mycall. ---->linux/mycall

Inside of that file, I placed mycall.c :

#include <linux/kernel.h>
asmlinkageintsysmcall(int i,int j )
{
return i + j ;
}

6)i create Makefile. ---> linux/mycall/Makefile.

obj−y := mycall.o

Then whrn i try this system call, it returns always -1. These lines are my test code in Desktop. testmycall.c

#include <stdio.h>
#include <sys/syscall.h>
#define __NR_mycall 333

int main(void)
{
int x1=10, x2=20, y ;
y = syscall (__NR_mycall, x1, x2 );
printf (”%d\n”,y );
return 0 ;
}

Then i recompile the kernel. If i compile the code, there is nothing wrong. when i run this program then it doesn't sum two values. It just returns always -1. What is wrong with my system call? (when i recompile the kernel, system didn't waste time more than 3 seconds. I think here, there could be a problem)

+2  A: 

Recompile the kernel and reboot. Or is it a kernel module?

Kelly French
IMO, a kernel module shouldn't /really/ be used to add system call functionality; too much bad voodoo can happen. (Plus they're a bugger to debug if something goes wrong!)
George Shore
I am just writing a system call. Do i need to recompile the kernel?
Iguramu
After recompile the system, do i have to install? (sudo dpkg -i linux-image-2.6.28.10-custom ....deb)
Iguramu
You usually copy the compiled kernel to a directory and then use a boot manager to let you select the newly built kernel. Once the kernel is up and you are logged it, you can then run your test program. No reinstall necessary.
Kelly French
I tried as you commented. But it doesn't work. I just wrote "make -kpkg clean" after 2 seconds it finished. Then "fakeroot make-kpkg -initrd -append-to-version=-custom kernel_image kernel_headers" this line worked maybe 10 seconds. I think, i have to wait more than 10 minutes. It seems there is a problem. Can you suggest me something?
Iguramu
See if this thread helps: http://stackoverflow.com/questions/1688844/compiling-my-own-kernel-not-from-linux-kernel-source
Kelly French