| 1 | /** We have to replace glibc getrandom only when glibc version is higher than 2.25. |
| 2 | * In previous versions of glibc this function doesn't exist |
| 3 | * and old kernels may be missing SYS_getrandom syscall. |
| 4 | */ |
| 5 | #include <features.h> |
| 6 | #if defined(__GLIBC__) && __GLIBC__ >= 2 |
| 7 | # define GLIBC_MINOR __GLIBC_MINOR__ |
| 8 | #elif defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ >= 2 |
| 9 | # define GLIBC_MINOR __GNU_LIBRARY_MINOR__ |
| 10 | #endif |
| 11 | |
| 12 | #if defined(GLIBC_MINOR) && GLIBC_MINOR >= 25 |
| 13 | |
| 14 | #include <unistd.h> |
| 15 | #include <syscall.h> |
| 16 | #include "syscall.h" |
| 17 | |
| 18 | ssize_t getrandom(void *buf, size_t buflen, unsigned flags) |
| 19 | { |
| 20 | /// There was cancellable syscall (syscall_cp), but I don't care too. |
| 21 | return syscall(SYS_getrandom, buf, buflen, flags); |
| 22 | } |
| 23 | #endif |
| 24 | |