From 82ab9b4bd6a35b9ebb58815d3f4a4c3dc82f3978 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 27 Jul 2019 22:34:47 +0100 Subject: [PATCH 1/3] tracking anonymous page lifetime on macOS. this platform allows to tag them per application up to 255. --- src/os.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/os.c b/src/os.c index 4279bf8d..6593906f 100644 --- a/src/os.c +++ b/src/os.c @@ -248,6 +248,7 @@ static void* mi_unix_mmap(size_t size, size_t try_alignment, int protect_flags) #define MAP_ANONYMOUS MAP_ANON #endif int flags = MAP_PRIVATE | MAP_ANONYMOUS; + int gfd = -1; #if defined(MAP_ALIGNED) // BSD if (try_alignment > 0) { size_t n = _mi_bsr(try_alignment); @@ -259,6 +260,12 @@ static void* mi_unix_mmap(size_t size, size_t try_alignment, int protect_flags) #if defined(PROT_MAX) protect_flags |= PROT_MAX(PROT_READ | PROT_WRITE); // BSD #endif + #if defined(VM_MAKE_TAG) + // tracking anonymous page with a specific ID + // all up to 98 are taken officially but LLVM + // sanitizers had taken 99 + gfd = VM_MAKE_TAG(100); + #endif if (large_os_page_size > 0 && use_large_os_page(size, try_alignment)) { int lflags = flags; int fd = -1; @@ -272,7 +279,7 @@ static void* mi_unix_mmap(size_t size, size_t try_alignment, int protect_flags) lflags |= MAP_HUGE_2MB; #endif #ifdef VM_FLAGS_SUPERPAGE_SIZE_2MB - fd = VM_FLAGS_SUPERPAGE_SIZE_2MB; + fd = VM_FLAGS_SUPERPAGE_SIZE_2MB | gfd; #endif if (lflags != flags) { // try large page allocation @@ -283,7 +290,7 @@ static void* mi_unix_mmap(size_t size, size_t try_alignment, int protect_flags) } } if (p == NULL) { - p = mmap(NULL, size, protect_flags, flags, -1, 0); + p = mmap(NULL, size, protect_flags, flags, gfd, 0); if (p == MAP_FAILED) p = NULL; } return p; From ccc78302bf7afdb25eae811ee64728fffbb725ca Mon Sep 17 00:00:00 2001 From: daan Date: Sat, 10 Aug 2019 09:53:00 -0700 Subject: [PATCH 2/3] fix double assignment (#125, by @ebudai) --- src/page.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/page.c b/src/page.c index 685b6b4a..60b3fc09 100644 --- a/src/page.c +++ b/src/page.c @@ -142,7 +142,7 @@ static void mi_page_thread_free_collect(mi_page_t* page) mi_thread_free_t tfree; mi_thread_free_t tfreex; do { - tfreex = tfree = page->thread_free; + tfree = page->thread_free; head = mi_tf_block(tfree); tfreex = mi_tf_set_block(tfree,NULL); } while (!mi_atomic_compare_exchange((volatile uintptr_t*)&page->thread_free, tfreex, tfree)); From 8ae2492eee3ba35a816c38f85850b414cdce414e Mon Sep 17 00:00:00 2001 From: daan Date: Sat, 10 Aug 2019 10:14:01 -0700 Subject: [PATCH 3/3] fix arguments for the heap visitor function, issue #124 --- src/heap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/heap.c b/src/heap.c index 2b7b7a99..b1c62491 100644 --- a/src/heap.c +++ b/src/heap.c @@ -506,7 +506,7 @@ typedef struct mi_visit_blocks_args_s { static bool mi_heap_area_visitor(const mi_heap_t* heap, const mi_heap_area_ex_t* xarea, void* arg) { mi_visit_blocks_args_t* args = (mi_visit_blocks_args_t*)arg; - if (!args->visitor(heap, &xarea->area, NULL, xarea->area.block_size, arg)) return false; + if (!args->visitor(heap, &xarea->area, NULL, xarea->area.block_size, args->arg)) return false; if (args->visit_blocks) { return mi_heap_area_visit_blocks(xarea, args->visitor, args->arg); }