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