From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id 6CE6F384644E; Wed, 26 Oct 2022 15:16:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6CE6F384644E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666797383; bh=e4B3EITcIUDCzZYOEJJVMqeff4i24itM3Gdz5ZAxqeg=; h=From:To:Subject:Date:From; b=TfFm+3boXvSjooMdAoKTapyDtmi1OLELK1m4AaWDG37fgtiuADRD8IHtRNLFl5Yx6 aDdMEIRG9uQwl6RAigXIWIhtMJStRVASlJBTqLEi9Pk9s3ng5fEHlpisSUla/38EVv 7gVlbSFYoNbHx+R/6D4x/0To8Hf361d7VLqSMe0A= 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: ef4103377aae39b21f41817976ce5c9383b0511a X-Git-Newrev: 0b476d1e176c6632807cfdb1be7fb0041cdbf82b Message-Id: <20221026151623.6CE6F384644E@sourceware.org> Date: Wed, 26 Oct 2022 15:16:23 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=0b476d1e176c6632807cfdb1be7fb0041cdbf82b commit 0b476d1e176c6632807cfdb1be7fb0041cdbf82b 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)