WINAPI
BaseProcessStartup(PPROCESS_START_ROUTINE lpStartAddress)
{
- UINT uExitCode = 0;
-
DPRINT("BaseProcessStartup(..) - setting up exception frame.\n");
_SEH2_TRY
sizeof(PPROCESS_START_ROUTINE));
/* Call the Start Routine */
- uExitCode = (lpStartAddress)();
+ ExitThread(lpStartAddress());
}
_SEH2_EXCEPT(BaseExceptionFilter(_SEH2_GetExceptionInformation()))
{
- /* Get the SEH Error */
- uExitCode = _SEH2_GetExceptionCode();
+ /* Get the Exit code from the SEH Handler */
+ if (!BaseRunningInServerProcess)
+ {
+ /* Kill the whole process, usually */
+ ExitProcess(_SEH2_GetExceptionCode());
+ }
+ else
+ {
+ /* If running inside CSRSS, kill just this thread */
+ ExitThread(_SEH2_GetExceptionCode());
+ }
}
_SEH2_END;
-
- /* Exit the Process with our error */
- ExitProcess(uExitCode);
-}
-
-/*
- * Tells CSR that a new process was created
- */
-NTSTATUS
-WINAPI
-BasepNotifyCsrOfCreation(ULONG dwCreationFlags,
- IN HANDLE ProcessId,
- IN BOOL InheritHandles)
-{
- ULONG Request = CREATE_PROCESS;
- CSR_API_MESSAGE CsrRequest;
- NTSTATUS Status;
-
- DPRINT("BasepNotifyCsrOfCreation: Process: %lx, Flags %lx\n",
- ProcessId, dwCreationFlags);
-
- /* Fill out the request */
- CsrRequest.Data.CreateProcessRequest.NewProcessId = ProcessId;
- CsrRequest.Data.CreateProcessRequest.Flags = dwCreationFlags;
- CsrRequest.Data.CreateProcessRequest.bInheritHandles = InheritHandles;
-
- /* Call CSR */
- Status = CsrClientCallServer(&CsrRequest,
- NULL,
- MAKE_CSR_API(Request, CSR_NATIVE),
- sizeof(CSR_API_MESSAGE));
- if (!NT_SUCCESS(Status) || !NT_SUCCESS(CsrRequest.Status))
- {
- DPRINT1("Failed to tell csrss about new process\n");
- return CsrRequest.Status;
- }
-
- /* Return Success */
- return STATUS_SUCCESS;
}
NTSTATUS
sizeof(CSR_API_MESSAGE));
if (!NT_SUCCESS(Status) || !NT_SUCCESS(CsrRequest.Status))
{
- DPRINT1("Failed to tell csrss about new thread\n");
+ DPRINT1("Failed to tell csrss about new thread: %lx %lx\n", Status, CsrRequest.Status);
return CsrRequest.Status;
}
BasepCreateFirstThread(HANDLE ProcessHandle,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
PSECTION_IMAGE_INFORMATION SectionImageInfo,
- PCLIENT_ID ClientId)
+ PCLIENT_ID ClientId,
+ BOOLEAN InheritHandles,
+ DWORD dwCreationFlags)
{
OBJECT_ATTRIBUTES LocalObjectAttributes;
POBJECT_ATTRIBUTES ObjectAttributes;
INITIAL_TEB InitialTeb;
NTSTATUS Status;
HANDLE hThread;
-
+ ULONG Request = CREATE_PROCESS;
+ CSR_API_MESSAGE CsrRequest;
DPRINT("BasepCreateFirstThread. hProcess: %lx\n", ProcessHandle);
/* Create the Thread's Stack */
return NULL;
}
- Status = BasepNotifyCsrOfThread(hThread, ClientId);
- if (!NT_SUCCESS(Status))
+ /* Fill out the request to notify CSRSS */
+ CsrRequest.Data.CreateProcessRequest.ClientId = *ClientId;
+ CsrRequest.Data.CreateProcessRequest.ProcessHandle = ProcessHandle;
+ CsrRequest.Data.CreateProcessRequest.ThreadHandle = hThread;
+ CsrRequest.Data.CreateProcessRequest.CreationFlags = dwCreationFlags;
+ CsrRequest.Data.CreateProcessRequest.bInheritHandles = InheritHandles;
+
+ /* Call CSR */
+ Status = CsrClientCallServer(&CsrRequest,
+ NULL,
+ MAKE_CSR_API(Request, CSR_NATIVE),
+ sizeof(CSR_API_MESSAGE));
+ if (!NT_SUCCESS(Status) || !NT_SUCCESS(CsrRequest.Status))
{
- ASSERT(FALSE);
+ DPRINT1("Failed to tell csrss about new process: %lx %lx\n", Status, CsrRequest.Status);
+ return NULL;
}
/* Success */
if ((Size) && (Size <= (MAX_PATH + 4)))
{
/* Get the DLL Path */
- DllPathString = BaseComputeProcessDllPath((LPWSTR)ApplicationPathName,
- lpEnvironment);
+ DllPathString = BaseComputeProcessDllPath(FullPath, lpEnvironment);
if (!DllPathString)
{
/* Fail */
/* Initialize Strings */
RtlInitUnicodeString(&DllPath, DllPathString);
- RtlInitUnicodeString(&ImageName, ApplicationPathName);
+ RtlInitUnicodeString(&ImageName, FullPath);
}
else
{
- /* Get the DLL Path */
- DllPathString = BaseComputeProcessDllPath(FullPath, lpEnvironment);
+ /* Couldn't get the path name. Just take the original path */
+ DllPathString = BaseComputeProcessDllPath((LPWSTR)ApplicationPathName,
+ lpEnvironment);
if (!DllPathString)
{
/* Fail */
/* Initialize Strings */
RtlInitUnicodeString(&DllPath, DllPathString);
- RtlInitUnicodeString(&ImageName, FullPath);
+ RtlInitUnicodeString(&ImageName, ApplicationPathName);
}
/* Initialize Strings */
/* Allocate and Initialize new Environment Block */
Size = EnviroSize;
ProcessParameters->Environment = NULL;
- Status = ZwAllocateVirtualMemory(ProcessHandle,
+ Status = NtAllocateVirtualMemory(ProcessHandle,
(PVOID*)&ProcessParameters->Environment,
0,
&Size,
if (!NT_SUCCESS(Status)) goto FailPath;
/* Write the Environment Block */
- Status = ZwWriteVirtualMemory(ProcessHandle,
+ Status = NtWriteVirtualMemory(ProcessHandle,
ProcessParameters->Environment,
lpEnvironment,
EnviroSize,
/* Someone beat us to it, use their data instead */
StartupInfo = BaseAnsiStartupInfo;
Status = STATUS_SUCCESS;
-
+
/* We're going to free our own stuff, but not raise */
RtlFreeAnsiString(&TitleString);
}
LdrShutdownProcess();
/* Notify Base Server of process termination */
+ CsrRequest.Data.TerminateProcessRequest.uExitCode = uExitCode;
CsrClientCallServer(&CsrRequest,
NULL,
MAKE_CSR_API(TERMINATE_PROCESS, CSR_NATIVE),
/* FIXME: Allow CREATE_SEPARATE only for WOW Apps, once we have that. */
/* Get some information about the executable */
- Status = ZwQuerySection(hSection,
+ Status = NtQuerySection(hSection,
SectionImageInformation,
&SectionImageInfo,
sizeof(SectionImageInfo),
/* Check if only this process will be debugged */
if (dwCreationFlags & DEBUG_ONLY_THIS_PROCESS)
{
- /* FIXME: Set process flag */
+ /* Set process flag */
+ hDebug = (HANDLE)((ULONG_PTR)hDebug | 0x1);
}
}
&RemoteParameters->StandardError);
}
- /* Notify CSRSS */
- Status = BasepNotifyCsrOfCreation(dwCreationFlags,
- (HANDLE)ProcessBasicInfo.UniqueProcessId,
- bInheritHandles);
-
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("CSR Notification Failed\n");
- BaseSetLastNTError(Status);
- goto Cleanup;
- }
-
/* Create the first thread */
DPRINT("Creating thread for process (EntryPoint = 0x%p)\n",
SectionImageInfo.TransferAddress);
hThread = BasepCreateFirstThread(hProcess,
lpThreadAttributes,
&SectionImageInfo,
- &ClientId);
+ &ClientId,
+ bInheritHandles,
+ dwCreationFlags);
if (hThread == NULL)
{