简体   繁体   English

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

[英]How to obtain Linux syscall name from the syscall number?

I need to translate Linux syscall number into human-readable name.我需要将 Linux 系统调用号转换为人类可读的名称。 With kernel 2.6.32, I was extracting the names from _ NR * macros in /usr/include/asm/unistd_32.h , which was hacky but it worked.使用内核 2.6.32,我从/usr/include/asm/unistd_32.h 中的_ NR * 宏中提取名称,这很笨拙,但有效。 Now I need to make it work on kernel 3.2.0 and this file is no longer there.现在我需要让它在内核 3.2.0 上工作并且这个文件不再存在。

What is the least hacky and most portable way of mapping the Linux syscall number into human-readable name?将 Linux 系统调用号映射为人类可读名称的最简单、最便携的方法是什么? Eg 1->exit, 6->close etc.例如1->退出,6->关闭等。

The file <sys/syscall.h> defines a lot of SYS_ macros (indirectly through bits/syscall.h on my system).文件<sys/syscall.h>定义了很多SYS_宏(间接通过我系统上的bits/syscall.h )。 For example:例如:

#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

Is this what you are looking?这是你要找的吗? I am not sure if this is part of your question, but then you can do:我不确定这是否是您问题的一部分,但您可以这样做:

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

You still need to know what are the available macros, but you do not need to know the actual value.您仍然需要知道可用的宏是什么,但您不需要知道实际值。

Edit:编辑:

My source is the man 2 syscall , which states:我的来源是man 2 syscall ,它指出:

#include <sys/syscall.h>`   /* For SYS_xxx definitions
  1. You can do a grep -rA3 'SYSCALL_DEFINE.\\?(<syscallname>,' * in your kernel sources directory (substitute <syscallname> with your actual syscall).您可以在内核源目录中执行grep -rA3 'SYSCALL_DEFINE.\\?(<syscallname>,' * (用实际的系统调用替换<syscallname> )。
  2. You can man syscalls and start looking from there on.您可以管理man syscalls并从那里开始查找。
  3. Check here and be patient (link reported broken in the comments)检查这里并耐心等待(评论中报告的链接已损坏)
  4. This one seems to be working这个似乎有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM