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