diff options
author | Christopher Faylor <me@cgf.cx> | 2001-08-31 05:06:14 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2001-08-31 05:06:14 +0000 |
commit | 5835f2cf8dfb01b93c233bfb5e486482a545aded (patch) | |
tree | 1384eb71caa42c16db5ae0ad966088417bed66fa /winsup/cygwin/cygheap.cc | |
parent | 33bc82476eb92308590d03407cb1597eca8b0079 (diff) | |
download | newlib-5835f2cf8dfb01b93c233bfb5e486482a545aded.zip newlib-5835f2cf8dfb01b93c233bfb5e486482a545aded.tar.gz newlib-5835f2cf8dfb01b93c233bfb5e486482a545aded.tar.bz2 |
* cygwin.sc: New file -- linker script for building cygwin DLL.
* Makefile.in: Use linker script to control location of cygheap.
* cygheap.cc (buckets): Make static.
(init_cheap): Remove special iswinnt handling. Allocate cygheap at a fixed
location. Display more info when allocation fails.
(cygheap_fixup_in_child): Try harder to move cygheap to correct location.
Display more info when allocation fails.
* fhandler.h (fhandler_socket): Add macros for tracking socket shutdown state.
* net.cc (cygwin_shutdown): Set appropriate shutdown value for future use.
* select.cc (select_stuff::cleanup): New method.
(cygwin_select): Call cleanup explicitly to avoid a race.
(select_stuff:~select_stuff): Call cleanup chain via cleanup method.
(fhandler_socket::select_read): Set *_ready when shutdown has been called on
the socket.
(fhandler_socket::select_write): Ditto.
(fhandler_socket::select_except): Ditto.
* winsup.h: Move NO_COPY to "COMMON" section.
* autoload.cc (wsock_started): Avoid initializing NO_COPY value.
* sigproc.cc: Remove initialization from NO_COPY variables.
(sigproc_init): Initialize sig_loop_wait here, rather than via initialization.
(subproc_init): Initialize proc_loop_wait here, rather than via initialization.
Diffstat (limited to 'winsup/cygwin/cygheap.cc')
-rw-r--r-- | winsup/cygwin/cygheap.cc | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc index 39e3082..dc2c72e 100644 --- a/winsup/cygwin/cygheap.cc +++ b/winsup/cygwin/cygheap.cc @@ -36,7 +36,7 @@ struct cygheap_entry }; #define NBUCKETS 32 -char *buckets[NBUCKETS] = {0}; +static char *buckets[NBUCKETS] = {0}; #define N0 ((_cmalloc_entry *) NULL) #define to_cmalloc(s) ((_cmalloc_entry *) (((char *) (s)) - (int) (N0->data))) @@ -46,28 +46,21 @@ char *buckets[NBUCKETS] = {0}; extern "C" { static void __stdcall _cfree (void *ptr) __attribute__((regparm(1))); +extern void *_cygheap_start; } inline static void init_cheap () { - if (!iswinnt) + cygheap = (init_cygheap *) VirtualAlloc ((void *) &_cygheap_start, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS); + if (!cygheap) { - cygheap = (init_cygheap *) VirtualAlloc (NULL, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS); - if (!cygheap) - api_fatal ("Couldn't reserve space for cygwin's heap, %E"); - } - else - { - HANDLE h; - h = CreateFileMapping (INVALID_HANDLE_VALUE, &sec_none, PAGE_READWRITE, - 0, CYGHEAPSIZE, NULL); - if (!h) - api_fatal ("CreateFileMapping failed, %E"); - cygheap = (init_cygheap *) MapViewOfFile (h, FILE_MAP_WRITE, 0, 0, 0); - if (!cygheap) - api_fatal ("Couldn't allocate shared memory for cygwin heap, %E"); - CloseHandle (h); + MEMORY_BASIC_INFORMATION m; + if (!VirtualQuery ((LPCVOID) &_cygheap_start, &m, sizeof m)) + system_printf ("couldn't get memory info, %E"); + small_printf ("AllocationBase %p, BaseAddress %p, RegionSize %p, State %p\n", + m.AllocationBase, m.BaseAddress, m.RegionSize, m.State); + api_fatal ("Couldn't reserve space for cygwin's heap, %E"); } cygheap_max = cygheap + 1; } @@ -106,18 +99,30 @@ cygheap_fixup_in_child (child_info *ci, bool execed) cygheap_max = ci->cygheap_max; void *addr = iswinnt ? cygheap : NULL; void *newaddr; + newaddr = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, addr); - if (!iswinnt || newaddr != addr) + if (newaddr != cygheap) { + if (!newaddr) + newaddr = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL); DWORD n = (DWORD) cygheap_max - (DWORD) cygheap; /* Reserve cygwin heap in same spot as parent */ if (!VirtualAlloc (cygheap, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS)) - api_fatal ("Couldn't reserve space for cygwin's heap (%p <%p>) in child, %E", cygheap, newaddr); + { + MEMORY_BASIC_INFORMATION m; + memset (&m, 0, sizeof m); + if (!VirtualQuery ((LPCVOID) cygheap, &m, sizeof m)) + system_printf ("couldn't get memory info, %E"); + + small_printf ("m.AllocationBase %p, m.BaseAddress %p, m.RegionSize %p, m.State %p\n", + m.AllocationBase, m.BaseAddress, m.RegionSize, m.State); + api_fatal ("Couldn't reserve space for cygwin's heap (%p <%p>) in child, %E", cygheap, newaddr); + } /* Allocate same amount of memory as parent */ if (!VirtualAlloc (cygheap, n, MEM_COMMIT, PAGE_READWRITE)) - api_fatal ("Couldn't allocate space for child's heap %p, size %d, %E", - cygheap, n); + api_fatal ("Couldn't allocate space for child's heap %p, size %d, %E", + cygheap, n); memcpy (cygheap, newaddr, n); UnmapViewOfFile (newaddr); } |