1.83k likes | 2.25k Vues
Linux Project. 中央大學資工系 碩士二年級 江瑞敏. Outline. How to compile linux kernel How to add a new system call Some Projects Example and Way to Solve it System Call Hooking by Module Project about Memory Project about Process. Download Link.
E N D
Linux Project 中央大學資工系 碩士二年級 江瑞敏
Outline • How to compile linux kernel • How to add a new system call • Some Projects Example and Way to Solve it • System Call Hooking by Module • Project about Memory • Project about Process
Download Link • wgethttps://kernel.org/pub/linux/kernel/linux-2.6.18.tar.bz2 • tar xvf linux-2.6.18.tar.bz2
The Basic Process • 0. make mrproper • 1. make oldconfig • 2. make –j[n] • 3. make modules_install • 4. make install • 5. reboot
make mrproer • Clean up the environment • Will Remove almost everything, except….
make clean • Almost the same as make mrproper.
make oldconfig • Use the configuration file the current kernel is using. • Some other alternative options. • Make menuconfig • …
Config file • Determine which kind of kernel you are compiling • Determine which modules you want the kernel to compile. • Misconfiguration will lead to kernel crash.
make –j[n] • Compile the whole source code according to your configuration
make modules_install • Install the modules into the necessary folder. • /lib/modules/`uname –r`/
make install • Install the image into the boot directory. • Sometimes, update grub is necessary.
Between Device Device User Device Device
User Application Printf libc.so System Call Kernel Code Device Driver IO Device
Let’s Focus On … User Application Printf libc.so System Call Kernel Code Device Driver IO Device
User Application Kernel Device Driver CPU 8259 PIC Device Device Device Device
Kernel Device Driver Interrupt Descriptor Table Device Driver … ….. Device Driver Device Driver CPU 8259 PIC Device Device Device Device Physical Device
System Call Handler Interrupt Descriptor Table syscall_table System Call Handler ….. ….. 0x80 System Call Handler ….. CPU 8259 PIC int 0x80 Device Device Device Device Physical Device
cpu User Application CPU int 0x80 cs ds ss Kernel esp eip … … Stack
cpu User Application CPU int 0x80 cs ds ss esp eip … … Get TSS GDT Stack TSS
cpu User Application CPU int 0x80 cs ds ss esp eip … … Get TSS GDT Stack TSS
cpu User Application CPU int 0x80 cs ds ss esp eip … … Get IDT IDT ENTRY(system_call) Stack 0x80 sys_call_table
cpu User Application CPU int 0x80 cs ds ss esp eip … … Get IDT IDT ENTRY(system_call) Stack 0x80 sys_call_table
cpu User Application CPU int 0x80 cs ss esp ds ss eflags cs esp eip eip … … Get IDT IDT ENTRY(system_call) Stack 0x80 sys_call_table
Add a System Call • 1. cd $kernel_src • 2. cd arch/i386/kernel/syscall_table.S • 3. • …. • .long sys_tee /* 315 */.long sys_vmsplice.long sys_move_pages.long sys_project /* 318 */ • Kernel.org/pub/linux/kernel
Add a System Call • cd linux/include/asm-i386/unistd.h • #define __NR_vmsplice 316#define __NR_move_pages 317#define __NR_project 318#ifdef __KERNEL__#define NR_syscalls 319
Add a System Call • cd linux/include/linux/syscalls.h • asmlinkagelong sys_set_robust_list(structrobust_list_head __user *head,size_tlen);asmlinkage long sys_project( inti );#endif