Skip to content

Commit be6d493

Browse files
committed
PR Comments: Introduce dlsym allocator
1 parent 01190d9 commit be6d493

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include "rtsan/rtsan_interceptors.h"
1212

13+
#include "interception/interception.h"
14+
#include "sanitizer_common/sanitizer_allocator_dlsym.h"
1315
#include "sanitizer_common/sanitizer_allocator_internal.h"
1416
#include "sanitizer_common/sanitizer_platform.h"
1517
#include "sanitizer_common/sanitizer_platform_interceptors.h"
@@ -40,6 +42,12 @@ using namespace __sanitizer;
4042
using __rtsan::rtsan_init_is_running;
4143
using __rtsan::rtsan_initialized;
4244

45+
namespace {
46+
struct DlsymAlloc : public DlSymAllocator<DlsymAlloc> {
47+
static bool UseImpl() { return !rtsan_initialized; }
48+
};
49+
} // namespace
50+
4351
void ExpectNotRealtime(const char *intercepted_function_name) {
4452
__rtsan::GetContextForThisThread().ExpectNotRealtime(
4553
intercepted_function_name);
@@ -243,16 +251,16 @@ INTERCEPTOR(int, nanosleep, const struct timespec *rqtp,
243251
// Memory
244252

245253
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);
248256

249257
ExpectNotRealtime("calloc");
250258
return REAL(calloc)(num, size);
251259
}
252260

253261
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);
256264

257265
if (ptr != NULL) {
258266
ExpectNotRealtime("free");
@@ -261,16 +269,16 @@ INTERCEPTOR(void, free, void *ptr) {
261269
}
262270

263271
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);
266274

267275
ExpectNotRealtime("malloc");
268276
return REAL(malloc)(size);
269277
}
270278

271279
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);
274282

275283
ExpectNotRealtime("realloc");
276284
return REAL(realloc)(ptr, size);

0 commit comments

Comments
 (0)