ReactOS 0.4.17-dev-812-ged4f258
proc.c File Reference
#include <k32.h>
#include <debug.h>
Include dependency graph for proc.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define CMD_STRING   L"cmd /c "
 
#define THEONLYGROUP   0
 
#define AddToHandle(x, y)   ((x) = (HANDLE)((ULONG_PTR)(x) | (y)))
 
#define RemoveFromHandle(x, y)   ((x) = (HANDLE)((ULONG_PTR)(x) & ~(y)))
 

Functions

VOID WINAPI RegisterWaitForInputIdle (WaitForInputIdleType lpfnRegisterWaitForInputIdle)
 
VOID WINAPI StuffStdHandle (IN HANDLE ProcessHandle, IN HANDLE StandardHandle, IN PHANDLE Address)
 
BOOLEAN WINAPI BuildSubSysCommandLine (IN LPCWSTR SubsystemName, IN LPCWSTR ApplicationName, IN LPCWSTR CommandLine, OUT PUNICODE_STRING SubsysCommandLine)
 
BOOLEAN WINAPI BasepIsImageVersionOk (IN ULONG ImageMajorVersion, IN ULONG ImageMinorVersion)
 
NTSTATUS WINAPI BasepCheckWebBladeHashes (IN HANDLE FileHandle)
 
NTSTATUS NTAPI BasepSaveAppCertRegistryValue (IN PLIST_ENTRY List, IN PWCHAR ComponentName, IN PWCHAR DllName)
 
NTSTATUS NTAPI BasepConfigureAppCertDlls (IN PWSTR ValueName, IN ULONG ValueType, IN PVOID ValueData, IN ULONG ValueLength, IN PVOID Context, IN PVOID EntryContext)
 
NTSTATUS WINAPI BasepIsProcessAllowed (IN LPWSTR ApplicationName)
 
NTSTATUS WINAPI BasepReplaceProcessThreadTokens (IN HANDLE TokenHandle, IN HANDLE ProcessHandle, IN HANDLE ThreadHandle)
 
VOID WINAPI BasepSxsCloseHandles (IN PBASE_MSG_SXS_HANDLES Handles)
 
DECLSPEC_NORETURN VOID WINAPI BaseProcessStartup (_In_ PPROCESS_START_ROUTINE lpStartAddress)
 
BOOLEAN WINAPI BasePushProcessParameters (IN ULONG ParameterFlags, IN HANDLE ProcessHandle, IN PPEB RemotePeb, IN LPCWSTR ApplicationPathName, IN LPWSTR lpCurrentDirectory, IN LPWSTR lpCommandLine, IN LPVOID lpEnvironment, IN LPSTARTUPINFOW StartupInfo, IN DWORD CreationFlags, IN BOOL InheritHandles, IN ULONG ImageSubsystem, IN PVOID AppCompatData, IN ULONG AppCompatDataSize)
 
VOID WINAPI InitCommandLines (VOID)
 
BOOL WINAPI GetProcessAffinityMask (IN HANDLE hProcess, OUT PDWORD_PTR lpProcessAffinityMask, OUT PDWORD_PTR lpSystemAffinityMask)
 
BOOL WINAPI SetProcessAffinityMask (IN HANDLE hProcess, IN DWORD_PTR dwProcessAffinityMask)
 
WORD WINAPI GetActiveProcessorGroupCount (VOID)
 
static DWORD GetProcessorCountInfo (IN WORD GroupNumber, IN BOOL Maximum)
 
DWORD WINAPI GetActiveProcessorCount (IN WORD GroupNumber)
 
DWORD WINAPI GetMaximumProcessorCount (IN WORD GroupNumber)
 
BOOL WINAPI GetProcessShutdownParameters (OUT LPDWORD lpdwLevel, OUT LPDWORD lpdwFlags)
 
BOOL WINAPI SetProcessShutdownParameters (IN DWORD dwLevel, IN DWORD dwFlags)
 
BOOL WINAPI GetProcessWorkingSetSizeEx (IN HANDLE hProcess, OUT PSIZE_T lpMinimumWorkingSetSize, OUT PSIZE_T lpMaximumWorkingSetSize, OUT PDWORD Flags)
 
BOOL WINAPI GetProcessWorkingSetSize (IN HANDLE hProcess, OUT PSIZE_T lpMinimumWorkingSetSize, OUT PSIZE_T lpMaximumWorkingSetSize)
 
BOOL WINAPI SetProcessWorkingSetSizeEx (IN HANDLE hProcess, IN SIZE_T dwMinimumWorkingSetSize, IN SIZE_T dwMaximumWorkingSetSize, IN DWORD Flags)
 
BOOL WINAPI SetProcessWorkingSetSize (IN HANDLE hProcess, IN SIZE_T dwMinimumWorkingSetSize, IN SIZE_T dwMaximumWorkingSetSize)
 
BOOL WINAPI GetProcessTimes (IN HANDLE hProcess, IN LPFILETIME lpCreationTime, IN LPFILETIME lpExitTime, IN LPFILETIME lpKernelTime, IN LPFILETIME lpUserTime)
 
HANDLE WINAPI GetCurrentProcess (VOID)
 
HANDLE WINAPI GetCurrentThread (VOID)
 
DWORD WINAPI GetCurrentProcessId (VOID)
 
BOOL WINAPI GetExitCodeProcess (IN HANDLE hProcess, IN LPDWORD lpExitCode)
 
DWORD WINAPI GetProcessId (IN HANDLE Process)
 
HANDLE WINAPI OpenProcess (IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
 
VOID WINAPI GetStartupInfoW (IN LPSTARTUPINFOW lpStartupInfo)
 
BOOL WINAPI FlushInstructionCache (IN HANDLE hProcess, IN LPCVOID lpBaseAddress, IN SIZE_T nSize)
 
VOID WINAPI ExitProcess (IN UINT uExitCode)
 
BOOL WINAPI TerminateProcess (IN HANDLE hProcess, IN UINT uExitCode)
 
VOID WINAPI FatalAppExitA (UINT uAction, LPCSTR lpMessageText)
 
VOID WINAPI FatalAppExitW (IN UINT uAction, IN LPCWSTR lpMessageText)
 
VOID WINAPI FatalExit (IN int ExitCode)
 
DWORD WINAPI GetPriorityClass (IN HANDLE hProcess)
 
BOOL WINAPI SetPriorityClass (IN HANDLE hProcess, IN DWORD dwPriorityClass)
 
DWORD WINAPI GetProcessVersion (IN DWORD ProcessId)
 
BOOL WINAPI GetProcessIoCounters (IN HANDLE hProcess, OUT PIO_COUNTERS lpIoCounters)
 
BOOL WINAPI GetProcessPriorityBoost (IN HANDLE hProcess, OUT PBOOL pDisablePriorityBoost)
 
BOOL WINAPI SetProcessPriorityBoost (IN HANDLE hProcess, IN BOOL bDisablePriorityBoost)
 
BOOL WINAPI GetProcessHandleCount (IN HANDLE hProcess, OUT PDWORD pdwHandleCount)
 
BOOL WINAPI IsWow64Process (IN HANDLE hProcess, OUT PBOOL Wow64Process)
 
LPSTR WINAPI GetCommandLineA (VOID)
 
LPWSTR WINAPI GetCommandLineW (VOID)
 
BOOL NTAPI ReadProcessMemory (IN HANDLE hProcess, IN LPCVOID lpBaseAddress, IN LPVOID lpBuffer, IN SIZE_T nSize, OUT SIZE_T *lpNumberOfBytesRead)
 
BOOL NTAPI WriteProcessMemory (IN HANDLE hProcess, IN LPVOID lpBaseAddress, IN LPCVOID lpBuffer, IN SIZE_T nSize, OUT SIZE_T *lpNumberOfBytesWritten)
 
BOOL WINAPI ProcessIdToSessionId (IN DWORD dwProcessId, OUT PDWORD pSessionId)
 
 C_ASSERT (PROCESS_PRIORITY_CLASS_REALTIME==(PROCESS_PRIORITY_CLASS_HIGH+1))
 
BOOL WINAPI CreateProcessInternalW (IN HANDLE hUserToken, IN LPCWSTR lpApplicationName, IN LPWSTR lpCommandLine, IN LPSECURITY_ATTRIBUTES lpProcessAttributes, IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN BOOL bInheritHandles, IN DWORD dwCreationFlags, IN LPVOID lpEnvironment, IN LPCWSTR lpCurrentDirectory, IN LPSTARTUPINFOW lpStartupInfo, IN LPPROCESS_INFORMATION lpProcessInformation, OUT PHANDLE hNewToken)
 
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW (LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
 

Variables

UNICODE_STRING BaseUnicodeCommandLine
 
ANSI_STRING BaseAnsiCommandLine
 
UNICODE_STRING BasePathVariableName = RTL_CONSTANT_STRING(L"PATH")
 
PLDR_DATA_TABLE_ENTRY BasepExeLdrEntry
 
BOOLEAN g_AppCertInitialized
 
BOOLEAN g_HaveAppCerts
 
LIST_ENTRY BasepAppCertDllsList
 
RTL_CRITICAL_SECTION gcsAppCert
 
PBASEP_APPCERT_EMBEDDED_FUNC fEmbeddedCertFunc
 
NTSTATUS g_AppCertStatus
 
RTL_QUERY_REGISTRY_TABLE BasepAppCertTable [2]
 
PSAFER_REPLACE_PROCESS_THREAD_TOKENS g_SaferReplaceProcessThreadTokens
 
HMODULE gSaferHandle = (HMODULE)-1
 

Macro Definition Documentation

◆ AddToHandle

#define AddToHandle (   x,
  y 
)    ((x) = (HANDLE)((ULONG_PTR)(x) | (y)))

Definition at line 2124 of file proc.c.

◆ CMD_STRING

#define CMD_STRING   L"cmd /c "

Definition at line 49 of file proc.c.

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file proc.c.

◆ RemoveFromHandle

#define RemoveFromHandle (   x,
  y 
)    ((x) = (HANDLE)((ULONG_PTR)(x) & ~(y)))

Definition at line 2125 of file proc.c.

◆ THEONLYGROUP

#define THEONLYGROUP   0

Definition at line 912 of file proc.c.

Function Documentation

◆ BasepCheckWebBladeHashes()

NTSTATUS WINAPI BasepCheckWebBladeHashes ( IN HANDLE  FileHandle)

Definition at line 147 of file proc.c.

148{
150 CHAR Hash[16];
151
152 /* Get all the MD5 hashes */
154 if (!NT_SUCCESS(Status)) return Status;
155
156 /* Depending on which suite this is, run a bsearch and block the appropriate ones */
158 {
159 DPRINT1("Egad! This is a ReactOS Compute Server and we should prevent you from using certain APIs...but we won't.");
160 }
161 else if (SharedUserData->SuiteMask & VER_SUITE_STORAGE_SERVER)
162 {
163 DPRINT1("Gasp! This is a ReactOS Storage Server and we should prevent you from using certain APIs...but we won't.");
164 }
165 else if (SharedUserData->SuiteMask & VER_SUITE_BLADE)
166 {
167 DPRINT1("Golly! This is a ReactOS Web Blade Server and we should prevent you from using certain APIs...but we won't.");
168 }
169
170 /* Actually, fuck it, don't block anything, we're open source */
171 return STATUS_SUCCESS;
172}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
NTSYSAPI NTSTATUS NTAPI RtlComputeImportTableHash(IN HANDLE FileHandle, OUT PCHAR Hash, IN ULONG ImportTableHashSize)
Definition: libsupp.c:1191
static int Hash(const char *)
Definition: reader.c:2237
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
Status
Definition: gdiplustypes.h:24
#define VER_SUITE_STORAGE_SERVER
#define VER_SUITE_COMPUTE_SERVER
#define VER_SUITE_BLADE
char CHAR
Definition: pedump.c:57
#define SharedUserData
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by CreateProcessInternalW().

◆ BasepConfigureAppCertDlls()

NTSTATUS NTAPI BasepConfigureAppCertDlls ( IN PWSTR  ValueName,
IN ULONG  ValueType,
IN PVOID  ValueData,
IN ULONG  ValueLength,
IN PVOID  Context,
IN PVOID  EntryContext 
)

Definition at line 187 of file proc.c.

193{
194 /* Add this to the certification list */
196}
NTSTATUS NTAPI BasepSaveAppCertRegistryValue(IN PLIST_ENTRY List, IN PWCHAR ComponentName, IN PWCHAR DllName)
Definition: proc.c:176
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:312
_In_ PVOID Context
Definition: storport.h:2269
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243

◆ BasepIsImageVersionOk()

BOOLEAN WINAPI BasepIsImageVersionOk ( IN ULONG  ImageMajorVersion,
IN ULONG  ImageMinorVersion 
)

Definition at line 121 of file proc.c.

123{
124 /* Accept images for NT 3.1 or higher */
125 if (ImageMajorVersion > 3 ||
126 (ImageMajorVersion == 3 && ImageMinorVersion >= 10))
127 {
128 /* ReactOS-specific: Accept images even if they are newer than our internal NT version. */
129 if (ImageMajorVersion > SharedUserData->NtMajorVersion ||
130 (ImageMajorVersion == SharedUserData->NtMajorVersion && ImageMinorVersion > SharedUserData->NtMinorVersion))
131 {
132 DPRINT1("Accepting image version %lu.%lu, although ReactOS is an NT %hu.%hu OS!\n",
133 ImageMajorVersion,
134 ImageMinorVersion,
135 SharedUserData->NtMajorVersion,
136 SharedUserData->NtMinorVersion);
137 }
138
139 return TRUE;
140 }
141
142 return FALSE;
143}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117

Referenced by CreateProcessInternalW().

◆ BasepIsProcessAllowed()

NTSTATUS WINAPI BasepIsProcessAllowed ( IN LPWSTR  ApplicationName)

Definition at line 200 of file proc.c.

201{
202 NTSTATUS Status, Status1;
204 UINT Length;
205 HMODULE TrustLibrary;
207 ULONG CertFlag;
208 PLIST_ENTRY NextEntry;
210 UNICODE_STRING CertKey = RTL_CONSTANT_STRING(L"\\Registry\\MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\AppCertDlls");
212
213 /* Try to initialize the certification subsystem */
214 while (!g_AppCertInitialized)
215 {
216 /* Defaults */
218 Buffer = NULL;
219
220 /* Acquire the lock while initializing and see if we lost a race */
222 if (g_AppCertInitialized) break;
223
224 /* On embedded, there is a special DLL */
225 if (SharedUserData->SuiteMask & VER_SUITE_EMBEDDEDNT)
226 {
227 /* Allocate a buffer for the name */
228 Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
229 0,
230 MAX_PATH * sizeof(WCHAR) +
231 sizeof(UNICODE_NULL));
232 if (!Buffer)
233 {
234 /* Fail if no memory */
236 }
237 else
238 {
239 /* Now get the system32 directory in our buffer, make sure it fits */
240 Length = GetSystemDirectoryW(Buffer, MAX_PATH - sizeof("EmbdTrst.DLL"));
241 if ((Length) && (Length <= MAX_PATH - sizeof("EmbdTrst.DLL")))
242 {
243 /* Add a slash if needed, and add the embedded cert DLL name */
244 if (Buffer[Length - 1] != '\\') Buffer[Length++] = '\\';
246 L"EmbdTrst.DLL",
247 sizeof(L"EmbdTrst.DLL"));
248
249 /* Try to load it */
250 TrustLibrary = LoadLibraryW(Buffer);
251 if (TrustLibrary)
252 {
253 /* And extract the special function out of it */
254 fEmbeddedCertFunc = (PVOID)GetProcAddress(TrustLibrary,
255 "ImageOkToRunOnEmbeddedNT");
256 }
257 }
258
259 /* If we didn't get this far, set a failure code */
261 }
262 }
263 else
264 {
265 /* Other systems have a registry entry for this */
267 if (NT_SUCCESS(Status1))
268 {
269 /* Close it, we'll query it through Rtl */
271
272 /* Do the query, which will call a special callback */
274 L"Session Manager",
276 NULL,
277 NULL);
279 {
281 }
282 }
283 }
284
285 /* Free any buffer if we had one */
286 if (Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
287
288 /* Check for errors, or a missing embedded/custom certification DLL */
289 if (!NT_SUCCESS(Status) ||
291 {
292 /* The subsystem is not active on this machine, so give up */
295 }
296 else
297 {
298 /* We have certification DLLs active, remember this */
300 }
301
302 /* We are done the initialization phase, release the lock */
305 }
306
307 /* If there's no certification DLLs present, return the failure code */
308 if (!g_HaveAppCerts) return g_AppCertStatus;
309
310 /* Otherwise, assume success and make sure we have *something* */
313
314 /* If the something is an embedded certification DLL, call it and return */
316
317 /* Otherwise we have custom certification DLLs, parse them */
318 NextEntry = BasepAppCertDllsList.Flink;
319 CertFlag = 2;
320 while (NextEntry != &BasepAppCertDllsList)
321 {
322 /* Make sure the entry has a callback */
324 ASSERT(Entry->fPluginCertFunc != NULL);
325
326 /* Call it and check if it failed */
327 Status = Entry->fPluginCertFunc(ApplicationName, 1);
328 if (!NT_SUCCESS(Status)) CertFlag = 3;
329
330 /* Move on */
331 NextEntry = NextEntry->Flink;
332 }
333
334 /* Now loop them again */
335 NextEntry = BasepAppCertDllsList.Flink;
336 while (NextEntry != &BasepAppCertDllsList)
337 {
338 /* Make sure the entry has a callback */
340 ASSERT(Entry->fPluginCertFunc != NULL);
341
342 /* Call it, this time with the flag from the loop above */
343 Status = Entry->fPluginCertFunc(ApplicationName, CertFlag);
344 }
345
346 /* All done, return the status */
347 return Status;
348}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:634
Definition: bufpool.h:45
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define NULL
Definition: types.h:112
#define RTL_CONSTANT_STRING(s)
Definition: combase.c:35
#define GetProcAddress(x, y)
Definition: compat.h:753
#define MAX_PATH
Definition: compat.h:34
#define LoadLibraryW(x)
Definition: compat.h:747
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2232
PBASEP_APPCERT_EMBEDDED_FUNC fEmbeddedCertFunc
Definition: proc.c:28
RTL_QUERY_REGISTRY_TABLE BasepAppCertTable[2]
Definition: proc.c:30
RTL_CRITICAL_SECTION gcsAppCert
Definition: proc.c:27
LIST_ENTRY BasepAppCertDllsList
Definition: proc.c:26
BOOLEAN g_AppCertInitialized
Definition: proc.c:24
BOOLEAN g_HaveAppCerts
Definition: proc.c:25
NTSTATUS g_AppCertStatus
Definition: proc.c:29
#define L(x)
Definition: resources.c:13
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
unsigned int UINT
Definition: sysinfo.c:13
#define ASSERT(a)
Definition: mode.c:44
PVOID PVOID PWCHAR ApplicationName
Definition: env.c:47
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define RTL_REGISTRY_CONTROL
Definition: nt_native.h:163
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
#define KEY_READ
Definition: nt_native.h:1026
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3429
#define UNICODE_NULL
#define VER_SUITE_EMBEDDEDNT
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define RTL_CONSTANT_OBJECT_ATTRIBUTES(n, a)
short WCHAR
Definition: pedump.c:58
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
Entry
Definition: section.c:5216
Definition: kernel32.h:386
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
void * PVOID
Definition: typedefs.h:50
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint16_t * PWCHAR
Definition: typedefs.h:56
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK _In_opt_ PWDF_OBJECT_ATTRIBUTES KeyAttributes
Definition: wdfdevice.h:2666
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)

Referenced by CreateProcessInternalW().

◆ BasepReplaceProcessThreadTokens()

NTSTATUS WINAPI BasepReplaceProcessThreadTokens ( IN HANDLE  TokenHandle,
IN HANDLE  ProcessHandle,
IN HANDLE  ThreadHandle 
)

Definition at line 352 of file proc.c.

355{
357 ANSI_STRING SaferiReplaceProcessThreadTokens = RTL_CONSTANT_STRING("SaferiReplaceProcessThreadTokens");
358
359 /* Enter the application certification lock */
361
362 /* Check if we already know the function */
364 {
365 /* Call it */
368 ThreadHandle) ?
371 }
372 else
373 {
374 /* Check if the app certification DLL isn't loaded */
375 if (!(gSaferHandle) ||
376 (gSaferHandle == (HMODULE)-1) ||
377 (gSaferHandle == (HMODULE)-2))
378 {
379 /* Then we can't call the function */
381 }
382 else
383 {
384 /* We have the DLL, find the address of the Safer function */
386 &SaferiReplaceProcessThreadTokens,
387 0,
389 if (NT_SUCCESS(Status))
390 {
391 /* Found it, now call it */
394 ThreadHandle) ?
397 }
398 else
399 {
400 /* We couldn't find it, so this must be an unsupported DLL */
404 }
405 }
406 }
407
408 /* Release the lock and return the result */
410 return Status;
411}
HMODULE gSaferHandle
Definition: proc.c:44
PSAFER_REPLACE_PROCESS_THREAD_TOKENS g_SaferReplaceProcessThreadTokens
Definition: proc.c:43
NTSTATUS NTAPI LdrUnloadDll(_In_ PVOID BaseAddress)
Definition: ldrapi.c:1305
NTSTATUS NTAPI LdrGetProcedureAddress(_In_ PVOID BaseAddress, _In_opt_ _When_(Ordinal==0, _Notnull_) PANSI_STRING Name, _In_opt_ _When_(Name==NULL, _In_range_(>, 0)) ULONG Ordinal, _Out_ PVOID *ProcedureAddress)
Definition: ldrapi.c:789
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:407
_In_ ACCESS_MASK _In_ ULONG _Out_ PHANDLE TokenHandle
Definition: psfuncs.h:749
#define STATUS_ENTRYPOINT_NOT_FOUND
Definition: ntstatus.h:643

Referenced by CreateProcessInternalW().

◆ BaseProcessStartup()

DECLSPEC_NORETURN VOID WINAPI BaseProcessStartup ( _In_ PPROCESS_START_ROUTINE  lpStartAddress)

Definition at line 449 of file proc.c.

451{
453 {
454 /* Set our Start Address */
457 &lpStartAddress,
458 sizeof(PPROCESS_START_ROUTINE));
459
460 /* Call the Start Routine */
461 ExitThread(lpStartAddress());
462 }
464 {
465 /* Get the Exit code from the SEH Handler */
467 {
468 /* Kill the whole process, usually */
470 }
471 else
472 {
473 /* If running inside CSRSS, kill just this thread */
475 }
476 }
477 _SEH2_END;
478}
@ ThreadQuerySetWin32StartAddress
Definition: compat.h:944
BOOLEAN BaseRunningInServerProcess
Definition: dllmain.c:20
LONG WINAPI UnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo)
Definition: except.c:269
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1380
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:365
DWORD(WINAPI * PPROCESS_START_ROUTINE)(VOID)
Definition: kernel32.h:246
NTSTATUS NTAPI NtSetInformationThread(_In_ HANDLE ThreadHandle, _In_ THREADINFOCLASS ThreadInformationClass, _In_reads_bytes_(ThreadInformationLength) PVOID ThreadInformation, _In_ ULONG ThreadInformationLength)
Definition: query.c:2301
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:204
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:104
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:203
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
#define NtCurrentThread()
Definition: winternl.h:5372

Referenced by BaseInitializeContext().

◆ BasepSaveAppCertRegistryValue()

NTSTATUS NTAPI BasepSaveAppCertRegistryValue ( IN PLIST_ENTRY  List,
IN PWCHAR  ComponentName,
IN PWCHAR  DllName 
)

Definition at line 176 of file proc.c.

179{
180 /* Pretty much the only thing this key is used for, is malware */
183}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42

Referenced by BasepConfigureAppCertDlls().

◆ BasepSxsCloseHandles()

VOID WINAPI BasepSxsCloseHandles ( IN PBASE_MSG_SXS_HANDLES  Handles)

Definition at line 415 of file proc.c.

416{
418
419 /* Sanity checks */
420 ASSERT(Handles != NULL);
421 ASSERT(Handles->Process == NULL || Handles->Process == NtCurrentProcess());
422
423 /* Close the file handle */
424 if (Handles->File)
425 {
426 Status = NtClose(Handles->File);
428 }
429
430 /* Close the section handle */
431 if (Handles->Section)
432 {
433 Status = NtClose(Handles->Section);
435 }
436
437 /* Unmap the section view */
438 if (Handles->ViewBase.QuadPart)
439 {
441 (PVOID)(ULONG_PTR)Handles->ViewBase.QuadPart);
443 }
444}
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3498
#define NtCurrentProcess()
Definition: nt_native.h:1660
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by CreateProcessInternalW().

◆ BasePushProcessParameters()

BOOLEAN WINAPI BasePushProcessParameters ( IN ULONG  ParameterFlags,
IN HANDLE  ProcessHandle,
IN PPEB  RemotePeb,
IN LPCWSTR  ApplicationPathName,
IN LPWSTR  lpCurrentDirectory,
IN LPWSTR  lpCommandLine,
IN LPVOID  lpEnvironment,
IN LPSTARTUPINFOW  StartupInfo,
IN DWORD  CreationFlags,
IN BOOL  InheritHandles,
IN ULONG  ImageSubsystem,
IN PVOID  AppCompatData,
IN ULONG  AppCompatDataSize 
)

Definition at line 482 of file proc.c.

495{
496 WCHAR FullPath[MAX_PATH + 5];
497 PWCHAR Remaining, DllPathString, ScanChar;
498 PRTL_USER_PROCESS_PARAMETERS ProcessParameters, RemoteParameters;
499 PVOID RemoteAppCompatData;
503 ULONG EnviroSize;
504 SIZE_T Size;
505 BOOLEAN HavePebLock = FALSE, Result;
507
508 /* Get the full path name */
509 Size = GetFullPathNameW(ApplicationPathName,
510 MAX_PATH + 4,
511 FullPath,
512 &Remaining);
513 if ((Size) && (Size <= (MAX_PATH + 4)))
514 {
515 /* Get the DLL Path */
516 DllPathString = BaseComputeProcessDllPath(FullPath, lpEnvironment);
517 if (!DllPathString)
518 {
519 /* Fail */
521 return FALSE;
522 }
523
524 /* Initialize Strings */
525 RtlInitUnicodeString(&DllPath, DllPathString);
527 }
528 else
529 {
530 /* Couldn't get the path name. Just take the original path */
531 DllPathString = BaseComputeProcessDllPath((LPWSTR)ApplicationPathName,
532 lpEnvironment);
533 if (!DllPathString)
534 {
535 /* Fail */
537 return FALSE;
538 }
539
540 /* Initialize Strings */
541 RtlInitUnicodeString(&DllPath, DllPathString);
542 RtlInitUnicodeString(&ImageName, ApplicationPathName);
543 }
544
545 /* Initialize Strings */
546 RtlInitUnicodeString(&CommandLine, lpCommandLine);
547 RtlInitUnicodeString(&CurrentDirectory, lpCurrentDirectory);
548
549 /* Initialize more Strings from the Startup Info */
550 if (StartupInfo->lpDesktop)
551 {
552 RtlInitUnicodeString(&Desktop, StartupInfo->lpDesktop);
553 }
554 else
555 {
557 }
558 if (StartupInfo->lpReserved)
559 {
560 RtlInitUnicodeString(&Shell, StartupInfo->lpReserved);
561 }
562 else
563 {
565 }
566 if (StartupInfo->lpTitle)
567 {
568 RtlInitUnicodeString(&Title, StartupInfo->lpTitle);
569 }
570 else
571 {
572 RtlInitUnicodeString(&Title, ApplicationPathName);
573 }
574
575 /* This one is special because the length can differ */
576 Runtime.Buffer = (LPWSTR)StartupInfo->lpReserved2;
577 Runtime.MaximumLength = Runtime.Length = StartupInfo->cbReserved2;
578
579 /* Enforce no app compat data if the pointer was NULL */
580 if (!AppCompatData) AppCompatDataSize = 0;
581
582 /* Create the Parameter Block */
583 ProcessParameters = NULL;
584 DPRINT("ImageName: '%wZ'\n", &ImageName);
585 DPRINT("DllPath : '%wZ'\n", &DllPath);
586 DPRINT("CurDir : '%wZ'\n", &CurrentDirectory);
587 DPRINT("CmdLine : '%wZ'\n", &CommandLine);
588 DPRINT("Title : '%wZ'\n", &Title);
589 DPRINT("Desktop : '%wZ'\n", &Desktop);
590 DPRINT("Shell : '%wZ'\n", &Shell);
591 DPRINT("Runtime : '%wZ'\n", &Runtime);
592 Status = RtlCreateProcessParameters(&ProcessParameters,
593 &ImageName,
594 &DllPath,
595 lpCurrentDirectory ?
597 &CommandLine,
598 lpEnvironment,
599 &Title,
600 &Desktop,
601 &Shell,
602 &Runtime);
603 if (!NT_SUCCESS(Status)) goto FailPath;
604
605 /* Clear the current directory handle if not inheriting */
606 if (!InheritHandles) ProcessParameters->CurrentDirectory.Handle = NULL;
607
608 /* Check if the user passed in an environment */
609 if (lpEnvironment)
610 {
611 /* We should've made it part of the parameters block, enforce this */
612 lpEnvironment = ProcessParameters->Environment;
613 }
614 else
615 {
616 /* The user did not, so use the one from the current PEB */
617 HavePebLock = TRUE;
619 lpEnvironment = Peb->ProcessParameters->Environment;
620 }
621
622 /* Save pointer and start lookup */
623 ScanChar = lpEnvironment;
624 if (lpEnvironment)
625 {
626 /* Find the environment size */
627 while (*ScanChar++) while (*ScanChar++);
628 EnviroSize = (ULONG)((ULONG_PTR)ScanChar - (ULONG_PTR)lpEnvironment);
629
630 /* Allocate and Initialize new Environment Block */
631 Size = EnviroSize;
632 ProcessParameters->Environment = NULL;
634 (PVOID*)&ProcessParameters->Environment,
635 0,
636 &Size,
639 if (!NT_SUCCESS(Status)) goto FailPath;
640
641 /* Write the Environment Block */
643 ProcessParameters->Environment,
644 lpEnvironment,
645 EnviroSize,
646 NULL);
647
648 /* No longer need the PEB lock anymore */
649 if (HavePebLock)
650 {
651 /* Release it */
653 HavePebLock = FALSE;
654 }
655
656 /* Check if the write failed */
657 if (!NT_SUCCESS(Status)) goto FailPath;
658 }
659
660 /* Write new parameters */
661 ProcessParameters->StartingX = StartupInfo->dwX;
662 ProcessParameters->StartingY = StartupInfo->dwY;
663 ProcessParameters->CountX = StartupInfo->dwXSize;
664 ProcessParameters->CountY = StartupInfo->dwYSize;
665 ProcessParameters->CountCharsX = StartupInfo->dwXCountChars;
666 ProcessParameters->CountCharsY = StartupInfo->dwYCountChars;
667 ProcessParameters->FillAttribute = StartupInfo->dwFillAttribute;
668 ProcessParameters->WindowFlags = StartupInfo->dwFlags;
669 ProcessParameters->ShowWindowFlags = StartupInfo->wShowWindow;
670
671 /* Write the handles only if we have to */
672 if (StartupInfo->dwFlags &
673 (STARTF_USESTDHANDLES | STARTF_USEHOTKEY | STARTF_SHELLPRIVATE))
674 {
675 ProcessParameters->StandardInput = StartupInfo->hStdInput;
676 ProcessParameters->StandardOutput = StartupInfo->hStdOutput;
677 ProcessParameters->StandardError = StartupInfo->hStdError;
678 }
679
680 /* Use Special Flags for ConDllInitialize in Kernel32 */
681 if (CreationFlags & DETACHED_PROCESS)
682 {
683 ProcessParameters->ConsoleHandle = HANDLE_DETACHED_PROCESS;
684 }
685 else if (CreationFlags & CREATE_NEW_CONSOLE)
686 {
687 ProcessParameters->ConsoleHandle = HANDLE_CREATE_NEW_CONSOLE;
688 }
689 else if (CreationFlags & CREATE_NO_WINDOW)
690 {
691 ProcessParameters->ConsoleHandle = HANDLE_CREATE_NO_WINDOW;
692 }
693 else
694 {
695 /* Inherit our Console Handle */
696 ProcessParameters->ConsoleHandle = Peb->ProcessParameters->ConsoleHandle;
697
698 /* Make sure that the shell isn't trampling on our handles first */
699 if (!(StartupInfo->dwFlags &
700 (STARTF_USESTDHANDLES | STARTF_USEHOTKEY | STARTF_SHELLPRIVATE)))
701 {
702 /* Copy the handle if we are inheriting or if it's a console handle */
703 if ((InheritHandles) ||
705 {
706 ProcessParameters->StandardInput = Peb->ProcessParameters->StandardInput;
707 }
708 if ((InheritHandles) ||
710 {
711 ProcessParameters->StandardOutput = Peb->ProcessParameters->StandardOutput;
712 }
713 if ((InheritHandles) ||
715 {
716 ProcessParameters->StandardError = Peb->ProcessParameters->StandardError;
717 }
718 }
719 }
720
721 /* Also set the Console Flag */
722 if ((CreationFlags & CREATE_NEW_PROCESS_GROUP) &&
723 (!(CreationFlags & CREATE_NEW_CONSOLE)))
724 {
725 ProcessParameters->ConsoleFlags = 1;
726 }
727
728 /* Check if there's a .local file present */
729 if (ParameterFlags & 1)
730 {
732 }
733
734 /* Check if we failed to open the IFEO key */
735 if (ParameterFlags & 2)
736 {
738 }
739
740 /* Allocate memory for the parameter block */
741 Size = ProcessParameters->Length;
742 RemoteParameters = NULL;
744 (PVOID*)&RemoteParameters,
745 0,
746 &Size,
749 if (!NT_SUCCESS(Status)) goto FailPath;
750
751 /* Set the allocated size */
752 ProcessParameters->MaximumLength = Size;
753
754 /* Handle some Parameter Flags */
755 ProcessParameters->Flags |= (CreationFlags & PROFILE_USER) ?
757 ProcessParameters->Flags |= (CreationFlags & PROFILE_KERNEL) ?
759 ProcessParameters->Flags |= (CreationFlags & PROFILE_SERVER) ?
761 ProcessParameters->Flags |= (Peb->ProcessParameters->Flags &
763
764 /* Write the Parameter Block */
766 RemoteParameters,
767 ProcessParameters,
768 ProcessParameters->Length,
769 NULL);
770 if (!NT_SUCCESS(Status)) goto FailPath;
771
772 /* Write the PEB Pointer */
774 &RemotePeb->ProcessParameters,
775 &RemoteParameters,
776 sizeof(PVOID),
777 NULL);
778 if (!NT_SUCCESS(Status)) goto FailPath;
779
780 /* Check if there's any app compat data to write */
781 RemoteAppCompatData = NULL;
782 if (AppCompatData)
783 {
784 /* Allocate some space for the application compatibility data */
785 Size = AppCompatDataSize;
787 &RemoteAppCompatData,
788 0,
789 &Size,
792 if (!NT_SUCCESS(Status)) goto FailPath;
793
794 /* Write the application compatibility data */
796 RemoteAppCompatData,
797 AppCompatData,
798 AppCompatDataSize,
799 NULL);
800 if (!NT_SUCCESS(Status)) goto FailPath;
801 }
802
803 /* Write the PEB Pointer to the app compat data (might be NULL) */
805 &RemotePeb->pShimData,
806 &RemoteAppCompatData,
807 sizeof(PVOID),
808 NULL);
809 if (!NT_SUCCESS(Status)) goto FailPath;
810
811 /* Now write Peb->ImageSubSystem */
812 if (ImageSubsystem)
813 {
815 &RemotePeb->ImageSubsystem,
816 &ImageSubsystem,
817 sizeof(ImageSubsystem),
818 NULL);
819 }
820
821 /* Success path */
822 Result = TRUE;
823
824Quickie:
825 /* Cleanup */
826 if (HavePebLock) RtlReleasePebLock();
827 RtlFreeHeap(RtlGetProcessHeap(), 0, DllPath.Buffer);
828 if (ProcessParameters) RtlDestroyProcessParameters(ProcessParameters);
829 return Result;
830FailPath:
831 DPRINT1("Failure to create process parameters: %lx\n", Status);
833 Result = FALSE;
834 goto Quickie;
835}
#define NtCurrentPeb()
Definition: FLS.c:22
unsigned char BOOLEAN
Definition: actypes.h:127
WCHAR CurrentDirectory[1024]
Definition: chkdsk.c:74
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
static CHAR Desktop[MAX_PATH]
Definition: dem.c:256
static CHAR Title[MAX_PATH]
Definition: dem.c:257
#define SetLastError(x)
Definition: compat.h:752
PPEB Peb
Definition: dllmain.c:27
LPWSTR WINAPI BaseComputeProcessDllPath(IN LPWSTR FullPath, IN PVOID Environment)
Definition: path.c:420
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1106
#define HANDLE_CREATE_NEW_CONSOLE
Definition: console.h:14
#define HANDLE_CREATE_NO_WINDOW
Definition: console.h:15
#define HANDLE_DETACHED_PROCESS
Definition: console.h:13
#define ULONG_PTR
Definition: config.h:101
if(dx< 0)
Definition: linetemp.h:194
static const char const char * DllPath
Definition: image.c:34
static const char * ImageName
Definition: image.c:34
NTSYSAPI NTSTATUS NTAPI RtlDestroyProcessParameters(_In_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters)
NTSYSAPI NTSTATUS NTAPI RtlCreateProcessParameters(_Out_ PRTL_USER_PROCESS_PARAMETERS *ProcessParameters, _In_ PUNICODE_STRING ImagePathName, _In_opt_ PUNICODE_STRING DllPath, _In_opt_ PUNICODE_STRING CurrentDirectory, _In_opt_ PUNICODE_STRING CommandLine, _In_opt_ PWSTR Environment, _In_opt_ PUNICODE_STRING WindowTitle, _In_opt_ PUNICODE_STRING DesktopInfo, _In_opt_ PUNICODE_STRING ShellInfo, _In_opt_ PUNICODE_STRING RuntimeInfo)
#define RTL_USER_PROCESS_PARAMETERS_IMAGE_KEY_MISSING
Definition: rtltypes.h:54
#define RTL_USER_PROCESS_PARAMETERS_PROFILE_KERNEL
Definition: rtltypes.h:43
#define RTL_USER_PROCESS_PARAMETERS_PROFILE_SERVER
Definition: rtltypes.h:44
#define RTL_USER_PROCESS_PARAMETERS_LOCAL_DLL_PATH
Definition: rtltypes.h:53
#define RTL_USER_PROCESS_PARAMETERS_PROFILE_USER
Definition: rtltypes.h:42
#define RTL_USER_PROCESS_PARAMETERS_DISABLE_HEAP_CHECKS
Definition: rtltypes.h:49
#define PAGE_READWRITE
Definition: nt_native.h:1307
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define MEM_COMMIT
Definition: nt_native.h:1316
NTSTATUS NTAPI NtWriteVirtualMemory(IN HANDLE ProcessHandle, IN PVOID BaseAddress, IN PVOID Buffer, IN SIZE_T NumberOfBytesToWrite, OUT PSIZE_T NumberOfBytesWritten OPTIONAL)
Definition: virtual.c:2895
NTSTATUS NTAPI NtAllocateVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UBaseAddress, IN ULONG_PTR ZeroBits, IN OUT PSIZE_T URegionSize, IN ULONG AllocationType, IN ULONG Protect)
Definition: virtual.c:4457
#define STARTF_USEHOTKEY
Definition: pch.h:41
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:167
#define IsConsoleHandle(h)
Definition: console.h:14
#define DPRINT
Definition: sndvol32.h:73
HANDLE Handle
Definition: rtltypes.h:1371
PRTL_USER_PROCESS_PARAMETERS ProcessParameters
Definition: btrfs_drv.h:1913
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * LPWSTR
Definition: typedefs.h:56
ULONG_PTR SIZE_T
Definition: typedefs.h:80
static int Shell(const char **args)
Definition: vfdcmd.c:1020
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
#define PROFILE_SERVER
Definition: winbase.h:220
#define CREATE_NO_WINDOW
Definition: winbase.h:217
#define CREATE_NEW_PROCESS_GROUP
Definition: winbase.h:190
#define PROFILE_KERNEL
Definition: winbase.h:219
#define PROFILE_USER
Definition: winbase.h:218
#define STARTF_USESTDHANDLES
Definition: winbase.h:476
#define DETACHED_PROCESS
Definition: winbase.h:184
#define CREATE_NEW_CONSOLE
Definition: winbase.h:185
NTSYSAPI void WINAPI RtlReleasePebLock(void)
Definition: libsupp.c:84
NTSYSAPI void WINAPI RtlAcquirePebLock(void)
Definition: libsupp.c:74
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by CreateProcessInternalW().

◆ BuildSubSysCommandLine()

BOOLEAN WINAPI BuildSubSysCommandLine ( IN LPCWSTR  SubsystemName,
IN LPCWSTR  ApplicationName,
IN LPCWSTR  CommandLine,
OUT PUNICODE_STRING  SubsysCommandLine 
)

Definition at line 87 of file proc.c.

91{
92 UNICODE_STRING CommandLineString, ApplicationNameString;
95
96 /* Convert to unicode strings */
97 RtlInitUnicodeString(&CommandLineString, ApplicationName);
98 RtlInitUnicodeString(&ApplicationNameString, CommandLine);
99
100 /* Allocate buffer for the output string */
101 Length = CommandLineString.MaximumLength + ApplicationNameString.MaximumLength + 32;
102 Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length);
103 RtlInitEmptyUnicodeString(SubsysCommandLine, Buffer, (USHORT)Length);
104 if (!Buffer)
105 {
106 /* Fail, no memory */
108 return FALSE;
109 }
110
111 /* Build the final subsystem command line */
112 RtlAppendUnicodeToString(SubsysCommandLine, SubsystemName);
113 RtlAppendUnicodeStringToString(SubsysCommandLine, &CommandLineString);
114 RtlAppendUnicodeToString(SubsysCommandLine, L" /C ");
115 RtlAppendUnicodeStringToString(SubsysCommandLine, &ApplicationNameString);
116 return TRUE;
117}
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
unsigned short USHORT
Definition: pedump.c:61

Referenced by CreateProcessInternalW().

◆ C_ASSERT()

◆ CreateProcessInternalW()

BOOL WINAPI CreateProcessInternalW ( IN HANDLE  hUserToken,
IN LPCWSTR  lpApplicationName,
IN LPWSTR  lpCommandLine,
IN LPSECURITY_ATTRIBUTES  lpProcessAttributes,
IN LPSECURITY_ATTRIBUTES  lpThreadAttributes,
IN BOOL  bInheritHandles,
IN DWORD  dwCreationFlags,
IN LPVOID  lpEnvironment,
IN LPCWSTR  lpCurrentDirectory,
IN LPSTARTUPINFOW  lpStartupInfo,
IN LPPROCESS_INFORMATION  lpProcessInformation,
OUT PHANDLE  hNewToken 
)

Definition at line 2133 of file proc.c.

2145{
2146 //
2147 // Core variables used for creating the initial process and thread
2148 //
2149 SECURITY_ATTRIBUTES LocalThreadAttributes, LocalProcessAttributes;
2150 OBJECT_ATTRIBUTES LocalObjectAttributes;
2152 SECTION_IMAGE_INFORMATION ImageInformation;
2155 ULONG NoWindow, StackSize, ErrorCode, Flags;
2157 USHORT ImageMachine;
2158 ULONG ParameterFlags, PrivilegeValue, HardErrorMode, ErrorResponse;
2159 ULONG_PTR ErrorParameters[2];
2160 BOOLEAN InJob, SaferNeeded, UseLargePages, HavePrivilege;
2161 BOOLEAN QuerySection, SkipSaferAndAppCompat;
2163 BASE_API_MESSAGE CsrMsg[2];
2164 PBASE_CREATE_PROCESS CreateProcessMsg;
2165 PCSR_CAPTURE_BUFFER CaptureBuffer;
2166 PVOID BaseAddress, PrivilegeState, RealTimePrivilegeState;
2167 HANDLE DebugHandle, TokenHandle, JobHandle, KeyHandle, ThreadHandle;
2168 HANDLE FileHandle, SectionHandle, ProcessHandle;
2170 PROCESS_PRIORITY_CLASS PriorityClass;
2171 NTSTATUS Status, AppCompatStatus, SaferStatus, IFEOStatus, ImageDbgStatus;
2172 PPEB Peb, RemotePeb;
2173 PTEB Teb;
2174 INITIAL_TEB InitialTeb;
2175 PVOID TibValue;
2176 PIMAGE_NT_HEADERS NtHeaders;
2177 STARTUPINFOW StartupInfo;
2178 PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
2179 UNICODE_STRING DebuggerString;
2180 BOOL Result;
2181 //
2182 // Variables used for command-line and argument parsing
2183 //
2184 PCHAR pcScan;
2185 SIZE_T n;
2186 WCHAR SaveChar;
2187 ULONG Length, FileAttribs, CmdQuoteLength;
2188 ULONG ResultSize;
2189 SIZE_T EnvironmentLength, CmdLineLength;
2190 PWCHAR QuotedCmdLine, AnsiCmdCommand, ExtBuffer, CurrentDirectory;
2191 PWCHAR NullBuffer, ScanString, NameBuffer, SearchPath, DebuggerCmdLine;
2192 ANSI_STRING AnsiEnv;
2193 UNICODE_STRING UnicodeEnv, PathName;
2194 BOOLEAN SearchRetry, QuotesNeeded, CmdLineIsAppName, HasQuotes;
2195
2196 //
2197 // Variables used for Fusion/SxS (Side-by-Side Assemblies)
2198 //
2199 RTL_PATH_TYPE SxsPathType, PathType;
2200#if _SXS_SUPPORT_ENABLED_
2201 PRTL_BUFFER ByteBuffer;
2202 PRTL_UNICODE_STRING_BUFFER ThisBuffer, Buffer, SxsStaticBuffers[5];
2203 PRTL_UNICODE_STRING_BUFFER* BufferHead, SxsStringBuffer;
2204 RTL_UNICODE_STRING_BUFFER SxsWin32ManifestPath, SxsNtManifestPath;
2205 RTL_UNICODE_STRING_BUFFER SxsWin32PolicyPath, SxsNtPolicyPath;
2206 RTL_UNICODE_STRING_BUFFER SxsWin32AssemblyDirectory;
2207 BASE_MSG_SXS_HANDLES MappedHandles, Handles, FileHandles;
2208 PVOID CapturedStrings[3];
2209 SXS_WIN32_NT_PATH_PAIR ExePathPair, ManifestPathPair, PolicyPathPair;
2210 SXS_OVERRIDE_MANIFEST OverrideManifest;
2211 UNICODE_STRING FreeString, SxsNtExePath;
2212 PWCHAR SxsConglomeratedBuffer, StaticBuffer;
2213 ULONG ConglomeratedBufferSizeBytes, StaticBufferSize, i;
2214#endif
2216
2217 //
2218 // Variables used for path conversion (and partially Fusion/SxS)
2219 //
2220 PWCHAR FilePart, PathBuffer, FreeBuffer;
2221 BOOLEAN TranslationStatus;
2222 RTL_RELATIVE_NAME_U SxsWin32RelativePath;
2223 UNICODE_STRING PathBufferString, SxsWin32ExePath;
2224
2225 //
2226 // Variables used by Application Compatibility (and partially Fusion/SxS)
2227 //
2228 PVOID AppCompatSxsData, AppCompatData;
2229 ULONG AppCompatSxsDataSize, AppCompatDataSize;
2230 //
2231 // Variables used by VDM (Virtual Dos Machine) and WOW32 (16-bit Support)
2232 //
2233 ULONG BinarySubType, VdmBinaryType, VdmTask, VdmReserve;
2234 ULONG VdmUndoLevel;
2235 BOOLEAN UseVdmReserve;
2236 HANDLE VdmWaitObject;
2237 ANSI_STRING VdmAnsiEnv;
2238 UNICODE_STRING VdmString, VdmUnicodeEnv;
2239 BOOLEAN IsWowApp;
2240 PBASE_CHECK_VDM CheckVdmMsg;
2241
2242 /* Zero out the initial core variables and handles */
2243 QuerySection = FALSE;
2244 InJob = FALSE;
2245 SkipSaferAndAppCompat = FALSE;
2246 ParameterFlags = 0;
2247 Flags = 0;
2248 DebugHandle = NULL;
2249 JobHandle = NULL;
2250 TokenHandle = NULL;
2251 FileHandle = NULL;
2252 SectionHandle = NULL;
2254 ThreadHandle = NULL;
2256 BaseAddress = (PVOID)1;
2257
2258 /* Zero out initial SxS and Application Compatibility state */
2259 AppCompatData = NULL;
2260 AppCompatDataSize = 0;
2261 AppCompatSxsData = NULL;
2262 AppCompatSxsDataSize = 0;
2263 CaptureBuffer = NULL;
2264#if _SXS_SUPPORT_ENABLED_
2265 SxsConglomeratedBuffer = NULL;
2266#endif
2267 FusionFlags = 0;
2268
2269 /* Zero out initial parsing variables -- others are initialized later */
2270 DebuggerCmdLine = NULL;
2271 PathBuffer = NULL;
2272 SearchPath = NULL;
2273 NullBuffer = NULL;
2274 FreeBuffer = NULL;
2275 NameBuffer = NULL;
2277 FilePart = NULL;
2278 DebuggerString.Buffer = NULL;
2279 HasQuotes = FALSE;
2280 QuotedCmdLine = NULL;
2281
2282 /* Zero out initial VDM state */
2283 VdmAnsiEnv.Buffer = NULL;
2284 VdmUnicodeEnv.Buffer = NULL;
2285 VdmString.Buffer = NULL;
2286 VdmTask = 0;
2287 VdmUndoLevel = 0;
2288 VdmBinaryType = 0;
2289 VdmReserve = 0;
2290 VdmWaitObject = NULL;
2291 UseVdmReserve = FALSE;
2292 IsWowApp = FALSE;
2293
2294 /* Set message structures */
2295 CreateProcessMsg = &CsrMsg[0].Data.CreateProcessRequest;
2296 CheckVdmMsg = &CsrMsg[1].Data.CheckVDMRequest;
2297
2298 /* Clear the more complex structures by zeroing out their entire memory */
2299 RtlZeroMemory(&Context, sizeof(Context));
2300#if _SXS_SUPPORT_ENABLED_
2301 RtlZeroMemory(&FileHandles, sizeof(FileHandles));
2302 RtlZeroMemory(&MappedHandles, sizeof(MappedHandles));
2303 RtlZeroMemory(&Handles, sizeof(Handles));
2304#endif
2305 RtlZeroMemory(&CreateProcessMsg->Sxs, sizeof(CreateProcessMsg->Sxs));
2306 RtlZeroMemory(&LocalProcessAttributes, sizeof(LocalProcessAttributes));
2307 RtlZeroMemory(&LocalThreadAttributes, sizeof(LocalThreadAttributes));
2308
2309 /* Zero out output arguments as well */
2310 RtlZeroMemory(lpProcessInformation, sizeof(*lpProcessInformation));
2311 if (hNewToken) *hNewToken = NULL;
2312
2313 /* Capture the special window flag */
2314 NoWindow = dwCreationFlags & CREATE_NO_WINDOW;
2315 dwCreationFlags &= ~CREATE_NO_WINDOW;
2316
2317#if _SXS_SUPPORT_ENABLED_
2318 /* Setup the SxS static string arrays and buffers */
2319 SxsStaticBuffers[0] = &SxsWin32ManifestPath;
2320 SxsStaticBuffers[1] = &SxsWin32PolicyPath;
2321 SxsStaticBuffers[2] = &SxsWin32AssemblyDirectory;
2322 SxsStaticBuffers[3] = &SxsNtManifestPath;
2323 SxsStaticBuffers[4] = &SxsNtPolicyPath;
2324 ExePathPair.Win32 = &SxsWin32ExePath;
2325 ExePathPair.Nt = &SxsNtExePath;
2326 ManifestPathPair.Win32 = &SxsWin32ManifestPath.String;
2327 ManifestPathPair.Nt = &SxsNtManifestPath.String;
2328 PolicyPathPair.Win32 = &SxsWin32PolicyPath.String;
2329 PolicyPathPair.Nt = &SxsNtPolicyPath.String;
2330#endif
2331
2332 DPRINT("CreateProcessInternalW: '%S' '%S' %lx\n", lpApplicationName, lpCommandLine, dwCreationFlags);
2333
2334 /* Finally, set our TEB and PEB */
2335 Teb = NtCurrentTeb();
2336 Peb = NtCurrentPeb();
2337
2338 /* This combination is illegal (see MSDN) */
2339 if ((dwCreationFlags & (DETACHED_PROCESS | CREATE_NEW_CONSOLE)) ==
2341 {
2342 DPRINT1("Invalid flag combo used\n");
2344 return FALSE;
2345 }
2346
2347 /* Convert the priority class */
2348 if (dwCreationFlags & IDLE_PRIORITY_CLASS)
2349 {
2351 }
2352 else if (dwCreationFlags & BELOW_NORMAL_PRIORITY_CLASS)
2353 {
2355 }
2356 else if (dwCreationFlags & NORMAL_PRIORITY_CLASS)
2357 {
2359 }
2360 else if (dwCreationFlags & ABOVE_NORMAL_PRIORITY_CLASS)
2361 {
2363 }
2364 else if (dwCreationFlags & HIGH_PRIORITY_CLASS)
2365 {
2367 }
2368 else if (dwCreationFlags & REALTIME_PRIORITY_CLASS)
2369 {
2371 PriorityClass.PriorityClass += (BasepIsRealtimeAllowed(FALSE) != NULL);
2372 }
2373 else
2374 {
2376 }
2377
2378 /* Done with the priority masks, so get rid of them */
2379 PriorityClass.Foreground = FALSE;
2380 dwCreationFlags &= ~(NORMAL_PRIORITY_CLASS |
2386
2387 /* You cannot request both a shared and a separate WoW VDM */
2388 if ((dwCreationFlags & CREATE_SEPARATE_WOW_VDM) &&
2389 (dwCreationFlags & CREATE_SHARED_WOW_VDM))
2390 {
2391 /* Fail such nonsensical attempts */
2392 DPRINT1("Invalid WOW flags\n");
2394 return FALSE;
2395 }
2396 else if (!(dwCreationFlags & CREATE_SHARED_WOW_VDM) &&
2398 {
2399 /* A shared WoW VDM was not requested but system enforces separation */
2400 dwCreationFlags |= CREATE_SEPARATE_WOW_VDM;
2401 }
2402
2403 /* If a shared WoW VDM is used, make sure the process isn't in a job */
2404 if (!(dwCreationFlags & CREATE_SEPARATE_WOW_VDM) &&
2406 {
2407 /* Remove the shared flag and add the separate flag */
2408 dwCreationFlags = (dwCreationFlags &~ CREATE_SHARED_WOW_VDM) |
2410 }
2411
2412 /* Convert the environment */
2413 if ((lpEnvironment) && !(dwCreationFlags & CREATE_UNICODE_ENVIRONMENT))
2414 {
2415 /* Scan the environment to calculate its Unicode size */
2416 AnsiEnv.Buffer = pcScan = (PCHAR)lpEnvironment;
2417 while ((*pcScan) || (*(pcScan + 1))) ++pcScan;
2418
2419 /* Make sure the environment is not too large */
2420 EnvironmentLength = (pcScan + sizeof(ANSI_NULL) - (PCHAR)lpEnvironment);
2421 if (EnvironmentLength > MAXUSHORT)
2422 {
2423 /* Fail */
2425 return FALSE;
2426 }
2427
2428 /* Create our ANSI String */
2429 AnsiEnv.Length = (USHORT)EnvironmentLength;
2430 AnsiEnv.MaximumLength = AnsiEnv.Length + sizeof(ANSI_NULL);
2431
2432 /* Allocate memory for the Unicode Environment */
2433 UnicodeEnv.Buffer = NULL;
2434 RegionSize = AnsiEnv.MaximumLength * sizeof(WCHAR);
2436 (PVOID)&UnicodeEnv.Buffer,
2437 0,
2438 &RegionSize,
2439 MEM_COMMIT,
2441 if (!NT_SUCCESS(Status))
2442 {
2443 /* Fail */
2445 return FALSE;
2446 }
2447
2448 /* Use the allocated size and convert */
2449 UnicodeEnv.MaximumLength = (USHORT)RegionSize;
2450 Status = RtlAnsiStringToUnicodeString(&UnicodeEnv, &AnsiEnv, FALSE);
2451 if (!NT_SUCCESS(Status))
2452 {
2453 /* Fail */
2455 (PVOID)&UnicodeEnv.Buffer,
2456 &RegionSize,
2457 MEM_RELEASE);
2459 return FALSE;
2460 }
2461
2462 /* Now set the Unicode environment as the environment string pointer */
2463 lpEnvironment = UnicodeEnv.Buffer;
2464 }
2465
2466 /* Make a copy of the caller's startup info since we'll modify it */
2467 StartupInfo = *lpStartupInfo;
2468
2469 /* Check if private data is being sent on the same channel as std handles */
2470 if ((StartupInfo.dwFlags & STARTF_USESTDHANDLES) &&
2471 (StartupInfo.dwFlags & (STARTF_USEHOTKEY | STARTF_SHELLPRIVATE)))
2472 {
2473 /* Cannot use the std handles since we have monitor/hotkey values */
2474 StartupInfo.dwFlags &= ~STARTF_USESTDHANDLES;
2475 }
2476
2477 /* If there's a debugger, or we have to launch cmd.exe, we go back here */
2478AppNameRetry:
2479 /* New iteration -- free any existing name buffer */
2480 if (NameBuffer)
2481 {
2482 RtlFreeHeap(RtlGetProcessHeap(), 0, NameBuffer);
2483 NameBuffer = NULL;
2484 }
2485
2486 /* New iteration -- free any existing free buffer */
2487 if (FreeBuffer)
2488 {
2489 RtlFreeHeap(RtlGetProcessHeap(), 0, FreeBuffer);
2490 FreeBuffer = NULL;
2491 }
2492
2493 /* New iteration -- close any existing file handle */
2494 if (FileHandle)
2495 {
2497 FileHandle = NULL;
2498 }
2499
2500 /* Set the initial parsing state. This code can loop -- don't move this! */
2501 ErrorCode = 0;
2502 SearchRetry = TRUE;
2503 QuotesNeeded = FALSE;
2504 CmdLineIsAppName = FALSE;
2505
2506 /* First check if we don't have an application name */
2507 if (!lpApplicationName)
2508 {
2509 /* This should be the first time we attempt creating one */
2510 ASSERT(NameBuffer == NULL);
2511
2512 /* Allocate a buffer to hold it */
2513 NameBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
2514 0,
2515 MAX_PATH * sizeof(WCHAR));
2516 if (!NameBuffer)
2517 {
2519 Result = FALSE;
2520 goto Quickie;
2521 }
2522
2523 /* Initialize the application name and our parsing parameters */
2524 lpApplicationName = NullBuffer = ScanString = lpCommandLine;
2525
2526 /* Check for an initial quote*/
2527 if (*lpCommandLine == L'\"')
2528 {
2529 /* We found a quote, keep searching for another one */
2530 SearchRetry = FALSE;
2531 ScanString++;
2532 lpApplicationName = ScanString;
2533 while (*ScanString)
2534 {
2535 /* Have we found the terminating quote? */
2536 if (*ScanString == L'\"')
2537 {
2538 /* We're done, get out of here */
2539 NullBuffer = ScanString;
2540 HasQuotes = TRUE;
2541 break;
2542 }
2543
2544 /* Keep searching for the quote */
2545 ScanString++;
2546 NullBuffer = ScanString;
2547 }
2548 }
2549 else
2550 {
2551StartScan:
2552 /* We simply make the application name be the command line*/
2553 lpApplicationName = lpCommandLine;
2554 while (*ScanString)
2555 {
2556 /* Check if it starts with a space or tab */
2557 if ((*ScanString == L' ') || (*ScanString == L'\t'))
2558 {
2559 /* Break out of the search loop */
2560 NullBuffer = ScanString;
2561 break;
2562 }
2563
2564 /* Keep searching for a space or tab */
2565 ScanString++;
2566 NullBuffer = ScanString;
2567 }
2568 }
2569
2570 /* We have found the end of the application name, terminate it */
2571 SaveChar = *NullBuffer;
2572 *NullBuffer = UNICODE_NULL;
2573
2574 /* New iteration -- free any existing saved path */
2575 if (SearchPath)
2576 {
2577 RtlFreeHeap(RtlGetProcessHeap(), 0, SearchPath);
2578 SearchPath = NULL;
2579 }
2580
2581 /* Now compute the final EXE path based on the name */
2582 SearchPath = BaseComputeProcessExePath((LPWSTR)lpApplicationName);
2583 DPRINT("Search Path: %S\n", SearchPath);
2584 if (!SearchPath)
2585 {
2587 Result = FALSE;
2588 goto Quickie;
2589 }
2590
2591 /* And search for the executable in the search path */
2593 lpApplicationName,
2594 L".exe",
2595 MAX_PATH,
2596 NameBuffer,
2597 NULL);
2598
2599 /* Did we find it? */
2600 if ((Length) && (Length < MAX_PATH))
2601 {
2602 /* Get file attributes */
2603 FileAttribs = GetFileAttributesW(NameBuffer);
2604 if ((FileAttribs != INVALID_FILE_ATTRIBUTES) &&
2605 (FileAttribs & FILE_ATTRIBUTE_DIRECTORY))
2606 {
2607 /* This was a directory, fail later on */
2608 Length = 0;
2609 }
2610 else
2611 {
2612 /* It's a file! */
2613 Length++;
2614 }
2615 }
2616
2617 DPRINT("Length: %lu Buffer: %S\n", Length, NameBuffer);
2618
2619 /* Check if there was a failure in SearchPathW */
2620 if ((Length) && (Length < MAX_PATH))
2621 {
2622 /* Everything looks good, restore the name */
2623 *NullBuffer = SaveChar;
2624 lpApplicationName = NameBuffer;
2625 }
2626 else
2627 {
2628 /* Check if this was a relative path, which would explain it */
2629 PathType = RtlDetermineDosPathNameType_U(lpApplicationName);
2631 {
2632 /* This should fail, and give us a detailed LastError */
2633 FileHandle = CreateFileW(lpApplicationName,
2637 NULL,
2640 NULL);
2642 {
2643 /* It worked? Return a generic error */
2645 FileHandle = NULL;
2647 }
2648 }
2649 else
2650 {
2651 /* Path was absolute, which means it doesn't exist */
2653 }
2654
2655 /* Did we already fail once? */
2656 if (ErrorCode)
2657 {
2658 /* Set the error code */
2660 }
2661 else
2662 {
2663 /* Not yet, cache it */
2665 }
2666
2667 /* Put back the command line */
2668 *NullBuffer = SaveChar;
2669 lpApplicationName = NameBuffer;
2670
2671 /* It's possible there's whitespace in the directory name */
2672 if (!(*ScanString) || !(SearchRetry))
2673 {
2674 /* Not the case, give up completely */
2675 Result = FALSE;
2676 goto Quickie;
2677 }
2678
2679 /* There are spaces, so keep trying the next possibility */
2680 ScanString++;
2681 NullBuffer = ScanString;
2682
2683 /* We will have to add a quote, since there is a space */
2684 QuotesNeeded = TRUE;
2685 HasQuotes = TRUE;
2686 goto StartScan;
2687 }
2688 }
2689 else if (!(lpCommandLine) || !(*lpCommandLine))
2690 {
2691 /* We don't have a command line, so just use the application name */
2692 CmdLineIsAppName = TRUE;
2693 lpCommandLine = (LPWSTR)lpApplicationName;
2694 }
2695
2696 /* Convert the application name to its NT path */
2697 TranslationStatus = RtlDosPathNameToRelativeNtPathName_U(lpApplicationName,
2698 &PathName,
2699 NULL,
2700 &SxsWin32RelativePath);
2701 if (!TranslationStatus)
2702 {
2703 /* Path must be invalid somehow, bail out */
2704 DPRINT1("Path translation for SxS failed\n");
2706 Result = FALSE;
2707 goto Quickie;
2708 }
2709
2710 /* Setup the buffer that needs to be freed at the end */
2711 ASSERT(FreeBuffer == NULL);
2712 FreeBuffer = PathName.Buffer;
2713
2714 /* Check what kind of path the application is, for SxS (Fusion) purposes */
2715 RtlInitUnicodeString(&SxsWin32ExePath, lpApplicationName);
2716 SxsPathType = RtlDetermineDosPathNameType_U(lpApplicationName);
2717 if ((SxsPathType != RtlPathTypeDriveAbsolute) &&
2718 (SxsPathType != RtlPathTypeLocalDevice) &&
2719 (SxsPathType != RtlPathTypeRootLocalDevice) &&
2720 (SxsPathType != RtlPathTypeUncAbsolute))
2721 {
2722 /* Relative-type path, get the full path */
2723 RtlInitEmptyUnicodeString(&PathBufferString, NULL, 0);
2724 Status = RtlGetFullPathName_UstrEx(&SxsWin32ExePath,
2725 NULL,
2726 &PathBufferString,
2727 NULL,
2728 NULL,
2729 NULL,
2730 &SxsPathType,
2731 NULL);
2732 if (!NT_SUCCESS(Status))
2733 {
2734 /* Fail the rest of the create */
2735 RtlReleaseRelativeName(&SxsWin32RelativePath);
2737 Result = FALSE;
2738 goto Quickie;
2739 }
2740
2741 /* Use this full path as the SxS path */
2742 SxsWin32ExePath = PathBufferString;
2743 PathBuffer = PathBufferString.Buffer;
2744 PathBufferString.Buffer = NULL;
2745 DPRINT("SxS Path: %S\n", PathBuffer);
2746 }
2747
2748 /* Also set the .EXE path based on the path name */
2749#if _SXS_SUPPORT_ENABLED_
2750 SxsNtExePath = PathName;
2751#endif
2752 if (SxsWin32RelativePath.RelativeName.Length)
2753 {
2754 /* If it's relative, capture the relative name */
2755 PathName = SxsWin32RelativePath.RelativeName;
2756 }
2757 else
2758 {
2759 /* Otherwise, it's absolute, make sure no relative dir is used */
2760 SxsWin32RelativePath.ContainingDirectory = NULL;
2761 }
2762
2763 /* Now use the path name, and the root path, to try opening the app */
2764 DPRINT("Path: %wZ. Dir: %p\n", &PathName, SxsWin32RelativePath.ContainingDirectory);
2765 InitializeObjectAttributes(&LocalObjectAttributes,
2766 &PathName,
2768 SxsWin32RelativePath.ContainingDirectory,
2769 NULL);
2771 SYNCHRONIZE |
2775 &LocalObjectAttributes,
2780 if (!NT_SUCCESS(Status))
2781 {
2782 /* Try to open the app just for execute purposes instead */
2785 &LocalObjectAttributes,
2790 }
2791
2792 /* Failure path, display which file failed to open */
2793 if (!NT_SUCCESS(Status))
2794 DPRINT1("Open file failed: %lx (%wZ)\n", Status, &PathName);
2795
2796 /* Cleanup in preparation for failure or success */
2797 RtlReleaseRelativeName(&SxsWin32RelativePath);
2798
2799 if (!NT_SUCCESS(Status))
2800 {
2801 /* Failure path, try to understand why */
2802 if (RtlIsDosDeviceName_U(lpApplicationName))
2803 {
2804 /* If a device is being executed, return this special error code */
2806 Result = FALSE;
2807 goto Quickie;
2808 }
2809 else
2810 {
2811 /* Otherwise return the converted NT error code */
2813 Result = FALSE;
2814 goto Quickie;
2815 }
2816 }
2817
2818 /* Did the caller specify a desktop? */
2819 if (!StartupInfo.lpDesktop)
2820 {
2821 /* Use the one from the current process */
2823 }
2824
2825 /* Create a section for this file */
2826 Status = NtCreateSection(&SectionHandle,
2828 NULL,
2829 NULL,
2831 SEC_IMAGE,
2832 FileHandle);
2833 DPRINT("Section status: %lx\n", Status);
2834 if (NT_SUCCESS(Status))
2835 {
2836 /* Are we running on Windows Embedded, Datacenter, Blade or Starter? */
2837 if (SharedUserData->SuiteMask & (VER_SUITE_EMBEDDEDNT |
2841 {
2842 /* These SKUs do not allow running certain applications */
2845 {
2846 /* And this is one of them! */
2847 DPRINT1("Invalid Blade hashes!\n");
2849 Result = FALSE;
2850 goto Quickie;
2851 }
2852
2853 /* Did we get some other failure? */
2854 if (!NT_SUCCESS(Status))
2855 {
2856 /* If we couldn't check the hashes, assume nefariousness */
2857 DPRINT1("Tampered Blade hashes!\n");
2859 Result = FALSE;
2860 goto Quickie;
2861 }
2862 }
2863
2864 /* Now do Winsafer, etc, checks */
2865 Status = BasepIsProcessAllowed((LPWSTR)lpApplicationName);
2866 if (!NT_SUCCESS(Status))
2867 {
2868 /* Fail if we're not allowed to launch the process */
2869 DPRINT1("Process not allowed to launch: %lx\n", Status);
2871 if (SectionHandle)
2872 {
2873 NtClose(SectionHandle);
2874 SectionHandle = NULL;
2875 }
2876 Result = FALSE;
2877 goto Quickie;
2878 }
2879
2880 /* Is a DOS VDM being forced, but we already have a WOW32 instance ready? */
2881 if ((dwCreationFlags & CREATE_FORCEDOS) &&
2883 {
2884 /* This request can't be satisfied, instead, a separate VDM is needed */
2885 dwCreationFlags &= ~(CREATE_FORCEDOS | CREATE_SHARED_WOW_VDM);
2886 dwCreationFlags |= CREATE_SEPARATE_WOW_VDM;
2887
2888 /* Set a failure code, ask for VDM reservation */
2890 UseVdmReserve = TRUE;
2891
2892 /* Close the current handle */
2893 NtClose(SectionHandle);
2894 SectionHandle = NULL;
2895
2896 /* Don't query the section later */
2897 QuerySection = FALSE;
2898 }
2899 }
2900
2901 /* Did we already do these checks? */
2902 if (!SkipSaferAndAppCompat)
2903 {
2904 /* Is everything OK so far, OR do we have an non-MZ, non-DOS app? */
2905 if ((NT_SUCCESS(Status)) ||
2907 !(BaseIsDosApplication(&PathName, Status))))
2908 {
2909 /* Clear the machine type in case of failure */
2910 ImageMachine = 0;
2911
2912 /* Clean any app compat data that may have accumulated */
2913 BasepFreeAppCompatData(AppCompatData, AppCompatSxsData);
2914 AppCompatData = NULL;
2915 AppCompatSxsData = NULL;
2916
2917 /* Do we have a section? */
2918 if (SectionHandle)
2919 {
2920 /* Have we already queried it? */
2921 if (QuerySection)
2922 {
2923 /* Nothing to do */
2924 AppCompatStatus = STATUS_SUCCESS;
2925 }
2926 else
2927 {
2928 /* Get some information about the executable */
2929 AppCompatStatus = NtQuerySection(SectionHandle,
2931 &ImageInformation,
2932 sizeof(ImageInformation),
2933 NULL);
2934 }
2935
2936 /* Do we have section information now? */
2937 if (NT_SUCCESS(AppCompatStatus))
2938 {
2939 /* Don't ask for it again, save the machine type */
2940 QuerySection = TRUE;
2941 ImageMachine = ImageInformation.Machine;
2942 }
2943 }
2944
2945 /* Is there a reason/Shim we shouldn't run this application? */
2946 AppCompatStatus = BasepCheckBadapp(FileHandle,
2947 FreeBuffer,
2948 lpEnvironment,
2949 ImageMachine,
2950 &AppCompatData,
2951 &AppCompatDataSize,
2952 &AppCompatSxsData,
2953 &AppCompatSxsDataSize,
2954 &FusionFlags);
2955 if (!NT_SUCCESS(AppCompatStatus))
2956 {
2957 /* This is usually the status we get back */
2958 DPRINT1("App compat launch failure: %lx\n", AppCompatStatus);
2959 if (AppCompatStatus == STATUS_ACCESS_DENIED)
2960 {
2961 /* Convert it to something more Win32-specific */
2963 }
2964 else
2965 {
2966 /* Some other error */
2967 BaseSetLastNTError(AppCompatStatus);
2968 }
2969
2970 /* Did we have a section? */
2971 if (SectionHandle)
2972 {
2973 /* Clean it up */
2974 NtClose(SectionHandle);
2975 SectionHandle = NULL;
2976 }
2977
2978 /* Fail the call */
2979 Result = FALSE;
2980 goto Quickie;
2981 }
2982 }
2983 }
2984
2985 //ASSERT((dwFusionFlags & ~SXS_APPCOMPACT_FLAG_APP_RUNNING_SAFEMODE) == 0);
2986
2987 /* Have we already done, and do we need to do, SRP (WinSafer) checks? */
2988 if (!(SkipSaferAndAppCompat) &&
2989 ~(dwCreationFlags & CREATE_PRESERVE_CODE_AUTHZ_LEVEL))
2990 {
2991 /* Assume yes */
2992 SaferNeeded = TRUE;
2993 switch (Status)
2994 {
2999 /* For all DOS, 16-bit, OS/2 images, we do*/
3000 break;
3001
3003 /* For invalid files, we don't, unless it's a .BAT file */
3004 if (BaseIsDosApplication(&PathName, Status)) break;
3005
3006 default:
3007 /* Any other error codes we also don't */
3008 if (!NT_SUCCESS(Status))
3009 {
3010 SaferNeeded = FALSE;
3011 }
3012
3013 /* But for success, we do */
3014 break;
3015 }
3016
3017 /* Okay, so what did the checks above result in? */
3018 if (SaferNeeded)
3019 {
3020 /* We have to call into the WinSafer library and actually check */
3022 (LPWSTR)lpApplicationName,
3023 FileHandle,
3024 &InJob,
3025 &TokenHandle,
3026 &JobHandle);
3027 if (SaferStatus == 0xFFFFFFFF)
3028 {
3029 /* Back in 2003, they didn't have an NTSTATUS for this... */
3030 DPRINT1("WinSafer blocking process launch\n");
3032 Result = FALSE;
3033 goto Quickie;
3034 }
3035
3036 /* Other status codes are not-Safer related, just convert them */
3037 if (!NT_SUCCESS(SaferStatus))
3038 {
3039 DPRINT1("Error checking WinSafer: %lx\n", SaferStatus);
3040 BaseSetLastNTError(SaferStatus);
3041 Result = FALSE;
3042 goto Quickie;
3043 }
3044 }
3045 }
3046
3047 /* The last step is to figure out why the section object was not created */
3048 switch (Status)
3049 {
3051 {
3052 /* 16-bit binary. Should we use WOW or does the caller force VDM? */
3053 if (!(dwCreationFlags & CREATE_FORCEDOS))
3054 {
3055 /* Remember that we're launching WOW */
3056 IsWowApp = TRUE;
3057
3058 /* Create the VDM environment, it's valid for WOW too */
3059 Result = BaseCreateVDMEnvironment(lpEnvironment,
3060 &VdmAnsiEnv,
3061 &VdmUnicodeEnv);
3062 if (!Result)
3063 {
3064 DPRINT1("VDM environment for WOW app failed\n");
3065 goto Quickie;
3066 }
3067
3068 /* We're going to try this twice, so do a loop */
3069 while (TRUE)
3070 {
3071 /* Pick which kind of WOW mode we want to run in */
3072 VdmBinaryType = (dwCreationFlags &
3075
3076 /* Get all the VDM settings and current status */
3077 Status = BaseCheckVDM(VdmBinaryType,
3078 lpApplicationName,
3079 lpCommandLine,
3080 lpCurrentDirectory,
3081 &VdmAnsiEnv,
3082 &CsrMsg[1],
3083 &VdmTask,
3084 dwCreationFlags,
3085 &StartupInfo,
3086 hUserToken);
3087
3088 /* If it worked, no need to try again */
3089 if (NT_SUCCESS(Status)) break;
3090
3091 /* Check if it's disallowed or if it's our second time */
3093 if ((Status == STATUS_VDM_DISALLOWED) ||
3094 (VdmBinaryType == BINARY_TYPE_SEPARATE_WOW) ||
3096 {
3097 /* Fail the call -- we won't try again */
3098 DPRINT1("VDM message failure for WOW: %lx\n", Status);
3099 Result = FALSE;
3100 goto Quickie;
3101 }
3102
3103 /* Try one more time, but with a separate WOW instance */
3104 dwCreationFlags |= CREATE_SEPARATE_WOW_VDM;
3105 }
3106
3107 /* Check which VDM state we're currently in */
3108 switch (CheckVdmMsg->VDMState & (VDM_NOT_LOADED |
3110 VDM_READY))
3111 {
3112 case VDM_NOT_LOADED:
3113 /* VDM is not fully loaded, so not that much to undo */
3114 VdmUndoLevel = VDM_UNDO_PARTIAL;
3115
3116 /* Reset VDM reserve if needed */
3117 if (UseVdmReserve) VdmReserve = 1;
3118
3119 /* Get the required parameters and names for launch */
3120 Result = BaseGetVdmConfigInfo(lpCommandLine,
3121 VdmTask,
3122 VdmBinaryType,
3123 &VdmString,
3124 &VdmReserve);
3125 if (!Result)
3126 {
3127 DPRINT1("VDM Configuration failed for WOW\n");
3129 goto Quickie;
3130 }
3131
3132 /* Update the command-line with the VDM one instead */
3133 lpCommandLine = VdmString.Buffer;
3134 lpApplicationName = NULL;
3135
3136 /* We don't want a console, detachment, nor a window */
3137 dwCreationFlags |= CREATE_NO_WINDOW;
3138 dwCreationFlags &= ~(CREATE_NEW_CONSOLE | DETACHED_PROCESS);
3139
3140 /* Force feedback on */
3141 StartupInfo.dwFlags |= STARTF_FORCEONFEEDBACK;
3142 break;
3143
3144
3145 case VDM_READY:
3146 /* VDM is ready, so we have to undo everything */
3147 VdmUndoLevel = VDM_UNDO_REUSE;
3148
3149 /* Check if CSRSS wants us to wait on VDM */
3150 VdmWaitObject = CheckVdmMsg->WaitObjectForParent;
3151 break;
3152
3153 case VDM_NOT_READY:
3154 /* Something is wrong with VDM, we'll fail the call */
3155 DPRINT1("VDM is not ready for WOW\n");
3157 Result = FALSE;
3158 goto Quickie;
3159
3160 default:
3161 break;
3162 }
3163
3164 /* Since to get NULL, we allocate from 0x1, account for this */
3165 VdmReserve--;
3166
3167 /* This implies VDM is ready, so skip everything else */
3168 if (VdmWaitObject) goto VdmShortCircuit;
3169
3170 /* Don't inherit handles since we're doing VDM now */
3171 bInheritHandles = FALSE;
3172
3173 /* Had the user passed in environment? If so, destroy it */
3174 if ((lpEnvironment) &&
3175 !(dwCreationFlags & CREATE_UNICODE_ENVIRONMENT))
3176 {
3177 RtlDestroyEnvironment(lpEnvironment);
3178 }
3179
3180 /* We've already done all these checks, don't do them again */
3181 SkipSaferAndAppCompat = TRUE;
3182 goto AppNameRetry;
3183 }
3184
3185 // There is no break here on purpose, so FORCEDOS drops down!
3186 }
3187
3191 {
3192 /* We're launching an executable application */
3193 BinarySubType = BINARY_TYPE_EXE;
3194
3195 /* We can drop here from other "cases" above too, so check */
3198 (BinarySubType = BaseIsDosApplication(&PathName, Status)))
3199 {
3200 /* We're launching a DOS application */
3201 VdmBinaryType = BINARY_TYPE_DOS;
3202
3203 /* Based on the caller environment, create a VDM one */
3204 Result = BaseCreateVDMEnvironment(lpEnvironment,
3205 &VdmAnsiEnv,
3206 &VdmUnicodeEnv);
3207 if (!Result)
3208 {
3209 DPRINT1("VDM environment for DOS failed\n");
3210 goto Quickie;
3211 }
3212
3213 /* Check the current state of the VDM subsystem */
3214 Status = BaseCheckVDM(VdmBinaryType | BinarySubType,
3215 lpApplicationName,
3216 lpCommandLine,
3217 lpCurrentDirectory,
3218 &VdmAnsiEnv,
3219 &CsrMsg[1],
3220 &VdmTask,
3221 dwCreationFlags,
3222 &StartupInfo,
3223 NULL);
3224 if (!NT_SUCCESS(Status))
3225 {
3226 /* Failed to inquire about VDM, fail the call */
3227 DPRINT1("VDM message failure for DOS: %lx\n", Status);
3229 Result = FALSE;
3230 goto Quickie;
3231 };
3232
3233 /* Handle possible VDM states */
3234 switch (CheckVdmMsg->VDMState & (VDM_NOT_LOADED |
3236 VDM_READY))
3237 {
3238 case VDM_NOT_LOADED:
3239 /* If VDM is not loaded, we'll do a partial undo */
3240 VdmUndoLevel = VDM_UNDO_PARTIAL;
3241
3242 /* A VDM process can't also be detached, so fail */
3243 if (dwCreationFlags & DETACHED_PROCESS)
3244 {
3245 DPRINT1("Detached process but no VDM, not allowed\n");
3247 return FALSE;
3248 }
3249
3250 /* Get the required parameters and names for launch */
3251 Result = BaseGetVdmConfigInfo(lpCommandLine,
3252 VdmTask,
3253 VdmBinaryType,
3254 &VdmString,
3255 &VdmReserve);
3256 if (!Result)
3257 {
3258 DPRINT1("VDM Configuration failed for DOS\n");
3260 goto Quickie;
3261 }
3262
3263 /* Update the command-line to launch VDM instead */
3264 lpCommandLine = VdmString.Buffer;
3265 lpApplicationName = NULL;
3266 break;
3267
3268 case VDM_READY:
3269 /* VDM is ready, so we have to undo everything */
3270 VdmUndoLevel = VDM_UNDO_REUSE;
3271
3272 /* Check if CSRSS wants us to wait on VDM */
3273 VdmWaitObject = CheckVdmMsg->WaitObjectForParent;
3274 break;
3275
3276 case VDM_NOT_READY:
3277 /* Something is wrong with VDM, we'll fail the call */
3278 DPRINT1("VDM is not ready for DOS\n");
3280 Result = FALSE;
3281 goto Quickie;
3282
3283 default:
3284 break;
3285 }
3286
3287 /* Since to get NULL, we allocate from 0x1, account for this */
3288 VdmReserve--;
3289
3290 /* This implies VDM is ready, so skip everything else */
3291 if (VdmWaitObject) goto VdmShortCircuit;
3292
3293 /* Don't inherit handles since we're doing VDM now */
3294 bInheritHandles = FALSE;
3295
3296 /* Had the user passed in environment? If so, destroy it */
3297 if ((lpEnvironment) &&
3298 !(dwCreationFlags & CREATE_UNICODE_ENVIRONMENT))
3299 {
3300 RtlDestroyEnvironment(lpEnvironment);
3301 }
3302
3303 /* Use our VDM Unicode environment instead */
3304 lpEnvironment = VdmUnicodeEnv.Buffer;
3305 }
3306 else
3307 {
3308 /* It's a batch file, get the extension */
3309 ExtBuffer = &PathName.Buffer[PathName.Length / sizeof(WCHAR) - 4];
3310
3311 /* Make sure the extensions are correct */
3312 if ((PathName.Length < (4 * sizeof(WCHAR))) ||
3313 ((_wcsnicmp(ExtBuffer, L".bat", 4)) &&
3314 (_wcsnicmp(ExtBuffer, L".cmd", 4))))
3315 {
3316 DPRINT1("'%wZ': Invalid EXE, and not a batch or script file\n", &PathName);
3318 Result = FALSE;
3319 goto Quickie;
3320 }
3321
3322 /* Check if we need to account for quotes around the path */
3323 CmdQuoteLength = CmdLineIsAppName || HasQuotes;
3324 if (!CmdLineIsAppName)
3325 {
3326 if (HasQuotes) CmdQuoteLength++;
3327 }
3328 else
3329 {
3330 CmdQuoteLength++;
3331 }
3332
3333 /* Calculate the length of the command line */
3334 CmdLineLength = wcslen(lpCommandLine);
3335 CmdLineLength += wcslen(CMD_STRING);
3336 CmdLineLength += CmdQuoteLength + sizeof(ANSI_NULL);
3337 CmdLineLength *= sizeof(WCHAR);
3338
3339 /* Allocate space for the new command line */
3340 AnsiCmdCommand = RtlAllocateHeap(RtlGetProcessHeap(),
3341 0,
3342 CmdLineLength);
3343 if (!AnsiCmdCommand)
3344 {
3346 Result = FALSE;
3347 goto Quickie;
3348 }
3349
3350 /* Build it */
3351 wcscpy(AnsiCmdCommand, CMD_STRING);
3352 if ((CmdLineIsAppName) || (HasQuotes))
3353 {
3354 wcscat(AnsiCmdCommand, L"\"");
3355 }
3356 wcscat(AnsiCmdCommand, lpCommandLine);
3357 if ((CmdLineIsAppName) || (HasQuotes))
3358 {
3359 wcscat(AnsiCmdCommand, L"\"");
3360 }
3361
3362 /* Create it as a Unicode String */
3363 RtlInitUnicodeString(&DebuggerString, AnsiCmdCommand);
3364
3365 /* Set the command line to this */
3366 lpCommandLine = DebuggerString.Buffer;
3367 lpApplicationName = NULL;
3368 DPRINT1("Retrying with: %S\n", lpCommandLine);
3369 }
3370
3371 /* We've already done all these checks, don't do them again */
3372 SkipSaferAndAppCompat = TRUE;
3373 goto AppNameRetry;
3374 }
3375
3377 {
3378 /* 64-bit binaries are not allowed to run on 32-bit ReactOS */
3379 DPRINT1("64-bit binary, failing\n");
3381 Result = FALSE;
3382 goto Quickie;
3383 }
3384
3386 {
3387 /* Set the correct last error for this */
3388 DPRINT1("File is offline, failing\n");
3390 break;
3391 }
3392
3393 default:
3394 {
3395 /* Any other error, convert it to a generic Win32 error */
3396 if (!NT_SUCCESS(Status))
3397 {
3398 DPRINT1("Failed to create section: %lx\n", Status);
3400 Result = FALSE;
3401 goto Quickie;
3402 }
3403
3404 /* Otherwise, this must be success */
3406 break;
3407 }
3408 }
3409
3410 /* Is this not a WOW application, but a WOW32 VDM was requested for it? */
3411 if (!(IsWowApp) && (dwCreationFlags & CREATE_SEPARATE_WOW_VDM))
3412 {
3413 /* Ignore the nonsensical request */
3414 dwCreationFlags &= ~CREATE_SEPARATE_WOW_VDM;
3415 }
3416
3417 /* Did we already check information for the section? */
3418 if (!QuerySection)
3419 {
3420 /* Get some information about the executable */
3421 Status = NtQuerySection(SectionHandle,
3423 &ImageInformation,
3424 sizeof(ImageInformation),
3425 NULL);
3426 if (!NT_SUCCESS(Status))
3427 {
3428 /* We failed, bail out */
3429 DPRINT1("Section query failed\n");
3431 Result = FALSE;
3432 goto Quickie;
3433 }
3434
3435 /* Don't check this later */
3436 QuerySection = TRUE;
3437 }
3438
3439 /* Check if this was linked as a DLL */
3440 if (ImageInformation.ImageCharacteristics & IMAGE_FILE_DLL)
3441 {
3442 /* These aren't valid images to try to execute! */
3443 DPRINT1("Trying to launch a DLL, failing\n");
3445 Result = FALSE;
3446 goto Quickie;
3447 }
3448
3449 /* Don't let callers pass in this flag -- we'll only get it from IFEO */
3450 Flags &= ~PROCESS_CREATE_FLAGS_LARGE_PAGES;
3451
3452 /* Clear the IFEO-missing flag, before we know for sure... */
3453 ParameterFlags &= ~2;
3454
3455 /* If the process is being debugged, only read IFEO if the PEB says so */
3456 if (!(dwCreationFlags & (DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS)) ||
3458 {
3459 /* Let's do this! Attempt to open IFEO */
3460 IFEOStatus = LdrOpenImageFileOptionsKey(&PathName, 0, &KeyHandle);
3461 if (!NT_SUCCESS(IFEOStatus))
3462 {
3463 /* We failed, set the flag so we store this in the parameters */
3464 if (IFEOStatus == STATUS_OBJECT_NAME_NOT_FOUND) ParameterFlags |= 2;
3465 }
3466 else
3467 {
3468 /* Was this our first time going through this path? */
3469 if (!DebuggerCmdLine)
3470 {
3471 /* Allocate a buffer for the debugger path */
3472 DebuggerCmdLine = RtlAllocateHeap(RtlGetProcessHeap(),
3473 0,
3474 MAX_PATH * sizeof(WCHAR));
3475 if (!DebuggerCmdLine)
3476 {
3477 /* Close IFEO on failure */
3478 IFEOStatus = NtClose(KeyHandle);
3479 ASSERT(NT_SUCCESS(IFEOStatus));
3480
3481 /* Fail the call */
3483 Result = FALSE;
3484 goto Quickie;
3485 }
3486 }
3487
3488 /* Now query for the debugger */
3490 L"Debugger",
3491 REG_SZ,
3492 DebuggerCmdLine,
3493 MAX_PATH * sizeof(WCHAR),
3494 &ResultSize);
3495 if (!(NT_SUCCESS(IFEOStatus)) ||
3496 (ResultSize < sizeof(WCHAR)) ||
3497 (DebuggerCmdLine[0] == UNICODE_NULL))
3498 {
3499 /* If it's not there, or too small, or invalid, ignore it */
3500 RtlFreeHeap(RtlGetProcessHeap(), 0, DebuggerCmdLine);
3501 DebuggerCmdLine = NULL;
3502 }
3503
3504 /* Also query if we should map with large pages */
3506 L"UseLargePages",
3507 REG_DWORD,
3508 &UseLargePages,
3509 sizeof(UseLargePages),
3510 NULL);
3511 if ((NT_SUCCESS(IFEOStatus)) && (UseLargePages))
3512 {
3513 /* Do it! This is the only way this flag can be set */
3515 }
3516
3517 /* We're done with IFEO, can close it now */
3518 IFEOStatus = NtClose(KeyHandle);
3519 ASSERT(NT_SUCCESS(IFEOStatus));
3520 }
3521 }
3522
3523 /* Make sure the image was compiled for this processor */
3524 if ((ImageInformation.Machine < SharedUserData->ImageNumberLow) ||
3525 (ImageInformation.Machine > SharedUserData->ImageNumberHigh))
3526 {
3527 /* It was not -- raise a hard error */
3528 ErrorResponse = ResponseOk;
3529 ErrorParameters[0] = (ULONG_PTR)&PathName;
3531 1,
3532 1,
3533 ErrorParameters,
3534 OptionOk,
3535 &ErrorResponse);
3537 {
3538 /* If it's really old, return this error */
3540 }
3541 else
3542 {
3543 /* Otherwise, return a more modern error */
3545 }
3546
3547 /* Go to the failure path */
3548 DPRINT1("Invalid image architecture: %lx\n", ImageInformation.Machine);
3549 Result = FALSE;
3550 goto Quickie;
3551 }
3552
3553 /* Check if this isn't a Windows image */
3554 if ((ImageInformation.SubSystemType != IMAGE_SUBSYSTEM_WINDOWS_GUI) &&
3555 (ImageInformation.SubSystemType != IMAGE_SUBSYSTEM_WINDOWS_CUI))
3556 {
3557 /* Get rid of section-related information since we'll retry */
3558 NtClose(SectionHandle);
3559 SectionHandle = NULL;
3560 QuerySection = FALSE;
3561
3562 /* The only other non-Windows image type we support here is POSIX */
3563 if (ImageInformation.SubSystemType != IMAGE_SUBSYSTEM_POSIX_CUI)
3564 {
3565 /* Bail out if it's something else */
3567 Result = FALSE;
3568 goto Quickie;
3569 }
3570
3571 /* Now build the command-line to have posix launch this image */
3572 Result = BuildSubSysCommandLine(L"POSIX /P ",
3573 lpApplicationName,
3574 lpCommandLine,
3575 &DebuggerString);
3576 if (!Result)
3577 {
3578 /* Bail out if that failed */
3579 DPRINT1("Subsystem command line failed\n");
3580 goto Quickie;
3581 }
3582
3583 /* And re-try launching the process, with the new command-line now */
3584 lpCommandLine = DebuggerString.Buffer;
3585 lpApplicationName = NULL;
3586
3587 /* We've already done all these checks, don't do them again */
3588 SkipSaferAndAppCompat = TRUE;
3589 DPRINT1("Retrying with: %S\n", lpCommandLine);
3590 goto AppNameRetry;
3591 }
3592
3593 /* Was this image built for a version of Windows whose images we can run? */
3595 ImageInformation.SubSystemMinorVersion);
3596 if (!Result)
3597 {
3598 /* It was not, bail out */
3599 DPRINT1("Invalid subsystem version: %hu.%hu\n",
3600 ImageInformation.SubSystemMajorVersion,
3601 ImageInformation.SubSystemMinorVersion);
3603 goto Quickie;
3604 }
3605
3606 /* Check if there is a debugger associated with the application */
3607 if (DebuggerCmdLine)
3608 {
3609 /* Get the length of the command line */
3610 n = wcslen(lpCommandLine);
3611 if (!n)
3612 {
3613 /* There's no command line, use the application name instead */
3614 lpCommandLine = (LPWSTR)lpApplicationName;
3615 n = wcslen(lpCommandLine);
3616 }
3617
3618 /* Protect against overflow */
3620 {
3622 Result = FALSE;
3623 goto Quickie;
3624 }
3625
3626 /* Now add the length of the debugger command-line */
3627 n += wcslen(DebuggerCmdLine);
3628
3629 /* Again make sure we don't overflow */
3631 {
3633 Result = FALSE;
3634 goto Quickie;
3635 }
3636
3637 /* Account for the quotes and space between the two */
3638 n += sizeof("\" \"") - sizeof(ANSI_NULL);
3639
3640 /* Convert to bytes, and make sure we don't overflow */
3641 n *= sizeof(WCHAR);
3643 {
3645 Result = FALSE;
3646 goto Quickie;
3647 }
3648
3649 /* Allocate space for the string */
3650 DebuggerString.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, n);
3651 if (!DebuggerString.Buffer)
3652 {
3654 Result = FALSE;
3655 goto Quickie;
3656 }
3657
3658 /* Set the length */
3659 RtlInitEmptyUnicodeString(&DebuggerString,
3660 DebuggerString.Buffer,
3661 (USHORT)n);
3662
3663 /* Now perform the command line creation */
3664 ImageDbgStatus = RtlAppendUnicodeToString(&DebuggerString,
3665 DebuggerCmdLine);
3666 ASSERT(NT_SUCCESS(ImageDbgStatus));
3667 ImageDbgStatus = RtlAppendUnicodeToString(&DebuggerString, L" ");
3668 ASSERT(NT_SUCCESS(ImageDbgStatus));
3669 ImageDbgStatus = RtlAppendUnicodeToString(&DebuggerString, lpCommandLine);
3670 ASSERT(NT_SUCCESS(ImageDbgStatus));
3671
3672 /* Make sure it all looks nice */
3673 DbgPrint("BASE: Calling debugger with '%wZ'\n", &DebuggerString);
3674
3675 /* Update the command line and application name */
3676 lpCommandLine = DebuggerString.Buffer;
3677 lpApplicationName = NULL;
3678
3679 /* Close all temporary state */
3680 NtClose(SectionHandle);
3681 SectionHandle = NULL;
3682 QuerySection = FALSE;
3683
3684 /* Free all temporary memory */
3685 RtlFreeHeap(RtlGetProcessHeap(), 0, NameBuffer);
3686 NameBuffer = NULL;
3687 RtlFreeHeap(RtlGetProcessHeap(), 0, FreeBuffer);
3688 FreeBuffer = NULL;
3689 RtlFreeHeap(RtlGetProcessHeap(), 0, DebuggerCmdLine);
3690 DebuggerCmdLine = NULL;
3691 DPRINT1("Retrying with: %S\n", lpCommandLine);
3692 goto AppNameRetry;
3693 }
3694
3695 /* Initialize the process object attributes */
3696 ObjectAttributes = BaseFormatObjectAttributes(&LocalObjectAttributes,
3697 lpProcessAttributes,
3698 NULL);
3699 if ((hUserToken) && (lpProcessAttributes))
3700 {
3701 /* Augment them with information from the user */
3702
3703 LocalProcessAttributes = *lpProcessAttributes;
3704 LocalProcessAttributes.lpSecurityDescriptor = NULL;
3705 ObjectAttributes = BaseFormatObjectAttributes(&LocalObjectAttributes,
3706 &LocalProcessAttributes,
3707 NULL);
3708 }
3709
3710 /* CREATE_BREAKAWAY_FROM_JOB allows the child process to break
3711 * away from the job associated with the calling process */
3712 if (dwCreationFlags & CREATE_BREAKAWAY_FROM_JOB)
3713 {
3715 }
3716
3717 /* Check if we're going to be debugged */
3718 if (dwCreationFlags & (DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS))
3719 {
3720 /* Connect to DbgUi */
3722 if (!NT_SUCCESS(Status))
3723 {
3724 DPRINT1("Failed to connect to DbgUI!\n");
3726 Result = FALSE;
3727 goto Quickie;
3728 }
3729
3730 /* Get the debug object */
3731 DebugHandle = DbgUiGetThreadDebugObject();
3732
3733 /* Check if only this process will be debugged */
3734 if (dwCreationFlags & DEBUG_ONLY_THIS_PROCESS)
3735 {
3736 /* Set process flag */
3738 }
3739 }
3740
3741 /* Set inherit flag */
3742 if (bInheritHandles) Flags |= PROCESS_CREATE_FLAGS_INHERIT_HANDLES;
3743
3744 /* Check if the process should be created with large pages */
3745 HavePrivilege = FALSE;
3746 PrivilegeState = NULL;
3748 {
3749 /* Acquire the required privilege so that the kernel won't fail the call */
3750 PrivilegeValue = SE_LOCK_MEMORY_PRIVILEGE;
3751 Status = RtlAcquirePrivilege(&PrivilegeValue, 1, 0, &PrivilegeState);
3752 if (NT_SUCCESS(Status))
3753 {
3754 /* Remember to release it later */
3755 HavePrivilege = TRUE;
3756 }
3757 }
3758
3759 /* Save the current TIB value since kernel overwrites it to store PEB */
3760 TibValue = Teb->NtTib.ArbitraryUserPointer;
3761
3762 /* Tell the kernel to create the process */
3767 Flags,
3768 SectionHandle,
3769 DebugHandle,
3770 NULL,
3771 InJob);
3772
3773 /* Load the PEB address from the hacky location where the kernel stores it */
3774 RemotePeb = Teb->NtTib.ArbitraryUserPointer;
3775
3776 /* And restore the old TIB value */
3777 Teb->NtTib.ArbitraryUserPointer = TibValue;
3778
3779 /* Release the large page privilege if we had acquired it */
3780 if (HavePrivilege) RtlReleasePrivilege(PrivilegeState);
3781
3782 /* And now check if the kernel failed to create the process */
3783 if (!NT_SUCCESS(Status))
3784 {
3785 /* Go to failure path */
3786 DPRINT1("Failed to create process: %lx\n", Status);
3788 Result = FALSE;
3789 goto Quickie;
3790 }
3791
3792 /* Check if there is a priority class to set */
3793 if (PriorityClass.PriorityClass)
3794 {
3795 /* Reset current privilege state */
3796 RealTimePrivilegeState = NULL;
3797
3798 /* Is realtime priority being requested? */
3800 {
3801 /* Check if the caller has real-time access, and enable it if so */
3802 RealTimePrivilegeState = BasepIsRealtimeAllowed(TRUE);
3803 }
3804
3805 /* Set the new priority class and release the privilege */
3808 &PriorityClass,
3809 sizeof(PROCESS_PRIORITY_CLASS));
3810 if (RealTimePrivilegeState) RtlReleasePrivilege(RealTimePrivilegeState);
3811
3812 /* Check if we failed to set the priority class */
3813 if (!NT_SUCCESS(Status))
3814 {
3815 /* Bail out on failure */
3816 DPRINT1("Failed to set priority class: %lx\n", Status);
3818 Result = FALSE;
3819 goto Quickie;
3820 }
3821 }
3822
3823 /* Check if the caller wants the default error mode */
3824 if (dwCreationFlags & CREATE_DEFAULT_ERROR_MODE)
3825 {
3826 /* Set Error Mode to only fail on critical errors */
3827 HardErrorMode = SEM_FAILCRITICALERRORS;
3830 &HardErrorMode,
3831 sizeof(ULONG));
3832 }
3833
3834 /* Check if this was a VDM binary */
3835 if (VdmBinaryType)
3836 {
3837 /* Update VDM by telling it the process has now been created */
3838 VdmWaitObject = ProcessHandle;
3840 &VdmWaitObject,
3841 VdmTask,
3842 VdmBinaryType);
3843
3844 if (!Result)
3845 {
3846 /* Bail out on failure */
3847 DPRINT1("Failed to update VDM with wait object\n");
3848 VdmWaitObject = NULL;
3849 goto Quickie;
3850 }
3851
3852 /* At this point, a failure means VDM has to undo all the state */
3853 VdmUndoLevel |= VDM_UNDO_FULL;
3854 }
3855
3856 /* Check if VDM needed reserved low-memory */
3857 if (VdmReserve)
3858 {
3859 /* Reserve the requested allocation */
3860 RegionSize = VdmReserve;
3862 &BaseAddress,
3863 0,
3864 &RegionSize,
3867 if (!NT_SUCCESS(Status))
3868 {
3869 /* Bail out on failure */
3870 DPRINT1("Failed to reserve memory for VDM: %lx\n", Status);
3872 Result = FALSE;
3873 goto Quickie;
3874 }
3875
3876 VdmReserve = (ULONG)RegionSize;
3877 }
3878
3879 /* Check if we've already queried information on the section */
3880 if (!QuerySection)
3881 {
3882 /* We haven't, so get some information about the executable */
3883 Status = NtQuerySection(SectionHandle,
3885 &ImageInformation,
3886 sizeof(ImageInformation),
3887 NULL);
3888 if (!NT_SUCCESS(Status))
3889 {
3890 /* Bail out on failure */
3891 DPRINT1("Failed to query section: %lx\n", Status);
3893 Result = FALSE;
3894 goto Quickie;
3895 }
3896
3897 /* If we encounter a restart, don't re-query this information again */
3898 QuerySection = TRUE;
3899 }
3900
3901 /* Do we need to apply SxS to this image? (On x86 this flag is set by PeFmtCreateSection) */
3903 {
3904 /* Too bad, we don't support this yet */
3905 DPRINT("Image should receive SxS Fusion Isolation\n");
3906 }
3907
3908 /* There's some SxS flag that we need to set if fusion flags have 1 set */
3909 if (FusionFlags & 1) CreateProcessMsg->Sxs.Flags |= 0x10;
3910
3911 /* Check if we have a current directory */
3912 if (lpCurrentDirectory)
3913 {
3914 /* Allocate a buffer so we can keep a Unicode copy */
3915 DPRINT("Current directory: %S\n", lpCurrentDirectory);
3916 CurrentDirectory = RtlAllocateHeap(RtlGetProcessHeap(),
3917 0,
3918 (MAX_PATH * sizeof(WCHAR)) +
3919 sizeof(UNICODE_NULL));
3920 if (!CurrentDirectory)
3921 {
3922 /* Bail out if this failed */
3924 Result = FALSE;
3925 goto Quickie;
3926 }
3927
3928 /* Get the length in Unicode */
3929 Length = GetFullPathNameW(lpCurrentDirectory,
3930 MAX_PATH,
3932 &FilePart);
3933 if (Length > MAX_PATH)
3934 {
3935 /* The directory is too long, so bail out */
3937 Result = FALSE;
3938 goto Quickie;
3939 }
3940
3941 /* Make sure the directory is actually valid */
3942 FileAttribs = GetFileAttributesW(CurrentDirectory);
3943 if ((FileAttribs == INVALID_FILE_ATTRIBUTES) ||
3944 !(FileAttribs & FILE_ATTRIBUTE_DIRECTORY))
3945 {
3946 /* It isn't, so bail out */
3947 DPRINT1("Current directory is invalid\n");
3949 Result = FALSE;
3950 goto Quickie;
3951 }
3952 }
3953
3954 /* Insert quotes if needed */
3955 if ((QuotesNeeded) || (CmdLineIsAppName))
3956 {
3957 /* Allocate our buffer, plus enough space for quotes and a NULL */
3958 QuotedCmdLine = RtlAllocateHeap(RtlGetProcessHeap(),
3959 0,
3960 (wcslen(lpCommandLine) * sizeof(WCHAR)) +
3961 (2 * sizeof(L'\"') + sizeof(UNICODE_NULL)));
3962 if (QuotedCmdLine)
3963 {
3964 /* Copy the first quote */
3965 wcscpy(QuotedCmdLine, L"\"");
3966
3967 /* Save the current null-character */
3968 if (QuotesNeeded)
3969 {
3970 SaveChar = *NullBuffer;
3971 *NullBuffer = UNICODE_NULL;
3972 }
3973
3974 /* Copy the command line and the final quote */
3975 wcscat(QuotedCmdLine, lpCommandLine);
3976 wcscat(QuotedCmdLine, L"\"");
3977
3978 /* Copy the null-char back */
3979 if (QuotesNeeded)
3980 {
3981 *NullBuffer = SaveChar;
3982 wcscat(QuotedCmdLine, NullBuffer);
3983 }
3984 }
3985 else
3986 {
3987 /* We can't put quotes around the thing, so try it anyway */
3988 if (QuotesNeeded) QuotesNeeded = FALSE;
3989 if (CmdLineIsAppName) CmdLineIsAppName = FALSE;
3990 }
3991 }
3992
3993 /* Use isolation if needed */
3994 if (CreateProcessMsg->Sxs.Flags & 1) ParameterFlags |= 1;
3995
3996 /* Set the new command-line if needed */
3997 if ((QuotesNeeded) || (CmdLineIsAppName)) lpCommandLine = QuotedCmdLine;
3998
3999 /* Call the helper function in charge of RTL_USER_PROCESS_PARAMETERS */
4000 Result = BasePushProcessParameters(ParameterFlags,
4002 RemotePeb,
4003 lpApplicationName,
4005 lpCommandLine,
4006 lpEnvironment,
4007 &StartupInfo,
4008 dwCreationFlags | NoWindow,
4009 bInheritHandles,
4010 IsWowApp ? IMAGE_SUBSYSTEM_WINDOWS_GUI: 0,
4011 AppCompatData,
4012 AppCompatDataSize);
4013 if (!Result)
4014 {
4015 /* The remote process would have an undefined state, so fail the call */
4016 DPRINT1("BasePushProcessParameters failed\n");
4017 goto Quickie;
4018 }
4019
4020 /* Free the VDM command line string as it's no longer needed */
4021 RtlFreeUnicodeString(&VdmString);
4022 VdmString.Buffer = NULL;
4023
4024 /* Non-VDM console applications usually inherit handles unless specified */
4025 if (!(VdmBinaryType) &&
4026 !(bInheritHandles) &&
4027 !(StartupInfo.dwFlags & STARTF_USESTDHANDLES) &&
4028 !(dwCreationFlags & (CREATE_NO_WINDOW |
4030 DETACHED_PROCESS)) &&
4031 (ImageInformation.SubSystemType == IMAGE_SUBSYSTEM_WINDOWS_CUI))
4032 {
4033 /* Get the remote parameters */
4035 &RemotePeb->ProcessParameters,
4036 &ProcessParameters,
4038 NULL);
4039 if (NT_SUCCESS(Status))
4040 {
4041 /* Duplicate standard input unless it's a console handle */
4043 {
4046 &ProcessParameters->StandardInput);
4047 }
4048
4049 /* Duplicate standard output unless it's a console handle */
4051 {
4054 &ProcessParameters->StandardOutput);
4055 }
4056
4057 /* Duplicate standard error unless it's a console handle */
4059 {
4062 &ProcessParameters->StandardError);
4063 }
4064 }
4065 }
4066
4067 /* Create the Thread's Stack */
4068 StackSize = max(256 * 1024, ImageInformation.MaximumStackSize);
4070 ImageInformation.CommittedStackSize,
4071 StackSize,
4072 &InitialTeb);
4073 if (!NT_SUCCESS(Status))
4074 {
4075 DPRINT1("Creating the thread stack failed: %lx\n", Status);
4077 Result = FALSE;
4078 goto Quickie;
4079 }
4080
4081 /* Create the Thread's Context */
4083 RemotePeb,
4084 ImageInformation.TransferAddress,
4085 InitialTeb.StackBase,
4086 0);
4087
4088 /* Convert the thread attributes */
4089 ObjectAttributes = BaseFormatObjectAttributes(&LocalObjectAttributes,
4090 lpThreadAttributes,
4091 NULL);
4092 if ((hUserToken) && (lpThreadAttributes))
4093 {
4094 /* If the caller specified a user token, zero the security descriptor */
4095 LocalThreadAttributes = *lpThreadAttributes;
4096 LocalThreadAttributes.lpSecurityDescriptor = NULL;
4097 ObjectAttributes = BaseFormatObjectAttributes(&LocalObjectAttributes,
4098 &LocalThreadAttributes,
4099 NULL);
4100 }
4101
4102 /* Create the Kernel Thread Object */
4103 Status = NtCreateThread(&ThreadHandle,
4107 &ClientId,
4108 &Context,
4109 &InitialTeb,
4110 TRUE);
4111 if (!NT_SUCCESS(Status))
4112 {
4113 /* A process is not allowed to exist without a main thread, so fail */
4114 DPRINT1("Creating the main thread failed: %lx\n", Status);
4116 Result = FALSE;
4117 goto Quickie;
4118 }
4119
4120 /* Begin filling out the CSRSS message, first with our IDs and handles */
4121 CreateProcessMsg->ProcessHandle = ProcessHandle;
4122 CreateProcessMsg->ThreadHandle = ThreadHandle;
4123 CreateProcessMsg->ClientId = ClientId;
4124
4125 /* Write the remote PEB address and clear it locally, we no longer use it */
4126 CreateProcessMsg->PebAddressNative = RemotePeb;
4127#ifdef _WIN64
4128 DPRINT("TODO: WOW64 is not supported yet\n");
4129 CreateProcessMsg->PebAddressWow64 = 0;
4130#else
4131 CreateProcessMsg->PebAddressWow64 = (ULONG)RemotePeb;
4132#endif
4133 RemotePeb = NULL;
4134
4135 /* Now check what kind of architecture this image was made for */
4136 switch (ImageInformation.Machine)
4137 {
4138 /* IA32, IA64 and AMD64 are supported in Server 2003 */
4141 break;
4144 break;
4147 break;
4148
4149 /* Anything else results in image unknown -- but no failure */
4150 default:
4151 DbgPrint("kernel32: No mapping for ImageInformation.Machine == %04x\n",
4152 ImageInformation.Machine);
4154 break;
4155 }
4156
4157 /* Write the input creation flags except any debugger-related flags */
4158 CreateProcessMsg->CreationFlags = dwCreationFlags &
4160
4161 /* CSRSS needs to know if this is a GUI app or not */
4162 if ((ImageInformation.SubSystemType == IMAGE_SUBSYSTEM_WINDOWS_GUI) ||
4163 (IsWowApp))
4164 {
4165 /*
4166 * For GUI apps we turn on the 2nd bit. This allow CSRSS server dlls
4167 * (basesrv in particular) to know whether or not this is a GUI or a
4168 * TUI application.
4169 */
4170 AddToHandle(CreateProcessMsg->ProcessHandle, 2);
4171
4172 /* Also check if the parent is also a GUI process */
4174 if ((NtHeaders) &&
4176 {
4177 /* Let it know that it should display the hourglass mouse cursor */
4178 AddToHandle(CreateProcessMsg->ProcessHandle, 1);
4179 }
4180 }
4181
4182 /* For all apps, if this flag is on, the hourglass mouse cursor is shown.
4183 * Likewise, the opposite holds as well, and no-feedback has precedence. */
4184 if (StartupInfo.dwFlags & STARTF_FORCEONFEEDBACK)
4185 {
4186 AddToHandle(CreateProcessMsg->ProcessHandle, 1);
4187 }
4188 if (StartupInfo.dwFlags & STARTF_FORCEOFFFEEDBACK)
4189 {
4190 RemoveFromHandle(CreateProcessMsg->ProcessHandle, 1);
4191 }
4192
4193 /* Also store which kind of VDM app (if any) this is */
4194 CreateProcessMsg->VdmBinaryType = VdmBinaryType;
4195
4196 /* And if it really is a VDM app... */
4197 if (VdmBinaryType)
4198 {
4199 /* Store the VDM console handle (none if inherited or WOW app) and the task ID */
4200 CreateProcessMsg->hVDM = VdmTask ? NULL : Peb->ProcessParameters->ConsoleHandle;
4201 CreateProcessMsg->VdmTask = VdmTask;
4202 }
4203 else if (VdmReserve)
4204 {
4205 /* Extended VDM, set a flag */
4206 CreateProcessMsg->VdmBinaryType |= BINARY_TYPE_WOW_EX;
4207 }
4208
4209 /* Check if there's side-by-side assembly data associated with the process */
4210 if (CreateProcessMsg->Sxs.Flags)
4211 {
4212 /* This should not happen in ReactOS yet */
4213 DPRINT1("This is an SxS Message -- should not happen yet\n");
4216 Result = FALSE;
4217 goto Quickie;
4218 }
4219
4220 /* We are finally ready to call CSRSS to tell it about our new process! */
4222 CaptureBuffer,
4225 sizeof(*CreateProcessMsg));
4226
4227 /* CSRSS has returned, free the capture buffer now if we had one */
4228 if (CaptureBuffer)
4229 {
4230 CsrFreeCaptureBuffer(CaptureBuffer);
4231 CaptureBuffer = NULL;
4232 }
4233
4234 /* Check if CSRSS failed to accept ownership of the new Windows process */
4235 if (!NT_SUCCESS(CsrMsg[0].Status))
4236 {
4237 /* Terminate the process and enter failure path with the CSRSS status */
4238 DPRINT1("Failed to tell csrss about new process\n");
4239 BaseSetLastNTError(CsrMsg[0].Status);
4241 Result = FALSE;
4242 goto Quickie;
4243 }
4244
4245 /* Check if we have a token due to Authz/Safer, not passed by the user */
4246 if ((TokenHandle) && !(hUserToken))
4247 {
4248 /* Replace the process and/or thread token with the one from Safer */
4251 ThreadHandle);
4252 if (!NT_SUCCESS(Status))
4253 {
4254 /* If this failed, kill the process and enter the failure path */
4255 DPRINT1("Failed to update process token: %lx\n", Status);
4258 Result = FALSE;
4259 goto Quickie;
4260 }
4261 }
4262
4263 /* Check if a job was associated with this process */
4264 if (JobHandle)
4265 {
4266 /* Bind the process and job together now */
4268 if (!NT_SUCCESS(Status))
4269 {
4270 /* Kill the process and enter the failure path if binding failed */
4271 DPRINT1("Failed to assign process to job: %lx\n", Status);
4274 Result = FALSE;
4275 goto Quickie;
4276 }
4277 }
4278
4279 /* Finally, resume the thread to actually get the process started */
4280 if (!(dwCreationFlags & CREATE_SUSPENDED))
4281 {
4282 NtResumeThread(ThreadHandle, &ResumeCount);
4283 }
4284
4285VdmShortCircuit:
4286 /* We made it this far, meaning we have a fully created process and thread */
4287 Result = TRUE;
4288
4289 /* Anyone doing a VDM undo should now undo everything, since we are done */
4290 if (VdmUndoLevel) VdmUndoLevel |= VDM_UNDO_COMPLETED;
4291
4292 /* Having a VDM wait object implies this must be a VDM process */
4293 if (VdmWaitObject)
4294 {
4295 /* Check if it's a 16-bit separate WOW process */
4296 if (VdmBinaryType == BINARY_TYPE_SEPARATE_WOW)
4297 {
4298 /* OR-in the special flag to indicate this, and return to caller */
4299 AddToHandle(VdmWaitObject, 2);
4300 lpProcessInformation->hProcess = VdmWaitObject;
4301
4302 /* Check if this was a re-used VDM */
4303 if (VdmUndoLevel & VDM_UNDO_REUSE)
4304 {
4305 /* No Client ID should be returned in this case */
4308 }
4309 }
4310 else
4311 {
4312 /* OR-in the special flag to indicate this is not a separate VDM,
4313 * and return the handle to the caller */
4314 AddToHandle(VdmWaitObject, 1);
4315 lpProcessInformation->hProcess = VdmWaitObject;
4316 }
4317
4318 /* Close the original process handle, since it's not needed for VDM */
4320 }
4321 else
4322 {
4323 /* This is a regular process, so return the real process handle */
4324 lpProcessInformation->hProcess = ProcessHandle;
4325 }
4326
4327 /* Return the rest of the process information based on what we have so far */
4328 lpProcessInformation->hThread = ThreadHandle;
4329 lpProcessInformation->dwProcessId = HandleToUlong(ClientId.UniqueProcess);
4330 lpProcessInformation->dwThreadId = HandleToUlong(ClientId.UniqueThread);
4331
4332 /* NULL these out here so we know to treat this as a success scenario */
4334 ThreadHandle = NULL;
4335
4336Quickie:
4337 /* Free the debugger command line if one was allocated */
4338 if (DebuggerCmdLine) RtlFreeHeap(RtlGetProcessHeap(), 0, DebuggerCmdLine);
4339
4340 /* Check if an SxS full path as queried */
4341 if (PathBuffer)
4342 {
4343 /* Reinitialize the executable path */
4344 RtlInitEmptyUnicodeString(&SxsWin32ExePath, NULL, 0);
4345 SxsWin32ExePath.Length = 0;
4346
4347 /* Free the path buffer */
4348 RtlFreeHeap(RtlGetProcessHeap(), 0, PathBuffer);
4349 }
4350
4351#if _SXS_SUPPORT_ENABLED_
4352 /* Check if this was a non-VDM process */
4353 if (!VdmBinaryType)
4354 {
4355 /* Then it must've had SxS data, so close the handles used for it */
4356 BasepSxsCloseHandles(&Handles);
4357 BasepSxsCloseHandles(&FileHandles);
4358
4359 /* Check if we built SxS byte buffers for this create process request */
4360 if (SxsConglomeratedBuffer)
4361 {
4362 /* Loop all of them */
4363 for (i = 0; i < 5; i++)
4364 {
4365 /* Check if this one was allocated */
4366 ThisBuffer = SxsStaticBuffers[i];
4367 if (ThisBuffer)
4368 {
4369 /* Get the underlying RTL_BUFFER structure */
4370 ByteBuffer = &ThisBuffer->ByteBuffer;
4371 if ((ThisBuffer != (PVOID)-8) && (ByteBuffer->Buffer))
4372 {
4373 /* Check if it was dynamic */
4374 if (ByteBuffer->Buffer != ByteBuffer->StaticBuffer)
4375 {
4376 /* Free it from the heap */
4377 FreeString.Buffer = (PWCHAR)ByteBuffer->Buffer;
4379 }
4380
4381 /* Reset the buffer to its static data */
4382 ByteBuffer->Buffer = ByteBuffer->StaticBuffer;
4383 ByteBuffer->Size = ByteBuffer->StaticSize;
4384 }
4385
4386 /* Reset the string to the static buffer */
4387 RtlInitEmptyUnicodeString(&ThisBuffer->String,
4388 (PWCHAR)ByteBuffer->StaticBuffer,
4389 ByteBuffer->StaticSize);
4390 if (ThisBuffer->String.Buffer)
4391 {
4392 /* Also NULL-terminate it */
4393 *ThisBuffer->String.Buffer = UNICODE_NULL;
4394 }
4395 }
4396 }
4397 }
4398 }
4399#endif
4400 /* Check if an environment was passed in */
4401 if ((lpEnvironment) && !(dwCreationFlags & CREATE_UNICODE_ENVIRONMENT))
4402 {
4403 /* Destroy it */
4404 RtlDestroyEnvironment(lpEnvironment);
4405
4406 /* If this was the VDM environment too, clear that as well */
4407 if (VdmUnicodeEnv.Buffer == lpEnvironment) VdmUnicodeEnv.Buffer = NULL;
4408 lpEnvironment = NULL;
4409 }
4410
4411 /* Unconditionally free all the name parsing buffers we always allocate */
4412 RtlFreeHeap(RtlGetProcessHeap(), 0, QuotedCmdLine);
4413 RtlFreeHeap(RtlGetProcessHeap(), 0, NameBuffer);
4414 RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentDirectory);
4415 RtlFreeHeap(RtlGetProcessHeap(), 0, FreeBuffer);
4416
4417 /* Close open file/section handles */
4419 if (SectionHandle) NtClose(SectionHandle);
4420
4421 /* If we have a thread handle, this was a failure path */
4422 if (ThreadHandle)
4423 {
4424 /* So kill the process and close the thread handle */
4426 NtClose(ThreadHandle);
4427 }
4428
4429 /* If we have a process handle, this was a failure path, so close it */
4431
4432 /* Thread/process handles, if any, are now processed. Now close this one. */
4433 if (JobHandle) NtClose(JobHandle);
4434
4435 /* Check if we had created a token */
4436 if (TokenHandle)
4437 {
4438 /* And if the user asked for one */
4439 if (hUserToken)
4440 {
4441 /* Then return it */
4442 *hNewToken = TokenHandle;
4443 }
4444 else
4445 {
4446 /* User didn't want it, so we used it temporarily -- close it */
4448 }
4449 }
4450
4451 /* Free any temporary app compatibility data, it's no longer needed */
4452 BasepFreeAppCompatData(AppCompatData, AppCompatSxsData);
4453
4454 /* Free a few strings. The API takes care of these possibly being NULL */
4455 RtlFreeUnicodeString(&VdmString);
4456 RtlFreeUnicodeString(&DebuggerString);
4457
4458 /* Check if we had built any sort of VDM environment */
4459 if ((VdmAnsiEnv.Buffer) || (VdmUnicodeEnv.Buffer))
4460 {
4461 /* Free it */
4462 BaseDestroyVDMEnvironment(&VdmAnsiEnv, &VdmUnicodeEnv);
4463 }
4464
4465 /* Check if this was any kind of VDM application that we ended up creating */
4466 if ((VdmUndoLevel) && (!(VdmUndoLevel & VDM_UNDO_COMPLETED)))
4467 {
4468 /* Send an undo */
4470 (PHANDLE)&VdmTask,
4471 VdmUndoLevel,
4472 VdmBinaryType);
4473
4474 /* And close whatever VDM handle we were using for notifications */
4475 if (VdmWaitObject) NtClose(VdmWaitObject);
4476 }
4477
4478 /* Check if we ended up here with an allocated search path, and free it */
4479 if (SearchPath) RtlFreeHeap(RtlGetProcessHeap(), 0, SearchPath);
4480
4481 /* Finally, return the API's result */
4482 return Result;
4483}
NTSTATUS NTAPI NtCreateSection(OUT PHANDLE SectionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER MaximumSize OPTIONAL, IN ULONG SectionPageProtection OPTIONAL, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL)
Definition: section.c:3090
static IN ULONG IN PWSTR OUT PCWSTR OUT PBOOLEAN OUT PATH_TYPE_AND_UNKNOWN * PathType
static ULONG StackSize
Definition: StackOverflow.c:21
NTSTATUS WINAPI BasepCheckBadapp(IN HANDLE FileHandle, IN PWCHAR ApplicationName, IN PWCHAR Environment, IN USHORT ExeType, IN PVOID *SdbQueryAppCompatData, IN PULONG SdbQueryAppCompatDataSize, IN PVOID *SxsData, IN PULONG SxsDataSize, OUT PULONG FusionFlags)
Definition: appcache.c:374
VOID WINAPI BasepFreeAppCompatData(IN PVOID AppCompatData, IN PVOID AppCompatSxsData)
Definition: appcache.c:444
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
HANDLE hUserToken
Definition: install.c:39
static DWORD ResumeCount
Definition: database.c:31
@ BasepCreateProcess
Definition: basemsg.h:21
#define BASESRV_SERVERDLL_INDEX
Definition: basemsg.h:15
#define HandleToUlong(h)
Definition: basetsd.h:73
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
_In_ PIO_STATUS_BLOCK IoStatusBlock
Definition: dispmprt.h:608
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245
#define CloseHandle
Definition: compat.h:739
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define RtlImageNtHeader
Definition: compat.h:806
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define FILE_SHARE_READ
Definition: compat.h:136
PBASE_STATIC_SERVER_DATA BaseStaticServerData
Definition: dllmain.c:19
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:636
LPWSTR WINAPI BaseComputeProcessExePath(IN LPWSTR FullPath)
Definition: path.c:405
DWORD WINAPI SearchPathW(IN LPCWSTR lpPath OPTIONAL, IN LPCWSTR lpFileName, IN LPCWSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart OPTIONAL)
Definition: path.c:1298
BOOLEAN WINAPI BasePushProcessParameters(IN ULONG ParameterFlags, IN HANDLE ProcessHandle, IN PPEB RemotePeb, IN LPCWSTR ApplicationPathName, IN LPWSTR lpCurrentDirectory, IN LPWSTR lpCommandLine, IN LPVOID lpEnvironment, IN LPSTARTUPINFOW StartupInfo, IN DWORD CreationFlags, IN BOOL InheritHandles, IN ULONG ImageSubsystem, IN PVOID AppCompatData, IN ULONG AppCompatDataSize)
Definition: proc.c:482
NTSTATUS WINAPI BasepCheckWebBladeHashes(IN HANDLE FileHandle)
Definition: proc.c:147
VOID WINAPI StuffStdHandle(IN HANDLE ProcessHandle, IN HANDLE StandardHandle, IN PHANDLE Address)
Definition: proc.c:55
BOOLEAN WINAPI BuildSubSysCommandLine(IN LPCWSTR SubsystemName, IN LPCWSTR ApplicationName, IN LPCWSTR CommandLine, OUT PUNICODE_STRING SubsysCommandLine)
Definition: proc.c:87
NTSTATUS WINAPI BasepIsProcessAllowed(IN LPWSTR ApplicationName)
Definition: proc.c:200
#define AddToHandle(x, y)
Definition: proc.c:2124
NTSTATUS WINAPI BasepReplaceProcessThreadTokens(IN HANDLE TokenHandle, IN HANDLE ProcessHandle, IN HANDLE ThreadHandle)
Definition: proc.c:352
VOID WINAPI BasepSxsCloseHandles(IN PBASE_MSG_SXS_HANDLES Handles)
Definition: proc.c:415
#define CMD_STRING
Definition: proc.c:49
#define RemoveFromHandle(x, y)
Definition: proc.c:2125
BOOLEAN WINAPI BasepIsImageVersionOk(IN ULONG ImageMajorVersion, IN ULONG ImageMinorVersion)
Definition: proc.c:121
NTSTATUS WINAPI BaseCreateStack(_In_ HANDLE hProcess, _In_opt_ SIZE_T StackCommit, _In_opt_ SIZE_T StackReserve, _Out_ PINITIAL_TEB InitialTeb)
Definition: utils.c:355
VOID WINAPI BaseInitializeContext(IN PCONTEXT Context, IN PVOID Parameter, IN PVOID StartAddress, IN PVOID StackAddress, IN ULONG ContextType)
Definition: utils.c:514
POBJECT_ATTRIBUTES WINAPI BaseFormatObjectAttributes(OUT POBJECT_ATTRIBUTES ObjectAttributes, IN PSECURITY_ATTRIBUTES SecurityAttributes OPTIONAL, IN PUNICODE_STRING ObjectName)
Definition: utils.c:305
NTSTATUS WINAPI BasepCheckWinSaferRestrictions(IN HANDLE UserToken, IN LPWSTR ApplicationName, IN HANDLE FileHandle, OUT PBOOLEAN InJob, OUT PHANDLE NewToken, OUT PHANDLE JobHandle)
Definition: utils.c:923
PVOID WINAPI BasepIsRealtimeAllowed(IN BOOLEAN Keep)
Definition: utils.c:666
ULONG WINAPI BaseIsDosApplication(IN PUNICODE_STRING PathName, IN NTSTATUS Status)
Definition: vdm.c:66
BOOL NTAPI BaseDestroyVDMEnvironment(IN PANSI_STRING AnsiEnv, IN PUNICODE_STRING UnicodeEnv)
Definition: vdm.c:1034
BOOL WINAPI BaseGetVdmConfigInfo(IN LPCWSTR CommandLineReserved, IN ULONG DosSeqId, IN ULONG BinaryType, IN PUNICODE_STRING CmdLineString, OUT PULONG VdmSize)
Definition: vdm.c:652
BOOL WINAPI BaseUpdateVDMEntry(IN ULONG UpdateIndex, IN OUT PHANDLE WaitHandle, IN ULONG IndexInfo, IN ULONG BinaryType)
Definition: vdm.c:542
BOOL NTAPI BaseCreateVDMEnvironment(IN PWCHAR lpEnvironment, OUT PANSI_STRING AnsiEnv, OUT PUNICODE_STRING UnicodeEnv)
Definition: vdm.c:744
NTSTATUS WINAPI BaseCheckVDM(IN ULONG BinaryType, IN PCWCH ApplicationName, IN PCWCH CommandLine, IN PCWCH CurrentDirectory, IN PANSI_STRING AnsiEnvironment, IN PBASE_API_MESSAGE ApiMessage, IN OUT PULONG iTask, IN DWORD CreationFlags, IN LPSTARTUPINFOW StartupInfo, IN HANDLE hUserToken OPTIONAL)
Definition: vdm.c:91
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2988
_ACRTIMP int __cdecl _wcsnicmp(const wchar_t *, const wchar_t *, size_t)
Definition: wcs.c:200
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
GLdouble n
Definition: glext.h:7729
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define DbgPrint
Definition: hal.h:12
NTSTATUS NTAPI NtRaiseHardError(IN NTSTATUS ErrorStatus, IN ULONG NumberOfParameters, IN ULONG UnicodeStringParameterMask, IN PULONG_PTR Parameters, IN ULONG ValidResponseOptions, OUT PULONG Response)
Definition: harderr.c:551
#define PROCESS_CREATE_FLAGS_BREAKAWAY
Definition: pstypes.h:87
#define PROCESS_PRIORITY_CLASS_IDLE
Definition: pstypes.h:103
#define PROCESS_CREATE_FLAGS_INHERIT_HANDLES
Definition: pstypes.h:89
#define PROCESS_PRIORITY_CLASS_INVALID
Definition: pstypes.h:102
#define PROCESS_PRIORITY_CLASS_NORMAL
Definition: pstypes.h:104
#define PROCESS_PRIORITY_CLASS_HIGH
Definition: pstypes.h:105
#define PROCESS_PRIORITY_CLASS_ABOVE_NORMAL
Definition: pstypes.h:108
#define PROCESS_CREATE_FLAGS_LARGE_PAGES
Definition: pstypes.h:91
#define PROCESS_PRIORITY_CLASS_BELOW_NORMAL
Definition: pstypes.h:107
#define PROCESS_PRIORITY_CLASS_REALTIME
Definition: pstypes.h:106
#define PROCESS_CREATE_FLAGS_NO_DEBUG_INHERIT
Definition: pstypes.h:88
#define NtCurrentTeb
#define REG_SZ
Definition: layer.c:22
NTSTATUS NTAPI LdrQueryImageFileKeyOption(_In_ HANDLE KeyHandle, _In_ PCWSTR ValueName, _In_ ULONG Type, _Out_ PVOID Buffer, _In_ ULONG BufferSize, _Out_opt_ PULONG ReturnedLength)
Definition: ldrinit.c:188
NTSTATUS NTAPI LdrOpenImageFileOptionsKey(_In_ PUNICODE_STRING SubKey, _In_ BOOLEAN Wow64, _Out_ PHANDLE NewKeyHandle)
Definition: ldrinit.c:115
#define PCHAR
Definition: match.c:90
PVOID PVOID PWCHAR PVOID USHORT PULONG PVOID PULONG PVOID PULONG PULONG FusionFlags
Definition: env.c:49
#define SE_LOCK_MEMORY_PRIVILEGE
Definition: security.c:558
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
@ OptionOk
Definition: extypes.h:187
@ ResponseOk
Definition: extypes.h:205
#define PROCESSOR_ARCHITECTURE_IA64
Definition: ketypes.h:111
#define PROCESSOR_ARCHITECTURE_UNKNOWN
Definition: ketypes.h:115
#define PROCESSOR_ARCHITECTURE_AMD64
Definition: ketypes.h:114
#define PROCESSOR_ARCHITECTURE_INTEL
Definition: ketypes.h:105
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize _Pre_valid_ PVOID * BaseAddress
Definition: mmfuncs.h:408
__kernel_entry _Inout_ _Inout_ PSIZE_T RegionSize
Definition: mmfuncs.h:176
#define SEC_IMAGE
Definition: mmtypes.h:97
@ SectionImageInformation
Definition: mmtypes.h:196
NTSYSAPI ULONG NTAPI RtlIsDosDeviceName_U(_In_ PCWSTR Name)
NTSYSAPI NTSTATUS NTAPI RtlAcquirePrivilege(_In_ PULONG Privilege, _In_ ULONG NumPriv, _In_ ULONG Flags, _Out_ PVOID *ReturnedState)
NTSTATUS NTAPI RtlGetFullPathName_UstrEx(_In_ PUNICODE_STRING FileName, _In_opt_ PUNICODE_STRING StaticString, _In_opt_ PUNICODE_STRING DynamicString, _Out_opt_ PUNICODE_STRING *StringUsed, _Out_opt_ PSIZE_T FilePartSize, _Out_opt_ PBOOLEAN NameInvalid, _Out_ RTL_PATH_TYPE *PathType, _Out_opt_ PSIZE_T LengthNeeded)
VOID NTAPI RtlReleaseRelativeName(_In_ PRTL_RELATIVE_NAME_U RelativeName)
NTSYSAPI VOID NTAPI RtlDestroyEnvironment(_In_ PWSTR Environment)
Definition: env.c:116
NTSYSAPI RTL_PATH_TYPE NTAPI RtlDetermineDosPathNameType_U(_In_ PCWSTR Path)
NTSYSAPI VOID NTAPI RtlReleasePrivilege(_In_ PVOID ReturnedState)
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToRelativeNtPathName_U(_In_ PCWSTR DosName, _Out_ PUNICODE_STRING NtName, _Out_ PCWSTR *PartName, _Out_ PRTL_RELATIVE_NAME_U RelativeName)
#define SEM_FAILCRITICALERRORS
Definition: rtltypes.h:69
@ RtlPathTypeRootLocalDevice
Definition: rtltypes.h:480
@ RtlPathTypeRelative
Definition: rtltypes.h:478
@ RtlPathTypeUncAbsolute
Definition: rtltypes.h:474
@ RtlPathTypeLocalDevice
Definition: rtltypes.h:479
@ RtlPathTypeDriveAbsolute
Definition: rtltypes.h:475
enum _RTL_PATH_TYPE RTL_PATH_TYPE
VOID WINAPI FreeString(_In_ LPWSTR pszString)
Definition: netsh.c:281
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1342
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_READ_DATA
Definition: nt_native.h:628
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1296
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define PROCESS_ALL_ACCESS
Definition: nt_native.h:1327
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
#define PAGE_EXECUTE
Definition: nt_native.h:1309
NTSTATUS NTAPI NtTerminateProcess(HANDLE ProcessHandle, LONG ExitStatus)
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define FILE_EXECUTE
Definition: nt_native.h:642
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define MEM_RESERVE
Definition: nt_native.h:1317
#define MEM_RELEASE
Definition: nt_native.h:1319
NTSYSAPI NTSTATUS NTAPI NtCreateThread(OUT PHANDLE phThread, IN ACCESS_MASK AccessMask, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE hProcess, OUT PCLIENT_ID pClientId, IN PCONTEXT pContext, OUT PSTACKINFO pStackInfo, IN BOOLEAN bSuspended)
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1311
#define UNICODE_STRING_MAX_CHARS
#define UNICODE_STRING_MAX_BYTES
#define VER_SUITE_DATACENTER
#define VER_SUITE_PERSONAL
#define ANSI_NULL
#define IMAGE_SUBSYSTEM_POSIX_CUI
Definition: ntimage.h:440
#define IMAGE_SUBSYSTEM_WINDOWS_CUI
Definition: ntimage.h:438
#define IMAGE_SUBSYSTEM_WINDOWS_GUI
Definition: ntimage.h:437
#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION
Definition: ntimage.h:458
#define IMAGE_FILE_MACHINE_AMD64
Definition: ntimage.h:17
#define IMAGE_FILE_MACHINE_IA64
Definition: ntimage.h:22
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5192
NTSTATUS NTAPI NtReadVirtualMemory(IN HANDLE ProcessHandle, IN PVOID BaseAddress, OUT PVOID Buffer, IN SIZE_T NumberOfBytesToRead, OUT PSIZE_T NumberOfBytesRead OPTIONAL)
Definition: virtual.c:2781
NTSTATUS NTAPI NtIsProcessInJob(_In_ HANDLE ProcessHandle, _In_opt_ HANDLE JobHandle)
Definition: job.c:2014
NTSTATUS NTAPI NtAssignProcessToJobObject(_In_ HANDLE JobHandle, _In_ HANDLE ProcessHandle)
Definition: job.c:1928
NTSTATUS NTAPI NtCreateProcessEx(OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN HANDLE ParentProcess, IN ULONG Flags, IN HANDLE SectionHandle OPTIONAL, IN HANDLE DebugPort OPTIONAL, IN HANDLE ExceptionPort OPTIONAL, IN BOOLEAN InJob)
Definition: process.c:1374
NTSTATUS NTAPI NtSetInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _In_reads_bytes_(ProcessInformationLength) PVOID ProcessInformation, _In_ ULONG ProcessInformationLength)
Definition: query.c:1422
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define STATUS_INVALID_IMAGE_WIN_64
Definition: ntstatus.h:1029
#define STATUS_INVALID_IMAGE_WIN_16
Definition: ntstatus.h:635
#define STATUS_INVALID_IMAGE_NE_FORMAT
Definition: ntstatus.h:613
#define STATUS_IMAGE_MACHINE_TYPE_MISMATCH_EXE
Definition: ntstatus.h:224
#define STATUS_INVALID_IMAGE_NOT_MZ
Definition: ntstatus.h:633
#define STATUS_INVALID_IMAGE_PROTECT
Definition: ntstatus.h:634
#define STATUS_VDM_DISALLOWED
Definition: ntstatus.h:1089
#define STATUS_FILE_IS_OFFLINE
Definition: ntstatus.h:862
#define STATUS_NAME_TOO_LONG
Definition: ntstatus.h:592
#define IMAGE_FILE_MACHINE_I386
Definition: pedump.c:174
#define IMAGE_FILE_DLL
Definition: pedump.c:169
#define REG_DWORD
Definition: sdbapi.c:615
VOID NTAPI CsrFreeCaptureBuffer(_In_ _Frees_ptr_ PCSR_CAPTURE_BUFFER CaptureBuffer)
Definition: capture.c:210
NTSTATUS NTAPI CsrClientCallServer(_Inout_ PCSR_API_MESSAGE ApiMessage, _Inout_opt_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_ CSR_API_NUMBER ApiNumber, _In_ ULONG DataLength)
Definition: connect.c:366
#define BINARY_TYPE_WOW
Definition: vdm.h:40
#define VDM_UNDO_PARTIAL
Definition: vdm.h:27
#define VDM_UNDO_COMPLETED
Definition: vdm.h:30
#define BINARY_TYPE_WOW_EX
Definition: vdm.h:41
#define VDM_NOT_READY
Definition: vdm.h:47
#define BINARY_TYPE_SEPARATE_WOW
Definition: vdm.h:39
#define VDM_UNDO_REUSE
Definition: vdm.h:29
@ VdmEntryUndo
Definition: vdm.h:19
@ VdmEntryUpdateProcess
Definition: vdm.h:20
#define VDM_UNDO_FULL
Definition: vdm.h:28
#define BINARY_TYPE_DOS
Definition: vdm.h:38
#define VDM_READY
Definition: vdm.h:48
#define VDM_NOT_LOADED
Definition: vdm.h:46
#define BINARY_TYPE_EXE
Definition: vdm.h:35
wcscat
wcscpy
NTSTATUS NTAPI NtQuerySection(_In_ HANDLE SectionHandle, _In_ SECTION_INFORMATION_CLASS SectionInformationClass, _Out_ PVOID SectionInformation, _In_ SIZE_T SectionInformationLength, _Out_opt_ PSIZE_T ResultLength)
Definition: section.c:3812
USHORT MaximumLength
Definition: env_spec_w32.h:377
BASE_CREATE_PROCESS CreateProcessRequest
Definition: basemsg.h:283
union _BASE_API_MESSAGE::@3970 Data
BASE_CHECK_VDM CheckVDMRequest
Definition: basemsg.h:287
USHORT VDMState
Definition: basemsg.h:147
HANDLE WaitObjectForParent
Definition: basemsg.h:123
BASE_SXS_CREATEPROCESS_MSG Sxs
Definition: basemsg.h:96
USHORT ProcessorArchitecture
Definition: basemsg.h:99
ULONG PebAddressWow64
Definition: basemsg.h:98
HANDLE ProcessHandle
Definition: basemsg.h:89
CLIENT_ID ClientId
Definition: basemsg.h:91
HANDLE ThreadHandle
Definition: basemsg.h:90
PVOID PebAddressNative
Definition: basemsg.h:97
BOOLEAN IsWowTaskReady
Definition: base.h:135
BOOLEAN DefaultSeparateVDM
Definition: base.h:134
HANDLE UniqueThread
Definition: compat.h:826
HANDLE UniqueProcess
Definition: compat.h:825
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
PVOID StackBase
Definition: pstypes.h:757
PVOID ArbitraryUserPointer
Definition: compat.h:719
BOOLEAN ReadImageFileExecOptions
Definition: ntddk_ex.h:240
ULONG ImageSubsystemMajorVersion
Definition: ntddk_ex.h:305
SIZE_T StaticSize
Definition: rtltypes.h:1903
PUCHAR StaticBuffer
Definition: rtltypes.h:1901
PUCHAR Buffer
Definition: rtltypes.h:1900
SIZE_T Size
Definition: rtltypes.h:1902
UNICODE_STRING RelativeName
Definition: rtltypes.h:1382
HANDLE ContainingDirectory
Definition: rtltypes.h:1383
UNICODE_STRING String
Definition: rtltypes.h:1910
UNICODE_STRING DesktopInfo
Definition: rtltypes.h:1582
LPVOID lpSecurityDescriptor
Definition: compat.h:193
PUNICODE_STRING Win32
Definition: kernel32.h:402
PUNICODE_STRING Nt
Definition: kernel32.h:403
Definition: compat.h:836
NT_TIB NtTib
Definition: ntddk_ex.h:332
#define max(a, b)
Definition: svc.c:63
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define MAXUSHORT
Definition: typedefs.h:83
char * PCHAR
Definition: typedefs.h:51
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define NORMAL_PRIORITY_CLASS
Definition: winbase.h:186
#define STARTF_FORCEOFFFEEDBACK
Definition: winbase.h:475
#define CREATE_BREAKAWAY_FROM_JOB
Definition: winbase.h:214
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CREATE_FORCEDOS
Definition: winbase.h:194
#define REALTIME_PRIORITY_CLASS
Definition: winbase.h:189
#define BELOW_NORMAL_PRIORITY_CLASS
Definition: winbase.h:195
#define CREATE_UNICODE_ENVIRONMENT
Definition: winbase.h:191
#define HIGH_PRIORITY_CLASS
Definition: winbase.h:188
#define CREATE_SHARED_WOW_VDM
Definition: winbase.h:193
#define GetModuleHandle
Definition: winbase.h:3549
#define CREATE_DEFAULT_ERROR_MODE
Definition: winbase.h:216
#define CREATE_SEPARATE_WOW_VDM
Definition: winbase.h:192
#define CREATE_SUSPENDED
Definition: winbase.h:183
#define DEBUG_ONLY_THIS_PROCESS
Definition: winbase.h:182
#define SearchPath
Definition: winbase.h:3622
#define CREATE_PRESERVE_CODE_AUTHZ_LEVEL
Definition: winbase.h:215
#define IDLE_PRIORITY_CLASS
Definition: winbase.h:187
#define STARTF_FORCEONFEEDBACK
Definition: winbase.h:474
#define DEBUG_PROCESS
Definition: winbase.h:181
#define ABOVE_NORMAL_PRIORITY_CLASS
Definition: winbase.h:196
NTSYSAPI NTSTATUS WINAPI DbgUiConnectToDbg(void)
Definition: dbgui.c:25
NTSYSAPI HANDLE WINAPI DbgUiGetThreadDebugObject(void)
Definition: dbgui.c:333
@ ProcessPriorityClass
Definition: winternl.h:1900
@ ProcessDefaultHardErrorMode
Definition: winternl.h:1894
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:228
#define ERROR_DIRECTORY
Definition: winerror.h:416
#define ERROR_NOT_READY
Definition: winerror.h:246
#define ERROR_BAD_EXE_FORMAT
Definition: winerror.h:373
#define ERROR_CHILD_NOT_COMPLETE
Definition: winerror.h:323
#define ERROR_ACCESS_DISABLED_BY_POLICY
Definition: winerror.h:1092
#define ERROR_CANCELLED
Definition: winerror.h:1055
#define ERROR_EXE_MACHINE_TYPE_MISMATCH
Definition: winerror.h:393
#define ERROR_ACCESS_DISABLED_WEBBLADE_TAMPER
Definition: winerror.h:1105
#define ERROR_ACCESS_DISABLED_WEBBLADE
Definition: winerror.h:1104
#define ERROR_FILE_OFFLINE
Definition: winerror.h:1714
#define ERROR_BAD_DEVICE
Definition: winerror.h:1032
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1151

Referenced by CreateProcessW().

◆ CreateProcessW()

BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW ( LPCWSTR  lpApplicationName,
LPWSTR  lpCommandLine,
LPSECURITY_ATTRIBUTES  lpProcessAttributes,
LPSECURITY_ATTRIBUTES  lpThreadAttributes,
BOOL  bInheritHandles,
DWORD  dwCreationFlags,
LPVOID  lpEnvironment,
LPCWSTR  lpCurrentDirectory,
LPSTARTUPINFOW  lpStartupInfo,
LPPROCESS_INFORMATION  lpProcessInformation 
)

Definition at line 4491 of file proc.c.

4501{
4502 /* Call the internal (but exported) version */
4504 lpApplicationName,
4505 lpCommandLine,
4506 lpProcessAttributes,
4507 lpThreadAttributes,
4508 bInheritHandles,
4509 dwCreationFlags,
4510 lpEnvironment,
4511 lpCurrentDirectory,
4512 lpStartupInfo,
4513 lpProcessInformation,
4514 NULL);
4515}
BOOL WINAPI CreateProcessInternalW(IN HANDLE hUserToken, IN LPCWSTR lpApplicationName, IN LPWSTR lpCommandLine, IN LPSECURITY_ATTRIBUTES lpProcessAttributes, IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN BOOL bInheritHandles, IN DWORD dwCreationFlags, IN LPVOID lpEnvironment, IN LPCWSTR lpCurrentDirectory, IN LPSTARTUPINFOW lpStartupInfo, IN LPPROCESS_INFORMATION lpProcessInformation, OUT PHANDLE hNewToken)
Definition: proc.c:2133

Referenced by alloc_console(), AudioDlgProc(), compile_cs(), ConsoleIMERoutine(), CorDebug_CreateProcess(), CProcess::CProcess(), create_pseudo_console(), create_server(), create_surrogate_server(), CreateClientProcess(), CreateProcessAsUserW(), CreateProcessWithTokenW(), do_register_dll(), execute_command(), HotkeyThread(), IDirectInputAImpl_RunControlPanel(), install_wine_gecko(), InstallDevice(), InstallLiveCD(), invoke_appwiz(), ITERATE_RemoveExistingProducts(), CNetConnectionPropertyUi::LANPropertiesUIDlg(), launch_exe(), CNewMenu::NewItemByCommand(), ProcessPage_OnDebug(), PromptAndRunProcessAs(), register_dll(), run_child(), run_rapps(), run_winemenubuilder(), runCmd(), RunCommandAndWait(), RunControlPanelApplet(), RunCurrentJobs(), runscriptfile(), RunSetupThreadProc(), ScmStartUserModeService(), SHELL_ExecuteW(), start_debugger(), START_TEST(), StartChild(), StartLsass(), StartProcess(), StartServicesManager(), TaskManager_OnFileNew(), Test_CommandLine(), test_debug_loop_wow64(), test_loadpaths_execute(), TestStaticDestruct(), UnhandledExceptionFilter(), WshExec_create(), and wWinMain().

◆ ExitProcess()

VOID WINAPI ExitProcess ( IN UINT  uExitCode)

Definition at line 1380 of file proc.c.

1381{
1382 BASE_API_MESSAGE ApiMessage;
1383 PBASE_EXIT_PROCESS ExitProcessRequest = &ApiMessage.Data.ExitProcessRequest;
1384
1386
1387 _SEH2_TRY
1388 {
1389 /* Acquire the PEB lock */
1391
1392 /* Kill all the threads */
1393 NtTerminateProcess(NULL, uExitCode);
1394
1395 /* Unload all DLLs */
1397
1398 /* Notify Base Server of process termination */
1399 ExitProcessRequest->uExitCode = uExitCode;
1401 NULL,
1403 sizeof(*ExitProcessRequest));
1404
1405 /* Now do it again */
1407 }
1409 {
1410 /* Release the PEB lock */
1412 }
1413 _SEH2_END;
1414
1415 /* should never get here */
1416 ASSERT(0);
1417 while(1);
1418}
@ BasepExitProcess
Definition: basemsg.h:24
#define _SEH2_FINALLY
Definition: pseh2_64.h:153
BASE_EXIT_PROCESS ExitProcessRequest
Definition: basemsg.h:286
NTSYSAPI void WINAPI LdrShutdownProcess(void)
Definition: ldrinit.c:954

Referenced by _CorExeMain(), _exit(), _font_assert(), _RunRemoteTest(), alarmThreadMain(), BaseProcessStartup(), BaseThreadStartup(), child_process(), CLRMetaHost_ExitProcess(), ConsoleControlDispatcher(), CtrlCIntercept(), DbgkExitProcess(), DECLARE_INTERFACE_(), DefaultConsoleCtrlHandler(), DevInstallW(), DisplayError(), dll_entry_point(), doChild(), doDebugger(), ErrorExit(), exit(), exit_or_terminate_process(), ExitThread(), FatalAppExitA(), FatalAppExitW(), FatalExit(), fls_exit_deadlock_child(), Host_Quit(), IEWinMain(), init(), LoadProc(), local_server_proc(), LogToFile(), main(), MyErrExit(), performUninstall(), restart_as_admin_elevated(), RpcRaiseException(), setupDelayHook(), ShellExec_RunDLL_Helper(), ShowUsage(), START_TEST(), StringListAppend(), test__popen_child(), test__popen_read_child(), thread_1(), timeout_thread_proc(), VdmShutdown(), wait_debugger(), WatchDirectory(), WinMain(), wmainCRTStartup(), and wWinMain().

◆ FatalAppExitA()

VOID WINAPI FatalAppExitA ( UINT  uAction,
LPCSTR  lpMessageText 
)

Definition at line 1455 of file proc.c.

1457{
1458 PUNICODE_STRING MessageTextU;
1459 ANSI_STRING MessageText;
1461
1462 /* Initialize the string using the static TEB pointer */
1463 MessageTextU = &NtCurrentTeb()->StaticUnicodeString;
1464 RtlInitAnsiString(&MessageText, (LPSTR)lpMessageText);
1465
1466 /* Convert to unicode, or just exit normally if this failed */
1467 Status = RtlAnsiStringToUnicodeString(MessageTextU, &MessageText, FALSE);
1468 if (!NT_SUCCESS(Status)) ExitProcess(0);
1469
1470 /* Call the Wide function */
1471 FatalAppExitW(uAction, MessageTextU->Buffer);
1472}
VOID WINAPI FatalAppExitW(IN UINT uAction, IN LPCWSTR lpMessageText)
Definition: proc.c:1479
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
char * LPSTR
Definition: typedefs.h:51

◆ FatalAppExitW()

VOID WINAPI FatalAppExitW ( IN UINT  uAction,
IN LPCWSTR  lpMessageText 
)

Definition at line 1479 of file proc.c.

1481{
1485
1486 /* Setup the string to print out */
1487 RtlInitUnicodeString(&UnicodeString, lpMessageText);
1488
1489 /* Display the hard error no matter what */
1491 1,
1492 1,
1494#if DBG
1495 /* On Checked builds, Windows allows the user to cancel the operation */
1497#else
1498 OptionOk,
1499#endif
1500 &Response);
1501
1502 /* Give the user a chance to abort */
1504 {
1505 return;
1506 }
1507
1508 /* Otherwise kill the process */
1509 ExitProcess(0);
1510}
#define DBG(x)
Definition: moztest.c:12
#define HARDERROR_OVERRIDE_ERRORMODE
Definition: extypes.h:146
@ OptionOkCancel
Definition: extypes.h:188
@ ResponseCancel
Definition: extypes.h:202
#define STATUS_FATAL_APP_EXIT
Definition: ntstatus.h:210
Definition: ncftp.h:89
uint32_t * PULONG_PTR
Definition: typedefs.h:65
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_opt_ PCUNICODE_STRING UnicodeString
Definition: wdfstring.h:64

Referenced by FatalAppExitA().

◆ FatalExit()

VOID WINAPI FatalExit ( IN int  ExitCode)

Definition at line 1517 of file proc.c.

1518{
1519#if DBG
1520 /* On Checked builds, Windows gives the user a nice little debugger UI */
1521 CHAR Action[2];
1522 DbgPrint("FatalExit...\n\n");
1523
1524 /* Check for reactos specific flag (set by rosautotest) */
1526 {
1528 }
1529
1530 while (TRUE)
1531 {
1532 DbgPrompt("A (Abort), B (Break), I (Ignore)? ", Action, sizeof(Action));
1533 switch (Action[0])
1534 {
1535 case 'B': case 'b':
1536 DbgBreakPoint();
1537 break;
1538
1539 case 'A': case 'a':
1540 ExitProcess(ExitCode);
1541
1542 case 'I': case 'i':
1543 return;
1544 }
1545 }
1546#endif
1547 /* On other builds, just kill the process */
1548 ExitProcess(ExitCode);
1549}
#define FLG_DISABLE_DEBUG_PROMPTS
Definition: pstypes.h:81
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
NTSYSAPI ULONG NTAPI DbgPrompt(_In_z_ PCCH Prompt, _Out_writes_bytes_(MaximumResponseLength) PCH Response, _In_ ULONG MaximumResponseLength)
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:510
NTSYSAPI void WINAPI DbgBreakPoint(void)
NTSYSAPI ULONG WINAPI RtlGetNtGlobalFlags(void)
Definition: libsupp.c:95

◆ FlushInstructionCache()

BOOL WINAPI FlushInstructionCache ( IN HANDLE  hProcess,
IN LPCVOID  lpBaseAddress,
IN SIZE_T  nSize 
)

Definition at line 1356 of file proc.c.

1359{
1361
1362 /* Call the native function */
1364 if (!NT_SUCCESS(Status))
1365 {
1366 /* Handle failure case */
1368 return FALSE;
1369 }
1370
1371 /* All good */
1372 return TRUE;
1373}
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
NTSTATUS NTAPI NtFlushInstructionCache(_In_ HANDLE ProcessHandle, _In_opt_ PVOID BaseAddress, _In_ SIZE_T FlushSize)
Definition: virtual.c:3009
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:1809

Referenced by test_cross_process_notifications().

◆ GetActiveProcessorCount()

DWORD WINAPI GetActiveProcessorCount ( IN WORD  GroupNumber)

Definition at line 945 of file proc.c.

946{
947 STUB; // FIXME: Real group support
948 return GetProcessorCountInfo(GroupNumber, FALSE);
949}
static DWORD GetProcessorCountInfo(IN WORD GroupNumber, IN BOOL Maximum)
Definition: proc.c:926
#define STUB
Definition: kernel32.h:27

◆ GetActiveProcessorGroupCount()

WORD WINAPI GetActiveProcessorGroupCount ( VOID  )

Definition at line 919 of file proc.c.

920{
921 STUB; // FIXME: Real group support
922 return 1; // TODO: SharedUserData->ActiveGroupCount?
923}

◆ GetCommandLineA()

LPSTR WINAPI GetCommandLineA ( VOID  )

Definition at line 1902 of file proc.c.

1903{
1905}
ANSI_STRING BaseAnsiCommandLine
Definition: proc.c:21

◆ GetCommandLineW()

LPWSTR WINAPI GetCommandLineW ( VOID  )

Definition at line 1912 of file proc.c.

1913{
1915}
UNICODE_STRING BaseUnicodeCommandLine
Definition: proc.c:20

◆ GetCurrentProcess()

HANDLE WINAPI GetCurrentProcess ( VOID  )

Definition at line 1185 of file proc.c.

1186{
1187 return (HANDLE)NtCurrentProcess();
1188}

◆ GetCurrentProcessId()

DWORD WINAPI GetCurrentProcessId ( VOID  )

Definition at line 1205 of file proc.c.

1206{
1208}

Referenced by __security_init_cookie(), _getpid(), _mktemp(), _mktemp_s(), _Success_(), _wmktemp(), _wmktemp_s(), AddPortW(), adns_getpid(), apartment_construct(), child_process(), ClientLoadLibrary(), CloseProcess(), CMP_RegisterNotification(), CommitSpoolData(), ConfigurePortW(), create_test_element_from_hwnd(), CreateNotificationParamAndSend(), CreatePipe(), CreateProcessWithLogonW(), CreateToolhelp32Snapshot(), CURSORICON_CopyImage(), custom_start_server(), default_ctrl_handler(), DirectDrawClipper_Initialize(), dll_entry_point(), DllMain(), do_msidbCustomActionTypeDll(), doChild(), DPLAYX_CreateLobbyApplication(), DPLAYX_IsAppIdLobbied(), DumpNotificationState(), enum_modules64(), EnumWindowsProc(), ExtractAndInstallThread(), ExtractArchiveForExecution(), FreeChangeNotifications(), generate_ipid(), get_cmdline(), get_node_provider_description_string(), get_proc_address64(), GetProcessVersion(), GetSpoolFileHandle(), handle_msi_break(), IDirectPlayLobby3AImpl_SetConnectionSettings(), IDirectPlayLobby3Impl_SetConnectionSettings(), ImmGetImeMenuItemsAW(), Internal_CreatePalette(), Internal_CreateSurface(), ipid_to_ifstub(), IsBlockFromHeap(), LresultFromObject(), main(), mark_task_process(), new_stub_manager(), NotifyLogon(), ole_server(), openlog(), OutputDebugStringA(), ParseSharedPacket(), ProcessIdToSessionId(), RegisterDragDrop(), rpc_execute_call(), rpcrt4_protseq_ncacn_np_open_endpoint(), rpcrt4_protseq_ncalrpc_open_endpoint(), run_in_temp_desktop_thread_func(), ScConnectControlPipe(), CNotifyToolbar::SendNotifyCallback(), ServerThread(), service_main(), SHAllocShared(), SHAppBarMessage(), SHFreeShared(), SHGetAppCompatFlags(), SHHandleUpdateImage(), SHLockShared(), SHMapHandle(), SHUpdateImageW(), start_debugger(), START_TEST(), StartDirectDraw(), TelnetGetConsoleWindow(), test_AddSelfToJob(), test_alloc_shared(), test_alloc_shared_remote(), test_AttachConsole(), test_AttachConsole_child(), test_BreakawayOk(), Test_CloseDuplicatedSocket(), Test_CloseWhileSelectDuplicatedSocket(), test_CoGetCurrentProcess(), test_D3DKMTQueryVideoMemoryInfo(), test_debug_loop(), test_default_clientside_providers(), test_duplicate_handle_access(), test_Element_Find(), test_exception_dispatcher(), test_exit_process_async(), test_GetConsoleProcessList(), test_GetExtendedTcpTable_owner(), test_GetExtendedUdpTable_owner(), test_GetFocusedElement(), test_GetProcessVersion(), test_GetRootElement(), test_handles(), test_hook_cleanup_thread_proc(), test_init_block(), test_IUIAutomationEventHandler(), test_IUIAutomationFocusChangedEventHandler(), test_jobInheritance(), test_nested_jobs_child(), test_nt_wow64(), test_OpenProcess(), test_parent_process_attribute(), test_peb_teb(), test_process(), test_process_id(), test_process_security_child(), Test_ProcessModules(), test_query_handle(), test_query_handle_ex(), test_query_process(), test_query_process_vm(), test_QueryFullProcessImageNameW(), test_QueryInformationJobObject(), test_readvirtualmemory(), test_RtlQueryProcessDebugInformation(), test_session_info(), test_set_hook(), test_shared_handle_table(), test_SHCreateSessionKey(), test_syscalls(), test_tcp(), test_thread_lookup(), test_Toolhelp(), test_udp(), test_uia_com_focus_change_event_handler_win_event_handling(), test_UiaAddEvent(), test_UiaAddEvent_client_proc(), test_UiaFind(), test_UiaGetRootNode(), test_UiaGetRuntimeId(), test_UiaGetUpdatedCache(), test_UiaNavigate(), test_UiaNodeFromFocus(), test_UiaNodeFromHandle(), test_UiaNodeFromHandle_client_proc(), test_UiaNodeFromProvider(), test_UiaRegisterProviderCallback(), test_WaitForJobObject(), test_Win32_Process(), test_winevents(), test_WithWSAStartup(), test_ws_functions(), test_zero_access(), TestChannelHook_ClientFillBuffer(), TestChannelHook_ClientGetSize(), TestChannelHook_ClientNotify(), TestChannelHook_ServerGetSize(), TestChannelHook_ServerNotify(), ThemeDestroyWndData(), tmpnam_helper(), uia_com_event_handler_test_thread(), uia_nested_node_provider_attach_event(), uia_node_from_handle_test_thread(), uia_proxy_provider_win_event_handler_test_thread(), WDML_AddServer(), WinMain(), wmain(), wtmpnam_helper(), and wWinMain().

◆ GetCurrentThread()

HANDLE WINAPI GetCurrentThread ( VOID  )

Definition at line 1195 of file proc.c.

1196{
1197 return (HANDLE)NtCurrentThread();
1198}

Referenced by __threadhandle(), AccpLookupCurrentUser(), AdjustAffinity(), AuthzpInitUnderImpersonation(), CheckTokenMembership(), ConsoleControlDispatcher(), DirectoryWatcherThreadFuncAPC(), dll_entry_point(), DwInitializeSdFromThreadToken(), exec_write_handler(), CShellCommandSACL::Execute(), GetProfileType(), GetSystemUserInfo(), GetUserNameW(), ImageView_Main(), IsCallerInteractive(), main(), OpenEffectiveToken(), PlaySound_ExpandEnvironmentStrings(), priorityTimeProc(), Privilege(), process_work_items(), RegOpenCurrentUser(), RevertToPrinterSelf(), rpcrt4_http_timer_thread(), RPCRT4_io_thread(), RPCRT4_server_thread(), CFindFolder::SearchThreadProc(), serverThreadMain2(), set_thread_name(), SetThreadToken(), SlideWindow(), SockAsyncThread(), start_address_thread(), start_fiber(), START_TEST(), test_affinity(), test_alertable(), test_CancelSynchronousIo(), test_cancelsynchronousio(), test_CoWaitForMultipleHandles(), test_CreateDirectoryA(), test_CreatePipe(), test_exec_memory_writes(), test_FileSecurity(), test_GetFileType(), test_GetNamedSecurityInfoA(), test_GetOverlappedResultEx(), test_GetSecurityInfo(), test_GetWindowsAccountDomainSid(), test_HideFromDebugger(), test_ImpersonateNamedPipeClient(), test_impersonation_level(), test_MsgWaitForMultipleObjects(), test_nonalertable(), test_NtGetCurrentProcessorNumber(), test_object_identity(), test_object_permanence(), test_post_completion(), test_pseudo_handle_security(), test_pseudo_tokens(), test_query_architectures(), test_query_object(), test_QueueUserAPC(), test_read_write(), test_selectors(), test_set_io_completion(), Test_SyscallPerformance(), test_thread_description(), test_thread_ideal_processor(), test_thread_info(), test_thread_priority(), test_thread_processor(), test_thread_start_address(), Test_ThreadBasicInformationClass(), test_ThreadEnableAlignmentFaultFixup(), Test_ThreadPriorityClass(), test_token(), test_user_apc(), test_WaitForMultipleObjects(), test_WaitForSingleObject(), TestTokenPrivilege(), ThreadFunc2(), threadFunc3(), TlsFree(), WahOpenCurrentThread(), WaveThread(), wmain(), and wWinMain().

◆ GetExitCodeProcess()

BOOL WINAPI GetExitCodeProcess ( IN HANDLE  hProcess,
IN LPDWORD  lpExitCode 
)

Definition at line 1215 of file proc.c.

1217{
1218 PROCESS_BASIC_INFORMATION ProcessBasic;
1220
1221 /* Ask the kernel */
1224 &ProcessBasic,
1225 sizeof(ProcessBasic),
1226 NULL);
1227 if (!NT_SUCCESS(Status))
1228 {
1229 /* We failed, was this because this is a VDM process? */
1230 if (BaseCheckForVDM(hProcess, lpExitCode) != FALSE) return TRUE;
1231
1232 /* Not a VDM process, fail the call */
1234 return FALSE;
1235 }
1236
1237 /* Succes case, return the exit code */
1238 *lpExitCode = (DWORD)ProcessBasic.ExitStatus;
1239 return TRUE;
1240}
@ ProcessBasicInformation
Definition: cicbase.cpp:63
BOOL WINAPI BaseCheckForVDM(IN HANDLE ProcessHandle, OUT LPDWORD ExitCode)
Definition: vdm.c:618
#define DWORD
Definition: nt_native.h:44
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_writes_bytes_to_opt_(ProcessInformationLength, *ReturnLength) PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:211

Referenced by _cwait(), check_child_console_bits(), CloseProcessAndVerify_(), cmd_start(), CommandThreadProc(), crash_and_debug(), crash_and_winedbg(), custom_get_process_return(), DoTestEntry(), Execute(), execute_command(), ExecutePipeline(), LauncherRoutine2(), MonitorChildThread(), ProcessRunning(), read_reg_output_(), restart_as_admin_elevated(), run_child_wait(), run_ex(), run_rapps(), run_reg_exe_(), run_script_file(), runcmd(), runCmd(), RunCommandAndWait(), runscriptfile(), RunSetupThreadProc(), runtime_is_usable(), shell_execute_ex_(), TerminateShell(), test_arm64ec(), test_CreateProcessWithDesktop(), test_CtrlHandlerSubsystem(), test_ddeml_server(), test_debug_loop_wow64(), test_DoInvalidDir(), test_end_to_end_server(), test_exit(), test_ExitProcess(), test_kill_on_exit(), test_loadpaths_execute(), test_msg_server(), test_pe_os_version(), test_quick_exit(), test_UiaAddEvent(), test_UiaNodeFromHandle(), WshExec_get_Status(), and WshShell3_Run().

◆ GetMaximumProcessorCount()

DWORD WINAPI GetMaximumProcessorCount ( IN WORD  GroupNumber)

Definition at line 956 of file proc.c.

957{
958 STUB; // FIXME: Real group support
959 return GetProcessorCountInfo(GroupNumber, TRUE);
960}

◆ GetPriorityClass()

DWORD WINAPI GetPriorityClass ( IN HANDLE  hProcess)

Definition at line 1556 of file proc.c.

1557{
1559 PROCESS_PRIORITY_CLASS DECLSPEC_ALIGN(4) PriorityClass;
1560
1561 /* Query the kernel */
1564 &PriorityClass,
1565 sizeof(PriorityClass),
1566 NULL);
1568 {
1569 /* Handle the conversion from NT to Win32 classes */
1570 switch (PriorityClass.PriorityClass)
1571 {
1578 }
1579 }
1580
1581 /* Failure path */
1583 return 0;
1584}
#define DECLSPEC_ALIGN(x)
Definition: corecrt.h:141
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList

Referenced by ProcessPageShowContextMenu(), and test_query_process_priority().

◆ GetProcessAffinityMask()

BOOL WINAPI GetProcessAffinityMask ( IN HANDLE  hProcess,
OUT PDWORD_PTR  lpProcessAffinityMask,
OUT PDWORD_PTR  lpSystemAffinityMask 
)

Definition at line 860 of file proc.c.

863{
864 PROCESS_BASIC_INFORMATION ProcessInfo;
866
867 /* Query information on the process from the kernel */
870 &ProcessInfo,
871 sizeof(ProcessInfo),
872 NULL);
873 if (!NT_SUCCESS(Status))
874 {
875 /* Fail */
877 return FALSE;
878 }
879
880 /* Copy the affinity mask, and get the system one from our shared data */
881 *lpProcessAffinityMask = (DWORD)ProcessInfo.AffinityMask;
883 return TRUE;
884}
unsigned long DWORD
Definition: ntddk_ex.h:95
SYSTEM_BASIC_INFORMATION SysInfo
Definition: base.h:130
KAFFINITY ActiveProcessorsAffinityMask
Definition: ntddk_ex.h:167

Referenced by AffinityDialogWndProc(), START_TEST(), and test_thread_processor().

◆ GetProcessHandleCount()

BOOL WINAPI GetProcessHandleCount ( IN HANDLE  hProcess,
OUT PDWORD  pdwHandleCount 
)

Definition at line 1844 of file proc.c.

1846{
1847 ULONG phc;
1849
1850 /* Query the kernel */
1853 &phc,
1854 sizeof(phc),
1855 NULL);
1856 if (NT_SUCCESS(Status))
1857 {
1858 /* Copy the count and return success */
1859 *pdwHandleCount = phc;
1860 return TRUE;
1861 }
1862
1863 /* Handle error path */
1865 return FALSE;
1866}
@ ProcessHandleCount
Definition: winternl.h:1902

◆ GetProcessId()

DWORD WINAPI GetProcessId ( IN HANDLE  Process)

Definition at line 1247 of file proc.c.

1248{
1249 PROCESS_BASIC_INFORMATION ProcessBasic;
1251
1252 /* Query the kernel */
1255 &ProcessBasic,
1256 sizeof(ProcessBasic),
1257 NULL);
1258 if (!NT_SUCCESS(Status))
1259 {
1260 /* Handle failure */
1262 return 0;
1263 }
1264
1265 /* Return the PID */
1266 return (DWORD)ProcessBasic.UniqueProcessId;
1267}
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223

◆ GetProcessIoCounters()

BOOL WINAPI GetProcessIoCounters ( IN HANDLE  hProcess,
OUT PIO_COUNTERS  lpIoCounters 
)

Definition at line 1760 of file proc.c.

1762{
1764
1765 /* Query the kernel. Structures are identical, so let it do the copy too. */
1768 lpIoCounters,
1769 sizeof(IO_COUNTERS),
1770 NULL);
1771 if (!NT_SUCCESS(Status))
1772 {
1773 /* Handle error path */
1775 return FALSE;
1776 }
1777
1778 /* All done */
1779 return TRUE;
1780}
@ ProcessIoCounters
Definition: winternl.h:1884

Referenced by PerfDataRefresh().

◆ GetProcessorCountInfo()

static DWORD GetProcessorCountInfo ( IN WORD  GroupNumber,
IN BOOL  Maximum 
)
static

Definition at line 926 of file proc.c.

927{
929
930 // TODO: SharedUserData->ActiveProcessorCount for ALL_PROCESSOR_GROUPS?
931 if (GroupNumber != ALL_PROCESSOR_GROUPS && GroupNumber != THEONLYGROUP)
932 {
934 return 0;
935 }
937 return info.dwNumberOfProcessors;
938}
#define THEONLYGROUP
Definition: proc.c:912
VOID WINAPI GetNativeSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:207
#define ALL_PROCESSOR_GROUPS
Definition: ntbasedef.h:656

Referenced by GetActiveProcessorCount(), and GetMaximumProcessorCount().

◆ GetProcessPriorityBoost()

BOOL WINAPI GetProcessPriorityBoost ( IN HANDLE  hProcess,
OUT PBOOL  pDisablePriorityBoost 
)

Definition at line 1787 of file proc.c.

1789{
1792
1793 /* Query the kernel */
1797 sizeof(PriorityBoost),
1798 NULL);
1799 if (NT_SUCCESS(Status))
1800 {
1801 /* Convert from ULONG to a BOOL */
1802 *pDisablePriorityBoost = PriorityBoost ? TRUE : FALSE;
1803 return TRUE;
1804 }
1805
1806 /* Handle error path */
1808 return FALSE;
1809}
_In_ WDFREQUEST _In_ NTSTATUS _In_ CCHAR PriorityBoost
Definition: wdfrequest.h:1016
@ ProcessPriorityBoost
Definition: winternl.h:1904

◆ GetProcessShutdownParameters()

BOOL WINAPI GetProcessShutdownParameters ( OUT LPDWORD  lpdwLevel,
OUT LPDWORD  lpdwFlags 
)

Definition at line 967 of file proc.c.

969{
970 BASE_API_MESSAGE ApiMessage;
971 PBASE_GETSET_PROCESS_SHUTDOWN_PARAMS ShutdownParametersRequest = &ApiMessage.Data.ShutdownParametersRequest;
972
973 /* Ask CSRSS for shutdown information */
975 NULL,
977 sizeof(*ShutdownParametersRequest));
978 if (!NT_SUCCESS(ApiMessage.Status))
979 {
980 /* Return the failure from CSRSS */
981 BaseSetLastNTError(ApiMessage.Status);
982 return FALSE;
983 }
984
985 /* Get the data back */
986 *lpdwLevel = ShutdownParametersRequest->ShutdownLevel;
987 *lpdwFlags = ShutdownParametersRequest->ShutdownFlags;
988 return TRUE;
989}
@ BasepGetProcessShutdownParam
Definition: basemsg.h:34
BASE_GETSET_PROCESS_SHUTDOWN_PARAMS ShutdownParametersRequest
Definition: basemsg.h:294
NTSTATUS Status
Definition: csrmsg.h:110

◆ GetProcessTimes()

BOOL WINAPI GetProcessTimes ( IN HANDLE  hProcess,
IN LPFILETIME  lpCreationTime,
IN LPFILETIME  lpExitTime,
IN LPFILETIME  lpKernelTime,
IN LPFILETIME  lpUserTime 
)

Definition at line 1146 of file proc.c.

1151{
1154
1155 /* Query the times */
1158 &Kut,
1159 sizeof(Kut),
1160 NULL);
1161 if (!NT_SUCCESS(Status))
1162 {
1163 /* Handle failure */
1165 return FALSE;
1166 }
1167
1168 /* Copy all the times and return success */
1169 lpCreationTime->dwLowDateTime = Kut.CreateTime.u.LowPart;
1170 lpCreationTime->dwHighDateTime = Kut.CreateTime.u.HighPart;
1171 lpExitTime->dwLowDateTime = Kut.ExitTime.u.LowPart;
1172 lpExitTime->dwHighDateTime = Kut.ExitTime.u.HighPart;
1173 lpKernelTime->dwLowDateTime = Kut.KernelTime.u.LowPart;
1174 lpKernelTime->dwHighDateTime = Kut.KernelTime.u.HighPart;
1175 lpUserTime->dwLowDateTime = Kut.UserTime.u.LowPart;
1176 lpUserTime->dwHighDateTime = Kut.UserTime.u.HighPart;
1177 return TRUE;
1178}
LARGE_INTEGER UserTime
Definition: winternl.h:2377
LARGE_INTEGER CreateTime
Definition: winternl.h:2374
LARGE_INTEGER KernelTime
Definition: winternl.h:2376
LARGE_INTEGER ExitTime
Definition: winternl.h:2375
struct _LARGE_INTEGER::@2642 u
@ ProcessTimes
Definition: winternl.h:1886

◆ GetProcessVersion()

DWORD WINAPI GetProcessVersion ( IN DWORD  ProcessId)

Definition at line 1659 of file proc.c.

1660{
1661 DWORD Version = 0;
1662 PIMAGE_NT_HEADERS NtHeader;
1663 PIMAGE_DOS_HEADER DosHeader;
1664 PPEB Peb;
1665 PROCESS_BASIC_INFORMATION ProcessBasicInfo;
1670 USHORT VersionData[2];
1672
1673 /* We'll be accessing stuff that can fault, so protect everything with SEH */
1674 _SEH2_TRY
1675 {
1676 /* It this an in-process or out-of-process request? */
1677 if (!(ProcessId) || (GetCurrentProcessId() == ProcessId))
1678 {
1679 /* It's in-process, so just read our own header */
1680 NtHeader = RtlImageNtHeader(NtCurrentPeb()->ImageBaseAddress);
1681 if (!NtHeader)
1682 {
1683 /* Unable to read the NT header, something is wrong here... */
1685 goto Error;
1686 }
1687
1688 /* Get the version straight out of the NT header */
1691 }
1692 else
1693 {
1694 /* Out-of-process, so open it */
1696 FALSE,
1697 ProcessId);
1698 if (!ProcessHandle) _SEH2_YIELD(return 0);
1699
1700 /* Try to find out where its PEB lives */
1703 &ProcessBasicInfo,
1704 sizeof(ProcessBasicInfo),
1705 NULL);
1706
1707 if (!NT_SUCCESS(Status)) goto Error;
1708 Peb = ProcessBasicInfo.PebBaseAddress;
1709
1710 /* Now that we have the PEB, read the image base address out of it */
1713 &BaseAddress,
1714 sizeof(BaseAddress),
1715 NULL);
1716 if (!Result) goto Error;
1717
1718 /* Now read the e_lfanew (offset to NT header) from the base */
1719 DosHeader = BaseAddress;
1721 &DosHeader->e_lfanew,
1722 &e_lfanew,
1723 sizeof(e_lfanew),
1724 NULL);
1725 if (!Result) goto Error;
1726
1727 /* And finally, read the NT header itself by adding the offset */
1728 NtHeader = (PVOID)((ULONG_PTR)BaseAddress + e_lfanew);
1731 &VersionData,
1732 sizeof(VersionData),
1733 NULL);
1734 if (!Result) goto Error;
1735
1736 /* Get the version straight out of the NT header */
1737 Version = MAKELONG(VersionData[0], VersionData[1]);
1738
1739Error:
1740 /* If there was an error anywhere, set the last error */
1742 }
1743 }
1745 {
1746 /* Close the process handle */
1748 }
1749 _SEH2_END;
1750
1751 /* And return the version data */
1752 return Version;
1753}
BOOL Error
Definition: chkdsk.c:66
#define ReadProcessMemory(a, b, c, d, e)
Definition: compat.h:758
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1274
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2712
#define PROCESS_VM_READ
Definition: pstypes.h:157
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:162
DWORD e_lfanew
Definition: crypt.c:1299
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:453
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:207
PVOID ImageBaseAddress
Definition: ntddk_ex.h:245
#define MAKELONG(a, b)
Definition: typedefs.h:249
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1205

Referenced by get_app_version(), GetSystemInfoInternal(), and SHLWAPI_InitAppCompat().

◆ GetProcessWorkingSetSize()

BOOL WINAPI GetProcessWorkingSetSize ( IN HANDLE  hProcess,
OUT PSIZE_T  lpMinimumWorkingSetSize,
OUT PSIZE_T  lpMaximumWorkingSetSize 
)

Definition at line 1058 of file proc.c.

1061{
1062 DWORD Dummy;
1064 lpMinimumWorkingSetSize,
1065 lpMaximumWorkingSetSize,
1066 &Dummy);
1067}
BOOL WINAPI GetProcessWorkingSetSizeEx(IN HANDLE hProcess, OUT PSIZE_T lpMinimumWorkingSetSize, OUT PSIZE_T lpMaximumWorkingSetSize, OUT PDWORD Flags)
Definition: proc.c:1025

◆ GetProcessWorkingSetSizeEx()

BOOL WINAPI GetProcessWorkingSetSizeEx ( IN HANDLE  hProcess,
OUT PSIZE_T  lpMinimumWorkingSetSize,
OUT PSIZE_T  lpMaximumWorkingSetSize,
OUT PDWORD  Flags 
)

Definition at line 1025 of file proc.c.

1029{
1030 QUOTA_LIMITS_EX QuotaLimits;
1032
1033 /* Query the kernel about this */
1036 &QuotaLimits,
1037 sizeof(QuotaLimits),
1038 NULL);
1039 if (!NT_SUCCESS(Status))
1040 {
1041 /* Return error */
1043 return FALSE;
1044 }
1045
1046 /* Copy the quota information out */
1047 *lpMinimumWorkingSetSize = QuotaLimits.MinimumWorkingSetSize;
1048 *lpMaximumWorkingSetSize = QuotaLimits.MaximumWorkingSetSize;
1049 *Flags = QuotaLimits.Flags;
1050 return TRUE;
1051}
SIZE_T MaximumWorkingSetSize
Definition: pstypes.h:71
SIZE_T MinimumWorkingSetSize
Definition: pstypes.h:70
@ ProcessQuotaLimits
Definition: winternl.h:1883

Referenced by GetProcessWorkingSetSize().

◆ GetStartupInfoW()

VOID WINAPI GetStartupInfoW ( IN LPSTARTUPINFOW  lpStartupInfo)

Definition at line 1315 of file proc.c.

1316{
1318
1319 /* Get the process parameters */
1320 Params = NtCurrentPeb()->ProcessParameters;
1321
1322 /* Copy the data out of there */
1323 lpStartupInfo->cb = sizeof(STARTUPINFOW);
1324 lpStartupInfo->lpReserved = Params->ShellInfo.Buffer;
1325 lpStartupInfo->lpDesktop = Params->DesktopInfo.Buffer;
1326 lpStartupInfo->lpTitle = Params->WindowTitle.Buffer;
1327 lpStartupInfo->dwX = Params->StartingX;
1328 lpStartupInfo->dwY = Params->StartingY;
1329 lpStartupInfo->dwXSize = Params->CountX;
1330 lpStartupInfo->dwYSize = Params->CountY;
1331 lpStartupInfo->dwXCountChars = Params->CountCharsX;
1332 lpStartupInfo->dwYCountChars = Params->CountCharsY;
1333 lpStartupInfo->dwFillAttribute = Params->FillAttribute;
1334 lpStartupInfo->dwFlags = Params->WindowFlags;
1335 lpStartupInfo->wShowWindow = (WORD)Params->ShowWindowFlags;
1336 lpStartupInfo->cbReserved2 = Params->RuntimeData.Length;
1337 lpStartupInfo->lpReserved2 = (LPBYTE)Params->RuntimeData.Buffer;
1338
1339 /* Check if the standard handles are being used for other features */
1340 if (lpStartupInfo->dwFlags & (STARTF_USESTDHANDLES |
1342 STARTF_SHELLPRIVATE))
1343 {
1344 /* These are, so copy the standard handles too */
1345 lpStartupInfo->hStdInput = Params->StandardInput;
1346 lpStartupInfo->hStdOutput = Params->StandardOutput;
1347 lpStartupInfo->hStdError = Params->StandardError;
1348 }
1349}
unsigned short WORD
Definition: ntddk_ex.h:93
struct _STARTUPINFOW STARTUPINFOW
unsigned char * LPBYTE
Definition: typedefs.h:53
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:308

Referenced by alloc_console(), AttachConsole(), initialize_inherited_file_handles_nolock(), test_AllocConsole_child(), wmain(), and wWinMain().

◆ InitCommandLines()

VOID WINAPI InitCommandLines ( VOID  )

Definition at line 839 of file proc.c.

840{
842
843 /* Read the UNICODE_STRING from the PEB */
844 BaseUnicodeCommandLine = NtCurrentPeb()->ProcessParameters->CommandLine;
845
846 /* Convert to ANSI_STRING for the *A callers */
849 TRUE);
850 if (!NT_SUCCESS(Status)) RtlInitEmptyAnsiString(&BaseAnsiCommandLine, 0, 0);
851}
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)

Referenced by DllMain().

◆ IsWow64Process()

BOOL WINAPI IsWow64Process ( IN HANDLE  hProcess,
OUT PBOOL  Wow64Process 
)

Definition at line 1873 of file proc.c.

1875{
1876 ULONG_PTR pbi;
1878
1879 /* Query the kernel */
1882 &pbi,
1883 sizeof(pbi),
1884 NULL);
1885 if (!NT_SUCCESS(Status))
1886 {
1887 /* Handle error path */
1889 return FALSE;
1890 }
1891
1892 /* Enforce this is a BOOL, and return success */
1893 *Wow64Process = (pbi != 0);
1894 return TRUE;
1895}
@ ProcessWow64Information
Definition: cicbase.cpp:65
_Inout_ PERBANDINFO * pbi
Definition: winddi.h:3917

◆ OpenProcess()

HANDLE WINAPI OpenProcess ( IN DWORD  dwDesiredAccess,
IN BOOL  bInheritHandle,
IN DWORD  dwProcessId 
)

Definition at line 1274 of file proc.c.

1277{
1282
1283 /* Setup the input client ID structure */
1286
1287 /* This is needed just to define the inheritance flags */
1289 NULL,
1291 NULL,
1292 NULL);
1293
1294 /* Now try to open the process */
1296 dwDesiredAccess,
1298 &ClientId);
1299 if (!NT_SUCCESS(Status))
1300 {
1301 /* Handle failure */
1303 return NULL;
1304 }
1305
1306 /* Otherwise return a handle to the process */
1307 return ProcessHandle;
1308}
#define UlongToHandle(ul)
Definition: basetsd.h:91
static BOOL bInheritHandle
Definition: pipe.c:110
NTSTATUS NTAPI NtOpenProcess(OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN PCLIENT_ID ClientId)
Definition: process.c:1470
_In_ DWORD dwProcessId
Definition: shlwapi.h:193
#define OBJ_INHERIT
Definition: winternl.h:225

Referenced by _DoDLLInjection(), _RpcCommitSpoolData2(), _RpcGetSpoolFileInfo2(), CIconWatcher::AddIconToWatcher(), child_process(), child_process_exit_process_async(), CloseProcess(), CloseProcessAndVerify_(), DebugActiveProcess(), DebugActiveProcessStop(), debugcontrol_WaitForEvent(), dll_entry_point(), doChild(), DoSetPriority(), enum_modules64(), ExecuteKill(), get_droptarget_local_handle(), get_proc_address64(), get_process_name_from_pid(), GetOwnerModuleFromPidEntry(), GetProcessExecutablePathById(), GetProcessHandleFromHwnd(), GetProcessVersion(), GetThemeServiceProcessHandle(), Ghost_DestroyTarget(), IsProcessRunning(), ObjectFromLresult(), PerfDataGetCommandLine(), PerfDataRefresh(), PNP_ReportLogOn(), ProcessIdToSessionId(), ProcessKeys(), ProcessList_Update(), ProcessPage_OnEndProcess(), ProcessPage_OnEndProcessTree(), ProcessPage_OnSetAffinity(), ProcessPageShowContextMenu(), ProcessRunning(), SeclCreateProcessWithLogonW(), SHMapHandle(), ShutdownProcessTreeHelper(), START_TEST(), terminate_processes(), test_D3DKMTQueryVideoMemoryInfo(), test_duplicate_handle_access_child(), test_exception_dispatcher(), test_ExitProcess(), test_init_block(), test_nt_wow64(), test_OpenProcess(), test_parent_process_attribute(), test_process_id(), test_process_security_child(), test_query_process_handlecount(), test_query_process_times(), test_query_process_vm(), test_QueryFullProcessImageNameW(), test_readvirtualmemory(), test_syscalls(), test_Toolhelp(), test_ws_functions(), Toolhelp32ReadProcessMemory(), WSPDuplicateSocket(), and wWinMain().

◆ ProcessIdToSessionId()

BOOL WINAPI ProcessIdToSessionId ( IN DWORD  dwProcessId,
OUT PDWORD  pSessionId 
)

Definition at line 2074 of file proc.c.

2076{
2077 PROCESS_SESSION_INFORMATION SessionInformation;
2082
2083 /* Do a quick check if the pointer is not writable */
2084 if (IsBadWritePtr(pSessionId, sizeof(DWORD)))
2085 {
2086 /* Fail fast */
2088 return FALSE;
2089 }
2090
2091 /* Open the process passed in by ID */
2098 &ClientId);
2099 if (NT_SUCCESS(Status))
2100 {
2101 /* Query the session ID from the kernel */
2104 &SessionInformation,
2105 sizeof(SessionInformation),
2106 NULL);
2107
2108 /* Close the handle and check if we succeeded */
2110 if (NT_SUCCESS(Status))
2111 {
2112 /* Return the session ID */
2113 *pSessionId = SessionInformation.SessionId;
2114 return TRUE;
2115 }
2116 }
2117
2118 /* Set error code and fail */
2120 return FALSE;
2121}
BOOL NTAPI IsBadWritePtr(IN LPVOID lp, IN UINT_PTR ucb)
Definition: except.c:883
@ ProcessSessionInformation
Definition: winternl.h:1906

Referenced by AddPortW(), child_process_check_session_id(), ConfigurePortW(), START_TEST(), test_namedpipe_session_id(), and test_SHCreateSessionKey().

◆ ReadProcessMemory()

BOOL NTAPI ReadProcessMemory ( IN HANDLE  hProcess,
IN LPCVOID  lpBaseAddress,
IN LPVOID  lpBuffer,
IN SIZE_T  nSize,
OUT SIZE_T lpNumberOfBytesRead 
)

Definition at line 1922 of file proc.c.

1927{
1929
1930 /* Do the read */
1932 (PVOID)lpBaseAddress,
1933 lpBuffer,
1934 nSize,
1935 &nSize);
1936
1937 /* In user-mode, this parameter is optional */
1938 if (lpNumberOfBytesRead) *lpNumberOfBytesRead = nSize;
1939 if (!NT_SUCCESS(Status))
1940 {
1941 /* We failed */
1943 return FALSE;
1944 }
1945
1946 /* Return success */
1947 return TRUE;
1948}
_Out_ LPWSTR lpBuffer
Definition: netsh.h:68

◆ RegisterWaitForInputIdle()

VOID WINAPI RegisterWaitForInputIdle ( WaitForInputIdleType  lpfnRegisterWaitForInputIdle)

◆ SetPriorityClass()

BOOL WINAPI SetPriorityClass ( IN HANDLE  hProcess,
IN DWORD  dwPriorityClass 
)

Definition at line 1591 of file proc.c.

1593{
1595 PVOID State = NULL;
1596 PROCESS_PRIORITY_CLASS PriorityClass;
1597
1598 /* Handle conversion from Win32 to NT priority classes */
1599 switch (dwPriorityClass)
1600 {
1603 break;
1604
1607 break;
1608
1611 break;
1612
1615 break;
1616
1619 break;
1620
1622 /* Try to acquire the privilege. If it fails, just use HIGH */
1625 PriorityClass.PriorityClass += (State != NULL);
1626 break;
1627
1628 default:
1629 /* Unrecognized priority classes don't make it to the kernel */
1631 return FALSE;
1632 }
1633
1634 /* Send the request to the kernel, and don't touch the foreground flag */
1635 PriorityClass.Foreground = FALSE;
1638 &PriorityClass,
1639 sizeof(PROCESS_PRIORITY_CLASS));
1640
1641 /* Release the privilege if we had it */
1643 if (!NT_SUCCESS(Status))
1644 {
1645 /* Handle error path */
1647 return FALSE;
1648 }
1649
1650 /* All done */
1651 return TRUE;
1652}

Referenced by CsrSetPriorityClass(), DoSetPriority(), main(), test_query_process_priority(), UpdatePriority(), and wWinMain().

◆ SetProcessAffinityMask()

BOOL WINAPI SetProcessAffinityMask ( IN HANDLE  hProcess,
IN DWORD_PTR  dwProcessAffinityMask 
)

Definition at line 891 of file proc.c.

893{
895
896 /* Directly set the affinity mask */
899 (PVOID)&dwProcessAffinityMask,
900 sizeof(dwProcessAffinityMask));
901 if (!NT_SUCCESS(Status))
902 {
903 /* Handle failure */
905 return FALSE;
906 }
907
908 /* Everything was ok */
909 return TRUE;
910}
@ ProcessAffinityMask
Definition: winternl.h:1903

Referenced by AffinityDialogWndProc(), and cmd_start().

◆ SetProcessPriorityBoost()

BOOL WINAPI SetProcessPriorityBoost ( IN HANDLE  hProcess,
IN BOOL  bDisablePriorityBoost 
)

Definition at line 1816 of file proc.c.

1818{
1821
1822 /* Enforce that this is a BOOL, and send it to the kernel as a ULONG */
1823 PriorityBoost = (bDisablePriorityBoost ? TRUE : FALSE);
1827 sizeof(ULONG));
1828 if (!NT_SUCCESS(Status))
1829 {
1830 /* Handle error path */
1832 return FALSE;
1833 }
1834
1835 /* All done */
1836 return TRUE;
1837}

◆ SetProcessShutdownParameters()

BOOL WINAPI SetProcessShutdownParameters ( IN DWORD  dwLevel,
IN DWORD  dwFlags 
)

Definition at line 996 of file proc.c.

998{
999 BASE_API_MESSAGE ApiMessage;
1000 PBASE_GETSET_PROCESS_SHUTDOWN_PARAMS ShutdownParametersRequest = &ApiMessage.Data.ShutdownParametersRequest;
1001
1002 /* Write the data into the CSRSS request and send it */
1003 ShutdownParametersRequest->ShutdownLevel = dwLevel;
1004 ShutdownParametersRequest->ShutdownFlags = dwFlags;
1006 NULL,
1008 sizeof(*ShutdownParametersRequest));
1009 if (!NT_SUCCESS(ApiMessage.Status))
1010 {
1011 /* Return the failure from CSRSS */
1012 BaseSetLastNTError(ApiMessage.Status);
1013 return FALSE;
1014 }
1015
1016 /* All went well */
1017 return TRUE;
1018}
@ BasepSetProcessShutdownParam
Definition: basemsg.h:33
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141

Referenced by _tWinMain(), and wWinMain().

◆ SetProcessWorkingSetSize()

BOOL WINAPI SetProcessWorkingSetSize ( IN HANDLE  hProcess,
IN SIZE_T  dwMinimumWorkingSetSize,
IN SIZE_T  dwMaximumWorkingSetSize 
)

Definition at line 1130 of file proc.c.

1133{
1134 /* Call the newer API */
1136 dwMinimumWorkingSetSize,
1137 dwMaximumWorkingSetSize,
1138 0);
1139}
BOOL WINAPI SetProcessWorkingSetSizeEx(IN HANDLE hProcess, IN SIZE_T dwMinimumWorkingSetSize, IN SIZE_T dwMaximumWorkingSetSize, IN DWORD Flags)
Definition: proc.c:1074

◆ SetProcessWorkingSetSizeEx()

BOOL WINAPI SetProcessWorkingSetSizeEx ( IN HANDLE  hProcess,
IN SIZE_T  dwMinimumWorkingSetSize,
IN SIZE_T  dwMaximumWorkingSetSize,
IN DWORD  Flags 
)

Definition at line 1074 of file proc.c.

1078{
1079 QUOTA_LIMITS_EX QuotaLimits;
1080 NTSTATUS Status, ReturnStatus;
1081 BOOL Result;
1082 PVOID State;
1084
1085 /* Zero out the input structure */
1086 RtlZeroMemory(&QuotaLimits, sizeof(QuotaLimits));
1087
1088 /* Check if the caller sent any limits */
1089 if ((dwMinimumWorkingSetSize) && (dwMaximumWorkingSetSize))
1090 {
1091 /* Write the quota information */
1092 QuotaLimits.MinimumWorkingSetSize = dwMinimumWorkingSetSize;
1093 QuotaLimits.MaximumWorkingSetSize = dwMaximumWorkingSetSize;
1094 QuotaLimits.Flags = Flags;
1095
1096 /* Acquire the required privilege */
1098
1099 /* Request the new quotas */
1100 ReturnStatus = NtSetInformationProcess(hProcess,
1102 &QuotaLimits,
1103 sizeof(QuotaLimits));
1104 Result = NT_SUCCESS(ReturnStatus);
1105 if (NT_SUCCESS(Status))
1106 {
1107 /* Release the privilege and set succes code */
1108 ASSERT(State != NULL);
1110 State = NULL;
1111 }
1112 }
1113 else
1114 {
1115 /* No limits, fail the call */
1116 ReturnStatus = STATUS_INVALID_PARAMETER;
1117 Result = FALSE;
1118 }
1119
1120 /* Return result code, set error code if this was a failure */
1121 if (!Result) BaseSetLastNTError(ReturnStatus);
1122 return Result;
1123}
#define SE_INC_BASE_PRIORITY_PRIVILEGE
Definition: security.c:568
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
BOOL Privilege(LPTSTR pszPrivilege, BOOL bEnable)
Definition: user_lib.cpp:531

Referenced by EmptyWorkingSet(), and SetProcessWorkingSetSize().

◆ StuffStdHandle()

VOID WINAPI StuffStdHandle ( IN HANDLE  ProcessHandle,
IN HANDLE  StandardHandle,
IN PHANDLE  Address 
)

Definition at line 55 of file proc.c.

58{
60 HANDLE DuplicatedHandle;
61 SIZE_T NumberOfBytesWritten;
62
63 /* If there is no handle to duplicate, return immediately */
64 if (!StandardHandle) return;
65
66 /* Duplicate the handle */
68 StandardHandle,
70 &DuplicatedHandle,
71 0,
72 0,
75 if (!NT_SUCCESS(Status)) return;
76
77 /* Write it */
79 Address,
80 &DuplicatedHandle,
81 sizeof(HANDLE),
82 &NumberOfBytesWritten);
83}
#define DUPLICATE_SAME_ATTRIBUTES
Definition: obtypes.h:127
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:3437
static WCHAR Address[46]
Definition: ping.c:68
#define DUPLICATE_SAME_ACCESS

Referenced by CreateProcessInternalW().

◆ TerminateProcess()

BOOL WINAPI TerminateProcess ( IN HANDLE  hProcess,
IN UINT  uExitCode 
)

Definition at line 1425 of file proc.c.

1427{
1429
1430 /* Check if no handle was passed in */
1431 if (!hProcess)
1432 {
1433 /* Set error code */
1435 }
1436 else
1437 {
1438 /* Otherwise, try to terminate the process */
1439 Status = NtTerminateProcess(hProcess, uExitCode);
1440 if (NT_SUCCESS(Status)) return TRUE;
1441
1442 /* It failed, convert error code */
1444 }
1445
1446 /* This is the failure path */
1447 return FALSE;
1448}
#define ERROR_INVALID_HANDLE
Definition: compat.h:98

Referenced by child_process(), Telnet::Close(), CloseProcess(), common_message_window(), ConsoleIMERoutine(), CorDebug_CreateProcess(), cordebugprocess_Terminate(), CPlApplet(), crash_and_debug(), CreateProcessAsUserCommon(), do_register_dll(), DoTestEntry(), ExecuteKill(), ExecutePipeline(), exit_or_terminate_process(), Ghost_DestroyTarget(), ProcessKeys(), ProcessPage_OnEndProcess(), RaiseFailFastException(), read_reg_output_(), run_ex(), run_reg_exe_(), run_regedit_exe_(), runcmd(), RunProcessInJob(), ScreenSaverConfig(), ScreenSaverPageProc(), ScreenSaverPreview(), SetScreenSaverPreviewBox(), ShutdownProcessTreeHelper(), START_TEST(), StartScreenSaver(), terminate_processes(), TerminateShell(), test_apc_deadlock(), test_async_cancel_on_handle_close(), test_BreakawayOk(), test_CompletionPort(), test_CreateRemoteThread(), test_CtrlHandlerSubsystem(), test_debugger(), test_Directory(), TEST_DoTestEntryStruct(), test_EnumProcessModules(), test_ExitProcess(), test_GetProcessVersion(), test_IsProcessInJob(), test_IsWow64Process(), test_IsWow64Process2(), test_job_list_attribute(), test_kill_on_exit(), test_KillOnJobClose(), Test_layers(), test_loadpaths_execute(), test_nested_jobs(), test_nested_jobs_child(), test_NtMapViewOfSection(), test_NtMapViewOfSectionEx(), test_overlapped_transport(), test_peb_teb(), test_process_access(), test_query_architectures(), test_QueryInformationJobObject(), Test_repeatlayer(), test_RunSetupCommand(), test_section_access(), test_TerminateJobObject(), test_TerminateProcess(), test_VirtualAllocEx(), test_WaitForInputIdle(), TestTerminateProcess(), UnhandledExceptionFilter(), WshExec_Terminate(), wWinMain(), and CProcess::~CProcess().

◆ WriteProcessMemory()

BOOL NTAPI WriteProcessMemory ( IN HANDLE  hProcess,
IN LPVOID  lpBaseAddress,
IN LPCVOID  lpBuffer,
IN SIZE_T  nSize,
OUT SIZE_T lpNumberOfBytesWritten 
)

Definition at line 1955 of file proc.c.

1960{
1962 ULONG OldValue;
1964 PVOID Base;
1966
1967 /* Set parameters for protect call */
1968 RegionSize = nSize;
1969 Base = lpBaseAddress;
1970
1971 /* Check the current status */
1973 &Base,
1974 &RegionSize,
1976 &OldValue);
1977 if (NT_SUCCESS(Status))
1978 {
1979 /* Check if we are unprotecting */
1980 UnProtect = OldValue & (PAGE_READWRITE |
1984 if (!UnProtect)
1985 {
1986 /* Set the new protection */
1988 &Base,
1989 &RegionSize,
1990 OldValue,
1991 &OldValue);
1992
1993 /* Write the memory */
1995 lpBaseAddress,
1997 nSize,
1998 &nSize);
1999
2000 /* In Win32, the parameter is optional, so handle this case */
2001 if (lpNumberOfBytesWritten) *lpNumberOfBytesWritten = nSize;
2002
2003 if (!NT_SUCCESS(Status))
2004 {
2005 /* We failed */
2007 return FALSE;
2008 }
2009
2010 /* Flush the ITLB */
2011 NtFlushInstructionCache(hProcess, lpBaseAddress, nSize);
2012 return TRUE;
2013 }
2014 else
2015 {
2016 /* Check if we were read only */
2017 if (OldValue & (PAGE_NOACCESS | PAGE_READONLY))
2018 {
2019 /* Restore protection and fail */
2021 &Base,
2022 &RegionSize,
2023 OldValue,
2024 &OldValue);
2026
2027 /* Note: This is what Windows returns and code depends on it */
2029 }
2030
2031 /* Otherwise, do the write */
2033 lpBaseAddress,
2035 nSize,
2036 &nSize);
2037
2038 /* In Win32, the parameter is optional, so handle this case */
2039 if (lpNumberOfBytesWritten) *lpNumberOfBytesWritten = nSize;
2040
2041 /* And restore the protection */
2043 &Base,
2044 &RegionSize,
2045 OldValue,
2046 &OldValue);
2047 if (!NT_SUCCESS(Status))
2048 {
2049 /* We failed */
2051
2052 /* Note: This is what Windows returns and code depends on it */
2054 }
2055
2056 /* Flush the ITLB */
2057 NtFlushInstructionCache(hProcess, lpBaseAddress, nSize);
2058 return TRUE;
2059 }
2060 }
2061 else
2062 {
2063 /* We failed */
2065 return FALSE;
2066 }
2067}
#define PAGE_READONLY
Definition: compat.h:138
#define STATUS_ACCESS_VIOLATION
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2486
#define PAGE_WRITECOPY
Definition: nt_native.h:1308
#define PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1312
#define PAGE_NOACCESS
Definition: nt_native.h:1305
NTSTATUS NTAPI NtProtectVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UnsafeBaseAddress, IN OUT SIZE_T *UnsafeNumberOfBytesToProtect, IN ULONG NewAccessProtection, OUT PULONG UnsafeOldAccessProtection)
Definition: virtual.c:3076

Referenced by _DoDLLInjection(), hook_notification_function(), test_cross_process_notifications(), test_debugger(), test_notifications(), and test_VirtualAllocEx().

Variable Documentation

◆ BaseAnsiCommandLine

ANSI_STRING BaseAnsiCommandLine

Definition at line 21 of file proc.c.

Referenced by GetCommandLineA(), and InitCommandLines().

◆ BasepAppCertDllsList

LIST_ENTRY BasepAppCertDllsList

Definition at line 26 of file proc.c.

Referenced by BasepIsProcessAllowed(), and DllMain().

◆ BasepAppCertTable

RTL_QUERY_REGISTRY_TABLE BasepAppCertTable[2]
Initial value:
=
{
{
1,
L"AppCertDlls",
0,
0
}
}
NTSTATUS NTAPI BasepConfigureAppCertDlls(IN PWSTR ValueName, IN ULONG ValueType, IN PVOID ValueData, IN ULONG ValueLength, IN PVOID Context, IN PVOID EntryContext)
Definition: proc.c:187

Definition at line 30 of file proc.c.

Referenced by BasepIsProcessAllowed().

◆ BasePathVariableName

UNICODE_STRING BasePathVariableName = RTL_CONSTANT_STRING(L"PATH")

Definition at line 22 of file proc.c.

Referenced by BasepComputeProcessPath().

◆ BasepExeLdrEntry

PLDR_DATA_TABLE_ENTRY BasepExeLdrEntry

Definition at line 23 of file proc.c.

Referenced by BasepComputeProcessPath(), BasepLocateExeLdrEntry(), and LoadLibraryExW().

◆ BaseUnicodeCommandLine

UNICODE_STRING BaseUnicodeCommandLine

Definition at line 20 of file proc.c.

Referenced by GetCommandLineW(), and InitCommandLines().

◆ fEmbeddedCertFunc

PBASEP_APPCERT_EMBEDDED_FUNC fEmbeddedCertFunc

Definition at line 28 of file proc.c.

Referenced by BasepIsProcessAllowed().

◆ g_AppCertInitialized

BOOLEAN g_AppCertInitialized

Definition at line 24 of file proc.c.

Referenced by BasepIsProcessAllowed().

◆ g_AppCertStatus

NTSTATUS g_AppCertStatus

Definition at line 29 of file proc.c.

Referenced by BasepIsProcessAllowed().

◆ g_HaveAppCerts

BOOLEAN g_HaveAppCerts

Definition at line 25 of file proc.c.

Referenced by BasepIsProcessAllowed().

◆ g_SaferReplaceProcessThreadTokens

PSAFER_REPLACE_PROCESS_THREAD_TOKENS g_SaferReplaceProcessThreadTokens

Definition at line 43 of file proc.c.

Referenced by BasepReplaceProcessThreadTokens().

◆ gcsAppCert

Definition at line 27 of file proc.c.

Referenced by BasepIsProcessAllowed(), BasepReplaceProcessThreadTokens(), and DllMain().

◆ gSaferHandle

HMODULE gSaferHandle = (HMODULE)-1

Definition at line 44 of file proc.c.

Referenced by BasepReplaceProcessThreadTokens().