Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a list of Linux system calls and number of args they take automatically?

Tags:

c

system-calls

I writing a Linux system call map for the radare2 debugger. This means providing a huge static array mapping system call number to a syscall name name and the number of arguments it takes. This was easy for OpenBSD as the syscall numbers are defined in sys/syscall.h and in a comment above each is the number of args. It was just a matter of writing a script to parse this and throw out the C code for the array.

On linux however, we do not have this luxury. It is easy to get the syscall number from the kernel headers, but how should I get the number of args? The only ideas I have are:

1) Type them in manually. For each and every arch (they vary between arches in linux). All 300+ of the damned things. No way!

2) Parse manual pages.

3) Write a script which tries to call each syscall with 0, 1, 2... args until the program builds. Won't work for varargs, but do syscalls support that?

There has to be a better way. Please help!

like image 889
Edd Barrett Avatar asked Jul 06 '11 22:07

Edd Barrett


People also ask

Which command is used to check system calls in Linux?

The ls command internally calls functions from system libraries (aka glibc) on Linux. These libraries invoke the system calls that do most of the work.

How many Linux system calls are there?

There are 116 system calls; documentation for these can be found in the man pages. A system call is a request by a running task to the kernel to provide some sort of service on its behalf.

How system calls are called by number and name in Linux?

System calls are identified by their numbers. The number of the call foo is __NR_foo . For example, the number of _llseek used above is __NR__llseek , defined as 140 in /usr/include/asm-i386/unistd.

What is the system call table?

A kernel system call, or syscall, is an entry point via which usermode code can call functions in the Linux kernel. A syscall table is a mapping between the syscall ID and the kernel address of its implementation.


1 Answers

strace (home page) has tables with all this stuff in (see linux/<platform>/syscallent.h). Source code available in GitHub/strace and GitLab/strace. For example, list of syscalls in x86_64 architecture are in this link.

like image 73
Matthew Slattery Avatar answered Sep 19 '22 16:09

Matthew Slattery