Skip to content

Conversation

@bernhardu
Copy link
Contributor

@bernhardu bernhardu commented Oct 16, 2025

That way failed interceptions of these Rtl* functions will report a message with verbosity >= 2.

…ions.

That way failed interceptions of these Rtl* functions
will report a message with verbosity >= 1.
@llvmbot
Copy link
Member

llvmbot commented Oct 16, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: None (bernhardu)

Changes

That way failed interceptions of these Rtl* functions will report a message with verbosity >= 1.


Full diff: https://github.com/llvm/llvm-project/pull/163818.diff

1 Files Affected:

  • (modified) compiler-rt/lib/asan/asan_malloc_win.cpp (+11-12)
diff --git a/compiler-rt/lib/asan/asan_malloc_win.cpp b/compiler-rt/lib/asan/asan_malloc_win.cpp
index ea6f7dfaa08cf..a122834007eab 100644
--- a/compiler-rt/lib/asan/asan_malloc_win.cpp
+++ b/compiler-rt/lib/asan/asan_malloc_win.cpp
@@ -485,10 +485,11 @@ INTERCEPTOR_WINAPI(void*, RtlReAllocateHeap, HANDLE HeapHandle, DWORD Flags,
 
 namespace __asan {
 
-static void TryToOverrideFunction(const char *fname, uptr new_func) {
+static void TryToOverrideFunction(const char *fname, uptr new_func,
+                                  uptr *orig_old_func = 0) {
   // Failure here is not fatal. The CRT may not be present, and different CRT
   // versions use different symbols.
-  if (!__interception::OverrideFunction(fname, new_func))
+  if (!__interception::OverrideFunction(fname, new_func, orig_old_func))
     VPrintf(2, "Failed to override function %s\n", fname);
 }
 
@@ -519,16 +520,14 @@ void ReplaceSystemMalloc() {
     ASAN_INTERCEPT_FUNC(HeapAlloc);
 
     // Undocumented functions must be intercepted by name, not by symbol.
-    __interception::OverrideFunction("RtlSizeHeap", (uptr)WRAP(RtlSizeHeap),
-                                     (uptr *)&REAL(RtlSizeHeap));
-    __interception::OverrideFunction("RtlFreeHeap", (uptr)WRAP(RtlFreeHeap),
-                                     (uptr *)&REAL(RtlFreeHeap));
-    __interception::OverrideFunction("RtlReAllocateHeap",
-                                     (uptr)WRAP(RtlReAllocateHeap),
-                                     (uptr *)&REAL(RtlReAllocateHeap));
-    __interception::OverrideFunction("RtlAllocateHeap",
-                                     (uptr)WRAP(RtlAllocateHeap),
-                                     (uptr *)&REAL(RtlAllocateHeap));
+    TryToOverrideFunction("RtlSizeHeap", (uptr)WRAP(RtlSizeHeap),
+                          (uptr *)&REAL(RtlSizeHeap));
+    TryToOverrideFunction("RtlFreeHeap", (uptr)WRAP(RtlFreeHeap),
+                          (uptr *)&REAL(RtlFreeHeap));
+    TryToOverrideFunction("RtlReAllocateHeap", (uptr)WRAP(RtlReAllocateHeap),
+                          (uptr *)&REAL(RtlReAllocateHeap));
+    TryToOverrideFunction("RtlAllocateHeap", (uptr)WRAP(RtlAllocateHeap),
+                          (uptr *)&REAL(RtlAllocateHeap));
   } else {
 #define INTERCEPT_UCRT_FUNCTION(func)                                  \
   if (!INTERCEPT_FUNCTION_DLLIMPORT(                                   \

@github-actions
Copy link

github-actions bot commented Oct 16, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@thurstond
Copy link
Contributor

That way failed interceptions of these Rtl* functions will report a message with verbosity >= 1.

It looks like it is for verbosity >= 2?

  if (!__interception::OverrideFunction(fname, new_func, orig_old_func))
    VPrintf(2, "Failed to override function %s\n", fname);
}

@thurstond thurstond requested a review from mcgov October 16, 2025 18:14
@thurstond
Copy link
Contributor

thurstond commented Oct 16, 2025

Adding @mcgov as a reviewer since they were the original author of those interceptions

@bernhardu
Copy link
Contributor Author

That way failed interceptions of these Rtl* functions will report a message with verbosity >= 1.

It looks like it is for verbosity >= 2?

Thanks for spotting this, I assume the first comment in the pull request gets used as commit message, so correcting that one is enough?

Also pushed a separate fix for the formatting, as committing will squash them?

@thurstond
Copy link
Contributor

Thanks for spotting this, I assume the first comment in the pull request gets used as commit message, so correcting that one is enough?

Yep!

Also pushed a separate fix for the formatting, as committing will squash them?

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants