public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Earnshaw <rearnsha@sourceware.org>
To: newlib-cvs@sourceware.org
Subject: [newlib-cygwin] Align libgloss/arm and libc/sys/arm sources: HeapInfo and __heap_limit
Date: Mon, 05 Aug 2019 12:02:00 -0000	[thread overview]
Message-ID: <20190805120210.66610.qmail@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=dfffe683038357d106893ef1ba30462b31e7b589

commit dfffe683038357d106893ef1ba30462b31e7b589
Author: Alexander Fedotov <alfedotov@gmail.com>
Date:   Fri Aug 2 07:33:44 2019 -0500

    Align libgloss/arm and libc/sys/arm sources: HeapInfo and __heap_limit
    
    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

Diff:
---
 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(-)

diff --git a/libgloss/arm/syscalls.c b/libgloss/arm/syscalls.c
index dacd1a9..3605e0f 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 40bbc3d..a55aa36 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 b521074..a2997b4 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.  */


                 reply	other threads:[~2019-08-05 12:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190805120210.66610.qmail@sourceware.org \
    --to=rearnsha@sourceware.org \
    --cc=newlib-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).