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_
17 #include <mono/io-layer/handles.h>
18 #include <mono/io-layer/io.h>
20 #include <mono/utils/mono-os-mutex.h>
22 /* Increment this whenever an incompatible change is made to the
23 * shared handle structure.
25 #define _WAPI_HANDLE_VERSION 12
39 WAPI_HANDLE_NAMEDMUTEX,
41 WAPI_HANDLE_NAMEDEVENT,
45 extern const char *_wapi_handle_typename[];
47 #define _WAPI_SHARED_HANDLE(type) (type == WAPI_HANDLE_NAMEDMUTEX || \
48 type == WAPI_HANDLE_NAMEDSEM || \
49 type == WAPI_HANDLE_NAMEDEVENT)
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)
56 #define _WAPI_SHARED_NAMESPACE(type) (type == WAPI_HANDLE_NAMEDMUTEX || \
57 type == WAPI_HANDLE_NAMEDSEM || \
58 type == WAPI_HANDLE_NAMEDEVENT)
62 gchar name[MAX_PATH + 1];
63 } WapiSharedNamespace;
66 WAPI_HANDLE_CAP_WAIT=0x01,
67 WAPI_HANDLE_CAP_SIGNAL=0x02,
68 WAPI_HANDLE_CAP_OWN=0x04,
69 WAPI_HANDLE_CAP_SPECIAL_WAIT=0x08
70 } WapiHandleCapability;
74 void (*close)(gpointer handle, gpointer data);
76 /* SignalObjectAndWait */
77 void (*signal)(gpointer signal);
79 /* Called by WaitForSingleObject and WaitForMultipleObjects,
80 * with the handle locked (shared handles aren't locked.)
81 * Returns TRUE if ownership was established, false otherwise.
83 gboolean (*own_handle)(gpointer handle);
85 /* Called by WaitForSingleObject and WaitForMultipleObjects, if the
86 * handle in question is "ownable" (ie mutexes), to see if the current
87 * thread already owns this handle
89 gboolean (*is_owned)(gpointer handle);
91 /* Called by WaitForSingleObject and WaitForMultipleObjects,
92 * if the handle in question needs a special wait function
93 * instead of using the normal handle signal mechanism.
94 * Returns the WaitForSingleObject return code.
96 guint32 (*special_wait)(gpointer handle, guint32 timeout, gboolean alertable);
98 /* Called by WaitForSingleObject and WaitForMultipleObjects,
99 * if the handle in question needs some preprocessing before the
102 void (*prewait)(gpointer handle);
105 #include <mono/io-layer/event-private.h>
106 #include <mono/io-layer/io-private.h>
107 #include <mono/io-layer/mutex-private.h>
108 #include <mono/io-layer/semaphore-private.h>
109 #include <mono/io-layer/socket-private.h>
110 #include <mono/io-layer/thread-private.h>
111 #include <mono/io-layer/process-private.h>
113 struct _WapiHandle_shared_ref
115 /* This will be split 16:16 with the shared file segment in
116 * the top half, when I implement space increases
121 #define _WAPI_HANDLE_INITIAL_COUNT 256
123 struct _WapiHandleUnshared
128 mono_mutex_t signal_mutex;
129 pthread_cond_t signal_cond;
133 struct _WapiHandle_event event;
134 struct _WapiHandle_file file;
135 struct _WapiHandle_find find;
136 struct _WapiHandle_mutex mutex;
137 struct _WapiHandle_sem sem;
138 struct _WapiHandle_socket sock;
139 struct _WapiHandle_thread thread;
140 struct _WapiHandle_process process;
141 struct _WapiHandle_shared_ref shared;
145 struct _WapiHandleShared
150 volatile gboolean signalled;
154 struct _WapiHandle_namedmutex namedmutex;
155 struct _WapiHandle_namedsem namedsem;
156 struct _WapiHandle_namedevent namedevent;
160 #define _WAPI_SHARED_SEM_NAMESPACE 0
161 /*#define _WAPI_SHARED_SEM_COLLECTION 1*/
162 #define _WAPI_SHARED_SEM_FILESHARE 2
163 #define _WAPI_SHARED_SEM_SHARED_HANDLES 3
164 #define _WAPI_SHARED_SEM_PROCESS_COUNT_LOCK 6
165 #define _WAPI_SHARED_SEM_PROCESS_COUNT 7
166 #define _WAPI_SHARED_SEM_COUNT 8 /* Leave some future expansion space */
168 struct _WapiHandleSharedLayout
170 volatile guint32 collection_count;
171 volatile key_t sem_key;
173 struct _WapiHandleShared handles[_WAPI_HANDLE_INITIAL_COUNT];
176 typedef struct _WapiHandleSharedLayout _WapiHandleSharedLayout;
178 #define _WAPI_FILESHARE_SIZE 102400
180 struct _WapiFileShare
182 #ifdef WAPI_FILE_SHARE_PLATFORM_EXTRA_DATA
183 WAPI_FILE_SHARE_PLATFORM_EXTRA_DATA
194 typedef struct _WapiFileShare _WapiFileShare;
196 struct _WapiFileShareLayout
200 struct _WapiFileShare share_info[_WAPI_FILESHARE_SIZE];
203 typedef struct _WapiFileShareLayout _WapiFileShareLayout;
207 #define _WAPI_HANDLE_INVALID (gpointer)-1
209 #endif /* _WAPI_PRIVATE_H_ */