Valarauca Valarauca - 2 months ago 14
C Question

PTRACE_SYSEMU, and PTRACE_SYSEMU_SINGLESTEP not defined on x64 or x86?

My code is as follows:

#include <sys/ptrace.h>
#include <stdio.h>

int
main()
{
printf("PTRACE_CONT: %d\n", PTRACE_CONT);
printf("PTRACE_SYSCALL: %d\n", PTRACE_SYSCALL);
printf("PTRACE_SINGLESTEP: %d\n", PTRACE_SINGLESTEP);
printf("PTRACE_SYSEMU: %d\n", PTRACE_SYSEMU);
printf("PTRACE_SYSEMU_SINGLESTEP: %d\n", PTRACE_SYSEMU_SINGLESTEP);
printf("PTRACE_LISTEN: %d\n", PTRACE_LISTEN);
return 0;
}


I'm compiling with the default flags on Ubuntu16.04 (Linux x86_64 4.40-38), with gcc v5.4.0.

This throws an error that
PTRACE_SYSEMU
is undeclared. While the
man ptrace
page states it exists. This is repeated for
PTRACE_SYSEMU_SINGLESTEP
if the line containing
PTRACE_SYSEMU
is commented out. Which the man page states
PTRACE_SYSEMU_SINGLESTEP
is only available for x86, except a patch was merged to unify the x86 and x64 handling of
PTRACE_SYSEMU_SINGLESTEP
in 2008.

This produces the same error on 32bit (well i686), or 64bit (AMD64). Is this distro specific? What is going on?

I can confirm neither of these values are defined are in my
/usr/include/x86_64/linux/sys/ptrace.h
. But they are defined in kernel sources?!?

Answer

On Ubuntu 16.04 (and also 14.04), these are defined in <asm/ptrace-abi.h>, which is included by <asm/ptrace.h>, which in turn is included by <linux/ptrace.h>, but not by <sys/ptrace.h>

Since these request codes are linux specific (not part of any standard), if you want them, you need to #include <linux/ptrace.h>