Syscalls
Sources (linux-3.2.33)
arch/x86/include/asm/unistd_64.h // This file contains the system call numbers
arch/x86/kernel/entry_64.S // It contains the system-call and fault low-level handling routines.
arch/x86/kernel/syscall_64.c // System call table for x86-64
include/linux/syscall.h // Linux syscall interfaces (non-arch-specific)
arch/x86/kernel/process.c // sys_clone()
Sources (linux-4.4 and later)
arch/x86/entry/syscalls/syscall_64.tbl // common entry for x86_64 and x32
arch/x86/entry/syscalls/syscall_32.tbl // for i386 entries
Adding a New System Call
Generic System Call Implementation
CONFIG
option for the new function, normally ininit/Kconfig
.SYSCALL_DEFINEn(xyzzy, ...)
for the entry pooint- corresponding prototype in
include/linux/syscalls.h
- generic table entry in
include/uapi/asm-generic/unistd.h
(this step can be ingored in x86 case.) - fallback stub in
kernel/sys_ni.c
x86 System Call Implementation
Practice
- Add
CONFIG_
option for the new function ininit/Kconfig
. - Wrapper new function code with
#ifdef CONFIG_XXX
Futexes
- A futex overview and update
- locklessinc. Mutexes and Condition Variables using Futexes
- Rusty Russel. Fuss, Futexes and Furwocks: Fast Userlevel Locking in Linux
- Ulrich Drepper. Futexes Are Tricky
- Requeue PI: Making Glibc Condvars PI-Aware
- FUTEX + rwsem = SNAFU
- lwn Kernel: Futex
- DESIGN-rwloc
- robust-futexes
Glibc Bugs
Glibc Wrappers
Tools
- ausyscall(8)
mapping syscall names and nubmers
$ ausyscall i386 open
open 5
mq_open 277
openat 295
perf_event_open 336
open_by_handle_at 342
$ ausyscall x86_64 open
open 2
mq_open 240
openat 257
perf_event_open 298
open_by_handle_at 304
$ ausyscall --dump | head -n10
Using x86_64 syscall table:
0 read
1 write
2 open
3 close
4 stat
5 fstat
6 lstat
7 poll
8 lseek