OSDN Git Service

* cygtls.cc (_cygtls::remove): Call remove_wq to ensure that wait stuff is
[pf3gnuchains/sourceware.git] / winsup / cygwin / cygtls.h
1 /* cygtls.h
2
3    Copyright 2003, 2004 Red Hat, Inc.
4
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
7 details. */
8
9 #ifndef _CYGTLS_H
10 #define _CYGTLS_H
11
12 #include <signal.h>
13 #include <pwd.h>
14 #include <grp.h>
15 #include <sys/time.h>
16 #define _NOMNTENT_FUNCS
17 #include <mntent.h>
18 #undef _NOMNTENT_FUNCS
19
20 #define CYGTLS_INITIALIZED 0x43227
21 #define CYGTLS_EXCEPTION (0x43227 + true)
22
23 #ifndef CYG_MAX_PATH
24 # define CYG_MAX_PATH 260
25 #endif
26
27 #ifndef UNLEN
28 # define UNLEN 256
29 #endif
30
31 #define TLS_STACK_SIZE 256
32
33 #pragma pack(push,4)
34 struct _local_storage
35 {
36   /*
37      Needed for the group functions
38    */
39   struct __group16 grp;
40   char *namearray[2];
41   int grp_pos;
42
43   /* console.cc */
44   unsigned rarg;
45
46   /* dlfcn.cc */
47   int dl_error;
48   char dl_buffer[256];
49
50   /* passwd.cc */
51   struct passwd res;
52   char pass[_PASSWORD_LEN];
53   int pw_pos;
54
55   /* path.cc */
56   struct mntent mntbuf;
57   int iteration;
58   unsigned available_drives;
59   char mnt_type[80];
60   char mnt_opts[80];
61   char mnt_fsname[CYG_MAX_PATH];
62   char mnt_dir[CYG_MAX_PATH];
63
64   /* strerror */
65   char strerror_buf[20];
66
67   /* sysloc.cc */
68   char *process_ident;
69   int process_logopt;
70   int process_facility;
71   int process_logmask;
72
73   /* times.cc */
74   char timezone_buf[20];
75   struct tm _localtime_buf;
76
77   /* uinfo.cc */
78   char username[UNLEN + 1];
79
80   /* net.cc */
81   char *ntoa_buf;
82   struct protoent *protoent_buf;
83   struct servent *servent_buf;
84   struct hostent *hostent_buf;
85   char signamebuf[sizeof ("Unknown signal 4294967295   ")];
86 };
87
88 typedef struct struct_waitq
89 {
90   int pid;
91   int options;
92   int status;
93   HANDLE ev;
94   void *rusage;                 /* pointer to potential rusage */
95   struct struct_waitq *next;
96   HANDLE thread_ev;
97 } waitq;
98
99 /* Changes to the below structure may require acompanying changes to the very
100    simple parser in the perl script 'gentls_offsets' (<<-- start parsing here).
101 */
102
103 typedef __uint32_t __stack_t;
104 struct _cygtls
105 {
106   void (*func) /*gentls_offsets*/(int)/*gentls_offsets*/;
107   int saved_errno;
108   int sa_flags;
109   sigset_t oldmask;
110   sigset_t deltamask;
111   HANDLE event;
112   int *errno_addr;
113   unsigned initialized;
114   sigset_t sigmask;
115   sigset_t sigwait_mask;
116   siginfo_t *sigwait_info;
117   unsigned threadkill;
118   siginfo_t infodata;
119   struct pthread *tid;
120   struct _reent local_clib;
121   struct _local_storage locals;
122   waitq wq;
123   struct _cygtls *prev, *next;
124   __stack_t *stackptr;
125   int sig;
126   unsigned incyg;
127   unsigned spinning;
128   unsigned stacklock;
129   __stack_t stack[TLS_STACK_SIZE];
130   unsigned padding[0];
131
132   /*gentls_offsets*/
133   static CRITICAL_SECTION protect_linked_list;
134   static void init ();
135   void init_thread (void *, DWORD (*) (void *, void *));
136   static void call (DWORD (*) (void *, void *), void *);
137   static void call2 (DWORD (*) (void *, void *), void *, void *) __attribute__ ((regparm (3)));
138   static struct _cygtls *find_tls (int sig);
139   void remove (DWORD);
140   void push (__stack_t, bool) __attribute__ ((regparm (3)));
141   __stack_t pop () __attribute__ ((regparm (1)));
142   bool isinitialized () const {return initialized == CYGTLS_INITIALIZED || initialized == CYGTLS_EXCEPTION;}
143   bool in_exception () const {return initialized == CYGTLS_EXCEPTION;}
144   void set_state (bool);
145   void reset_exception ();
146   bool interrupt_now (CONTEXT *, int, void *, struct sigaction&)
147     __attribute__((regparm(3)));
148   void __stdcall interrupt_setup (int sig, void *handler,
149                                   struct sigaction& siga)
150     __attribute__((regparm(3)));
151   void init_threadlist_exceptions (struct _exception_list *);
152   operator HANDLE () const {return tid->win32_obj_id;}
153   void set_siginfo (struct sigpacket *) __attribute__ ((regparm (3)));
154   void set_threadkill () {threadkill = true;}
155   void reset_threadkill () {threadkill = false;}
156   int call_signal_handler () __attribute__ ((regparm (1)));
157   void remove_wq () __attribute__ ((regparm (1)));
158   void fixup_after_fork () __attribute__ ((regparm (1)));
159   void lock () __attribute__ ((regparm (1)));
160   void unlock () __attribute__ ((regparm (1)));
161   bool locked () __attribute__ ((regparm (1)));
162   /*gentls_offsets*/
163 };
164 #pragma pack(pop)
165
166 extern char *_tlsbase __asm__ ("%fs:4");
167 extern char *_tlstop __asm__ ("%fs:8");
168 #define _my_tls (((_cygtls *) _tlsbase)[-1])
169 extern _cygtls *_main_tls;
170
171 #define __getreent() (&_my_tls.local_clib)
172
173 const int CYGTLS_PADSIZE  = (((char *) _main_tls->padding) - ((char *) _main_tls));
174 #endif /*_CYGTLS_H*/