summary refs log tree commit diff
path: root/sysdeps/generic/sbrk.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/generic/sbrk.c')
-rw-r--r--sysdeps/generic/sbrk.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/sysdeps/generic/sbrk.c b/sysdeps/generic/sbrk.c
index f63195adb3..d3ea705294 100644
--- a/sysdeps/generic/sbrk.c
+++ b/sysdeps/generic/sbrk.c
@@ -38,8 +38,22 @@ __sbrk (ptrdiff_t increment)
      instances of __brk and __sbrk can share the heap, returning
      interleaved pieces of it.  */
   if (__curbrk == NULL || __libc_multiple_libcs)
-    if (__brk (0) < 0)
-      return (void *) -1;
+    {
+      extern void _end;
+
+      if (__brk (0) < 0)		/* Initialize the break.  */
+	return (void *) -1;
+
+      /* Align break address to page boundary if not happened before.  */
+      if (!__libc_multiple_libcs && __curbrk == &_end)
+	{
+	  size_t pg = __getpagesize ();
+	  ptrdiff_t rest = pg - ((&_end - (void *) 0) & (pg - 1));
+
+	  if (__brk (__curbrk + rest) < 0)
+	    return (void *) -1;
+	}
+    }
 
   if (increment == 0)
     return __curbrk;