diff options
Diffstat (limited to 'winsup/cygwin/cygheap.cc')
-rw-r--r-- | winsup/cygwin/cygheap.cc | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc index edd77fcf325..7ea7a39c39e 100644 --- a/winsup/cygwin/cygheap.cc +++ b/winsup/cygwin/cygheap.cc @@ -61,6 +61,7 @@ init_cheap () api_fatal ("AllocationBase %p, BaseAddress %p, RegionSize %p, State %p\n", m.AllocationBase, m.BaseAddress, m.RegionSize, m.State); } + cygheap_max = cygheap; } static void dup_now (void *, child_info *, unsigned) __attribute__ ((regparm(3))); @@ -171,25 +172,13 @@ cygheap_fixup_in_child (bool execed) static void *__stdcall _csbrk (int sbs) { - void *prebrk; - - if (!cygheap) - { - init_cheap (); - cygheap_max = cygheap; - (void) _csbrk ((int) pagetrunc (4095 + sbs + sizeof (*cygheap))); - prebrk = (char *) (cygheap + 1) + sbs; - } - else - { - prebrk = cygheap_max; - void *prebrka = pagetrunc (prebrk); - (char *) cygheap_max += sbs; - if (!sbs || (prebrk != prebrka && prebrka == pagetrunc (cygheap_max))) - /* nothing to do */; - else if (!VirtualAlloc (prebrk, (DWORD) sbs, MEM_COMMIT, PAGE_READWRITE)) - api_fatal ("couldn't commit memory for cygwin heap, %E"); - } + void *prebrk = cygheap_max; + void *prebrka = pagetrunc (prebrk); + (char *) cygheap_max += sbs; + if (!sbs || (prebrk != prebrka && prebrka == pagetrunc (cygheap_max))) + /* nothing to do */; + else if (!VirtualAlloc (prebrk, (DWORD) sbs, MEM_COMMIT, PAGE_READWRITE)) + api_fatal ("couldn't commit memory for cygwin heap, %E"); return prebrk; } @@ -198,7 +187,11 @@ extern "C" void __stdcall cygheap_init () { new_muto (cygheap_protect); - _csbrk (0); + if (!cygheap) + { + init_cheap (); + (void) _csbrk (sizeof (*cygheap)); + } if (!cygheap->fdtab) cygheap->fdtab.init (); } |