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
|
|
|
|
2004-02-09 05:04:24 +01:00
|
|
|
Copyright 2000, 2001, 2002, 2003, 2004 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
|
|
|
|
|
2003-12-03 17:35:52 +01:00
|
|
|
#define PER_THREAD_FORK_CLEAR ((void *)UINT32_MAX)
|
2000-08-22 07:10:20 +02: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-20 20:36:35 +01:00
|
|
|
void *s = calloc (1, size ());
|
2000-08-22 07:10:20 +02:00
|
|
|
set (s);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-01-24 00:05:33 +01:00
|
|
|
#ifdef NEED_VFORK
|
2003-11-28 21:55:59 +01:00
|
|
|
#include "cygtls.h"
|
2004-01-24 00:05:33 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef NEWVFORK
|
|
|
|
#define VFORKPID 0
|
|
|
|
#else
|
|
|
|
#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];
|
2004-02-12 04:01:58 +01:00
|
|
|
_cygtls tls;
|
2000-08-22 07:10:20 +02:00
|
|
|
char **vfork_ebp;
|
|
|
|
char **vfork_esp;
|
2002-08-18 07:49:26 +02:00
|
|
|
int ctty;
|
|
|
|
pid_t sid;
|
|
|
|
pid_t pgid;
|
2003-12-30 02:57:16 +01:00
|
|
|
int open_fhs;
|
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;
|
2004-01-24 00:05:33 +01:00
|
|
|
#define VFORKPID main_vfork->pid
|
2000-09-08 04:56:55 +02:00
|
|
|
#endif
|
2004-01-24 00:05:33 +01:00
|
|
|
#endif /*NEWVFORK*/
|
2000-08-22 07:10:20 +02:00
|
|
|
|
|
|
|
extern per_thread *threadstuff[];
|