csci-3753: operating systems fall...
TRANSCRIPT
CSCI-3753: Operating SystemsFall 2019
Anh NguyenDepartment 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 programrequests a service from the kernel of the operatingsystem it is executed on
•Each system call
corresponds to a number
defined in a syscalls table.
3CSCI 3753 Fall 2019
syscall(number, …)
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 thesystem call number.
•Example 2:• In Unix-like systems, fork() and exec() are C-
library functions that in turn execute instructions thatinvoke the fork() and exec() system calls.
4CSCI 3753 Fall 2019
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
5CSCI 3753 Fall 2019
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
6CSCI 3753 Fall 2019
Protection of Passing Values Between Spaces
• copy_from_user()
•get_user()
• copy_to_user()
•put_user()
•printk()
• cat /var/log/syslog
•dmesg
7CSCI 3753 Fall 2019
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)
10CSCI 3753 Fall 2019
Loadable Kernel Module (LKM)
• LKM is an object file that contains a chunk of codeto add to the base kernel of an operating systemwhile it is RUNNING.
•Typically, it is used to add support for •New hardware as device drivers• Filesystem drivers
11CSCI 3753 Fall 2019
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
12CSCI 3753 Fall 2019
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
13CSCI 3753 Fall 2019
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.
14CSCI 3753 Fall 2019
Week 2 – Checklist
q Submit PS1 by 6PM today !!!
q Start PA1
q Read more about LKMs
q Quizo Every weeko Open book BUT NO use of device to interact with
otherso Only ONE attempt
16CSCI 3753 Fall 2019