[io-layer] Add typename and typesize handle operations
[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 extern gboolean _wapi_has_shut_down;
24
25 typedef enum {
26         WAPI_HANDLE_UNUSED=0,
27         WAPI_HANDLE_FILE,
28         WAPI_HANDLE_CONSOLE,
29         WAPI_HANDLE_THREAD,
30         WAPI_HANDLE_SEM,
31         WAPI_HANDLE_MUTEX,
32         WAPI_HANDLE_EVENT,
33         WAPI_HANDLE_SOCKET,
34         WAPI_HANDLE_FIND,
35         WAPI_HANDLE_PROCESS,
36         WAPI_HANDLE_PIPE,
37         WAPI_HANDLE_NAMEDMUTEX,
38         WAPI_HANDLE_NAMEDSEM,
39         WAPI_HANDLE_NAMEDEVENT,
40         WAPI_HANDLE_COUNT
41 } WapiHandleType;
42
43 extern const char *_wapi_handle_typename[];
44
45 #define _WAPI_FD_HANDLE(type) (type == WAPI_HANDLE_FILE || \
46                                type == WAPI_HANDLE_CONSOLE || \
47                                type == WAPI_HANDLE_SOCKET || \
48                                type == WAPI_HANDLE_PIPE)
49
50 #define _WAPI_SHARED_NAMESPACE(type) (type == WAPI_HANDLE_NAMEDMUTEX || \
51                                       type == WAPI_HANDLE_NAMEDSEM || \
52                                       type == WAPI_HANDLE_NAMEDEVENT)
53
54 typedef struct 
55 {
56         gchar name[MAX_PATH + 1];
57 } WapiSharedNamespace;
58
59 typedef enum {
60         WAPI_HANDLE_CAP_WAIT=0x01,
61         WAPI_HANDLE_CAP_SIGNAL=0x02,
62         WAPI_HANDLE_CAP_OWN=0x04,
63         WAPI_HANDLE_CAP_SPECIAL_WAIT=0x08
64 } WapiHandleCapability;
65
66 struct _WapiHandleOps 
67 {
68         void (*close)(gpointer handle, gpointer data);
69
70         /* SignalObjectAndWait */
71         void (*signal)(gpointer signal);
72
73         /* Called by WaitForSingleObject and WaitForMultipleObjects,
74          * with the handle locked (shared handles aren't locked.)
75          * Returns TRUE if ownership was established, false otherwise.
76          */
77         gboolean (*own_handle)(gpointer handle);
78
79         /* Called by WaitForSingleObject and WaitForMultipleObjects, if the
80          * handle in question is "ownable" (ie mutexes), to see if the current
81          * thread already owns this handle
82          */
83         gboolean (*is_owned)(gpointer handle);
84
85         /* Called by WaitForSingleObject and WaitForMultipleObjects,
86          * if the handle in question needs a special wait function
87          * instead of using the normal handle signal mechanism.
88          * Returns the WaitForSingleObject return code.
89          */
90         guint32 (*special_wait)(gpointer handle, guint32 timeout, gboolean alertable);
91
92         /* Called by WaitForSingleObject and WaitForMultipleObjects,
93          * if the handle in question needs some preprocessing before the
94          * signal wait.
95          */
96         void (*prewait)(gpointer handle);
97
98         /* Called when dumping the handles */
99         void (*details)(gpointer data);
100
101         /* Called to get the name of the handle type */
102         const gchar* (*typename) (void);
103
104         /* Called to get the size of the handle type */
105         gsize (*typesize) (void);
106 };
107
108 #include <mono/io-layer/event-private.h>
109 #include <mono/io-layer/io-private.h>
110 #include <mono/io-layer/mutex-private.h>
111 #include <mono/io-layer/semaphore-private.h>
112 #include <mono/io-layer/socket-private.h>
113 #include <mono/io-layer/thread-private.h>
114 #include <mono/io-layer/process-private.h>
115
116 struct _WapiHandle_shared_ref
117 {
118         /* This will be split 16:16 with the shared file segment in
119          * the top half, when I implement space increases
120          */
121         guint32 offset;
122 };
123
124 #define _WAPI_SHARED_SEM_NAMESPACE 0
125 /*#define _WAPI_SHARED_SEM_COLLECTION 1*/
126 #define _WAPI_SHARED_SEM_FILESHARE 2
127 #define _WAPI_SHARED_SEM_PROCESS_COUNT_LOCK 6
128 #define _WAPI_SHARED_SEM_PROCESS_COUNT 7
129 #define _WAPI_SHARED_SEM_COUNT 8        /* Leave some future expansion space */
130
131 struct _WapiFileShare
132 {
133 #ifdef WAPI_FILE_SHARE_PLATFORM_EXTRA_DATA
134         WAPI_FILE_SHARE_PLATFORM_EXTRA_DATA
135 #endif
136         guint64 device;
137         guint64 inode;
138         pid_t opened_by_pid;
139         guint32 sharemode;
140         guint32 access;
141         guint32 handle_refs;
142         guint32 timestamp;
143 };
144
145 typedef struct _WapiFileShare _WapiFileShare;
146
147 #define _WAPI_HANDLE_INVALID (gpointer)-1
148
149 pid_t
150 _wapi_getpid (void);
151
152 #endif /* _WAPI_PRIVATE_H_ */