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