This is the mail archive of the mailing list for the newlib project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] [nosys] ARM heap overflow check in libnosys

Original libnosys doesn't check heap overflow. This patch adds an ARM target
specific check there, without breaking other targets.

OK to upstream?

ChangeLog (libgloss):

2014-02-27  Joey Ye  <>
        libnosys/sbrk.c (errno.h): New include.
        (errno): Redefine.
        (STACK_PTR): Define macro for __arm__.
        (_sbrk): Check STACK_PTR.

diff --git a/libgloss/libnosys/sbrk.c b/libgloss/libnosys/sbrk.c
index 86c130a..910db20 100644
--- a/libgloss/libnosys/sbrk.c
+++ b/libgloss/libnosys/sbrk.c
@@ -2,6 +2,16 @@
 #include "config.h"
 #include <_syslist.h>
+#include <errno.h>
+#undef errno
+extern int errno;
+#undef STACK_PTR
+#ifdef __arm__
+/* Register name faking - works in collusion with the linker.  */
+register char *stack_ptr asm ("sp");
+#define STACK_PTR stack_ptr
 void *
 _sbrk (incr)
@@ -15,6 +25,15 @@ _sbrk (incr)
      heap_end = & end;
    prev_heap_end = heap_end;
+#ifdef STACK_PTR
+  if (heap_end + incr > STACK_PTR)
+    {
+      errno = ENOMEM;
+      return (void *) -1;
+    }
    heap_end += incr;
    return (void *) prev_heap_end;

Attachment: nosys_sbrk_overflow-0227.patch
Description: Binary data

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]