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 1
55 #define _WAPI_SHARED_NAMESPACE(type) (type==WAPI_HANDLE_MUTEX)
60 } WapiSharedNamespace;
63 WAPI_HANDLE_CAP_WAIT=0x01,
64 WAPI_HANDLE_CAP_SIGNAL=0x02,
65 WAPI_HANDLE_CAP_OWN=0x04,
66 } WapiHandleCapability;
70 void (*close_shared)(gpointer handle);
71 void (*close_private)(gpointer handle);
73 /* SignalObjectAndWait */
74 void (*signal)(gpointer signal);
76 /* Called by WaitForSingleObject and WaitForMultipleObjects,
77 * with the handle locked
79 void (*own_handle)(gpointer handle);
81 /* Called by WaitForSingleObject and WaitForMultipleObjects, if the
82 * handle in question is "ownable" (ie mutexes), to see if the current
83 * thread already owns this handle
85 gboolean (*is_owned)(gpointer handle);
88 #include <mono/io-layer/event-private.h>
89 #include <mono/io-layer/io-private.h>
90 #include <mono/io-layer/mutex-private.h>
91 #include <mono/io-layer/semaphore-private.h>
92 #include <mono/io-layer/socket-private.h>
93 #include <mono/io-layer/thread-private.h>
94 #include <mono/io-layer/process-private.h>
96 /* Shared threads don't seem to work yet */
97 #undef _POSIX_THREAD_PROCESS_SHARED
99 struct _WapiHandleShared
104 mono_mutex_t signal_mutex;
105 pthread_cond_t signal_cond;
109 struct _WapiHandle_event event;
110 struct _WapiHandle_file file;
111 struct _WapiHandle_find find;
112 struct _WapiHandle_mutex mutex;
113 struct _WapiHandle_sem sem;
114 struct _WapiHandle_socket sock;
115 struct _WapiHandle_thread thread;
116 struct _WapiHandle_process process;
120 #define _WAPI_HANDLES_PER_SEGMENT 4096
121 #define _WAPI_HANDLE_INVALID (gpointer)-1
123 #define _WAPI_SHM_SCRATCH_SIZE 512000
126 * This is the layout of the shared scratch data. When the data array
127 * is filled, it will be expanded by _WAPI_SHM_SCRATCH_SIZE
128 * bytes. (scratch data is always copied out of the shared memory, so
129 * it doesn't matter that the mapping will move around.)
131 struct _WapiHandleScratch
135 /* This is set to TRUE by the daemon. It determines whether a
136 * resize will go via mremap() or just realloc().
139 guchar scratch_data[MONO_ZERO_ARRAY_LENGTH];
143 * This is the layout of the shared memory segments. When the handles
144 * array is filled, another shared memory segment will be allocated
145 * with the same structure. This is to avoid having the shared memory
146 * potentially move if it is resized and remapped.
148 * Note that the additional segments have the same structure, but only
149 * the handle array is used.
151 struct _WapiHandleShared_list
153 guchar daemon[MONO_SIZEOF_SUNPATH];
154 _wapi_daemon_status daemon_running;
156 #if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1
157 mono_mutex_t signal_mutex;
158 pthread_cond_t signal_cond;
161 /* This holds the number of segments */
162 guint32 num_segments;
163 struct _WapiHandleShared handles[_WAPI_HANDLES_PER_SEGMENT];
166 struct _WapiHandlePrivate
172 struct _WapiHandlePrivate_event event;
173 struct _WapiHandlePrivate_file file;
174 struct _WapiHandlePrivate_find find;
175 struct _WapiHandlePrivate_mutex mutex;
176 struct _WapiHandlePrivate_sem sem;
177 struct _WapiHandlePrivate_socket sock;
178 struct _WapiHandlePrivate_thread thread;
179 struct _WapiHandlePrivate_process process;
183 /* Per-process handle info. For lookup convenience, each segment and
184 * index matches the corresponding shared data.
186 * Note that the additional segments have the same structure, but only
187 * the handle array is used.
189 struct _WapiHandlePrivate_list
191 #if !defined(_POSIX_THREAD_PROCESS_SHARED) || _POSIX_THREAD_PROCESS_SHARED == -1
192 mono_mutex_t signal_mutex;
193 pthread_cond_t signal_cond;
196 struct _WapiHandlePrivate handles[_WAPI_HANDLES_PER_SEGMENT];
200 #endif /* _WAPI_PRIVATE_H_ */