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 :
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 " | gcc -xc - -dD -E | grep ' __NR_read '
#define __NR_read 0
echo "#include " | 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.