Eliminate use of sigframe and sigthread throughout.
* Makefile.in (DLL_OFILES): Add sigfe.o. Remove reliance on cygwin.def from cygwin0.dll dependency since dependence on sigfe.o implies that. Generate def file on the fly using 'gendef'. * configure.in: Don't auto-generate cygwin.def. * configure: Regenerate. * cygwin.din: Add SIGFE stuff where appropriate. * dcrt0.cc (dll_crt0_1): Initialize cygwin tls early in process startup. Set _main_tls to address of the main thread's cygwin tls. * debug.h: Remove now unneeded WFSO and WFMO declarations. * exceptions.cc (_last_thread): Define. (set_thread_state_for_signals): New function. (reset_thread_exception_for_signals): Ditto. (init_thread_for_signals): Ditto. (delete_thread_for_signals): Ditto. (capture_thread_for_signals): Ditto. (handle_exceptions): Set return address explicitly for exceptions prior to calling sig_send. (interrupt_on_return): Eliminate. (setup_handler): Add preliminary implementation for dealing with thread-specific signals by querying _main_tls. (signal_exit): Use cygthread::main_thread_id instead of mainthread.id. (call_signal_handler_now): For now, just handle the main thread. * fork.cc (vfork): Save and restore main _my_tls. * gendef: New file. Generates def file and sigfe.s file. * gentls_offsets: New file. Generates offsets for perl to use in sigfe.s. * how-signals-work.txt: Mention that info is obsolete. * init.cc (dll_entry): Initialize cygwin tls storage here. * miscfuncs.cc (low_priority_sleep): Make a C function for easier calling from asm. * perthread.h (vfork_save::tls): New element. * signal.cc (nanosleep): Replace previous use of sigframe.call_signal_handler_now with straight call to call_signal_handler_now. (abort): Ditto. * syscalls.cc (readv): Ditto. * termios.cc (tcsetattr): Ditto. * wait.cc (wait4): Ditto. * sigproc.cc (sig_dispatch_pending): Ditto. (sig_send): Ditto. * sigproc.h: Declare call_signal_handler_now. * thread.cc (pthread::thread_init_wrapper): Initialize cygwin tls. Remove obsolete and unworking signal stuff. * thread.h (verifyable_object::sigs): Eliminate. (verifyable_object::sigmask): Eliminate. (verifyable_object::sigtodo): Eliminate. (verifyable_object::exit): Make attribute noreturn. (verifyable_object::thread_init_wrapper): Ditto. (pthread_null::exit): Ditto. * winbase.h (__stackbase): Always define. * winsup.h (low_priority_sleep): Declare as a "C" function. * include/cygwin/version.h: Bump API version to reflect sigwait export. * include/sys/queue.h: Protect SLIST_ENTRY from previous declaration. * signal.cc (sigwait): Implement. * select.cc (fhandler_base::ready_for_read): Add debugging output. * devices.h: Define more device pointers via their storage. * devices.in: Don't parse things like /dev/inet/tcp, as they really have no meaning. * devices.cc: Regenerate. * gendevices: Set proper protection for output file. * cygtls.h: New file. * gendef: New file. * gentls_offsets: New file. * tlsoffsets.h: New file. Autogenerated. * config/i386/longjmp.c: Remove. File subsumed by gendef output. * config/i386/makefrag: Remove obsolete file. * fhandler.cc: Remove spurious access_worker declaration. * spawn.cc (spawnve): Make debugging output more accurate. * cygwin-gperf: Remove. * devices.cc: Remove.
This commit is contained in:
@ -36,12 +36,14 @@ details. */
|
||||
#include <stdlib.h>
|
||||
#include <syslog.h>
|
||||
#include "pinfo.h"
|
||||
#include "sigproc.h"
|
||||
#include "perprocess.h"
|
||||
#include "security.h"
|
||||
#include "exceptions.h"
|
||||
#include "cygtls.h"
|
||||
#include <semaphore.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <exceptions.h>
|
||||
#include <sys/fcntl.h>
|
||||
|
||||
extern int threadsafe;
|
||||
@ -191,7 +193,6 @@ MTinterface::fixup_after_fork (void)
|
||||
{
|
||||
pthread_key::fixup_after_fork ();
|
||||
|
||||
#ifndef __SIGNALS_ARE_MULTITHREADED__
|
||||
/* As long as the signal handling not multithreaded
|
||||
switch reents storage back to _impure_ptr for the mainthread
|
||||
to support fork from threads other than the mainthread */
|
||||
@ -199,9 +200,8 @@ MTinterface::fixup_after_fork (void)
|
||||
reents._winsup = &winsup_reent;
|
||||
winsup_reent._process_logmask = LOG_UPTO (LOG_DEBUG);
|
||||
reent_key.set (&reents);
|
||||
#endif
|
||||
|
||||
threadcount = 1;
|
||||
threadcount = 0;
|
||||
pthread::init_mainthread ();
|
||||
|
||||
pthread::fixup_after_fork ();
|
||||
@ -225,7 +225,15 @@ pthread::init_mainthread ()
|
||||
api_fatal ("failed to create mainthread object");
|
||||
}
|
||||
|
||||
thread->init_current_thread ();
|
||||
thread->cygtls = &_my_tls;
|
||||
_my_tls.tid = thread;
|
||||
thread->thread_id = GetCurrentThreadId ();
|
||||
if (!DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
|
||||
GetCurrentProcess (), &thread->win32_obj_id,
|
||||
0, FALSE, DUPLICATE_SAME_ACCESS))
|
||||
thread->win32_obj_id = NULL;
|
||||
thread->set_tls_self_pointer ();
|
||||
thread->postcreate ();
|
||||
}
|
||||
|
||||
pthread *
|
||||
@ -238,9 +246,9 @@ pthread::self ()
|
||||
}
|
||||
|
||||
void
|
||||
pthread::set_tls_self_pointer (pthread *thisThread)
|
||||
pthread::set_tls_self_pointer ()
|
||||
{
|
||||
MT_INTERFACE->thread_self_key.set (thisThread);
|
||||
MT_INTERFACE->thread_self_key.set (this);
|
||||
}
|
||||
|
||||
pthread *
|
||||
@ -274,12 +282,6 @@ pthread::~pthread ()
|
||||
threads.remove (this);
|
||||
}
|
||||
|
||||
void
|
||||
pthread::set_thread_id_to_current ()
|
||||
{
|
||||
thread_id = GetCurrentThreadId ();
|
||||
}
|
||||
|
||||
void
|
||||
pthread::precreate (pthread_attr *newattr)
|
||||
{
|
||||
@ -334,7 +336,7 @@ pthread::create (void *(*func) (void *), pthread_attr *newattr,
|
||||
|
||||
if (!win32_obj_id)
|
||||
{
|
||||
thread_printf ("CreateThread failed: this %p LastError %E", this);
|
||||
thread_printf ("CreateThread failed: this %p, %E", this);
|
||||
magic = 0;
|
||||
}
|
||||
else
|
||||
@ -347,6 +349,15 @@ pthread::create (void *(*func) (void *), pthread_attr *newattr,
|
||||
void
|
||||
pthread::postcreate ()
|
||||
{
|
||||
cancel_event = ::CreateEvent (&sec_none_nih, TRUE, FALSE, NULL);
|
||||
if (!cancel_event)
|
||||
{
|
||||
system_printf ("couldn't create cancel event for main thread, %E");
|
||||
/* we need the event for correct behaviour */
|
||||
magic = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
valid = true;
|
||||
|
||||
InterlockedIncrement (&MT_INTERFACE->threadcount);
|
||||
@ -737,19 +748,6 @@ pthread::get_thread_id ()
|
||||
return thread_id;
|
||||
}
|
||||
|
||||
void
|
||||
pthread::init_current_thread ()
|
||||
{
|
||||
cancel_event = ::CreateEvent (&sec_none_nih, TRUE, FALSE, NULL);
|
||||
if (!DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
|
||||
GetCurrentProcess (), &win32_obj_id,
|
||||
0, FALSE, DUPLICATE_SAME_ACCESS))
|
||||
win32_obj_id = NULL;
|
||||
set_thread_id_to_current ();
|
||||
set_tls_self_pointer (this);
|
||||
valid = true;
|
||||
}
|
||||
|
||||
void
|
||||
pthread::_fixup_after_fork ()
|
||||
{
|
||||
@ -1892,27 +1890,19 @@ void *
|
||||
pthread::thread_init_wrapper (void *_arg)
|
||||
{
|
||||
// Setup the local/global storage of this thread
|
||||
|
||||
__uint64_t padding[CYGTLS_PADSIZE];
|
||||
pthread *thread = (pthread *) _arg;
|
||||
thread->cygtls = _my_tls.init (padding, &thread);
|
||||
_my_tls.tid = thread;
|
||||
|
||||
exception_list cygwin_except_entry;
|
||||
init_exceptions (&cygwin_except_entry); /* Initialize SIGSEGV handling, etc. */
|
||||
|
||||
thread->set_tls_self_pointer ();
|
||||
struct __reent_t local_reent;
|
||||
struct _winsup_t local_winsup;
|
||||
struct _reent local_clib;
|
||||
|
||||
struct sigaction _sigs[NSIG];
|
||||
sigset_t _sig_mask; /* one set for everything to ignore. */
|
||||
|
||||
/* According to onno@stack.urc.tue.nl, the exception handler record must
|
||||
be on the stack. */
|
||||
exception_list cygwin_except_entry;
|
||||
|
||||
/* Initialize SIGSEGV handling, etc. */
|
||||
init_exceptions (&cygwin_except_entry);
|
||||
|
||||
// setup signal structures
|
||||
thread->sigs = _sigs;
|
||||
thread->sigmask = &_sig_mask;
|
||||
thread->sigtodo = NULL;
|
||||
|
||||
memset (&local_winsup, 0, sizeof (struct _winsup_t));
|
||||
|
||||
local_reent.init_clib (local_clib);
|
||||
@ -1922,9 +1912,6 @@ pthread::thread_init_wrapper (void *_arg)
|
||||
|
||||
MT_INTERFACE->reent_key.set (&local_reent);
|
||||
|
||||
thread->set_thread_id_to_current ();
|
||||
set_tls_self_pointer (thread);
|
||||
|
||||
thread->mutex.lock ();
|
||||
// if thread is detached force cleanup on exit
|
||||
if (thread->attr.joinable == PTHREAD_CREATE_DETACHED && thread->joiner == NULL)
|
||||
@ -1943,13 +1930,6 @@ pthread::thread_init_wrapper (void *_arg)
|
||||
void *ret = thread->function (thread->arg);
|
||||
|
||||
thread->exit (ret);
|
||||
|
||||
#if 0
|
||||
// ??? This code only runs if the thread exits by returning.
|
||||
// it's all now in __pthread_exit ();
|
||||
#endif
|
||||
/* never reached */
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool
|
||||
@ -1970,7 +1950,6 @@ int
|
||||
pthread::create (pthread_t *thread, const pthread_attr_t *attr,
|
||||
void *(*start_routine) (void *), void *arg)
|
||||
{
|
||||
DECLARE_TLS_STORAGE;
|
||||
if (attr && !pthread_attr::is_good_object (attr))
|
||||
return EINVAL;
|
||||
|
||||
@ -2904,7 +2883,7 @@ pthread_kill (pthread_t thread, int sig)
|
||||
if (!pthread::is_good_object (&thread))
|
||||
return EINVAL;
|
||||
|
||||
int rval = raise (sig);
|
||||
int rval = sig ? sig_send (NULL, sig, thread->cygtls) : 0;
|
||||
|
||||
// unlock myself
|
||||
return rval;
|
||||
@ -2913,11 +2892,7 @@ pthread_kill (pthread_t thread, int sig)
|
||||
extern "C" int
|
||||
pthread_sigmask (int operation, const sigset_t *set, sigset_t *old_set)
|
||||
{
|
||||
int rval = sigprocmask (operation, set, old_set);
|
||||
|
||||
// unlock this myself
|
||||
|
||||
return rval;
|
||||
return handle_sigprocmask (operation, set, old_set, _my_tls.sigmask);
|
||||
}
|
||||
|
||||
/* ID */
|
||||
|
Reference in New Issue
Block a user