【问题标题】:PTrace: linux/user.h: No such file or directoryPTrace: linux/user.h: 没有这样的文件或目录
【发布时间】:2014-04-12 07:09:44
【问题描述】:

我在英特尔 32 位机器上使用带有 linux-headers-3.2.0-60 的 Ubuntu 12.04。我正在尝试构建这个简单的程序来理解 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 的文件。我尝试使用&lt;sys/user.h&gt;,但又出现了另一个错误。

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

请帮忙。

【问题讨论】:

    标签: linux ubuntu-12.04 ptrace


    【解决方案1】:

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

    【讨论】:

    • 即使在包含两者之后我仍然无法获得那个常量 ORIG_EAX .. 但我可以在 sys/reg.h #define ORIG_EAX 11 中看到这一行。你能帮忙吗?
    • 你发现了问题..我的是 64 位所以不得不使用 ORIG_RAX
    • 我也面临 64 位问题,我不得不将所有 EAX,EBX,ECX,EDX 分别替换为 RAX,RBX,RCX,RDX
    【解决方案2】:

    好吧,让我们再进一步看看 /usr/include/sys/reg.h 中的 reg.h 我们有如下代码;对于 64 位,它的 ORIG_RAX 否则为 ORIG_EAX。我的是 64 位工作站。

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

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

    结果将是59 for execve system-call (/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
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-12
    • 2015-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多