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-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.
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;
/* 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;
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);
}
}
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;
#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 *);
{
HANDLE output_handle;
HANDLE owner; // You can't have too many mutexes, now, can you?
- ATOM upand;
long read_use;
long write_use;
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
#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)
{
}
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 ();
set_io_handle (NULL);
CloseHandle (h);
}
- DeleteAtom (ant);
}
}
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 ())};
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)
{
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++)
{
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 ());
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:
}
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))
{
{
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;