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 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 /* Shared threads don't seem to work yet */
21 #undef _POSIX_THREAD_PROCESS_SHARED
22
23 /* Increment this whenever an incompatible change is made to the
24  * shared handle structure.
25  */
26 #define _WAPI_HANDLE_VERSION 0
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_COUNT,
41 } WapiHandleType;
42
43 typedef enum {
44         WAPI_HANDLE_CAP_WAIT=0x01,
45         WAPI_HANDLE_CAP_SIGNAL=0x02,
46         WAPI_HANDLE_CAP_OWN=0x04,
47 } WapiHandleCapability;
48
49 struct _WapiHandleOps 
50 {
51         void (*close_shared)(gpointer handle);
52         void (*close_private)(gpointer handle);
53
54         /* SignalObjectAndWait */
55         void (*signal)(gpointer signal);
56
57         /* Called by WaitForSingleObject and WaitForMultipleObjects,
58          * with the handle locked
59          */
60         void (*own_handle)(gpointer handle);
61
62         /* Called by WaitForSingleObject and WaitForMultipleObjects, if the
63          * handle in question is "ownable" (ie mutexes), to see if the current
64          * thread already owns this handle
65          */
66         gboolean (*is_owned)(gpointer handle);
67 };
68
69 #include <mono/io-layer/event-private.h>
70 #include <mono/io-layer/io-private.h>
71 #include <mono/io-layer/mutex-private.h>
72 #include <mono/io-layer/semaphore-private.h>
73 #include <mono/io-layer/socket-private.h>
74 #include <mono/io-layer/thread-private.h>
75 #include <mono/io-layer/process-private.h>
76
77 struct _WapiHandleShared
78 {
79         WapiHandleType type;
80         guint ref;
81         gboolean signalled;
82         mono_mutex_t signal_mutex;
83         pthread_cond_t signal_cond;
84         
85         union 
86         {
87                 struct _WapiHandle_event event;
88                 struct _WapiHandle_file file;
89                 struct _WapiHandle_find find;
90                 struct _WapiHandle_mutex mutex;
91                 struct _WapiHandle_sem sem;
92                 struct _WapiHandle_socket sock;
93                 struct _WapiHandle_thread thread;
94                 struct _WapiHandle_process process;
95         } u;
96 };
97
98 #define _WAPI_MAX_HANDLES 4096
99 #define _WAPI_HANDLE_INVALID (gpointer)-1
100
101 /*
102  * This is the layout of the shared memory segment
103  */
104 struct _WapiHandleShared_list
105 {
106         guchar daemon[MONO_SIZEOF_SUNPATH];
107         _wapi_daemon_status daemon_running;
108         
109 #ifdef _POSIX_THREAD_PROCESS_SHARED
110         mono_mutex_t signal_mutex;
111         pthread_cond_t signal_cond;
112 #endif
113         struct _WapiHandleShared handles[_WAPI_MAX_HANDLES];
114         guchar scratch_base[0];
115 };
116
117 struct _WapiHandlePrivate
118 {
119         union 
120         {
121                 struct _WapiHandlePrivate_event event;
122                 struct _WapiHandlePrivate_file file;
123                 struct _WapiHandlePrivate_find find;
124                 struct _WapiHandlePrivate_mutex mutex;
125                 struct _WapiHandlePrivate_sem sem;
126                 struct _WapiHandlePrivate_socket sock;
127                 struct _WapiHandlePrivate_thread thread;
128                 struct _WapiHandlePrivate_process process;
129         } u;
130 };
131
132 /* Per-process handle info. For lookup convenience, each index matches
133  * the corresponding shared data.
134  */
135 struct _WapiHandlePrivate_list
136 {
137 #ifndef _POSIX_THREAD_PROCESS_SHARED
138         mono_mutex_t signal_mutex;
139         pthread_cond_t signal_cond;
140 #endif
141         struct _WapiHandlePrivate handles[_WAPI_MAX_HANDLES];
142 };
143
144
145 #endif /* _WAPI_PRIVATE_H_ */