代码之家  ›  专栏  ›  技术社区  ›  Nishant Kumar

PTrace:linux/user.h:没有这样的文件或目录

  •  14
  • Nishant Kumar  · 技术社区  · 11 年前

    我在英特尔32位机器上使用Ubuntu 12.04和linux-headers-3.2.0-60 PTrace 。但在编译过程中出错。

    #include <sys/ptrace.h>
    #include <sys/types.h>
    #include <sys/wait.h>
    #include <unistd.h>
    #include <linux/user.h>   /* For constants
                                       ORIG_EAX etc */
    int main()
    {   pid_t child;
        long orig_eax;
        child = fork();
        if(child == 0) {
            ptrace(PTRACE_TRACEME, 0, NULL, NULL);
            execl("/bin/ls", "ls", NULL);
        }
        else {
            wait(NULL);
            orig_eax = ptrace(PTRACE_PEEKUSER,
                              child, 4 * ORIG_EAX,
                              NULL);
            printf("The child made a "
                   "system call %ld\n", orig_eax);
            ptrace(PTRACE_CONT, child, NULL, NULL);
        }
        return 0;
    }
    

    我收到以下错误:

    make all 
    Building file: ../src/Test.cpp
    Invoking: Cross G++ Compiler
    g++ -I/usr/local/include/boost -O0 -g3 -Wall -c -fmessage-length=0  -pthread -MMD -MP -MF"src/Test.d" -MT"src/Test.d" -o "src/Test.o" "../src/Test.cpp"
    ../src/Test.cpp:6:51: fatal error: linux/user.h: No such file or directory
    compilation terminated.
    make: *** [src/Test.o] Error 1
    

    我检查了我的 /usr/include/linux 文件夹,但没有名为的文件 user.h 。我试过了 <sys/user.h> 但它给出了另一个错误。

    ../src/Test.cpp:18:38: error: ‘ORIG_EAX’ was not declared in this scope
    

    请帮忙。

    2 回复  |  直到 11 年前
        1
  •  23
  •   sheeru    11 年前

    尝试包括sys/user.h和sys/reg.h ORIG_EAX在reg.h中定义

        2
  •  7
  •   jarvis1729    9 年前

    让我们再深入一点,看看/usr/include/sys/reg.h中的reg.h 我们的代码如下:;对于64位的ORIG_ RAX或ORIG_。我的是64位工作站。

    同样对于64位,代码变化如下,因为它是8字节长的数组

        orig_rax = ptrace(PTRACE_PEEKUSER,
                child, 8 * ORIG_RAX,
                NULL);
    

    结果是 59 对于 execve 系统调用(/usr/include/asm/unistd_64.h)

    The child made a system call 59
    

    /usr/include/sys/reg.h

    #if __WORDSIZE == 64
    /* Index into an array of 8 byte longs returned from ptrace for
        location of the users' stored general purpose registers.  */
    
    # define R15    0
    # define R14    1
    # define R13    2
    # define R12    3
    # define RBP    4
    # define RBX    5
    # define R11    6
    # define R10    7
    # define R9 8
    # define R8 9
    # define RAX    10
    # define RCX    11
    # define RDX    12
    # define RSI    13
    # define RDI    14
    # define ORIG_RAX 15
    # define RIP    16
    # define CS 17
    # define EFLAGS 18
    # define RSP    19
    # define SS 20
    # define FS_BASE 21
    # define GS_BASE 22
    # define DS 23
    # define ES 24
    # define FS 25
    # define GS 26
    #else
    
    /* Index into an array of 4 byte integers returned from ptrace for
     * location of the users' stored general purpose registers. */
    
    # define EBX 0
    # define ECX 1
    # define EDX 2
    # define ESI 3
    # define EDI 4
    # define EBP 5
    # define EAX 6
    # define DS 7
    # define ES 8
    # define FS 9
    # define GS 10
    # define ORIG_EAX 11
    # define EIP 12
    # define CS  13
    # define EFL 14
    # define UESP 15
    # define SS   16
    #endif