updated browser capabilities file
[mono.git] / mono / io-layer / wapi-private.h
1 /*
2  * wapi-private.h:  internal definitions of handles and shared memory layout
3  *
4  * Author:
5  *      Dick Porter (dick@ximian.com)
6  *
7  * (C) 2002 Ximian, Inc.
8  */
9
10 #ifndef _WAPI_PRIVATE_H_
11 #define _WAPI_PRIVATE_H_
12
13 #include <config.h>
14 #include <glib.h>
15
16 #include <mono/io-layer/handles.h>
17 #include <mono/io-layer/io.h>
18 #include <mono/io-layer/daemon-private.h>
19
20 /* for non-GCC compilers where Glib gives an empty pretty function 
21  * macro create one that gives file & line number instead
22  */
23 #ifndef __GNUC__
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__) ")"
28 #endif
29
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
33 #endif
34
35 /* Increment this whenever an incompatible change is made to the
36  * shared handle structure.
37  */
38 #define _WAPI_HANDLE_VERSION 1
39
40 typedef enum {
41         WAPI_HANDLE_UNUSED=0,
42         WAPI_HANDLE_FILE,
43         WAPI_HANDLE_CONSOLE,
44         WAPI_HANDLE_THREAD,
45         WAPI_HANDLE_SEM,
46         WAPI_HANDLE_MUTEX,
47         WAPI_HANDLE_EVENT,
48         WAPI_HANDLE_SOCKET,
49         WAPI_HANDLE_FIND,
50         WAPI_HANDLE_PROCESS,
51         WAPI_HANDLE_PIPE,
52         WAPI_HANDLE_COUNT,
53 } WapiHandleType;
54
55 #define _WAPI_SHARED_NAMESPACE(type) (type==WAPI_HANDLE_MUTEX)
56
57 typedef struct 
58 {
59         guint32 name;
60 } WapiSharedNamespace;
61
62 typedef enum {
63         WAPI_HANDLE_CAP_WAIT=0x01,
64         WAPI_HANDLE_CAP_SIGNAL=0x02,
65         WAPI_HANDLE_CAP_OWN=0x04,
66 } WapiHandleCapability;
67
68 struct _WapiHandleOps 
69 {
70         void (*close_shared)(gpointer handle);
71         void (*close_private)(gpointer handle);
72
73         /* SignalObjectAndWait */
74         void (*signal)(gpointer signal);
75
76         /* Called by WaitForSingleObject and WaitForMultipleObjects,
77          * with the handle locked
78          */
79         void (*own_handle)(gpointer handle);
80
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
84          */
85         gboolean (*is_owned)(gpointer handle);
86 };
87
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>
95
96 /* Shared threads don't seem to work yet */
97 #undef _POSIX_THREAD_PROCESS_SHARED
98
99 struct _WapiHandleShared
100 {
101         WapiHandleType type;
102         guint ref;
103         gboolean signalled;
104         mono_mutex_t signal_mutex;
105         pthread_cond_t signal_cond;
106         
107         union 
108         {
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;
117         } u;
118 };
119
120 #define _WAPI_HANDLES_PER_SEGMENT 4096
121 #define _WAPI_HANDLE_INVALID (gpointer)-1
122
123 #define _WAPI_SHM_SCRATCH_SIZE 512000
124
125 /*
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.)
130  */
131 struct _WapiHandleScratch
132 {
133         guint32 data_len;
134
135         /* This is set to TRUE by the daemon.  It determines whether a
136          * resize will go via mremap() or just realloc().
137          */
138         gboolean is_shared;
139         guchar scratch_data[MONO_ZERO_ARRAY_LENGTH];
140 };
141
142 /*
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.
147  *
148  * Note that the additional segments have the same structure, but only
149  * the handle array is used.
150  */
151 struct _WapiHandleShared_list
152 {
153         guchar daemon[MONO_SIZEOF_SUNPATH];
154         _wapi_daemon_status daemon_running;
155         
156 #if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1
157         mono_mutex_t signal_mutex;
158         pthread_cond_t signal_cond;
159 #endif
160
161         /* This holds the number of segments */
162         guint32 num_segments;
163         struct _WapiHandleShared handles[_WAPI_HANDLES_PER_SEGMENT];
164 };
165
166 struct _WapiHandlePrivate
167 {
168         WapiHandleType type;
169
170         union 
171         {
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;
180         } u;
181 };
182
183 /* Per-process handle info. For lookup convenience, each segment and
184  * index matches the corresponding shared data.
185  *
186  * Note that the additional segments have the same structure, but only
187  * the handle array is used.
188  */
189 struct _WapiHandlePrivate_list
190 {
191 #if !defined(_POSIX_THREAD_PROCESS_SHARED) || _POSIX_THREAD_PROCESS_SHARED == -1
192         mono_mutex_t signal_mutex;
193         pthread_cond_t signal_cond;
194 #endif
195         
196         struct _WapiHandlePrivate handles[_WAPI_HANDLES_PER_SEGMENT];
197 };
198
199
200 #endif /* _WAPI_PRIVATE_H_ */