[compiler-rt] [win/asan] Don't intercept memset etc. in ntdll (PR #120397)

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 18 18:49:12 PST 2024


================
@@ -1281,9 +1280,22 @@ uptr InternalGetProcAddress(void *module, const char *func_name) {
 
 bool OverrideFunction(
     const char *func_name, uptr new_func, uptr *orig_old_func) {
+  static const char *kNtDllIgnore[] = {
+    "memcmp", "memcpy", "memmove", "memset"
+  };
+
   bool hooked = false;
   void **DLLs = InterestingDLLsAvailable();
   for (size_t i = 0; DLLs[i]; ++i) {
+    if (DLLs[i + 1] == nullptr) {
+      // This is the last DLL, i.e. NTDLL. It exports some functions that
+      // we only want to override in the CRT.
+      for (const char *ignored : kNtDllIgnore) {
+        if (strcmp(func_name, ignored) == 0)
+          return hooked;
----------------
rnk wrote:

Nit, let's just `break` or `continue` so the reader doesn't have to think about what `hooked` is, we just hit the shared return codepath.

https://github.com/llvm/llvm-project/pull/120397


More information about the llvm-commits mailing list