[boehm] Put *_freelists into thread_local_freelists (as in BDWGC v7)
[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-2006 Novell, Inc.
8  */
9
10 #ifndef _WAPI_PRIVATE_H_
11 #define _WAPI_PRIVATE_H_
12
13 #include <config.h>
14 #include <glib.h>
15 #include <sys/stat.h>
16
17 #include <mono/io-layer/handles.h>
18 #include <mono/io-layer/io.h>
19
20 /* Increment this whenever an incompatible change is made to the
21  * shared handle structure.
22  */
23 #define _WAPI_HANDLE_VERSION 12
24
25 typedef enum {
26         WAPI_HANDLE_UNUSED=0,
27         WAPI_HANDLE_FILE,
28         WAPI_HANDLE_CONSOLE,
29         WAPI_HANDLE_THREAD,
30         WAPI_HANDLE_SEM,
31         WAPI_HANDLE_MUTEX,
32         WAPI_HANDLE_EVENT,
33         WAPI_HANDLE_SOCKET,
34         WAPI_HANDLE_FIND,
35         WAPI_HANDLE_PROCESS,
36         WAPI_HANDLE_PIPE,
37         WAPI_HANDLE_NAMEDMUTEX,
38         WAPI_HANDLE_NAMEDSEM,
39         WAPI_HANDLE_NAMEDEVENT,
40         WAPI_HANDLE_COUNT
41 } WapiHandleType;
42
43 extern const char *_wapi_handle_typename[];
44
45 #define _WAPI_SHARED_HANDLE(type) (type == WAPI_HANDLE_NAMEDMUTEX || \
46                                    type == WAPI_HANDLE_NAMEDSEM || \
47                                    type == WAPI_HANDLE_NAMEDEVENT)
48
49 #define _WAPI_FD_HANDLE(type) (type == WAPI_HANDLE_FILE || \
50                                type == WAPI_HANDLE_CONSOLE || \
51                                type == WAPI_HANDLE_SOCKET || \
52                                type == WAPI_HANDLE_PIPE)
53
54 #define _WAPI_SHARED_NAMESPACE(type) (type == WAPI_HANDLE_NAMEDMUTEX || \
55                                       type == WAPI_HANDLE_NAMEDSEM || \
56                                       type == WAPI_HANDLE_NAMEDEVENT)
57
58 typedef struct 
59 {
60         gchar name[MAX_PATH + 1];
61 } WapiSharedNamespace;
62
63 typedef enum {
64         WAPI_HANDLE_CAP_WAIT=0x01,
65         WAPI_HANDLE_CAP_SIGNAL=0x02,
66         WAPI_HANDLE_CAP_OWN=0x04,
67         WAPI_HANDLE_CAP_SPECIAL_WAIT=0x08
68 } WapiHandleCapability;
69
70 struct _WapiHandleOps 
71 {
72         void (*close)(gpointer handle, gpointer data);
73
74         /* SignalObjectAndWait */
75         void (*signal)(gpointer signal);
76
77         /* Called by WaitForSingleObject and WaitForMultipleObjects,
78          * with the handle locked (shared handles aren't locked.)
79          * Returns TRUE if ownership was established, false otherwise.
80          */
81         gboolean (*own_handle)(gpointer handle);
82
83         /* Called by WaitForSingleObject and WaitForMultipleObjects, if the
84          * handle in question is "ownable" (ie mutexes), to see if the current
85          * thread already owns this handle
86          */
87         gboolean (*is_owned)(gpointer handle);
88
89         /* Called by WaitForSingleObject and WaitForMultipleObjects,
90          * if the handle in question needs a special wait function
91          * instead of using the normal handle signal mechanism.
92          * Returns the WaitForSingleObject return code.
93          */
94         guint32 (*special_wait)(gpointer handle, guint32 timeout, gboolean alertable);
95
96         /* Called by WaitForSingleObject and WaitForMultipleObjects,
97          * if the handle in question needs some preprocessing before the
98          * signal wait.
99          */
100         void (*prewait)(gpointer handle);
101 };
102
103 #include <mono/io-layer/event-private.h>
104 #include <mono/io-layer/io-private.h>
105 #include <mono/io-layer/mutex-private.h>
106 #include <mono/io-layer/semaphore-private.h>
107 #include <mono/io-layer/socket-private.h>
108 #include <mono/io-layer/thread-private.h>
109 #include <mono/io-layer/process-private.h>
110
111 struct _WapiHandle_shared_ref
112 {
113         /* This will be split 16:16 with the shared file segment in
114          * the top half, when I implement space increases
115          */
116         guint32 offset;
117 };
118
119 #define _WAPI_HANDLE_INITIAL_COUNT 256
120
121 struct _WapiHandleUnshared
122 {
123         WapiHandleType type;
124         guint ref;
125         gboolean signalled;
126         mono_mutex_t signal_mutex;
127         pthread_cond_t signal_cond;
128         
129         union 
130         {
131                 struct _WapiHandle_event event;
132                 struct _WapiHandle_file file;
133                 struct _WapiHandle_find find;
134                 struct _WapiHandle_mutex mutex;
135                 struct _WapiHandle_sem sem;
136                 struct _WapiHandle_socket sock;
137                 struct _WapiHandle_thread thread;
138                 struct _WapiHandle_process process;
139                 struct _WapiHandle_shared_ref shared;
140         } u;
141 };
142
143 struct _WapiHandleShared
144 {
145         WapiHandleType type;
146         guint32 timestamp;
147         guint32 handle_refs;
148         volatile gboolean signalled;
149         
150         union
151         {
152                 struct _WapiHandle_namedmutex namedmutex;
153                 struct _WapiHandle_namedsem namedsem;
154                 struct _WapiHandle_namedevent namedevent;
155         } u;
156 };
157
158 #define _WAPI_SHARED_SEM_NAMESPACE 0
159 /*#define _WAPI_SHARED_SEM_COLLECTION 1*/
160 #define _WAPI_SHARED_SEM_FILESHARE 2
161 #define _WAPI_SHARED_SEM_SHARED_HANDLES 3
162 #define _WAPI_SHARED_SEM_PROCESS_COUNT_LOCK 6
163 #define _WAPI_SHARED_SEM_PROCESS_COUNT 7
164 #define _WAPI_SHARED_SEM_COUNT 8        /* Leave some future expansion space */
165
166 struct _WapiHandleSharedLayout
167 {
168         volatile guint32 collection_count;
169         volatile key_t sem_key;
170         
171         struct _WapiHandleShared handles[_WAPI_HANDLE_INITIAL_COUNT];
172 };
173
174 #define _WAPI_FILESHARE_SIZE 102400
175
176 struct _WapiFileShare
177 {
178 #ifdef WAPI_FILE_SHARE_PLATFORM_EXTRA_DATA
179         WAPI_FILE_SHARE_PLATFORM_EXTRA_DATA
180 #endif
181         guint64 device;
182         guint64 inode;
183         pid_t opened_by_pid;
184         guint32 sharemode;
185         guint32 access;
186         guint32 handle_refs;
187         guint32 timestamp;
188 };
189
190 typedef struct _WapiFileShare _WapiFileShare;
191
192 struct _WapiFileShareLayout
193 {
194         guint32 hwm;
195         
196         struct _WapiFileShare share_info[_WAPI_FILESHARE_SIZE];
197 };
198
199
200
201 #define _WAPI_HANDLE_INVALID (gpointer)-1
202
203 #endif /* _WAPI_PRIVATE_H_ */