OSDN Git Service

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