/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
- * FILE: lib/kernel32/proc/proc.c
+ * FILE: dll/win32/kernel32/client/proc.c
* PURPOSE: Process functions
* PROGRAMMERS: Ariadne (ariadne@xs4all.nl)
* UPDATE HISTORY:
BasepNotifyCsrOfThread(IN HANDLE ThreadHandle,
IN PCLIENT_ID ClientId)
{
- NTSTATUS Status;
BASE_API_MESSAGE ApiMessage;
PBASE_CREATE_THREAD CreateThreadRequest = &ApiMessage.Data.CreateThreadRequest;
CreateThreadRequest->ThreadHandle = ThreadHandle;
/* Call CSR */
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- NULL,
- CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepCreateThread),
- sizeof(BASE_CREATE_THREAD));
- if (!NT_SUCCESS(Status))
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ NULL,
+ CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepCreateThread),
+ sizeof(*CreateThreadRequest));
+ if (!NT_SUCCESS(ApiMessage.Status))
{
- DPRINT1("Failed to tell CSRSS about new thread: %lx\n", Status);
- return Status;
+ DPRINT1("Failed to tell CSRSS about new thread: %lx\n", ApiMessage.Status);
+ return ApiMessage.Status;
}
/* Return Success */
/* Query information on the process from the kernel */
Status = NtQueryInformationProcess(hProcess,
ProcessBasicInformation,
- (PVOID)&ProcessInfo,
- sizeof(PROCESS_BASIC_INFORMATION),
+ &ProcessInfo,
+ sizeof(ProcessInfo),
NULL);
if (!NT_SUCCESS(Status))
{
GetProcessShutdownParameters(OUT LPDWORD lpdwLevel,
OUT LPDWORD lpdwFlags)
{
- NTSTATUS Status;
BASE_API_MESSAGE ApiMessage;
PBASE_GETSET_PROCESS_SHUTDOWN_PARAMS ShutdownParametersRequest = &ApiMessage.Data.ShutdownParametersRequest;
/* Ask CSRSS for shutdown information */
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- NULL,
- CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepGetProcessShutdownParam),
- sizeof(BASE_GETSET_PROCESS_SHUTDOWN_PARAMS));
- if (!NT_SUCCESS(Status))
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ NULL,
+ CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepGetProcessShutdownParam),
+ sizeof(*ShutdownParametersRequest));
+ if (!NT_SUCCESS(ApiMessage.Status))
{
/* Return the failure from CSRSS */
- BaseSetLastNTError(Status);
+ BaseSetLastNTError(ApiMessage.Status);
return FALSE;
}
SetProcessShutdownParameters(IN DWORD dwLevel,
IN DWORD dwFlags)
{
- NTSTATUS Status;
BASE_API_MESSAGE ApiMessage;
PBASE_GETSET_PROCESS_SHUTDOWN_PARAMS ShutdownParametersRequest = &ApiMessage.Data.ShutdownParametersRequest;
/* Write the data into the CSRSS request and send it */
ShutdownParametersRequest->ShutdownLevel = dwLevel;
ShutdownParametersRequest->ShutdownFlags = dwFlags;
- Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
- NULL,
- CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepSetProcessShutdownParam),
- sizeof(BASE_GETSET_PROCESS_SHUTDOWN_PARAMS));
- if (!NT_SUCCESS(Status))
+ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+ NULL,
+ CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepSetProcessShutdownParam),
+ sizeof(*ShutdownParametersRequest));
+ if (!NT_SUCCESS(ApiMessage.Status))
{
/* Return the failure from CSRSS */
- BaseSetLastNTError(Status);
+ BaseSetLastNTError(ApiMessage.Status);
return FALSE;
}
Status = NtQueryInformationProcess(hProcess,
ProcessQuotaLimits,
&QuotaLimits,
- sizeof(QUOTA_LIMITS_EX),
+ sizeof(QuotaLimits),
NULL);
if (!NT_SUCCESS(Status))
{
Status = NtQueryInformationProcess(hProcess,
ProcessBasicInformation,
&ProcessBasic,
- sizeof(PROCESS_BASIC_INFORMATION),
+ sizeof(ProcessBasic),
NULL);
if (!NT_SUCCESS(Status))
{
Status = NtQueryInformationProcess(Process,
ProcessBasicInformation,
&ProcessBasic,
- sizeof(PROCESS_BASIC_INFORMATION),
+ sizeof(ProcessBasic),
NULL);
if (!NT_SUCCESS(Status))
{
StartupInfo->lpTitle = TitleString.Buffer;
/* We finished with the ANSI version, try to cache it */
- if (!InterlockedCompareExchangePointer(&BaseAnsiStartupInfo,
+ if (!InterlockedCompareExchangePointer((PVOID*)&BaseAnsiStartupInfo,
StartupInfo,
NULL))
{
WINAPI
FlushInstructionCache(IN HANDLE hProcess,
IN LPCVOID lpBaseAddress,
- IN SIZE_T dwSize)
+ IN SIZE_T nSize)
{
NTSTATUS Status;
/* Call the native function */
- Status = NtFlushInstructionCache(hProcess, (PVOID)lpBaseAddress, dwSize);
+ Status = NtFlushInstructionCache(hProcess, (PVOID)lpBaseAddress, nSize);
if (!NT_SUCCESS(Status))
{
/* Handle failure case */
RtlAcquirePebLock();
/* Kill all the threads */
- NtTerminateProcess(NULL, 0);
+ NtTerminateProcess(NULL, uExitCode);
/* Unload all DLLs */
LdrShutdownProcess();
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
NULL,
CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepExitProcess),
- sizeof(BASE_EXIT_PROCESS));
+ sizeof(*ExitProcessRequest));
/* Now do it again */
NtTerminateProcess(NtCurrentProcess(), uExitCode);
MessageTextU = &NtCurrentTeb()->StaticUnicodeString;
RtlInitAnsiString(&MessageText, (LPSTR)lpMessageText);
- /* Convert to unicode and just exit normally if this failed */
+ /* Convert to unicode, or just exit normally if this failed */
Status = RtlAnsiStringToUnicodeString(MessageTextU, &MessageText, FALSE);
if (!NT_SUCCESS(Status)) ExitProcess(0);
1,
1,
(PULONG_PTR)&UnicodeString,
+#if DBG
+ /* On Checked builds, Windows allows the user to cancel the operation */
OptionOkCancel,
+#else
+ OptionOk,
+#endif
&Response);
+#if DBG
/* Give the user a chance to abort */
if ((NT_SUCCESS(Status)) && (Response == ResponseCancel)) return;
+#endif
/* Otherwise kill the process */
ExitProcess(0);
FatalExit(IN int ExitCode)
{
#if DBG
- /* On Checked builds, Windows gives you a nice little debugger UI */
+ /* On Checked builds, Windows gives the user a nice little debugger UI */
CHAR ch[2];
DbgPrint("FatalExit...\n");
DbgPrint("\n");
Status = NtQueryInformationProcess(hProcess,
ProcessPriorityClass,
&PriorityClass,
- sizeof(PROCESS_PRIORITY_CLASS),
+ sizeof(PriorityClass),
NULL);
if (NT_SUCCESS(Status))
{
Status = NtQueryInformationProcess(hProcess,
ProcessPriorityBoost,
&PriorityBoost,
- sizeof(ULONG),
+ sizeof(PriorityBoost),
NULL);
if (NT_SUCCESS(Status))
{
Status = NtQueryInformationProcess(hProcess,
ProcessHandleCount,
&phc,
- sizeof(ULONG),
+ sizeof(phc),
NULL);
if (NT_SUCCESS(Status))
{
- /* Copy the count and return sucecss */
+ /* Copy the count and return success */
*pdwHandleCount = phc;
return TRUE;
}
sizeof(SessionInformation),
NULL);
- /* Close the handle and check if we suceeded */
+ /* Close the handle and check if we succeeded */
NtClose(ProcessHandle);
if (NT_SUCCESS(Status))
{
HANDLE FileHandle, SectionHandle, ProcessHandle;
ULONG ResumeCount;
PROCESS_PRIORITY_CLASS PriorityClass;
- NTSTATUS Status, Status1, ImageDbgStatus;
+ NTSTATUS Status, AppCompatStatus, SaferStatus, IFEOStatus, ImageDbgStatus;
PPEB Peb, RemotePeb;
PTEB Teb;
INITIAL_TEB InitialTeb;
PCHAR pcScan;
SIZE_T n;
WCHAR SaveChar;
- ULONG Length, CurdirLength, CmdQuoteLength;
+ ULONG Length, FileAttribs, CmdQuoteLength;
ULONG CmdLineLength, ResultSize;
PWCHAR QuotedCmdLine, AnsiCmdCommand, ExtBuffer, CurrentDirectory;
PWCHAR NullBuffer, ScanString, NameBuffer, SearchPath, DebuggerCmdLine;
BASE_MSG_SXS_HANDLES MappedHandles, Handles, FileHandles;
PVOID CapturedStrings[3];
SXS_WIN32_NT_PATH_PAIR ExePathPair, ManifestPathPair, PolicyPathPair;
- SXS_OVERRIDE_MANIFEST OverrideMannifest;
+ SXS_OVERRIDE_MANIFEST OverrideManifest;
UNICODE_STRING FreeString, SxsNtExePath;
PWCHAR SxsConglomeratedBuffer, StaticBuffer;
ULONG ConglomeratedBufferSizeBytes, StaticBufferSize, i;
/* Zero out the initial core variables and handles */
QuerySection = FALSE;
InJob = FALSE;
- SkipSaferAndAppCompat = TRUE; // HACK for making .bat/.cmd launch working again.
+ SkipSaferAndAppCompat = FALSE;
ParameterFlags = 0;
Flags = 0;
DebugHandle = NULL;
if ((Length) && (Length < MAX_PATH))
{
/* Get file attributes */
- CurdirLength = GetFileAttributesW(NameBuffer);
- if ((CurdirLength != 0xFFFFFFFF) &&
- (CurdirLength & FILE_ATTRIBUTE_DIRECTORY))
+ FileAttribs = GetFileAttributesW(NameBuffer);
+ if ((FileAttribs != INVALID_FILE_ATTRIBUTES) &&
+ (FileAttribs & FILE_ATTRIBUTE_DIRECTORY))
{
/* This was a directory, fail later on */
Length = 0;
&SxsWin32RelativePath);
if (!TranslationStatus)
{
- /* Path must be invaild somehow, bail out */
+ /* Path must be invalid somehow, bail out */
DPRINT1("Path translation for SxS failed\n");
SetLastError(ERROR_PATH_NOT_FOUND);
Result = FALSE;
FILE_NON_DIRECTORY_FILE);
}
+ /* Failure path, display which file failed to open */
+ if (!NT_SUCCESS(Status))
+ DPRINT1("Open file failed: %lx (%wZ)\n", Status, &PathName);
+
/* Cleanup in preparation for failure or success */
RtlReleaseRelativeName(&SxsWin32RelativePath);
+
if (!NT_SUCCESS(Status))
{
/* Failure path, try to understand why */
- DPRINT1("Open file failed: %lx\n", Status);
if (RtlIsDosDeviceName_U(lpApplicationName))
{
/* If a device is being executed, return this special error code */
if (QuerySection)
{
/* Nothing to do */
- Status = STATUS_SUCCESS;
+ AppCompatStatus = STATUS_SUCCESS;
}
else
{
/* Get some information about the executable */
- Status = NtQuerySection(SectionHandle,
+ AppCompatStatus = NtQuerySection(SectionHandle,
SectionImageInformation,
&ImageInformation,
sizeof(ImageInformation),
}
/* Do we have section information now? */
- if (NT_SUCCESS(Status))
+ if (NT_SUCCESS(AppCompatStatus))
{
/* Don't ask for it again, save the machine type */
QuerySection = TRUE;
}
/* Is there a reason/Shim we shouldn't run this application? */
- Status = BasepCheckBadapp(FileHandle,
+ AppCompatStatus = BasepCheckBadapp(FileHandle,
FreeBuffer,
lpEnvironment,
ImageMachine,
&AppCompatSxsData,
&AppCompatSxsDataSize,
&FusionFlags);
- if (!NT_SUCCESS(Status))
+ if (!NT_SUCCESS(AppCompatStatus))
{
/* This is usually the status we get back */
- DPRINT1("App compat launch failure: %lx\n", Status);
- if (Status == STATUS_ACCESS_DENIED)
+ DPRINT1("App compat launch failure: %lx\n", AppCompatStatus);
+ if (AppCompatStatus == STATUS_ACCESS_DENIED)
{
/* Convert it to something more Win32-specific */
SetLastError(ERROR_CANCELLED);
else
{
/* Some other error */
- BaseSetLastNTError(Status);
+ BaseSetLastNTError(AppCompatStatus);
}
/* Did we have a section? */
if (SaferNeeded)
{
/* We have to call into the WinSafer library and actually check */
- Status = BasepCheckWinSaferRestrictions(hUserToken,
+ SaferStatus = BasepCheckWinSaferRestrictions(hUserToken,
(LPWSTR)lpApplicationName,
FileHandle,
&InJob,
&TokenHandle,
&JobHandle);
- if (Status == 0xFFFFFFFF)
+ if (SaferStatus == 0xFFFFFFFF)
{
/* Back in 2003, they didn't have an NTSTATUS for this... */
DPRINT1("WinSafer blocking process launch\n");
}
/* Other status codes are not-Safer related, just convert them */
- if (!NT_SUCCESS(Status))
+ if (!NT_SUCCESS(SaferStatus))
{
- DPRINT1("Error checking WinSafer: %lx\n", Status);
- BaseSetLastNTError(Status);
+ DPRINT1("Error checking WinSafer: %lx\n", SaferStatus);
+ BaseSetLastNTError(SaferStatus);
Result = FALSE;
goto Quickie;
}
goto Quickie;
}
- /* Don't let callers pass in this flag -- we'll only get it from IFRO */
+ /* Don't let callers pass in this flag -- we'll only get it from IFEO */
Flags &= ~PROCESS_CREATE_FLAGS_LARGE_PAGES;
/* Clear the IFEO-missing flag, before we know for sure... */
(NtCurrentPeb()->ReadImageFileExecOptions))
{
/* Let's do this! Attempt to open IFEO */
- Status1 = LdrOpenImageFileOptionsKey(&PathName, 0, &KeyHandle);
- if (!NT_SUCCESS(Status1))
+ IFEOStatus = LdrOpenImageFileOptionsKey(&PathName, 0, &KeyHandle);
+ if (!NT_SUCCESS(IFEOStatus))
{
/* We failed, set the flag so we store this in the parameters */
- if (Status1 == STATUS_OBJECT_NAME_NOT_FOUND) ParameterFlags |= 2;
+ if (IFEOStatus == STATUS_OBJECT_NAME_NOT_FOUND) ParameterFlags |= 2;
}
else
{
if (!DebuggerCmdLine)
{
/* Close IFEO on failure */
- Status1 = NtClose(KeyHandle);
- ASSERT(NT_SUCCESS(Status1));
+ IFEOStatus = NtClose(KeyHandle);
+ ASSERT(NT_SUCCESS(IFEOStatus));
/* Fail the call */
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
}
/* Now query for the debugger */
- Status1 = LdrQueryImageFileKeyOption(KeyHandle,
+ IFEOStatus = LdrQueryImageFileKeyOption(KeyHandle,
L"Debugger",
REG_SZ,
DebuggerCmdLine,
MAX_PATH * sizeof(WCHAR),
&ResultSize);
- if (!(NT_SUCCESS(Status1)) ||
+ if (!(NT_SUCCESS(IFEOStatus)) ||
(ResultSize < sizeof(WCHAR)) ||
(DebuggerCmdLine[0] == UNICODE_NULL))
{
}
/* Also query if we should map with large pages */
- Status1 = LdrQueryImageFileKeyOption(KeyHandle,
+ IFEOStatus = LdrQueryImageFileKeyOption(KeyHandle,
L"UseLargePages",
REG_DWORD,
&UseLargePages,
sizeof(UseLargePages),
NULL);
- if ((NT_SUCCESS(Status1)) && (UseLargePages))
+ if ((NT_SUCCESS(IFEOStatus)) && (UseLargePages))
{
/* Do it! This is the only way this flag can be set */
Flags |= PROCESS_CREATE_FLAGS_LARGE_PAGES;
}
/* We're done with IFEO, can close it now */
- Status1 = NtClose(KeyHandle);
- ASSERT(NT_SUCCESS(Status1));
+ IFEOStatus = NtClose(KeyHandle);
+ ASSERT(NT_SUCCESS(IFEOStatus));
}
}
NULL);
if ((hUserToken) && (lpProcessAttributes))
{
- /* Auggment them with information from the user */
+ /* Augment them with information from the user */
LocalProcessAttributes = *lpProcessAttributes;
LocalProcessAttributes.lpSecurityDescriptor = NULL;
}
/* Make sure the directory is actually valid */
- CurdirLength = GetFileAttributesW(CurrentDirectory);
- if ((CurdirLength == 0xffffffff) ||
- !(CurdirLength & FILE_ATTRIBUTE_DIRECTORY))
+ FileAttribs = GetFileAttributesW(CurrentDirectory);
+ if ((FileAttribs == INVALID_FILE_ATTRIBUTES) ||
+ !(FileAttribs & FILE_ATTRIBUTE_DIRECTORY))
{
/* It isn't, so bail out */
DPRINT1("Current directory is invalid\n");
LPPROCESS_INFORMATION lpProcessInformation,
PHANDLE hNewToken)
{
- PUNICODE_STRING CommandLine = NULL;
- UNICODE_STRING DummyString;
- UNICODE_STRING LiveCommandLine;
+ UNICODE_STRING CommandLine;
UNICODE_STRING ApplicationName;
UNICODE_STRING CurrentDirectory;
BOOL bRetVal;
RtlMoveMemory(&StartupInfo, lpStartupInfo, sizeof(*lpStartupInfo));
/* Initialize all strings to nothing */
- LiveCommandLine.Buffer = NULL;
- DummyString.Buffer = NULL;
+ CommandLine.Buffer = NULL;
ApplicationName.Buffer = NULL;
CurrentDirectory.Buffer = NULL;
StartupInfo.lpDesktop = NULL;
/* Convert the Command line */
if (lpCommandLine)
{
- /* If it's too long, then we'll have a problem */
- if ((strlen(lpCommandLine) + 1) * sizeof(WCHAR) <
- NtCurrentTeb()->StaticUnicodeString.MaximumLength)
- {
- /* Cache it in the TEB */
- CommandLine = Basep8BitStringToStaticUnicodeString(lpCommandLine);
- }
- else
- {
- /* Use a dynamic version */
- Basep8BitStringToDynamicUnicodeString(&LiveCommandLine,
- lpCommandLine);
- }
- }
- else
- {
- /* The logic below will use CommandLine, so we must make it valid */
- CommandLine = &DummyString;
+ Basep8BitStringToDynamicUnicodeString(&CommandLine,
+ lpCommandLine);
}
/* Convert the Name and Directory */
/* Call the Unicode function */
bRetVal = CreateProcessInternalW(hToken,
ApplicationName.Buffer,
- LiveCommandLine.Buffer ?
- LiveCommandLine.Buffer : CommandLine->Buffer,
+ CommandLine.Buffer,
lpProcessAttributes,
lpThreadAttributes,
bInheritHandles,
/* Clean up */
RtlFreeUnicodeString(&ApplicationName);
- RtlFreeUnicodeString(&LiveCommandLine);
+ RtlFreeUnicodeString(&CommandLine);
RtlFreeUnicodeString(&CurrentDirectory);
RtlFreeHeap(RtlGetProcessHeap(), 0, StartupInfo.lpDesktop);
RtlFreeHeap(RtlGetProcessHeap(), 0, StartupInfo.lpReserved);
*/
UINT
WINAPI
+DECLSPEC_HOTPATCH
WinExec(LPCSTR lpCmdLine,
UINT uCmdShow)
{