* cygheap.cc (dup_now): New function.

(cygheap_setup_for_child): Accept new argument controlling whether to delay
copying of cygheap to shared memory region.
(cygheap_setup_for_child_cleanup): Accept new arguments controlling whether to
copy cygheap at this point.
* cygheap.h: Reflect above changes.
* fork.cc (fork_parent): Break copying of cygheap into two parts when
fork_fixup is required so that the child can see the parent's changes.
(vfork): Do stack cleanup prior to forcing a fork error.
* spawn.cc (spawn_guts): Ditto.
This commit is contained in:
Christopher Faylor
2001-09-14 00:49:00 +00:00
parent 3e2d8af0b9
commit e2e078278c
5 changed files with 64 additions and 24 deletions

View File

@@ -464,7 +464,8 @@ fork_parent (HANDLE& hParent, dll *&first_dll,
syscall_printf ("CreateProcess (%s, %s, 0, 0, 1, %x, 0, 0, %p, %p)",
myself->progname, myself->progname, c_flags, &si, &pi);
__malloc_lock (_reent_clib ());
cygheap_setup_for_child (&ch);
void *newheap;
newheap = cygheap_setup_for_child (&ch,cygheap->fdtab.need_fixup_before ());
rc = CreateProcess (myself->progname, /* image to run */
myself->progname, /* what we send in arg0 */
allow_ntsec ? sec_user (sa_buf) : &sec_none_nih,
@@ -477,7 +478,6 @@ fork_parent (HANDLE& hParent, dll *&first_dll,
&pi);
CloseHandle (hParent);
cygheap_setup_for_child_cleanup (&ch);
if (!rc)
{
@@ -489,14 +489,18 @@ fork_parent (HANDLE& hParent, dll *&first_dll,
if (cygheap->user.impersonated
&& cygheap->user.token != INVALID_HANDLE_VALUE)
ImpersonateLoggedOnUser (cygheap->user.token);
cygheap_setup_for_child_cleanup (newheap, &ch, 0);
return -1;
}
/* Fixup the parent datastructure if needed and resume the child's
main thread. */
if (cygheap->fdtab.need_fixup_before ())
if (!cygheap->fdtab.need_fixup_before ())
cygheap_setup_for_child_cleanup (newheap, &ch, 0);
else
{
cygheap->fdtab.fixup_before_fork (pi.dwProcessId);
cygheap_setup_for_child_cleanup (newheap, &ch, 1);
ResumeThread (pi.hThread);
}
@@ -718,6 +722,12 @@ vfork ()
cygheap->fdtab.vfork_parent_restore ();
vf = get_vfork_val ();
__asm__ volatile ("movl %%esp,%0": "=r" (esp):);
for (pp = (char **)vf->frame, esp = vf->vfork_esp;
esp <= vf->vfork_ebp + 1; pp++, esp++)
*esp = *pp;
if (vf->pid < 0)
{
int exitval = -vf->pid;
@@ -725,11 +735,6 @@ vfork ()
exit (exitval);
}
__asm__ volatile ("movl %%esp,%0": "=r" (esp):);
for (pp = (char **)vf->frame, esp = vf->vfork_esp;
esp <= vf->vfork_ebp + 1; pp++, esp++)
*esp = *pp;
return vf->pid;
#endif
}