From patchwork Wed Jul 31 16:38:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Fedotov X-Patchwork-Id: 170193 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp4245902ile; Wed, 31 Jul 2019 09:38:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAmsyPhajCQxYsMUfWdnaUuu2et7iUuLdKcduc4mTeplhp5i4fmh/s/pEby7ZD2uMpJxdq X-Received: by 2002:a63:9245:: with SMTP id s5mr116861565pgn.123.1564591121953; Wed, 31 Jul 2019 09:38:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564591121; cv=none; d=google.com; s=arc-20160816; b=B2Fefxm1irtEtcTvF6VPrjgvuEmLlAnP/FUs0zzm8/kaVy+dHBphkcB8ZegMFg2Uu4 FMQ6o23bTQDX0A/yCmQ0n/M/zEJfnm1ha6KI+IOIaffKJBcevLjgp8SzpvbOejWVNtbu R81lG/FDNI1p8rJXMGxBX31/UsCtunuBgHRj28Qf1smMpsM4LVOsHvfmz8fXB+xAPPMR f9R6sAxEo25nybb9iQEFH6rDSLsgzBlEjMQ3lMRK6vG4ruMIY5yiV2lfw4cS90ZzQwPF Efup7MkK63zYHpipF39Jq//J8R7GctIoqD6sGK8D+5DUzl/CC6qQAZCJuaZREmqhxTGe jSvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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=gVhaIhZ+tiyRi1VEKhkBOGYh2NIN5yPsXZ6dyyXwwF4aqKjaAahbF/hEzCwdVfv8zZ 0+rQ32FJQLL6nl+0dMMTqoRwuuV3up+SVt+hJd+/7MJym6XpHq2r/IC6nsL8PbbrGcUw wWgJCkQMc2iHQv4TsxVFkB11ZtB2j3zTMGOOc+N8c2O5U6whS07XFx+/tJTloHko6XCs wUCddTnYfZMUmInnKzaICbVEQh66T368cSvnLZxrExIMBDqiiLo/7FgreWai5N8FYZmL JwTKM325BhVRY4W0Tt2oRIloJHUIuwVVB8BYGO9vFFat9jX0CedNI4ovBUOhtRq6hwjn a9MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=xzO2Rn3+; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EEBpnVJn; spf=pass (google.com: domain of newlib-return-17095-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="newlib-return-17095-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 q187si31745687pfb.51.2019.07.31.09.38.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jul 2019 09:38:41 -0700 (PDT) Received-SPF: pass (google.com: domain of newlib-return-17095-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=xzO2Rn3+; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EEBpnVJn; spf=pass (google.com: domain of newlib-return-17095-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="newlib-return-17095-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; q=dns; s= default; b=v4byB1N+xUFAULskltpHeNr3IlGvuiJU2LLnCn3Dr9vFt/UYwJE5i uLYw2Bkiigk0/l8Ye9iVe8w787EAuCAgsQzp0lOJi3wOuHcpeZe7XCWrD9snD6cL nomnMW+NTFUfZHcnVrRobNNwbzZ9drEQISiRYIljVR1NuD7Zw+DJFU= 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; s=default; bh=Feaga8j2MKSOlTqi0FlhDUFvT/4=; b=xzO2Rn3+hZs+IzcH4+JjcTdBWaRZ 2l1SWXtfEBbgnlO1KMJWQ3KEf/xe6ZvMvAEJED8JXn9c8FQECLLXDU9fpuemBmvs MF1UQv4F4kSsUqruQAySdhpDbeKmwpdfu5s6XwHV3kKmk5fILJq58M9h7N+HF0iz Bfcm1a6Lny8RFCI= Received: (qmail 74202 invoked by alias); 31 Jul 2019 16:38:33 -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 73464 invoked by uid 89); 31 Jul 2019 16:38:33 -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=angel, Angel, honour, UD:cygwin.com X-HELO: mail-lf1-f66.google.com Received: from mail-lf1-f66.google.com (HELO mail-lf1-f66.google.com) (209.85.167.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 31 Jul 2019 16:38:32 +0000 Received: by mail-lf1-f66.google.com with SMTP id c9so47861178lfh.4 for ; Wed, 31 Jul 2019 09:38:31 -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; bh=WQWSz+VZ0TRVn4xK5UIuderZYlwmT7d85FvRdA2eCLA=; b=EEBpnVJnhuUe1vnGuAcPmGpI6nWDY1OzqV9XYHurQ18MzJzTINr2C7aaupQelNjrBg c9WLB/5Oc4C3Ljf8N8ejOD/0l/htQaRpmj+TLp4upk9eQp4hSJhNwf15AAJTDPaOn+Rm Ugp8m21gbumCGNHecfDMGRqxNNSThpxTVdBoCpRev8yAcSZPl2igCGd2BoBwiK64oivu +Ryh8kknmFwkNnBuhS9pbbqDjD0UuF/ZcGSBT5me4fUt/LYlew13XDNfZO13kkgSlkjP Dx1vhQQSYB6zIqQsM2L03sXZlK5YT5UDJyq5UN2xepayGhLRzjP9TXOWeZfdVkPYc3R7 xCmA== Return-Path: Received: from af-ubuntu18-hyperv.cmtknet.ru (relay.cmtk.ru. [195.5.145.226]) by smtp.gmail.com with ESMTPSA id q4sm16001413lje.99.2019.07.31.09.38.28 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:38:29 -0700 (PDT) From: Alexander Fedotov To: Richard.Earnshaw@arm.com, newlib@sourceware.org Cc: Alexander Fedotov Subject: [PATCH v1 1/3] Reflect commits: 1. 8d98f95 (https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git; a=commit; h=8d98f956cc398d086794e19051c3380d599022da) 2. 5c9403e (https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git; a=commit; h=5c9403eaf40951f8a4f55ed65f661b485ff44be7) Date: Wed, 31 Jul 2019 11:38:03 -0500 Message-Id: <20190731163805.28834-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. */