OSDN Git Service

Rename _threadinfo to _cygtls, throughout.
[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 /* Please keep this file simple.  Changes to the below structure may require
89    acompanying changes to the very simple parser in the perl script
90    'gentls_offsets' (<<-- start parsing here).  */
91
92 typedef __uint32_t __stack_t;
93 struct _cygtls
94 {
95   void (*func) /*gentls_offsets*/(int)/*gentls_offsets*/;
96   int saved_errno;
97   int sa_flags;
98   sigset_t oldmask;
99   sigset_t newmask;
100   HANDLE event;
101   int *errno_addr;
102   unsigned initialized;
103   sigset_t sigmask;
104   sigset_t sigwait_mask;
105   siginfo_t *sigwait_info;
106   unsigned threadkill;
107   siginfo_t infodata;
108   struct pthread *tid;
109   struct _reent local_clib;
110   struct _local_storage locals;
111   struct _cygtls *prev, *next;
112   __stack_t *stackptr;
113   int sig;
114   unsigned stacklock;
115   __stack_t stack[TLS_STACK_SIZE];
116   unsigned padding[0];
117
118   /*gentls_offsets*/
119   static CRITICAL_SECTION protect_linked_list;
120   static void init ();
121   void init_thread (void *, DWORD (*) (void *, void *));
122   static void call (DWORD (*) (void *, void *), void *);
123   static void call2 (DWORD (*) (void *, void *), void *, void *) __attribute__ ((regparm (3)));
124   static struct _cygtls *find_tls (int sig);
125   void remove (DWORD);
126   void push (__stack_t, bool) __attribute__ ((regparm (3)));
127   __stack_t pop () __attribute__ ((regparm (1)));
128   bool isinitialized () {return initialized == CYGTLS_INITIALIZED || initialized == CYGTLS_EXCEPTION;}
129   void set_state (bool);
130   void reset_exception ();
131   bool interrupt_now (CONTEXT *, int, void *, struct sigaction&)
132     __attribute__((regparm(3)));
133   void __stdcall interrupt_setup (int sig, void *handler,
134                                   struct sigaction& siga)
135     __attribute__((regparm(3)));
136   void init_threadlist_exceptions (struct _exception_list *);
137   operator HANDLE () const {return tid->win32_obj_id;}
138   void set_siginfo (struct sigpacket *) __attribute__ ((regparm (3)));
139   void set_threadkill () {threadkill = true;}
140   void reset_threadkill () {threadkill = false;}
141   int call_signal_handler () __attribute__ ((regparm (1)));
142   void fixup_after_fork () __attribute__ ((regparm (1)));
143   void lock () __attribute__ ((regparm (1)));
144   void unlock () __attribute__ ((regparm (1)));
145   bool locked () __attribute__ ((regparm (1)));
146   /*gentls_offsets*/
147 };
148 #pragma pack(pop)
149
150 extern char *_tlsbase __asm__ ("%fs:4");
151 extern char *_tlstop __asm__ ("%fs:8");
152 #define _my_tls (((_cygtls *) _tlsbase)[-1])
153 extern _cygtls *_main_tls;
154
155 #define __getreent() (&_my_tls.local_clib)
156
157 const int CYGTLS_PADSIZE  = (((char *) _main_tls->padding) - ((char *) _main_tls));
158 #endif /*_CYGTLS_H*/