开发者

Writing a System Calls for linux

开发者 https://www.devze.com 2022-12-10 23:01 出处:网络
i try to write a system call. I followed these steps: linux/arch/x86/kernel/syscall_table_32.S ---->. long sys mycall

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 ;
}
开发者_StackOverflow中文版

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)


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

0

精彩评论

暂无评论...
验证码 换一张
取 消