Download the linux kernel 2.6.x from http://www.kernel.org
. In /usr/src/Linux-2.6.35.5/, Create a NewFolder and your new file that would contain your new system call lets say “myservice.c”.
Define your system call.
sample file myservice.c
#include <linux/linkage.h> //for linking a system call
#include <linux/kernel.h> //for the printk
asmlinkage long sys_myservice (int arg1, char* arg2) {
printk(KERN_EMERG “My Service is Running”);
//kernel messages logged to /var/log/kernel/warnings
return(1);
}
//What is asmlinkage?
//Asmlinkage is used to look for the arguments on the kernel stack.
In /usr/src/linux-2.6.35.5/arch/x86/include/asm/unistd_32.h, define an index for your system call.
Your index should be the number after the last system call defined in the list.
#define __NR_myservice 338
5. Also, you should increment the system call count.
#define NR_syscalls 339
6. /usr/src/linux-2.6.35.5/arch/x86/kernel/syscall_table.S, you should define a pointer to
hold a reference to your system call routine. It is important that your data entry
placement corresponds to the index you assigned to your system call.
.long sys_myservice
7. Create a Makefile in a NewFolder (folder you created in step 3) Add your system call to the Makefile by adding the line below.
#####Makefile Start#####
obj-y += myservice.o
#####Makefile End#######
8.
In /usr/src/linux-2.6.35.5/include/linux/syscalls.h
This file contain the declarations for system calls.
Add the following line at the end of the file:
asmlinkage long sys_myservice (int arg1, char* arg2);
9. Add directory path of the NewFolder to the Makefile (/usr/src/Linux-2.6.35.5/Makefile)
Add your call to core-y (Search for regex: core-y.*+=). This directory will contain the source file, header file and the Makefile for our system call.
core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ NewFolder
10.
For testing our new system call you will need to recompile Kernel.
Compilation Steps
a. Enter
/usr/src/linux-2.6.35.5/make menuconfig
exit and save changes
b. Start compiling to create a compressed kernel image, enter:
$ make
c. Start compiling to kernel modules, enter:
$ make modules
d. Install kernel modules
$ make modules_install
e. Install kernel
So far we have compiled kernel and installed kernel modules. It is time to install kernel itself.
# make install
f.
Create an initrd image
Type the following command at a shell prompt:
# cd /boot
# mkinitram fs-o initrd.img-2.6.35.5
g.
# update-grub
h.
Reboot computer and boot into your new kernel
Just issue reboot command:
# reboot
11.
Create a C program and check your system call
. In /usr/src/Linux-2.6.35.5/, Create a NewFolder and your new file that would contain your new system call lets say “myservice.c”.
Define your system call.
sample file myservice.c
#include <linux/linkage.h> //for linking a system call
#include <linux/kernel.h> //for the printk
asmlinkage long sys_myservice (int arg1, char* arg2) {
printk(KERN_EMERG “My Service is Running”);
//kernel messages logged to /var/log/kernel/warnings
return(1);
}
//What is asmlinkage?
//Asmlinkage is used to look for the arguments on the kernel stack.
In /usr/src/linux-2.6.35.5/arch/x86/include/asm/unistd_32.h, define an index for your system call.
Your index should be the number after the last system call defined in the list.
#define __NR_myservice 338
5. Also, you should increment the system call count.
#define NR_syscalls 339
6. /usr/src/linux-2.6.35.5/arch/x86/kernel/syscall_table.S, you should define a pointer to
hold a reference to your system call routine. It is important that your data entry
placement corresponds to the index you assigned to your system call.
.long sys_myservice
7. Create a Makefile in a NewFolder (folder you created in step 3) Add your system call to the Makefile by adding the line below.
#####Makefile Start#####
obj-y += myservice.o
#####Makefile End#######
8.
In /usr/src/linux-2.6.35.5/include/linux/syscalls.h
This file contain the declarations for system calls.
Add the following line at the end of the file:
asmlinkage long sys_myservice (int arg1, char* arg2);
9. Add directory path of the NewFolder to the Makefile (/usr/src/Linux-2.6.35.5/Makefile)
Add your call to core-y (Search for regex: core-y.*+=). This directory will contain the source file, header file and the Makefile for our system call.
core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ NewFolder
10.
For testing our new system call you will need to recompile Kernel.
Compilation Steps
a. Enter
/usr/src/linux-2.6.35.5/make menuconfig
exit and save changes
b. Start compiling to create a compressed kernel image, enter:
$ make
c. Start compiling to kernel modules, enter:
$ make modules
d. Install kernel modules
$ make modules_install
e. Install kernel
So far we have compiled kernel and installed kernel modules. It is time to install kernel itself.
# make install
f.
Create an initrd image
Type the following command at a shell prompt:
# cd /boot
# mkinitram fs-o initrd.img-2.6.35.5
g.
# update-grub
h.
Reboot computer and boot into your new kernel
Just issue reboot command:
# reboot
11.
Create a C program and check your system call

No comments:
Post a Comment