10
10
11
11
#include " rtsan/rtsan_interceptors.h"
12
12
13
+ #include " interception/interception.h"
14
+ #include " sanitizer_common/sanitizer_allocator_dlsym.h"
13
15
#include " sanitizer_common/sanitizer_allocator_internal.h"
14
16
#include " sanitizer_common/sanitizer_platform.h"
15
17
#include " sanitizer_common/sanitizer_platform_interceptors.h"
@@ -40,6 +42,12 @@ using namespace __sanitizer;
40
42
using __rtsan::rtsan_init_is_running;
41
43
using __rtsan::rtsan_initialized;
42
44
45
+ namespace {
46
+ struct DlsymAlloc : public DlSymAllocator <DlsymAlloc> {
47
+ static bool UseImpl () { return !rtsan_initialized; }
48
+ };
49
+ } // namespace
50
+
43
51
void ExpectNotRealtime (const char *intercepted_function_name) {
44
52
__rtsan::GetContextForThisThread ().ExpectNotRealtime (
45
53
intercepted_function_name);
@@ -243,16 +251,16 @@ INTERCEPTOR(int, nanosleep, const struct timespec *rqtp,
243
251
// Memory
244
252
245
253
INTERCEPTOR (void *, calloc, SIZE_T num, SIZE_T size) {
246
- if (rtsan_init_is_running && REAL (calloc) == nullptr )
247
- return __sanitizer::InternalCalloc (num, size);
254
+ if (DlsymAlloc::Use () )
255
+ return DlsymAlloc::Callocate (num, size);
248
256
249
257
ExpectNotRealtime (" calloc" );
250
258
return REAL (calloc)(num, size);
251
259
}
252
260
253
261
INTERCEPTOR (void , free, void *ptr) {
254
- if (__sanitizer::internal_allocator ()-> PointerIsMine (ptr))
255
- return __sanitizer::InternalFree (ptr);
262
+ if (DlsymAlloc:: PointerIsMine (ptr))
263
+ return DlsymAlloc::Free (ptr);
256
264
257
265
if (ptr != NULL ) {
258
266
ExpectNotRealtime (" free" );
@@ -261,16 +269,16 @@ INTERCEPTOR(void, free, void *ptr) {
261
269
}
262
270
263
271
INTERCEPTOR (void *, malloc, SIZE_T size) {
264
- if (rtsan_init_is_running && REAL (malloc) == nullptr )
265
- return __sanitizer::InternalAlloc (size);
272
+ if (DlsymAlloc::Use () )
273
+ return DlsymAlloc::Allocate (size);
266
274
267
275
ExpectNotRealtime (" malloc" );
268
276
return REAL (malloc)(size);
269
277
}
270
278
271
279
INTERCEPTOR (void *, realloc, void *ptr, SIZE_T size) {
272
- if (rtsan_init_is_running && REAL (realloc) == nullptr )
273
- return __sanitizer::InternalRealloc (ptr, size);
280
+ if (DlsymAlloc::Use () || DlsymAlloc::PointerIsMine (ptr) )
281
+ return DlsymAlloc::Realloc (ptr, size);
274
282
275
283
ExpectNotRealtime (" realloc" );
276
284
return REAL (realloc)(ptr, size);
0 commit comments