1 / 182

Linux Project

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.

ahava
Download Presentation

Linux Project

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Linux Project 中央大學資工系 碩士二年級 江瑞敏

  2. 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

  3. Download Link • wgethttps://kernel.org/pub/linux/kernel/linux-2.6.18.tar.bz2 • tar xvf linux-2.6.18.tar.bz2

  4. The Beginning of everything

  5. Compile Linux Kernel

  6. It is Hard?

  7. No, If you understand the concept

  8. The Basic Process • 0. make mrproper • 1. make oldconfig • 2. make –j[n] • 3. make modules_install • 4. make install • 5. reboot

  9. Do You Know What It Means?

  10. make mrproer • Clean up the environment • Will Remove almost everything, except….

  11. make clean • Almost the same as make mrproper.

  12. make oldconfig • Use the configuration file the current kernel is using. • Some other alternative options. • Make menuconfig • …

  13. Is config File Important?

  14. 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.

  15. make –j[n] • Compile the whole source code according to your configuration

  16. make modules_install • Install the modules into the necessary folder. • /lib/modules/`uname –r`/

  17. make install • Install the image into the boot directory. • Sometimes, update grub is necessary.

  18. What Is System Call

  19. It’s a Bridge

  20. Between Device Device User Device Device

  21. Why System Call

  22. Pop Quiz :Write A Program To Print “Hello World”

  23. What You May Write

  24. What Actually Happened ….

  25. User Application Printf libc.so System Call Kernel Code Device Driver IO Device

  26. What If There Is No System Call

  27. Everything Will Bex86 instruction in and out

  28. Let’s Focus On … User Application Printf libc.so System Call Kernel Code Device Driver IO Device

  29. Magic int 0x80

  30. Before We Talk Further,Let’s Talk About X86 Architecture

  31. X86 Architecture Is Interrupt Driven

  32. User Application Kernel Device Driver CPU 8259 PIC Device Device Device Device

  33. How The CPU Find The Address of The Device Driver Code

  34. Callback Mechanism

  35. Kernel Device Driver Interrupt Descriptor Table Device Driver … ….. Device Driver Device Driver CPU 8259 PIC Device Device Device Device Physical Device

  36. How About System Call

  37. Magic int 0x80

  38. 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

  39. cpu User Application CPU int 0x80 cs ds ss Kernel esp eip … … Stack

  40. cpu User Application CPU int 0x80 cs ds ss esp eip … … Get TSS GDT Stack TSS

  41. cpu User Application CPU int 0x80 cs ds ss esp eip … … Get TSS GDT Stack TSS

  42. cpu User Application CPU int 0x80 cs ds ss esp eip … … Get IDT IDT ENTRY(system_call) Stack 0x80 sys_call_table

  43. cpu User Application CPU int 0x80 cs ds ss esp eip … … Get IDT IDT ENTRY(system_call) Stack 0x80 sys_call_table

  44. 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

  45. How To Add A System Call

  46. 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

  47. 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

  48. 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

More Related