From: Szabolcs Nagy Date: Tue, 1 Mar 2022 12:42:26 +0000 (+0000) Subject: cheri: fix __minimal_malloc X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=110733491ab6faea0583accddec5877678c60052;p=thirdparty%2Fglibc.git 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. --- 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)