How to get syscall linux name from system number?

I need to translate the syscall Linux number into a human-readable name. With kernel 2.6.32, I extracted names from __NR_ * macros in / usr / include / asm / unistd _32.h, which was hacked, but it worked. Now I need to get it to work with the 3.2.0 kernel, and this file no longer exists.

What is the least hacky and most portable way to map a Linux system call number to a human-readable name? For instance. 1-> exit, 6-> close, etc.

+4
source share
2 answers

The file <sys/syscall.h>defines many macros SYS_(indirectly through bits/syscall.hon my system). For instance:

#define SYS_eventfd __NR_eventfd
#define SYS_eventfd2 __NR_eventfd2
#define SYS_execve __NR_execve
#define SYS_exit __NR_exit
#define SYS_exit_group __NR_exit_group
#define SYS_faccessat __NR_faccessat

, ? , , :

switch(code) {
#define syscode_case(x) case x: return #x;
    syscode_case(SYS_eventfd);
    syscode_case(SYS_eventf2);
}

, , .

Edit:

man 2 syscall, :

#include <sys/syscall.h>`   /* For SYS_xxx definitions
+1
  • grep -rA3 'SYSCALL_DEFINE.\?(<syscallname>,' * ( <syscallname> syscall).
  • man syscalls .
0

Source: https://habr.com/ru/post/1537742/


All Articles