Inline Assembler for wrapper function doesn't work for some reason

后端 未结 2 937
鱼传尺愫
鱼传尺愫 2021-01-25 02:22

I\'m trying to write a wrapper function for read() system call , using asm volatile , but it won\'t work , since the res doesn\'t change its value .

Here\'s the code :

相关标签:
2条回答
  • 2021-01-25 02:45

    Run it under strace to see what's happening for sure, but I think your problem is that you put all the inputs in the output register list rather than the input register list...

    0 讨论(0)
  • 2021-01-25 02:51

    it fails and goes into if (-125 <= res && res < 0)

    Where did you expect it to go?

    I expect the read system call to fail with -EINVAL, as you are not pasing in a valid file descriptor to it.

    Update:

    Where did you get an idea that SYS_read is 5?

    On my system, SYS_read is 3 in 32-bit mode, and 0 in 64-bit mode:

    echo "#include <syscall.h>" | gcc -xc - -dD -E | grep ' __NR_read '
    #define __NR_read 0
    
    echo "#include <syscall.h>" | gcc -xc - -dD -E -m32 | grep ' __NR_read '
    #define __NR_read 3
    

    Assuming you are on 32-bit system, you are invoking SYS_open, which is failing with -EFAULT (-14) because the first parameter to the open system call is supposed to be a filename and 0 (NULL) isn't a valid filename.

    0 讨论(0)
提交回复
热议问题