Valarauca
Valarauca

Reputation: 1141

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?!?

Upvotes: 1

Views: 617

Answers (2)

osgx
osgx

Reputation: 94455

Sysemu is used in user-mode linux as optimization and described at http://sysemu.sourceforge.net/ site. It is feature for UML (when special kernel runs as ordinary process) and not for typical users of ptrace.

Its implementation in x86 linux can be checked by TIF_SYSCALL_EMU flag in lxr of linux kernel (ptrace_resume)

http://lxr.free-electrons.com/source/kernel/ptrace.c?v=4.10#L767

767 static int ptrace_resume(struct task_struct *child, long request,
768                          unsigned long data)
   ...
780 #ifdef TIF_SYSCALL_EMU
781         if (request == PTRACE_SYSEMU || request == PTRACE_SYSEMU_SINGLESTEP)
782                 set_tsk_thread_flag(child, TIF_SYSCALL_EMU);
783         else
784                 clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
785 #endif

http://lxr.free-electrons.com/ident?i=TIF_SYSCALL_EMU

The only definition is for x86:

http://lxr.free-electrons.com/source/arch/x86/include/asm/thread_info.h?v=4.10#L85

 85 #define TIF_SYSCALL_EMU         6       /* syscall emulation active */

Upvotes: 0

Chris Dodd
Chris Dodd

Reputation: 126488

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>

Upvotes: 2

Related Questions