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>
18 #include <mono/io-layer/daemon-private.h>
20 /* Catch this here rather than corrupt the shared data at runtime */
21 #if MONO_SIZEOF_SUNPATH==0
22 #error configure failed to discover size of unix socket path
25 /* Increment this whenever an incompatible change is made to the
26 * shared handle structure.
28 #define _WAPI_HANDLE_VERSION 1
46 WAPI_HANDLE_CAP_WAIT=0x01,
47 WAPI_HANDLE_CAP_SIGNAL=0x02,
48 WAPI_HANDLE_CAP_OWN=0x04,
49 } WapiHandleCapability;
53 void (*close_shared)(gpointer handle);
54 void (*close_private)(gpointer handle);
56 /* SignalObjectAndWait */
57 void (*signal)(gpointer signal);
59 /* Called by WaitForSingleObject and WaitForMultipleObjects,
60 * with the handle locked
62 void (*own_handle)(gpointer handle);
64 /* Called by WaitForSingleObject and WaitForMultipleObjects, if the
65 * handle in question is "ownable" (ie mutexes), to see if the current
66 * thread already owns this handle
68 gboolean (*is_owned)(gpointer handle);
71 #include <mono/io-layer/event-private.h>
72 #include <mono/io-layer/io-private.h>
73 #include <mono/io-layer/mutex-private.h>
74 #include <mono/io-layer/semaphore-private.h>
75 #include <mono/io-layer/socket-private.h>
76 #include <mono/io-layer/thread-private.h>
77 #include <mono/io-layer/process-private.h>
79 /* Shared threads don't seem to work yet */
80 #undef _POSIX_THREAD_PROCESS_SHARED
82 struct _WapiHandleShared
87 mono_mutex_t signal_mutex;
88 pthread_cond_t signal_cond;
92 struct _WapiHandle_event event;
93 struct _WapiHandle_file file;
94 struct _WapiHandle_find find;
95 struct _WapiHandle_mutex mutex;
96 struct _WapiHandle_sem sem;
97 struct _WapiHandle_socket sock;
98 struct _WapiHandle_thread thread;
99 struct _WapiHandle_process process;
103 #define _WAPI_HANDLES_PER_SEGMENT 4096
104 #define _WAPI_HANDLE_INVALID (gpointer)-1
106 #define _WAPI_SHM_SCRATCH_SIZE 512000
109 * This is the layout of the shared scratch data. When the data array
110 * is filled, it will be expanded by _WAPI_SHM_SCRATCH_SIZE
111 * bytes. (scratch data is always copied out of the shared memory, so
112 * it doesn't matter that the mapping will move around.)
114 struct _WapiHandleScratch
118 /* This is set to TRUE by the daemon. It determines whether a
119 * resize will go via mremap() or just realloc().
122 guchar scratch_data[MONO_ZERO_ARRAY_LENGTH];
126 * This is the layout of the shared memory segments. When the handles
127 * array is filled, another shared memory segment will be allocated
128 * with the same structure. This is to avoid having the shared memory
129 * potentially move if it is resized and remapped.
131 * Note that the additional segments have the same structure, but only
132 * the handle array is used.
134 struct _WapiHandleShared_list
136 guchar daemon[MONO_SIZEOF_SUNPATH];
137 _wapi_daemon_status daemon_running;
139 #if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1
140 mono_mutex_t signal_mutex;
141 pthread_cond_t signal_cond;
144 /* This holds the number of segments */
145 guint32 num_segments;
146 struct _WapiHandleShared handles[_WAPI_HANDLES_PER_SEGMENT];
149 struct _WapiHandlePrivate
155 struct _WapiHandlePrivate_event event;
156 struct _WapiHandlePrivate_file file;
157 struct _WapiHandlePrivate_find find;
158 struct _WapiHandlePrivate_mutex mutex;
159 struct _WapiHandlePrivate_sem sem;
160 struct _WapiHandlePrivate_socket sock;
161 struct _WapiHandlePrivate_thread thread;
162 struct _WapiHandlePrivate_process process;
166 /* Per-process handle info. For lookup convenience, each segment and
167 * index matches the corresponding shared data.
169 * Note that the additional segments have the same structure, but only
170 * the handle array is used.
172 struct _WapiHandlePrivate_list
174 #if !defined(_POSIX_THREAD_PROCESS_SHARED) || _POSIX_THREAD_PROCESS_SHARED == -1
175 mono_mutex_t signal_mutex;
176 pthread_cond_t signal_cond;
179 struct _WapiHandlePrivate handles[_WAPI_HANDLES_PER_SEGMENT];
183 #endif /* _WAPI_PRIVATE_H_ */