* 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:
parent
3e2d8af0b9
commit
e2e078278c
|
@ -1,3 +1,16 @@
|
||||||
|
Thu Sep 13 20:46:05 2001 Christopher Faylor <cgf@cygnus.com>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
Thu Sep 13 17:14:59 2001 Christopher Faylor <cgf@cygnus.com>
|
Thu Sep 13 17:14:59 2001 Christopher Faylor <cgf@cygnus.com>
|
||||||
|
|
||||||
* cygheap.cc (ccalloc): Pass correct length to creturn so that
|
* cygheap.cc (ccalloc): Pass correct length to creturn so that
|
||||||
|
|
|
@ -64,8 +64,17 @@ init_cheap ()
|
||||||
cygheap_max = cygheap + 1;
|
cygheap_max = cygheap + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __stdcall
|
static void dup_now (void *, child_info *, unsigned) __attribute__ ((regparm(3)));
|
||||||
cygheap_setup_for_child (child_info *ci)
|
static void
|
||||||
|
dup_now (void *newcygheap, child_info *ci, unsigned n)
|
||||||
|
{
|
||||||
|
if (!VirtualAlloc (newcygheap, n, MEM_COMMIT, PAGE_READWRITE))
|
||||||
|
api_fatal ("couldn't allocate new cygwin heap for child, %E");
|
||||||
|
memcpy (newcygheap, cygheap, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *__stdcall
|
||||||
|
cygheap_setup_for_child (child_info *ci, bool dup_later)
|
||||||
{
|
{
|
||||||
void *newcygheap;
|
void *newcygheap;
|
||||||
cygheap_protect->acquire ();
|
cygheap_protect->acquire ();
|
||||||
|
@ -73,20 +82,29 @@ cygheap_setup_for_child (child_info *ci)
|
||||||
ci->cygheap_h = CreateFileMapping (INVALID_HANDLE_VALUE, &sec_none,
|
ci->cygheap_h = CreateFileMapping (INVALID_HANDLE_VALUE, &sec_none,
|
||||||
CFMAP_OPTIONS, 0, CYGHEAPSIZE, NULL);
|
CFMAP_OPTIONS, 0, CYGHEAPSIZE, NULL);
|
||||||
newcygheap = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL);
|
newcygheap = MapViewOfFileEx (ci->cygheap_h, MVMAP_OPTIONS, 0, 0, 0, NULL);
|
||||||
if (!VirtualAlloc (newcygheap, n, MEM_COMMIT, PAGE_READWRITE))
|
ProtectHandle1 (ci->cygheap_h, passed_cygheap_h);
|
||||||
api_fatal ("couldn't allocate new cygwin heap for child, %E");
|
if (!dup_later)
|
||||||
memcpy (newcygheap, cygheap, n);
|
dup_now (newcygheap, ci, n);
|
||||||
UnmapViewOfFile (newcygheap);
|
cygheap_protect->release ();
|
||||||
ci->cygheap = cygheap;
|
ci->cygheap = cygheap;
|
||||||
ci->cygheap_max = cygheap_max;
|
ci->cygheap_max = cygheap_max;
|
||||||
ProtectHandle1 (ci->cygheap_h, passed_cygheap_h);
|
return newcygheap;
|
||||||
cygheap_protect->release ();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void __stdcall
|
void __stdcall
|
||||||
cygheap_setup_for_child_cleanup (child_info *ci)
|
cygheap_setup_for_child_cleanup (void *newcygheap, child_info *ci,
|
||||||
|
bool dup_it_now)
|
||||||
{
|
{
|
||||||
|
if (dup_it_now)
|
||||||
|
{
|
||||||
|
/* NOTE: There is an assumption here that cygheap_max has not changed
|
||||||
|
between the time that cygheap_setup_for_child was called and now.
|
||||||
|
Make sure that this is a correct assumption. */
|
||||||
|
cygheap_protect->acquire ();
|
||||||
|
dup_now (newcygheap, ci, (char *) cygheap_max - (char *) cygheap);
|
||||||
|
cygheap_protect->release ();
|
||||||
|
}
|
||||||
|
UnmapViewOfFile (newcygheap);
|
||||||
ForceCloseHandle1 (ci->cygheap_h, passed_cygheap_h);
|
ForceCloseHandle1 (ci->cygheap_h, passed_cygheap_h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,8 +177,8 @@ extern init_cygheap *cygheap;
|
||||||
extern void *cygheap_max;
|
extern void *cygheap_max;
|
||||||
|
|
||||||
class child_info;
|
class child_info;
|
||||||
void __stdcall cygheap_setup_for_child (child_info *ci) __attribute__ ((regparm(1)));
|
void *__stdcall cygheap_setup_for_child (child_info *ci, bool dup_later) __attribute__ ((regparm(2)));
|
||||||
void __stdcall cygheap_setup_for_child_cleanup (child_info *ci) __attribute__ ((regparm(1)));
|
void __stdcall cygheap_setup_for_child_cleanup (void *, child_info *, bool) __attribute__ ((regparm(3)));
|
||||||
void __stdcall cygheap_fixup_in_child (child_info *, bool);
|
void __stdcall cygheap_fixup_in_child (child_info *, bool);
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void __stdcall cfree (void *) __attribute__ ((regparm(1)));
|
void __stdcall cfree (void *) __attribute__ ((regparm(1)));
|
||||||
|
|
|
@ -464,7 +464,8 @@ fork_parent (HANDLE& hParent, dll *&first_dll,
|
||||||
syscall_printf ("CreateProcess (%s, %s, 0, 0, 1, %x, 0, 0, %p, %p)",
|
syscall_printf ("CreateProcess (%s, %s, 0, 0, 1, %x, 0, 0, %p, %p)",
|
||||||
myself->progname, myself->progname, c_flags, &si, &pi);
|
myself->progname, myself->progname, c_flags, &si, &pi);
|
||||||
__malloc_lock (_reent_clib ());
|
__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 */
|
rc = CreateProcess (myself->progname, /* image to run */
|
||||||
myself->progname, /* what we send in arg0 */
|
myself->progname, /* what we send in arg0 */
|
||||||
allow_ntsec ? sec_user (sa_buf) : &sec_none_nih,
|
allow_ntsec ? sec_user (sa_buf) : &sec_none_nih,
|
||||||
|
@ -477,7 +478,6 @@ fork_parent (HANDLE& hParent, dll *&first_dll,
|
||||||
&pi);
|
&pi);
|
||||||
|
|
||||||
CloseHandle (hParent);
|
CloseHandle (hParent);
|
||||||
cygheap_setup_for_child_cleanup (&ch);
|
|
||||||
|
|
||||||
if (!rc)
|
if (!rc)
|
||||||
{
|
{
|
||||||
|
@ -489,14 +489,18 @@ fork_parent (HANDLE& hParent, dll *&first_dll,
|
||||||
if (cygheap->user.impersonated
|
if (cygheap->user.impersonated
|
||||||
&& cygheap->user.token != INVALID_HANDLE_VALUE)
|
&& cygheap->user.token != INVALID_HANDLE_VALUE)
|
||||||
ImpersonateLoggedOnUser (cygheap->user.token);
|
ImpersonateLoggedOnUser (cygheap->user.token);
|
||||||
|
cygheap_setup_for_child_cleanup (newheap, &ch, 0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fixup the parent datastructure if needed and resume the child's
|
/* Fixup the parent datastructure if needed and resume the child's
|
||||||
main thread. */
|
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->fdtab.fixup_before_fork (pi.dwProcessId);
|
||||||
|
cygheap_setup_for_child_cleanup (newheap, &ch, 1);
|
||||||
ResumeThread (pi.hThread);
|
ResumeThread (pi.hThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -718,6 +722,12 @@ vfork ()
|
||||||
cygheap->fdtab.vfork_parent_restore ();
|
cygheap->fdtab.vfork_parent_restore ();
|
||||||
|
|
||||||
vf = get_vfork_val ();
|
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)
|
if (vf->pid < 0)
|
||||||
{
|
{
|
||||||
int exitval = -vf->pid;
|
int exitval = -vf->pid;
|
||||||
|
@ -725,11 +735,6 @@ vfork ()
|
||||||
exit (exitval);
|
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;
|
return vf->pid;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -590,6 +590,7 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv,
|
||||||
|
|
||||||
syscall_printf ("spawn_guts null_app_name %d (%s, %.132s)", null_app_name, runpath, one_line.buf);
|
syscall_printf ("spawn_guts null_app_name %d (%s, %.132s)", null_app_name, runpath, one_line.buf);
|
||||||
|
|
||||||
|
void *newheap;
|
||||||
cygbench ("spawn-guts");
|
cygbench ("spawn-guts");
|
||||||
if (!hToken)
|
if (!hToken)
|
||||||
{
|
{
|
||||||
|
@ -597,7 +598,7 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv,
|
||||||
/* FIXME: This leaks a handle in the CreateProcessAsUser case since the
|
/* FIXME: This leaks a handle in the CreateProcessAsUser case since the
|
||||||
child process doesn't know about cygwin_mount_h. */
|
child process doesn't know about cygwin_mount_h. */
|
||||||
ciresrv.mount_h = cygwin_mount_h;
|
ciresrv.mount_h = cygwin_mount_h;
|
||||||
cygheap_setup_for_child (&ciresrv);
|
newheap = cygheap_setup_for_child (&ciresrv, cygheap->fdtab.need_fixup_before ());
|
||||||
rc = CreateProcess (runpath, /* image name - with full path */
|
rc = CreateProcess (runpath, /* image name - with full path */
|
||||||
one_line.buf, /* what was passed to exec */
|
one_line.buf, /* what was passed to exec */
|
||||||
/* process security attrs */
|
/* process security attrs */
|
||||||
|
@ -659,7 +660,7 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv,
|
||||||
strcat (wstname, dskname);
|
strcat (wstname, dskname);
|
||||||
si.lpDesktop = wstname;
|
si.lpDesktop = wstname;
|
||||||
|
|
||||||
cygheap_setup_for_child (&ciresrv);
|
newheap = cygheap_setup_for_child (&ciresrv, cygheap->fdtab.need_fixup_before ());
|
||||||
rc = CreateProcessAsUser (hToken,
|
rc = CreateProcessAsUser (hToken,
|
||||||
runpath, /* image name - with full path */
|
runpath, /* image name - with full path */
|
||||||
one_line.buf, /* what was passed to exec */
|
one_line.buf, /* what was passed to exec */
|
||||||
|
@ -682,7 +683,6 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv,
|
||||||
MALLOC_CHECK;
|
MALLOC_CHECK;
|
||||||
if (envblock)
|
if (envblock)
|
||||||
free (envblock);
|
free (envblock);
|
||||||
cygheap_setup_for_child_cleanup (&ciresrv);
|
|
||||||
MALLOC_CHECK;
|
MALLOC_CHECK;
|
||||||
|
|
||||||
/* Set errno now so that debugging messages from it appear before our
|
/* Set errno now so that debugging messages from it appear before our
|
||||||
|
@ -694,14 +694,18 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv,
|
||||||
syscall_printf ("CreateProcess failed, %E");
|
syscall_printf ("CreateProcess failed, %E");
|
||||||
if (spr)
|
if (spr)
|
||||||
ForceCloseHandle (spr);
|
ForceCloseHandle (spr);
|
||||||
|
cygheap_setup_for_child_cleanup (newheap, &ciresrv, 0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fixup the parent datastructure if needed and resume the child's
|
/* Fixup the parent datastructure if needed and resume the child's
|
||||||
main thread. */
|
main thread. */
|
||||||
if (cygheap->fdtab.need_fixup_before ())
|
if (!cygheap->fdtab.need_fixup_before ())
|
||||||
|
cygheap_setup_for_child_cleanup (newheap, &ciresrv, 0);
|
||||||
|
else
|
||||||
{
|
{
|
||||||
cygheap->fdtab.fixup_before_exec (pi.dwProcessId);
|
cygheap->fdtab.fixup_before_exec (pi.dwProcessId);
|
||||||
|
cygheap_setup_for_child_cleanup (newheap, &ciresrv, 1);
|
||||||
if (mode == _P_OVERLAY)
|
if (mode == _P_OVERLAY)
|
||||||
ResumeThread (pi.hThread);
|
ResumeThread (pi.hThread);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue