diff --git a/compiler-rt/lib/hwasan/hwasan_platform_interceptors.h b/compiler-rt/lib/hwasan/hwasan_platform_interceptors.h index e8011014c2331..8a653d83dec65 100644 --- a/compiler-rt/lib/hwasan/hwasan_platform_interceptors.h +++ b/compiler-rt/lib/hwasan/hwasan_platform_interceptors.h @@ -209,6 +209,9 @@ #undef SANITIZER_INTERCEPT_TIME #define SANITIZER_INTERCEPT_TIME 0 +#undef SANITIZER_INTERCEPT_TIMESPEC_GET +#define SANITIZER_INTERCEPT_TIMESPEC_GET 0 + #undef SANITIZER_INTERCEPT_GLOB #define SANITIZER_INTERCEPT_GLOB 0 diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc index 99fa737adfaf2..ba3693dbd11f6 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -2389,6 +2389,25 @@ INTERCEPTOR(int, setitimer, int which, const void *new_value, void *old_value) { #define INIT_GETITIMER #endif +#if SANITIZER_INTERCEPT_TIMESPEC_GET +INTERCEPTOR(int, timespec_get, struct __sanitizer_timespec *ts, int base) { + void *ctx; + COMMON_INTERCEPTOR_ENTER(ctx, timespec_get, ts, base); + // We don't yet know if ts is addressable, so we use our own scratch buffer + struct __sanitizer_timespec ts_local; + int res = REAL(timespec_get)(&ts_local, base); + if (res) { + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ts, + sizeof(struct __sanitizer_timespec)); + internal_memcpy(ts, &ts_local, sizeof(struct __sanitizer_timespec)); + } + return res; +} +# define INIT_TIMESPEC_GET COMMON_INTERCEPT_FUNCTION(timespec_get); +#else +# define INIT_TIMESPEC_GET +#endif + #if SANITIZER_INTERCEPT_GLOB static void unpoison_glob_t(void *ctx, __sanitizer_glob_t *pglob) { COMMON_INTERCEPTOR_WRITE_RANGE(ctx, pglob, sizeof(*pglob)); @@ -10324,6 +10343,7 @@ static void InitializeCommonInterceptors() { INIT_TIMER_CREATE; INIT_GETITIMER; INIT_TIME; + INIT_TIMESPEC_GET; INIT_GLOB; INIT_GLOB64; INIT___B64_TO; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index 1f78b1af8e2c6..190cad7cf7c3f 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -263,6 +263,7 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment, #define SANITIZER_INTERCEPT_TIMER_CREATE SI_GLIBC #define SANITIZER_INTERCEPT_GETITIMER SI_POSIX #define SANITIZER_INTERCEPT_TIME SI_POSIX +#define SANITIZER_INTERCEPT_TIMESPEC_GET SI_LINUX #define SANITIZER_INTERCEPT_GLOB (SI_GLIBC || SI_SOLARIS) #define SANITIZER_INTERCEPT_GLOB64 SI_GLIBC #define SANITIZER_INTERCEPT___B64_TO SI_LINUX_NOT_ANDROID