Files
libfaketime/test/syscall_test.c
Daniel Kahn Gillmor 811283e683 Intercept syscall
This is an attempt at an implementation to address #301.

Some things worth noting:

 - I am not particularly confident in my reverse of the variadic C
   ABI. While the code appears to work for me on x86_64, I could
   imagine some variations between platforms that I'm not
   understanding.

 - This works to intercept the invocation of syscall as seen in
   test/syscalltest.sh, as long as it was compiled with -DFAKE_RANDOM

 - defining -DINTERCEPT_SYSCALL on non-Linux platforms should result
   in a compile-time error.

 - This does *not* work to intercept the syscall sent by `openssl
   rand`, for some reason I don't yet understand.  Perhaps openssl has
   some platform-specific syscall mechanism that doesn't route them
   through libc's syscall() shim?
2021-02-24 14:45:38 -05:00

12 lines
277 B
C

#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
int main() {
int d = 0;
long r = syscall(__NR_getrandom, &d, sizeof(d), 0);
printf("getrandom(%d, <ptr>, %zd, 0) returned %ld and yielded 0x%08x\n",
__NR_getrandom, sizeof(d), r, d);
return 0;
}