e431827c7c
* cygtls.h (_cygtls::call_signal_handler): Rename from call_signal_handler_now. (_cygtls::push): Make second argument mandatory. (_cygtls::fixup_after_fork): Declare new function. (_cygtls::lock): Ditto. * cygtls.cc (_cygtls::fixup_after_fork): Define new function. * dcrt0.cc (cygwin_finished_initializing): Define as bool. (alloc_stack): Use _tlstop rather than arbitrary variable in probably vain attempt to avoid strange fork problem on CTRL-C. (dll_crt0_0): Remove obsolete winpids::init call. * dll_init.cc (dll_dllcrt0): Detect forkee condition as equivalent to initializing. * winsup.h (cygwin_finished_initializing): Declare as bool. * exceptions.cc (handle_exceptions): Rely on cygwin_finished_initializing to determine how to handle exception during process startup. (_cygtls::call_signal_handler): Rename from call_signal_handler_now. (_cygtls::interrupt_now): Fill in second argument to push. (signal_fixup_after_fork): Eliminate. (setup_handler): Initialize locked to avoid potential inappropriate unlock. Resume thread if it has acquired the stack lock. (ctrl_c_handler): Just exit if ctrl-c is hit before cygiwn has finished initializing. * fork.cc (sync_with_child): Don't call abort since it can cause exit deadlocks. (sync_with_child): Change debugging output slightly. (fork_child): Set cygwin_finished_initializing here. Call _cygtls fork fixup and explicitly call sigproc_init. (fork_parent): Release malloc lock on fork failure. (vfork): Call signal handler via _my_tls. * sigproc.cc (sig_send): Ditto. * syscalls.cc (readv): Ditto. * termios.cc (tcsetattr): Ditto. * wait.cc (wait4): Ditto. * signal.cc (nanosleep): Ditto. (abort): Ditto. (kill_pgrp): Avoid killing self if exiting. * sync.cc (muto::acquire): Remove (temporarily?) ill-advised exiting_thread check. * gendef (_sigfe): Be more agressive in protecting stack pointer from other access by signal thread. (_cygtls::locked): Define new function. (_sigbe): Ditto. (_cygtls::pop): Protect edx. (_cygtls::lock): Use guaranteed method to set eax to 1. (longjmp): Aggressively protect signal stack. * miscfuncs.cc (low_priority_sleep): Reduce "sleep time" for secs == 0. * pinfo.cc (winpids::set): Counterintuitively use malloc's lock to protect simultaneous access to the pids list since there are pathological conditions which can cause malloc to call winpid. (winpids::init): Eliminate. * pinfo.h (winpids::cs): Eliminate declaration. * pinfo.h (winpids::init): Eliminate definition.
98 lines
2.1 KiB
C++
98 lines
2.1 KiB
C++
/* perthread.h: Header file for cygwin thread-local storage.
|
|
|
|
Copyright 2000, 2001, 2002, 2003, 2004 Red Hat, Inc.
|
|
|
|
Written by Christopher Faylor <cgf@cygnus.com>
|
|
|
|
This file is part of Cygwin.
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
details. */
|
|
|
|
#define PTMAGIC 0x77366377
|
|
|
|
#define PER_THREAD_FORK_CLEAR ((void *)UINT32_MAX)
|
|
class per_thread
|
|
{
|
|
DWORD tls;
|
|
int clear_on_fork_p;
|
|
public:
|
|
per_thread (int forkval = 1) {tls = TlsAlloc (); clear_on_fork_p = forkval;}
|
|
DWORD get_tls () {return tls;}
|
|
int clear_on_fork () {return clear_on_fork_p;}
|
|
|
|
virtual void *get () {return TlsGetValue (get_tls ());}
|
|
virtual size_t size () {return 0;}
|
|
virtual void set (void *s = NULL);
|
|
virtual void set (int n) {TlsSetValue (get_tls (), (void *)n);}
|
|
virtual void *create ()
|
|
{
|
|
void *s = calloc (1, size ());
|
|
set (s);
|
|
return s;
|
|
}
|
|
};
|
|
|
|
class per_thread_waitq : public per_thread
|
|
{
|
|
public:
|
|
per_thread_waitq () : per_thread (0) {}
|
|
void *get () {return (waitq *) per_thread::get ();}
|
|
void *create () {return (waitq *) per_thread::create ();}
|
|
size_t size () {return sizeof (waitq);}
|
|
};
|
|
|
|
#ifdef NEED_VFORK
|
|
#include "cygtls.h"
|
|
#endif
|
|
|
|
#ifndef NEWVFORK
|
|
#define VFORKPID 0
|
|
#else
|
|
#if defined (NEED_VFORK)
|
|
class vfork_save
|
|
{
|
|
jmp_buf j;
|
|
int exitval;
|
|
public:
|
|
int pid;
|
|
DWORD frame[100];
|
|
_cygtls tls;
|
|
char **vfork_ebp;
|
|
char **vfork_esp;
|
|
int ctty;
|
|
pid_t sid;
|
|
pid_t pgid;
|
|
int open_fhs;
|
|
int is_active () { return pid < 0; }
|
|
void restore_pid (int val)
|
|
{
|
|
pid = val;
|
|
longjmp (j, 1);
|
|
}
|
|
void restore_exit (int val)
|
|
{
|
|
exitval = val;
|
|
longjmp (j, 1);
|
|
}
|
|
friend int vfork ();
|
|
};
|
|
|
|
class per_thread_vfork : public per_thread
|
|
{
|
|
public:
|
|
vfork_save *val () { return (vfork_save *) per_thread::get (); }
|
|
vfork_save *create () {return (vfork_save *) per_thread::create ();}
|
|
size_t size () {return sizeof (vfork_save);}
|
|
};
|
|
extern per_thread_vfork vfork_storage;
|
|
extern vfork_save *main_vfork;
|
|
#define VFORKPID main_vfork->pid
|
|
#endif
|
|
#endif /*NEWVFORK*/
|
|
|
|
extern per_thread_waitq waitq_storage;
|
|
|
|
extern per_thread *threadstuff[];
|