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