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