[CSRSRV]
[reactos.git] / include / reactos / subsys / csr / csrmsg.h
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@relsoft.net)
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 CsrpIdentifyAlertable,
29 CsrpSetPriorityClass,
30
31 CsrpMaxApiNumber
32 } CSRSRV_API_NUMBER, *PCSRSRV_API_NUMBER;
33
34
35 /*
36 typedef union _CSR_API_NUMBER
37 {
38 WORD Index;
39 WORD Subsystem;
40 } CSR_API_NUMBER, *PCSR_API_NUMBER;
41 */
42 typedef ULONG CSR_API_NUMBER;
43
44 #define CSR_CREATE_API_NUMBER(ServerId, ApiId) \
45 (CSR_API_NUMBER)(((ServerId) << 16) | (ApiId))
46
47 #define CSR_API_NUMBER_TO_SERVER_ID(ApiNumber) \
48 (ULONG)((ULONG)(ApiNumber) >> 16)
49
50 #define CSR_API_NUMBER_TO_API_ID(ApiNumber) \
51 (ULONG)((ULONG)(ApiNumber) & 0xFFFF)
52
53
54 typedef struct _CSR_CONNECTION_INFO
55 {
56 ULONG Version;
57 ULONG Unknown;
58 HANDLE ObjectDirectory;
59 PVOID SharedSectionBase;
60 PVOID SharedSectionHeap;
61 PVOID SharedSectionData;
62 ULONG DebugFlags;
63 ULONG Unknown2[3];
64 HANDLE ProcessId;
65 } CSR_CONNECTION_INFO, *PCSR_CONNECTION_INFO;
66
67 // We must have a size at most equal to the maximum acceptable LPC data size.
68 C_ASSERT(sizeof(CSR_CONNECTION_INFO) <= LPC_MAX_DATA_LENGTH);
69
70
71 typedef struct _CSR_IDENTIFY_ALTERTABLE_THREAD
72 {
73 CLIENT_ID Cid;
74 } CSR_IDENTIFY_ALTERTABLE_THREAD, *PCSR_IDENTIFY_ALTERTABLE_THREAD;
75
76 typedef struct _CSR_SET_PRIORITY_CLASS
77 {
78 HANDLE hProcess;
79 ULONG PriorityClass;
80 } CSR_SET_PRIORITY_CLASS, *PCSR_SET_PRIORITY_CLASS;
81
82 typedef struct
83 {
84 HANDLE UniqueThread;
85 CLIENT_ID Cid;
86 } CSRSS_IDENTIFY_ALERTABLE_THREAD, *PCSRSS_IDENTIFY_ALERTABLE_THREAD;
87
88 typedef struct _CSR_CLIENT_CONNECT
89 {
90 ULONG ServerId;
91 PVOID ConnectionInfo;
92 ULONG ConnectionInfoSize;
93 } CSR_CLIENT_CONNECT, *PCSR_CLIENT_CONNECT;
94
95 typedef struct _CSR_CAPTURE_BUFFER
96 {
97 ULONG Size;
98 struct _CSR_CAPTURE_BUFFER *PreviousCaptureBuffer;
99 ULONG PointerCount;
100 PVOID BufferEnd;
101 ULONG_PTR PointerOffsetsArray[ANYSIZE_ARRAY];
102 } CSR_CAPTURE_BUFFER, *PCSR_CAPTURE_BUFFER;
103
104
105 typedef struct _CSR_API_MESSAGE
106 {
107 PORT_MESSAGE Header;
108 union
109 {
110 CSR_CONNECTION_INFO ConnectionInfo; // Uniquely used in CSRSRV for internal signaling (opening a new connection).
111 struct
112 {
113 PCSR_CAPTURE_BUFFER CsrCaptureData;
114 CSR_API_NUMBER ApiNumber;
115 NTSTATUS Status; // ReturnValue;
116 ULONG Reserved;
117 union
118 {
119 CSR_CLIENT_CONNECT CsrClientConnect;
120 CSR_SET_PRIORITY_CLASS SetPriorityClass;
121 CSR_IDENTIFY_ALTERTABLE_THREAD IdentifyAlertableThread;
122
123 //
124 // This padding is used to make the CSR_API_MESSAGE structure
125 // large enough to hold full other API_MESSAGE-type structures
126 // used by other servers. These latter structures's sizes must
127 // be checked against the size of CSR_API_MESSAGE by using the
128 // CHECK_API_MSG_SIZE macro defined below.
129 //
130 // This is required because LPC will use this generic structure
131 // for communicating all the different servers' messages, and
132 // thus we avoid possible buffer overflows with this method.
133 // The problems there are, that we have to manually adjust the
134 // size of the padding to hope that all the servers' messaging
135 // structures will hold in it, or, that we have to be careful
136 // to not define too big messaging structures for the servers.
137 //
138 // Finally, the overall message structure size must be at most
139 // equal to the maximum acceptable LPC message size.
140 //
141 ULONG_PTR Padding[35];
142 } Data;
143 };
144 };
145 } CSR_API_MESSAGE, *PCSR_API_MESSAGE;
146
147 // We must have a size at most equal to the maximum acceptable LPC message size.
148 C_ASSERT(sizeof(CSR_API_MESSAGE) <= LPC_MAX_MESSAGE_LENGTH);
149
150 // Macro to check that the total size of servers' message structures
151 // are at most equal to the size of the CSR_API_MESSAGE structure.
152 #define CHECK_API_MSG_SIZE(type) C_ASSERT(sizeof(type) <= sizeof(CSR_API_MESSAGE))
153
154 #endif // _CSRMSG_H
155
156 /* EOF */