* dcrt0.cc (getstack): New function.

(alloc_stack): Use tls stuff for stack info rather than calling VirtualQuery.
(dll_crt0_0): Initialize _impure_ptr stuff much earlier.  Move
init_console_handler here.
* fork.cc (class frok): New class renamed from local fork() struct.
(stack_base): Change argument type.  Use tls stuff to determine stack info
rather than calling VirtualQuery.
(frok::child): Rename from fork_child.  Eliminate now unneeded arguments.
(frok::parent): Rename from fork_parent and ditto.  Set error and errno as
appropriate.  Fixup impersonation in cleanup, if needed.  Try harder to set
errno appropriately.
(fork): Define "grouped" as a frok type.  Deal with errors from fork_parent
here.
* init.cc (dll_entry): Remove init_console_handler call.
This commit is contained in:
Christopher Faylor
2005-09-28 15:18:49 +00:00
parent 9edadc960e
commit 280fdd0b67
4 changed files with 131 additions and 64 deletions

View File

@@ -502,22 +502,29 @@ alloc_stack_hard_way (child_info_fork *ci, volatile char *b)
b[0] = '\0';
}
void *getstack (void *) __attribute__ ((noinline));
volatile char *
getstack (volatile char *p)
{
*p |= 0;
return p - 4096;
}
/* extend the stack prior to fork longjmp */
static void
alloc_stack (child_info_fork *ci)
{
/* FIXME: adding 16384 seems to avoid a stack copy problem during
fork on Win95, but I don't know exactly why yet. DJ */
volatile char b[ci->stacksize + 16384];
if (!VirtualQuery ((LPCVOID) &b, &sm, sizeof sm))
api_fatal ("fork: couldn't get stack info, %E");
if (sm.AllocationBase == ci->stacktop)
ci->stacksize = 0;
volatile char *esp;
__asm__ volatile ("movl %%esp,%0": "=r" (esp));
if (_tlsbase != ci->stackbottom)
alloc_stack_hard_way (ci, esp);
else
alloc_stack_hard_way (ci, b + sizeof (b) - 1);
{
while (_tlstop > ci->stacktop)
esp = getstack (esp);
ci->stacksize = 0;
}
}
#ifdef DEBUGGING
@@ -629,6 +636,12 @@ get_cygwin_startup_info ()
void __stdcall
dll_crt0_0 ()
{
init_console_handler (TRUE);
_impure_ptr = _GLOBAL_REENT;
_impure_ptr->_stdin = &_impure_ptr->__sf[0];
_impure_ptr->_stdout = &_impure_ptr->__sf[1];
_impure_ptr->_stderr = &_impure_ptr->__sf[2];
_impure_ptr->_current_locale = "C";
wincap.init ();
initial_env ();
@@ -931,11 +944,6 @@ _dll_crt0 ()
*main_environ = NULL;
char padding[CYGTLS_PADSIZE];
_impure_ptr = _GLOBAL_REENT;
_impure_ptr->_stdin = &_impure_ptr->__sf[0];
_impure_ptr->_stdout = &_impure_ptr->__sf[1];
_impure_ptr->_stderr = &_impure_ptr->__sf[2];
_impure_ptr->_current_locale = "C";
if (child_proc_info && child_proc_info->type == _PROC_FORK)
user_data->forkee = true;