xref: /reactos/sdk/include/reactos/subsys/csr/csrmsg.h (revision 7353af1e)
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS Client/Server Runtime SubSystem
4  * FILE:            include/reactos/subsys/csr/csrmsg.h
5  * PURPOSE:         Public definitions for communication
6  *                  between CSR Clients and Servers
7  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
8  *                  Hermes Belusca-Maito (hermes.belusca@sfr.fr)
9  */
10 
11 #ifndef _CSRMSG_H
12 #define _CSRMSG_H
13 
14 #pragma once
15 
16 
17 #define CSR_PORT_NAME L"ApiPort" // CSR_API_PORT_NAME
18 
19 
20 #define CSRSRV_SERVERDLL_INDEX      0
21 #define CSRSRV_FIRST_API_NUMBER     0
22 
23 typedef enum _CSRSRV_API_NUMBER
24 {
25     CsrpClientConnect = CSRSRV_FIRST_API_NUMBER,
26     CsrpThreadConnect,
27     CsrpProfileControl,
28     CsrpIdentifyAlertableThread,
29     CsrpSetPriorityClass,
30 
31     CsrpMaxApiNumber
32 } CSRSRV_API_NUMBER, *PCSRSRV_API_NUMBER;
33 
34 
35 typedef ULONG CSR_API_NUMBER;
36 
37 #define CSR_CREATE_API_NUMBER(ServerId, ApiId) \
38     (CSR_API_NUMBER)(((ServerId) << 16) | (ApiId))
39 
40 #define CSR_API_NUMBER_TO_SERVER_ID(ApiNumber) \
41     (ULONG)((ULONG)(ApiNumber) >> 16)
42 
43 #define CSR_API_NUMBER_TO_API_ID(ApiNumber) \
44     (ULONG)((ULONG)(ApiNumber) & 0xFFFF)
45 
46 
47 typedef struct _CSR_API_CONNECTINFO
48 {
49     HANDLE ObjectDirectory; // Unused on Windows >= 2k3
50     PVOID  SharedSectionBase;
51     PVOID  SharedStaticServerData;
52     PVOID  SharedSectionHeap;
53     ULONG  DebugFlags;
54     ULONG  SizeOfPebData;
55     ULONG  SizeOfTebData;
56     ULONG  NumberOfServerDllNames;
57     HANDLE ServerProcessId;
58 } CSR_API_CONNECTINFO, *PCSR_API_CONNECTINFO;
59 
60 #if defined(_M_IX86)
61 C_ASSERT(sizeof(CSR_API_CONNECTINFO) == 0x24);
62 #endif
63 
64 // We must have a size at most equal to the maximum acceptable LPC data size.
65 C_ASSERT(sizeof(CSR_API_CONNECTINFO) <= LPC_MAX_DATA_LENGTH);
66 
67 
68 #if (NTDDI_VERSION < NTDDI_WS03)
69 
70 typedef struct _CSR_IDENTIFY_ALERTABLE_THREAD
71 {
72     CLIENT_ID Cid;
73 } CSR_IDENTIFY_ALERTABLE_THREAD, *PCSR_IDENTIFY_ALERTABLE_THREAD;
74 
75 typedef struct _CSR_SET_PRIORITY_CLASS
76 {
77     HANDLE hProcess;
78     ULONG PriorityClass;
79 } CSR_SET_PRIORITY_CLASS, *PCSR_SET_PRIORITY_CLASS;
80 
81 #endif // (NTDDI_VERSION < NTDDI_WS03)
82 
83 typedef struct _CSR_CLIENT_CONNECT
84 {
85     ULONG ServerId;
86     PVOID ConnectionInfo;
87     ULONG ConnectionInfoSize;
88 } CSR_CLIENT_CONNECT, *PCSR_CLIENT_CONNECT;
89 
90 typedef struct _CSR_CAPTURE_BUFFER
91 {
92     ULONG Size;
93     struct _CSR_CAPTURE_BUFFER *PreviousCaptureBuffer;
94     ULONG PointerCount;
95     PVOID BufferEnd;
96     ULONG_PTR PointerOffsetsArray[ANYSIZE_ARRAY];
97 } CSR_CAPTURE_BUFFER, *PCSR_CAPTURE_BUFFER;
98 
99 
100 typedef struct _CSR_API_MESSAGE
101 {
102     PORT_MESSAGE Header;
103     union
104     {
105         CSR_API_CONNECTINFO ConnectionInfo; // Uniquely used in CSRSRV for internal signaling (opening a new connection).
106         struct
107         {
108             PCSR_CAPTURE_BUFFER CsrCaptureData;
109             CSR_API_NUMBER ApiNumber;
110             NTSTATUS Status; // ReturnValue;
111             ULONG Reserved;
112             union
113             {
114                 CSR_CLIENT_CONNECT CsrClientConnect;
115 #if (NTDDI_VERSION < NTDDI_WS03)
116                 CSR_SET_PRIORITY_CLASS SetPriorityClass;
117                 CSR_IDENTIFY_ALERTABLE_THREAD IdentifyAlertableThread;
118 #endif
119                 //
120                 // This padding is used to make the CSR_API_MESSAGE structure
121                 // large enough to hold full other API_MESSAGE-type structures
122                 // used by other servers. These latter structures's sizes must
123                 // be checked against the size of CSR_API_MESSAGE by using the
124                 // CHECK_API_MSG_SIZE macro defined below.
125                 //
126                 // This is required because LPC will use this generic structure
127                 // for communicating all the different servers' messages, and
128                 // thus we avoid possible buffer overflows with this method.
129                 // The problems there are, that we have to manually adjust the
130                 // size of the padding to hope that all the servers' messaging
131                 // structures will hold in it, or, that we have to be careful
132                 // to not define too big messaging structures for the servers.
133                 //
134                 // Finally, the overall message structure size must be at most
135                 // equal to the maximum acceptable LPC message size.
136                 //
137                 ULONG_PTR ApiMessageData[39];
138             } Data;
139         };
140     };
141 } CSR_API_MESSAGE, *PCSR_API_MESSAGE;
142 
143 // We must have a size at most equal to the maximum acceptable LPC message size.
144 C_ASSERT(sizeof(CSR_API_MESSAGE) <= LPC_MAX_MESSAGE_LENGTH);
145 
146 // Macro to check that the total size of servers' message structures
147 // are at most equal to the size of the CSR_API_MESSAGE structure.
148 #define CHECK_API_MSG_SIZE(type) C_ASSERT(sizeof(type) <= sizeof(CSR_API_MESSAGE))
149 
150 #endif // _CSRMSG_H
151 
152 /* EOF */
153