summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/cygheap.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2004-03-21 17:41:40 +0000
committerChristopher Faylor <me@cgf.cx>2004-03-21 17:41:40 +0000
commitc795774c91303368f36369f7dac0d18aa25a5996 (patch)
tree8b670b7b945e6106fc46a72d294e20fdf05125c9 /winsup/cygwin/cygheap.cc
parent7f5a71079f098a9b45328fb86b68442774323c1d (diff)
downloadcygnal-c795774c91303368f36369f7dac0d18aa25a5996.tar.gz
cygnal-c795774c91303368f36369f7dac0d18aa25a5996.tar.bz2
cygnal-c795774c91303368f36369f7dac0d18aa25a5996.zip
* cygheap.cc (init_cheap): Add ability to specify minimal cygwin heap size when
debugging. (_csbrk): Report error in allocation to stderr. (ccalloc): Ditto. * dtable.cc (dtable::find_fifo): Remove use of atoms. * dtable.h (dtable::find_fifo): Ditto. * fhandler.h (fhandler_fifo): Ditto. * fhandler_fifo.cc (fhandler_fifo::fhandler_fifo): Ditto. (fhandler_fifo::set_use): Ditto. (fhandler_fifo::open_not_mine): Ditto. (fhandler_fifo::open): Ditto. * pinfo.cc (_pinfo::commune_recv): Ditto. (_pinfo::commune_send): Ditto.
Diffstat (limited to 'winsup/cygwin/cygheap.cc')
-rw-r--r--winsup/cygwin/cygheap.cc34
1 files changed, 27 insertions, 7 deletions
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc
index b4ecf89e7..7e9b14448 100644
--- a/winsup/cygwin/cygheap.cc
+++ b/winsup/cygwin/cygheap.cc
@@ -51,11 +51,27 @@ static void __stdcall _cfree (void *ptr) __attribute__((regparm(1)));
static void
init_cheap ()
{
- 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);
+#ifndef DEBUGGING
+ alloc_sz = CYGHEAPSIZE;
+#else
+ char buf[80];
+ DWORD initial_sz = 0;
+ if (!GetEnvironmentVariable ("CYGWIN_HEAPSIZE", buf, sizeof buf - 1))
+ alloc_sz = CYGHEAPSIZE;
+ else
+ {
+ initial_sz = alloc_sz = atoi (buf);
+ small_printf ("using cygheap size %d\n", alloc_sz);
+ }
+#endif
+ do
+ if ((cygheap = (init_cygheap *) VirtualAlloc ((void *) &_cygheap_start,
+ alloc_sz, MEM_RESERVE,
+ PAGE_NOACCESS)))
+ break;
+ while ((alloc_sz -= 2 * (1024 * 1024)) >= CYGHEAPSIZE_MIN);
+ if (alloc_sz != initial_sz)
+ small_printf ("reset initial cygheap size to %u\n", alloc_sz);
if (!cygheap)
{
MEMORY_BASIC_INFORMATION m;
@@ -213,9 +229,15 @@ _csbrk (int sbs)
/* nothing to do */;
else if (!VirtualAlloc (prebrk, (DWORD) sbs, MEM_COMMIT, PAGE_READWRITE))
{
+#if 1
+ system_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);
+#else
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);
+#endif
__seterrno ();
cygheap_max = (char *) cygheap_max - sbs;
return NULL;
@@ -389,10 +411,8 @@ ccalloc (cygheap_types x, DWORD n, DWORD size)
c = (cygheap_entry *) _cmalloc (sizeof_cygheap (n));
if (c)
memset (c->data, 0, n);
-#ifdef DEBUGGING
if (!c)
system_printf ("ccalloc returned NULL");
-#endif
return creturn (x, c, n);
}