[compiler-rt] [TySan] Intercept malloc_size on Apple platforms. (PR #122133)

Dan Liew via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 8 08:07:42 PST 2025


================
@@ -108,6 +108,14 @@ INTERCEPTOR(void *, malloc, uptr size) {
   return res;
 }
 
+#if SANITIZER_APPLE
+INTERCEPTOR(uptr, malloc_size, void *ptr) {
+  if (DlsymAlloc::Use())
----------------
delcypher wrote:

A less fragile implementation here would be ask the `DlsymAlloc` allocator if it owns this allocation and if so request the size from it, otherwise call the system `malloc_size`. That way `malloc_size` always reports the right things no matter which allocator actually allocated the memory.

The current implementation means that if `malloc_size` is called **after** TYSan init on an allocation that was allocated during TySan init then we'll call the system `malloc_size` which will fail because the system allocator didn't allocator the memory.

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


More information about the llvm-commits mailing list