2 * wapi-private.h: internal definitions of handles and shared memory layout
5 * Dick Porter (dick@ximian.com)
7 * (C) 2002-2006 Novell, Inc.
10 #ifndef _WAPI_PRIVATE_H_
11 #define _WAPI_PRIVATE_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
24 /* Increment this whenever an incompatible change is made to the
25 * shared handle structure.
27 /* Next time I change this, remember to fix the process count in shared.c */
28 #define _WAPI_HANDLE_VERSION 10
42 WAPI_HANDLE_NAMEDMUTEX,
44 WAPI_HANDLE_NAMEDEVENT,
48 extern const char *_wapi_handle_typename[];
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)
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)
61 #define _WAPI_SHARED_NAMESPACE(type) (type == WAPI_HANDLE_NAMEDMUTEX || \
62 type == WAPI_HANDLE_NAMEDSEM || \
63 type == WAPI_HANDLE_NAMEDEVENT)
67 gchar name[MAX_PATH + 1];
68 } WapiSharedNamespace;
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;
79 void (*close)(gpointer handle, gpointer data);
81 /* SignalObjectAndWait */
82 void (*signal)(gpointer signal);
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.
88 gboolean (*own_handle)(gpointer handle);
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
94 gboolean (*is_owned)(gpointer handle);
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.
101 guint32 (*special_wait)(gpointer handle, guint32 timeout);
103 /* Called by WaitForSingleObject and WaitForMultipleObjects,
104 * if the handle in question needs some preprocessing before the
107 void (*prewait)(gpointer handle);
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>
118 struct _WapiHandle_shared_ref
120 /* This will be split 16:16 with the shared file segment in
121 * the top half, when I implement space increases
126 #define _WAPI_HANDLE_INITIAL_COUNT 4096
128 struct _WapiHandleUnshared
133 mono_mutex_t signal_mutex;
134 pthread_cond_t signal_cond;
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;
148 struct _WapiHandleShared
153 volatile gboolean signalled;
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;
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 */
173 struct _WapiHandleSharedLayout
175 volatile guint32 collection_count;
176 volatile key_t sem_key;
178 struct _WapiHandleShared handles[_WAPI_HANDLE_INITIAL_COUNT];
181 #define _WAPI_FILESHARE_SIZE 102400
183 struct _WapiFileShare
194 struct _WapiFileShareLayout
198 struct _WapiFileShare share_info[_WAPI_FILESHARE_SIZE];
203 #define _WAPI_HANDLE_INVALID (gpointer)-1
205 #endif /* _WAPI_PRIVATE_H_ */