Build A New Kernel and Add New System
Build A New Kernel and Add New System Calls in A Linux OS jlchou@csie. nctu. edu. tw C. L. Chou
Goals n n Learn how to build a new Linux kernel Learn how to add new system calls
Build A New Linux Kernel
Reference n Refer to relative documents on Internet n n 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 n n File system support RAM disk support may need to be checked when configuring the kernel. n n 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 n Basic installation steps: n n n n %make %make n xconfig/menuconfig dep clean bz. Image modules_install Automatically copy kernel image, copy system. map, create initial ramdisk, modify grub. conf, etc.
Add New System Calls
Reference n Refer to relative documents on Internet n n Use “how to add a system call” as key words for search engine. E. g. http: //fossil. wpi. edu/docs/howto_add_syst emcall. html
Added or Modified Kernel Files n n The version of example kernel is 2. 6. 11. 1 Files added or modified in the kernel: n n n n arch/i 386/kernel/syscall_table. S (split from entry. S) include/asm/unistd. h include/linux/myservice. h include/net/myvariable. h net/ipv 4/myservice. c init/main. c net/ipv 4/tcp. c
Functionalities of added system calls n mysetflag() n n Turn on/off a kernel flag to start/stop counting the number of invoking tcp_sendmsg() in the kernel. mygetdata() n Obtain the number of invoking tcp_sendmsg() recorded in the kernel.
arch/i 386/kernel/syscall_table. S n n Modified file Search key words: n n sys_mysetflag sys_mygetdata
include/asm/unistd. h n n Modified file Search key words: n n n mysetflag mygetdata #define NR_syscalls 313 n 313 is the total number of system calls.
include/linux/myservice. h n n Added file The header file of net/ipv 4/myservice. c
include/net/myvariable. h n n Added file Declaration of two global variables and one data structure which are used in kernel.
net/ipv 4/myservice. c n n Added file Define two system call functions and one initialization function. n n n sys_mysetflag() sys_mygetdata() myvariable_init()
init/main. c n n Modified file Search key word: n myvariable_init (twice)
net/ipv 4/tcp. c n n Modified file Search key words: n n myflag (twice) tcp_sendmsg_call_count (twice)
User-level Example Program Files n n n myservice_user. h myservice_user. c Compiling myservice_user. c n gcc –o myservice_user. c
Demo n n Date: 4/24 (Mon. ), 4/25(Tues. ) at EC 215 Steps: n n Run the user-level program. Run any application that creates a TCP connection to send data packets. n n n ssh ftp http
Downloading FTP Site n n n IP: 140. 113. 214. 77 Port: 21 Login: homework Password: homework Files: n n n Build A New Kernel and Add New System Calls. ptt linux-2. 6. 1. tar. gz myservice_user. tar. gz
- Slides: 20