]> sourceware.org Git - newlib-cygwin.git/commitdiff
* child_info.h (CURR_CHILD_INFO_MAGIC): Reset.
authorChristopher Faylor <me@cgf.cx>
Tue, 15 Oct 2002 07:03:45 +0000 (07:03 +0000)
committerChristopher Faylor <me@cgf.cx>
Tue, 15 Oct 2002 07:03:45 +0000 (07:03 +0000)
(child_info_fork::mount_table): Remove.
(child_info_fork::myself_addr): Remove.
* fork.cc (fork_child): Don't set either of the above.
* dcrt0.cc (dll_crt0_1): Call memory_init as early as possible.
* fhandler_console.cc (console_state): Move to shared_info.h.
(fhandler_console::get_tty_stuff): Reflect open_shared arg change.
* pinfo.cc (myself_addr): Remove definition.
(pinfo::init): Get myself address from open_shared.
* pinfo.h (myself_addr): Remove declaration.
* shared.cc (open_shared): Rework so that known shared memory locations are
protected.  Take shared memory type as fifth argument.
(memory_init): Reflect open_shared arg change.
* shared_info.h (shared_locations): New enum.
(console_state): Move here.
(open_shared): Reflect open_shared arg change in declaration.

winsup/cygwin/ChangeLog
winsup/cygwin/child_info.h
winsup/cygwin/dcrt0.cc
winsup/cygwin/fhandler_console.cc
winsup/cygwin/fork.cc
winsup/cygwin/pinfo.cc
winsup/cygwin/pinfo.h
winsup/cygwin/shared.cc
winsup/cygwin/shared_info.h

index 80325cc3738b44b86657661799828b20b8ee3613..bd35ed16e5ad65e1a3b22541bbd0564d7315955e 100644 (file)
@@ -1,3 +1,22 @@
+2002-10-15  Christopher Faylor  <cgf@redhat.com>
+
+       * child_info.h (CURR_CHILD_INFO_MAGIC): Reset.
+       (child_info_fork::mount_table): Remove.
+       (child_info_fork::myself_addr): Remove.
+       * fork.cc (fork_child): Don't set either of the above.
+       * dcrt0.cc (dll_crt0_1): Call memory_init as early as possible.
+       * fhandler_console.cc (console_state): Move to shared_info.h.
+       (fhandler_console::get_tty_stuff): Reflect open_shared arg change.
+       * pinfo.cc (myself_addr): Remove definition.
+       (pinfo::init): Get myself address from open_shared.
+       * pinfo.h (myself_addr): Remove declaration.
+       * shared.cc (open_shared): Rework so that known shared memory locations
+       are protected.  Take shared memory type as fifth argument.
+       (memory_init): Reflect open_shared arg change.
+       * shared_info.h (shared_locations): New enum.
+       (console_state): Move here.
+       (open_shared): Reflect open_shared arg change in declaration.
+
 2002-10-14  Christopher Faylor  <cgf@redhat.com>
 
        * child_info.h (CURR_CHILD_INFO_MAGIC): Reset.
index 4cc09b74bcf13e22cc47e2ef3b7c3a16f256592e..2ac01522223916bbb486cba413730c2dfa1bab34 100644 (file)
@@ -29,7 +29,7 @@ enum
 
 #define EXEC_MAGIC_SIZE sizeof(child_info)
 
-#define CURR_CHILD_INFO_MAGIC 0x64848c11U
+#define CURR_CHILD_INFO_MAGIC 0x8e0899faU
 
 /* NOTE: Do not make gratuitous changes to the names or organization of the
    below class.  The layout is checksummed to determine compatibility between
@@ -61,8 +61,6 @@ class child_info_fork: public child_info
 public:
   HANDLE forker_finished;// for synchronization with child
   DWORD stacksize;     // size of parent stack
-  mount_info *mount_table;// location of mount table in parent
-  _pinfo *myself_addr; // where myself shared memory lives in the parent
   jmp_buf jmp;         // where child will jump to
   void *stacktop;      // location of top of parent stack
   void *stackbottom;   // location of bottom of parent stack
index e7babe08bbb83a51757eb3870568b6fb0d12f2b7..4270c58a4855682ca61ecd42e65bae4abafd7478 100644 (file)
@@ -572,7 +572,9 @@ dll_crt0_1 ()
   int envc = 0;
   char **envp = NULL;
 
-  if (child_proc_info)
+  if (!child_proc_info)
+    memory_init ();
+  else
     {
       bool close_ppid_handle = false;
       bool close_hexec_proc = false;
@@ -581,10 +583,9 @@ dll_crt0_1 ()
          case _PROC_FORK:
            cygheap_fixup_in_child (0);
            alloc_stack (fork_info);
-           mount_table = fork_info->mount_table;
-           myself_addr = fork_info->myself_addr;
-           set_myself (mypid);
            close_ppid_handle = !!child_proc_info->pppid_handle;
+           memory_init ();
+           set_myself (mypid);
            break;
          case _PROC_SPAWN:
            /* Have to delay closes until after cygheap is setup */
@@ -596,6 +597,7 @@ dll_crt0_1 ()
          around:
            HANDLE h;
            cygheap_fixup_in_child (1);
+           memory_init ();
            if (!spawn_info->moreinfo->myself_pinfo ||
                !DuplicateHandle (hMainProc, spawn_info->moreinfo->myself_pinfo,
                                  hMainProc, &h, 0, 0,
@@ -622,9 +624,6 @@ dll_crt0_1 ()
        CloseHandle (child_proc_info->pppid_handle);
     }
 
-  /* Initialize the cygwin subsystem if this is the first process,
-     or attach to shared data structures if it's already running. */
-  memory_init ();
   cygthread::init ();
 
   ProtectHandle (hMainProc);
index a43dad11fd7c151d26843a9d79d39b137f12c8b6..5be009eb926a1281eef3ef242ba0e2e735382a8a 100644 (file)
@@ -85,14 +85,7 @@ str_to_con (char *d, const char *s, DWORD sz)
 
 const char * get_nonascii_key (INPUT_RECORD&, char *);
 
-struct console_state
-{
-  tty_min tty_min_state;
-  dev_console dev_state;
-};
-
 static console_state NO_COPY *shared_console_info;
-static console_state *shared_console_info_save;
 
 dev_console NO_COPY *fhandler_console::dev_state;
 
@@ -104,10 +97,10 @@ fhandler_console::get_tty_stuff (int flags = 0)
   if (dev_state)
     return &shared_console_info->tty_min_state;
 
-  shared_console_info = shared_console_info_save =
+  shared_console_info =
     (console_state *) open_shared (NULL, 0, cygheap->console_h,
                                   sizeof (*shared_console_info),
-                                  shared_console_info_save);
+                                  SH_SHARED_CONSOLE);
   dev_state = &shared_console_info->dev_state;
 
   ProtectHandleINH (cygheap->console_h);
index f104e41963f5aacc4d2a9a8cb30c0b05ece5255f..c3045c4b90921babb34a9e1e48f330cff8657088 100644 (file)
@@ -422,8 +422,6 @@ fork_parent (HANDLE& hParent, dll *&first_dll,
   init_child_info (PROC_FORK, &ch, 1, subproc_ready);
 
   ch.forker_finished = forker_finished;
-  ch.mount_table = mount_table;
-  ch.myself_addr = myself_addr;
 
   stack_base (ch);
 
index 349545440bfefb75546026faca8c7771a4869334..0ffd00edd1e50d9738d9d671aa2faf6de27c24ea 100644 (file)
@@ -27,13 +27,13 @@ details. */
 #include <ntdef.h>
 #include "ntdll.h"
 #include "cygthread.h"
+#include "shared_info.h"
 
 static char NO_COPY pinfo_dummy[sizeof (_pinfo)] = {0};
 
 pinfo NO_COPY myself ((_pinfo *)&pinfo_dummy); // Avoid myself != NULL checks
 
 HANDLE hexec_proc;
-_pinfo NO_COPY *myself_addr;
 
 void __stdcall
 pinfo_fixup_after_fork ()
@@ -128,17 +128,13 @@ pinfo::init (pid_t n, DWORD flag, HANDLE in_h)
     }
 
   void *mapaddr;
-  bool itsme;
   if (!(flag & PID_MYSELF))
-    {
-      mapaddr = NULL;
-      itsme = false;
-    }
+    mapaddr = NULL;
   else
     {
       flag &= ~PID_MYSELF;
-      mapaddr = myself_addr;
-      itsme = true;
+      HANDLE hdummy;
+      mapaddr = open_shared (NULL, 0, hdummy, 0, SH_MYSELF);
     }
 
   int createit = flag & (PID_IN_USE | PID_EXECED);
@@ -182,8 +178,6 @@ pinfo::init (pid_t n, DWORD flag, HANDLE in_h)
       procinfo = (_pinfo *) MapViewOfFileEx (h, FILE_MAP_READ | FILE_MAP_WRITE,
                                             0, 0, 0, mapaddr);
       ProtectHandle1 (h, pinfo_shared_handle);
-      if (itsme)
-       myself_addr = procinfo;
 
       if ((procinfo->process_state & PID_INITIALIZING) && (flag & PID_NOREDIR)
          && cygwin_pid (procinfo->dwProcessId) != procinfo->pid)
index f99b6aa5e8a8364505102873ce5a90eed82864a4..dcb814bcc712b021608169b4be3bacab15fa2cc2 100644 (file)
@@ -202,7 +202,6 @@ cygwin_pid (pid_t pid)
 void __stdcall pinfo_init (char **, int);
 void __stdcall set_myself (pid_t pid, HANDLE h = NULL);
 extern pinfo myself;
-extern _pinfo *myself_addr;
 
 #define _P_VFORK 0
 extern void __stdcall pinfo_fixup_after_fork ();
index 61ec95e13cf3b8b0c6a97403ec190d0fdb4ad62b..113e7f542f516fc506d1e54c5f350f17fa83a38e 100644 (file)
@@ -26,6 +26,7 @@ details. */
 #include "shared_info_magic.h"
 #include "registry.h"
 #include "cygwin_version.h"
+#include "child_info.h"
 
 shared_info NO_COPY *cygwin_shared;
 mount_info NO_COPY *mount_table;
@@ -43,10 +44,48 @@ shared_name (const char *str, int num)
   return buf;
 }
 
+#define page_const (65535)
+#define pround(n) (((size_t) (n) + page_const) & ~page_const)
+
 void * __stdcall
-open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, void *addr)
+open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, shared_locations m)
 {
   void *shared;
+  static char *offsets[] =
+  {
+    (char *) cygwin_shared_address,
+    (char *) cygwin_shared_address
+      + pround (sizeof (shared_info)),
+    (char *) cygwin_shared_address
+      + pround (sizeof (shared_info))
+      + pround (sizeof (mount_info)),
+    (char *) cygwin_shared_address
+      + pround (sizeof (shared_info))
+      + pround (sizeof (mount_info))
+      + pround (sizeof (console_state)),
+    (char *) cygwin_shared_address
+      + pround (sizeof (shared_info))
+      + pround (sizeof (mount_info))
+      + pround (sizeof (console_state))
+      + pround (sizeof (_pinfo))
+  };
+
+  if (m == SH_CYGWIN_SHARED)
+    {
+      for (int i = SH_CYGWIN_SHARED; i < SH_TOTAL_SIZE; i++)
+       if (!VirtualAlloc (offsets[i], offsets[i + 1] - offsets[i],
+                          MEM_RESERVE, PAGE_NOACCESS))
+         continue;  /* oh well */
+      if (!child_proc_info)
+       for (DWORD s = 0x950000; s <= 0xa40000; s += 0x1000)
+         VirtualAlloc ((void *) s, 4, MEM_RESERVE, PAGE_NOACCESS);
+    }
+
+  void *addr = offsets[m];
+  (void) VirtualFree (addr, 0, MEM_RELEASE);
+
+  if (!size)
+    return addr;
 
   if (!shared_h)
     {
@@ -65,9 +104,8 @@ open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, void *addr)
        api_fatal ("CreateFileMapping, %E.  Terminating.");
     }
 
-  shared = (shared_info *) MapViewOfFileEx (shared_h,
-                                      FILE_MAP_READ | FILE_MAP_WRITE,
-                                      0, 0, 0, addr);
+  shared = (shared_info *)
+    MapViewOfFileEx (shared_h, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, addr);
 
   if (!shared)
     {
@@ -115,13 +153,14 @@ shared_info::initialize ()
 void __stdcall
 memory_init ()
 {
+  getpagesize ();
   /* Initialize general shared memory */
   HANDLE shared_h = cygheap ? cygheap->shared_h : NULL;
   cygwin_shared = (shared_info *) open_shared ("shared",
                                               CYGWIN_VERSION_SHARED_DATA,
                                               shared_h,
                                               sizeof (*cygwin_shared),
-                                              cygwin_shared_address);
+                                              SH_CYGWIN_SHARED);
 
   cygwin_shared->initialize ();
 
@@ -142,13 +181,13 @@ memory_init ()
   cygheap->shared_h = shared_h;
   ProtectHandleINH (cygheap->shared_h);
 
-  getpagesize ();
   heap_init ();
+
   mount_table = (mount_info *) open_shared (user_name, MOUNT_VERSION,
                                            cygwin_mount_h, sizeof (mount_info),
-                                           mount_table);
+                                           SH_MOUNT_TABLE);
   debug_printf ("opening mount table for '%s' at %p", cygheap->user.name (),
-               mount_table_address);
+               mount_table);
   ProtectHandleINH (cygwin_mount_h);
   debug_printf ("mount table version %x at %p", mount_table->version, mount_table);
 
index 232575bc7659fed2264b9f5464101ad5a79b4cec..a39275e493383ae0dc94a956cb2ab5b27dbdd29e 100644 (file)
@@ -161,6 +161,14 @@ extern shared_info *cygwin_shared;
 extern mount_info *mount_table;
 extern HANDLE cygwin_mount_h;
 
+enum shared_locations
+{
+  SH_CYGWIN_SHARED,
+  SH_MOUNT_TABLE,
+  SH_SHARED_CONSOLE,
+  SH_MYSELF,
+  SH_TOTAL_SIZE
+};
 void __stdcall memory_init ();
 
 #define shared_align_past(p) \
@@ -169,8 +177,14 @@ void __stdcall memory_init ();
              system_info.dwAllocationGranularity)))
 
 #define cygwin_shared_address  ((void *) 0xa000000)
-#define mount_table_address    shared_align_past (cygwin_shared)
-#define cygheap_address                shared_align_past ((mount_info *) shared_align_past (cygwin_shared))
+
+#ifdef FHDEVN
+struct console_state
+{
+  tty_min tty_min_state;
+  dev_console dev_state;
+};
+#endif
 
 char *__stdcall shared_name (const char *, int);
-void *__stdcall open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, void *addr);
+void *__stdcall open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, shared_locations);
This page took 0.049618 seconds and 5 git commands to generate.