* 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.
This commit is contained in:
Christopher Faylor 2004-03-21 17:41:40 +00:00
parent 7f5a71079f
commit c795774c91
7 changed files with 75 additions and 54 deletions

View File

@ -1,3 +1,19 @@
2004-03-21 Christopher Faylor <cgf@redhat.com>
* 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.
2004-03-19 Pierre Humblet <pierre.humblet@ieee.org>
* dir.cc (rmdir): Reorganize error handling to reduce indentation.

View File

@ -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);
}

View File

@ -554,13 +554,13 @@ done:
}
fhandler_fifo *
dtable::find_fifo (ATOM hill)
dtable::find_fifo (const char *path)
{
lock ();
for (unsigned i = 0; i < size; i++)
{
fhandler_base *fh = fds[i];
if (fh && fh->isfifo () && ((fhandler_fifo *) fh)->get_atom () == hill)
if (fh && fh->isfifo () && strcmp (path, fh->get_win32_name ()) == 0)
return (fhandler_fifo *) fh;
}
return NULL;

View File

@ -79,7 +79,7 @@ public:
#ifdef NEWVFORK
bool in_vfork_cleanup () {return fds_on_hold == fds;}
#endif
fhandler_fifo *find_fifo (ATOM);
fhandler_fifo *find_fifo (const char *);
fhandler_base *find_archetype (device& dev);
fhandler_base **add_archetype ();
void delete_archetype (fhandler_base *);

View File

@ -481,7 +481,6 @@ class fhandler_fifo: public fhandler_pipe
{
HANDLE output_handle;
HANDLE owner; // You can't have too many mutexes, now, can you?
ATOM upand;
long read_use;
long write_use;
public:
@ -496,7 +495,6 @@ public:
void set_use ();
int dup (fhandler_base *child);
bool is_slow () {return 1;}
ATOM& get_atom () {return upand;}
};
class fhandler_dev_raw: public fhandler_base

View File

@ -23,7 +23,7 @@
#include "pinfo.h"
fhandler_fifo::fhandler_fifo ()
: fhandler_pipe (), output_handle (NULL), owner (NULL), upand (0),
: fhandler_pipe (), output_handle (NULL), owner (NULL),
read_use (0), write_use (0)
{
}
@ -45,11 +45,6 @@ fhandler_fifo::set_use (int incr)
if (incr >= 0)
return;
char buf[24];
__small_sprintf (buf, "%x.%x", upand, myself->pid);
ATOM ant = GlobalFindAtom (buf);
if (!ant)
return;
if (read_use <= 0 && oread_use != read_use)
{
HANDLE h = get_handle ();
@ -58,7 +53,6 @@ fhandler_fifo::set_use (int incr)
set_io_handle (NULL);
CloseHandle (h);
}
DeleteAtom (ant);
}
}
@ -75,7 +69,6 @@ fhandler_fifo::close ()
int
fhandler_fifo::open_not_mine (int flags)
{
char buf[24];
winpids pids;
static int flagtypes[] = {DUMMY_O_RDONLY | O_RDWR, O_WRONLY | O_APPEND | O_RDWR};
HANDLE *usehandles[2] = {&(get_handle ()), &(get_output_handle ())};
@ -84,10 +77,6 @@ fhandler_fifo::open_not_mine (int flags)
for (unsigned i = 0; i < pids.npids; i++)
{
_pinfo *p = pids[i];
__small_sprintf (buf, "%x.%x", upand, p->pid);
if (!GlobalFindAtom (buf))
continue;
HANDLE hp = OpenProcess (PROCESS_DUP_HANDLE, false, p->dwProcessId);
if (!hp)
{
@ -97,7 +86,10 @@ fhandler_fifo::open_not_mine (int flags)
HANDLE handles[2];
commune_result r;
r = p->commune_send (PICOM_FIFO, upand);
r = p->commune_send (PICOM_FIFO, get_win32_name ());
if (r.handles[0] == NULL)
continue; // process doesn't own fifo
flags = (flags & (O_RDWR | O_WRONLY | O_APPEND)) ?: DUMMY_O_RDONLY;
for (int i = 0; i < 2; i++)
{
@ -139,28 +131,10 @@ int
fhandler_fifo::open (int flags, mode_t)
{
int res = 1;
char buf[24];
upand = GlobalAddAtom (pc);
__small_sprintf (buf, "%x.owner", upand);
debug_printf ("mutex %s", buf);
HANDLE h = CreateMutex (&sec_none, false, buf);
if (!h)
goto errnout;
if (GetLastError () == ERROR_ALREADY_EXISTS)
{
CloseHandle (h);
return open_not_mine (flags);
}
fhandler_pipe *fhs[2];
if (create (fhs, 0, flags, true))
{
CloseHandle (h);
goto errout;
}
goto errnout;
set_flags (fhs[0]->get_flags ());
set_io_handle (fhs[0]->get_handle ());
@ -173,13 +147,10 @@ fhandler_fifo::open (int flags, mode_t)
delete (fhs[0]);
delete (fhs[1]);
set_use (1);
__small_sprintf (buf, "%x.%x", upand, myself->pid);
(void) GlobalAddAtom (buf);
goto out;
errnout:
__seterrno ();
errout:
res = 0;
out:

View File

@ -398,16 +398,31 @@ _pinfo::commune_recv ()
}
case PICOM_FIFO:
{
int formic;
if (!ReadFile (__fromthem, &formic, sizeof formic, &nr, NULL)
|| nr != sizeof formic)
char path[CYG_MAX_PATH + 1];
unsigned len;
if (!ReadFile (__fromthem, &len, sizeof len, &nr, NULL)
|| nr != sizeof len)
{
/* __seterrno ();*/ // this is run from the signal thread, so don't set errno
goto out;
}
/* Get null-terminated path */
if (!ReadFile (__fromthem, path, len, &nr, NULL)
|| nr != len)
{
/* __seterrno ();*/ // this is run from the signal thread, so don't set errno
goto out;
}
fhandler_fifo *fh = cygheap->fdtab.find_fifo ((ATOM) formic);
HANDLE it[] = {(fh->get_handle ()), (fh->get_output_handle ())};
fhandler_fifo *fh = cygheap->fdtab.find_fifo (path);
HANDLE it[2];
if (fh == NULL)
it[0] = it[1] = NULL;
else
{
it[0] = fh->get_handle ();
it[1] = fh->get_output_handle ();
}
if (!WriteFile (__tothem, it, sizeof (it), &nr, NULL))
{
@ -474,8 +489,9 @@ _pinfo::commune_send (DWORD code, ...)
{
case PICOM_FIFO:
{
int formic = va_arg (args, int);
if (!WriteFile (tothem, &formic, sizeof formic, &nr, NULL) || nr != sizeof formic)
char *path = va_arg (args, char *);
size_t len = strlen (path) + 1;
if (!WriteFile (tothem, path, len, &nr, NULL) || nr != len)
{
__seterrno ();
goto err;