This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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]

Re: [PATCH, HURD]: Fix sbrk beyond 128MB


Samuel Thibault, le Mon 14 Sep 2009 10:51:42 +0200, a écrit :
> Samuel Thibault, le Mon 14 Sep 2009 01:04:59 +0200, a écrit :
> > The patch below fixes sbrk() calls beyond the initial allocation of
> > 128MB: passing pagebrk makes the kernel return an error when there is
> > some room (but not enough for the desired increase) between pagebrk and
> > _hurd_data_end where vm is already allocated.
> 
> Here is a fixed version: the last bit of pre-allocated space needs to be
> enabled too.

Yet fixed again version: err was being used uninitialized.

Samuel

2009-09-14  Samuel Thibault  <samuel.thibault@ens-lyon.org>

        * sysdeps/mach/hurd/brk.c (_hurd_set_brk): When more space needs to be
        allocated, call __vm_protect to finish enabling the existing space, and
        pass a copy of _hurd_data_end instead of pagebrk to __vm_allocate to
        allocate the remainder.

---
 brk.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/sysdeps/mach/hurd/brk.c b/sysdeps/mach/hurd/brk.c
index 931b260..4a135d3 100644
--- a/sysdeps/mach/hurd/brk.c
+++ b/sysdeps/mach/hurd/brk.c
@@ -64,7 +64,7 @@ weak_alias (__brk, brk)
 int
 _hurd_set_brk (vm_address_t addr)
 {
-  error_t err;
+  error_t err = 0;
   vm_address_t pagend = round_page (addr);
   vm_address_t pagebrk = round_page (_hurd_brk);
   long int rlimit;
@@ -101,8 +101,22 @@ _hurd_set_brk (vm_address_t addr)
 
   if (pagend > _hurd_data_end)
     {
+      vm_address_t alloc_start = _hurd_data_end;
+
       /* We didn't allocate enough space!  Hopefully we can get some more!  */
-      err = __vm_allocate (__mach_task_self (), &pagebrk, pagend - pagebrk, 0);
+
+      if (_hurd_data_end > pagebrk)
+	/* First finish allocation */
+	err = __vm_protect (__mach_task_self (), pagebrk,
+			    alloc_start - pagebrk, 0,
+			    VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
+      if (! err)
+	_hurd_brk = alloc_start;
+
+      if (! err)
+	err = __vm_allocate (__mach_task_self (), &alloc_start,
+			     pagend - alloc_start, 0);
+
       if (! err)
 	_hurd_data_end = pagend;
     }


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