[CSRSRV]
[reactos.git] / include / reactos / subsys / sm / smmsg.h
1 /*
2 * PROJECT: ReactOS Windows-Compatible Session Manager
3 * LICENSE: BSD 2-Clause License
4 * FILE: include/reactos/subsystems/sm/smmsg.h
5 * PURPOSE: SMSS (SB and SM) Message Format
6 * PROGRAMMERS: Alex Ionescu
7 */
8 #pragma once
9 #ifndef _SM_MSG_
10 #define _SM_MSG_
11
12 //
13 // There are the APIs that a Client (such as CSRSS) can send to the SMSS Server.
14 //
15 // These are called "SM" APIs.
16 //
17 // The exact names are not known, but we are basing them on the SmpApiName array
18 // in the checked build of SMSS, which is probably a close approximation. We add
19 // "p" to use the similar nomenclature seen/leaked out in the Base CSRSS APIs.
20 //
21 // The enumeration finishes with an enumeratee holding the maximum API number.
22 // Its name is based on BasepMaxApiNumber, UserpMaxApiNumber...
23 //
24 //
25 typedef enum _SMSRV_API_NUMBER
26 {
27 SmpCreateForeignSessionApi,
28 SmpSessionCompleteApi,
29 SmpTerminateForeignSessionApi,
30 SmpExecPgmApi,
31 SmpLoadDeferedSubsystemApi,
32 SmpStartCsrApi,
33 SmpStopCsrApi,
34
35 SmpMaxApiNumber
36 } SMSRV_API_NUMBER;
37
38 //
39 // These are the structures making up the SM_API_MSG packet structure defined
40 // below. Each one corresponds to an equivalent API from the list above.
41 //
42 typedef struct _SM_CREATE_FOREIGN_SESSION_MSG
43 {
44 ULONG NotImplemented;
45 } SM_CREATE_FOREIGN_SESSION_MSG, *PSM_CREATE_FOREIGN_SESSION_MSG;
46
47 typedef struct _SM_SESSION_COMPLETE_MSG
48 {
49 ULONG SessionId;
50 NTSTATUS SessionStatus;
51 } SM_SESSION_COMPLETE_MSG, *PSM_SESSION_COMPLETE_MSG;
52
53 typedef struct _SM_TERMINATE_FOREIGN_SESSION_MSG
54 {
55 ULONG NotImplemented;
56 } SM_TERMINATE_FOREIGN_SESSION_MSG, *PSM_TERMINATE_FOREIGN_SESSION_MSG;
57
58 typedef struct _SM_EXEC_PGM_MSG
59 {
60 RTL_USER_PROCESS_INFORMATION ProcessInformation;
61 BOOLEAN DebugFlag;
62 } SM_EXEC_PGM_MSG, *PSM_EXEC_PGM_MSG;
63 #ifndef _WIN64
64 C_ASSERT(sizeof(SM_EXEC_PGM_MSG) == 0x48);
65 #endif
66
67 typedef struct _SM_LOAD_DEFERED_SUBSYSTEM_MSG
68 {
69 ULONG Length;
70 WCHAR Buffer[32];
71 } SM_LOAD_DEFERED_SUBSYSTEM_MSG, *PSM_LOAD_DEFERED_SUBSYSTEM_MSG;
72
73 typedef struct _SM_START_CSR_MSG
74 {
75 ULONG MuSessionId;
76 ULONG Length;
77 WCHAR Buffer[128];
78 HANDLE WindowsSubSysProcessId;
79 HANDLE SmpInitialCommandProcessId;
80 } SM_START_CSR_MSG, *PSM_START_CSR_MSG;
81
82 typedef struct _SM_STOP_CSR_MSG
83 {
84 ULONG MuSessionId;
85 } SM_STOP_CSR_MSG, *PSM_STOP_CSR_MSG;
86
87 //
88 // This is the actual packet structure sent over LCP to the \SmApiPort
89 //
90 typedef struct _SM_API_MSG
91 {
92 PORT_MESSAGE h;
93 SMSRV_API_NUMBER ApiNumber;
94 NTSTATUS ReturnValue;
95 union
96 {
97 SM_CREATE_FOREIGN_SESSION_MSG CreateForeignSession;
98 SM_SESSION_COMPLETE_MSG SessionComplete;
99 SM_TERMINATE_FOREIGN_SESSION_MSG TerminateForeignComplete;
100 SM_EXEC_PGM_MSG ExecPgm;
101 SM_LOAD_DEFERED_SUBSYSTEM_MSG LoadDefered;
102 SM_START_CSR_MSG StartCsr;
103 SM_STOP_CSR_MSG StopCsr;
104 } u;
105 } SM_API_MSG, *PSM_API_MSG;
106
107 //
108 // This is the size that Server 2003 SP1 SMSS expects, so make sure we conform.
109 //
110 #ifndef _WIN64
111 C_ASSERT(sizeof(SM_API_MSG) == 0x130);
112 #endif
113
114 //
115 // There are the APIs that the SMSS Server can send to a client (such as CSRSS).
116 //
117 // These are called "SB" APIs.
118 //
119 // The exact names are unknown but we are basing them on the CsrServerSbApiName
120 // array in the checked build of CSRSRV which is probably a close approximation.
121 // We add "p" to use the similar nomenclature seen/leaked out in the Base CSRSS
122 // APIs.
123 //
124 // The enumeration finishes with an enumeratee holding the maximum API number.
125 // Its name is based on BasepMaxApiNumber, UserpMaxApiNumber...
126 //
127 //
128 typedef enum _SB_API_NUMBER
129 {
130 SbpCreateSession,
131 SbpTerminateSession,
132 SbpForeignSessionComplete,
133 SbpCreateProcess,
134
135 SbpMaxApiNumber
136 } SB_API_NUMBER;
137
138 //
139 // These are the structures making up the SB_API_MSG packet structure defined
140 // below. Each one corresponds to an equivalent API from the list above.
141 //
142 typedef struct _SB_CREATE_SESSION_MSG
143 {
144 ULONG SessionId;
145 RTL_USER_PROCESS_INFORMATION ProcessInfo;
146 ULONG Unknown;
147 ULONG MuSessionId;
148 CLIENT_ID ClientId;
149 } SB_CREATE_SESSION_MSG, *PSB_CREATE_SESSION_MSG;
150
151 typedef struct _SB_TERMINATE_SESSION_MSG
152 {
153 ULONG SessionId;
154 } SB_TERMINATE_SESSION_MSG, *PSB_TERMINATE_SESSION_MSG;
155
156 typedef struct _SB_FOREIGN_SESSION_COMPLETE_MSG
157 {
158 ULONG SessionId;
159 } SB_FOREIGN_SESSION_COMPLETE_MSG, *PSB_FOREIGN_SESSION_COMPLETE_MSG;
160
161 #define SB_PROCESS_FLAGS_DEBUG 0x1
162 #define SB_PROCESS_FLAGS_WAIT_ON_THREAD 0x2
163 #define SB_PROCESS_FLAGS_RESERVE_1MB 0x8
164 #define SB_PROCESS_FLAGS_SKIP_CHECKS 0x20
165 typedef struct _SB_CREATE_PROCESS_MSG
166 {
167 union
168 {
169 struct
170 {
171 PUNICODE_STRING ImageName;
172 PUNICODE_STRING CurrentDirectory;
173 PUNICODE_STRING CommandLine;
174 PUNICODE_STRING DllPath;
175 ULONG Flags;
176 ULONG DebugFlags;
177 } In;
178 struct
179 {
180 HANDLE ProcessHandle;
181 HANDLE ThreadHandle;
182 ULONG SubsystemType;
183 CLIENT_ID ClientId;
184 } Out;
185 };
186 } SB_CREATE_PROCESS_MSG, *PSB_CREATE_PROCESS_MSG;
187
188 //
189 // When the server connects to a client, this structure is exchanged
190 //
191 typedef struct _SB_CONNECTION_INFO
192 {
193 ULONG SubsystemType;
194 WCHAR SbApiPortName[120];
195 } SB_CONNECTION_INFO, *PSB_CONNECTION_INFO;
196
197 //
198 // This is the actual packet structure sent over LCP to the \SbApiPort
199 //
200 typedef struct _SB_API_MSG
201 {
202 PORT_MESSAGE h;
203 union
204 {
205 SB_CONNECTION_INFO ConnectionInfo;
206 struct
207 {
208 SB_API_NUMBER ApiNumber;
209 NTSTATUS ReturnValue;
210 union
211 {
212 SB_CREATE_SESSION_MSG CreateSession;
213 SB_TERMINATE_SESSION_MSG TerminateSession;
214 SB_FOREIGN_SESSION_COMPLETE_MSG ForeignSessionComplete;
215 SB_CREATE_PROCESS_MSG CreateProcess;
216 };
217 };
218 };
219 } SB_API_MSG, *PSB_API_MSG;
220
221 //
222 // This is the size that Server 2003 SP1 SMSS expects, so make sure we conform.
223 //
224 #ifndef _WIN64
225 C_ASSERT(sizeof(SB_CONNECTION_INFO) == 0xF4);
226 C_ASSERT(sizeof(SB_API_MSG) == 0x110);
227 #endif
228
229 //
230 // SB Message Handler
231 //
232 typedef
233 BOOLEAN
234 (NTAPI *PSB_API_ROUTINE)(
235 IN PSB_API_MSG SbApiMsg
236 );
237
238 //
239 // The actual server functions that a client linking with smlib can call
240 //
241 NTSTATUS
242 NTAPI
243 SmConnectToSm(
244 IN PUNICODE_STRING SbApiPortName,
245 IN HANDLE SbApiPort,
246 IN ULONG ImageType,
247 IN HANDLE SmApiPort
248 );
249
250 NTSTATUS
251 NTAPI
252 SmExecPgm(
253 IN HANDLE SmApiPort,
254 IN PRTL_USER_PROCESS_INFORMATION ProcessInformation,
255 IN BOOLEAN DebugFlag
256 );
257
258 NTSTATUS
259 NTAPI
260 SmSessionComplete(
261 IN HANDLE SmApiPort,
262 IN ULONG SessionId,
263 IN NTSTATUS SessionStatus
264 );
265
266 #endif