Index: compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -7242,6 +7242,21 @@ #define INIT_READLINKAT #endif +#if SANITIZER_INTERCEPT_CCRANDOM_GENERATE_BYTES +INTERCEPTOR(int, CCRandomGenerateBytes, void *bytes, SIZE_T count) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, CCRandomGenerateBytes, bytes, count); + int ret = REAL(CCRandomGenerateBytes)(bytes, count); + if (ret == 0) { + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, bytes, count); + } + return ret; +} +#define INIT_CCRANDOM_GENERATE_BYTES COMMON_INTERCEPT_FUNCTION(CCRandomGenerateBytes); +#else +#define INIT_CCRANDOM_GENERATE_BYTES +#endif + #if SANITIZER_INTERCEPT_NAME_TO_HANDLE_AT INTERCEPTOR(int, name_to_handle_at, int dirfd, const char *pathname, struct file_handle *handle, int *mount_id, int flags) { @@ -10308,6 +10323,7 @@ INIT_GETGROUPMEMBERSHIP; INIT_READLINK; INIT_READLINKAT; + INIT_CCRANDOM_GENERATE_BYTES; INIT_NAME_TO_HANDLE_AT; INIT_OPEN_BY_HANDLE_AT; INIT_STRLCPY; Index: compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -512,6 +512,8 @@ #endif #define SANITIZER_INTERCEPT_READLINKAT \ (SI_POSIX && !SI_MAC_DEPLOYMENT_BELOW_10_10) +#define SANITIZER_INTERCEPT_CCRANDOM_GENERATE_BYTES \ + (SI_MAC && !SI_MAC_DEPLOYMENT_BELOW_10_10) #define SANITIZER_INTERCEPT_DEVNAME (SI_NETBSD || SI_FREEBSD) #define SANITIZER_INTERCEPT_DEVNAME_R (SI_NETBSD || SI_FREEBSD) Index: compiler-rt/test/sanitizer_common/TestCases/Darwin/ccrandomgeneratebytes.c =================================================================== --- /dev/null +++ compiler-rt/test/sanitizer_common/TestCases/Darwin/ccrandomgeneratebytes.c @@ -0,0 +1,21 @@ +// We try to ensure the api interceptor functions properly. +// +// RUN: %clang -O2 %s -o %t && %run %t + +#include +#include +#include + +int main() { + char buf[16]; + int n = !(CCRandomGenerateBytes(buf, sizeof(buf)) == kCCSuccess); + if (n == 0) { + printf("CCRandomGenerateBytes\n"); + for (int i = 0; i