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/wapi.h>
18 #include <mono/io-layer/handles.h>
19 #include <mono/io-layer/io.h>
21 #include <mono/utils/mono-os-mutex.h>
23 /* Increment this whenever an incompatible change is made to the
24 * shared handle structure.
26 #define _WAPI_HANDLE_VERSION 12
40 WAPI_HANDLE_NAMEDMUTEX,
42 WAPI_HANDLE_NAMEDEVENT,
46 extern const char *_wapi_handle_typename[];
48 #define _WAPI_SHARED_HANDLE(type) (type == WAPI_HANDLE_NAMEDMUTEX || \
49 type == WAPI_HANDLE_NAMEDSEM || \
50 type == WAPI_HANDLE_NAMEDEVENT)
52 #define _WAPI_FD_HANDLE(type) (type == WAPI_HANDLE_FILE || \
53 type == WAPI_HANDLE_CONSOLE || \
54 type == WAPI_HANDLE_SOCKET || \
55 type == WAPI_HANDLE_PIPE)
57 #define _WAPI_SHARED_NAMESPACE(type) (type == WAPI_HANDLE_NAMEDMUTEX || \
58 type == WAPI_HANDLE_NAMEDSEM || \
59 type == WAPI_HANDLE_NAMEDEVENT)
63 gchar name[MAX_PATH + 1];
64 } WapiSharedNamespace;
67 WAPI_HANDLE_CAP_WAIT=0x01,
68 WAPI_HANDLE_CAP_SIGNAL=0x02,
69 WAPI_HANDLE_CAP_OWN=0x04,
70 WAPI_HANDLE_CAP_SPECIAL_WAIT=0x08
71 } WapiHandleCapability;
75 void (*close)(gpointer handle, gpointer data);
77 /* SignalObjectAndWait */
78 void (*signal)(gpointer signal);
80 /* Called by WaitForSingleObject and WaitForMultipleObjects,
81 * with the handle locked (shared handles aren't locked.)
82 * Returns TRUE if ownership was established, false otherwise.
84 gboolean (*own_handle)(gpointer handle);
86 /* Called by WaitForSingleObject and WaitForMultipleObjects, if the
87 * handle in question is "ownable" (ie mutexes), to see if the current
88 * thread already owns this handle
90 gboolean (*is_owned)(gpointer handle);
92 /* Called by WaitForSingleObject and WaitForMultipleObjects,
93 * if the handle in question needs a special wait function
94 * instead of using the normal handle signal mechanism.
95 * Returns the WaitForSingleObject return code.
97 guint32 (*special_wait)(gpointer handle, guint32 timeout, gboolean alertable);
99 /* Called by WaitForSingleObject and WaitForMultipleObjects,
100 * if the handle in question needs some preprocessing before the
103 void (*prewait)(gpointer handle);
106 #include <mono/io-layer/event-private.h>
107 #include <mono/io-layer/io-private.h>
108 #include <mono/io-layer/mutex-private.h>
109 #include <mono/io-layer/semaphore-private.h>
110 #include <mono/io-layer/socket-private.h>
111 #include <mono/io-layer/thread-private.h>
112 #include <mono/io-layer/process-private.h>
114 struct _WapiHandle_shared_ref
116 /* This will be split 16:16 with the shared file segment in
117 * the top half, when I implement space increases
122 #define _WAPI_HANDLE_INITIAL_COUNT 256
124 struct _WapiHandleUnshared
129 mono_mutex_t signal_mutex;
130 pthread_cond_t signal_cond;
134 struct _WapiHandle_event event;
135 struct _WapiHandle_file file;
136 struct _WapiHandle_find find;
137 struct _WapiHandle_mutex mutex;
138 struct _WapiHandle_sem sem;
139 struct _WapiHandle_socket sock;
140 struct _WapiHandle_thread thread;
141 struct _WapiHandle_process process;
142 struct _WapiHandle_shared_ref shared;
146 struct _WapiHandleShared
151 volatile gboolean signalled;
155 struct _WapiHandle_namedmutex namedmutex;
156 struct _WapiHandle_namedsem namedsem;
157 struct _WapiHandle_namedevent namedevent;
161 #define _WAPI_SHARED_SEM_NAMESPACE 0
162 /*#define _WAPI_SHARED_SEM_COLLECTION 1*/
163 #define _WAPI_SHARED_SEM_FILESHARE 2
164 #define _WAPI_SHARED_SEM_SHARED_HANDLES 3
165 #define _WAPI_SHARED_SEM_PROCESS_COUNT_LOCK 6
166 #define _WAPI_SHARED_SEM_PROCESS_COUNT 7
167 #define _WAPI_SHARED_SEM_COUNT 8 /* Leave some future expansion space */
169 struct _WapiHandleSharedLayout
171 volatile guint32 collection_count;
172 volatile key_t sem_key;
174 struct _WapiHandleShared handles[_WAPI_HANDLE_INITIAL_COUNT];
177 typedef struct _WapiHandleSharedLayout _WapiHandleSharedLayout;
179 struct _WapiFileShare
181 #ifdef WAPI_FILE_SHARE_PLATFORM_EXTRA_DATA
182 WAPI_FILE_SHARE_PLATFORM_EXTRA_DATA
193 typedef struct _WapiFileShare _WapiFileShare;
195 #define _WAPI_HANDLE_INVALID (gpointer)-1
197 #endif /* _WAPI_PRIVATE_H_ */