From patchwork Fri Aug 2 12:33:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Fedotov X-Patchwork-Id: 170429 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp759245ile; Fri, 2 Aug 2019 05:34:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqzZtYgvhBZk6RAYWNjwaQwMHF9iSY6wGETA3udJwk4VPE/KDRKyG5z5u8+v/jABMljWSirn X-Received: by 2002:a63:10a:: with SMTP id 10mr40403233pgb.281.1564749258932; Fri, 02 Aug 2019 05:34:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564749258; cv=none; d=google.com; s=arc-20160816; b=ExJlb+RnOLVgcf/5UGK0RDx6PDMxrlYv6/pEpZhduG7LYnxLFSGcyvGzzpCKUdkhHB HbKMPmboHAxV85+wwYxtdZScG3hfbyAqfOilbkW2oNzAiy4Z/c3/n1omg8GrTFcbppmr LwY22gFiwtY629mr1dq/p9+G1fyuzYbrfzgzmfoWKmebN/r9Tqn21q/ojG2Ic8uRcWjb NDXIw5Gr7Bs320FY5x0gEuegSDzzcm7qH9rd+g/RQBqbAysg5OVAB1w7EAysbSfbp6i2 msD/4CsKSphKHnzVk7G9OVQRPDssbPO3g7ez0adJ4UFR7HrhG/huMwqmufHXLRgXzxry FnEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=IL9CudBbhiDKUhDyvXAavj2G4Ul/zmv2Xv3miSuT/d0=; b=cc9pMb2J1y1lRrOPXNgmlQZwWrywTwX70/FjrENEtcsDOYuyA1oHVODkTpqXLDktXd UNXei72mB7ajfcjNgxH5VasuezOEogeJZxo7D4zefIWn/ZCln5KCfjjCvtOl5YGQiXu/ vKYQfMGhWpHOKn0Ca6/dpciZe5I81cDHihiLq+5Iwt7OPxowMwZwBt6RihgRFw9osA3j LS7vhvQWGaLAwWti2N+j0qrwQ4YSwtdwdeF7Zl2caAWERgjW7q65O7aJcGydJ2LHZKAI iMpsaC9DSB5p6gC8vZ7KR0/wt4DH9LIIvltcG8cKyTw9hRX6R1JEkmMhJJWI657/18S+ yZeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=CZ92zIr1; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tEFcvuxL; spf=pass (google.com: domain of newlib-return-17120-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="newlib-return-17120-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 188si39937095pgd.404.2019.08.02.05.34.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Aug 2019 05:34:18 -0700 (PDT) Received-SPF: pass (google.com: domain of newlib-return-17120-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=CZ92zIr1; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tEFcvuxL; spf=pass (google.com: domain of newlib-return-17120-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="newlib-return-17120-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=y00lFCg6OQpUNiUSkdjMgnvqdSCdDa1 VN81r3ZhFVhuwb8Pk56dhlizTHr5hfreawH5KLKP5cMIjkymQzqFCCrnvyEkRZu9 Wak3rDqsSD2egrGipv9sS7HXdSstD+e3l9YzoUPZ3TkmyBGMJ5a573SmM8CmDKJr DRQCxGH64LZI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=SoVp94H44DLdZS2452WOYNjEkpU=; b=CZ92z Ir1/ZzfERsz8qs/nLE4aHmpPHBsGOuWE9k2ZO7PP7i+QxlAo9TXcRBXRck7NKUVL jev7yl2bQE34PAm820M49sOZcI+3jBMEfx7vvmgto481ngyDDkLaIfxwr+QsISJE 9KnIeYDkPbpHNXy950fFEgk07E7WFTKwB2Gh6k= Received: (qmail 47622 invoked by alias); 2 Aug 2019 12:33:56 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Delivered-To: mailing list newlib@sourceware.org Received: (qmail 47525 invoked by uid 89); 2 Aug 2019 12:33:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-lj1-f193.google.com Received: from mail-lj1-f193.google.com (HELO mail-lj1-f193.google.com) (209.85.208.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Aug 2019 12:33:54 +0000 Received: by mail-lj1-f193.google.com with SMTP id v24so72823319ljg.13 for ; Fri, 02 Aug 2019 05:33:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IL9CudBbhiDKUhDyvXAavj2G4Ul/zmv2Xv3miSuT/d0=; b=tEFcvuxLryTAVCFl+wtVZx682oNKKp+7LsaCS0byJA9fobUY0GykWjbz5TT9VZ3pgc +FAgcBVdPMHt/wRoLi5fJCxi65OHQX3eAFI29fJlhGvMwdEQX1ofKLqAL//e2Wfsmsc+ sFZMjpHvTpvhH2+g0a2sAFF1tVmx3dT3FnWkpCiywU2Eoda6QeuOPTluZ0l0A6KgPG+7 7oHcBufjkmq3O5Q2SMpkSJvmGaiKZ1p4ni74i+BO14WbSSesJu+tlgaLSlPVCE275gEi FcwcIpSZryHxxQ/m4L4Na+nyCKr2BToui1Wwd0sPtvFJvM65zmActsF4AQQTLjgeceUB AUpw== Return-Path: Received: from af-ubuntu18-hyperv.cmtknet.ru (relay.cmtk.ru. [195.5.145.226]) by smtp.gmail.com with ESMTPSA id u9sm12914135lfk.64.2019.08.02.05.33.51 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 02 Aug 2019 05:33:51 -0700 (PDT) From: Alexander Fedotov To: newlib@sourceware.org Cc: Alexander Fedotov Subject: [PATCH v2 2/4] Align libgloss/arm and libc/sys/arm sources: HeapInfo and __heap_limit Date: Fri, 2 Aug 2019 07:33:44 -0500 Message-Id: <20190802123346.5377-3-alfedotov@gmail.com> In-Reply-To: <20190802123346.5377-1-alfedotov@gmail.com> References: <20190802123346.5377-1-alfedotov@gmail.com> Applied changes from commit 8d98f95: * arm/crt0.S: Initialise __heap_limit when ARM_RDI_MONITOR is defined. * arm/syscalls.c: define __heap_limit global symbol. * arm/syscalls.c (_sbrk): Honour __heap_limit. Applied changes from commit 8d98f95: Fixed semihosting for ARM when heapinfo not provided by debugger --- libgloss/arm/syscalls.c | 12 ++++++------ newlib/libc/sys/arm/crt0.S | 7 +++++++ newlib/libc/sys/arm/syscalls.c | 9 +++++++-- 3 files changed, 20 insertions(+), 8 deletions(-) -- 2.17.1 diff --git a/libgloss/arm/syscalls.c b/libgloss/arm/syscalls.c index dacd1a9d3..3605e0fd0 100644 --- a/libgloss/arm/syscalls.c +++ b/libgloss/arm/syscalls.c @@ -707,15 +707,15 @@ uint __heap_limit = 0xcafedead; void * __attribute__((weak)) _sbrk (ptrdiff_t incr) { - extern char end asm ("end"); /* Defined by the linker. */ + extern char end asm ("end"); /* Defined by the linker. */ static char * heap_end; - char * prev_heap_end; + char * prev_heap_end; if (heap_end == NULL) heap_end = & end; - + prev_heap_end = heap_end; - + if ((heap_end + incr > stack_ptr) /* Honour heap limit if it's valid. */ || (__heap_limit != 0xcafedead && heap_end + incr > (char *)__heap_limit)) @@ -726,14 +726,14 @@ _sbrk (ptrdiff_t incr) extern void abort (void); _write (1, "_sbrk: Heap and stack collision\n", 32); - + abort (); #else errno = ENOMEM; return (void *) -1; #endif } - + heap_end += incr; return (void *) prev_heap_end; diff --git a/newlib/libc/sys/arm/crt0.S b/newlib/libc/sys/arm/crt0.S index 40bbc3d69..a55aa365b 100644 --- a/newlib/libc/sys/arm/crt0.S +++ b/newlib/libc/sys/arm/crt0.S @@ -282,6 +282,13 @@ #endif ldr r0, .LC0 /* Point at values read. */ + /* Set __heap_limit. */ + ldr r1, [r0, #4] + cmp r1, #0 + beq .LC33 + ldr r2, =__heap_limit + str r1, [r2] +.LC33: ldr r1, [r0, #0] cmp r1, #0 bne .LC32 diff --git a/newlib/libc/sys/arm/syscalls.c b/newlib/libc/sys/arm/syscalls.c index b52107491..a2997b44c 100644 --- a/newlib/libc/sys/arm/syscalls.c +++ b/newlib/libc/sys/arm/syscalls.c @@ -487,10 +487,13 @@ _getpid (void) return (pid_t)1; } +/* Heap limit returned from SYS_HEAPINFO Angel semihost call. */ +uint __heap_limit = 0xcafedead; + void * __attribute__((weak)) _sbrk (ptrdiff_t incr) { - extern char end asm ("end"); /* Defined by the linker. */ + extern char end asm ("end"); /* Defined by the linker. */ static char * heap_end; char * prev_heap_end; @@ -499,7 +502,9 @@ _sbrk (ptrdiff_t incr) prev_heap_end = heap_end; - if (heap_end + incr > stack_ptr) + if ((heap_end + incr > stack_ptr) + /* Honour heap limit if it's valid. */ + || (__heap_limit != 0xcafedead && heap_end + incr > (char *)__heap_limit)) { /* Some of the libstdc++-v3 tests rely upon detecting out of memory errors, so do not abort here. */