2 * wapi-private.h: internal definitions of handles and shared memory layout
5 * Dick Porter (dick@ximian.com)
7 * (C) 2002 Ximian, 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 #define _WAPI_HANDLE_VERSION 6
41 WAPI_HANDLE_NAMEDMUTEX,
45 extern const char *_wapi_handle_typename[];
47 #define _WAPI_SHARED_HANDLE(type) (type == WAPI_HANDLE_PROCESS || \
48 type == WAPI_HANDLE_NAMEDMUTEX)
50 #define _WAPI_FD_HANDLE(type) (type == WAPI_HANDLE_FILE || \
51 type == WAPI_HANDLE_CONSOLE || \
52 type == WAPI_HANDLE_SOCKET || \
53 type == WAPI_HANDLE_PIPE)
55 #define _WAPI_SHARED_NAMESPACE(type) (type == WAPI_HANDLE_NAMEDMUTEX)
59 gchar name[MAX_PATH + 1];
60 } WapiSharedNamespace;
63 WAPI_HANDLE_CAP_WAIT=0x01,
64 WAPI_HANDLE_CAP_SIGNAL=0x02,
65 WAPI_HANDLE_CAP_OWN=0x04,
66 WAPI_HANDLE_CAP_SPECIAL_WAIT=0x08
67 } WapiHandleCapability;
71 void (*close)(gpointer handle, gpointer data);
73 /* SignalObjectAndWait */
74 void (*signal)(gpointer signal);
76 /* Called by WaitForSingleObject and WaitForMultipleObjects,
77 * with the handle locked (shared handles aren't locked.)
78 * Returns TRUE if ownership was established, false otherwise.
80 gboolean (*own_handle)(gpointer handle);
82 /* Called by WaitForSingleObject and WaitForMultipleObjects, if the
83 * handle in question is "ownable" (ie mutexes), to see if the current
84 * thread already owns this handle
86 gboolean (*is_owned)(gpointer handle);
88 /* Called by WaitForSingleObject and WaitForMultipleObjects,
89 * if the handle in question needs a special wait function
90 * instead of using the normal handle signal mechanism.
91 * Returns the WaitForSingleObject return code.
93 guint32 (*special_wait)(gpointer handle, guint32 timeout);
96 #include <mono/io-layer/event-private.h>
97 #include <mono/io-layer/io-private.h>
98 #include <mono/io-layer/mutex-private.h>
99 #include <mono/io-layer/semaphore-private.h>
100 #include <mono/io-layer/socket-private.h>
101 #include <mono/io-layer/thread-private.h>
102 #include <mono/io-layer/process-private.h>
104 struct _WapiHandle_shared_ref
106 /* This will be split 16:16 with the shared file segment in
107 * the top half, when I implement space increases
112 #define _WAPI_HANDLE_INITIAL_COUNT 4096
113 #define _WAPI_HEADROOM 16
115 struct _WapiHandleUnshared
120 mono_mutex_t signal_mutex;
121 pthread_cond_t signal_cond;
125 struct _WapiHandle_event event;
126 struct _WapiHandle_file file;
127 struct _WapiHandle_find find;
128 struct _WapiHandle_mutex mutex;
129 struct _WapiHandle_sem sem;
130 struct _WapiHandle_socket sock;
131 struct _WapiHandle_shared_ref shared;
133 /* Move thread data into the private set, while
134 * problems with cleaning up shared handles are fixed
136 struct _WapiHandle_thread thread;
140 struct _WapiHandleSharedMetadata
142 volatile guint32 offset;
144 volatile gboolean signalled;
147 struct _WapiHandleShared
154 /* Leave this one while the thread is in the private
155 * set, so the shared space doesn't change size
157 struct _WapiHandle_thread thread;
158 struct _WapiHandle_process process;
159 struct _WapiHandle_namedmutex namedmutex;
163 #define _WAPI_SHARED_SEM_NAMESPACE 0
164 #define _WAPI_SHARED_SEM_COLLECTION 1
165 #define _WAPI_SHARED_SEM_SHARE 2
166 #define _WAPI_SHARED_SEM_HANDLE 3
167 #define _WAPI_SHARED_SEM_COUNT 8 /* Leave some future expansion space */
169 struct _WapiHandleSharedLayout
171 volatile guint32 signal_count;
172 volatile guint32 collection_count;
173 volatile key_t sem_key;
175 struct _WapiHandleSharedMetadata metadata[_WAPI_HANDLE_INITIAL_COUNT];
176 struct _WapiHandleShared handles[_WAPI_HANDLE_INITIAL_COUNT];
179 #define _WAPI_FILESHARE_SIZE 102400
181 struct _WapiFileShare
192 struct _WapiFileShareLayout
196 struct _WapiFileShare share_info[_WAPI_FILESHARE_SIZE];
201 #define _WAPI_HANDLE_INVALID (gpointer)-1
203 #endif /* _WAPI_PRIVATE_H_ */