about summary refs log tree commit diff
path: root/sysdeps/generic
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/generic')
-rw-r--r--sysdeps/generic/dl-sysdep.c25
-rw-r--r--sysdeps/generic/sbrk.c18
2 files changed, 23 insertions, 20 deletions
diff --git a/sysdeps/generic/dl-sysdep.c b/sysdeps/generic/dl-sysdep.c
index 36349a5658..0dfb499d52 100644
--- a/sysdeps/generic/dl-sysdep.c
+++ b/sysdeps/generic/dl-sysdep.c
@@ -31,21 +31,26 @@ Cambridge, MA 02139, USA.  */
 extern int _dl_argc;
 extern char **_dl_argv;
 extern char **_environ;
+extern void _end;
 extern void _start (void);
 
 int __libc_enable_secure;
+int __libc_multiple_libcs;	/* Defining this here avoids the inclusion
+				   of init-first.  */
 
 ElfW(Addr)
 _dl_sysdep_start (void **start_argptr,
 		  void (*dl_main) (const ElfW(Phdr) *phdr, ElfW(Word) phnum,
 				   ElfW(Addr) *user_entry))
 {
-  const ElfW(Phdr) *phdr;
-  ElfW(Word) phnum;
+  const ElfW(Phdr) *phdr = NULL;
+  ElfW(Word) phnum = 0;
   ElfW(Addr) user_entry;
   ElfW(auxv_t) *av;
-  uid_t uid, euid;
-  gid_t gid, egid;
+  uid_t uid = 0;
+  uid_t euid = 0;
+  gid_t gid = 0;
+  gid_t egid = 0;
   unsigned int seen;
 
   user_entry = (ElfW(Addr)) &_start;
@@ -103,6 +108,18 @@ _dl_sysdep_start (void **start_argptr,
   DL_SYSDEP_INIT;
 #endif
 
+  if (__sbrk (0) == &_end)
+    {
+      /* The dynamic linker was run as a program, and so the initial break
+	 starts just after our bss, at &_end.  The malloc in dl-minimal.c
+	 will consume the rest of this page, so tell the kernel to move the
+	 break up that far.  When the user program examines its break, it
+	 will see this new value and not clobber our data.  */
+      size_t pg = __getpagesize ();
+
+      __sbrk (pg - ((&_end - (void *) 0) & (pg - 1)));
+    }
+
   (*dl_main) (phdr, phnum, &user_entry);
   return user_entry;
 }
diff --git a/sysdeps/generic/sbrk.c b/sysdeps/generic/sbrk.c
index d3ea705294..afed5902dc 100644
--- a/sysdeps/generic/sbrk.c
+++ b/sysdeps/generic/sbrk.c
@@ -38,22 +38,8 @@ __sbrk (ptrdiff_t increment)
      instances of __brk and __sbrk can share the heap, returning
      interleaved pieces of it.  */
   if (__curbrk == NULL || __libc_multiple_libcs)
-    {
-      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 (__brk (0) < 0)		/* Initialize the break.  */
+      return (void *) -1;
 
   if (increment == 0)
     return __curbrk;