[NDK]
[reactos.git] / reactos / include / ndk / lpctypes.h
1 /*++ NDK Version: 0098
2
3 Copyright (c) Alex Ionescu. All rights reserved.
4
5 Header Name:
6
7 lpctypes.h
8
9 Abstract:
10
11 Type definitions for the Loader.
12
13 Author:
14
15 Alex Ionescu (alexi@tinykrnl.org) - Updated - 27-Feb-2006
16
17 --*/
18
19 #ifndef _LPCTYPES_H
20 #define _LPCTYPES_H
21
22 //
23 // Dependencies
24 //
25 #include <umtypes.h>
26 //#include <pstypes.h>
27
28 #ifndef NTOS_MODE_USER
29
30 //
31 // Kernel Exported Object Types
32 //
33 extern POBJECT_TYPE NTSYSAPI LpcPortObjectType;
34
35 #endif // !NTOS_MODE_USER
36
37 //
38 // Internal helper macro
39 //
40 #define N_ROUND_UP(x,s) \
41 (((ULONG)(x)+(s)-1) & ~((ULONG)(s)-1))
42
43 //
44 // Port Object Access Masks
45 //
46 #define PORT_CONNECT 0x1
47 #define PORT_ALL_ACCESS 0x1
48
49 //
50 // Port Object Flags
51 //
52 #define LPCP_CONNECTION_PORT 0x00000001
53 #define LPCP_UNCONNECTED_PORT 0x00000002
54 #define LPCP_COMMUNICATION_PORT 0x00000003
55 #define LPCP_CLIENT_PORT 0x00000004
56 #define LPCP_PORT_TYPE_MASK 0x0000000F
57 #define LPCP_PORT_DELETED 0x10000000
58 #define LPCP_WAITABLE_PORT 0x20000000
59 #define LPCP_NAME_DELETED 0x40000000
60 #define LPCP_SECURITY_DYNAMIC 0x80000000
61
62 //
63 // LPC Message Types
64 //
65 typedef enum _LPC_TYPE
66 {
67 LPC_NEW_MESSAGE,
68 LPC_REQUEST,
69 LPC_REPLY,
70 LPC_DATAGRAM,
71 LPC_LOST_REPLY,
72 LPC_PORT_CLOSED,
73 LPC_CLIENT_DIED,
74 LPC_EXCEPTION,
75 LPC_DEBUG_EVENT,
76 LPC_ERROR_EVENT,
77 LPC_CONNECTION_REQUEST,
78 LPC_CONNECTION_REFUSED,
79 LPC_MAXIMUM
80 } LPC_TYPE;
81
82 //
83 // Information Classes for NtQueryInformationPort
84 //
85 typedef enum _PORT_INFORMATION_CLASS
86 {
87 PortNoInformation
88 } PORT_INFORMATION_CLASS;
89
90 #ifdef NTOS_MODE_USER
91
92 //
93 // Maximum message size that can be sent through an LPC Port without a section
94 //
95 #ifdef _WIN64
96 #define PORT_MAXIMUM_MESSAGE_LENGTH 512
97 #else
98 #define PORT_MAXIMUM_MESSAGE_LENGTH 256
99 #endif
100
101 //
102 // Portable LPC Types for 32/64-bit compatibility
103 //
104 #ifdef USE_LPC6432
105 #define LPC_CLIENT_ID CLIENT_ID64
106 #define LPC_SIZE_T ULONGLONG
107 #define LPC_PVOID ULONGLONG
108 #define LPC_HANDLE ULONGLONG
109 #else
110 #define LPC_CLIENT_ID CLIENT_ID
111 #define LPC_SIZE_T SIZE_T
112 #define LPC_PVOID PVOID
113 #define LPC_HANDLE HANDLE
114 #endif
115
116 //
117 // LPC Port Message
118 //
119 typedef struct _PORT_MESSAGE
120 {
121 union
122 {
123 struct
124 {
125 CSHORT DataLength;
126 CSHORT TotalLength;
127 } s1;
128 ULONG Length;
129 } u1;
130 union
131 {
132 struct
133 {
134 CSHORT Type;
135 CSHORT DataInfoOffset;
136 } s2;
137 ULONG ZeroInit;
138 } u2;
139 union
140 {
141 LPC_CLIENT_ID ClientId;
142 double DoNotUseThisField;
143 };
144 ULONG MessageId;
145 union
146 {
147 LPC_SIZE_T ClientViewSize;
148 ULONG CallbackId;
149 };
150 } PORT_MESSAGE, *PPORT_MESSAGE;
151
152 //
153 // Local and Remove Port Views
154 //
155 typedef struct _PORT_VIEW
156 {
157 ULONG Length;
158 LPC_HANDLE SectionHandle;
159 ULONG SectionOffset;
160 LPC_SIZE_T ViewSize;
161 LPC_PVOID ViewBase;
162 LPC_PVOID ViewRemoteBase;
163 } PORT_VIEW, *PPORT_VIEW;
164
165 typedef struct _REMOTE_PORT_VIEW
166 {
167 ULONG Length;
168 LPC_SIZE_T ViewSize;
169 LPC_PVOID ViewBase;
170 } REMOTE_PORT_VIEW, *PREMOTE_PORT_VIEW;
171
172 //
173 // LPC Kernel-Mode Message Structures defined for size only
174 //
175 typedef struct _LPCP_MESSAGE
176 {
177 UCHAR Data[0x14];
178 PORT_MESSAGE Request;
179 } LPCP_MESSAGE;
180
181 typedef struct _LPCP_CONNECTION_MESSAGE
182 {
183 UCHAR Data[0x2C];
184 } LPCP_CONNECTION_MESSAGE;
185
186 #else
187
188 //
189 // LPC Paged and Non-Paged Port Queues
190 //
191 typedef struct _LPCP_NONPAGED_PORT_QUEUE
192 {
193 KSEMAPHORE Semaphore;
194 struct _LPCP_PORT_OBJECT *BackPointer;
195 } LPCP_NONPAGED_PORT_QUEUE, *PLPCP_NONPAGED_PORT_QUEUE;
196
197 typedef struct _LPCP_PORT_QUEUE
198 {
199 PLPCP_NONPAGED_PORT_QUEUE NonPagedPortQueue;
200 PKSEMAPHORE Semaphore;
201 LIST_ENTRY ReceiveHead;
202 } LPCP_PORT_QUEUE, *PLPCP_PORT_QUEUE;
203
204 //
205 // LPC Port Object
206 //
207 typedef struct _LPCP_PORT_OBJECT
208 {
209 struct _LPCP_PORT_OBJECT *ConnectionPort;
210 struct _LPCP_PORT_OBJECT *ConnectedPort;
211 LPCP_PORT_QUEUE MsgQueue;
212 CLIENT_ID Creator;
213 PVOID ClientSectionBase;
214 PVOID ServerSectionBase;
215 PVOID PortContext;
216 PETHREAD ClientThread;
217 SECURITY_QUALITY_OF_SERVICE SecurityQos;
218 SECURITY_CLIENT_CONTEXT StaticSecurity;
219 LIST_ENTRY LpcReplyChainHead;
220 LIST_ENTRY LpcDataInfoChainHead;
221 union
222 {
223 PEPROCESS ServerProcess;
224 PEPROCESS MappingProcess;
225 };
226 ULONG MaxMessageLength;
227 ULONG MaxConnectionInfoLength;
228 ULONG Flags;
229 KEVENT WaitEvent;
230 } LPCP_PORT_OBJECT, *PLPCP_PORT_OBJECT;
231
232 //
233 // LPC Kernel-Mode Message Structures
234 //
235 typedef struct _LPCP_MESSAGE
236 {
237 union
238 {
239 LIST_ENTRY Entry;
240 struct
241 {
242 SINGLE_LIST_ENTRY FreeEntry;
243 ULONG Reserved0;
244 };
245 };
246 PLPCP_PORT_OBJECT SenderPort;
247 PETHREAD RepliedToThread;
248 PVOID PortContext;
249 PORT_MESSAGE Request;
250 } LPCP_MESSAGE, *PLPCP_MESSAGE;
251
252 typedef struct _LPCP_CONNECTION_MESSAGE
253 {
254 PORT_VIEW ClientView;
255 PLPCP_PORT_OBJECT ClientPort;
256 PVOID SectionToMap;
257 REMOTE_PORT_VIEW ServerView;
258 } LPCP_CONNECTION_MESSAGE, *PLPCP_CONNECTION_MESSAGE;
259
260 #endif
261
262 //
263 // Client Died LPC Message
264 //
265 typedef struct _CLIENT_DIED_MSG
266 {
267 PORT_MESSAGE h;
268 LARGE_INTEGER CreateTime;
269 } CLIENT_DIED_MSG, *PCLIENT_DIED_MSG;
270
271 //
272 // Maximum total Kernel-Mode LPC Message Structure Size
273 //
274 #define LPCP_MAX_MESSAGE_SIZE \
275 N_ROUND_UP(PORT_MAXIMUM_MESSAGE_LENGTH + \
276 sizeof(LPCP_MESSAGE) + \
277 sizeof(LPCP_CONNECTION_MESSAGE), 16)
278
279 //
280 // Maximum actual LPC Message Length
281 //
282 #define LPC_MAX_MESSAGE_LENGTH \
283 (LPCP_MAX_MESSAGE_SIZE - \
284 FIELD_OFFSET(LPCP_MESSAGE, Request))
285
286 //
287 // Maximum actual size of LPC Message Data
288 //
289 #define LPC_MAX_DATA_LENGTH \
290 (LPC_MAX_MESSAGE_LENGTH - \
291 sizeof(PORT_MESSAGE) - \
292 sizeof(LPCP_CONNECTION_MESSAGE))
293
294 #endif // _LPCTYPES_H