OSDN Git Service

* fork.cc (fork_child): Call fixup_mmaps_after_fork() before
authorcorinna <corinna>
Mon, 11 Mar 2002 17:57:21 +0000 (17:57 +0000)
committercorinna <corinna>
Mon, 11 Mar 2002 17:57:21 +0000 (17:57 +0000)
closing parent process handle.  Call fixup_mmaps_after_fork()
with parent process handle as parameter.
* mmap.cc (mmap_record::access): New method.
(fixup_mmaps_after_fork): Take process handle as parameter.
In case of FILE_MAP_COPY access, copy valid memory regions to child.
* pinfo.h (fixup_mmaps_after_fork): Change prototype accordingly.

winsup/cygwin/ChangeLog
winsup/cygwin/fork.cc
winsup/cygwin/mmap.cc
winsup/cygwin/pinfo.h

index 3029b83..fa15f2c 100644 (file)
@@ -1,3 +1,13 @@
+2002-03-11  Corinna Vinschen  <corina@vinschen.de>
+
+       * fork.cc (fork_child): Call fixup_mmaps_after_fork() before
+       closing parent process handle.  Call fixup_mmaps_after_fork()
+       with parent process handle as parameter.
+       * mmap.cc (mmap_record::access): New method.
+       (fixup_mmaps_after_fork): Take process handle as parameter.
+       In case of FILE_MAP_COPY access, copy valid memory regions to child.
+       * pinfo.h (fixup_mmaps_after_fork): Change prototype accordingly.
+
 2002-03-07  Corinna Vinschen  <corina@vinschen.de>
 
        * autoload.cc (NetGetDCName): Add symbol.
index f7133df..03d17ee 100644 (file)
@@ -296,13 +296,13 @@ fork_child (HANDLE& hParent, dll *&first_dll, bool& load_dlls)
       sync_with_parent ("loaded dlls", TRUE);
     }
 
+  if (fixup_mmaps_after_fork (hParent))
+    api_fatal ("recreate_mmaps_after_fork_failed");
+
   ForceCloseHandle (hParent);
   (void) ForceCloseHandle (child_proc_info->subproc_ready);
   (void) ForceCloseHandle (child_proc_info->forker_finished);
 
-  if (fixup_mmaps_after_fork ())
-    api_fatal ("recreate_mmaps_after_fork_failed");
-
   if (fixup_shms_after_fork ())
     api_fatal ("recreate_shm areas after fork failed");
 
index 57bd827..dae80e4 100644 (file)
@@ -98,6 +98,7 @@ class mmap_record
     __off64_t map_map (__off64_t off, DWORD len);
     BOOL unmap_map (caddr_t addr, DWORD len);
     void fixup_map (void);
+    int access (char *address);
 
     fhandler_base *alloc_fh ();
     void free_fh (fhandler_base *fh);
@@ -219,6 +220,15 @@ mmap_record::fixup_map ()
                    &old_prot);
 }
 
+int
+mmap_record::access (char *address)
+{
+  if (address < base_address_ || address >= base_address_ + size_to_map_)
+    return 0;
+  DWORD off = (address - base_address_) / getpagesize ();
+  return MAP_ISSET (off);
+}
+
 static fhandler_disk_file fh_paging_file;
 
 fhandler_base *
@@ -887,7 +897,7 @@ mprotect (caddr_t addr, size_t len, int prot)
  */
 
 int __stdcall
-fixup_mmaps_after_fork ()
+fixup_mmaps_after_fork (HANDLE parent)
 {
 
   debug_printf ("recreate_mmaps_after_fork, mmapped_areas %p", mmapped_areas);
@@ -925,6 +935,20 @@ fixup_mmaps_after_fork ()
                                 rec->get_address ());
                  return -1;
                }
+             if (rec->get_access () == FILE_MAP_COPY)
+               {
+                 for (char *address = rec->get_address ();
+                      address < rec->get_address () + rec->get_size ();
+                      address += getpagesize ())
+                   if (rec->access (address)
+                       && !ReadProcessMemory (parent, address, address,
+                                              getpagesize (), NULL))
+                     {
+                       system_printf ("ReadProcessMemory failed for MAP_PRIVATE address %p, %E",
+                                      rec->get_address ());
+                       return -1;
+                     }
+               }
              rec->fixup_map ();
            }
        }
index 1bc2f79..dc16966 100644 (file)
@@ -200,7 +200,7 @@ extern void __stdcall pinfo_fixup_after_fork ();
 extern HANDLE hexec_proc;
 
 /* For mmaps across fork(). */
-int __stdcall fixup_mmaps_after_fork ();
+int __stdcall fixup_mmaps_after_fork (HANDLE parent);
 /* for shm areas across fork (). */
 int __stdcall fixup_shms_after_fork ();