Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygensmsbapi.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Windows-Compatible Session Manager 00003 * LICENSE: BSD 2-Clause License 00004 * FILE: base/system/smss/smss.c 00005 * PURPOSE: Main SMSS Code 00006 * PROGRAMMERS: Alex Ionescu 00007 */ 00008 00009 /* INCLUDES *******************************************************************/ 00010 00011 #include "smss.h" 00012 #define NDEBUG 00013 #include "debug.h" 00014 00015 /* GLOBALS ********************************************************************/ 00016 00017 PCHAR SmpSubSystemNames[] = 00018 { 00019 "Unknown", 00020 "Native", 00021 "Windows", 00022 "Posix", 00023 "OS/2" 00024 }; 00025 00026 /* FUNCTIONS ******************************************************************/ 00027 00028 NTSTATUS 00029 NTAPI 00030 SmpSbCreateSession(IN PVOID Reserved, 00031 IN PSMP_SUBSYSTEM OtherSubsystem, 00032 IN PRTL_USER_PROCESS_INFORMATION ProcessInformation, 00033 IN ULONG MuSessionId, 00034 IN PCLIENT_ID DbgClientId) 00035 { 00036 NTSTATUS Status; 00037 PSMP_SUBSYSTEM KnownSubsys; 00038 SB_API_MSG SbApiMsg; 00039 ULONG SessionId; 00040 PSB_CREATE_SESSION_MSG CreateSessionMsg; 00041 00042 /* Write out the create session message including its initial process */ 00043 CreateSessionMsg = &SbApiMsg.CreateSession; 00044 CreateSessionMsg->ProcessInfo = *ProcessInformation; 00045 CreateSessionMsg->MuSessionId = MuSessionId; 00046 if (DbgClientId) 00047 { 00048 CreateSessionMsg->ClientId = *DbgClientId; 00049 } 00050 else 00051 { 00052 CreateSessionMsg->ClientId.UniqueThread = NULL; 00053 CreateSessionMsg->ClientId.UniqueProcess = NULL; 00054 } 00055 00056 /* Find a subsystem responsible for this session */ 00057 SmpGetProcessMuSessionId(ProcessInformation->ProcessHandle, &MuSessionId); 00058 if (!SmpCheckDuplicateMuSessionId(MuSessionId)) 00059 { 00060 NtClose(ProcessInformation->ProcessHandle); 00061 NtClose(ProcessInformation->ThreadHandle); 00062 DPRINT1("SMSS: CreateSession status=%x\n", STATUS_OBJECT_NAME_NOT_FOUND); 00063 return STATUS_OBJECT_NAME_NOT_FOUND; 00064 } 00065 00066 /* Find the subsystem we have for this initial process */ 00067 KnownSubsys = SmpLocateKnownSubSysByType(MuSessionId, 00068 ProcessInformation-> 00069 ImageInformation.SubSystemType); 00070 if (KnownSubsys) 00071 { 00072 /* Duplicate the process handle into the message */ 00073 Status = NtDuplicateObject(NtCurrentProcess(), 00074 ProcessInformation->ProcessHandle, 00075 KnownSubsys->ProcessHandle, 00076 &CreateSessionMsg->ProcessInfo.ProcessHandle, 00077 PROCESS_ALL_ACCESS, 00078 0, 00079 0); 00080 if (NT_SUCCESS(Status)) 00081 { 00082 /* Duplicate the thread handle into the message */ 00083 Status = NtDuplicateObject(NtCurrentProcess(), 00084 ProcessInformation->ThreadHandle, 00085 KnownSubsys->ProcessHandle, 00086 &CreateSessionMsg->ProcessInfo.ThreadHandle, 00087 THREAD_ALL_ACCESS, 00088 0, 00089 0); 00090 if (!NT_SUCCESS(Status)) 00091 { 00092 /* Close everything on failure */ 00093 NtClose(ProcessInformation->ProcessHandle); 00094 NtClose(ProcessInformation->ThreadHandle); 00095 SmpDereferenceSubsystem(KnownSubsys); 00096 DbgPrint("SmpSbCreateSession: NtDuplicateObject (Thread) Failed %lx\n", Status); 00097 return Status; 00098 } 00099 00100 /* Close the original handles as they are no longer needed */ 00101 NtClose(ProcessInformation->ProcessHandle); 00102 NtClose(ProcessInformation->ThreadHandle); 00103 00104 /* Finally, allocate a new SMSS session ID for this session */ 00105 SessionId = SmpAllocateSessionId(KnownSubsys, OtherSubsystem); 00106 CreateSessionMsg->SessionId = SessionId; 00107 00108 /* Fill out the LPC message header and send it to the client! */ 00109 SbApiMsg.ApiNumber = SbpCreateSession; 00110 SbApiMsg.h.u2.ZeroInit = 0; 00111 SbApiMsg.h.u1.s1.DataLength = sizeof(SB_CREATE_SESSION_MSG) + 8; 00112 SbApiMsg.h.u1.s1.TotalLength = sizeof(SbApiMsg); 00113 Status = NtRequestWaitReplyPort(KnownSubsys->SbApiPort, 00114 &SbApiMsg.h, 00115 &SbApiMsg.h); 00116 if (!NT_SUCCESS(Status)) 00117 { 00118 /* Bail out */ 00119 DPRINT1("SmpSbCreateSession: NtRequestWaitReply Failed %lx\n", Status); 00120 } 00121 else 00122 { 00123 /* If the API succeeded, get the result value from the LPC */ 00124 Status = SbApiMsg.ReturnValue; 00125 } 00126 00127 /* Delete the session on any kind of failure */ 00128 if (!NT_SUCCESS(Status)) SmpDeleteSession(SessionId); 00129 } 00130 else 00131 { 00132 /* Close the handles on failure */ 00133 DPRINT1("SmpSbCreateSession: NtDuplicateObject (Process) Failed %lx\n", Status); 00134 NtClose(ProcessInformation->ProcessHandle); 00135 NtClose(ProcessInformation->ThreadHandle); 00136 } 00137 00138 /* Dereference the subsystem and return the status of the LPC call */ 00139 SmpDereferenceSubsystem(KnownSubsys); 00140 return Status; 00141 } 00142 00143 /* If we don't yet have a subsystem, only native images can be launched */ 00144 if (ProcessInformation->ImageInformation.SubSystemType != IMAGE_SUBSYSTEM_NATIVE) 00145 { 00146 /* Fail */ 00147 DPRINT1("SMSS: %s SubSystem has not been started.\n", 00148 SmpSubSystemNames[ProcessInformation->ImageInformation.SubSystemType]); 00149 Status = STATUS_UNSUCCESSFUL; 00150 NtClose(ProcessInformation->ProcessHandle); 00151 NtClose(ProcessInformation->ThreadHandle); 00152 return Status; 00153 } 00154 00155 #if 0 00156 /* This code handles debug applications, but it seems vestigial... */ 00157 if ((*(ULONGLONG)&CreateSessionMsg.ClientId) && (SmpDbgSsLoaded)) 00158 { 00159 Process = RtlAllocateHeap(SmpHeap, SmBaseTag, sizeof(SMP_PROCESS)); 00160 if (!Process) 00161 { 00162 DPRINT1("Unable to initialize debugging for Native App %lx.%lx -- out of memory\n", 00163 ProcessInformation->ClientId.UniqueProcess, 00164 ProcessInformation->ClientId.UniqueThread); 00165 NtClose(ProcessInformation->ProcessHandle); 00166 NtClose(ProcessInformation->ThreadHandle); 00167 return STATUS_NO_MEMORY; 00168 } 00169 00170 Process->DbgClientId = CreateSessionMsg->ClientId; 00171 Process->ClientId = ProcessInformation->ClientId; 00172 InsertHeadList(&NativeProcessList, &Process->Entry); 00173 DPRINT1("Native Debug App %lx.%lx\n", Process->ClientId.UniqueProcess, Process->ClientId.UniqueThread); 00174 00175 Status = NtSetInformationProcess(ProcessInformation->ProcessHandle, 7, &SmpDebugPort, 4); 00176 ASSERT(NT_SUCCESS(Status)); 00177 } 00178 #endif 00179 00180 /* This is a native application being started as the initial command */ 00181 DPRINT1("Subsystem active, starting thread\n"); 00182 NtClose(ProcessInformation->ProcessHandle); 00183 NtResumeThread(ProcessInformation->ThreadHandle, NULL); 00184 NtClose(ProcessInformation->ThreadHandle); 00185 return STATUS_SUCCESS; 00186 } Generated on Sat May 26 2012 04:17:44 for ReactOS by
1.7.6.1
|