]> sourceware.org Git - newlib-cygwin.git/commitdiff
* cygheap.cc (init_cheap): Add ability to specify minimal cygwin heap size when
authorChristopher Faylor <me@cgf.cx>
Sun, 21 Mar 2004 17:41:40 +0000 (17:41 +0000)
committerChristopher Faylor <me@cgf.cx>
Sun, 21 Mar 2004 17:41:40 +0000 (17:41 +0000)
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.

winsup/cygwin/ChangeLog
winsup/cygwin/cygheap.cc
winsup/cygwin/dtable.cc
winsup/cygwin/dtable.h
winsup/cygwin/fhandler.h
winsup/cygwin/fhandler_fifo.cc
winsup/cygwin/pinfo.cc

index b5a4e1be8c53f4b7aa90f7d48e53cf7299ec8ce2..335019e01fc5aef54a08020b3e5ca42b44c7d22f 100644 (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.
index b4ecf89e7480232dbe1c98d3b70f279827ab5dd1..7e9b144481b67eb05afeb785fc84aaa552fcfbb9 100644 (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);
 }
 
index 24793733da3c7cc951b6766b08cd92f5964a897c..d3377e74a9d2595cb0224ffdb93ad08b918c478f 100644 (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;
index 5732ed531a43adbb9257d10bbbe2c05bc2ab0768..0c6153aae77bef42eef376bdc7ed16c3c07160a4 100644 (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 *);
index 9d3a56ac03490fa73bfd389073f5242bf4c56ba8..26380e263438e7b98cbbd7e6084dfb780416c5d0 100644 (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
index c45a4dcdd5ae4a5e930eb451a329ce87b58d62f0..d38d5867073c09ec397b0cd76311ef34396f10ba 100644 (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:
index f467d7e87f2b8a0a51cea65738ba72c2add828fa..0ed74009f9307946086539189ee778c0ae9616c7 100644 (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;
This page took 0.090445 seconds and 5 git commands to generate.