diff options
author | Szabolcs Nagy <szabolcs.nagy@arm.com> | 2022-03-01 12:42:26 +0000 |
---|---|---|
committer | Szabolcs Nagy <szabolcs.nagy@arm.com> | 2022-11-22 14:31:25 +0000 |
commit | b4e28743ec4dbec80c2ebc1f596409ddca60322c (patch) | |
tree | 3dfa9644703ad37dc1f83b1dfca40593e5f70144 /elf/dl-minimal-malloc.c | |
parent | 7f6564cd800df24154650d363ff048c5869affa0 (diff) | |
download | glibc-b4e28743ec4dbec80c2ebc1f596409ddca60322c.tar.gz glibc-b4e28743ec4dbec80c2ebc1f596409ddca60322c.tar.xz glibc-b4e28743ec4dbec80c2ebc1f596409ddca60322c.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.
Diffstat (limited to 'elf/dl-minimal-malloc.c')
-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) |