Skip to content

Commit 91b49f1

Browse files
committed
[win/asan] Don't intercept memset etc. in ntdll
1 parent 9096879 commit 91b49f1

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

compiler-rt/lib/interception/interception_win.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,8 +1177,7 @@ static void **InterestingDLLsAvailable() {
11771177
"libc++.dll", // libc++
11781178
"libunwind.dll", // libunwind
11791179
# endif
1180-
// NTDLL should go last as it exports some functions that we should
1181-
// override in the CRT [presumably only used internally].
1180+
// NTDLL must go last as it gets special treatment in OverrideFunction.
11821181
"ntdll.dll",
11831182
NULL
11841183
};
@@ -1281,9 +1280,22 @@ uptr InternalGetProcAddress(void *module, const char *func_name) {
12811280

12821281
bool OverrideFunction(
12831282
const char *func_name, uptr new_func, uptr *orig_old_func) {
1283+
static const char *kNtDllIgnore[] = {
1284+
"memcmp", "memcpy", "memmove", "memset"
1285+
};
1286+
12841287
bool hooked = false;
12851288
void **DLLs = InterestingDLLsAvailable();
12861289
for (size_t i = 0; DLLs[i]; ++i) {
1290+
if (DLLs[i + 1] == nullptr) {
1291+
// This is the last DLL, i.e. NTDLL. It exports some functions that
1292+
// we only want to override in the CRT.
1293+
for (const char *ignored : kNtDllIgnore) {
1294+
if (strcmp(func_name, ignored) == 0)
1295+
return hooked;
1296+
}
1297+
}
1298+
12871299
uptr func_addr = InternalGetProcAddress(DLLs[i], func_name);
12881300
if (func_addr &&
12891301
OverrideFunction(func_addr, new_func, orig_old_func)) {

0 commit comments

Comments
 (0)