Merge pull request #3214 from tritao/zip_new_entries_writes
[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_FD_HANDLE(type) (type == WAPI_HANDLE_FILE || \
49                                type == WAPI_HANDLE_CONSOLE || \
50                                type == WAPI_HANDLE_SOCKET || \
51                                type == WAPI_HANDLE_PIPE)
52
53 #define _WAPI_SHARED_NAMESPACE(type) (type == WAPI_HANDLE_NAMEDMUTEX || \
54                                       type == WAPI_HANDLE_NAMEDSEM || \
55                                       type == WAPI_HANDLE_NAMEDEVENT)
56
57 typedef struct 
58 {
59         gchar name[MAX_PATH + 1];
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         WAPI_HANDLE_CAP_SPECIAL_WAIT=0x08
67 } WapiHandleCapability;
68
69 struct _WapiHandleOps 
70 {
71         void (*close)(gpointer handle, gpointer data);
72
73         /* SignalObjectAndWait */
74         void (*signal)(gpointer signal);
75
76         /* Called by WaitForSingleObject and WaitForMultipleObjects,
77          * with the handle locked (shared handles aren't locked.)
78          * Returns TRUE if ownership was established, false otherwise.
79          */
80         gboolean (*own_handle)(gpointer handle);
81
82         /* Called by WaitForSingleObject and WaitForMultipleObjects, if the
83          * handle in question is "ownable" (ie mutexes), to see if the current
84          * thread already owns this handle
85          */
86         gboolean (*is_owned)(gpointer handle);
87
88         /* Called by WaitForSingleObject and WaitForMultipleObjects,
89          * if the handle in question needs a special wait function
90          * instead of using the normal handle signal mechanism.
91          * Returns the WaitForSingleObject return code.
92          */
93         guint32 (*special_wait)(gpointer handle, guint32 timeout, gboolean alertable);
94
95         /* Called by WaitForSingleObject and WaitForMultipleObjects,
96          * if the handle in question needs some preprocessing before the
97          * signal wait.
98          */
99         void (*prewait)(gpointer handle);
100 };
101
102 #include <mono/io-layer/event-private.h>
103 #include <mono/io-layer/io-private.h>
104 #include <mono/io-layer/mutex-private.h>
105 #include <mono/io-layer/semaphore-private.h>
106 #include <mono/io-layer/socket-private.h>
107 #include <mono/io-layer/thread-private.h>
108 #include <mono/io-layer/process-private.h>
109
110 struct _WapiHandle_shared_ref
111 {
112         /* This will be split 16:16 with the shared file segment in
113          * the top half, when I implement space increases
114          */
115         guint32 offset;
116 };
117
118 #define _WAPI_HANDLE_INITIAL_COUNT 256
119
120 struct _WapiHandleUnshared
121 {
122         WapiHandleType type;
123         guint ref;
124         gboolean signalled;
125         mono_mutex_t signal_mutex;
126         mono_cond_t signal_cond;
127         
128         union 
129         {
130                 struct _WapiHandle_event event;
131                 struct _WapiHandle_file file;
132                 struct _WapiHandle_find find;
133                 struct _WapiHandle_mutex mutex;
134                 struct _WapiHandle_sem sem;
135                 struct _WapiHandle_socket sock;
136                 struct _WapiHandle_thread thread;
137                 struct _WapiHandle_process process;
138                 struct _WapiHandle_shared_ref shared;
139                 struct _WapiHandle_namedmutex namedmutex;
140                 struct _WapiHandle_namedsem namedsem;
141                 struct _WapiHandle_namedevent namedevent;
142         } u;
143 };
144
145 #define _WAPI_SHARED_SEM_NAMESPACE 0
146 /*#define _WAPI_SHARED_SEM_COLLECTION 1*/
147 #define _WAPI_SHARED_SEM_FILESHARE 2
148 #define _WAPI_SHARED_SEM_PROCESS_COUNT_LOCK 6
149 #define _WAPI_SHARED_SEM_PROCESS_COUNT 7
150 #define _WAPI_SHARED_SEM_COUNT 8        /* Leave some future expansion space */
151
152 struct _WapiFileShare
153 {
154 #ifdef WAPI_FILE_SHARE_PLATFORM_EXTRA_DATA
155         WAPI_FILE_SHARE_PLATFORM_EXTRA_DATA
156 #endif
157         guint64 device;
158         guint64 inode;
159         pid_t opened_by_pid;
160         guint32 sharemode;
161         guint32 access;
162         guint32 handle_refs;
163         guint32 timestamp;
164 };
165
166 typedef struct _WapiFileShare _WapiFileShare;
167
168 #define _WAPI_HANDLE_INVALID (gpointer)-1
169
170 #endif /* _WAPI_PRIVATE_H_ */