[compiler-rt] [win/asan] Improve SharedReAlloc with HEAP_REALLOC_IN_PLACE_ONLY. (PR #132558)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 20 07:47:32 PDT 2025


================
@@ -322,6 +322,22 @@ void *SharedReAlloc(ReAllocFunction reallocFunc, SizeFunction heapSizeFunc,
       }
     }
 
+    if (dwFlags & HEAP_REALLOC_IN_PLACE_ONLY) {
+      size_t old_usable_size = asan_malloc_usable_size(lpMem, pc, bp);
+      if (dwBytes == old_usable_size) {
+        // Nothing to change, return the current pointer.
+        return lpMem;
+      } else if (dwBytes >= old_usable_size) {
+        // Growing with HEAP_REALLOC_IN_PLACE_ONLY is not supported.
+        return nullptr;
+      } else {
+        // Shrinking with HEAP_REALLOC_IN_PLACE_ONLY is not yet supported.
+        // For now return the current pointer and
+        // leave the allocation size as it is.
+        return lpMem;
+      }
+    }
----------------
bernhardu wrote:

Sorry for the delay, it took me a while to run some tests.
And I found following "real world" location as an example [1] in the Wine tree to fail when always returning nullptr with `HEAP_REALLOC_IN_PLACE_ONLY`.

So in the end it boils down to the question if an application is allowed to rely on at least shrinking to succeed?
What do you think?

[1] https://github.com/wine-mirror/wine/blob/288a40d05c8cddf62d0b12524a90d2d4f5ce114d/dlls/kernelbase/locale.c#L5493-L5517

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


More information about the llvm-commits mailing list