From patchwork Thu Aug 1 10:13:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Fedotov X-Patchwork-Id: 170367 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp5213906ile; Thu, 1 Aug 2019 03:14:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzTd1KRMRyqz/t/1+HAQ6yMmt5kVlegWuiJ54llesdws1FmV6vApvduS+q84Tcr/DIk/u5D X-Received: by 2002:a17:90a:374a:: with SMTP id u68mr7772910pjb.4.1564654454057; Thu, 01 Aug 2019 03:14:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564654454; cv=none; d=google.com; s=arc-20160816; b=GJLPErK+N5Hiv0OCZ+BoMQl74YF15BBUV9kQm0fpy4/vYjWQc66760A/2uXDV0AO5F DCw48Q6vqDk9SLi4xDpdosozBSeU+OHaXXczz/Jh9ijosU01T+gZrlau6boLxNiEjXj/ nZTsRiOgm+ievcATAm0B0uawi23jrUO2cQzffGGIp7ozrchGxkjkb8uQujG4XBb/v18P 1WqKAJGh5FC8D4Rrg+r8Q9WgKV7zq650xEsi3IX3H0RczlpP6xDMvVpFVpC6bSd2WRQR YlrfBW7vn4jkED3YdiAKTGmdxRfrhPxklpLns25exr1X9ZYZYamAqwt8r954wsdP2VAo 5hWg== 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=WQWSz+VZ0TRVn4xK5UIuderZYlwmT7d85FvRdA2eCLA=; b=XRv+n0xiLtJ4JgME9MV4xIkXhWnfrNQWm4EgM8El0Bc/CA8B20bJ4QjF+IDPe4EdSJ 1l+SPva3C0NX1kJKMO5D7/Dk3/b1DAck+N3N7F8MNQLDyeKj9fAkJ+m73XJP9OFIJlGz lTW66ceor6Wi4SDqDW0L8F1E7BnuDB09/kxmzoqQOWnBf4b9hagjU25gZTqUflEpZU4o 4WOPeDDVKLytgHbsVinUX76oJiIcJCjHwggrUT+MIHXbkhoPQqvcx8pd0RMGyq6il+3K P7MDQUzYFnOetfzeAtakUdrfZupt6LPPO2WTR3H/ZlwbtVW5LcDdcJo6ShsZ4IXT2X+j yvMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=XuCGKsm5; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gZsh9q7S; spf=pass (google.com: domain of newlib-return-17109-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="newlib-return-17109-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 q85si34578999pfc.85.2019.08.01.03.14.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Aug 2019 03:14:14 -0700 (PDT) Received-SPF: pass (google.com: domain of newlib-return-17109-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=XuCGKsm5; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gZsh9q7S; spf=pass (google.com: domain of newlib-return-17109-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="newlib-return-17109-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=br0MLQX5b2iIuuG8W2YHi1S4ODnR3MW BT2cykj1tNHim5UAK/+iVbta74n00JLbeC6qUJZmbMlGW5Pe4DN8nCeP+JVzORMX Zb8e4tuZhoPHB1tqr+8cFMR4M8bQBvzdpffxqCxFlPSSYRofbop3gaHtnWn5CBaW 4drheicCWjL8= 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=Feaga8j2MKSOlTqi0FlhDUFvT/4=; b=XuCGK sm5YmVDeBc2eVojB/YVg8JAeiP9wNWJg7q4nDu9GT3IKgvkj/9xWV+TBTvxuqPlF Eo7sS5T5DpC6mumP5K/zB6wtxati7kkbj9a3+zSeU7yeyBPfNk9IGIFWz9gioGN5 aKXQBKyj7o+zRRdyGmrB0fAnSM5LYc61otnU7k= Received: (qmail 94745 invoked by alias); 1 Aug 2019 10:13:50 -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 94671 invoked by uid 89); 1 Aug 2019 10:13:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 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=H*MI:sk:2019080, H*i:sk:2019080 X-HELO: mail-lf1-f68.google.com Received: from mail-lf1-f68.google.com (HELO mail-lf1-f68.google.com) (209.85.167.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 01 Aug 2019 10:13:48 +0000 Received: by mail-lf1-f68.google.com with SMTP id s19so49815266lfb.9 for ; Thu, 01 Aug 2019 03:13:47 -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=WQWSz+VZ0TRVn4xK5UIuderZYlwmT7d85FvRdA2eCLA=; b=gZsh9q7SuPfKt0/V03GA8CXvFCJjGjuDuL+A28fy6eOANNmcg+9N1sOa93pWWfT6/j u/KOgAVECv9zFcmWPAFcJFD98l+KOfvRl5lIfmYYBP/LRO5T8zUMbT1HJxrTHctm8rVw /Vp1vMQJ93iEwlyLHR8Cz+OKQpANhYQPR//WszzCxoXYKoeO9QCbuKU1YBeF0pqYTqzp yxRVlGC2YmqlgrLsnMqROEXAxb55Xfkldiak6WytbBk87cDnb4bX7H39/4klEuQ18nPk shLQ74hYS9Azy2e5Z4cfC/DSeGvu2QTntW4vXpIhv+Od6zU9hrl4SN5YFS/xXd33M+IK hyQw== Return-Path: Received: from af-ubuntu18-hyperv.cmtknet.ru (relay.cmtk.ru. [195.5.145.226]) by smtp.gmail.com with ESMTPSA id n1sm12221136lfk.19.2019.08.01.03.13.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 03:13:45 -0700 (PDT) From: Alexander Fedotov To: newlib@sourceware.org, Richard.Earnshaw@arm.com Cc: Alexander Fedotov Subject: [PATCH v1 2/4] Alignment libgloss/arm and newlib/libc/sys/arm: reflect commits 8d98f95, 5c9403e Date: Thu, 1 Aug 2019 05:13:32 -0500 Message-Id: <20190801101334.6213-2-alfedotov@gmail.com> In-Reply-To: <20190801101334.6213-1-alfedotov@gmail.com> References: <20190801101334.6213-1-alfedotov@gmail.com> --- 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. */