Kernel 3.10.104
楊佳峻
方廷宇
吳榕憲
Ubuntu 16.04.7 LTS
onVirtual Box
-
Install Necessary Packages
sudo apt update && sudo apt install wget build-essential libncurses-dev libssl-dev libelf-dev bison flex -y
-
Download
Kernel 3.10.104
& Extract itwget https://mirrors.edge.kernel.org/pub/linux/kernel/v3.0/linux-3.10.104.tar.gz
tar -xvf linux-3.10.104.tar.gz -C ~/Desktop
-C
extract to which foldercd ~/Desktop/linux-3.10.104/
-
Set Up Kernel Config
sudo make menuconfig # eg. load config-`uname -r` and exit with save
-
You can copy current configuration from device and load it
sudo cp /boot/config-`uname -r` .config
-
-
Compile Kernel & Install
sudo make -j5 && sudo make modules_install -j5 && sudo make install -j5
-
Update GRUB Setting
sudo update-grub
Because the kernel version from
4.15.0-112
to3.10.104
, we do the following things beforeupdate-grub
sudo nano /etc/default/grub
- Set
GRUB_TIMEOUT=-1
- Comment out all items starting with
GRUB_HIDDEN_TIMEOUT_
- Set
-
Reboot the Machine
reboot
- Select
kernel-3.10.104
in ubuntu advance option when booting
- Select
⚠️ Please create a folder in the kernel folder, eg. custom_syscall⚠️
-
Write Custom System Call and Add Them into Makefile
# file: custom_syscall/Makefile # custom syscall file & *.c=*.o obj-y := helloworld.o get_phy_addr.o get_segment.o
# file: Makefile # ... core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ # custom_syscall # add below after the above line core-y += custom_syscall/ # ...
-
Add Custom System Call in the Button of
include/linux/syscalls.h
// file: include/linux/syscalls.h // ... // custom // add at the end before `#endif` asmlinkage int helloworld(void); // 8787 asmlinkage unsigned long sys_get_phy_addr(unsigned long vaddr); // 8788 asmlinkage unsigned long sys_get_segment(unsigned long vaddr, void *out); // 8789 #endif
-
Add Custom System Call in the Button of
arch/x86/syscalls/syscall_32.tbl
(32 bits)# file: arch/x86/syscalls/syscall_32.tbl # ... # custom # add at the end 8787 i386 helloworld sys_helloworld 8788 i386 get_phy_addr sys_get_phy_addr 8789 i386 get_segment sys_get_segment
-
Re-compile & Re-install Kernel
If your are on amd64 installation, please
sudo apt install libc6-dev-i386 -y
-
Use your system call and get return value by using function
syscall(syscall_index, arg...)
-
Compile your .c/.cpp files using
gcc -m32 project1.c -o project1 -lpthread -Wall -fPIE
-
To see
printk()
message, usedmesg
command. Eg../test_helloworld && dmesg | tail