I am following a Linux System Programming Video Tutorial.
When I reached "how to add your own Linux System Call" section, the instructor shows that all System Call IDs (macros starting with __NR) are present in arch/x86/include/asm/unistd_32.h or unistd_64.h (depending on the target).
But in my source code(linux-5.0.1) I do not see those files, there's just one unistd.h which does not contain the system call IDs. Were these files moved elsewhere or does x86 not have its own system call table now.
Edit: I downloaded the latest kernel source code from kernel.org and I am trying to modify it. I cannot find unistd_32.h and unistd_64.h files at the aforementioned location. Do I need to do something first?
Arch Linux ships unistd_32.h
and unistd_64.h
in /usr/include/asm/
. Just look at those headers unless you're modifying the kernel to add new system calls.
<asm/unistd.h>
checks macros to figure out if its being included in 32 or 64-bit code (and checks for x32), and uses #include
to pull in the right set of definitions for the target.
On my up-to-date x86-64 Arch system:
$ pacman -Fo /usr/include/asm/unistd*
usr/include/asm/unistd_32.h is owned by core/linux-api-headers 4.7-1
usr/include/asm/unistd_64.h is owned by core/linux-api-headers 4.7-1
usr/include/asm/unistd.h is owned by core/linux-api-headers 4.7-1
usr/include/asm/unistd_x32.h is owned by core/linux-api-headers 4.7-1
In the kernel source itself, starting with version 3.3, the unistd_32.h
for use by user-space is built from other files.
https://github.com/torvalds/linux/search?q=unistd_32.h&unscoped_q=unistd_32.h finds this in arch/x86/entry/syscalls/Makefile
$(uapi)/unistd_32.h: $(syscall32) $(syshdr)
$(call if_changed,syshdr)
The syscall tables are defined in: arch/x86/entry/syscalls/syscall_32.tbl
and .../syscall_64.tbl
The contents of syscall_32.tbl
looks like:
# some comments
0 i386 restart_syscall sys_restart_syscall __ia32_sys_restart_syscall
1 i386 exit sys_exit __ia32_sys_exit
2 i386 fork sys_fork __ia32_sys_fork
3 i386 read sys_read __ia32_sys_read
...