* 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.
This commit is contained in:
Corinna Vinschen 2002-03-11 17:57:22 +00:00
parent eabb48d53d
commit 713fb38b7c
4 changed files with 39 additions and 5 deletions

View 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.

View 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");

View 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 ();
}
}

View 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 ();