linux 内核中的 ptrace 在哪里?
Where is ptrace in linux kernel?
我在 global ptrace
的内核源代码中找不到它,在 kernel/ptrace.c 中没有定义,就像在手册页中说明的那样......我可以看到 kernel/ptrace.c 和 include/linux/ptrace.h 但什么也没有
你需要在你的libc源代码中寻找它,例如
glibc 或
musl。并注意它在
man ptrace
在 NOTES
部分下:
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. 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.
在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;
}
我在 global ptrace
的内核源代码中找不到它,在 kernel/ptrace.c 中没有定义,就像在手册页中说明的那样......我可以看到 kernel/ptrace.c 和 include/linux/ptrace.h 但什么也没有
你需要在你的libc源代码中寻找它,例如
glibc 或
musl。并注意它在
man ptrace
在 NOTES
部分下:
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. 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.
在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;
}