InstructionsToAddSystemCallToLinux Rev00
InstructionsToAddSystemCallToLinux Rev00
x Linux Kernel
By Corban Rivera, 3204 GTA
Prerequisites
• You must have root access (CS lab machines are not available ).
1. Download the latest version of the 2.6 Linux kernel from www.kernel.org.
2. Unzip and untar the kernel directory into /usr/src/.
3. In /usr/src/Linux-x.x.x/kernel/, Create a new file myservice.c to define your
system call.
.long sys_myservice
9. Add a new boot image to Lilo, by editing /etc/lilo.conf. Your lilo configuration
will vary slightly. After saving, run lilo –v to install your settings. Don’t just
modify an existing lilo entry; you may need it if your new kernel has bugs.
image=/usr/src/Linux-x.x.x/arch/i386/boot/bzImage
label=”Linux-test”
root=/dev/hda5
read-only
10. Making a user test file. You also need to copy your edited unistd.h from
/usr/src/Linux- x.x.x/include/asm/ to /usr/include/kernel/ because it contains your
system call’s index.
#include <Linux/errno.h>
#include<sys/syscall.h>
#include <Linux/unistd.h>
long errno; //this is the return code from the system call
//this is a macro defined in unistd.h to help prototype sys calls
_syscall2(int, myservice, int, arg1, char*, arg2);
main() {
myservice(1, "hi");
}
11. Reboot into your new kernel and compile your user test program to try out
your system call. You will know if it worked if you see a kernel message in
/var/log/kernel/warnings announcing that your service is running.