From 772f6c3e12a207c923d25fbc04757f01a31fda48 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Wed, 7 Aug 2002 01:20:59 +0000 Subject: * cygheap.cc (_csbrk): Avoid !cygheap considerations. (cygheap_init): Deal with unintialized cygheap issues here. --- winsup/cygwin/cygheap.cc | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'winsup/cygwin/cygheap.cc') diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc index 976618bf7..fb13fbed6 100644 --- a/winsup/cygwin/cygheap.cc +++ b/winsup/cygwin/cygheap.cc @@ -171,25 +171,13 @@ cygheap_fixup_in_child (bool execed) static void *__stdcall _csbrk (int sbs) { - void *prebrk; - - if (!cygheap) - { - init_cheap (); - cygheap_max = cygheap; - (void) _csbrk (sbs + sizeof (*cygheap) + (2 * system_info.dwPageSize)); - prebrk = (char *) (cygheap + 1); - } - 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 +186,12 @@ extern "C" void __stdcall cygheap_init () { new_muto (cygheap_protect); - _csbrk (0); + if (!cygheap) + { + init_cheap (); + cygheap_max = cygheap; + (void) _csbrk (sizeof (*cygheap)); + } if (!cygheap->fdtab) cygheap->fdtab.init (); } -- cgit v1.2.3