简体   繁体   English

linux kernel 中的 ptrace 在哪里?

[英]Where is ptrace in linux kernel?

I can't find it in kernel source with global ptrace , there is no definition in kernel/ptrace.c like it was stated in man page..... I can see kernel/ptrace.c and include/linux/ptrace.h but there is nothing我在具有global ptrace的 kernel 源代码中找不到它,在 kernel/ptrace.c 中没有定义,就像在手册页中所述...... h 但是什么都没有

You need to look for it in your libc source code, for example glibc or musl .您需要在您的 libc 源代码中查找它,例如glibcmusl And notice what does it say in man ptrace under NOTES section:并注意它在NOTES部分下的man ptrace中所说的内容:

Although arguments to ptrace() are interpreted according to the prototype given, glibc currently declares ptrace() as a variadic function with only the request argument fixed.虽然 arguments 到 ptrace() 是根据给定的原型解释的,但 glibc 目前将 ptrace() 声明为可变参数 function 仅修复了请求参数。 It is recommended to always supply four arguments, even if the requested operation does not use them, setting unused/ignored arguments to 0L or (void *) 0.建议始终提供四个 arguments,即使请求的操作不使用它们,将未使用/忽略的 arguments 设置为 0L 或 (void *) 0。

In glibc for example ptrace() is defined in sysdeps/unix/sysv/linux/ptrace.c :glibc中,例如ptrace()sysdeps/unix/sysv/linux/ptrace.c中定义:

long int
ptrace (enum __ptrace_request request, ...)
{
  long int res, ret;
  va_list ap;
  pid_t pid;
  void *addr, *data;

  va_start (ap, request);
  pid = va_arg (ap, pid_t);
  addr = va_arg (ap, void *);
  data = va_arg (ap, void *);
  va_end (ap);

  if (request > 0 && request < 4)
    data = &ret;

  res = INLINE_SYSCALL (ptrace, 4, request, pid, addr, data);
  if (res >= 0 && request > 0 && request < 4)
    {
      __set_errno (0);
      return ret;
    }

  return res;
}

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

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