2008-10-26 Zoltan Varga <vargaz@gmail.com>
[mono-project.git] / mono / io-layer / wapi-private.h
blob54306baedda48628288bd27b65433c652becc147
1 /*
2 * wapi-private.h: internal definitions of handles and shared memory layout
4 * Author:
5 * Dick Porter (dick@ximian.com)
7 * (C) 2002-2006 Novell, Inc.
8 */
10 #ifndef _WAPI_PRIVATE_H_
11 #define _WAPI_PRIVATE_H_
13 #include <config.h>
14 #include <glib.h>
16 #include <mono/io-layer/handles.h>
17 #include <mono/io-layer/io.h>
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
24 /* Increment this whenever an incompatible change is made to the
25 * shared handle structure.
27 #define _WAPI_HANDLE_VERSION 12
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;
47 extern const char *_wapi_handle_typename[];
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)
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)
59 #define _WAPI_SHARED_NAMESPACE(type) (type == WAPI_HANDLE_NAMEDMUTEX || \
60 type == WAPI_HANDLE_NAMEDSEM || \
61 type == WAPI_HANDLE_NAMEDEVENT)
63 typedef struct
65 gchar name[MAX_PATH + 1];
66 } WapiSharedNamespace;
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;
75 struct _WapiHandleOps
77 void (*close)(gpointer handle, gpointer data);
79 /* SignalObjectAndWait */
80 void (*signal)(gpointer signal);
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.
86 gboolean (*own_handle)(gpointer handle);
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
92 gboolean (*is_owned)(gpointer handle);
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.
99 guint32 (*special_wait)(gpointer handle, guint32 timeout);
101 /* Called by WaitForSingleObject and WaitForMultipleObjects,
102 * if the handle in question needs some preprocessing before the
103 * signal wait.
105 void (*prewait)(gpointer handle);
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>
116 struct _WapiHandle_shared_ref
118 /* This will be split 16:16 with the shared file segment in
119 * the top half, when I implement space increases
121 guint32 offset;
124 #define _WAPI_HANDLE_INITIAL_COUNT 256
126 struct _WapiHandleUnshared
128 WapiHandleType type;
129 guint ref;
130 gboolean signalled;
131 mono_mutex_t signal_mutex;
132 pthread_cond_t signal_cond;
134 union
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;
147 struct _WapiHandleShared
149 WapiHandleType type;
150 guint32 timestamp;
151 guint32 handle_refs;
152 volatile gboolean signalled;
154 union
156 struct _WapiHandle_process process;
157 struct _WapiHandle_namedmutex namedmutex;
158 struct _WapiHandle_namedsem namedsem;
159 struct _WapiHandle_namedevent namedevent;
160 } u;
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 */
171 struct _WapiHandleSharedLayout
173 volatile guint32 collection_count;
174 volatile key_t sem_key;
176 struct _WapiHandleShared handles[_WAPI_HANDLE_INITIAL_COUNT];
179 #define _WAPI_FILESHARE_SIZE 102400
181 struct _WapiFileShare
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;
192 struct _WapiFileShareLayout
194 guint32 hwm;
196 struct _WapiFileShare share_info[_WAPI_FILESHARE_SIZE];
201 #define _WAPI_HANDLE_INVALID (gpointer)-1
203 #endif /* _WAPI_PRIVATE_H_ */