Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2002-10-09 08:08:05 +0400
committerChristopher Faylor <me@cgf.cx>2002-10-09 08:08:05 +0400
commit7da53596cf1385616721180b48b2159802045d1c (patch)
tree7c7c049a2429b3d778f4d8f33ede670f44fb7d58 /winsup/cygwin/cygheap.cc
parentce6ac4003f2155c0f76d086673aa12193661e1c3 (diff)
* cygheap.cc (dup_now): Make fatal error a little more informative.
(cygheap_setup_for_child): Detect when default size of shared region is less than the current size and allocate that much. (_cbrk): Just return NULL on inability to allocate. (_cmalloc): Ditto. * cygheap.h (CYGHEAPSIZE): Change size to reflect newer, tinier fhandler sizes. * spawn.cc (av::error): New element, reflects potential errno from cmalloc. (av::~av): Don't free NULL pointers. (av::replace0_maybe): Detect out-of-memory conditions. (av::dup_maybe): Ditto. (av::dup_all): Ditto. (av::unshift): Ditto. (spawn_guts): Set errno and return if argv creation ran into problems. * fhandler.h (fhandler_union): Change member names to something safer. * fhandler_console.cc (fhandler_console::get_tty_stuff): Always set fhandler_console::dev_state regardless of whether shared region is initialized. * cygthread.cc (cygthread::runner): Use ExitThread rather than return (planning for future).
Diffstat (limited to 'winsup/cygwin/cygheap.cc')
-rw-r--r--winsup/cygwin/cygheap.cc25
1 files changed, 21 insertions, 4 deletions
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc
index 60eafcd44..d3d1bd610 100644
--- a/winsup/cygwin/cygheap.cc
+++ b/winsup/cygwin/cygheap.cc
@@ -63,12 +63,13 @@ init_cheap ()
cygheap_max = cygheap;
}
-static void dup_now (void *, child_info *, unsigned) __attribute__ ((regparm(3)));
+// static void dup_now (void *, child_info *, unsigned) __attribute__ ((regparm(3)));
static void
dup_now (void *newcygheap, child_info *ci, unsigned n)
{
if (!VirtualAlloc (newcygheap, n, MEM_COMMIT, PAGE_READWRITE))
- api_fatal ("couldn't allocate new cygwin heap for child, %E");
+ api_fatal ("couldn't allocate new cygwin heap %p, %d for child, %E",
+ newcygheap, n);
memcpy (newcygheap, cygheap, n);
}
@@ -77,9 +78,15 @@ cygheap_setup_for_child (child_info *ci, bool dup_later)
{
void *newcygheap;
cygheap_protect->acquire ();
+if (!ci) try_to_debug ();
unsigned n = (char *) cygheap_max - (char *) cygheap;
+ unsigned size = CYGHEAPSIZE;
+ if (size < n)
+ size = n + (128 * 1024);
ci->cygheap_h = CreateFileMapping (INVALID_HANDLE_VALUE, &sec_none,
- CFMAP_OPTIONS, 0, CYGHEAPSIZE, NULL);
+ CFMAP_OPTIONS, 0, size, NULL);
+ if (!ci->cygheap_h)
+ api_fatal ("Couldn't create heap for child, size %d, %E", CYGHEAPSIZE);
newcygheap = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL);
ProtectHandle1INH (ci->cygheap_h, passed_cygheap_h);
if (!dup_later)
@@ -177,7 +184,12 @@ _csbrk (int 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");
+ {
+ malloc_printf ("couldn't commit memory for cygwin heap, %E");
+ __seterrno ();
+ (char *) cygheap_max -= sbs;
+ return NULL;
+ }
return prebrk;
}
@@ -222,6 +234,11 @@ _cmalloc (int size)
{
size = sz + sizeof (_cmalloc_entry);
rvc = (_cmalloc_entry *) _csbrk (size);
+ if (!rvc)
+ {
+ cygheap_protect->release ();
+ return NULL;
+ }
rvc->b = b;
rvc->prev = cygheap->chain;