From 45337ebe078cf7f8f7dbead31a5ff2445550590a Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Fri, 22 Mar 2019 23:17:26 -0400 Subject: [PATCH] label allocate_pages mappings --- h_malloc.c | 7 +++---- pages.c | 3 ++- pages.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/h_malloc.c b/h_malloc.c index 1fafdd0..7e36e1b 100644 --- a/h_malloc.c +++ b/h_malloc.c @@ -972,7 +972,7 @@ COLD static void init_slow_path(void) { fatal_error("page size mismatch"); } - struct random_state *rng = allocate_pages(sizeof(struct random_state), PAGE_SIZE, true); + struct random_state *rng = allocate_pages(sizeof(struct random_state), PAGE_SIZE, true, "malloc init rng"); if (rng == NULL) { fatal_error("failed to allocate init rng"); } @@ -982,11 +982,10 @@ COLD static void init_slow_path(void) { (get_random_u64_uniform(rng, REAL_CLASS_REGION_SIZE / PAGE_SIZE) + 1) * PAGE_SIZE; struct allocator_state *allocator_state = - allocate_pages(sizeof(struct allocator_state), metadata_guard_size, false); + allocate_pages(sizeof(struct allocator_state), metadata_guard_size, false, "malloc allocator_state"); if (allocator_state == NULL) { fatal_error("failed to reserve allocator state"); } - memory_set_name(allocator_state, sizeof(struct allocator_state), "malloc allocator_state"); if (memory_protect_rw_metadata(allocator_state, offsetof(struct allocator_state, regions_a))) { fatal_error("failed to unprotect allocator state"); } @@ -1076,7 +1075,7 @@ static void *allocate(size_t size) { size_t guard_size = get_guard_size(&ra->rng, size); mutex_unlock(&ra->lock); - void *p = allocate_pages(size, guard_size, true); + void *p = allocate_pages(size, guard_size, true, "malloc large"); if (p == NULL) { return NULL; } diff --git a/pages.c b/pages.c index 93f1d11..4cd6ba8 100644 --- a/pages.c +++ b/pages.c @@ -8,7 +8,7 @@ static uintptr_t alignment_ceiling(uintptr_t s, uintptr_t alignment) { return ((s) + (alignment - 1)) & ((~alignment) + 1); } -void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect) { +void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect, const char *name) { size_t real_size; if (unlikely(__builtin_add_overflow(usable_size, guard_size * 2, &real_size))) { errno = ENOMEM; @@ -18,6 +18,7 @@ void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect) { if (unlikely(real == NULL)) { return NULL; } + memory_set_name(real, real_size, name); void *usable = (char *)real + guard_size; if (unprotect && unlikely(memory_protect_rw(usable, usable_size))) { memory_unmap(real, real_size); diff --git a/pages.h b/pages.h index 672b30f..124afe7 100644 --- a/pages.h +++ b/pages.h @@ -10,7 +10,7 @@ #endif #define PAGE_CEILING(s) (((s) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)) -void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect); +void *allocate_pages(size_t usable_size, size_t guard_size, bool unprotect, const char *name); void deallocate_pages(void *usable, size_t usable_size, size_t guard_size); void *allocate_pages_aligned(size_t usable_size, size_t alignment, size_t guard_size);