* cygthread.cc (cygthread::stub): Properly establish _threadinfo environment.

(cygthread::stub2): New function.
(cygthread::simplestub): Ditto.
(cygthread::simplestub2): New function.
* cygthread.h (cygthread::stub2): Declare new function.
(cygthread::simplestub2): Ditto.
* cygtls.h (_threadinfo::call): Declare new function.
(_threadinfo::call2): Ditto.
* dcrt0.cc (dll_crt0_1): Accommodate new _threadinfo::init which doesn't return
pointer to tls.
(_dll_crt0): Remove obsolete DECLARE_TLS_STORAGE.
(dll_crt0): Ditto.
* exceptions.cc (_threadinfo::call): New function.
(_threadinfo::call2): Ditto.
(_threadinfo::init): Don't return pointer.
* thread.cc (pthread::thread_init_wrapper): Properly establish _threadinfo
environment.
(pthread::thread_init_wrapper2): New function.
* thread.h (pthread::thread_init_wrapper): Remove noreturn attribute
(pthread::thread_init_wrapper2): Declare new function.
* winbase.h: Remove obsolete code.
This commit is contained in:
Christopher Faylor 2003-12-03 05:21:55 +00:00
parent af9ef8abb2
commit d1eb7a4615
9 changed files with 80 additions and 64 deletions

View File

@ -1,3 +1,28 @@
2003-12-03 Christopher Faylor <cgf@redhat.com>
* cygthread.cc (cygthread::stub): Properly establish _threadinfo
environment.
(cygthread::stub2): New function.
(cygthread::simplestub): Ditto.
(cygthread::simplestub2): New function.
* cygthread.h (cygthread::stub2): Declare new function.
(cygthread::simplestub2): Ditto.
* cygtls.h (_threadinfo::call): Declare new function.
(_threadinfo::call2): Ditto.
* dcrt0.cc (dll_crt0_1): Accommodate new _threadinfo::init which
doesn't return pointer to tls.
(_dll_crt0): Remove obsolete DECLARE_TLS_STORAGE.
(dll_crt0): Ditto.
* exceptions.cc (_threadinfo::call): New function.
(_threadinfo::call2): Ditto.
(_threadinfo::init): Don't return pointer.
* thread.cc (pthread::thread_init_wrapper): Properly establish
_threadinfo environment.
(pthread::thread_init_wrapper2): New function.
* thread.h (pthread::thread_init_wrapper): Remove noreturn attribute
(pthread::thread_init_wrapper2): Declare new function.
* winbase.h: Remove obsolete code.
2003-12-02 Christopher Faylor <cgf@redhat.com>
* Makefile.in: Change the way that -f options are appended to CFLAGS,

View File

@ -15,6 +15,8 @@ details. */
#include "sync.h"
#include "cygerrno.h"
#include "sigproc.h"
#include "thread.h"
#include "cygtls.h"
#undef CloseHandle
@ -30,13 +32,20 @@ bool NO_COPY cygthread::exiting;
DWORD WINAPI
cygthread::stub (VOID *arg)
{
DECLARE_TLS_STORAGE;
_threadinfo::call (stub2, arg);
return 0;
}
void
cygthread::stub2 (void *arg, void *)
{
exception_list except_entry;
/* Initialize this thread's ability to respond to things like
SIGSEGV or SIGFPE. */
init_exceptions (&except_entry);
cygthread *info = (cygthread *) arg;
if (info->arg == cygself)
{
@ -91,7 +100,13 @@ cygthread::stub (VOID *arg)
DWORD WINAPI
cygthread::simplestub (VOID *arg)
{
DECLARE_TLS_STORAGE;
_threadinfo::call (simplestub2, arg);
return 0;
}
void
cygthread::simplestub2 (void *arg, void *)
{
exception_list except_entry;
/* Initialize this thread's ability to respond to things like

View File

@ -20,7 +20,9 @@ class cygthread
bool is_freerange;
static bool exiting;
static DWORD WINAPI stub (VOID *);
static void stub2 (void *, void *);
static DWORD WINAPI simplestub (VOID *);
static void simplestub2 (void *, void *);
void terminate_thread ();
public:
static DWORD main_thread_id;

View File

@ -40,7 +40,9 @@ struct _threadinfo
int sig;
__stack_t *stackptr;
struct _threadinfo *init (void *, void * = NULL);
void init (void *);
static void call (void (*) (void *, void *), void *);
void call2 (void (*) (void *, void *), void *, void *);
void remove ();
void push (__stack_t, bool = false);
__stack_t pop ();

View File

@ -532,8 +532,9 @@ _threadinfo NO_COPY *_main_tls;
static void
dll_crt0_1 ()
{
__uint64_t padding[CYGTLS_PADSIZE];
_main_tls = _my_tls.init (padding);
char padding[CYGTLS_PADSIZE];
_main_tls = &_my_tls;
_main_tls->init (padding);
/* According to onno@stack.urc.tue.nl, the exception handler record must
be on the stack. */
@ -838,7 +839,6 @@ initial_env ()
extern "C" void __stdcall
_dll_crt0 ()
{
DECLARE_TLS_STORAGE;
initial_env ();
char zeros[sizeof (fork_info->zero)] = {0};
static NO_COPY STARTUPINFO si;
@ -907,7 +907,6 @@ _dll_crt0 ()
void
dll_crt0 (per_process *uptr)
{
DECLARE_TLS_STORAGE;
/* Set the local copy of the pointer into the user space. */
if (uptr && uptr != user_data)
{

View File

@ -147,8 +147,22 @@ _threadinfo::reset_exception ()
}
}
_threadinfo *
_threadinfo::init (void *, void *thread)
void
_threadinfo::call (void (*func) (void *, void *), void *arg)
{
char buf[CYGTLS_PADSIZE];
_my_tls.call2 (func, arg, buf);
}
void
_threadinfo::call2 (void (*func) (void *, void *), void *arg, void *buf)
{
init (buf);
func (arg, buf);
}
void
_threadinfo::init (void *)
{
memset (this, 0, sizeof (*this));
stackptr = stack;
@ -157,7 +171,6 @@ _threadinfo::init (void *, void *thread)
_last_thread = this;
set_state (false);
errno_addr = &errno;
return this;
}
void

View File

@ -1885,14 +1885,10 @@ __reent_t::init_clib (struct _reent& var)
_clib = &var;
};
/* Pthreads */
void *
pthread::thread_init_wrapper (void *_arg)
void
pthread::thread_init_wrapper2 (void *arg, void *)
{
// Setup the local/global storage of this thread
__uint64_t padding[CYGTLS_PADSIZE];
pthread *thread = (pthread *) _arg;
thread->cygtls = _my_tls.init (padding, &thread);
pthread *thread = (pthread *) arg;
_my_tls.tid = thread;
exception_list cygwin_except_entry;
@ -1923,7 +1919,7 @@ pthread::thread_init_wrapper (void *_arg)
system_printf ("local storage for thread isn't setup correctly");
#endif
thread_printf ("started thread %p %p %p %p %p %p", _arg, &local_clib,
thread_printf ("started thread %p %p %p %p %p %p", arg, &local_clib,
_impure_ptr, thread, thread->function, thread->arg);
// call the user's thread
@ -1932,6 +1928,14 @@ pthread::thread_init_wrapper (void *_arg)
thread->exit (ret);
}
/* Pthreads */
void
pthread::thread_init_wrapper (void *arg)
{
// calls thread_init_wrapper2. Never returns.
_threadinfo::call (thread_init_wrapper2, arg);
}
bool
pthread::is_good_object (pthread_t const *thread)
{

View File

@ -502,7 +502,8 @@ public:
virtual void pop_cleanup_handler (int const execute);
static pthread* self ();
static void *thread_init_wrapper (void *) __attribute__ ((noreturn));
static void thread_init_wrapper (void *);
static void thread_init_wrapper2 (void *, void *);
virtual unsigned long getsequence_np();

View File

@ -56,49 +56,4 @@ ilockcmpexch (long *t, long v, long c)
#define InterlockedExchange ilockexch
#undef InterlockedCompareExchange
#define InterlockedCompareExchange ilockcmpexch
// extern char * volatile *__stackbase __asm__ ("%fs:4");
#ifndef EXPCGf
#define DECLARE_TLS_STORAGE do {} while (0)
#else
#define DECLARE_TLS_STORAGE char **tls[4096] __attribute__ ((unused))
extern long tls_ix;
extern __inline__ DWORD
my_tlsalloc ()
{
DWORD n = ilockdecr (&tls_ix);
__stackbase[tls_ix] = NULL;
return n;
}
extern __inline__ BOOL
my_tlssetvalue (DWORD ix, void *val)
{
__stackbase[ix] = (char *) val;
return 1;
}
extern __inline__ void *
my_tlsgetvalue (DWORD ix)
{
return __stackbase[ix];
}
extern __inline__ BOOL
my_tlsfree (DWORD ix)
{
/* nothing for now */
return 1;
}
#undef TlsAlloc
#define TlsAlloc my_tlsalloc
#undef TlsGetValue
#define TlsGetValue my_tlsgetvalue
#undef TlsSetValue
#define TlsSetValue my_tlssetvalue
#undef TlsFree
#define TlsFree my_tlsfree
#endif /*EXPCGF*/
#endif /*_WINBASE2_H*/