From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id 4035B3852C56; Wed, 23 Nov 2022 14:44:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4035B3852C56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669214697; bh=uLcx4WZonfclI8VMl/GqVjpMhRbjSQA7unKOAPIqXek=; h=From:To:Subject:Date:From; b=J1rWzT51FO8WSziqXYVeEII70CVxbAPVjeMRsC42fRcVClrE1hkaPV5UbY3Z0OOQp BbIf0m/fkapGTCCffIUc6tK+CjoJjRVzNUOYNd3Xb4ro6/INPwpLder0M/L/XPpjzH 7sBphGseJaWozJ2FG46VCl6+JWsXI8fFUW/Me6Gg= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Szabolcs Nagy To: glibc-cvs@sourceware.org Subject: [glibc/arm/morello/main] cheri: fix __minimal_malloc X-Act-Checkin: glibc X-Git-Author: Szabolcs Nagy X-Git-Refname: refs/heads/arm/morello/main X-Git-Oldrev: 7f6564cd800df24154650d363ff048c5869affa0 X-Git-Newrev: b4e28743ec4dbec80c2ebc1f596409ddca60322c Message-Id: <20221123144457.4035B3852C56@sourceware.org> Date: Wed, 23 Nov 2022 14:44:57 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b4e28743ec4dbec80c2ebc1f596409ddca60322c commit b4e28743ec4dbec80c2ebc1f596409ddca60322c Author: Szabolcs Nagy Date: Tue Mar 1 12:42:26 2022 +0000 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: --- 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 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 +#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)