[compiler-rt] r374315 - [Sanitizers] Porting getrandom/getentropy interceptors to FreeBSD
David Carlier via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 10 04:31:37 PDT 2019
Author: devnexen
Date: Thu Oct 10 04:31:37 2019
New Revision: 374315
URL: http://llvm.org/viewvc/llvm-project?rev=374315&view=rev
Log:
[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
Added:
compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getrandom.c
Removed:
compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/getrandom.cpp
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=374315&r1=374314&r2=374315&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Thu Oct 10 04:31:37 2019
@@ -9608,6 +9608,21 @@ INTERCEPTOR(char *, crypt_r, char *key,
#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;
}
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=374315&r1=374314&r2=374315&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Thu Oct 10 04:31:37 2019
@@ -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
Removed: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/getrandom.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/getrandom.cpp?rev=374314&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/getrandom.cpp (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/getrandom.cpp (removed)
@@ -1,22 +0,0 @@
-// RUN: %clangxx -O2 %s -o %t && %run %t
-// UNSUPPORTED: android
-//
-
-#include <sys/types.h>
-
-#if !defined(__GLIBC_PREREQ)
-#define __GLIBC_PREREQ(a, b) 0
-#endif
-
-#if __GLIBC_PREREQ(2, 25)
-#include <sys/random.h>
-#endif
-
-int main() {
- char buf[16];
- ssize_t n = 1;
-#if __GLIBC_PREREQ(2, 25)
- n = getrandom(buf, sizeof(buf), 0);
-#endif
- return (int)(n <= 0);
-}
Added: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getrandom.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getrandom.c?rev=374315&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getrandom.c (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/getrandom.c Thu Oct 10 04:31:37 2019
@@ -0,0 +1,26 @@
+// RUN: %clang -O2 %s -o %t && %run %t
+// UNSUPPORTED: android netbsd darwin solaris
+//
+
+#include <sys/types.h>
+
+#if !defined(__GLIBC_PREREQ)
+#define __GLIBC_PREREQ(a, b) 0
+#endif
+
+#if (defined(__linux__) && __GLIBC_PREREQ(2, 25)) || defined(__FreeBSD__)
+#define HAS_GETRANDOM
+#endif
+
+#if defined(HAS_GETRANDOM)
+#include <sys/random.h>
+#endif
+
+int main() {
+ char buf[16];
+ ssize_t n = 1;
+#if defined(HAS_GETRANDOM)
+ n = getrandom(buf, sizeof(buf), 0);
+#endif
+ return (int)(n <= 0);
+}
More information about the llvm-commits
mailing list