diff options
author | Szabolcs Nagy <szabolcs.nagy@arm.com> | 2022-03-01 12:42:26 +0000 |
---|---|---|
committer | Szabolcs Nagy <szabolcs.nagy@arm.com> | 2022-10-27 14:46:51 +0100 |
commit | db0005c7d3ad9f27e1acc0610b58dddde095be00 (patch) | |
tree | bce6ebde6929066ef348788edf96f0bdc6d97387 | |
parent | d4060ecfa0bb220714199c63be8a692060d6d324 (diff) | |
download | glibc-db0005c7d3ad9f27e1acc0610b58dddde095be00.tar glibc-db0005c7d3ad9f27e1acc0610b58dddde095be00.tar.gz glibc-db0005c7d3ad9f27e1acc0610b58dddde095be00.tar.bz2 glibc-db0005c7d3ad9f27e1acc0610b58dddde095be00.zip |
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.
-rw-r--r-- | elf/dl-minimal-malloc.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/elf/dl-minimal-malloc.c b/elf/dl-minimal-malloc.c index 7cca54208d..5f5f5554e5 100644 --- a/elf/dl-minimal-malloc.c +++ b/elf/dl-minimal-malloc.c @@ -23,6 +23,7 @@ # pragma GCC visibility push(hidden) #endif #include <assert.h> +#include <stdint.h> #include <string.h> #include <ldsodefs.h> #include <malloc/malloc-internal.h> @@ -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) |