Skip to content

Commit 9ba6672

Browse files
authored
[sanitizer_common] Intercept timespec_get except for hwasan (llvm#117080)
Intercept timespec_get for all sanitizers except for hwasan
1 parent b89e774 commit 9ba6672

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

compiler-rt/lib/hwasan/hwasan_platform_interceptors.h

+3
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@
209209
#undef SANITIZER_INTERCEPT_TIME
210210
#define SANITIZER_INTERCEPT_TIME 0
211211

212+
#undef SANITIZER_INTERCEPT_TIMESPEC_GET
213+
#define SANITIZER_INTERCEPT_TIMESPEC_GET 0
214+
212215
#undef SANITIZER_INTERCEPT_GLOB
213216
#define SANITIZER_INTERCEPT_GLOB 0
214217

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

+20
Original file line numberDiff line numberDiff line change
@@ -2389,6 +2389,25 @@ INTERCEPTOR(int, setitimer, int which, const void *new_value, void *old_value) {
23892389
#define INIT_GETITIMER
23902390
#endif
23912391

2392+
#if SANITIZER_INTERCEPT_TIMESPEC_GET
2393+
INTERCEPTOR(int, timespec_get, struct __sanitizer_timespec *ts, int base) {
2394+
void *ctx;
2395+
COMMON_INTERCEPTOR_ENTER(ctx, timespec_get, ts, base);
2396+
// We don't yet know if ts is addressable, so we use our own scratch buffer
2397+
struct __sanitizer_timespec ts_local;
2398+
int res = REAL(timespec_get)(&ts_local, base);
2399+
if (res) {
2400+
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ts,
2401+
sizeof(struct __sanitizer_timespec));
2402+
internal_memcpy(ts, &ts_local, sizeof(struct __sanitizer_timespec));
2403+
}
2404+
return res;
2405+
}
2406+
# define INIT_TIMESPEC_GET COMMON_INTERCEPT_FUNCTION(timespec_get);
2407+
#else
2408+
# define INIT_TIMESPEC_GET
2409+
#endif
2410+
23922411
#if SANITIZER_INTERCEPT_GLOB
23932412
static void unpoison_glob_t(void *ctx, __sanitizer_glob_t *pglob) {
23942413
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, pglob, sizeof(*pglob));
@@ -10324,6 +10343,7 @@ static void InitializeCommonInterceptors() {
1032410343
INIT_TIMER_CREATE;
1032510344
INIT_GETITIMER;
1032610345
INIT_TIME;
10346+
INIT_TIMESPEC_GET;
1032710347
INIT_GLOB;
1032810348
INIT_GLOB64;
1032910349
INIT___B64_TO;

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
263263
#define SANITIZER_INTERCEPT_TIMER_CREATE SI_GLIBC
264264
#define SANITIZER_INTERCEPT_GETITIMER SI_POSIX
265265
#define SANITIZER_INTERCEPT_TIME SI_POSIX
266+
#define SANITIZER_INTERCEPT_TIMESPEC_GET SI_LINUX
266267
#define SANITIZER_INTERCEPT_GLOB (SI_GLIBC || SI_SOLARIS)
267268
#define SANITIZER_INTERCEPT_GLOB64 SI_GLIBC
268269
#define SANITIZER_INTERCEPT___B64_TO SI_LINUX_NOT_ANDROID

0 commit comments

Comments
 (0)