From db0005c7d3ad9f27e1acc0610b58dddde095be00 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Tue, 1 Mar 2022 12:42:26 +0000 Subject: [PATCH] cheri: fix __minimal_malloc The linker created _end symbol does not have the right bounds, so don't try to reuse leftover memory at the end of the .data section. --- elf/dl-minimal-malloc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/elf/dl-minimal-malloc.c b/elf/dl-minimal-malloc.c index 7cca54208d0..5f5f5554e5c 100644 --- a/elf/dl-minimal-malloc.c +++ b/elf/dl-minimal-malloc.c @@ -23,6 +23,7 @@ # pragma GCC visibility push(hidden) #endif #include +#include #include #include #include @@ -33,6 +34,7 @@ static void *alloc_ptr, *alloc_end, *alloc_last_block; void * __minimal_malloc (size_t n) { +#ifndef __CHERI_PURE_CAPABILITY__ if (alloc_end == 0) { /* Consume any unused space in the last page of our data segment. */ @@ -42,9 +44,10 @@ __minimal_malloc (size_t n) + GLRO(dl_pagesize) - 1) & ~(GLRO(dl_pagesize) - 1)); } +#endif /* Make sure the allocation pointer is ideally aligned. */ - alloc_ptr = (void *) 0 + (((alloc_ptr - (void *) 0) + MALLOC_ALIGNMENT - 1) + alloc_ptr = (void *)(((uintptr_t)alloc_ptr + (MALLOC_ALIGNMENT - 1)) & ~(MALLOC_ALIGNMENT - 1)); if (alloc_ptr + n >= alloc_end || n >= -(uintptr_t) alloc_ptr) -- 2.47.2