[compiler-rt] [compiler-rt][asan] _aligned_malloc/_aligned_free interception. (PR #82049)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 8 05:25:28 PST 2024


================
@@ -141,6 +141,24 @@ STATIC_MALLOC_INTERFACE void *_expand_dbg(void *, size_t, int, const char *,
   return nullptr;
 }
 
+// _aligned
+STATIC_MALLOC_INTERFACE void *_aligned_malloc(size_t size, size_t alignment) {
+  size = (size + alignment - 1) & ~(alignment - 1);
+  return __asan_malloc(size);
+}
+
+STATIC_MALLOC_INTERFACE void *_aligned_realloc(void *ptr, size_t size,
+                                            size_t alignment) {
+  size = (size + alignment - 1) & ~(alignment - 1);
+  return __asan_realloc(ptr, size);
+}
----------------
zmodem wrote:

This code doesn't actually guarantee the returned pointer will be aligned though.

I think the way to do this is to dllexport an __asan_aligned_{malloc,realloc} in asan_malloc_win.cpp, and dllimport and call them here -- look at __asan_malloc for an example.

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


More information about the llvm-commits mailing list