System Calls Userspace programs can request action by the kernel - Like with /proc files - System calls have return AND parameters CS250 review: How to trigger one of these POSIX: Portable Operating System Interface X - man lists POSIX compatibility - *nix systems are POSIX-compatible - Older Windows is, maybe still by library (nanosleep) - Philisophically, non-busybody, like big box store Remember: On *nix, return of 0 generally means success - Otherwise, errno will be set Need two pieces: - Userspace library function - Kernel implementation Let's look at read - First: What do we do to call it in the program? - read system call (fs/read_write.c) - vfs_read and what is vfs (file_operations struct) - Macro sets up system call, assigns number, etc. - Exact set of system calls is architecture-dependent - read in arch/x86 system call table Mechanism: - Memory manipulation as required (like x86 function call) - System call number goes in eax - Interrupt 0x80 is triggered (we'll play with interrupts later) - We end up in entry_64.S - System call is looked up, and the appropriate kernel code is run Generally speaking, system calls have a particular purpose - Like read - NOT like ioctl The book goes through the process of adding one - This class (usually) covers using /proc and /dev, but not syscalls Why not add these? - After all, they're fast, and pretty simple to add actually - Syscalls have syscall numbers that are part of the kernel interface - If you add a system call, on an "unofficial" number, and that number is later used, you will have a problem - Can't be used without userspace C code (no vfs interface) - /proc, /dev, and /sys exist for this (/sys is newer than me)