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 /* for non-GCC compilers where Glib gives an empty pretty function
21 * macro create one that gives file & line number instead
24 #undef G_GNUC_PRETTY_FUNCTION
25 #define STRINGIZE_HELPER(exp) #exp
26 #define STRINGIZE(exp) STRINGIZE_HELPER(exp)
27 #define G_GNUC_PRETTY_FUNCTION __FILE__ "(" STRINGIZE(__LINE__) ")"
30 /* Catch this here rather than corrupt the shared data at runtime */
31 #if MONO_SIZEOF_SUNPATH==0
32 #error configure failed to discover size of unix socket path
35 /* Increment this whenever an incompatible change is made to the
36 * shared handle structure.
38 #define _WAPI_HANDLE_VERSION 3
55 #define _WAPI_SHARED_NAMESPACE(type) (type==WAPI_HANDLE_MUTEX)
60 } WapiSharedNamespace;
62 /* The boolean is for distinguishing between a zeroed struct being not
63 * as yet assigned, and one containing a valid fd 0. It's also used
64 * to signal that a previously-good fd has been reused behind our
65 * back, so we need to invalidate the handle that thought it owned the
76 WAPI_HANDLE_CAP_WAIT=0x01,
77 WAPI_HANDLE_CAP_SIGNAL=0x02,
78 WAPI_HANDLE_CAP_OWN=0x04
79 } WapiHandleCapability;
83 void (*close_shared)(gpointer handle);
84 void (*close_private)(gpointer handle);
86 /* SignalObjectAndWait */
87 void (*signal)(gpointer signal);
89 /* Called by WaitForSingleObject and WaitForMultipleObjects,
90 * with the handle locked
92 void (*own_handle)(gpointer handle);
94 /* Called by WaitForSingleObject and WaitForMultipleObjects, if the
95 * handle in question is "ownable" (ie mutexes), to see if the current
96 * thread already owns this handle
98 gboolean (*is_owned)(gpointer handle);
101 #include <mono/io-layer/event-private.h>
102 #include <mono/io-layer/io-private.h>
103 #include <mono/io-layer/mutex-private.h>
104 #include <mono/io-layer/semaphore-private.h>
105 #include <mono/io-layer/socket-private.h>
106 #include <mono/io-layer/thread-private.h>
107 #include <mono/io-layer/process-private.h>
109 /* Shared threads don't seem to work yet */
110 #undef _POSIX_THREAD_PROCESS_SHARED
112 struct _WapiHandleShared
117 mono_mutex_t signal_mutex;
118 pthread_cond_t signal_cond;
122 struct _WapiHandle_event event;
123 struct _WapiHandle_file file;
124 struct _WapiHandle_find find;
125 struct _WapiHandle_mutex mutex;
126 struct _WapiHandle_sem sem;
127 struct _WapiHandle_socket sock;
128 struct _WapiHandle_thread thread;
129 struct _WapiHandle_process process;
133 #define _WAPI_HANDLES_PER_SEGMENT 4096
134 #define _WAPI_HANDLE_INVALID (gpointer)-1
136 #define _WAPI_SHM_SCRATCH_SIZE 512000
139 * This is the layout of the shared scratch data. When the data array
140 * is filled, it will be expanded by _WAPI_SHM_SCRATCH_SIZE
141 * bytes. (scratch data is always copied out of the shared memory, so
142 * it doesn't matter that the mapping will move around.)
144 struct _WapiHandleScratch
148 /* This is set to TRUE by the daemon. It determines whether a
149 * resize will go via mremap() or just realloc().
152 guchar scratch_data[MONO_ZERO_ARRAY_LENGTH];
156 * This is the layout of the shared memory segments. When the handles
157 * array is filled, another shared memory segment will be allocated
158 * with the same structure. This is to avoid having the shared memory
159 * potentially move if it is resized and remapped.
161 * Note that the additional segments have the same structure, but only
162 * the handle array is used.
164 struct _WapiHandleShared_list
166 guchar daemon[MONO_SIZEOF_SUNPATH];
167 _wapi_daemon_status daemon_running;
168 guint32 fd_offset_table_size;
170 #if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1
171 mono_mutex_t signal_mutex;
172 pthread_cond_t signal_cond;
175 /* This holds the number of segments */
176 guint32 num_segments;
177 struct _WapiHandleShared handles[_WAPI_HANDLES_PER_SEGMENT];
180 struct _WapiHandlePrivate
186 struct _WapiHandlePrivate_event event;
187 struct _WapiHandlePrivate_file file;
188 struct _WapiHandlePrivate_find find;
189 struct _WapiHandlePrivate_mutex mutex;
190 struct _WapiHandlePrivate_sem sem;
191 struct _WapiHandlePrivate_socket sock;
192 struct _WapiHandlePrivate_thread thread;
193 struct _WapiHandlePrivate_process process;
197 /* Per-process handle info. For lookup convenience, each segment and
198 * index matches the corresponding shared data.
200 * Note that the additional segments have the same structure, but only
201 * the handle array is used.
203 struct _WapiHandlePrivate_list
205 #if !defined(_POSIX_THREAD_PROCESS_SHARED) || _POSIX_THREAD_PROCESS_SHARED == -1
206 mono_mutex_t signal_mutex;
207 pthread_cond_t signal_cond;
210 struct _WapiHandlePrivate handles[_WAPI_HANDLES_PER_SEGMENT];
214 #endif /* _WAPI_PRIVATE_H_ */