Skip to content

Instantly share code, notes, and snippets.

@nickedes
Last active September 15, 2015 17:27
Show Gist options
  • Save nickedes/88f0fd68d51de304f55a to your computer and use it in GitHub Desktop.
Save nickedes/88f0fd68d51de304f55a to your computer and use it in GitHub Desktop.
Download 3.14.37.tar.xz
STEP 1:
cd Downloads/
sudo tar -xvJf linux-3.14.37.tar.xz -C /usr/src/
cd /usr/src/linux-3.14.37/
sudo mkdir hello
cd hello/
sudo gedit hello.c #given below
sudo gedit Makefile
Add the following line into hello/Makefile.
obj-y := hello.o
STEP 2:
$ cd ..
Edit Makefile of linux directory
replace
core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
with the below given line.
core-y+= kernel/ mm/ fs/ ipc/ security/ crypto/ block/ hello/
STEP 3:
$ cd arch/x86/syscalls/
$ sudo gedit syscall_64.tbl
add this line:
317 common hello sys_hello
317 is ur system call no. , if the previous ends on number X then ur system call no. shud be x+1 :P
now
$ cd /usr/src/linux-3.14.37/include/linux/
$ sudo gedit syscalls.h
add this line above "#endif"
asmlinkage long sys_hello(void);
STEP 4: Compile kernel
$ cd /usr/src/linux-3.14.37
$ sudo make defconfig
$ sudo make -j4
$ sudo make modules_install install
after this reboot from new installed kernel i.e. 3.14.37
STEP 5:
After booting from new kernel
$ cd ~
$ sudo gedit syshello.c #given below
$ gcc syshello.c
$ ./a.out
$ dmesg
DONE!
#include<linux/kernel.h>
asmlinkage long sys_hello(void)
{
printk("Hello world\n");
//printk is similar to printf function of C but writes to the kernel log //instead of the screen.
return 0;
}
#include <linux/kernel.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
int main()
{
long int r = syscall(316);
printf("System call sys_hello returned %ld\n",r);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment