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