@@ -418,6 +418,59 @@ aligned_alloc(size_t alignment, size_t size) noexcept
418418 return ret;
419419}
420420
421+ // Apache Arrow mimalloc wrapper hooks (apache/arrow#41128). These wrap
422+ // mimalloc allocations that are otherwise opaque to memray because mimalloc
423+ // is statically linked into libarrow and serves allocations out of mmap
424+ // arenas. Tracked under the existing aligned-alloc / realloc / free families.
425+ void *
426+ arrow_mi_malloc_aligned (size_t size, size_t alignment) noexcept
427+ {
428+ assert (MEMRAY_ORIG (arrow_mi_malloc_aligned));
429+
430+ void * ret;
431+ {
432+ tracking_api::RecursionGuard guard;
433+ ret = MEMRAY_ORIG (arrow_mi_malloc_aligned)(size, alignment);
434+ }
435+ if (ret) {
436+ tracking_api::Tracker::trackAllocation (ret, size, hooks::Allocator::ALIGNED_ALLOC );
437+ }
438+ return ret;
439+ }
440+
441+ void *
442+ arrow_mi_realloc_aligned (void * ptr, size_t new_size, size_t alignment) noexcept
443+ {
444+ assert (MEMRAY_ORIG (arrow_mi_realloc_aligned));
445+
446+ void * ret;
447+ {
448+ tracking_api::RecursionGuard guard;
449+ ret = MEMRAY_ORIG (arrow_mi_realloc_aligned)(ptr, new_size, alignment);
450+ }
451+ if (ret) {
452+ if (ptr != nullptr ) {
453+ tracking_api::Tracker::trackDeallocation (ptr, 0 , hooks::Allocator::FREE );
454+ }
455+ tracking_api::Tracker::trackAllocation (ret, new_size, hooks::Allocator::REALLOC );
456+ }
457+ return ret;
458+ }
459+
460+ void
461+ arrow_mi_free (void * ptr) noexcept
462+ {
463+ assert (MEMRAY_ORIG (arrow_mi_free));
464+
465+ if (ptr != nullptr ) {
466+ tracking_api::Tracker::trackDeallocation (ptr, 0 , hooks::Allocator::FREE );
467+ }
468+ {
469+ tracking_api::RecursionGuard guard;
470+ MEMRAY_ORIG (arrow_mi_free)(ptr);
471+ }
472+ }
473+
421474#if defined(__linux__)
422475
423476void *
0 commit comments