2002-12-05 04:46:16 +08:00
|
|
|
/* perthread.h: Header file for cygwin thread-local storage.
|
2000-07-01 11:52:33 +08:00
|
|
|
|
2004-02-09 12:04:24 +08:00
|
|
|
Copyright 2000, 2001, 2002, 2003, 2004 Red Hat, Inc.
|
2000-07-01 11:52:33 +08: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
|
|
|
|
|
2003-12-04 00:35:52 +08:00
|
|
|
#define PER_THREAD_FORK_CLEAR ((void *)UINT32_MAX)
|
2000-08-22 13:10:20 +08:00
|
|
|
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 ()
|
|
|
|
{
|
2004-01-21 03:36:35 +08:00
|
|
|
void *s = calloc (1, size ());
|
2000-08-22 13:10:20 +08:00
|
|
|
set (s);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class per_thread_waitq : public per_thread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
per_thread_waitq () : per_thread (0) {}
|
2003-02-04 11:01:17 +08:00
|
|
|
void *get () {return (waitq *) per_thread::get ();}
|
|
|
|
void *create () {return (waitq *) per_thread::create ();}
|
2000-08-22 13:10:20 +08:00
|
|
|
size_t size () {return sizeof (waitq);}
|
|
|
|
};
|
|
|
|
|
2004-01-24 07:05:33 +08:00
|
|
|
#ifdef NEED_VFORK
|
2003-11-29 04:55:59 +08:00
|
|
|
#include "cygtls.h"
|
2004-01-24 07:05:33 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef NEWVFORK
|
|
|
|
#define VFORKPID 0
|
|
|
|
#else
|
|
|
|
#if defined (NEED_VFORK)
|
2002-08-18 13:49:26 +08:00
|
|
|
class vfork_save
|
2000-08-22 13:10:20 +08:00
|
|
|
{
|
|
|
|
jmp_buf j;
|
2002-08-18 13:49:26 +08:00
|
|
|
int exitval;
|
|
|
|
public:
|
|
|
|
int pid;
|
2000-08-22 13:10:20 +08:00
|
|
|
DWORD frame[100];
|
2004-02-12 11:01:58 +08:00
|
|
|
_cygtls tls;
|
2000-08-22 13:10:20 +08:00
|
|
|
char **vfork_ebp;
|
|
|
|
char **vfork_esp;
|
2002-08-18 13:49:26 +08:00
|
|
|
int ctty;
|
|
|
|
pid_t sid;
|
|
|
|
pid_t pgid;
|
2003-12-30 09:57:16 +08:00
|
|
|
int open_fhs;
|
2000-08-22 13:10:20 +08:00
|
|
|
int is_active () { return pid < 0; }
|
2002-08-18 13:49:26 +08: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 13:10:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class per_thread_vfork : public per_thread
|
|
|
|
{
|
|
|
|
public:
|
2003-02-04 11:01:17 +08:00
|
|
|
vfork_save *val () { return (vfork_save *) per_thread::get (); }
|
|
|
|
vfork_save *create () {return (vfork_save *) per_thread::create ();}
|
2000-08-22 13:10:20 +08:00
|
|
|
size_t size () {return sizeof (vfork_save);}
|
|
|
|
};
|
2000-09-08 10:56:55 +08:00
|
|
|
extern per_thread_vfork vfork_storage;
|
2001-09-15 08:47:44 +08:00
|
|
|
extern vfork_save *main_vfork;
|
2004-01-24 07:05:33 +08:00
|
|
|
#define VFORKPID main_vfork->pid
|
2000-09-08 10:56:55 +08:00
|
|
|
#endif
|
2004-01-24 07:05:33 +08:00
|
|
|
#endif /*NEWVFORK*/
|
2000-08-22 13:10:20 +08:00
|
|
|
|
|
|
|
extern per_thread_waitq waitq_storage;
|
|
|
|
|
|
|
|
extern per_thread *threadstuff[];
|