mirror of
https://github.com/wolfcw/libfaketime.git
synced 2026-05-17 08:36:28 +03:00
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?
12 lines
277 B
C
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;
|
|
}
|