Skip to content

Commit 1b688aa

Browse files
committed
Put linux specific code into linux/san_utils.cpp
1 parent 8e84eec commit 1b688aa

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

source/loader/layers/sanitizer/asan_interceptor.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include "asan_interceptor.hpp"
1515
#include "ur_sanitizer_layer.hpp"
1616

17-
#include <dlfcn.h>
18-
1917
namespace ur_sanitizer_layer {
2018

2119
namespace {
@@ -365,20 +363,7 @@ ur_result_t SanitizerInterceptor::enqueueMemSetShadow(
365363

366364
// Poison shadow memory outside of asan runtime is not allowed, so we
367365
// need to avoid memset's call from being intercepted.
368-
static void *memset_ptr = []() {
369-
void *handle = dlopen("libc.so.6", RTLD_LAZY);
370-
if (!handle) {
371-
context.logger.error("dlopen failed: {}", dlerror());
372-
return (void *)nullptr;
373-
}
374-
void *ptr = dlsym(handle, "memset");
375-
if (!ptr) {
376-
context.logger.error("dlsym failed: {}", dlerror());
377-
return (void *)nullptr;
378-
}
379-
return ptr;
380-
}();
381-
366+
static void *memset_ptr = GetMemFunctionPointer("memset");
382367
assert(nullptr != memset_ptr);
383368
((void *(*)(void *, int, size_t))memset_ptr)(
384369
(void *)ShadowBegin, Value, ShadowEnd - ShadowBegin + 1);

source/loader/layers/sanitizer/common.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,6 @@ bool SetupShadowMem();
105105

106106
bool DestroyShadowMem();
107107

108+
void *GetMemFunctionPointer(const char *);
109+
108110
} // namespace ur_sanitizer_layer

source/loader/layers/sanitizer/linux/san_utils.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "common.hpp"
1515
#include <asm/param.h>
16+
#include <dlfcn.h>
1617
#include <sys/mman.h>
1718

1819
extern "C" __attribute__((weak)) void __asan_init(void);
@@ -67,4 +68,16 @@ bool DestroyShadowMem() {
6768
return true;
6869
}
6970

71+
void *GetMemFunctionPointer(const char *FuncName) {
72+
void *handle = dlopen("libc.so.6", RTLD_LAZY);
73+
if (!handle) {
74+
return (void *)nullptr;
75+
}
76+
void *ptr = dlsym(handle, FuncName);
77+
if (!ptr) {
78+
return (void *)nullptr;
79+
}
80+
return ptr;
81+
}
82+
7083
} // namespace ur_sanitizer_layer

0 commit comments

Comments
 (0)