Merge pull request #2296 from xmcclure/webrequest-regex
[mono.git] / mono / io-layer / wapi-private.h
1 /*
2  * wapi-private.h:  internal definitions of handles and shared memory layout
3  *
4  * Author:
5  *      Dick Porter (dick@ximian.com)
6  *
7  * (C) 2002-2006 Novell, Inc.
8  */
9
10 #ifndef _WAPI_PRIVATE_H_
11 #define _WAPI_PRIVATE_H_
12
13 #include <config.h>
14 #include <glib.h>
15 #include <sys/stat.h>
16
17 #include <mono/io-layer/handles.h>
18 #include <mono/io-layer/io.h>
19
20 #include <mono/utils/mono-os-mutex.h>
21
22 /* Increment this whenever an incompatible change is made to the
23  * shared handle structure.
24  */
25 #define _WAPI_HANDLE_VERSION 12
26
27 typedef enum {
28         WAPI_HANDLE_UNUSED=0,
29         WAPI_HANDLE_FILE,
30         WAPI_HANDLE_CONSOLE,
31         WAPI_HANDLE_THREAD,
32         WAPI_HANDLE_SEM,
33         WAPI_HANDLE_MUTEX,
34         WAPI_HANDLE_EVENT,
35         WAPI_HANDLE_SOCKET,
36         WAPI_HANDLE_FIND,
37         WAPI_HANDLE_PROCESS,
38         WAPI_HANDLE_PIPE,
39         WAPI_HANDLE_NAMEDMUTEX,
40         WAPI_HANDLE_NAMEDSEM,
41         WAPI_HANDLE_NAMEDEVENT,
42         WAPI_HANDLE_COUNT
43 } WapiHandleType;
44
45 extern const char *_wapi_handle_typename[];
46
47 #define _WAPI_SHARED_HANDLE(type) (type == WAPI_HANDLE_NAMEDMUTEX || \
48                                    type == WAPI_HANDLE_NAMEDSEM || \
49                                    type == WAPI_HANDLE_NAMEDEVENT)
50
51 #define _WAPI_FD_HANDLE(type) (type == WAPI_HANDLE_FILE || \
52                                type == WAPI_HANDLE_CONSOLE || \
53                                type == WAPI_HANDLE_SOCKET || \
54                                type == WAPI_HANDLE_PIPE)
55
56 #define _WAPI_SHARED_NAMESPACE(type) (type == WAPI_HANDLE_NAMEDMUTEX || \
57                                       type == WAPI_HANDLE_NAMEDSEM || \
58                                       type == WAPI_HANDLE_NAMEDEVENT)
59
60 typedef struct 
61 {
62         gchar name[MAX_PATH + 1];
63 } WapiSharedNamespace;
64
65 typedef enum {
66         WAPI_HANDLE_CAP_WAIT=0x01,
67         WAPI_HANDLE_CAP_SIGNAL=0x02,
68         WAPI_HANDLE_CAP_OWN=0x04,
69         WAPI_HANDLE_CAP_SPECIAL_WAIT=0x08
70 } WapiHandleCapability;
71
72 struct _WapiHandleOps 
73 {
74         void (*close)(gpointer handle, gpointer data);
75
76         /* SignalObjectAndWait */
77         void (*signal)(gpointer signal);
78
79         /* Called by WaitForSingleObject and WaitForMultipleObjects,
80          * with the handle locked (shared handles aren't locked.)
81          * Returns TRUE if ownership was established, false otherwise.
82          */
83         gboolean (*own_handle)(gpointer handle);
84
85         /* Called by WaitForSingleObject and WaitForMultipleObjects, if the
86          * handle in question is "ownable" (ie mutexes), to see if the current
87          * thread already owns this handle
88          */
89         gboolean (*is_owned)(gpointer handle);
90
91         /* Called by WaitForSingleObject and WaitForMultipleObjects,
92          * if the handle in question needs a special wait function
93          * instead of using the normal handle signal mechanism.
94          * Returns the WaitForSingleObject return code.
95          */
96         guint32 (*special_wait)(gpointer handle, guint32 timeout, gboolean alertable);
97
98         /* Called by WaitForSingleObject and WaitForMultipleObjects,
99          * if the handle in question needs some preprocessing before the
100          * signal wait.
101          */
102         void (*prewait)(gpointer handle);
103 };
104
105 #include <mono/io-layer/event-private.h>
106 #include <mono/io-layer/io-private.h>
107 #include <mono/io-layer/mutex-private.h>
108 #include <mono/io-layer/semaphore-private.h>
109 #include <mono/io-layer/socket-private.h>
110 #include <mono/io-layer/thread-private.h>
111 #include <mono/io-layer/process-private.h>
112
113 struct _WapiHandle_shared_ref
114 {
115         /* This will be split 16:16 with the shared file segment in
116          * the top half, when I implement space increases
117          */
118         guint32 offset;
119 };
120
121 #define _WAPI_HANDLE_INITIAL_COUNT 256
122
123 struct _WapiHandleUnshared
124 {
125         WapiHandleType type;
126         guint ref;
127         gboolean signalled;
128         mono_mutex_t signal_mutex;
129         pthread_cond_t signal_cond;
130         
131         union 
132         {
133                 struct _WapiHandle_event event;
134                 struct _WapiHandle_file file;
135                 struct _WapiHandle_find find;
136                 struct _WapiHandle_mutex mutex;
137                 struct _WapiHandle_sem sem;
138                 struct _WapiHandle_socket sock;
139                 struct _WapiHandle_thread thread;
140                 struct _WapiHandle_process process;
141                 struct _WapiHandle_shared_ref shared;
142         } u;
143 };
144
145 struct _WapiHandleShared
146 {
147         WapiHandleType type;
148         guint32 timestamp;
149         guint32 handle_refs;
150         volatile gboolean signalled;
151         
152         union
153         {
154                 struct _WapiHandle_namedmutex namedmutex;
155                 struct _WapiHandle_namedsem namedsem;
156                 struct _WapiHandle_namedevent namedevent;
157         } u;
158 };
159
160 #define _WAPI_SHARED_SEM_NAMESPACE 0
161 /*#define _WAPI_SHARED_SEM_COLLECTION 1*/
162 #define _WAPI_SHARED_SEM_FILESHARE 2
163 #define _WAPI_SHARED_SEM_SHARED_HANDLES 3
164 #define _WAPI_SHARED_SEM_PROCESS_COUNT_LOCK 6
165 #define _WAPI_SHARED_SEM_PROCESS_COUNT 7
166 #define _WAPI_SHARED_SEM_COUNT 8        /* Leave some future expansion space */
167
168 struct _WapiHandleSharedLayout
169 {
170         volatile guint32 collection_count;
171         volatile key_t sem_key;
172         
173         struct _WapiHandleShared handles[_WAPI_HANDLE_INITIAL_COUNT];
174 };
175
176 typedef struct _WapiHandleSharedLayout _WapiHandleSharedLayout;
177
178 #define _WAPI_FILESHARE_SIZE 102400
179
180 struct _WapiFileShare
181 {
182 #ifdef WAPI_FILE_SHARE_PLATFORM_EXTRA_DATA
183         WAPI_FILE_SHARE_PLATFORM_EXTRA_DATA
184 #endif
185         guint64 device;
186         guint64 inode;
187         pid_t opened_by_pid;
188         guint32 sharemode;
189         guint32 access;
190         guint32 handle_refs;
191         guint32 timestamp;
192 };
193
194 typedef struct _WapiFileShare _WapiFileShare;
195
196 struct _WapiFileShareLayout
197 {
198         guint32 hwm;
199         
200         struct _WapiFileShare share_info[_WAPI_FILESHARE_SIZE];
201 };
202
203 typedef struct _WapiFileShareLayout _WapiFileShareLayout;
204
205
206
207 #define _WAPI_HANDLE_INVALID (gpointer)-1
208
209 #endif /* _WAPI_PRIVATE_H_ */