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