svn path=/branches/Mainsoft.System.Data/mcs/; revision=43729
[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 Ximian, 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 4
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_COUNT
43 } WapiHandleType;
44
45 extern const char *_wapi_handle_typename[];
46
47 #define _WAPI_SHARED_HANDLE(type) (type == WAPI_HANDLE_THREAD || \
48                                    type == WAPI_HANDLE_PROCESS || \
49                                    type == WAPI_HANDLE_NAMEDMUTEX)
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
58 typedef struct 
59 {
60         gchar name[MAX_PATH + 1];
61 } WapiSharedNamespace;
62
63 typedef enum {
64         WAPI_HANDLE_CAP_WAIT=0x01,
65         WAPI_HANDLE_CAP_SIGNAL=0x02,
66         WAPI_HANDLE_CAP_OWN=0x04,
67         WAPI_HANDLE_CAP_SPECIAL_WAIT=0x08
68 } WapiHandleCapability;
69
70 struct _WapiHandleOps 
71 {
72         void (*close)(gpointer handle);
73
74         /* SignalObjectAndWait */
75         void (*signal)(gpointer signal);
76
77         /* Called by WaitForSingleObject and WaitForMultipleObjects,
78          * with the handle locked (shared handles aren't locked.)
79          * Returns TRUE if ownership was established, false otherwise.
80          */
81         gboolean (*own_handle)(gpointer handle);
82
83         /* Called by WaitForSingleObject and WaitForMultipleObjects, if the
84          * handle in question is "ownable" (ie mutexes), to see if the current
85          * thread already owns this handle
86          */
87         gboolean (*is_owned)(gpointer handle);
88
89         /* Called by WaitForSingleObject, if the handle in question
90          * needs a special wait function instead of using the normal
91          * handle signal mechanism.  Returns the WaitForSingleObject
92          * return code.
93          */
94         guint32 (*special_wait)(gpointer handle, guint32 timeout);
95 };
96
97 #include <mono/io-layer/event-private.h>
98 #include <mono/io-layer/io-private.h>
99 #include <mono/io-layer/mutex-private.h>
100 #include <mono/io-layer/semaphore-private.h>
101 #include <mono/io-layer/socket-private.h>
102 #include <mono/io-layer/thread-private.h>
103 #include <mono/io-layer/process-private.h>
104
105 struct _WapiHandle_shared_ref
106 {
107         /* This will be split 16:16 with the shared file segment in
108          * the top half, when I implement space increases
109          */
110         guint32 offset;
111 };
112
113 #define _WAPI_HANDLE_INITIAL_COUNT 4096
114 #define _WAPI_HEADROOM 16
115
116 struct _WapiHandleUnshared
117 {
118         WapiHandleType type;
119         guint ref;
120         gboolean signalled;
121         mono_mutex_t signal_mutex;
122         pthread_cond_t signal_cond;
123         
124         union 
125         {
126                 struct _WapiHandle_event event;
127                 struct _WapiHandle_file file;
128                 struct _WapiHandle_find find;
129                 struct _WapiHandle_mutex mutex;
130                 struct _WapiHandle_sem sem;
131                 struct _WapiHandle_socket sock;
132                 struct _WapiHandle_shared_ref shared;
133         } u;
134 };
135
136 struct _WapiHandleSharedMetadata
137 {
138         volatile guint32 offset;
139         guint32 timestamp;
140         volatile gboolean signalled;
141         volatile guint32 checking;
142 };
143
144 struct _WapiHandleShared
145 {
146         WapiHandleType type;
147         gboolean stale;
148         
149         union
150         {
151                 struct _WapiHandle_thread thread;
152                 struct _WapiHandle_process process;
153                 struct _WapiHandle_namedmutex namedmutex;
154         } u;
155 };
156
157 struct _WapiHandleSharedLayout
158 {
159         guint32 namespace_check;
160         volatile guint32 signal_count;
161
162         guint32 master_timestamp;
163         volatile guint32 collection_count;
164         
165         struct _WapiHandleSharedMetadata metadata[_WAPI_HANDLE_INITIAL_COUNT];
166         struct _WapiHandleShared handles[_WAPI_HANDLE_INITIAL_COUNT];
167 };
168
169 #define _WAPI_FILESHARE_SIZE 102400
170
171 struct _WapiFileShare
172 {
173         dev_t device;
174         ino_t inode;
175         guint32 sharemode;
176         guint32 access;
177         guint32 handle_refs;
178         guint32 timestamp;
179 };
180
181 struct _WapiFileShareLayout
182 {
183         guint32 share_check;
184         guint32 hwm;
185         
186         struct _WapiFileShare share_info[_WAPI_FILESHARE_SIZE];
187 };
188
189
190
191 #define _WAPI_HANDLE_INVALID (gpointer)-1
192
193 #endif /* _WAPI_PRIVATE_H_ */