diff options
author | Christopher Faylor <me@cgf.cx> | 2004-03-18 19:30:51 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2004-03-18 19:30:51 +0000 |
commit | d8f87fba651a721601fa86d1e4b95d8ea17d9e79 (patch) | |
tree | d137c5e2b58bb055eac6fd31f8703bec9a83f4a1 /winsup | |
parent | 891d1990ab12996b3ae2e0538d78c7b6fd697462 (diff) | |
download | newlib-d8f87fba651a721601fa86d1e4b95d8ea17d9e79.zip newlib-d8f87fba651a721601fa86d1e4b95d8ea17d9e79.tar.gz newlib-d8f87fba651a721601fa86d1e4b95d8ea17d9e79.tar.bz2 |
* child_info.h (CURR_CHILD_INFO_MAGIC): Reset to new value.
(child_info::cygheap_alloc_sz): New field.
* cygheap.cc (init_cheap): Reduce size of cygwin stack until minimal hit when
attempting initial allocation.
(cygheap_setup_for_child): Use alloc_sz to create secondary memory mapped
entry. Store alloc_sz in cygheap_alloc_sz.
(cygheap_fixup_in_child): Use cygheap_alloc_sz to map parent's cygheap.
* cygheap.h (_CYGHEAPSIZE_SLOP): New define.
(CYGHEAPSIZE): Use _CYGHEAPSIZE_SLOP.
Diffstat (limited to 'winsup')
-rw-r--r-- | winsup/cygwin/ChangeLog | 12 | ||||
-rw-r--r-- | winsup/cygwin/child_info.h | 3 | ||||
-rw-r--r-- | winsup/cygwin/cygheap.cc | 23 | ||||
-rw-r--r-- | winsup/cygwin/cygheap.h | 4 |
4 files changed, 33 insertions, 9 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 83c970a..32bdb89 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,15 @@ +2004-03-18 Christopher Faylor <cgf@redhat.com> + + * child_info.h (CURR_CHILD_INFO_MAGIC): Reset to new value. + (child_info::cygheap_alloc_sz): New field. + * cygheap.cc (init_cheap): Reduce size of cygwin stack until minimal + hit when attempting initial allocation. + (cygheap_setup_for_child): Use alloc_sz to create secondary memory + mapped entry. Store alloc_sz in cygheap_alloc_sz. + (cygheap_fixup_in_child): Use cygheap_alloc_sz to map parent's cygheap. + * cygheap.h (_CYGHEAPSIZE_SLOP): New define. + (CYGHEAPSIZE): Use _CYGHEAPSIZE_SLOP. + 2004-03-18 Corinna Vinschen <corinna@vinschen.de> * fhandler_proc.cc (format_proc_meminfo): On NT, try to figure out diff --git a/winsup/cygwin/child_info.h b/winsup/cygwin/child_info.h index 4088477..25591d8 100644 --- a/winsup/cygwin/child_info.h +++ b/winsup/cygwin/child_info.h @@ -29,7 +29,7 @@ enum #define EXEC_MAGIC_SIZE sizeof(child_info) -#define CURR_CHILD_INFO_MAGIC 0x4239088U +#define CURR_CHILD_INFO_MAGIC 0x70172124U /* NOTE: Do not make gratuitous changes to the names or organization of the below class. The layout is checksummed to determine compatibility between @@ -49,6 +49,7 @@ public: HANDLE pppid_handle; init_cygheap *cygheap; void *cygheap_max; + DWORD cygheap_alloc_sz; HANDLE cygheap_h; unsigned fhandler_union_cb; }; diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc index 5da6fa6..b4ecf89 100644 --- a/winsup/cygwin/cygheap.cc +++ b/winsup/cygwin/cygheap.cc @@ -28,6 +28,7 @@ init_cygheap NO_COPY *cygheap; void NO_COPY *cygheap_max; static NO_COPY muto *cygheap_protect; +static NO_COPY DWORD alloc_sz; struct cygheap_entry { @@ -50,13 +51,18 @@ static void __stdcall _cfree (void *ptr) __attribute__((regparm(1))); static void init_cheap () { - cygheap = (init_cygheap *) VirtualAlloc ((void *) &_cygheap_start, CYGHEAPSIZE, MEM_RESERVE, PAGE_NOACCESS); + for (cygheap = NULL, alloc_sz = CYGHEAPSIZE; + !cygheap && alloc_sz > CYGHEAPSIZE_MIN; + alloc_sz -= 2 * (1024 * 1024)) + cygheap = (init_cygheap *) VirtualAlloc ((void *) &_cygheap_start, alloc_sz, + MEM_RESERVE, PAGE_NOACCESS); if (!cygheap) { MEMORY_BASIC_INFORMATION m; if (!VirtualQuery ((LPCVOID) &_cygheap_start, &m, sizeof m)) system_printf ("couldn't get memory info, %E"); - system_printf ("Couldn't reserve space for cygwin's heap, %E"); + system_printf ("Couldn't reserve %d bytes of space for cygwin's heap, %E", + alloc_sz); api_fatal ("AllocationBase %p, BaseAddress %p, RegionSize %p, State %p\n", m.AllocationBase, m.BaseAddress, m.RegionSize, m.State); } @@ -79,13 +85,13 @@ cygheap_setup_for_child (child_info *ci, bool dup_later) void *newcygheap; cygheap_protect->acquire (); unsigned n = (char *) cygheap_max - (char *) cygheap; - unsigned size = CYGHEAPSIZE; + unsigned size = alloc_sz; if (size < n) size = n + (128 * 1024); ci->cygheap_h = CreateFileMapping (INVALID_HANDLE_VALUE, &sec_none, CFMAP_OPTIONS, 0, size, NULL); if (!ci->cygheap_h) - api_fatal ("Couldn't create heap for child, size %d, %E", CYGHEAPSIZE); + api_fatal ("Couldn't create heap for child, size %d, %E", size); newcygheap = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL); ProtectHandle1INH (ci->cygheap_h, passed_cygheap_h); if (!dup_later) @@ -93,6 +99,7 @@ cygheap_setup_for_child (child_info *ci, bool dup_later) cygheap_protect->release (); ci->cygheap = cygheap; ci->cygheap_max = cygheap_max; + ci->cygheap_alloc_sz = size; return newcygheap; } @@ -129,7 +136,8 @@ cygheap_fixup_in_child (bool execed) newaddr = MapViewOfFileEx (child_proc_info->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)) + if (!VirtualAlloc (cygheap, child_proc_info->cygheap_alloc_sz, + MEM_RESERVE, PAGE_NOACCESS)) { MEMORY_BASIC_INFORMATION m; memset (&m, 0, sizeof m); @@ -205,8 +213,9 @@ _csbrk (int sbs) /* nothing to do */; else if (!VirtualAlloc (prebrk, (DWORD) sbs, MEM_COMMIT, PAGE_READWRITE)) { - malloc_printf ("couldn't commit memory for cygwin heap, prebrk %p, size %d, heapsize now %d, max heap size %d, %E", - prebrk, sbs, (char *) cygheap_max - (char *) cygheap, CYGHEAPSIZE); + malloc_printf ("couldn't commit memory for cygwin heap, prebrk %p, size %d, heapsize now %d, max heap size %u, %E", + prebrk, sbs, (char *) cygheap_max - (char *) cygheap, + alloc_sz); __seterrno (); cygheap_max = (char *) cygheap_max - sbs; return NULL; diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h index 518e9dc..864fa97 100644 --- a/winsup/cygwin/cygheap.h +++ b/winsup/cygwin/cygheap.h @@ -272,7 +272,9 @@ struct init_cygheap void close_ctty (); }; -#define CYGHEAPSIZE (sizeof (init_cygheap) + (20000 * sizeof (fhandler_union)) + (32 * 1024 * 1024)) +#define _CYGHEAPSIZE_SLOP (32 * 1024 * 1024) +#define CYGHEAPSIZE (sizeof (init_cygheap) + (20000 * sizeof (fhandler_union)) + _CYGHEAPSIZE_SLOP) +#define CYGHEAPSIZE_MIN (sizeof (init_cygheap) + (10000 * sizeof (fhandler_union))) extern init_cygheap *cygheap; extern void *cygheap_max; |