2002-12-04 21:46:16 +01:00
|
|
|
/* perthread.h: Header file for cygwin thread-local storage.
|
2000-07-01 05:52:33 +02:00
|
|
|
|
2002-12-04 21:46:16 +01:00
|
|
|
Copyright 2000, 2001, 2002 Red Hat, Inc.
|
2000-07-01 05:52:33 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
struct _reent;
|
|
|
|
extern struct _reent reent_data;
|
|
|
|
|
2000-08-22 07:10:20 +02:00
|
|
|
#define PER_THREAD_FORK_CLEAR ((void *)0xffffffff)
|
|
|
|
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 = new char [size ()];
|
|
|
|
memset (s, 0, size ());
|
|
|
|
set (s);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class per_thread_waitq : public per_thread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
per_thread_waitq () : per_thread (0) {}
|
2003-02-04 04:01:17 +01:00
|
|
|
void *get () {return (waitq *) per_thread::get ();}
|
|
|
|
void *create () {return (waitq *) per_thread::create ();}
|
2000-08-22 07:10:20 +02:00
|
|
|
size_t size () {return sizeof (waitq);}
|
|
|
|
};
|
|
|
|
|
2001-09-15 02:47:44 +02:00
|
|
|
#if defined (NEED_VFORK)
|
2002-08-18 07:49:26 +02:00
|
|
|
class vfork_save
|
2000-08-22 07:10:20 +02:00
|
|
|
{
|
|
|
|
jmp_buf j;
|
2002-08-18 07:49:26 +02:00
|
|
|
int exitval;
|
|
|
|
public:
|
|
|
|
int pid;
|
2000-08-22 07:10:20 +02:00
|
|
|
DWORD frame[100];
|
|
|
|
char **vfork_ebp;
|
|
|
|
char **vfork_esp;
|
2002-08-18 07:49:26 +02:00
|
|
|
int ctty;
|
|
|
|
pid_t sid;
|
|
|
|
pid_t pgid;
|
2000-08-22 07:10:20 +02:00
|
|
|
int is_active () { return pid < 0; }
|
2002-08-18 07:49:26 +02:00
|
|
|
void restore_pid (int val)
|
|
|
|
{
|
|
|
|
pid = val;
|
|
|
|
longjmp (j, 1);
|
|
|
|
}
|
|
|
|
void restore_exit (int val)
|
|
|
|
{
|
|
|
|
exitval = val;
|
|
|
|
longjmp (j, 1);
|
|
|
|
}
|
|
|
|
friend int vfork ();
|
2000-08-22 07:10:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class per_thread_vfork : public per_thread
|
|
|
|
{
|
|
|
|
public:
|
2003-02-04 04:01:17 +01:00
|
|
|
vfork_save *val () { return (vfork_save *) per_thread::get (); }
|
|
|
|
vfork_save *create () {return (vfork_save *) per_thread::create ();}
|
2000-08-22 07:10:20 +02:00
|
|
|
size_t size () {return sizeof (vfork_save);}
|
|
|
|
};
|
2000-09-08 04:56:55 +02:00
|
|
|
extern per_thread_vfork vfork_storage;
|
2001-09-15 02:47:44 +02:00
|
|
|
extern vfork_save *main_vfork;
|
2000-09-08 04:56:55 +02:00
|
|
|
#endif
|
2000-08-22 07:10:20 +02:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
struct signal_dispatch
|
|
|
|
{
|
|
|
|
int arg;
|
|
|
|
void (*func) (int);
|
|
|
|
int sig;
|
|
|
|
int saved_errno;
|
2001-01-12 06:38:25 +01:00
|
|
|
int sa_flags;
|
2000-08-22 07:10:20 +02:00
|
|
|
DWORD oldmask;
|
2000-11-16 06:16:59 +01:00
|
|
|
DWORD newmask;
|
2000-08-22 07:10:20 +02:00
|
|
|
DWORD retaddr;
|
|
|
|
DWORD *retaddr_on_stack;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct per_thread_signal_dispatch : public per_thread
|
|
|
|
{
|
2003-02-04 04:01:17 +01:00
|
|
|
signal_dispatch *get () { return (signal_dispatch *) per_thread::get (); }
|
|
|
|
signal_dispatch *create () {return (signal_dispatch *) per_thread::create ();}
|
2000-08-22 07:10:20 +02:00
|
|
|
size_t size () {return sizeof (signal_dispatch);}
|
|
|
|
};
|
|
|
|
|
|
|
|
extern per_thread_waitq waitq_storage;
|
|
|
|
extern per_thread_signal_dispatch signal_dispatch_storage;
|
|
|
|
|
|
|
|
extern per_thread *threadstuff[];
|