V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
KyL
V2EX  ›  Linux

如何在 Linux Kernel 3.x 中找到某个 system call 的实现呢

  •  
  •   KyL · 2015-08-28 13:46:30 +08:00 · 2431 次点击
    这是一个创建于 3163 天前的主题,其中的信息可能已经有所发展或是发生改变。

    比如我想要找到execve在内核中的实现代码。我在源码中搜索sys_execve,在代码中只能找到头文件声明,系统调用注册的相关代码,找不到函数体。其他系统调用也都有这个问题。请问该如何寻找呢?

    第 1 条附言  ·  2015-08-28 15:58:22 +08:00

    我已经在StackOverflow 的问题里找到答案了

    Syscall function names, which are always sys_something, are generated by funny preprocessor macros (SYSCALL_DEFINEn where n is the number of arguments).

    As you can see (very close to do_sys_open):

    SYSCALL_DEFINE3(open, const char __user *, filename, int, flags, umode_t, mode)
    {
            long ret;
            ....
    

    This is the code of open syscall.

    4 条回复    2015-08-28 17:31:03 +08:00
    whatot
        1
    whatot  
       2015-08-28 14:29:25 +08:00   ❤️ 1
    搜索 do_execve 看看,我也是 google 到的。

    linux-4.1 fs/exec.c:1704

    SYSCALL_DEFINE3 (execve,
    const char __user *, filename,
    const char __user *const __user *, argv,
    const char __user *const __user *, envp )
    {
    return do_execve (getname (filename ), argv, envp );
    }
    lynx
        2
    lynx  
       2015-08-28 14:51:48 +08:00
    google: execve site:lxr.free-electrons.com/source
    liwei
        3
    liwei  
       2015-08-28 15:09:35 +08:00
    make ARCH=x86 -j2 tags cscope
    vim -t sys_execve
    oska874
        4
    oska874  
       2015-08-28 17:31:03 +08:00
    arm 的我知道: arch/arm/kernel/call.S 里面有系统调用列表,然后你就可以在内核根目录 ctags -R ,在 vim 里面 tags <func_name> 了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2796 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 15:36 · PVG 23:36 · LAX 08:36 · JFK 11:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.