2002-09-27 Dick Porter <dick@ximian.com>
[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  * If this ever reaches 255, we have problems :-(
27  */
28 #define _WAPI_HANDLE_VERSION 7
29
30 typedef enum {
31         WAPI_HANDLE_UNUSED=0,
32         WAPI_HANDLE_FILE,
33         WAPI_HANDLE_CONSOLE,
34         WAPI_HANDLE_THREAD,
35         WAPI_HANDLE_SEM,
36         WAPI_HANDLE_MUTEX,
37         WAPI_HANDLE_EVENT,
38         WAPI_HANDLE_SOCKET,
39         WAPI_HANDLE_FIND,
40         WAPI_HANDLE_PROCESS,
41         WAPI_HANDLE_PIPE,
42         WAPI_HANDLE_COUNT,
43 } WapiHandleType;
44
45 typedef enum {
46         WAPI_HANDLE_CAP_WAIT=0x01,
47         WAPI_HANDLE_CAP_SIGNAL=0x02,
48         WAPI_HANDLE_CAP_OWN=0x04,
49 } WapiHandleCapability;
50
51 struct _WapiHandleOps 
52 {
53         void (*close_shared)(gpointer handle);
54         void (*close_private)(gpointer handle);
55
56         /* SignalObjectAndWait */
57         void (*signal)(gpointer signal);
58
59         /* Called by WaitForSingleObject and WaitForMultipleObjects,
60          * with the handle locked
61          */
62         void (*own_handle)(gpointer handle);
63
64         /* Called by WaitForSingleObject and WaitForMultipleObjects, if the
65          * handle in question is "ownable" (ie mutexes), to see if the current
66          * thread already owns this handle
67          */
68         gboolean (*is_owned)(gpointer handle);
69 };
70
71 #include <mono/io-layer/event-private.h>
72 #include <mono/io-layer/io-private.h>
73 #include <mono/io-layer/mutex-private.h>
74 #include <mono/io-layer/semaphore-private.h>
75 #include <mono/io-layer/socket-private.h>
76 #include <mono/io-layer/thread-private.h>
77 #include <mono/io-layer/process-private.h>
78
79 struct _WapiHandleShared
80 {
81         WapiHandleType type;
82         guint ref;
83         gboolean signalled;
84         mono_mutex_t signal_mutex;
85         pthread_cond_t signal_cond;
86         
87         union 
88         {
89                 struct _WapiHandle_event event;
90                 struct _WapiHandle_file file;
91                 struct _WapiHandle_find find;
92                 struct _WapiHandle_mutex mutex;
93                 struct _WapiHandle_sem sem;
94                 struct _WapiHandle_socket sock;
95                 struct _WapiHandle_thread thread;
96                 struct _WapiHandle_process process;
97         } u;
98 };
99
100 #define _WAPI_MAX_HANDLES 4096
101 #define _WAPI_HANDLE_INVALID (gpointer)-1
102
103 /*
104  * This is the layout of the shared memory segment
105  */
106 struct _WapiHandleShared_list
107 {
108         guchar daemon[MONO_SIZEOF_SUNPATH];
109         _wapi_daemon_status daemon_running;
110         
111 #ifdef _POSIX_THREAD_PROCESS_SHARED
112         mono_mutex_t signal_mutex;
113         pthread_cond_t signal_cond;
114 #endif
115         struct _WapiHandleShared handles[_WAPI_MAX_HANDLES];
116         guchar scratch_base[0];
117 };
118
119 struct _WapiHandlePrivate
120 {
121         union 
122         {
123                 struct _WapiHandlePrivate_event event;
124                 struct _WapiHandlePrivate_file file;
125                 struct _WapiHandlePrivate_find find;
126                 struct _WapiHandlePrivate_mutex mutex;
127                 struct _WapiHandlePrivate_sem sem;
128                 struct _WapiHandlePrivate_socket sock;
129                 struct _WapiHandlePrivate_thread thread;
130                 struct _WapiHandlePrivate_process process;
131         } u;
132 };
133
134 /* Per-process handle info. For lookup convenience, each index matches
135  * the corresponding shared data.
136  */
137 struct _WapiHandlePrivate_list
138 {
139 #ifndef _POSIX_THREAD_PROCESS_SHARED
140         mono_mutex_t signal_mutex;
141         pthread_cond_t signal_cond;
142 #endif
143         struct _WapiHandlePrivate handles[_WAPI_MAX_HANDLES];
144 };
145
146
147 #endif /* _WAPI_PRIVATE_H_ */