Courses/Computer Science/CPSC 457.F2014/Lecture Notes/SystemCalls
System calls are one of the most important constructs in OS. More generally, the represent a way to transition in a standard, safe, and well-understood fashion between unprivileged code and privileged code.
We will start from a discussion of x86 assembly language programming and see how system calls are made (i.e., their calling convention on x86/Linux), how they are defined, how they can be traced, and how they differ from "normal" function calls.
We looked at assembly-level function invocation (as a reminder).
We saw how we could talk directly to the kernel via the syscall interface
- now let's write a program using write(2)
- compare this with our assembly version mywrite.asm
- what is the nature of this interface? (combined API and privilege transition mechanism)
- where are the parts documented?
- manual pages for syscall definitions (syntax and semantics)
- show locations of syscall number definitions: /usr/include/asm/unistd_32.h
- what is the actual mechanism?
- trace the "control flow" of making a system call
- phrack article on IDT: http://www.phrack.com/issues.html?issue=59&id=4&mode=txt
Links to kernel code:
- http://lxr.cpsc.ucalgary.ca/lxr/#linux+v2.6.32/include/linux/syscalls.h#L256 (DEFINE0 macro)
- x86_64 syscall table data structure declaration: http://lxr.cpsc.ucalgary.ca/lxr/#linux/arch/x86/kernel/syscall_64.c
- http://lxr.cpsc.ucalgary.ca/lxr/#linux+v2.6.32/include/linux/linkage.h#L64 (ENTRY macro)
- each architecture is free to define its own system call numbers, see, e.g., Itanium (IA64): http://lxr.cpsc.ucalgary.ca/lxr/#linux+v2.6.32/arch/ia64/include/asm/unistd.h
- do_fork() system call: http://lxr.cpsc.ucalgary.ca/lxr/#linux+v2.6.32/kernel/fork.c#L1375
- MOS: 1.6: System Calls (you should have read this already)
- LKD: Chapter 5. System Calls (this describes how to add a system call to your OS, something you'll have an opportunity to practice in your tutorials later and in homeworks)