@@ -147,6 +147,10 @@ __declspec(noinline) void *_aligned_malloc(size_t size, size_t alignment) {
147147 return asan_aligned_alloc (alignment, size, &stack);
148148}
149149
150+ __declspec (noinline) void *_aligned_malloc_dbg(size_t size, size_t alignment) {
151+ return _aligned_malloc (alignment, size);
152+ }
153+
150154__declspec (noinline) void *_aligned_realloc(void *p, size_t size,
151155 size_t alignment) {
152156 GET_STACK_TRACE_MALLOC;
@@ -160,7 +164,55 @@ __declspec(noinline) void *_aligned_realloc(void *p, size_t size,
160164 return n;
161165}
162166
163- __declspec (noinline) void _aligned_free(void *p) { free (p); }
167+ __declspec (noinline) void *_aligned_realloc_dbg(void *p, size_t size,
168+ size_t alignment) {
169+ return _aligned_realloc (p, size, alignment);
170+ }
171+
172+ __declspec (noinline) void *_aligned_recalloc(void *p, size_t nmemb, size_t size,
173+ size_t alignment) {
174+ const size_t total = nmemb * size;
175+ if (total && total / size != nmemb)
176+ return nullptr ;
177+ void *n = _aligned_realloc (p, total, alignment);
178+ if (n)
179+ REAL (memset)(n, 0 , size);
180+
181+ return n;
182+ }
183+
184+ __declspec (noinline) void *_aligned_recalloc_dbg(void *p, size_t nmemb,
185+ size_t size,
186+ size_t alignment) {
187+ return _aligned_recalloc (p, nmemb, size, alignment);
188+ }
189+
190+ __declspec (noinline) void *_aligned_offset_malloc(size_t size, size_t alignment,
191+ size_t offset) {
192+ const size_t total = offset + size;
193+ if (total && (total - offset) != size)
194+ return nullptr ;
195+ void *p = _aligned_malloc (total, alignment);
196+ if (p)
197+ return ((u8 *)p) + offset;
198+
199+ return nullptr ;
200+ }
201+
202+ __declspec (noinline) void *_aligned_offset_malloc_dbg(size_t size,
203+ size_t alignment,
204+ size_t offset) {
205+ return _aligned_offset_malloc (size, alignment, offset);
206+ }
207+
208+ __declspec (noinline) void _aligned_free(void *p) {
209+ void *b = const_cast <void *>(
210+ __sanitizer_get_allocated_begin (const_cast <void *>(p)));
211+ CHECK (b != nullptr && " invalid pointer" );
212+ free (b);
213+ }
214+
215+ __declspec (noinline) void _aligned_free_dbg(void *p) { _aligned_free (p); }
164216
165217__declspec (noinline) size_t _aligned_msize(void *p) {
166218 GET_CURRENT_PC_BP_SP;
@@ -169,6 +221,10 @@ __declspec(noinline) size_t _aligned_msize(void *p) {
169221 return asan_malloc_usable_size (p, pc, bp);
170222}
171223
224+ __declspec (noinline) size_t _aligned_msize_dbg(void *p) {
225+ return _aligned_msize (p);
226+ }
227+
172228__declspec (noinline) void *_expand(void *memblock, size_t size) {
173229 // _expand is used in realloc-like functions to resize the buffer if possible.
174230 // We don't want memory to stand still while resizing buffers, so return 0.
@@ -531,8 +587,17 @@ void ReplaceSystemMalloc() {
531587 TryToOverrideFunction (" _expand_base" , (uptr)_expand);
532588 TryToOverrideFunction (" _aligned_malloc" , (uptr)_aligned_malloc);
533589 TryToOverrideFunction (" _aligned_realloc" , (uptr)_aligned_realloc);
590+ TryToOverrideFunction (" _aligned_recalloc" , (uptr)_aligned_recalloc);
534591 TryToOverrideFunction (" _aligned_free" , (uptr)_aligned_free);
535592 TryToOverrideFunction (" _aligned_msize" , (uptr)_aligned_msize);
593+ TryToOverrideFunction (" _aligned_malloc_dbg" , (uptr)_aligned_malloc_dbg);
594+ TryToOverrideFunction (" _aligned_realloc_dbg" , (uptr)_aligned_realloc_dbg);
595+ TryToOverrideFunction (" _aligned_recalloc_dbg" , (uptr)_aligned_recalloc_dbg);
596+ TryToOverrideFunction (" _aligned_free_dbg" , (uptr)_aligned_free_dbg);
597+ TryToOverrideFunction (" _aligned_msize_dbg" , (uptr)_aligned_msize_dbg);
598+ TryToOverrideFunction (" _aligned_offset_malloc" , (uptr)_aligned_offset_malloc);
599+ TryToOverrideFunction (" _aligned_offset_malloc_dbg" ,
600+ (uptr)_aligned_offset_malloc_dbg);
536601
537602 if (flags ()->windows_hook_rtl_allocators ) {
538603 ASAN_INTERCEPT_FUNC (HeapSize);
0 commit comments