jasoncc.github.io

Random Signals on Some Low-level Stuff.

View on GitHub

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

  1. CONFIG option for the new function, normally in init/Kconfig.
  2. SYSCALL_DEFINEn(xyzzy, ...) for the entry pooint
  3. corresponding prototype in include/linux/syscalls.h
  4. generic table entry in include/uapi/asm-generic/unistd.h (this step can be ingored in x86 case.)
  5. fallback stub in kernel/sys_ni.c

x86 System Call Implementation

Practice

  1. Add CONFIG_ option for the new function in init/Kconfig.
  2. Wrapper new function code with #ifdef CONFIG_XXX

Futexes

Glibc Bugs

Glibc Wrappers

Tools

$ 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

References

back