c - 如何从系统调用号获取 Linux 系统调用名称?

标签 c linux system-calls

我需要将 Linux 系统调用号翻译成人类可读的名称。在内核 2.6.32 中,我从 /usr/include/asm/unistd_32.h 中的 _NR* 宏中提取名称,这很笨拙,但它确实有效。现在我需要让它在内核 3.2.0 上运行,而这个文件不再存在。

将 Linux 系统调用编号映射到人类可读名称的最简单、最便携的方法是什么?例如。 1->退出,6->关闭等

最佳答案

文件<sys/syscall.h>定义了很多 SYS_宏(间接通过我系统上的 bits/syscall.h)。例如:

#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);
}

您仍然需要知道可用的宏有哪些,但您不需要知道实际值。

编辑:

我的来源是 man 2 syscall ,其中指出:

#include <sys/syscall.h>`   /* For SYS_xxx definitions

关于c - 如何从系统调用号获取 Linux 系统调用名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23249373/

相关文章:

c - 获取 Windows 任务栏的高度 (Winapi)

c - 尝试追踪 archLinux64 下的内存分配错误

linux - 如何创建特定用途的命令 shell

linux - 如何在sys_create中设置权限

c - 编写新系统调用时可用的函数

c++ - 在 C++ 中使用 linux 系统调用和文件和文件夹管理

c - 如何在 2013 zlib API 接口(interface)中模仿(被黑)1998 uncompress() 上的 "use_crc"标志?

c++ - 使用为不同机器编译的静态库

linux - 如何在 Amazon Linux AMI 中安装 Postgresql 11?

c - Linux 系统调用何时触发段错误与返回 EFAULT?