* 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:
parent
7f5a71079f
commit
c795774c91
|
@ -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>
|
2004-03-19 Pierre Humblet <pierre.humblet@ieee.org>
|
||||||
|
|
||||||
* dir.cc (rmdir): Reorganize error handling to reduce indentation.
|
* dir.cc (rmdir): Reorganize error handling to reduce indentation.
|
||||||
|
|
|
@ -51,11 +51,27 @@ static void __stdcall _cfree (void *ptr) __attribute__((regparm(1)));
|
||||||
static void
|
static void
|
||||||
init_cheap ()
|
init_cheap ()
|
||||||
{
|
{
|
||||||
for (cygheap = NULL, alloc_sz = CYGHEAPSIZE;
|
#ifndef DEBUGGING
|
||||||
!cygheap && alloc_sz > CYGHEAPSIZE_MIN;
|
alloc_sz = CYGHEAPSIZE;
|
||||||
alloc_sz -= 2 * (1024 * 1024))
|
#else
|
||||||
cygheap = (init_cygheap *) VirtualAlloc ((void *) &_cygheap_start, alloc_sz,
|
char buf[80];
|
||||||
MEM_RESERVE, PAGE_NOACCESS);
|
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)
|
if (!cygheap)
|
||||||
{
|
{
|
||||||
MEMORY_BASIC_INFORMATION m;
|
MEMORY_BASIC_INFORMATION m;
|
||||||
|
@ -213,9 +229,15 @@ _csbrk (int sbs)
|
||||||
/* nothing to do */;
|
/* nothing to do */;
|
||||||
else if (!VirtualAlloc (prebrk, (DWORD) sbs, MEM_COMMIT, PAGE_READWRITE))
|
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",
|
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,
|
prebrk, sbs, (char *) cygheap_max - (char *) cygheap,
|
||||||
alloc_sz);
|
alloc_sz);
|
||||||
|
#endif
|
||||||
__seterrno ();
|
__seterrno ();
|
||||||
cygheap_max = (char *) cygheap_max - sbs;
|
cygheap_max = (char *) cygheap_max - sbs;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -389,10 +411,8 @@ ccalloc (cygheap_types x, DWORD n, DWORD size)
|
||||||
c = (cygheap_entry *) _cmalloc (sizeof_cygheap (n));
|
c = (cygheap_entry *) _cmalloc (sizeof_cygheap (n));
|
||||||
if (c)
|
if (c)
|
||||||
memset (c->data, 0, n);
|
memset (c->data, 0, n);
|
||||||
#ifdef DEBUGGING
|
|
||||||
if (!c)
|
if (!c)
|
||||||
system_printf ("ccalloc returned NULL");
|
system_printf ("ccalloc returned NULL");
|
||||||
#endif
|
|
||||||
return creturn (x, c, n);
|
return creturn (x, c, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -554,13 +554,13 @@ done:
|
||||||
}
|
}
|
||||||
|
|
||||||
fhandler_fifo *
|
fhandler_fifo *
|
||||||
dtable::find_fifo (ATOM hill)
|
dtable::find_fifo (const char *path)
|
||||||
{
|
{
|
||||||
lock ();
|
lock ();
|
||||||
for (unsigned i = 0; i < size; i++)
|
for (unsigned i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
fhandler_base *fh = fds[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 (fhandler_fifo *) fh;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -79,7 +79,7 @@ public:
|
||||||
#ifdef NEWVFORK
|
#ifdef NEWVFORK
|
||||||
bool in_vfork_cleanup () {return fds_on_hold == fds;}
|
bool in_vfork_cleanup () {return fds_on_hold == fds;}
|
||||||
#endif
|
#endif
|
||||||
fhandler_fifo *find_fifo (ATOM);
|
fhandler_fifo *find_fifo (const char *);
|
||||||
fhandler_base *find_archetype (device& dev);
|
fhandler_base *find_archetype (device& dev);
|
||||||
fhandler_base **add_archetype ();
|
fhandler_base **add_archetype ();
|
||||||
void delete_archetype (fhandler_base *);
|
void delete_archetype (fhandler_base *);
|
||||||
|
|
|
@ -481,7 +481,6 @@ class fhandler_fifo: public fhandler_pipe
|
||||||
{
|
{
|
||||||
HANDLE output_handle;
|
HANDLE output_handle;
|
||||||
HANDLE owner; // You can't have too many mutexes, now, can you?
|
HANDLE owner; // You can't have too many mutexes, now, can you?
|
||||||
ATOM upand;
|
|
||||||
long read_use;
|
long read_use;
|
||||||
long write_use;
|
long write_use;
|
||||||
public:
|
public:
|
||||||
|
@ -496,7 +495,6 @@ public:
|
||||||
void set_use ();
|
void set_use ();
|
||||||
int dup (fhandler_base *child);
|
int dup (fhandler_base *child);
|
||||||
bool is_slow () {return 1;}
|
bool is_slow () {return 1;}
|
||||||
ATOM& get_atom () {return upand;}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class fhandler_dev_raw: public fhandler_base
|
class fhandler_dev_raw: public fhandler_base
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "pinfo.h"
|
#include "pinfo.h"
|
||||||
|
|
||||||
fhandler_fifo::fhandler_fifo ()
|
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)
|
read_use (0), write_use (0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -45,11 +45,6 @@ fhandler_fifo::set_use (int incr)
|
||||||
|
|
||||||
if (incr >= 0)
|
if (incr >= 0)
|
||||||
return;
|
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)
|
if (read_use <= 0 && oread_use != read_use)
|
||||||
{
|
{
|
||||||
HANDLE h = get_handle ();
|
HANDLE h = get_handle ();
|
||||||
|
@ -58,7 +53,6 @@ fhandler_fifo::set_use (int incr)
|
||||||
set_io_handle (NULL);
|
set_io_handle (NULL);
|
||||||
CloseHandle (h);
|
CloseHandle (h);
|
||||||
}
|
}
|
||||||
DeleteAtom (ant);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +69,6 @@ fhandler_fifo::close ()
|
||||||
int
|
int
|
||||||
fhandler_fifo::open_not_mine (int flags)
|
fhandler_fifo::open_not_mine (int flags)
|
||||||
{
|
{
|
||||||
char buf[24];
|
|
||||||
winpids pids;
|
winpids pids;
|
||||||
static int flagtypes[] = {DUMMY_O_RDONLY | O_RDWR, O_WRONLY | O_APPEND | O_RDWR};
|
static int flagtypes[] = {DUMMY_O_RDONLY | O_RDWR, O_WRONLY | O_APPEND | O_RDWR};
|
||||||
HANDLE *usehandles[2] = {&(get_handle ()), &(get_output_handle ())};
|
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++)
|
for (unsigned i = 0; i < pids.npids; i++)
|
||||||
{
|
{
|
||||||
_pinfo *p = pids[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);
|
HANDLE hp = OpenProcess (PROCESS_DUP_HANDLE, false, p->dwProcessId);
|
||||||
if (!hp)
|
if (!hp)
|
||||||
{
|
{
|
||||||
|
@ -97,7 +86,10 @@ fhandler_fifo::open_not_mine (int flags)
|
||||||
|
|
||||||
HANDLE handles[2];
|
HANDLE handles[2];
|
||||||
commune_result r;
|
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;
|
flags = (flags & (O_RDWR | O_WRONLY | O_APPEND)) ?: DUMMY_O_RDONLY;
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
|
@ -139,28 +131,10 @@ int
|
||||||
fhandler_fifo::open (int flags, mode_t)
|
fhandler_fifo::open (int flags, mode_t)
|
||||||
{
|
{
|
||||||
int res = 1;
|
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];
|
fhandler_pipe *fhs[2];
|
||||||
if (create (fhs, 0, flags, true))
|
if (create (fhs, 0, flags, true))
|
||||||
{
|
goto errnout;
|
||||||
CloseHandle (h);
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
|
|
||||||
set_flags (fhs[0]->get_flags ());
|
set_flags (fhs[0]->get_flags ());
|
||||||
set_io_handle (fhs[0]->get_handle ());
|
set_io_handle (fhs[0]->get_handle ());
|
||||||
|
@ -173,13 +147,10 @@ fhandler_fifo::open (int flags, mode_t)
|
||||||
delete (fhs[0]);
|
delete (fhs[0]);
|
||||||
delete (fhs[1]);
|
delete (fhs[1]);
|
||||||
set_use (1);
|
set_use (1);
|
||||||
__small_sprintf (buf, "%x.%x", upand, myself->pid);
|
|
||||||
(void) GlobalAddAtom (buf);
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
errnout:
|
errnout:
|
||||||
__seterrno ();
|
__seterrno ();
|
||||||
errout:
|
|
||||||
res = 0;
|
res = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
|
|
@ -398,16 +398,31 @@ _pinfo::commune_recv ()
|
||||||
}
|
}
|
||||||
case PICOM_FIFO:
|
case PICOM_FIFO:
|
||||||
{
|
{
|
||||||
int formic;
|
char path[CYG_MAX_PATH + 1];
|
||||||
if (!ReadFile (__fromthem, &formic, sizeof formic, &nr, NULL)
|
unsigned len;
|
||||||
|| nr != sizeof formic)
|
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
|
/* __seterrno ();*/ // this is run from the signal thread, so don't set errno
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
fhandler_fifo *fh = cygheap->fdtab.find_fifo ((ATOM) formic);
|
fhandler_fifo *fh = cygheap->fdtab.find_fifo (path);
|
||||||
HANDLE it[] = {(fh->get_handle ()), (fh->get_output_handle ())};
|
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))
|
if (!WriteFile (__tothem, it, sizeof (it), &nr, NULL))
|
||||||
{
|
{
|
||||||
|
@ -474,8 +489,9 @@ _pinfo::commune_send (DWORD code, ...)
|
||||||
{
|
{
|
||||||
case PICOM_FIFO:
|
case PICOM_FIFO:
|
||||||
{
|
{
|
||||||
int formic = va_arg (args, int);
|
char *path = va_arg (args, char *);
|
||||||
if (!WriteFile (tothem, &formic, sizeof formic, &nr, NULL) || nr != sizeof formic)
|
size_t len = strlen (path) + 1;
|
||||||
|
if (!WriteFile (tothem, path, len, &nr, NULL) || nr != len)
|
||||||
{
|
{
|
||||||
__seterrno ();
|
__seterrno ();
|
||||||
goto err;
|
goto err;
|
||||||
|
|
Loading…
Reference in New Issue