Loadable Kernel Modules (Lkms)

Loadable Kernel Modules (Lkms)

CSCI-3753: Operating Systems Fall 2019 Anh Nguyen Department of Computer SCienCe University of Colorado Boulder Week 2: System Calls vs Loadable Kernel Modules (LKMs) CSCI 3753 Fall 2019 2 What is a System Call? • A programmatic way in which a computer program requests a service from the kernel of the operating system it is executeD on • Each system call corresponDs to a number defineD in a syscalls table. syscall(number, …) CSCI 3753 Fall 2019 3 Do we use system calls at all? • Example 1: • If you open a file using fopen() in the library stdio.h, it gets translateD into the open() system call. • In the standarD library, the user-space implementation of the open() system call executes and passes the system call number. • Example 2: • In Unix-like systems, fork() and exec() are C- library functions that in turn execute instructions that invoke the fork() and exec() system calls. CSCI 3753 Fall 2019 4 EXECUTing a System Call 1. A user space program invokes the syscall 2. A (typically) software interrupt called a trap is triggereD (INT) 3. Mode bit is flipped from user to kernel (1 to 0) 4. The interrupt tells the kernel which syscall was calleD 1. Requisite data may be passed in 2. The kernel verifies if all parameters are legal before executing the system call 5. After execution, moDe bit flips anD user program resumes CSCI 3753 Fall 2019 5 ADDing a System Call 1. Write the system call source coDe arch/x86/kernel/newSysCall.c 2. Add the syscall prototype to the syscalls header file incluDe/linux/syscalls.h 3. Add the new syscall to the Makefile arch/x86/kernel/Makefile 4. Add the syscall to the syscalls table arch/x86/entry/syscalls/syscall_64.tbl 5. Re-compile the kernel CSCI 3753 Fall 2019 6 Protection of Passing Values Between Spaces • copy_from_user() • get_user() • copy_to_user() • put_user() • printk() • cat /var/log/syslog • dmesg CSCI 3753 Fall 2019 7 How to Extend a Kernel? • Method 1: System calls Recompile the kernel !!! è It takes a long time to compile the kernel source coDe (2-3 hours) • Method 2: Loadable Kernel Module (LKM) CSCI 3753 Fall 2019 10 Loadable Kernel Module (LKM) • LKM is an object file that contains a chunk of coDe to adD to the base kernel of an operating system while it is RUNNING. • Typically, it is useD to aDD support for • New hardware as device drivers • Filesystem drivers CSCI 3753 Fall 2019 11 LKM Pros & Cons • Pros: • DON’T have to REBUILD the kernel • Save memory • UnloaDeD in orDer to free memory anD other resources when it is no longer requireD • Be MUCH faster to maintain and debug • Cons • FRAGMENTATION penalty • Security CSCI 3753 Fall 2019 12 LKM Utilities • insmod: Insert an LKM into the kernel. • rmmod: Remove an LKM from the kernel. • lsmod: List currently loaDeD LKMs. • modprobe: Insert/remove an LKM or set of LKMs intelligently. • e.g., if you must loaD A before loaDing B, modprobe will automatically load A when you tell it to load B. • kerneld: Kernel Daemon program • allows kernel moDules to be loadeD automatically rather than manually with insmod/modprobe CSCI 3753 Fall 2019 13 LKM Utilities • depmod: Determine interDepenDencies between LKMs. • ksyms: Display symbols that are exporteD by the kernel for use by new LKMs. • modinfo: Display contents of .moDinfo section in an LKM object file. CSCI 3753 Fall 2019 14 Week 2 – Checklist q Submit PS1 by 6PM toDay !!! q Start PA1 q ReaD more about LKMs q Quiz o Every week o Open book BUT NO use of device to interact with others o Only ONE attempt CSCI 3753 Fall 2019 16.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    13 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us