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