3 Copyright 2003, 2004, 2005, 2008, 2009 Red Hat, Inc.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
16 #define _NOMNTENT_FUNCS
18 #undef _NOMNTENT_FUNCS
20 #include <exceptions.h>
22 #define CYGTLS_INITIALIZED 0xc763173f
25 # define CYG_MAX_PATH 260
32 #define TLS_STACK_SIZE 256
34 #include "cygthread.h"
36 #define TP_NUM_C_BUFS 10
37 #define TP_NUM_W_BUFS 10
44 /* Defined here to support auto rebuild of tlsoffsets.h. */
49 char *c_buf[TP_NUM_C_BUFS];
50 WCHAR *w_buf[TP_NUM_W_BUFS];
54 friend class tmp_pathbuf;
63 short port_proto_addrtype;
72 t_hostent, t_protoent, t_servent
79 Needed for the group functions
94 char pass[_PASSWORD_LEN];
100 unsigned available_drives;
103 char mnt_fsname[CYG_MAX_PATH];
104 char mnt_dir[CYG_MAX_PATH];
110 LONG *ser_num; // note: malloced
111 HANDLE *w4; // note: malloced
115 char strerror_buf[sizeof ("Unknown error 4294967295")];
118 char *process_ident; // note: malloced
120 int process_facility;
124 char timezone_buf[20];
125 struct tm _localtime_buf;
128 char username[UNLEN + 1];
131 char *ntoa_buf; // note: malloced
132 char signamebuf[sizeof ("Unknown signal 4294967295 ")];
134 unionent *hostent_buf; // note: malloced
135 unionent *protoent_buf; // note: malloced
136 unionent *servent_buf; // note: malloced
139 char unknown_thread_name[30];
145 /* All functions requiring temporary path buffers. */
146 tls_pathbuf pathbufs;
149 typedef struct struct_waitq
155 void *rusage; /* pointer to potential rusage */
156 struct struct_waitq *next;
168 /* Changes to the below structure may require acompanying changes to the very
169 simple parser in the perl script 'gentls_offsets' (<<-- start parsing here).
170 The union in this structure is used to force alignment between the version
171 of the compiler used to generate tlsoffsets.h and the cygwin cross compiler.
175 #include "cygerrno.h"
177 extern "C" int __sjfault (jmp_buf);
178 extern "C" int __ljfault (jmp_buf, int);
182 typedef __uint32_t __stack_t;
185 void (*func) /*gentls_offsets*/(int)/*gentls_offsets*/;
194 sigset_t sigwait_mask;
195 siginfo_t *sigwait_info;
196 struct ucontext thread_context;
203 struct _reent local_clib;
204 char __dontuse[8 * ((sizeof(struct _reent) + 4) / 8)];
206 struct _local_storage locals;
207 class cygthread *_ctinfo;
210 struct _cygtls *prev, *next;
216 __stack_t stack[TLS_STACK_SIZE];
217 unsigned initialized;
220 static CRITICAL_SECTION protect_linked_list;
222 void init_thread (void *, DWORD (*) (void *, void *));
223 static void call (DWORD (*) (void *, void *), void *);
224 void call2 (DWORD (*) (void *, void *), void *, void *) __attribute__ ((regparm (3)));
225 static struct _cygtls *find_tls (int sig);
227 void push (__stack_t) __attribute__ ((regparm (2)));
228 __stack_t pop () __attribute__ ((regparm (1)));
229 __stack_t retaddr () {return stackptr[-1];}
230 bool isinitialized () const
232 return initialized == CYGTLS_INITIALIZED;
234 bool interrupt_now (CONTEXT *, int, void *, struct sigaction&)
235 __attribute__((regparm(3)));
236 void __stdcall interrupt_setup (int sig, void *handler,
237 struct sigaction& siga)
238 __attribute__((regparm(3)));
240 /* exception handling */
241 static int handle_exceptions (EXCEPTION_RECORD *, exception_list *, CONTEXT *, void *);
242 bool inside_kernel (CONTEXT *);
243 void init_exception_handler (int (*) (EXCEPTION_RECORD *, exception_list *, CONTEXT *, void*));
244 void signal_exit (int) __attribute__ ((noreturn, regparm(2)));
245 void copy_context (CONTEXT *) __attribute__ ((regparm(2)));
246 void signal_debugger (int) __attribute__ ((regparm(2)));
249 operator HANDLE () const {return tid->win32_obj_id;}
251 void set_siginfo (struct sigpacket *) __attribute__ ((regparm (3)));
252 void set_threadkill () {threadkill = true;}
253 void reset_threadkill () {threadkill = false;}
254 int call_signal_handler () __attribute__ ((regparm (1)));
255 void remove_wq (DWORD) __attribute__ ((regparm (1)));
256 void fixup_after_fork () __attribute__ ((regparm (1)));
257 void lock () __attribute__ ((regparm (1)));
258 void unlock () __attribute__ ((regparm (1)));
259 bool locked () __attribute__ ((regparm (1)));
260 void*& fault_guarded () {return andreas._myfault;}
261 void return_from_fault ()
263 if (andreas._myfault_errno)
264 set_errno (andreas._myfault_errno);
265 /* Restore tls_pathbuf counters in case of error. */
266 locals.pathbufs.c_cnt = andreas._myfault_c_cnt;
267 locals.pathbufs.w_cnt = andreas._myfault_w_cnt;
268 __ljfault ((int *) andreas._myfault, 1);
270 int setup_fault (jmp_buf j, san& old_j, int myerrno) __attribute__ ((always_inline))
272 old_j._myfault = andreas._myfault;
273 old_j._myfault_errno = andreas._myfault_errno;
274 old_j._myfault_c_cnt = andreas._myfault_c_cnt;
275 old_j._myfault_w_cnt = andreas._myfault_w_cnt;
276 andreas._myfault = (void *) j;
277 andreas._myfault_errno = myerrno;
278 /* Save tls_pathbuf counters. */
279 andreas._myfault_c_cnt = locals.pathbufs.c_cnt;
280 andreas._myfault_w_cnt = locals.pathbufs.w_cnt;
281 return __sjfault (j);
283 void reset_fault (san& old_j) __attribute__ ((always_inline))
285 andreas._myfault = old_j._myfault;
286 andreas._myfault_errno = old_j._myfault_errno;
292 const int CYGTLS_PADSIZE = 12700; /* FIXME: Find some way to autogenerate
296 extern char *_tlsbase __asm__ ("%fs:4");
297 extern char *_tlstop __asm__ ("%fs:8");
298 #define _my_tls (*((_cygtls *) (_tlsbase - CYGTLS_PADSIZE)))
299 extern _cygtls *_main_tls;
300 extern _cygtls *_sig_tls;
307 ~myfault () __attribute__ ((always_inline)) { _my_tls.reset_fault (sebastian); }
308 inline int faulted (int myerrno = 0) __attribute__ ((always_inline))
310 return _my_tls.setup_fault (buf, sebastian, myerrno);
314 #define __getreent() (&_my_tls.local_clib)
316 #endif /*_CYGTLS_H*/ /*gentls_offsets*/