Hi,
I have tried to add a system call in Fedora Linux 6. I have attached a file where the steps are written
its URL is http://nd.edu/~ablaich/system_call_implementation_a_blaich.txt
During compilation of the kernel I got the following error.
Can any body help me or suggest me any solution.
____________________________________________________________________________________________
root@localhost linux-2.6.18.2]# make all
scripts/kconfig/conf -s arch/i386/Kconfig
CHK include/linux/version.h
CHK include/linux/utsrelease.h
CHK include/linux/compile.h
dnsdomainname: Unknown host
GEN .version
CHK include/linux/compile.h
dnsdomainname: Unknown host
UPD include/linux/compile.h
CC init/version.o
LD init/built-in.o
LD .tmp_vmlinux1
arch/i386/kernel/built-in.o: In function `sys_ipc':
arch/i386/kernel/sys_i386.c:181: undefined reference to `do_shmat'
arch/i386/kernel/sys_i386.c:190: undefined reference to `do_shmat'
kernel/built-in.o: In function `copy_process':
kernel/fork.c:1093: undefined reference to `copy_semundo'
kernel/fork.c:1270: undefined reference to `exit_sem'
kernel/built-in.o: In function `do_exit':
kernel/exit.c:916: undefined reference to `exit_sem'
kernel/built-in.o:(.data+0xb08): undefined reference to `shm_ctlmax'
kernel/built-in.o:(.data+0xb34): undefined reference to `shm_ctlall'
kernel/built-in.o:(.data+0xb60): undefined reference to `shm_ctlmni'
kernel/built-in.o:(.data+0xb8c): undefined reference to `msg_ctlmax'
kernel/built-in.o:(.data+0xbb8): undefined reference to `msg_ctlmni'
kernel/built-in.o:(.data+0xbe4): undefined reference to `msg_ctlmnb'
kernel/built-in.o:(.data+0xc10): undefined reference to `sem_ctls'
make: *** [.tmp_vmlinux1] Error 1
[root@localhost linux-2.6.18.2]#
_________________________________________________________________________________________
I have tried to add a system call in Fedora Linux 6. I have attached a file where the steps are written
its URL is http://nd.edu/~ablaich/system_call_implementation_a_blaich.txt
During compilation of the kernel I got the following error.
Can any body help me or suggest me any solution.
____________________________________________________________________________________________
root@localhost linux-2.6.18.2]# make all
scripts/kconfig/conf -s arch/i386/Kconfig
CHK include/linux/version.h
CHK include/linux/utsrelease.h
CHK include/linux/compile.h
dnsdomainname: Unknown host
GEN .version
CHK include/linux/compile.h
dnsdomainname: Unknown host
UPD include/linux/compile.h
CC init/version.o
LD init/built-in.o
LD .tmp_vmlinux1
arch/i386/kernel/built-in.o: In function `sys_ipc':
arch/i386/kernel/sys_i386.c:181: undefined reference to `do_shmat'
arch/i386/kernel/sys_i386.c:190: undefined reference to `do_shmat'
kernel/built-in.o: In function `copy_process':
kernel/fork.c:1093: undefined reference to `copy_semundo'
kernel/fork.c:1270: undefined reference to `exit_sem'
kernel/built-in.o: In function `do_exit':
kernel/exit.c:916: undefined reference to `exit_sem'
kernel/built-in.o:(.data+0xb08): undefined reference to `shm_ctlmax'
kernel/built-in.o:(.data+0xb34): undefined reference to `shm_ctlall'
kernel/built-in.o:(.data+0xb60): undefined reference to `shm_ctlmni'
kernel/built-in.o:(.data+0xb8c): undefined reference to `msg_ctlmax'
kernel/built-in.o:(.data+0xbb8): undefined reference to `msg_ctlmni'
kernel/built-in.o:(.data+0xbe4): undefined reference to `msg_ctlmnb'
kernel/built-in.o:(.data+0xc10): undefined reference to `sem_ctls'
make: *** [.tmp_vmlinux1] Error 1
[root@localhost linux-2.6.18.2]#
_________________________________________________________________________________________
Send instant messages to your online friends http://uk.messenger.yahoo.com
How to add a system call in Fedora Core: This was tested on FC6 with linux kernel source: 2.6.18.2: Source material was: Implementing a System Call on Linux 2.6 for i386 by: Amit Choudhary However several modifications are needed to fully get a system call implemented and WORKING. Step 1: Full path of the file â?? /usr/src/linux/arch/i386/kernel/syscall_table.S This file contains system call names. 1. Add a line to the end of this file (Let's assume that the name of our system call is mycall). 2. Add ".long sys_mycall" at the end of the list. Step2: Full path of the file â?? /usr/src/linux/include/asmâ??i386/unistd.h This file contains the system call number that is passed to the kernel through the register (EAX) when a system call is invoked. 1. Add "#define __NR_mycall <Last_System_Call_Num + 1>" at the end of the list. If the last system call defined here is: "#define __NR_vmsplice316", then add: "#define __NR_mycall317" at the end of the list. 1. Increment the "NR_syscalls" by 1. So, if NR_syscalls is defined as: "#define NR_syscalls 317", then change it to: "#define NR_syscalls 318" Step3: Full path of the file â?? /usr/src/linux/include/linux/syscalls.h This file contain the declarations for system calls. 1. Add the following line at the end of the file: "asmlinkage long sys_mycall(int i);" Step 4 (deviation from Amit): Write your source code in one of the known folders, I chose ipc/ full path: /usr/src/linux/ipc/ 1. Create a source file named "mycall.c" mycall.c will have the code for our system call. The definition of the system call in the source file would be asmlinkage long sys_mycall(...){...} . It should include the file linux/linkage.h So, the file "mycall.c" will look like: /*â??â??â??Start of mycall.câ??â??â??â??*/ #include<linux/linkage.h> asmlinkage long sys_mycall(int i) { return i+10; } /*â??â??â??End of mycall.câ??â??â??â??â??â??*/ What is asmlinkage? Asmlinkage is used to look for the arguments on the kernel stack. Step 5 (deviation from Amit): Add the following line to the Makefile located in the folder of your source code [this is needed because when there was the seperate mycall/ directory in /usr/src/linux/mycall there were issues with the system looking for a built-in.o file after compile, due to lack of knowledge on how to fix it, by putting the source in the ipc folder for example and adding the new .o file to that exisiting makefile, the make file to make the kernel doesn't need to be modified, and everything is copastetic [checking spelling]. objâ??y := mycall.o Step 6: Compile/install kernel [check this: http://www.howtoforge.com/kernel_compilation_fedora_p2] make all make modules_install make install Step 7: Test system call works, wrote a user-space progam. NOTE: syscallX macros were "under threat" and no longer work , avoid using them, rather use the syscall() lib function syscall(syscallnumber,arguments for sys call ....) returns -1 if an error occurs Code: testmycall.c : compile: cc -g -o testmycall testmycall.c ////////////////////////////////// #include <linux/unistd.h> #include <sys/syscall.h> #include <errno.h> #include <stdio.h> int main() { int rc; rc = syscall(318,15);/*system call number, arguments ...*/ printf("RC=%d\n",rc); if(rc==-1) printf("ERROR\n"); return 0; } ////////////////////////////////// Output results: [root@ndss-str-hpnb1 test]# ./testmycall RC=25 Woo hoo, Success is sweet! [...and very time consuming]