diff options
author | David Carlier <devnexen@gmail.com> | 2019-10-10 11:31:37 +0000 |
---|---|---|
committer | David Carlier <devnexen@gmail.com> | 2019-10-10 11:31:37 +0000 |
commit | f6e9da08badf010d1be8fc3b24d57c7ad6c8a0cb (patch) | |
tree | a5cbd7a210617a84ea92b305bc83bedb6bacd11a /lib | |
parent | eac233c8a8711e52d3ecd7f63815b384dce71e04 (diff) | |
download | compiler-rt-f6e9da08badf010d1be8fc3b24d57c7ad6c8a0cb.tar.gz |
[Sanitizers] Porting getrandom/getentropy interceptors to FreeBSD
- Available from 12.x branch, by the time it lands next year in FreeBSD tree, the 11.x's might be EOL.
- Intentionally changed the getrandom test to C code as with 12.0 (might be fixed in CURRENT since), there is a linkage issue in C++ context.
Reviewers: emaste, dim, vitalybuka
Reviewed-By: vitalybuka
Differential Revision: https://reviews.llvm.org/D68451
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@374315 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sanitizer_common/sanitizer_common_interceptors.inc | 16 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_platform_interceptors.h | 3 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/sanitizer_common/sanitizer_common_interceptors.inc b/lib/sanitizer_common/sanitizer_common_interceptors.inc index 7cae94559..50e3558b5 100644 --- a/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -9608,6 +9608,21 @@ INTERCEPTOR(char *, crypt_r, char *key, char *salt, void *data) { #define INIT_CRYPT_R #endif +#if SANITIZER_INTERCEPT_GETENTROPY +INTERCEPTOR(int, getentropy, void *buf, SIZE_T buflen) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, getentropy, buf, buflen); + int r = REAL(getentropy)(buf, buflen); + if (r == 0) { + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, buf, buflen); + } + return r; +} +#define INIT_GETENTROPY COMMON_INTERCEPT_FUNCTION(getentropy) +#else +#define INIT_GETENTROPY +#endif + static void InitializeCommonInterceptors() { #if SI_POSIX static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1]; @@ -9908,6 +9923,7 @@ static void InitializeCommonInterceptors() { INIT_GETRANDOM; INIT_CRYPT; INIT_CRYPT_R; + INIT_GETENTROPY; INIT___PRINTF_CHK; } diff --git a/lib/sanitizer_common/sanitizer_platform_interceptors.h b/lib/sanitizer_common/sanitizer_platform_interceptors.h index 54a1699f5..4aeecf120 100644 --- a/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -569,9 +569,10 @@ #define SANITIZER_INTERCEPT_CRYPT (SI_POSIX && !SI_ANDROID) #define SANITIZER_INTERCEPT_CRYPT_R (SI_LINUX && !SI_ANDROID) -#define SANITIZER_INTERCEPT_GETRANDOM (SI_LINUX && __GLIBC_PREREQ(2, 25)) +#define SANITIZER_INTERCEPT_GETRANDOM ((SI_LINUX && __GLIBC_PREREQ(2, 25)) || SI_FREEBSD) #define SANITIZER_INTERCEPT___CXA_ATEXIT SI_NETBSD #define SANITIZER_INTERCEPT_ATEXIT SI_NETBSD #define SANITIZER_INTERCEPT_PTHREAD_ATFORK SI_NETBSD +#define SANITIZER_INTERCEPT_GETENTROPY SI_FREEBSD #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H |