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

David CARLIER via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 16 14:10:32 PST 2024


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

None

>From 0d22af1e2abd0b4a8ca340ee71cbe6fa07b8a689 Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Fri, 16 Feb 2024 22:08:25 +0000
Subject: [PATCH] [compiler-rt][asan] _aligned_malloc/_aligned_free
 interception.

---
 compiler-rt/lib/asan/asan_malloc_win.cpp    | 11 +++++++++++
 compiler-rt/lib/asan/asan_win_dll_thunk.cpp |  2 ++
 2 files changed, 13 insertions(+)

diff --git a/compiler-rt/lib/asan/asan_malloc_win.cpp b/compiler-rt/lib/asan/asan_malloc_win.cpp
index 7e1d04c36dd580..01428a7c582842 100644
--- a/compiler-rt/lib/asan/asan_malloc_win.cpp
+++ b/compiler-rt/lib/asan/asan_malloc_win.cpp
@@ -171,6 +171,17 @@ void *_recalloc_base(void *p, size_t n, size_t elem_size) {
   return _recalloc(p, n, elem_size);
 }
 
+ALLOCATION_FUNCTION_ATTRIBUTE
+void *_aligned_malloc(size_t alignment, size_t size) {
+  GET_STACK_TRACE_MALLOC;
+  return asan_aligned_alloc(alignment, size, &stack);
+}
+
+ALLOCATION_FUNCTION_ATTRIBUTE
+void *_aligned_free(void *p) {
+  free(p);
+}
+
 ALLOCATION_FUNCTION_ATTRIBUTE
 void *_expand(void *memblock, size_t size) {
   // _expand is used in realloc-like functions to resize the buffer if possible.
diff --git a/compiler-rt/lib/asan/asan_win_dll_thunk.cpp b/compiler-rt/lib/asan/asan_win_dll_thunk.cpp
index 0fa636bec0d001..fecf63e53d66e9 100644
--- a/compiler-rt/lib/asan/asan_win_dll_thunk.cpp
+++ b/compiler-rt/lib/asan/asan_win_dll_thunk.cpp
@@ -30,10 +30,12 @@
 INTERCEPT_WRAP_V_W(free)
 INTERCEPT_WRAP_V_W(_free_base)
 INTERCEPT_WRAP_V_WW(_free_dbg)
+INTERCEPT_WRAP_V_W(_aligned_free)
 
 INTERCEPT_WRAP_W_W(malloc)
 INTERCEPT_WRAP_W_W(_malloc_base)
 INTERCEPT_WRAP_W_WWWW(_malloc_dbg)
+INTERCEPT_WRAP_W_WW(_aligned_malloc)
 
 INTERCEPT_WRAP_W_WW(calloc)
 INTERCEPT_WRAP_W_WW(_calloc_base)



More information about the llvm-commits mailing list