Build A New Kernel and Add New System Calls in A Linux OS jlchou@csie.nctu.edu.tw C.L. Chou
Goals Learn how to build a new Linux kernel Learn how to add new system calls
Build A New Linux Kernel
Reference Refer to relative documents on Internet Use “how to build a linux kernel” as key words for search engine. E.g. http://www.digitalhermit.com/linux/Kernel-Build-HOWTO.html
Note for Kernel Configuration File system support RAM disk support may need to be checked when configuring the kernel. Device Drivers Block devices RAM disk support Network devices’ drivers have to be checked according to what kinds of network devices equipped on your PC.
Note for Kernel Compilation and Installation Basic installation steps: %make xconfig/menuconfig %make dep %make clean %make bzImage %make modules %make modules_install %make install Automatically copy kernel image, copy system.map, create initial ramdisk, modify grub.conf, etc.
Add New System Calls
Reference Refer to relative documents on Internet Use “how to add a system call” as key words for search engine. E.g. http://fossil.wpi.edu/docs/howto_add_systemcall.html
Added or Modified Kernel Files The version of example kernel is 2.6.11.1 Files added or modified in the kernel: arch/i386/kernel/syscall_table.S (split from entry.S) include/asm/unistd.h include/linux/myservice.h include/net/myvariable.h net/ipv4/myservice.c init/main.c net/ipv4/tcp.c
Functionalities of added system calls mysetflag() Turn on/off a kernel flag to start/stop counting the number of invoking tcp_sendmsg() in the kernel. mygetdata() Obtain the number of invoking tcp_sendmsg() recorded in the kernel.
arch/i386/kernel/syscall_table.S Modified file Search key words: sys_mysetflag sys_mygetdata
include/asm/unistd.h Modified file Search key words: mysetflag mygetdata #define NR_syscalls 313 313 is the total number of system calls.
include/linux/myservice.h Added file The header file of net/ipv4/myservice.c
include/net/myvariable.h Added file Declaration of two global variables and one data structure which are used in kernel.
net/ipv4/myservice.c Added file Define two system call functions and one initialization function. sys_mysetflag() sys_mygetdata() myvariable_init()
init/main.c Modified file Search key word: myvariable_init (twice)
net/ipv4/tcp.c Modified file Search key words: myflag (twice) tcp_sendmsg_call_count (twice)
User-level Example Program Files myservice_user.h myservice_user.c Compiling myservice_user.c gcc –o myservice_user myservice_user.c
Demo Date: 4/24 (Mon.), 4/25(Tues.) at EC215 Steps: Run the user-level program. Run any application that creates a TCP connection to send data packets. ssh ftp http
Downloading FTP Site IP: 140.113.214.77 Port: 21 Login: homework Password: homework Files: Build A New Kernel and Add New System Calls.ptt linux-2.6.16.1.tar.gz myservice_user.tar.gz