ReactOS 0.4.15-dev-7842-g558ab78
smsbapi.c File Reference
#include "smss.h"
#include <debug.h>
Include dependency graph for smsbapi.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI SmpSbCreateSession (IN PVOID Reserved, IN PSMP_SUBSYSTEM OtherSubsystem, IN PRTL_USER_PROCESS_INFORMATION ProcessInformation, IN ULONG DbgSessionId, IN PCLIENT_ID DbgUiClientId)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file smsbapi.c.

Function Documentation

◆ SmpSbCreateSession()

NTSTATUS NTAPI SmpSbCreateSession ( IN PVOID  Reserved,
IN PSMP_SUBSYSTEM  OtherSubsystem,
IN PRTL_USER_PROCESS_INFORMATION  ProcessInformation,
IN ULONG  DbgSessionId,
IN PCLIENT_ID  DbgUiClientId 
)

Definition at line 36 of file smsbapi.c.

41{
43 ULONG SubSystemType = ProcessInformation->ImageInformation.SubSystemType;
44 ULONG MuSessionId;
46 PSMP_SUBSYSTEM KnownSubsys;
47 SB_API_MSG SbApiMsg = {0};
48 PSB_CREATE_SESSION_MSG CreateSessionMsg = &SbApiMsg.u.CreateSession;
49
50 /* Write out the create session message including its initial process */
51 CreateSessionMsg->ProcessInfo = *ProcessInformation;
52 CreateSessionMsg->DbgSessionId = DbgSessionId;
53 if (DbgUiClientId)
54 {
55 CreateSessionMsg->DbgUiClientId = *DbgUiClientId;
56 }
57 else
58 {
59 CreateSessionMsg->DbgUiClientId.UniqueThread = NULL;
60 CreateSessionMsg->DbgUiClientId.UniqueProcess = NULL;
61 }
62
63 /* Find a subsystem responsible for this session */
64 SmpGetProcessMuSessionId(ProcessInformation->ProcessHandle, &MuSessionId);
65 if (!SmpCheckDuplicateMuSessionId(MuSessionId))
66 {
67 NtClose(ProcessInformation->ProcessHandle);
68 NtClose(ProcessInformation->ThreadHandle);
69 DPRINT1("SMSS: CreateSession status=%x\n", STATUS_OBJECT_NAME_NOT_FOUND);
71 }
72
73 /* Find the subsystem suitable for this initial process */
74 KnownSubsys = SmpLocateKnownSubSysByType(MuSessionId, SubSystemType);
75 if (KnownSubsys)
76 {
77 /* Duplicate the process handle into the message */
79 ProcessInformation->ProcessHandle,
80 KnownSubsys->ProcessHandle,
81 &CreateSessionMsg->ProcessInfo.ProcessHandle,
83 0,
84 0);
85 if (NT_SUCCESS(Status))
86 {
87 /* Duplicate the thread handle into the message */
89 ProcessInformation->ThreadHandle,
90 KnownSubsys->ProcessHandle,
91 &CreateSessionMsg->ProcessInfo.ThreadHandle,
93 0,
94 0);
95 if (!NT_SUCCESS(Status))
96 {
97 /* Close everything on failure */
98 NtClose(ProcessInformation->ProcessHandle);
99 NtClose(ProcessInformation->ThreadHandle);
100 SmpDereferenceSubsystem(KnownSubsys);
101 DPRINT1("SmpSbCreateSession: NtDuplicateObject (Thread) Failed %lx\n", Status);
102 return Status;
103 }
104
105 /* Close the original handles as they are no longer needed */
106 NtClose(ProcessInformation->ProcessHandle);
107 NtClose(ProcessInformation->ThreadHandle);
108
109 /* Finally, allocate a new SMSS session ID for this session */
110 SessionId = SmpAllocateSessionId(KnownSubsys, OtherSubsystem);
111 CreateSessionMsg->SessionId = SessionId;
112
113 /* Fill out the LPC message header and send it to the client! */
114 SbApiMsg.ApiNumber = SbpCreateSession;
115 SbApiMsg.h.u2.ZeroInit = 0;
116 SbApiMsg.h.u1.s1.DataLength = sizeof(SB_CREATE_SESSION_MSG) + 8;
117 SbApiMsg.h.u1.s1.TotalLength = sizeof(SbApiMsg);
119 &SbApiMsg.h,
120 &SbApiMsg.h);
121 if (!NT_SUCCESS(Status))
122 {
123 /* Bail out */
124 DPRINT1("SmpSbCreateSession: NtRequestWaitReply Failed %lx\n", Status);
125 }
126 else
127 {
128 /* If the API succeeded, get the result value from the LPC */
129 Status = SbApiMsg.ReturnValue;
130 }
131
132 /* Delete the session on any kind of failure */
134 }
135 else
136 {
137 /* Close the handles on failure */
138 DPRINT1("SmpSbCreateSession: NtDuplicateObject (Process) Failed %lx\n", Status);
139 NtClose(ProcessInformation->ProcessHandle);
140 NtClose(ProcessInformation->ThreadHandle);
141 }
142
143 /* Dereference the subsystem and return the status of the LPC call */
144 SmpDereferenceSubsystem(KnownSubsys);
145 return Status;
146 }
147
148 /* If we don't yet have a subsystem, only native images can be launched */
149 if (SubSystemType != IMAGE_SUBSYSTEM_NATIVE)
150 {
151 /* Fail */
152#if DBG
153 PCSTR SubSysName = NULL;
154 CHAR SubSysTypeName[sizeof("Type 0x")+8];
155
156 if (SubSystemType < RTL_NUMBER_OF(SmpSubSystemNames))
157 SubSysName = SmpSubSystemNames[SubSystemType];
158 if (!SubSysName)
159 {
160 SubSysName = SubSysTypeName;
161 sprintf(SubSysTypeName, "Type 0x%08lx", SubSystemType);
162 }
163 DPRINT1("SMSS: %s SubSystem not found (either not started or destroyed).\n", SubSysName);
164#endif
166 NtClose(ProcessInformation->ProcessHandle);
167 NtClose(ProcessInformation->ThreadHandle);
168 return Status;
169 }
170
171#if 0
172 /*
173 * This code is part of the LPC-based legacy debugging support for native
174 * applications, implemented with the debug client interface (DbgUi) and
175 * debug subsystem (DbgSs). It is now vestigial since WinXP+ and is here
176 * for informational purposes only.
177 */
178 if ((*(ULONGLONG)&CreateSessionMsg.DbgUiClientId) && SmpDbgSsLoaded)
179 {
180 Process = RtlAllocateHeap(SmpHeap, SmBaseTag, sizeof(SMP_PROCESS));
181 if (!Process)
182 {
183 DPRINT1("Unable to initialize debugging for Native App %lx.%lx -- out of memory\n",
184 ProcessInformation->ClientId.UniqueProcess,
185 ProcessInformation->ClientId.UniqueThread);
186 NtClose(ProcessInformation->ProcessHandle);
187 NtClose(ProcessInformation->ThreadHandle);
188 return STATUS_NO_MEMORY;
189 }
190
191 Process->DbgUiClientId = CreateSessionMsg->DbgUiClientId;
192 Process->ClientId = ProcessInformation->ClientId;
194 DPRINT1("Native Debug App %lx.%lx\n",
195 Process->ClientId.UniqueProcess,
196 Process->ClientId.UniqueThread);
197
198 Status = NtSetInformationProcess(ProcessInformation->ProcessHandle,
201 sizeof(SmpDebugPort));
203 }
204#endif
205
206 /* This is a native application being started as the initial command */
207 DPRINT("Subsystem active, starting thread\n");
208 NtClose(ProcessInformation->ProcessHandle);
209 NtResumeThread(ProcessInformation->ThreadHandle, NULL);
210 NtClose(ProcessInformation->ThreadHandle);
211 return STATUS_SUCCESS;
212}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG SessionId
Definition: dllmain.c:28
#define InsertHeadList(ListHead, Entry)
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
Status
Definition: gdiplustypes.h:25
@ ProcessDebugPort
Definition: winternl.h:395
#define ASSERT(a)
Definition: mode.c:44
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
#define PROCESS_ALL_ACCESS
Definition: nt_native.h:1324
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define IMAGE_SUBSYSTEM_NATIVE
Definition: ntimage.h:436
NTSTATUS NTAPI NtRequestWaitReplyPort(IN HANDLE PortHandle, IN PPORT_MESSAGE LpcRequest, IN OUT PPORT_MESSAGE LpcReply)
Definition: send.c:696
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1105
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
NTSTATUS NTAPI NtDuplicateObject(IN HANDLE SourceProcessHandle, IN HANDLE SourceHandle, IN HANDLE TargetProcessHandle OPTIONAL, OUT PHANDLE TargetHandle OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG HandleAttributes, IN ULONG Options)
Definition: obhandle.c:3410
#define STATUS_SUCCESS
Definition: shellext.h:65
PVOID SmpHeap
Definition: sminit.c:25
HANDLE SmpDebugPort
Definition: sminit.c:27
ULONG SmBaseTag
Definition: sminit.c:26
LIST_ENTRY NativeProcessList
Definition: sminit.c:23
struct _SB_CREATE_SESSION_MSG SB_CREATE_SESSION_MSG
@ SbpCreateSession
Definition: smmsg.h:146
NTSTATUS NTAPI SmpGetProcessMuSessionId(IN HANDLE ProcessHandle, OUT PULONG SessionId)
Definition: smsessn.c:168
BOOLEAN NTAPI SmpCheckDuplicateMuSessionId(IN ULONG MuSessionId)
Definition: smsessn.c:37
ULONG NTAPI SmpAllocateSessionId(IN PSMP_SUBSYSTEM Subsystem, IN PSMP_SUBSYSTEM OtherSubsystem)
Definition: smsessn.c:123
VOID NTAPI SmpDeleteSession(IN ULONG SessionId)
Definition: smsessn.c:98
BOOLEAN SmpDbgSsLoaded
Definition: smsessn.c:30
VOID NTAPI SmpDereferenceSubsystem(IN PSMP_SUBSYSTEM SubSystem)
Definition: smsubsys.c:47
PSMP_SUBSYSTEM NTAPI SmpLocateKnownSubSysByType(IN ULONG MuSessionId, IN ULONG ImageType)
Definition: smsubsys.c:102
#define DPRINT
Definition: sndvol32.h:71
HANDLE UniqueThread
Definition: compat.h:826
HANDLE UniqueProcess
Definition: compat.h:825
NTSTATUS ReturnValue
Definition: smmsg.h:239
SB_API_NUMBER ApiNumber
Definition: smmsg.h:238
union _SB_API_MSG::@3525::@3527::@3529 u
SB_CREATE_SESSION_MSG CreateSession
Definition: smmsg.h:242
PORT_MESSAGE h
Definition: smmsg.h:232
CLIENT_ID DbgUiClientId
Definition: smmsg.h:164
RTL_USER_PROCESS_INFORMATION ProcessInfo
Definition: smmsg.h:161
HANDLE ProcessHandle
Definition: smss.h:67
HANDLE SbApiPort
Definition: smss.h:70
const char * PCSTR
Definition: typedefs.h:52
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
char CHAR
Definition: xmlstorage.h:175

Referenced by SmpExecPgm().