ReactOS  0.4.14-dev-884-ga57f7b5
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 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)
 
VOID WINAPI BaseProcessStartup (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)
 
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 RegisterWaitForInputIdle (IN WaitForInputIdleType lpfnRegisterWaitForInputIdle)
 
VOID WINAPI GetStartupInfoW (IN LPSTARTUPINFOW lpStartupInfo)
 
VOID WINAPI GetStartupInfoA (IN LPSTARTUPINFOA 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)
 
BOOL WINAPI CreateProcessInternalA (HANDLE hToken, LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation, PHANDLE hNewToken)
 
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA (LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
 
UINT WINAPI DECLSPEC_HOTPATCH WinExec (LPCSTR lpCmdLine, UINT uCmdShow)
 

Variables

WaitForInputIdleType UserWaitForInputIdleRoutine
 
UNICODE_STRING BaseUnicodeCommandLine
 
ANSI_STRING BaseAnsiCommandLine
 
UNICODE_STRING BasePathVariableName = RTL_CONSTANT_STRING(L"PATH")
 
LPSTARTUPINFOA BaseAnsiStartupInfo = NULL
 
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 2225 of file proc.c.

◆ CMD_STRING

#define CMD_STRING   L"cmd /c "

Definition at line 51 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 2226 of file proc.c.

Function Documentation

◆ BasepCheckWebBladeHashes()

NTSTATUS WINAPI BasepCheckWebBladeHashes ( IN HANDLE  FileHandle)

Definition at line 149 of file proc.c.

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

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 189 of file proc.c.

195 {
196  /* Add this to the certification list */
198 }
NTSTATUS NTAPI BasepSaveAppCertRegistryValue(IN PLIST_ENTRY List, IN PWCHAR ComponentName, IN PWCHAR DllName)
Definition: proc.c:178
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:311

◆ BasepIsImageVersionOk()

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

Definition at line 123 of file proc.c.

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

Referenced by CreateProcessInternalW().

◆ BasepIsProcessAllowed()

NTSTATUS WINAPI BasepIsProcessAllowed ( IN LPWSTR  ApplicationName)

Definition at line 202 of file proc.c.

203 {
204  NTSTATUS Status, Status1;
205  PWCHAR Buffer;
206  UINT Length;
207  HMODULE TrustLibrary;
209  ULONG CertFlag;
210  PLIST_ENTRY NextEntry;
212  UNICODE_STRING CertKey = RTL_CONSTANT_STRING(L"\\Registry\\MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\AppCertDlls");
214 
215  /* Try to initialize the certification subsystem */
216  while (!g_AppCertInitialized)
217  {
218  /* Defaults */
220  Buffer = NULL;
221 
222  /* Acquire the lock while initializing and see if we lost a race */
224  if (g_AppCertInitialized) break;
225 
226  /* On embedded, there is a special DLL */
227  if (SharedUserData->SuiteMask & VER_SUITE_EMBEDDEDNT)
228  {
229  /* Allocate a buffer for the name */
230  Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
231  0,
232  MAX_PATH * sizeof(WCHAR) +
233  sizeof(UNICODE_NULL));
234  if (!Buffer)
235  {
236  /* Fail if no memory */
238  }
239  else
240  {
241  /* Now get the system32 directory in our buffer, make sure it fits */
242  Length = GetSystemDirectoryW(Buffer, MAX_PATH - sizeof("EmbdTrst.DLL"));
243  if ((Length) && (Length <= MAX_PATH - sizeof("EmbdTrst.DLL")))
244  {
245  /* Add a slash if needed, and add the embedded cert DLL name */
246  if (Buffer[Length - 1] != '\\') Buffer[Length++] = '\\';
248  L"EmbdTrst.DLL",
249  sizeof(L"EmbdTrst.DLL"));
250 
251  /* Try to load it */
252  TrustLibrary = LoadLibraryW(Buffer);
253  if (TrustLibrary)
254  {
255  /* And extract the special function out of it */
256  fEmbeddedCertFunc = (PVOID)GetProcAddress(TrustLibrary,
257  "ImageOkToRunOnEmbeddedNT");
258  }
259  }
260 
261  /* If we didn't get this far, set a failure code */
263  }
264  }
265  else
266  {
267  /* Other systems have a registry entry for this */
268  Status1 = NtOpenKey(&KeyHandle, KEY_READ, &KeyAttributes);
269  if (NT_SUCCESS(Status1))
270  {
271  /* Close it, we'll query it through Rtl */
273 
274  /* Do the query, which will call a special callback */
276  L"Session Manager",
278  NULL,
279  NULL);
281  {
283  }
284  }
285  }
286 
287  /* Free any buffer if we had one */
288  if (Buffer) RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
289 
290  /* Check for errors, or a missing embedded/custom certification DLL */
291  if (!NT_SUCCESS(Status) ||
293  {
294  /* The subsystem is not active on this machine, so give up */
297  }
298  else
299  {
300  /* We have certification DLLs active, remember this */
302  }
303 
304  /* We are done the initialization phase, release the lock */
307  }
308 
309  /* If there's no certification DLLs present, return the failure code */
310  if (!g_HaveAppCerts) return g_AppCertStatus;
311 
312  /* Otherwise, assume success and make sure we have *something* */
315 
316  /* If the something is an embedded certification DLL, call it and return */
318 
319  /* Otherwise we have custom certification DLLs, parse them */
320  NextEntry = BasepAppCertDllsList.Flink;
321  CertFlag = 2;
322  while (NextEntry != &BasepAppCertDllsList)
323  {
324  /* Make sure the entry has a callback */
326  ASSERT(Entry->fPluginCertFunc != NULL);
327 
328  /* Call it and check if it failed */
329  Status = Entry->fPluginCertFunc(ApplicationName, 1);
330  if (!NT_SUCCESS(Status)) CertFlag = 3;
331 
332  /* Move on */
333  NextEntry = NextEntry->Flink;
334  }
335 
336  /* Now loop them again */
337  NextEntry = BasepAppCertDllsList.Flink;
338  while (NextEntry != &BasepAppCertDllsList)
339  {
340  /* Make sure the entry has a callback */
342  ASSERT(Entry->fPluginCertFunc != NULL);
343 
344  /* Call it, this time with the flag from the loop above */
345  Status = Entry->fPluginCertFunc(ApplicationName, CertFlag);
346  }
347 
348  /* All done, return the status */
349  return Status;
350 }
NTSTATUS g_AppCertStatus
Definition: proc.c:31
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
RTL_CRITICAL_SECTION gcsAppCert
Definition: proc.c:29
struct _Entry Entry
Definition: kefuncs.h:627
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define KEY_READ
Definition: nt_native.h:1023
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
BOOLEAN g_AppCertInitialized
Definition: proc.c:26
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
uint16_t * PWCHAR
Definition: typedefs.h:55
#define RTL_REGISTRY_CONTROL
Definition: nt_native.h:163
Definition: kernel32.h:385
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
BOOLEAN g_HaveAppCerts
Definition: proc.c:27
#define UNICODE_NULL
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define LoadLibraryW(x)
Definition: compat.h:412
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_PATH
Definition: compat.h:26
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define SharedUserData
static const WCHAR L[]
Definition: oid.c:1250
Definition: typedefs.h:118
Status
Definition: gdiplustypes.h:24
#define RTL_CONSTANT_OBJECT_ATTRIBUTES(n, a)
#define VER_SUITE_EMBEDDEDNT
PVOID PVOID PWCHAR ApplicationName
Definition: env.c:45
RTL_QUERY_REGISTRY_TABLE BasepAppCertTable[2]
Definition: proc.c:32
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
PBASEP_APPCERT_EMBEDDED_FUNC fEmbeddedCertFunc
Definition: proc.c:30
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2312
unsigned int UINT
Definition: ndis.h:50
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
LIST_ENTRY BasepAppCertDllsList
Definition: proc.c:28
unsigned int ULONG
Definition: retypes.h:1
#define GetProcAddress(x, y)
Definition: compat.h:418
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2938
base of all file and directory entries
Definition: entries.h:82
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by CreateProcessInternalW().

◆ BasepReplaceProcessThreadTokens()

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

Definition at line 354 of file proc.c.

357 {
359  ANSI_STRING SaferiReplaceProcessThreadTokens = RTL_CONSTANT_STRING("SaferiReplaceProcessThreadTokens");
360 
361  /* Enter the application certification lock */
363 
364  /* Check if we already know the function */
366  {
367  /* Call it */
370  ThreadHandle) ?
373  }
374  else
375  {
376  /* Check if the app certification DLL isn't loaded */
377  if (!(gSaferHandle) ||
378  (gSaferHandle == (HMODULE)-1) ||
379  (gSaferHandle == (HMODULE)-2))
380  {
381  /* Then we can't call the function */
383  }
384  else
385  {
386  /* We have the DLL, find the address of the Safer function */
388  &SaferiReplaceProcessThreadTokens,
389  0,
391  if (NT_SUCCESS(Status))
392  {
393  /* Found it, now call it */
396  ThreadHandle) ?
399  }
400  else
401  {
402  /* We couldn't find it, so this must be an unsupported DLL */
404  gSaferHandle = NULL;
406  }
407  }
408  }
409 
410  /* Release the lock and return the result */
412  return Status;
413 }
RTL_CRITICAL_SECTION gcsAppCert
Definition: proc.c:29
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
PSAFER_REPLACE_PROCESS_THREAD_TOKENS g_SaferReplaceProcessThreadTokens
Definition: proc.c:45
NTSTATUS NTAPI LdrGetProcedureAddress(IN PVOID BaseAddress, IN PANSI_STRING Name, IN ULONG Ordinal, OUT PVOID *ProcedureAddress)
Definition: ldrapi.c:823
smooth NULL
Definition: ftsmooth.c:416
_In_ ACCESS_MASK _In_ ULONG _Out_ PHANDLE TokenHandle
Definition: psfuncs.h:715
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI LdrUnloadDll(IN PVOID BaseAddress)
Definition: ldrapi.c:1322
HMODULE gSaferHandle
Definition: proc.c:46
#define STATUS_ENTRYPOINT_NOT_FOUND
Definition: ntstatus.h:535
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by CreateProcessInternalW().

◆ BaseProcessStartup()

VOID WINAPI BaseProcessStartup ( PPROCESS_START_ROUTINE  lpStartAddress)

Definition at line 450 of file proc.c.

451 {
452  DPRINT("BaseProcessStartup(..) - setting up exception frame.\n");
453 
454  _SEH2_TRY
455  {
456  /* Set our Start Address */
459  &lpStartAddress,
460  sizeof(PPROCESS_START_ROUTINE));
461 
462  /* Call the Start Routine */
463  ExitThread(lpStartAddress());
464  }
466  {
467  /* Get the Exit code from the SEH Handler */
469  {
470  /* Kill the whole process, usually */
472  }
473  else
474  {
475  /* If running inside CSRSS, kill just this thread */
477  }
478  }
479  _SEH2_END;
480 }
#define NtCurrentThread()
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1487
_SEH2_TRY
Definition: create.c:4250
LONG WINAPI UnhandledExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo)
Definition: except.c:262
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:11
void DPRINT(...)
Definition: polytest.cpp:61
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:364
NTSTATUS NTAPI NtSetInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, IN PVOID ThreadInformation, IN ULONG ThreadInformationLength)
Definition: query.c:2014
BOOLEAN BaseRunningInServerProcess
Definition: dllmain.c:20
_SEH2_END
Definition: create.c:4424
UINT(WINAPI * PPROCESS_START_ROUTINE)(VOID)
Definition: kernel32.h:248
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12

◆ BasepSaveAppCertRegistryValue()

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

Definition at line 178 of file proc.c.

181 {
182  /* Pretty much the only thing this key is used for, is malware */
184  return STATUS_NOT_IMPLEMENTED;
185 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

Referenced by BasepConfigureAppCertDlls().

◆ BasepSxsCloseHandles()

VOID WINAPI BasepSxsCloseHandles ( IN PBASE_MSG_SXS_HANDLES  Handles)

Definition at line 417 of file proc.c.

418 {
420 
421  /* Sanity checks */
422  ASSERT(Handles != NULL);
423  ASSERT(Handles->Process == NULL || Handles->Process == NtCurrentProcess());
424 
425  /* Close the file handle */
426  if (Handles->File)
427  {
428  Status = NtClose(Handles->File);
430  }
431 
432  /* Close the section handle */
433  if (Handles->Section)
434  {
435  Status = NtClose(Handles->Section);
437  }
438 
439  /* Unmap the section view */
440  if (Handles->ViewBase.QuadPart)
441  {
443  (PVOID)(ULONG_PTR)Handles->ViewBase.QuadPart);
445  }
446 }
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3782
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:64
smooth NULL
Definition: ftsmooth.c:416
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24

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 484 of file proc.c.

497 {
498  WCHAR FullPath[MAX_PATH + 5];
499  PWCHAR Remaining, DllPathString, ScanChar;
500  PRTL_USER_PROCESS_PARAMETERS ProcessParameters, RemoteParameters;
501  PVOID RemoteAppCompatData;
503  UNICODE_STRING Desktop, Shell, Runtime, Title;
505  ULONG EnviroSize;
506  SIZE_T Size;
507  BOOLEAN HavePebLock = FALSE, Result;
508  PPEB Peb = NtCurrentPeb();
509 
510  /* Get the full path name */
511  Size = GetFullPathNameW(ApplicationPathName,
512  MAX_PATH + 4,
513  FullPath,
514  &Remaining);
515  if ((Size) && (Size <= (MAX_PATH + 4)))
516  {
517  /* Get the DLL Path */
518  DllPathString = BaseComputeProcessDllPath(FullPath, lpEnvironment);
519  if (!DllPathString)
520  {
521  /* Fail */
523  return FALSE;
524  }
525 
526  /* Initialize Strings */
527  RtlInitUnicodeString(&DllPath, DllPathString);
528  RtlInitUnicodeString(&ImageName, FullPath);
529  }
530  else
531  {
532  /* Couldn't get the path name. Just take the original path */
533  DllPathString = BaseComputeProcessDllPath((LPWSTR)ApplicationPathName,
534  lpEnvironment);
535  if (!DllPathString)
536  {
537  /* Fail */
539  return FALSE;
540  }
541 
542  /* Initialize Strings */
543  RtlInitUnicodeString(&DllPath, DllPathString);
544  RtlInitUnicodeString(&ImageName, ApplicationPathName);
545  }
546 
547  /* Initialize Strings */
548  RtlInitUnicodeString(&CommandLine, lpCommandLine);
549  RtlInitUnicodeString(&CurrentDirectory, lpCurrentDirectory);
550 
551  /* Initialize more Strings from the Startup Info */
552  if (StartupInfo->lpDesktop)
553  {
554  RtlInitUnicodeString(&Desktop, StartupInfo->lpDesktop);
555  }
556  else
557  {
559  }
560  if (StartupInfo->lpReserved)
561  {
562  RtlInitUnicodeString(&Shell, StartupInfo->lpReserved);
563  }
564  else
565  {
567  }
568  if (StartupInfo->lpTitle)
569  {
570  RtlInitUnicodeString(&Title, StartupInfo->lpTitle);
571  }
572  else
573  {
574  RtlInitUnicodeString(&Title, ApplicationPathName);
575  }
576 
577  /* This one is special because the length can differ */
578  Runtime.Buffer = (LPWSTR)StartupInfo->lpReserved2;
579  Runtime.MaximumLength = Runtime.Length = StartupInfo->cbReserved2;
580 
581  /* Enforce no app compat data if the pointer was NULL */
582  if (!AppCompatData) AppCompatDataSize = 0;
583 
584  /* Create the Parameter Block */
585  ProcessParameters = NULL;
586  DPRINT("ImageName: '%wZ'\n", &ImageName);
587  DPRINT("DllPath : '%wZ'\n", &DllPath);
588  DPRINT("CurDir : '%wZ'\n", &CurrentDirectory);
589  DPRINT("CmdLine : '%wZ'\n", &CommandLine);
590  DPRINT("Title : '%wZ'\n", &Title);
591  DPRINT("Desktop : '%wZ'\n", &Desktop);
592  DPRINT("Shell : '%wZ'\n", &Shell);
593  DPRINT("Runtime : '%wZ'\n", &Runtime);
594  Status = RtlCreateProcessParameters(&ProcessParameters,
595  &ImageName,
596  &DllPath,
597  lpCurrentDirectory ?
599  &CommandLine,
600  lpEnvironment,
601  &Title,
602  &Desktop,
603  &Shell,
604  &Runtime);
605  if (!NT_SUCCESS(Status)) goto FailPath;
606 
607  /* Clear the current directory handle if not inheriting */
608  if (!InheritHandles) ProcessParameters->CurrentDirectory.Handle = NULL;
609 
610  /* Check if the user passed in an environment */
611  if (lpEnvironment)
612  {
613  /* We should've made it part of the parameters block, enforce this */
614  ASSERT(ProcessParameters->Environment == lpEnvironment);
615  lpEnvironment = ProcessParameters->Environment;
616  }
617  else
618  {
619  /* The user did not, so use the one from the current PEB */
620  HavePebLock = TRUE;
622  lpEnvironment = Peb->ProcessParameters->Environment;
623  }
624 
625  /* Save pointer and start lookup */
626  ScanChar = lpEnvironment;
627  if (lpEnvironment)
628  {
629  /* Find the environment size */
630  while (*ScanChar++) while (*ScanChar++);
631  EnviroSize = (ULONG)((ULONG_PTR)ScanChar - (ULONG_PTR)lpEnvironment);
632 
633  /* Allocate and Initialize new Environment Block */
634  Size = EnviroSize;
635  ProcessParameters->Environment = NULL;
637  (PVOID*)&ProcessParameters->Environment,
638  0,
639  &Size,
640  MEM_COMMIT,
642  if (!NT_SUCCESS(Status)) goto FailPath;
643 
644  /* Write the Environment Block */
646  ProcessParameters->Environment,
647  lpEnvironment,
648  EnviroSize,
649  NULL);
650 
651  /* No longer need the PEB lock anymore */
652  if (HavePebLock)
653  {
654  /* Release it */
656  HavePebLock = FALSE;
657  }
658 
659  /* Check if the write failed */
660  if (!NT_SUCCESS(Status)) goto FailPath;
661  }
662 
663  /* Write new parameters */
664  ProcessParameters->StartingX = StartupInfo->dwX;
665  ProcessParameters->StartingY = StartupInfo->dwY;
666  ProcessParameters->CountX = StartupInfo->dwXSize;
667  ProcessParameters->CountY = StartupInfo->dwYSize;
668  ProcessParameters->CountCharsX = StartupInfo->dwXCountChars;
669  ProcessParameters->CountCharsY = StartupInfo->dwYCountChars;
670  ProcessParameters->FillAttribute = StartupInfo->dwFillAttribute;
671  ProcessParameters->WindowFlags = StartupInfo->dwFlags;
672  ProcessParameters->ShowWindowFlags = StartupInfo->wShowWindow;
673 
674  /* Write the handles only if we have to */
675  if (StartupInfo->dwFlags &
676  (STARTF_USESTDHANDLES | STARTF_USEHOTKEY | STARTF_SHELLPRIVATE))
677  {
678  ProcessParameters->StandardInput = StartupInfo->hStdInput;
679  ProcessParameters->StandardOutput = StartupInfo->hStdOutput;
680  ProcessParameters->StandardError = StartupInfo->hStdError;
681  }
682 
683  /* Use Special Flags for ConDllInitialize in Kernel32 */
684  if (CreationFlags & DETACHED_PROCESS)
685  {
686  ProcessParameters->ConsoleHandle = HANDLE_DETACHED_PROCESS;
687  }
688  else if (CreationFlags & CREATE_NEW_CONSOLE)
689  {
690  ProcessParameters->ConsoleHandle = HANDLE_CREATE_NEW_CONSOLE;
691  }
692  else if (CreationFlags & CREATE_NO_WINDOW)
693  {
694  ProcessParameters->ConsoleHandle = HANDLE_CREATE_NO_WINDOW;
695  }
696  else
697  {
698  /* Inherit our Console Handle */
699  ProcessParameters->ConsoleHandle = Peb->ProcessParameters->ConsoleHandle;
700 
701  /* Make sure that the shell isn't trampling on our handles first */
702  if (!(StartupInfo->dwFlags &
703  (STARTF_USESTDHANDLES | STARTF_USEHOTKEY | STARTF_SHELLPRIVATE)))
704  {
705  /* Copy the handle if we are inheriting or if it's a console handle */
706  if ((InheritHandles) ||
708  {
709  ProcessParameters->StandardInput = Peb->ProcessParameters->StandardInput;
710  }
711  if ((InheritHandles) ||
713  {
714  ProcessParameters->StandardOutput = Peb->ProcessParameters->StandardOutput;
715  }
716  if ((InheritHandles) ||
718  {
719  ProcessParameters->StandardError = Peb->ProcessParameters->StandardError;
720  }
721  }
722  }
723 
724  /* Also set the Console Flag */
725  if ((CreationFlags & CREATE_NEW_PROCESS_GROUP) &&
726  (!(CreationFlags & CREATE_NEW_CONSOLE)))
727  {
728  ProcessParameters->ConsoleFlags = 1;
729  }
730 
731  /* Check if there's a .local file present */
732  if (ParameterFlags & 1)
733  {
735  }
736 
737  /* Check if we failed to open the IFEO key */
738  if (ParameterFlags & 2)
739  {
741  }
742 
743  /* Allocate memory for the parameter block */
744  Size = ProcessParameters->Length;
745  RemoteParameters = NULL;
747  (PVOID*)&RemoteParameters,
748  0,
749  &Size,
750  MEM_COMMIT,
752  if (!NT_SUCCESS(Status)) goto FailPath;
753 
754  /* Set the allocated size */
755  ProcessParameters->MaximumLength = Size;
756 
757  /* Handle some Parameter Flags */
758  ProcessParameters->Flags |= (CreationFlags & PROFILE_USER) ?
760  ProcessParameters->Flags |= (CreationFlags & PROFILE_KERNEL) ?
762  ProcessParameters->Flags |= (CreationFlags & PROFILE_SERVER) ?
764  ProcessParameters->Flags |= (Peb->ProcessParameters->Flags &
766 
767  /* Write the Parameter Block */
769  RemoteParameters,
770  ProcessParameters,
771  ProcessParameters->Length,
772  NULL);
773  if (!NT_SUCCESS(Status)) goto FailPath;
774 
775  /* Write the PEB Pointer */
777  &RemotePeb->ProcessParameters,
778  &RemoteParameters,
779  sizeof(PVOID),
780  NULL);
781  if (!NT_SUCCESS(Status)) goto FailPath;
782 
783  /* Check if there's any app compat data to write */
784  RemoteAppCompatData = NULL;
785  if (AppCompatData)
786  {
787  /* Allocate some space for the application compatibility data */
788  Size = AppCompatDataSize;
790  &RemoteAppCompatData,
791  0,
792  &Size,
793  MEM_COMMIT,
795  if (!NT_SUCCESS(Status)) goto FailPath;
796 
797  /* Write the application compatibility data */
799  RemoteAppCompatData,
800  AppCompatData,
801  AppCompatDataSize,
802  NULL);
803  if (!NT_SUCCESS(Status)) goto FailPath;
804  }
805 
806  /* Write the PEB Pointer to the app compat data (might be NULL) */
808  &RemotePeb->pShimData,
809  &RemoteAppCompatData,
810  sizeof(PVOID),
811  NULL);
812  if (!NT_SUCCESS(Status)) goto FailPath;
813 
814  /* Now write Peb->ImageSubSystem */
815  if (ImageSubsystem)
816  {
818  &RemotePeb->ImageSubsystem,
819  &ImageSubsystem,
820  sizeof(ImageSubsystem),
821  NULL);
822  }
823 
824  /* Success path */
825  Result = TRUE;
826 
827 Quickie:
828  /* Cleanup */
829  if (HavePebLock) RtlReleasePebLock();
830  RtlFreeHeap(RtlGetProcessHeap(), 0, DllPath.Buffer);
831  if (ProcessParameters) RtlDestroyProcessParameters(ProcessParameters);
832  return Result;
833 FailPath:
834  DPRINT1("Failure to create process parameters: %lx\n", Status);
836  Result = FALSE;
837  goto Quickie;
838 }
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 TRUE
Definition: types.h:120
PPEB Peb
Definition: dllmain.c:27
#define RTL_USER_PROCESS_PARAMETERS_IMAGE_KEY_MISSING
Definition: rtltypes.h:54
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define HANDLE_DETACHED_PROCESS
Definition: console.h:13
#define HANDLE_CREATE_NO_WINDOW
Definition: console.h:15
WCHAR CurrentDirectory[1024]
Definition: chkdsk.c:74
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define PROFILE_KERNEL
Definition: winbase.h:197
NTSYSAPI NTSTATUS NTAPI RtlDestroyProcessParameters(_In_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters)
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1105
VOID NTAPI RtlReleasePebLock(VOID)
Definition: libsupp.c:82
uint16_t * PWCHAR
Definition: typedefs.h:55
#define CREATE_NEW_PROCESS_GROUP
Definition: winbase.h:185
#define MEM_COMMIT
Definition: nt_native.h:1313
#define PROFILE_USER
Definition: winbase.h:196
uint32_t ULONG_PTR
Definition: typedefs.h:64
#define CREATE_NO_WINDOW
Definition: winbase.h:195
#define STARTF_SHELLPRIVATE
Definition: kernel32.h:60
#define RTL_USER_PROCESS_PARAMETERS_PROFILE_USER
Definition: rtltypes.h:42
unsigned char BOOLEAN
#define RTL_USER_PROCESS_PARAMETERS_PROFILE_KERNEL
Definition: rtltypes.h:43
smooth NULL
Definition: ftsmooth.c:416
_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:426
void DPRINT(...)
Definition: polytest.cpp:61
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
static CHAR Desktop[MAX_PATH]
Definition: dem.c:256
#define STARTF_USESTDHANDLES
Definition: winbase.h:480
#define HANDLE_CREATE_NEW_CONSOLE
Definition: console.h:14
#define CREATE_NEW_CONSOLE
Definition: winbase.h:180
static const WCHAR Title[]
Definition: oid.c:1259
if(!(yy_init))
Definition: macro.lex.yy.c:714
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define RTL_USER_PROCESS_PARAMETERS_PROFILE_SERVER
Definition: rtltypes.h:44
#define MAX_PATH
Definition: compat.h:26
#define SetLastError(x)
Definition: compat.h:417
#define IsConsoleHandle(h)
Definition: console.h:14
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const char * ImageName
Definition: image.c:34
static const WCHAR L[]
Definition: oid.c:1250
#define RTL_USER_PROCESS_PARAMETERS_DISABLE_HEAP_CHECKS
Definition: rtltypes.h:49
PRTL_USER_PROCESS_PARAMETERS ProcessParameters
Definition: btrfs_drv.h:1890
static int Shell(const char **args)
Definition: vfdcmd.c:1020
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
LPWSTR WINAPI BaseComputeProcessDllPath(IN LPWSTR FullPath, IN PVOID Environment)
Definition: path.c:420
ULONG_PTR SIZE_T
Definition: typedefs.h:79
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:4367
#define NtCurrentPeb()
Definition: FLS.c:20
static const char const char * DllPath
Definition: image.c:34
#define DETACHED_PROCESS
Definition: winbase.h:179
VOID NTAPI RtlAcquirePebLock(VOID)
Definition: libsupp.c:72
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
HANDLE Handle
Definition: rtltypes.h:1363
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ULONG_PTR
Definition: config.h:101
#define PROFILE_SERVER
Definition: winbase.h:198
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define RTL_USER_PROCESS_PARAMETERS_LOCAL_DLL_PATH
Definition: rtltypes.h:53
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
NTSTATUS NTAPI NtWriteVirtualMemory(IN HANDLE ProcessHandle, IN PVOID BaseAddress, IN PVOID Buffer, IN SIZE_T NumberOfBytesToWrite, OUT PSIZE_T NumberOfBytesWritten OPTIONAL)
Definition: virtual.c:2805
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by CreateProcessInternalW().

◆ BuildSubSysCommandLine()

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

Definition at line 89 of file proc.c.

93 {
94  UNICODE_STRING CommandLineString, ApplicationNameString;
95  PWCHAR Buffer;
96  ULONG Length;
97 
98  /* Convert to unicode strings */
99  RtlInitUnicodeString(&CommandLineString, ApplicationName);
100  RtlInitUnicodeString(&ApplicationNameString, CommandLine);
101 
102  /* Allocate buffer for the output string */
103  Length = CommandLineString.MaximumLength + ApplicationNameString.MaximumLength + 32;
104  Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length);
105  RtlInitEmptyUnicodeString(SubsysCommandLine, Buffer, (USHORT)Length);
106  if (!Buffer)
107  {
108  /* Fail, no memory */
110  return FALSE;
111  }
112 
113  /* Build the final subsystem command line */
114  RtlAppendUnicodeToString(SubsysCommandLine, SubsystemName);
115  RtlAppendUnicodeStringToString(SubsysCommandLine, &CommandLineString);
116  RtlAppendUnicodeToString(SubsysCommandLine, L" /C ");
117  RtlAppendUnicodeStringToString(SubsysCommandLine, &ApplicationNameString);
118  return TRUE;
119 }
#define TRUE
Definition: types.h:120
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWCHAR
Definition: typedefs.h:55
Definition: bufpool.h:45
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static const WCHAR L[]
Definition: oid.c:1250
PVOID PVOID PWCHAR ApplicationName
Definition: env.c:45
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by CreateProcessInternalW().

◆ C_ASSERT()

◆ CreateProcessA()

BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA ( LPCSTR  lpApplicationName,
LPSTR  lpCommandLine,
LPSECURITY_ATTRIBUTES  lpProcessAttributes,
LPSECURITY_ATTRIBUTES  lpThreadAttributes,
BOOL  bInheritHandles,
DWORD  dwCreationFlags,
LPVOID  lpEnvironment,
LPCSTR  lpCurrentDirectory,
LPSTARTUPINFOA  lpStartupInfo,
LPPROCESS_INFORMATION  lpProcessInformation 
)

Definition at line 4742 of file proc.c.

4752 {
4753  /* Call the internal (but exported) version */
4755  lpApplicationName,
4756  lpCommandLine,
4757  lpProcessAttributes,
4758  lpThreadAttributes,
4759  bInheritHandles,
4760  dwCreationFlags,
4761  lpEnvironment,
4762  lpCurrentDirectory,
4763  lpStartupInfo,
4764  lpProcessInformation,
4765  NULL);
4766 }
BOOL WINAPI CreateProcessInternalA(HANDLE hToken, LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation, PHANDLE hNewToken)
Definition: proc.c:4624
smooth NULL
Definition: ftsmooth.c:416

Referenced by _create_process(), cmd_available(), CommandThreadProc(), crash_and_debug(), crash_and_winedbg(), create_proc(), create_process(), create_server_process(), create_target_process(), create_writepipe_process(), CreateProcessAsUserA(), do_parent(), doChildren(), DoTestEntry(), fork_helper(), IDirectPlayLobby3AImpl_RunApplication(), LoadModule(), run_child_process(), run_client(), run_cmd(), run_ex(), run_process(), run_reg_exe_(), run_regedit_exe_(), run_script_file(), runcmd(), start_server(), START_TEST(), system(), test___getmainargs_parent(), test_alloc_shared(), test_apc_deadlock(), test_BreakawayOk(), test_comctl32_classes(), test_CommandLine(), test_Console(), test_CreateProcessWithDesktop(), test_debug_children(), test_debug_heap(), test_debug_loop(), test_DebuggingFlag(), test_DetachConsoleHandles(), test_DetachStdHandles(), test_Directory(), test_EnumProcessModules(), test_Environment(), test_ExitCode(), test_ExitProcess(), test_GetProcessVersion(), test_internet_features(), test_invalid_stdin(), test_IsWow64Process(), test_jobInheritance(), test_LresultFromObject(), test_NonExistentPath(), test_NtSuspendProcess(), test_process_access(), test_process_security(), test_query_process_debug_flags(), test_query_process_debug_object_handle(), test_query_process_debug_port(), test_section_access(), test_shared_memory(), test_shared_memory_ro(), test_Startup(), test_StartupNoConsole(), test_stdout_handle(), test_SuspendFlag(), test_TerminateProcess(), test_token_security_descriptor(), test_Toolhelp(), test_WaitForInputIdle(), test_window_from_point(), test_winproc_handles(), and WinExec().

◆ CreateProcessInternalA()

BOOL WINAPI CreateProcessInternalA ( HANDLE  hToken,
LPCSTR  lpApplicationName,
LPSTR  lpCommandLine,
LPSECURITY_ATTRIBUTES  lpProcessAttributes,
LPSECURITY_ATTRIBUTES  lpThreadAttributes,
BOOL  bInheritHandles,
DWORD  dwCreationFlags,
LPVOID  lpEnvironment,
LPCSTR  lpCurrentDirectory,
LPSTARTUPINFOA  lpStartupInfo,
LPPROCESS_INFORMATION  lpProcessInformation,
PHANDLE  hNewToken 
)

Definition at line 4624 of file proc.c.

4636 {
4637  UNICODE_STRING CommandLine;
4640  BOOL bRetVal;
4641  STARTUPINFOW StartupInfo;
4642 
4643  DPRINT("dwCreationFlags %x, lpEnvironment %p, lpCurrentDirectory %p, "
4644  "lpStartupInfo %p, lpProcessInformation %p\n",
4645  dwCreationFlags, lpEnvironment, lpCurrentDirectory,
4646  lpStartupInfo, lpProcessInformation);
4647 
4648  /* Copy Startup Info */
4649  RtlMoveMemory(&StartupInfo, lpStartupInfo, sizeof(*lpStartupInfo));
4650 
4651  /* Initialize all strings to nothing */
4652  CommandLine.Buffer = NULL;
4653  ApplicationName.Buffer = NULL;
4654  CurrentDirectory.Buffer = NULL;
4655  StartupInfo.lpDesktop = NULL;
4656  StartupInfo.lpReserved = NULL;
4657  StartupInfo.lpTitle = NULL;
4658 
4659  /* Convert the Command line */
4660  if (lpCommandLine)
4661  {
4663  lpCommandLine);
4664  }
4665 
4666  /* Convert the Name and Directory */
4667  if (lpApplicationName)
4668  {
4670  lpApplicationName);
4671  }
4672  if (lpCurrentDirectory)
4673  {
4675  lpCurrentDirectory);
4676  }
4677 
4678  /* Now convert Startup Strings */
4679  if (lpStartupInfo->lpReserved)
4680  {
4682  &StartupInfo.lpReserved);
4683  }
4684  if (lpStartupInfo->lpDesktop)
4685  {
4687  &StartupInfo.lpDesktop);
4688  }
4689  if (lpStartupInfo->lpTitle)
4690  {
4692  &StartupInfo.lpTitle);
4693  }
4694 
4695  /* Call the Unicode function */
4696  bRetVal = CreateProcessInternalW(hToken,
4697  ApplicationName.Buffer,
4698  CommandLine.Buffer,
4699  lpProcessAttributes,
4700  lpThreadAttributes,
4701  bInheritHandles,
4702  dwCreationFlags,
4703  lpEnvironment,
4704  CurrentDirectory.Buffer,
4705  &StartupInfo,
4706  lpProcessInformation,
4707  hNewToken);
4708 
4709  /* Clean up */
4711  RtlFreeUnicodeString(&CommandLine);
4713  RtlFreeHeap(RtlGetProcessHeap(), 0, StartupInfo.lpDesktop);
4714  RtlFreeHeap(RtlGetProcessHeap(), 0, StartupInfo.lpReserved);
4715  RtlFreeHeap(RtlGetProcessHeap(), 0, StartupInfo.lpTitle);
4716 
4717  /* Return what Unicode did */
4718  return bRetVal;
4719 }
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:2234
LPSTR lpTitle
Definition: winbase.h:806
LPWSTR lpReserved
Definition: winbase.h:825
WCHAR CurrentDirectory[1024]
Definition: chkdsk.c:74
VOID WINAPI BasepAnsiStringToHeapUnicodeString(IN LPCSTR AnsiString, OUT LPWSTR *UnicodeString)
Definition: utils.c:263
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
BOOLEAN WINAPI Basep8BitStringToDynamicUnicodeString(OUT PUNICODE_STRING UnicodeString, IN LPCSTR String)
Definition: utils.c:225
unsigned int BOOL
Definition: ntddk_ex.h:94
LPWSTR lpDesktop
Definition: winbase.h:826
smooth NULL
Definition: ftsmooth.c:416
LPWSTR lpTitle
Definition: winbase.h:827
void DPRINT(...)
Definition: polytest.cpp:61
LPSTR lpReserved
Definition: winbase.h:804
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
PVOID PVOID PWCHAR ApplicationName
Definition: env.c:45
LPSTR lpDesktop
Definition: winbase.h:805

Referenced by CreateProcessA().

◆ 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 2234 of file proc.c.

2246 {
2247  //
2248  // Core variables used for creating the initial process and thread
2249  //
2250  SECURITY_ATTRIBUTES LocalThreadAttributes, LocalProcessAttributes;
2251  OBJECT_ATTRIBUTES LocalObjectAttributes;
2253  SECTION_IMAGE_INFORMATION ImageInformation;
2256  ULONG NoWindow, StackSize, ErrorCode, Flags;
2258  USHORT ImageMachine;
2259  ULONG ParameterFlags, PrivilegeValue, HardErrorMode, ErrorResponse;
2260  ULONG_PTR ErrorParameters[2];
2261  BOOLEAN InJob, SaferNeeded, UseLargePages, HavePrivilege;
2262  BOOLEAN QuerySection, SkipSaferAndAppCompat;
2263  CONTEXT Context;
2264  BASE_API_MESSAGE CsrMsg[2];
2265  PBASE_CREATE_PROCESS CreateProcessMsg;
2266  PCSR_CAPTURE_BUFFER CaptureBuffer;
2267  PVOID BaseAddress, PrivilegeState, RealTimePrivilegeState;
2268  HANDLE DebugHandle, TokenHandle, JobHandle, KeyHandle, ThreadHandle;
2269  HANDLE FileHandle, SectionHandle, ProcessHandle;
2271  PROCESS_PRIORITY_CLASS PriorityClass;
2272  NTSTATUS Status, AppCompatStatus, SaferStatus, IFEOStatus, ImageDbgStatus;
2273  PPEB Peb, RemotePeb;
2274  PTEB Teb;
2275  INITIAL_TEB InitialTeb;
2276  PVOID TibValue;
2277  PIMAGE_NT_HEADERS NtHeaders;
2278  STARTUPINFOW StartupInfo;
2279  PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
2280  UNICODE_STRING DebuggerString;
2281  BOOL Result;
2282  //
2283  // Variables used for command-line and argument parsing
2284  //
2285  PCHAR pcScan;
2286  SIZE_T n;
2287  WCHAR SaveChar;
2288  ULONG Length, FileAttribs, CmdQuoteLength;
2289  ULONG ResultSize;
2290  SIZE_T EnvironmentLength, CmdLineLength;
2291  PWCHAR QuotedCmdLine, AnsiCmdCommand, ExtBuffer, CurrentDirectory;
2292  PWCHAR NullBuffer, ScanString, NameBuffer, SearchPath, DebuggerCmdLine;
2293  ANSI_STRING AnsiEnv;
2294  UNICODE_STRING UnicodeEnv, PathName;
2295  BOOLEAN SearchRetry, QuotesNeeded, CmdLineIsAppName, HasQuotes;
2296 
2297  //
2298  // Variables used for Fusion/SxS (Side-by-Side Assemblies)
2299  //
2300  RTL_PATH_TYPE SxsPathType, PathType;
2301 #if _SXS_SUPPORT_ENABLED_
2302  PRTL_BUFFER ByteBuffer;
2303  PRTL_UNICODE_STRING_BUFFER ThisBuffer, Buffer, SxsStaticBuffers[5];
2304  PRTL_UNICODE_STRING_BUFFER* BufferHead, SxsStringBuffer;
2305  RTL_UNICODE_STRING_BUFFER SxsWin32ManifestPath, SxsNtManifestPath;
2306  RTL_UNICODE_STRING_BUFFER SxsWin32PolicyPath, SxsNtPolicyPath;
2307  RTL_UNICODE_STRING_BUFFER SxsWin32AssemblyDirectory;
2308  BASE_MSG_SXS_HANDLES MappedHandles, Handles, FileHandles;
2309  PVOID CapturedStrings[3];
2310  SXS_WIN32_NT_PATH_PAIR ExePathPair, ManifestPathPair, PolicyPathPair;
2311  SXS_OVERRIDE_MANIFEST OverrideManifest;
2312  UNICODE_STRING FreeString, SxsNtExePath;
2313  PWCHAR SxsConglomeratedBuffer, StaticBuffer;
2314  ULONG ConglomeratedBufferSizeBytes, StaticBufferSize, i;
2315 #endif
2317 
2318  //
2319  // Variables used for path conversion (and partially Fusion/SxS)
2320  //
2321  PWCHAR FilePart, PathBuffer, FreeBuffer;
2322  BOOLEAN TranslationStatus;
2323  RTL_RELATIVE_NAME_U SxsWin32RelativePath;
2324  UNICODE_STRING PathBufferString, SxsWin32ExePath;
2325 
2326  //
2327  // Variables used by Application Compatibility (and partially Fusion/SxS)
2328  //
2329  PVOID AppCompatSxsData, AppCompatData;
2330  ULONG AppCompatSxsDataSize, AppCompatDataSize;
2331  //
2332  // Variables used by VDM (Virtual Dos Machine) and WOW32 (16-bit Support)
2333  //
2334  ULONG BinarySubType, VdmBinaryType, VdmTask, VdmReserve;
2335  ULONG VdmUndoLevel;
2336  BOOLEAN UseVdmReserve;
2337  HANDLE VdmWaitObject;
2338  ANSI_STRING VdmAnsiEnv;
2339  UNICODE_STRING VdmString, VdmUnicodeEnv;
2340  BOOLEAN IsWowApp;
2341  PBASE_CHECK_VDM CheckVdmMsg;
2342 
2343  /* Zero out the initial core variables and handles */
2344  QuerySection = FALSE;
2345  InJob = FALSE;
2346  SkipSaferAndAppCompat = FALSE;
2347  ParameterFlags = 0;
2348  Flags = 0;
2349  DebugHandle = NULL;
2350  JobHandle = NULL;
2351  TokenHandle = NULL;
2352  FileHandle = NULL;
2353  SectionHandle = NULL;
2354  ProcessHandle = NULL;
2355  ThreadHandle = NULL;
2356  BaseAddress = (PVOID)1;
2357 
2358  /* Zero out initial SxS and Application Compatibility state */
2359  AppCompatData = NULL;
2360  AppCompatDataSize = 0;
2361  AppCompatSxsData = NULL;
2362  AppCompatSxsDataSize = 0;
2363  CaptureBuffer = NULL;
2364 #if _SXS_SUPPORT_ENABLED_
2365  SxsConglomeratedBuffer = NULL;
2366 #endif
2367  FusionFlags = 0;
2368 
2369  /* Zero out initial parsing variables -- others are initialized later */
2370  DebuggerCmdLine = NULL;
2371  PathBuffer = NULL;
2372  SearchPath = NULL;
2373  NullBuffer = NULL;
2374  FreeBuffer = NULL;
2375  NameBuffer = NULL;
2377  FilePart = NULL;
2378  DebuggerString.Buffer = NULL;
2379  HasQuotes = FALSE;
2380  QuotedCmdLine = NULL;
2381 
2382  /* Zero out initial VDM state */
2383  VdmAnsiEnv.Buffer = NULL;
2384  VdmUnicodeEnv.Buffer = NULL;
2385  VdmString.Buffer = NULL;
2386  VdmTask = 0;
2387  VdmUndoLevel = 0;
2388  VdmBinaryType = 0;
2389  VdmReserve = 0;
2390  VdmWaitObject = NULL;
2391  UseVdmReserve = FALSE;
2392  IsWowApp = FALSE;
2393 
2394  /* Set message structures */
2395  CreateProcessMsg = &CsrMsg[0].Data.CreateProcessRequest;
2396  CheckVdmMsg = &CsrMsg[1].Data.CheckVDMRequest;
2397 
2398  /* Clear the more complex structures by zeroing out their entire memory */
2399  RtlZeroMemory(&Context, sizeof(Context));
2400 #if _SXS_SUPPORT_ENABLED_
2401  RtlZeroMemory(&FileHandles, sizeof(FileHandles));
2402  RtlZeroMemory(&MappedHandles, sizeof(MappedHandles));
2403  RtlZeroMemory(&Handles, sizeof(Handles));
2404 #endif
2405  RtlZeroMemory(&CreateProcessMsg->Sxs, sizeof(CreateProcessMsg->Sxs));
2406  RtlZeroMemory(&LocalProcessAttributes, sizeof(LocalProcessAttributes));
2407  RtlZeroMemory(&LocalThreadAttributes, sizeof(LocalThreadAttributes));
2408 
2409  /* Zero out output arguments as well */
2410  RtlZeroMemory(lpProcessInformation, sizeof(*lpProcessInformation));
2411  if (hNewToken) *hNewToken = NULL;
2412 
2413  /* Capture the special window flag */
2414  NoWindow = dwCreationFlags & CREATE_NO_WINDOW;
2415  dwCreationFlags &= ~CREATE_NO_WINDOW;
2416 
2417 #if _SXS_SUPPORT_ENABLED_
2418  /* Setup the SxS static string arrays and buffers */
2419  SxsStaticBuffers[0] = &SxsWin32ManifestPath;
2420  SxsStaticBuffers[1] = &SxsWin32PolicyPath;
2421  SxsStaticBuffers[2] = &SxsWin32AssemblyDirectory;
2422  SxsStaticBuffers[3] = &SxsNtManifestPath;
2423  SxsStaticBuffers[4] = &SxsNtPolicyPath;
2424  ExePathPair.Win32 = &SxsWin32ExePath;
2425  ExePathPair.Nt = &SxsNtExePath;
2426  ManifestPathPair.Win32 = &SxsWin32ManifestPath.String;
2427  ManifestPathPair.Nt = &SxsNtManifestPath.String;
2428  PolicyPathPair.Win32 = &SxsWin32PolicyPath.String;
2429  PolicyPathPair.Nt = &SxsNtPolicyPath.String;
2430 #endif
2431 
2432  DPRINT("CreateProcessInternalW: '%S' '%S' %lx\n", lpApplicationName, lpCommandLine, dwCreationFlags);
2433 
2434  /* Finally, set our TEB and PEB */
2435  Teb = NtCurrentTeb();
2436  Peb = NtCurrentPeb();
2437 
2438  /* This combination is illegal (see MSDN) */
2439  if ((dwCreationFlags & (DETACHED_PROCESS | CREATE_NEW_CONSOLE)) ==
2441  {
2442  DPRINT1("Invalid flag combo used\n");
2444  return FALSE;
2445  }
2446 
2447  /* Convert the priority class */
2448  if (dwCreationFlags & IDLE_PRIORITY_CLASS)
2449  {
2451  }
2452  else if (dwCreationFlags & BELOW_NORMAL_PRIORITY_CLASS)
2453  {
2455  }
2456  else if (dwCreationFlags & NORMAL_PRIORITY_CLASS)
2457  {
2459  }
2460  else if (dwCreationFlags & ABOVE_NORMAL_PRIORITY_CLASS)
2461  {
2463  }
2464  else if (dwCreationFlags & HIGH_PRIORITY_CLASS)
2465  {
2467  }
2468  else if (dwCreationFlags & REALTIME_PRIORITY_CLASS)
2469  {
2471  PriorityClass.PriorityClass += (BasepIsRealtimeAllowed(FALSE) != NULL);
2472  }
2473  else
2474  {
2476  }
2477 
2478  /* Done with the priority masks, so get rid of them */
2479  PriorityClass.Foreground = FALSE;
2480  dwCreationFlags &= ~(NORMAL_PRIORITY_CLASS |
2486 
2487  /* You cannot request both a shared and a separate WoW VDM */
2488  if ((dwCreationFlags & CREATE_SEPARATE_WOW_VDM) &&
2489  (dwCreationFlags & CREATE_SHARED_WOW_VDM))
2490  {
2491  /* Fail such nonsensical attempts */
2492  DPRINT1("Invalid WOW flags\n");
2494  return FALSE;
2495  }
2496  else if (!(dwCreationFlags & CREATE_SHARED_WOW_VDM) &&
2498  {
2499  /* A shared WoW VDM was not requested but system enforces separation */
2500  dwCreationFlags |= CREATE_SEPARATE_WOW_VDM;
2501  }
2502 
2503  /* If a shared WoW VDM is used, make sure the process isn't in a job */
2504  if (!(dwCreationFlags & CREATE_SEPARATE_WOW_VDM) &&
2506  {
2507  /* Remove the shared flag and add the separate flag */
2508  dwCreationFlags = (dwCreationFlags &~ CREATE_SHARED_WOW_VDM) |
2510  }
2511 
2512  /* Convert the environment */
2513  if ((lpEnvironment) && !(dwCreationFlags & CREATE_UNICODE_ENVIRONMENT))
2514  {
2515  /* Scan the environment to calculate its Unicode size */
2516  AnsiEnv.Buffer = pcScan = (PCHAR)lpEnvironment;
2517  while ((*pcScan) || (*(pcScan + 1))) ++pcScan;
2518 
2519  /* Make sure the environment is not too large */
2520  EnvironmentLength = (pcScan + sizeof(ANSI_NULL) - (PCHAR)lpEnvironment);
2521  if (EnvironmentLength > MAXUSHORT)
2522  {
2523  /* Fail */
2525  return FALSE;
2526  }
2527 
2528  /* Create our ANSI String */
2529  AnsiEnv.Length = (USHORT)EnvironmentLength;
2530  AnsiEnv.MaximumLength = AnsiEnv.Length + sizeof(ANSI_NULL);
2531 
2532  /* Allocate memory for the Unicode Environment */
2533  UnicodeEnv.Buffer = NULL;
2534  RegionSize = AnsiEnv.MaximumLength * sizeof(WCHAR);
2536  (PVOID)&UnicodeEnv.Buffer,
2537  0,
2538  &RegionSize,
2539  MEM_COMMIT,
2540  PAGE_READWRITE);
2541  if (!NT_SUCCESS(Status))
2542  {
2543  /* Fail */
2545  return FALSE;
2546  }
2547 
2548  /* Use the allocated size and convert */
2549  UnicodeEnv.MaximumLength = (USHORT)RegionSize;
2550  Status = RtlAnsiStringToUnicodeString(&UnicodeEnv, &AnsiEnv, FALSE);
2551  if (!NT_SUCCESS(Status))
2552  {
2553  /* Fail */
2555  (PVOID)&UnicodeEnv.Buffer,
2556  &RegionSize,
2557  MEM_RELEASE);
2559  return FALSE;
2560  }
2561 
2562  /* Now set the Unicode environment as the environment string pointer */
2563  lpEnvironment = UnicodeEnv.Buffer;
2564  }
2565 
2566  /* Make a copy of the caller's startup info since we'll modify it */
2567  StartupInfo = *lpStartupInfo;
2568 
2569  /* Check if private data is being sent on the same channel as std handles */
2570  if ((StartupInfo.dwFlags & STARTF_USESTDHANDLES) &&
2571  (StartupInfo.dwFlags & (STARTF_USEHOTKEY | STARTF_SHELLPRIVATE)))
2572  {
2573  /* Cannot use the std handles since we have monitor/hotkey values */
2574  StartupInfo.dwFlags &= ~STARTF_USESTDHANDLES;
2575  }
2576 
2577  /* If there's a debugger, or we have to launch cmd.exe, we go back here */
2578 AppNameRetry:
2579  /* New iteration -- free any existing name buffer */
2580  if (NameBuffer)
2581  {
2582  RtlFreeHeap(RtlGetProcessHeap(), 0, NameBuffer);
2583  NameBuffer = NULL;
2584  }
2585 
2586  /* New iteration -- free any existing free buffer */
2587  if (FreeBuffer)
2588  {
2589  RtlFreeHeap(RtlGetProcessHeap(), 0, FreeBuffer);
2590  FreeBuffer = NULL;
2591  }
2592 
2593  /* New iteration -- close any existing file handle */
2594  if (FileHandle)
2595  {
2597  FileHandle = NULL;
2598  }
2599 
2600  /* Set the initial parsing state. This code can loop -- don't move this! */
2601  ErrorCode = 0;
2602  SearchRetry = TRUE;
2603  QuotesNeeded = FALSE;
2604  CmdLineIsAppName = FALSE;
2605 
2606  /* First check if we don't have an application name */
2607  if (!lpApplicationName)
2608  {
2609  /* This should be the first time we attempt creating one */
2610  ASSERT(NameBuffer == NULL);
2611 
2612  /* Allocate a buffer to hold it */
2613  NameBuffer = RtlAllocateHeap(RtlGetProcessHeap(),
2614  0,
2615  MAX_PATH * sizeof(WCHAR));
2616  if (!NameBuffer)
2617  {
2619  Result = FALSE;
2620  goto Quickie;
2621  }
2622 
2623  /* Initialize the application name and our parsing parameters */
2624  lpApplicationName = NullBuffer = ScanString = lpCommandLine;
2625 
2626  /* Check for an initial quote*/
2627  if (*lpCommandLine == L'\"')
2628  {
2629  /* We found a quote, keep searching for another one */
2630  SearchRetry = FALSE;
2631  ScanString++;
2632  lpApplicationName = ScanString;
2633  while (*ScanString)
2634  {
2635  /* Have we found the terminating quote? */
2636  if (*ScanString == L'\"')
2637  {
2638  /* We're done, get out of here */
2639  NullBuffer = ScanString;
2640  HasQuotes = TRUE;
2641  break;
2642  }
2643 
2644  /* Keep searching for the quote */
2645  ScanString++;
2646  NullBuffer = ScanString;
2647  }
2648  }
2649  else
2650  {
2651 StartScan:
2652  /* We simply make the application name be the command line*/
2653  lpApplicationName = lpCommandLine;
2654  while (*ScanString)
2655  {
2656  /* Check if it starts with a space or tab */
2657  if ((*ScanString == L' ') || (*ScanString == L'\t'))
2658  {
2659  /* Break out of the search loop */
2660  NullBuffer = ScanString;
2661  break;
2662  }
2663 
2664  /* Keep searching for a space or tab */
2665  ScanString++;
2666  NullBuffer = ScanString;
2667  }
2668  }
2669 
2670  /* We have found the end of the application name, terminate it */
2671  SaveChar = *NullBuffer;
2672  *NullBuffer = UNICODE_NULL;
2673 
2674  /* New iteration -- free any existing saved path */
2675  if (SearchPath)
2676  {
2677  RtlFreeHeap(RtlGetProcessHeap(), 0, SearchPath);
2678  SearchPath = NULL;
2679  }
2680 
2681  /* Now compute the final EXE path based on the name */
2682  SearchPath = BaseComputeProcessExePath((LPWSTR)lpApplicationName);
2683  DPRINT("Search Path: %S\n", SearchPath);
2684  if (!SearchPath)
2685  {
2687  Result = FALSE;
2688  goto Quickie;
2689  }
2690 
2691  /* And search for the executable in the search path */
2693  lpApplicationName,
2694  L".exe",
2695  MAX_PATH,
2696  NameBuffer,
2697  NULL);
2698 
2699  /* Did we find it? */
2700  if ((Length) && (Length < MAX_PATH))
2701  {
2702  /* Get file attributes */
2703  FileAttribs = GetFileAttributesW(NameBuffer);
2704  if ((FileAttribs != INVALID_FILE_ATTRIBUTES) &&
2705  (FileAttribs & FILE_ATTRIBUTE_DIRECTORY))
2706  {
2707  /* This was a directory, fail later on */
2708  Length = 0;
2709  }
2710  else
2711  {
2712  /* It's a file! */
2713  Length++;
2714  }
2715  }
2716 
2717  DPRINT("Length: %lu Buffer: %S\n", Length, NameBuffer);
2718 
2719  /* Check if there was a failure in SearchPathW */
2720  if ((Length) && (Length < MAX_PATH))
2721  {
2722  /* Everything looks good, restore the name */
2723  *NullBuffer = SaveChar;
2724  lpApplicationName = NameBuffer;
2725  }
2726  else
2727  {
2728  /* Check if this was a relative path, which would explain it */
2729  PathType = RtlDetermineDosPathNameType_U(lpApplicationName);
2731  {
2732  /* This should fail, and give us a detailed LastError */
2733  FileHandle = CreateFileW(lpApplicationName,
2734  GENERIC_READ,
2735  FILE_SHARE_READ |
2737  NULL,
2738  OPEN_EXISTING,
2740  NULL);
2742  {
2743  /* It worked? Return a generic error */
2745  FileHandle = NULL;
2747  }
2748  }
2749  else
2750  {
2751  /* Path was absolute, which means it doesn't exist */
2753  }
2754 
2755  /* Did we already fail once? */
2756  if (ErrorCode)
2757  {
2758  /* Set the error code */
2760  }
2761  else
2762  {
2763  /* Not yet, cache it */
2764  ErrorCode = GetLastError();
2765  }
2766 
2767  /* Put back the command line */
2768  *NullBuffer = SaveChar;
2769  lpApplicationName = NameBuffer;
2770 
2771  /* It's possible there's whitespace in the directory name */
2772  if (!(*ScanString) || !(SearchRetry))
2773  {
2774  /* Not the case, give up completely */
2775  Result = FALSE;
2776  goto Quickie;
2777  }
2778 
2779  /* There are spaces, so keep trying the next possibility */
2780  ScanString++;
2781  NullBuffer = ScanString;
2782 
2783  /* We will have to add a quote, since there is a space */
2784  QuotesNeeded = TRUE;
2785  HasQuotes = TRUE;
2786  goto StartScan;
2787  }
2788  }
2789  else if (!(lpCommandLine) || !(*lpCommandLine))
2790  {
2791  /* We don't have a command line, so just use the application name */
2792  CmdLineIsAppName = TRUE;
2793  lpCommandLine = (LPWSTR)lpApplicationName;
2794  }
2795 
2796  /* Convert the application name to its NT path */
2797  TranslationStatus = RtlDosPathNameToRelativeNtPathName_U(lpApplicationName,
2798  &PathName,
2799  NULL,
2800  &SxsWin32RelativePath);
2801  if (!TranslationStatus)
2802  {
2803  /* Path must be invalid somehow, bail out */
2804  DPRINT1("Path translation for SxS failed\n");
2806  Result = FALSE;
2807  goto Quickie;
2808  }
2809 
2810  /* Setup the buffer that needs to be freed at the end */
2811  ASSERT(FreeBuffer == NULL);
2812  FreeBuffer = PathName.Buffer;
2813 
2814  /* Check what kind of path the application is, for SxS (Fusion) purposes */
2815  RtlInitUnicodeString(&SxsWin32ExePath, lpApplicationName);
2816  SxsPathType = RtlDetermineDosPathNameType_U(lpApplicationName);
2817  if ((SxsPathType != RtlPathTypeDriveAbsolute) &&
2818  (SxsPathType != RtlPathTypeLocalDevice) &&
2819  (SxsPathType != RtlPathTypeRootLocalDevice) &&
2820  (SxsPathType != RtlPathTypeUncAbsolute))
2821  {
2822  /* Relative-type path, get the full path */
2823  RtlInitEmptyUnicodeString(&PathBufferString, NULL, 0);
2824  Status = RtlGetFullPathName_UstrEx(&SxsWin32ExePath,
2825  NULL,
2826  &PathBufferString,
2827  NULL,
2828  NULL,
2829  NULL,
2830  &SxsPathType,
2831  NULL);
2832  if (!NT_SUCCESS(Status))
2833  {
2834  /* Fail the rest of the create */
2835  RtlReleaseRelativeName(&SxsWin32RelativePath);
2837  Result = FALSE;
2838  goto Quickie;
2839  }
2840 
2841  /* Use this full path as the SxS path */
2842  SxsWin32ExePath = PathBufferString;
2843  PathBuffer = PathBufferString.Buffer;
2844  PathBufferString.Buffer = NULL;
2845  DPRINT("SxS Path: %S\n", PathBuffer);
2846  }
2847 
2848  /* Also set the .EXE path based on the path name */
2849 #if _SXS_SUPPORT_ENABLED_
2850  SxsNtExePath = PathName;
2851 #endif
2852  if (SxsWin32RelativePath.RelativeName.Length)
2853  {
2854  /* If it's relative, capture the relative name */
2855  PathName = SxsWin32RelativePath.RelativeName;
2856  }
2857  else
2858  {
2859  /* Otherwise, it's absolute, make sure no relative dir is used */
2860  SxsWin32RelativePath.ContainingDirectory = NULL;
2861  }
2862 
2863  /* Now use the path name, and the root path, to try opening the app */
2864  DPRINT("Path: %wZ. Dir: %p\n", &PathName, SxsWin32RelativePath.ContainingDirectory);
2865  InitializeObjectAttributes(&LocalObjectAttributes,
2866  &PathName,
2868  SxsWin32RelativePath.ContainingDirectory,
2869  NULL);
2871  SYNCHRONIZE |
2873  FILE_READ_DATA |
2874  FILE_EXECUTE,
2875  &LocalObjectAttributes,
2876  &IoStatusBlock,
2880  if (!NT_SUCCESS(Status))
2881  {
2882  /* Try to open the app just for execute purposes instead */
2885  &LocalObjectAttributes,
2886  &IoStatusBlock,
2890  }
2891 
2892  /* Failure path, display which file failed to open */
2893  if (!NT_SUCCESS(Status))
2894  DPRINT1("Open file failed: %lx (%wZ)\n", Status, &PathName);
2895 
2896  /* Cleanup in preparation for failure or success */
2897  RtlReleaseRelativeName(&SxsWin32RelativePath);
2898 
2899  if (!NT_SUCCESS(Status))
2900  {
2901  /* Failure path, try to understand why */
2902  if (RtlIsDosDeviceName_U(lpApplicationName))
2903  {
2904  /* If a device is being executed, return this special error code */
2906  Result = FALSE;
2907  goto Quickie;
2908  }
2909  else
2910  {
2911  /* Otherwise return the converted NT error code */
2913  Result = FALSE;
2914  goto Quickie;
2915  }
2916  }
2917 
2918  /* Did the caller specify a desktop? */
2919  if (!StartupInfo.lpDesktop)
2920  {
2921  /* Use the one from the current process */
2923  }
2924 
2925  /* Create a section for this file */
2926  Status = NtCreateSection(&SectionHandle,
2928  NULL,
2929  NULL,
2930  PAGE_EXECUTE,
2931  SEC_IMAGE,
2932  FileHandle);
2933  DPRINT("Section status: %lx\n", Status);
2934  if (NT_SUCCESS(Status))
2935  {
2936  /* Are we running on Windows Embedded, Datacenter, Blade or Starter? */
2937  if (SharedUserData->SuiteMask & (VER_SUITE_EMBEDDEDNT |
2940  VER_SUITE_BLADE))
2941  {
2942  /* These SKUs do not allow running certain applications */
2945  {
2946  /* And this is one of them! */
2947  DPRINT1("Invalid Blade hashes!\n");
2949  Result = FALSE;
2950  goto Quickie;
2951  }
2952 
2953  /* Did we get some other failure? */
2954  if (!NT_SUCCESS(Status))
2955  {
2956  /* If we couldn't check the hashes, assume nefariousness */
2957  DPRINT1("Tampered Blade hashes!\n");
2959  Result = FALSE;
2960  goto Quickie;
2961  }
2962  }
2963 
2964  /* Now do Winsafer, etc, checks */
2965  Status = BasepIsProcessAllowed((LPWSTR)lpApplicationName);
2966  if (!NT_SUCCESS(Status))
2967  {
2968  /* Fail if we're not allowed to launch the process */
2969  DPRINT1("Process not allowed to launch: %lx\n", Status);
2971  if (SectionHandle)
2972  {
2973  NtClose(SectionHandle);
2974  SectionHandle = NULL;
2975  }
2976  Result = FALSE;
2977  goto Quickie;
2978  }
2979 
2980  /* Is a DOS VDM being forced, but we already have a WOW32 instance ready? */
2981  if ((dwCreationFlags & CREATE_FORCEDOS) &&
2983  {
2984  /* This request can't be satisfied, instead, a separate VDM is needed */
2985  dwCreationFlags &= ~(CREATE_FORCEDOS | CREATE_SHARED_WOW_VDM);
2986  dwCreationFlags |= CREATE_SEPARATE_WOW_VDM;
2987 
2988  /* Set a failure code, ask for VDM reservation */
2990  UseVdmReserve = TRUE;
2991 
2992  /* Close the current handle */
2993  NtClose(SectionHandle);
2994  SectionHandle = NULL;
2995 
2996  /* Don't query the section later */
2997  QuerySection = FALSE;
2998  }
2999  }
3000 
3001  /* Did we already do these checks? */
3002  if (!SkipSaferAndAppCompat)
3003  {
3004  /* Is everything OK so far, OR do we have an non-MZ, non-DOS app? */
3005  if ((NT_SUCCESS(Status)) ||
3007  !(BaseIsDosApplication(&PathName, Status))))
3008  {
3009  /* Clear the machine type in case of failure */
3010  ImageMachine = 0;
3011 
3012  /* Clean any app compat data that may have accumulated */
3013  BasepFreeAppCompatData(AppCompatData, AppCompatSxsData);
3014  AppCompatData = NULL;
3015  AppCompatSxsData = NULL;
3016 
3017  /* Do we have a section? */
3018  if (SectionHandle)
3019  {
3020  /* Have we already queried it? */
3021  if (QuerySection)
3022  {
3023  /* Nothing to do */
3024  AppCompatStatus = STATUS_SUCCESS;
3025  }
3026  else
3027  {
3028  /* Get some information about the executable */
3029  AppCompatStatus = NtQuerySection(SectionHandle,
3031  &ImageInformation,
3032  sizeof(ImageInformation),
3033  NULL);
3034  }
3035 
3036  /* Do we have section information now? */
3037  if (NT_SUCCESS(AppCompatStatus))
3038  {
3039  /* Don't ask for it again, save the machine type */
3040  QuerySection = TRUE;
3041  ImageMachine = ImageInformation.Machine;
3042  }
3043  }
3044 
3045  /* Is there a reason/Shim we shouldn't run this application? */
3046  AppCompatStatus = BasepCheckBadapp(FileHandle,
3047  FreeBuffer,
3048  lpEnvironment,
3049  ImageMachine,
3050  &AppCompatData,
3051  &AppCompatDataSize,
3052  &AppCompatSxsData,
3053  &AppCompatSxsDataSize,
3054  &FusionFlags);
3055  if (!NT_SUCCESS(AppCompatStatus))
3056  {
3057  /* This is usually the status we get back */
3058  DPRINT1("App compat launch failure: %lx\n", AppCompatStatus);
3059  if (AppCompatStatus == STATUS_ACCESS_DENIED)
3060  {
3061  /* Convert it to something more Win32-specific */
3063  }
3064  else
3065  {
3066  /* Some other error */
3067  BaseSetLastNTError(AppCompatStatus);
3068  }
3069 
3070  /* Did we have a section? */
3071  if (SectionHandle)
3072  {
3073  /* Clean it up */
3074  NtClose(SectionHandle);
3075  SectionHandle = NULL;
3076  }
3077 
3078  /* Fail the call */
3079  Result = FALSE;
3080  goto Quickie;
3081  }
3082  }
3083  }
3084 
3085  //ASSERT((dwFusionFlags & ~SXS_APPCOMPACT_FLAG_APP_RUNNING_SAFEMODE) == 0);
3086 
3087  /* Have we already done, and do we need to do, SRP (WinSafer) checks? */
3088  if (!(SkipSaferAndAppCompat) &&
3089  ~(dwCreationFlags & CREATE_PRESERVE_CODE_AUTHZ_LEVEL))
3090  {
3091  /* Assume yes */
3092  SaferNeeded = TRUE;
3093  switch (Status)
3094  {
3099  /* For all DOS, 16-bit, OS/2 images, we do*/
3100  break;
3101 
3103  /* For invalid files, we don't, unless it's a .BAT file */
3104  if (BaseIsDosApplication(&PathName, Status)) break;
3105 
3106  default:
3107  /* Any other error codes we also don't */
3108  if (!NT_SUCCESS(Status))
3109  {
3110  SaferNeeded = FALSE;
3111  }
3112 
3113  /* But for success, we do */
3114  break;
3115  }
3116 
3117  /* Okay, so what did the checks above result in? */
3118  if (SaferNeeded)
3119  {
3120  /* We have to call into the WinSafer library and actually check */
3122  (LPWSTR)lpApplicationName,
3123  FileHandle,
3124  &InJob,
3125  &TokenHandle,
3126  &JobHandle);
3127  if (SaferStatus == 0xFFFFFFFF)
3128  {
3129  /* Back in 2003, they didn't have an NTSTATUS for this... */
3130  DPRINT1("WinSafer blocking process launch\n");
3132  Result = FALSE;
3133  goto Quickie;
3134  }
3135 
3136  /* Other status codes are not-Safer related, just convert them */
3137  if (!NT_SUCCESS(SaferStatus))
3138  {
3139  DPRINT1("Error checking WinSafer: %lx\n", SaferStatus);
3140  BaseSetLastNTError(SaferStatus);
3141  Result = FALSE;
3142  goto Quickie;
3143  }
3144  }
3145  }
3146 
3147  /* The last step is to figure out why the section object was not created */
3148  switch (Status)
3149  {
3151  {
3152  /* 16-bit binary. Should we use WOW or does the caller force VDM? */
3153  if (!(dwCreationFlags & CREATE_FORCEDOS))
3154  {
3155  /* Remember that we're launching WOW */
3156  IsWowApp = TRUE;
3157 
3158  /* Create the VDM environment, it's valid for WOW too */
3159  Result = BaseCreateVDMEnvironment(lpEnvironment,
3160  &VdmAnsiEnv,
3161  &VdmUnicodeEnv);
3162  if (!Result)
3163  {
3164  DPRINT1("VDM environment for WOW app failed\n");
3165  goto Quickie;
3166  }
3167 
3168  /* We're going to try this twice, so do a loop */
3169  while (TRUE)
3170  {
3171  /* Pick which kind of WOW mode we want to run in */
3172  VdmBinaryType = (dwCreationFlags &
3175 
3176  /* Get all the VDM settings and current status */
3177  Status = BaseCheckVDM(VdmBinaryType,
3178  lpApplicationName,
3179  lpCommandLine,
3180  lpCurrentDirectory,
3181  &VdmAnsiEnv,
3182  &CsrMsg[1],
3183  &VdmTask,
3184  dwCreationFlags,
3185  &StartupInfo,
3186  hUserToken);
3187 
3188  /* If it worked, no need to try again */
3189  if (NT_SUCCESS(Status)) break;
3190 
3191  /* Check if it's disallowed or if it's our second time */
3193  if ((Status == STATUS_VDM_DISALLOWED) ||
3194  (VdmBinaryType == BINARY_TYPE_SEPARATE_WOW) ||
3196  {
3197  /* Fail the call -- we won't try again */
3198  DPRINT1("VDM message failure for WOW: %lx\n", Status);
3199  Result = FALSE;
3200  goto Quickie;
3201  }
3202 
3203  /* Try one more time, but with a separate WOW instance */
3204  dwCreationFlags |= CREATE_SEPARATE_WOW_VDM;
3205  }
3206 
3207  /* Check which VDM state we're currently in */
3208  switch (CheckVdmMsg->VDMState & (VDM_NOT_LOADED |
3209  VDM_NOT_READY |
3210  VDM_READY))
3211  {
3212  case VDM_NOT_LOADED:
3213  /* VDM is not fully loaded, so not that much to undo */
3214  VdmUndoLevel = VDM_UNDO_PARTIAL;
3215 
3216  /* Reset VDM reserve if needed */
3217  if (UseVdmReserve) VdmReserve = 1;
3218 
3219  /* Get the required parameters and names for launch */
3220  Result = BaseGetVdmConfigInfo(lpCommandLine,
3221  VdmTask,
3222  VdmBinaryType,
3223  &VdmString,
3224  &VdmReserve);
3225  if (!Result)
3226  {
3227  DPRINT1("VDM Configuration failed for WOW\n");
3229  goto Quickie;
3230  }
3231 
3232  /* Update the command-line with the VDM one instead */
3233  lpCommandLine = VdmString.Buffer;
3234  lpApplicationName = NULL;
3235 
3236  /* We don't want a console, detachment, nor a window */
3237  dwCreationFlags |= CREATE_NO_WINDOW;
3238  dwCreationFlags &= ~(CREATE_NEW_CONSOLE | DETACHED_PROCESS);
3239 
3240  /* Force feedback on */
3241  StartupInfo.dwFlags |= STARTF_FORCEONFEEDBACK;
3242  break;
3243 
3244 
3245  case VDM_READY:
3246  /* VDM is ready, so we have to undo everything */
3247  VdmUndoLevel = VDM_UNDO_REUSE;
3248 
3249  /* Check if CSRSS wants us to wait on VDM */
3250  VdmWaitObject = CheckVdmMsg->WaitObjectForParent;
3251  break;
3252 
3253  case VDM_NOT_READY:
3254  /* Something is wrong with VDM, we'll fail the call */
3255  DPRINT1("VDM is not ready for WOW\n");
3257  Result = FALSE;
3258  goto Quickie;
3259 
3260  default:
3261  break;
3262  }
3263 
3264  /* Since to get NULL, we allocate from 0x1, account for this */
3265  VdmReserve--;
3266 
3267  /* This implies VDM is ready, so skip everything else */
3268  if (VdmWaitObject) goto VdmShortCircuit;
3269 
3270  /* Don't inherit handles since we're doing VDM now */
3271  bInheritHandles = FALSE;
3272 
3273  /* Had the user passed in environment? If so, destroy it */
3274  if ((lpEnvironment) &&
3275  !(dwCreationFlags & CREATE_UNICODE_ENVIRONMENT))
3276  {
3277  RtlDestroyEnvironment(lpEnvironment);
3278  }
3279 
3280  /* We've already done all these checks, don't do them again */
3281  SkipSaferAndAppCompat = TRUE;
3282  goto AppNameRetry;
3283  }
3284 
3285  // There is no break here on purpose, so FORCEDOS drops down!
3286  }
3287 
3291  {
3292  /* We're launching an executable application */
3293  BinarySubType = BINARY_TYPE_EXE;
3294 
3295  /* We can drop here from other "cases" above too, so check */
3298  (BinarySubType = BaseIsDosApplication(&PathName, Status)))
3299  {
3300  /* We're launching a DOS application */
3301  VdmBinaryType = BINARY_TYPE_DOS;
3302 
3303  /* Based on the caller environment, create a VDM one */
3304  Result = BaseCreateVDMEnvironment(lpEnvironment,
3305  &VdmAnsiEnv,
3306  &VdmUnicodeEnv);
3307  if (!Result)
3308  {
3309  DPRINT1("VDM environment for DOS failed\n");
3310  goto Quickie;
3311  }
3312 
3313  /* Check the current state of the VDM subsystem */
3314  Status = BaseCheckVDM(VdmBinaryType | BinarySubType,
3315  lpApplicationName,
3316  lpCommandLine,
3317  lpCurrentDirectory,
3318  &VdmAnsiEnv,
3319  &CsrMsg[1],
3320  &VdmTask,
3321  dwCreationFlags,
3322  &StartupInfo,
3323  NULL);
3324  if (!NT_SUCCESS(Status))
3325  {
3326  /* Failed to inquire about VDM, fail the call */
3327  DPRINT1("VDM message failure for DOS: %lx\n", Status);
3329  Result = FALSE;
3330  goto Quickie;
3331  };
3332 
3333  /* Handle possible VDM states */
3334  switch (CheckVdmMsg->VDMState & (VDM_NOT_LOADED |
3335  VDM_NOT_READY |
3336  VDM_READY))
3337  {
3338  case VDM_NOT_LOADED:
3339  /* If VDM is not loaded, we'll do a partial undo */
3340  VdmUndoLevel = VDM_UNDO_PARTIAL;
3341 
3342  /* A VDM process can't also be detached, so fail */
3343  if (dwCreationFlags & DETACHED_PROCESS)
3344  {
3345  DPRINT1("Detached process but no VDM, not allowed\n");
3347  return FALSE;
3348  }
3349 
3350  /* Get the required parameters and names for launch */
3351  Result = BaseGetVdmConfigInfo(lpCommandLine,
3352  VdmTask,
3353  VdmBinaryType,
3354  &VdmString,
3355  &VdmReserve);
3356  if (!Result)
3357  {
3358  DPRINT1("VDM Configuration failed for DOS\n");
3360  goto Quickie;
3361  }
3362 
3363  /* Update the command-line to launch VDM instead */
3364  lpCommandLine = VdmString.Buffer;
3365  lpApplicationName = NULL;
3366  break;
3367 
3368  case VDM_READY:
3369  /* VDM is ready, so we have to undo everything */
3370  VdmUndoLevel = VDM_UNDO_REUSE;
3371 
3372  /* Check if CSRSS wants us to wait on VDM */
3373  VdmWaitObject = CheckVdmMsg->WaitObjectForParent;
3374  break;
3375 
3376  case VDM_NOT_READY:
3377  /* Something is wrong with VDM, we'll fail the call */
3378  DPRINT1("VDM is not ready for DOS\n");
3380  Result = FALSE;
3381  goto Quickie;
3382 
3383  default:
3384  break;
3385  }
3386 
3387  /* Since to get NULL, we allocate from 0x1, account for this */
3388  VdmReserve--;
3389 
3390  /* This implies VDM is ready, so skip everything else */
3391  if (VdmWaitObject) goto VdmShortCircuit;
3392 
3393  /* Don't inherit handles since we're doing VDM now */
3394  bInheritHandles = FALSE;
3395 
3396  /* Had the user passed in environment? If so, destroy it */
3397  if ((lpEnvironment) &&
3398  !(dwCreationFlags & CREATE_UNICODE_ENVIRONMENT))
3399  {
3400  RtlDestroyEnvironment(lpEnvironment);
3401  }
3402 
3403  /* Use our VDM Unicode environment instead */
3404  lpEnvironment = VdmUnicodeEnv.Buffer;
3405  }
3406  else
3407  {
3408  /* It's a batch file, get the extension */
3409  ExtBuffer = &PathName.Buffer[PathName.Length / sizeof(WCHAR) - 4];
3410 
3411  /* Make sure the extensions are correct */
3412  if ((PathName.Length < (4 * sizeof(WCHAR))) ||
3413  ((_wcsnicmp(ExtBuffer, L".bat", 4)) &&
3414  (_wcsnicmp(ExtBuffer, L".cmd", 4))))
3415  {
3416  DPRINT1("'%wZ': Invalid EXE, and not a batch or script file\n", &PathName);
3418  Result = FALSE;
3419  goto Quickie;
3420  }
3421 
3422  /* Check if we need to account for quotes around the path */
3423  CmdQuoteLength = CmdLineIsAppName || HasQuotes;
3424  if (!CmdLineIsAppName)
3425  {
3426  if (HasQuotes) CmdQuoteLength++;
3427  }
3428  else
3429  {
3430  CmdQuoteLength++;
3431  }
3432 
3433  /* Calculate the length of the command line */
3434  CmdLineLength = wcslen(lpCommandLine);
3435  CmdLineLength += wcslen(CMD_STRING);
3436  CmdLineLength += CmdQuoteLength + sizeof(ANSI_NULL);
3437  CmdLineLength *= sizeof(WCHAR);
3438 
3439  /* Allocate space for the new command line */
3440  AnsiCmdCommand = RtlAllocateHeap(RtlGetProcessHeap(),
3441  0,
3442  CmdLineLength);
3443  if (!AnsiCmdCommand)
3444  {
3446  Result = FALSE;
3447  goto Quickie;
3448  }
3449 
3450  /* Build it */
3451  wcscpy(AnsiCmdCommand, CMD_STRING);
3452  if ((CmdLineIsAppName) || (HasQuotes))
3453  {
3454  wcscat(AnsiCmdCommand, L"\"");
3455  }
3456  wcscat(AnsiCmdCommand, lpCommandLine);
3457  if ((CmdLineIsAppName) || (HasQuotes))
3458  {
3459  wcscat(AnsiCmdCommand, L"\"");
3460  }
3461 
3462  /* Create it as a Unicode String */
3463  RtlInitUnicodeString(&DebuggerString, AnsiCmdCommand);
3464 
3465  /* Set the command line to this */
3466  lpCommandLine = DebuggerString.Buffer;
3467  lpApplicationName = NULL;
3468  DPRINT1("Retrying with: %S\n", lpCommandLine);
3469  }
3470 
3471  /* We've already done all these checks, don't do them again */
3472  SkipSaferAndAppCompat = TRUE;
3473  goto AppNameRetry;
3474  }
3475 
3477  {
3478  /* 64-bit binaries are not allowed to run on 32-bit ReactOS */
3479  DPRINT1("64-bit binary, failing\n");
3481  Result = FALSE;
3482  goto Quickie;
3483  }
3484 
3486  {
3487  /* Set the correct last error for this */
3488  DPRINT1("File is offline, failing\n");
3490  break;
3491  }
3492 
3493  default:
3494  {
3495  /* Any other error, convert it to a generic Win32 error */
3496  if (!NT_SUCCESS(Status))
3497  {
3498  DPRINT1("Failed to create section: %lx\n", Status);
3500  Result = FALSE;
3501  goto Quickie;
3502  }
3503 
3504  /* Otherwise, this must be success */
3506  break;
3507  }
3508  }
3509 
3510  /* Is this not a WOW application, but a WOW32 VDM was requested for it? */
3511  if (!(IsWowApp) && (dwCreationFlags & CREATE_SEPARATE_WOW_VDM))
3512  {
3513  /* Ignore the nonsensical request */
3514  dwCreationFlags &= ~CREATE_SEPARATE_WOW_VDM;
3515  }
3516 
3517  /* Did we already check information for the section? */
3518  if (!QuerySection)
3519  {
3520  /* Get some information about the executable */
3521  Status = NtQuerySection(SectionHandle,
3523  &ImageInformation,
3524  sizeof(ImageInformation),
3525  NULL);
3526  if (!NT_SUCCESS(Status))
3527  {
3528  /* We failed, bail out */
3529  DPRINT1("Section query failed\n");
3531  Result = FALSE;
3532  goto Quickie;
3533  }
3534 
3535  /* Don't check this later */
3536  QuerySection = TRUE;
3537  }
3538 
3539  /* Check if this was linked as a DLL */
3540  if (ImageInformation.ImageCharacteristics & IMAGE_FILE_DLL)
3541  {
3542  /* These aren't valid images to try to execute! */
3543  DPRINT1("Trying to launch a DLL, failing\n");
3545  Result = FALSE;
3546  goto Quickie;
3547  }
3548 
3549  /* Don't let callers pass in this flag -- we'll only get it from IFEO */
3551 
3552  /* Clear the IFEO-missing flag, before we know for sure... */
3553  ParameterFlags &= ~2;
3554 
3555  /* If the process is being debugged, only read IFEO if the PEB says so */
3556  if (!(dwCreationFlags & (DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS)) ||
3557  (NtCurrentPeb()->ReadImageFileExecOptions))
3558  {
3559  /* Let's do this! Attempt to open IFEO */
3560  IFEOStatus = LdrOpenImageFileOptionsKey(&PathName, 0, &KeyHandle);
3561  if (!NT_SUCCESS(IFEOStatus))
3562  {
3563  /* We failed, set the flag so we store this in the parameters */
3564  if (IFEOStatus == STATUS_OBJECT_NAME_NOT_FOUND) ParameterFlags |= 2;
3565  }
3566  else
3567  {
3568  /* Was this our first time going through this path? */
3569  if (!DebuggerCmdLine)
3570  {
3571  /* Allocate a buffer for the debugger path */
3572  DebuggerCmdLine = RtlAllocateHeap(RtlGetProcessHeap(),
3573  0,
3574  MAX_PATH * sizeof(WCHAR));
3575  if (!DebuggerCmdLine)
3576  {
3577  /* Close IFEO on failure */
3578  IFEOStatus = NtClose(KeyHandle);
3579  ASSERT(NT_SUCCESS(IFEOStatus));
3580 
3581  /* Fail the call */
3583  Result = FALSE;
3584  goto Quickie;
3585  }
3586  }
3587 
3588  /* Now query for the debugger */
3590  L"Debugger",
3591  REG_SZ,
3592  DebuggerCmdLine,
3593  MAX_PATH * sizeof(WCHAR),
3594  &ResultSize);
3595  if (!(NT_SUCCESS(IFEOStatus)) ||
3596  (ResultSize < sizeof(WCHAR)) ||
3597  (DebuggerCmdLine[0] == UNICODE_NULL))
3598  {
3599  /* If it's not there, or too small, or invalid, ignore it */
3600  RtlFreeHeap(RtlGetProcessHeap(), 0, DebuggerCmdLine);
3601  DebuggerCmdLine = NULL;
3602  }
3603 
3604  /* Also query if we should map with large pages */
3606  L"UseLargePages",
3607  REG_DWORD,
3608  &UseLargePages,
3609  sizeof(UseLargePages),
3610  NULL);
3611  if ((NT_SUCCESS(IFEOStatus)) && (UseLargePages))
3612  {
3613  /* Do it! This is the only way this flag can be set */
3615  }
3616 
3617  /* We're done with IFEO, can close it now */
3618  IFEOStatus = NtClose(KeyHandle);
3619  ASSERT(NT_SUCCESS(IFEOStatus));
3620  }
3621  }
3622 
3623  /* Make sure the image was compiled for this processor */
3624  if ((ImageInformation.Machine < SharedUserData->ImageNumberLow) ||
3625  (ImageInformation.Machine > SharedUserData->ImageNumberHigh))
3626  {
3627  /* It was not -- raise a hard error */
3628  ErrorResponse = ResponseOk;
3629  ErrorParameters[0] = (ULONG_PTR)&PathName;
3631  1,
3632  1,
3633  ErrorParameters,
3634  OptionOk,
3635  &ErrorResponse);
3636  if (Peb->ImageSubsystemMajorVersion <= 3)
3637  {
3638  /* If it's really old, return this error */
3640  }
3641  else
3642  {
3643  /* Otherwise, return a more modern error */
3645  }
3646 
3647  /* Go to the failure path */
3648  DPRINT1("Invalid image architecture: %lx\n", ImageInformation.Machine);
3649  Result = FALSE;
3650  goto Quickie;
3651  }
3652 
3653  /* Check if this isn't a Windows image */
3654  if ((ImageInformation.SubSystemType != IMAGE_SUBSYSTEM_WINDOWS_GUI) &&
3655  (ImageInformation.SubSystemType != IMAGE_SUBSYSTEM_WINDOWS_CUI))
3656  {
3657  /* Get rid of section-related information since we'll retry */
3658  NtClose(SectionHandle);
3659  SectionHandle = NULL;
3660  QuerySection = FALSE;
3661 
3662  /* The only other non-Windows image type we support here is POSIX */
3663  if (ImageInformation.SubSystemType != IMAGE_SUBSYSTEM_POSIX_CUI)
3664  {
3665  /* Bail out if it's something else */
3667  Result = FALSE;
3668  goto Quickie;
3669  }
3670 
3671  /* Now build the command-line to have posix launch this image */
3672  Result = BuildSubSysCommandLine(L"POSIX /P ",
3673  lpApplicationName,
3674  lpCommandLine,
3675  &DebuggerString);
3676  if (!Result)
3677  {
3678  /* Bail out if that failed */
3679  DPRINT1("Subsystem command line failed\n");
3680  goto Quickie;
3681  }
3682 
3683  /* And re-try launching the process, with the new command-line now */
3684  lpCommandLine = DebuggerString.Buffer;
3685  lpApplicationName = NULL;
3686 
3687  /* We've already done all these checks, don't do them again */
3688  SkipSaferAndAppCompat = TRUE;
3689  DPRINT1("Retrying with: %S\n", lpCommandLine);
3690  goto AppNameRetry;
3691  }
3692 
3693  /* Was this image built for a version of Windows whose images we can run? */
3695  ImageInformation.SubSystemMinorVersion);
3696  if (!Result)
3697  {
3698  /* It was not, bail out */
3699  DPRINT1("Invalid subsystem version: %hu.%hu\n",
3700  ImageInformation.SubSystemMajorVersion,
3701  ImageInformation.SubSystemMinorVersion);
3703  goto Quickie;
3704  }
3705 
3706  /* Check if there is a debugger associated with the application */
3707  if (DebuggerCmdLine)
3708  {
3709  /* Get the length of the command line */
3710  n = wcslen(lpCommandLine);
3711  if (!n)
3712  {
3713  /* There's no command line, use the application name instead */
3714  lpCommandLine = (LPWSTR)lpApplicationName;
3715  n = wcslen(lpCommandLine);
3716  }
3717 
3718  /* Protect against overflow */
3720  {
3722  Result = FALSE;
3723  goto Quickie;
3724  }
3725 
3726  /* Now add the length of the debugger command-line */
3727  n += wcslen(DebuggerCmdLine);
3728 
3729  /* Again make sure we don't overflow */
3731  {
3733  Result = FALSE;
3734  goto Quickie;
3735  }
3736 
3737  /* Account for the quotes and space between the two */
3738  n += sizeof("\" \"") - sizeof(ANSI_NULL);
3739 
3740  /* Convert to bytes, and make sure we don't overflow */
3741  n *= sizeof(WCHAR);
3743  {
3745  Result = FALSE;
3746  goto Quickie;
3747  }
3748 
3749  /* Allocate space for the string */
3750  DebuggerString.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, n);
3751  if (!DebuggerString.Buffer)
3752  {
3754  Result = FALSE;
3755  goto Quickie;
3756  }
3757 
3758  /* Set the length */
3759  RtlInitEmptyUnicodeString(&DebuggerString,
3760  DebuggerString.Buffer,
3761  (USHORT)n);
3762 
3763  /* Now perform the command line creation */
3764  ImageDbgStatus = RtlAppendUnicodeToString(&DebuggerString,
3765  DebuggerCmdLine);
3766  ASSERT(NT_SUCCESS(ImageDbgStatus));
3767  ImageDbgStatus = RtlAppendUnicodeToString(&DebuggerString, L" ");
3768  ASSERT(NT_SUCCESS(ImageDbgStatus));
3769  ImageDbgStatus = RtlAppendUnicodeToString(&DebuggerString, lpCommandLine);
3770  ASSERT(NT_SUCCESS(ImageDbgStatus));
3771 
3772  /* Make sure it all looks nice */
3773  DbgPrint("BASE: Calling debugger with '%wZ'\n", &DebuggerString);
3774 
3775  /* Update the command line and application name */
3776  lpCommandLine = DebuggerString.Buffer;
3777  lpApplicationName = NULL;
3778 
3779  /* Close all temporary state */
3780  NtClose(SectionHandle);
3781  SectionHandle = NULL;
3782  QuerySection = FALSE;
3783 
3784  /* Free all temporary memory */
3785  RtlFreeHeap(RtlGetProcessHeap(), 0, NameBuffer);
3786  NameBuffer = NULL;
3787  RtlFreeHeap(RtlGetProcessHeap(), 0, FreeBuffer);
3788  FreeBuffer = NULL;
3789  RtlFreeHeap(RtlGetProcessHeap(), 0, DebuggerCmdLine);
3790  DebuggerCmdLine = NULL;
3791  DPRINT1("Retrying with: %S\n", lpCommandLine);
3792  goto AppNameRetry;
3793  }
3794 
3795  /* Initialize the process object attributes */
3796  ObjectAttributes = BaseFormatObjectAttributes(&LocalObjectAttributes,
3797  lpProcessAttributes,
3798  NULL);
3799  if ((hUserToken) && (lpProcessAttributes))
3800  {
3801  /* Augment them with information from the user */
3802 
3803  LocalProcessAttributes = *lpProcessAttributes;
3804  LocalProcessAttributes.lpSecurityDescriptor = NULL;
3805  ObjectAttributes = BaseFormatObjectAttributes(&LocalObjectAttributes,
3806  &LocalProcessAttributes,
3807  NULL);
3808  }
3809 
3810  /* Check if we're going to be debugged */
3811  if (dwCreationFlags & DEBUG_PROCESS)
3812  {
3813  /* Set process flag */
3815  }
3816 
3817  /* Check if we're going to be debugged */
3818  if (dwCreationFlags & (DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS))
3819  {
3820  /* Connect to DbgUi */
3822  if (!NT_SUCCESS(Status))
3823  {
3824  DPRINT1("Failed to connect to DbgUI!\n");
3826  Result = FALSE;
3827  goto Quickie;
3828  }
3829 
3830  /* Get the debug object */
3831  DebugHandle = DbgUiGetThreadDebugObject();
3832 
3833  /* Check if only this process will be debugged */
3834  if (dwCreationFlags & DEBUG_ONLY_THIS_PROCESS)
3835  {
3836  /* Set process flag */
3838  }
3839  }
3840 
3841  /* Set inherit flag */
3842  if (bInheritHandles) Flags |= PROCESS_CREATE_FLAGS_INHERIT_HANDLES;
3843 
3844  /* Check if the process should be created with large pages */
3845  HavePrivilege = FALSE;
3846  PrivilegeState = NULL;
3848  {
3849  /* Acquire the required privilege so that the kernel won't fail the call */
3850  PrivilegeValue = SE_LOCK_MEMORY_PRIVILEGE;
3851  Status = RtlAcquirePrivilege(&PrivilegeValue, 1, 0, &PrivilegeState);
3852  if (NT_SUCCESS(Status))
3853  {
3854  /* Remember to release it later */
3855  HavePrivilege = TRUE;
3856  }
3857  }
3858 
3859  /* Save the current TIB value since kernel overwrites it to store PEB */
3860  TibValue = Teb->NtTib.ArbitraryUserPointer;
3861 
3862  /* Tell the kernel to create the process */
3866  NtCurrentProcess(),
3867  Flags,
3868  SectionHandle,
3869  DebugHandle,
3870  NULL,
3871  InJob);
3872 
3873  /* Load the PEB address from the hacky location where the kernel stores it */
3874  RemotePeb = Teb->NtTib.ArbitraryUserPointer;
3875 
3876  /* And restore the old TIB value */
3877  Teb->NtTib.ArbitraryUserPointer = TibValue;
3878 
3879  /* Release the large page privilege if we had acquired it */
3880  if (HavePrivilege) RtlReleasePrivilege(PrivilegeState);
3881 
3882  /* And now check if the kernel failed to create the process */
3883  if (!NT_SUCCESS(Status))
3884  {
3885  /* Go to failure path */
3886  DPRINT1("Failed to create process: %lx\n", Status);
3888  Result = FALSE;
3889  goto Quickie;
3890  }
3891 
3892  /* Check if there is a priority class to set */
3893  if (PriorityClass.PriorityClass)
3894  {
3895  /* Reset current privilege state */
3896  RealTimePrivilegeState = NULL;
3897 
3898  /* Is realtime priority being requested? */
3899  if (PriorityClass.PriorityClass == PROCESS_PRIORITY_CLASS_REALTIME)
3900  {
3901  /* Check if the caller has real-time access, and enable it if so */
3902  RealTimePrivilegeState = BasepIsRealtimeAllowed(TRUE);
3903  }
3904 
3905  /* Set the new priority class and release the privilege */
3908  &PriorityClass,
3909  sizeof(PROCESS_PRIORITY_CLASS));
3910  if (RealTimePrivilegeState) RtlReleasePrivilege(RealTimePrivilegeState);
3911 
3912  /* Check if we failed to set the priority class */
3913  if (!NT_SUCCESS(Status))
3914  {
3915  /* Bail out on failure */
3916  DPRINT1("Failed to set priority class: %lx\n", Status);
3918  Result = FALSE;
3919  goto Quickie;
3920  }
3921  }
3922 
3923  /* Check if the caller wants the default error mode */
3924  if (dwCreationFlags & CREATE_DEFAULT_ERROR_MODE)
3925  {
3926  /* Set Error Mode to only fail on critical errors */
3927  HardErrorMode = SEM_FAILCRITICALERRORS;
3930  &HardErrorMode,
3931  sizeof(ULONG));
3932  }
3933 
3934  /* Check if this was a VDM binary */
3935  if (VdmBinaryType)
3936  {
3937  /* Update VDM by telling it the process has now been created */
3938  VdmWaitObject = ProcessHandle;
3940  &VdmWaitObject,
3941  VdmTask,
3942  VdmBinaryType);
3943 
3944  if (!Result)
3945  {
3946  /* Bail out on failure */
3947  DPRINT1("Failed to update VDM with wait object\n");
3948  VdmWaitObject = NULL;
3949  goto Quickie;
3950  }
3951 
3952  /* At this point, a failure means VDM has to undo all the state */
3953  VdmUndoLevel |= VDM_UNDO_FULL;
3954  }
3955 
3956  /* Check if VDM needed reserved low-memory */
3957  if (VdmReserve)
3958  {
3959  /* Reserve the requested allocation */
3960  RegionSize = VdmReserve;
3962  &BaseAddress,
3963  0,
3964  &RegionSize,
3965  MEM_RESERVE,
3967  if (!NT_SUCCESS(Status))
3968  {
3969  /* Bail out on failure */
3970  DPRINT1("Failed to reserve memory for VDM: %lx\n", Status);
3972  Result = FALSE;
3973  goto Quickie;
3974  }
3975 
3976  VdmReserve = (ULONG)RegionSize;
3977  }
3978 
3979  /* Check if we've already queried information on the section */
3980  if (!QuerySection)
3981  {
3982  /* We haven't, so get some information about the executable */
3983  Status = NtQuerySection(SectionHandle,
3985  &ImageInformation,
3986  sizeof(ImageInformation),
3987  NULL);
3988  if (!NT_SUCCESS(Status))
3989  {
3990  /* Bail out on failure */
3991  DPRINT1("Failed to query section: %lx\n", Status);
3993  Result = FALSE;
3994  goto Quickie;
3995  }
3996 
3997  /* If we encounter a restart, don't re-query this information again */
3998  QuerySection = TRUE;
3999  }
4000 
4001  /* Do we need to apply SxS to this image? */
4003  {
4004  /* Too bad, we don't support this yet */
4005  DPRINT1("Image should receive SxS Fusion Isolation\n");
4006  }
4007 
4008  /* There's some SxS flag that we need to set if fusion flags have 1 set */
4009  if (FusionFlags & 1) CreateProcessMsg->Sxs.Flags |= 0x10;
4010 
4011  /* Check if we have a current directory */
4012  if (lpCurrentDirectory)
4013  {
4014  /* Allocate a buffer so we can keep a Unicode copy */
4015  DPRINT("Current directory: %S\n", lpCurrentDirectory);
4016  CurrentDirectory = RtlAllocateHeap(RtlGetProcessHeap(),
4017  0,
4018  (MAX_PATH * sizeof(WCHAR)) +
4019  sizeof(UNICODE_NULL));
4020  if (!CurrentDirectory)
4021  {
4022  /* Bail out if this failed */
4024  Result = FALSE;
4025  goto Quickie;
4026  }
4027 
4028  /* Get the length in Unicode */
4029  Length = GetFullPathNameW(lpCurrentDirectory,
4030  MAX_PATH,
4032  &FilePart);
4033  if (Length > MAX_PATH)
4034  {
4035  /* The directory is too long, so bail out */
4037  Result = FALSE;
4038  goto Quickie;
4039  }
4040 
4041  /* Make sure the directory is actually valid */
4042  FileAttribs = GetFileAttributesW(CurrentDirectory);
4043  if ((FileAttribs == INVALID_FILE_ATTRIBUTES) ||
4044  !(FileAttribs & FILE_ATTRIBUTE_DIRECTORY))
4045  {
4046  /* It isn't, so bail out */
4047  DPRINT1("Current directory is invalid\n");
4049  Result = FALSE;
4050  goto Quickie;
4051  }
4052  }
4053 
4054  /* Insert quotes if needed */
4055  if ((QuotesNeeded) || (CmdLineIsAppName))
4056  {
4057  /* Allocate our buffer, plus enough space for quotes and a NULL */
4058  QuotedCmdLine = RtlAllocateHeap(RtlGetProcessHeap(),
4059  0,
4060  (wcslen(lpCommandLine) * sizeof(WCHAR)) +
4061  (2 * sizeof(L'\"') + sizeof(UNICODE_NULL)));
4062  if (QuotedCmdLine)
4063  {
4064  /* Copy the first quote */
4065  wcscpy(QuotedCmdLine, L"\"");
4066 
4067  /* Save the current null-character */
4068  if (QuotesNeeded)
4069  {
4070  SaveChar = *NullBuffer;
4071  *NullBuffer = UNICODE_NULL;
4072  }
4073 
4074  /* Copy the command line and the final quote */
4075  wcscat(QuotedCmdLine, lpCommandLine);
4076  wcscat(QuotedCmdLine, L"\"");
4077 
4078  /* Copy the null-char back */
4079  if (QuotesNeeded)
4080  {
4081  *NullBuffer = SaveChar;
4082  wcscat(QuotedCmdLine, NullBuffer);
4083  }
4084  }
4085  else
4086  {
4087  /* We can't put quotes around the thing, so try it anyway */
4088  if (QuotesNeeded) QuotesNeeded = FALSE;
4089  if (CmdLineIsAppName) CmdLineIsAppName = FALSE;
4090  }
4091  }
4092 
4093  /* Use isolation if needed */
4094  if (CreateProcessMsg->Sxs.Flags & 1) ParameterFlags |= 1;
4095 
4096  /* Set the new command-line if needed */
4097  if ((QuotesNeeded) || (CmdLineIsAppName)) lpCommandLine = QuotedCmdLine;
4098 
4099  /* Call the helper function in charge of RTL_USER_PROCESS_PARAMETERS */
4100  Result = BasePushProcessParameters(ParameterFlags,
4101  ProcessHandle,
4102  RemotePeb,
4103  lpApplicationName,
4105  lpCommandLine,
4106  lpEnvironment,
4107  &StartupInfo,
4108  dwCreationFlags | NoWindow,
4109  bInheritHandles,
4110  IsWowApp ? IMAGE_SUBSYSTEM_WINDOWS_GUI: 0,
4111  AppCompatData,
4112  AppCompatDataSize);
4113  if (!Result)
4114  {
4115  /* The remote process would have an undefined state, so fail the call */
4116  DPRINT1("BasePushProcessParameters failed\n");
4117  goto Quickie;
4118  }
4119 
4120  /* Free the VDM command line string as it's no longer needed */
4121  RtlFreeUnicodeString(&VdmString);
4122  VdmString.Buffer = NULL;
4123 
4124  /* Non-VDM console applications usually inherit handles unless specified */
4125  if (!(VdmBinaryType) &&
4126  !(bInheritHandles) &&
4127  !(StartupInfo.dwFlags & STARTF_USESTDHANDLES) &&
4128  !(dwCreationFlags & (CREATE_NO_WINDOW |
4130  DETACHED_PROCESS)) &&
4131  (ImageInformation.SubSystemType == IMAGE_SUBSYSTEM_WINDOWS_CUI))
4132  {
4133  /* Get the remote parameters */
4135  &RemotePeb->ProcessParameters,
4136  &ProcessParameters,
4138  NULL);
4139  if (NT_SUCCESS(Status))
4140  {
4141  /* Duplicate standard input unless it's a console handle */
4143  {
4146  &ProcessParameters->StandardInput);
4147  }
4148 
4149  /* Duplicate standard output unless it's a console handle */
4151  {
4154  &ProcessParameters->StandardOutput);
4155  }
4156 
4157  /* Duplicate standard error unless it's a console handle */
4159  {
4162  &ProcessParameters->StandardError);
4163  }
4164  }
4165  }
4166 
4167  /* Create the Thread's Stack */
4168  StackSize = max(256 * 1024, ImageInformation.MaximumStackSize);
4170  ImageInformation.CommittedStackSize,
4171  StackSize,
4172  &InitialTeb);
4173  if (!NT_SUCCESS(Status))
4174  {
4175  DPRINT1("Creating the thread stack failed: %lx\n", Status);
4177  Result = FALSE;
4178  goto Quickie;
4179  }
4180 
4181  /* Create the Thread's Context */
4183  Peb,
4184  ImageInformation.TransferAddress,
4185  InitialTeb.StackBase,
4186  0);
4187 
4188  /* Convert the thread attributes */
4189  ObjectAttributes = BaseFormatObjectAttributes(&LocalObjectAttributes,
4190  lpThreadAttributes,
4191  NULL);
4192  if ((hUserToken) && (lpThreadAttributes))
4193  {
4194  /* If the caller specified a user token, zero the security descriptor */
4195  LocalThreadAttributes = *lpThreadAttributes;
4196  LocalThreadAttributes.lpSecurityDescriptor = NULL;
4197  ObjectAttributes = BaseFormatObjectAttributes(&LocalObjectAttributes,
4198  &LocalThreadAttributes,
4199  NULL);
4200  }
4201 
4202  /* Create the Kernel Thread Object */
4203  Status = NtCreateThread(&ThreadHandle,
4206  ProcessHandle,
4207  &ClientId,
4208  &Context,
4209  &InitialTeb,
4210  TRUE);
4211  if (!NT_SUCCESS(Status))
4212  {
4213  /* A process is not allowed to exist without a main thread, so fail */
4214  DPRINT1("Creating the main thread failed: %lx\n", Status);
4216  Result = FALSE;
4217  goto Quickie;
4218  }
4219 
4220  /* Begin filling out the CSRSS message, first with our IDs and handles */
4221  CreateProcessMsg->ProcessHandle = ProcessHandle;
4222  CreateProcessMsg->ThreadHandle = ThreadHandle;
4223  CreateProcessMsg->ClientId = ClientId;
4224 
4225  /* Write the remote PEB address and clear it locally, we no longer use it */
4226  CreateProcessMsg->PebAddressNative = RemotePeb;
4227 #ifdef _WIN64
4228  DPRINT1("TODO: WOW64 is not supported yet\n");
4229  CreateProcessMsg->PebAddressWow64 = 0;
4230 #else
4231  CreateProcessMsg->PebAddressWow64 = (ULONG)RemotePeb;
4232 #endif
4233  RemotePeb = NULL;
4234 
4235  /* Now check what kind of architecture this image was made for */
4236  switch (ImageInformation.Machine)
4237  {
4238  /* IA32, IA64 and AMD64 are supported in Server 2003 */
4241  break;
4244  break;
4247  break;
4248 
4249  /* Anything else results in image unknown -- but no failure */
4250  default:
4251  DbgPrint("kernel32: No mapping for ImageInformation.Machine == %04x\n",
4252  ImageInformation.Machine);
4254  break;
4255  }
4256 
4257  /* Write the input creation flags except any debugger-related flags */
4258  CreateProcessMsg->CreationFlags = dwCreationFlags &
4260 
4261  /* CSRSS needs to know if this is a GUI app or not */
4262  if ((ImageInformation.SubSystemType == IMAGE_SUBSYSTEM_WINDOWS_GUI) ||
4263  (IsWowApp))
4264  {
4265  /*
4266  * For GUI apps we turn on the 2nd bit. This allow CSRSS server dlls
4267  * (basesrv in particular) to know whether or not this is a GUI or a
4268  * TUI application.
4269  */
4270  AddToHandle(CreateProcessMsg->ProcessHandle, 2);
4271 
4272  /* Also check if the parent is also a GUI process */
4273  NtHeaders = RtlImageNtHeader(GetModuleHandle(NULL));
4274  if ((NtHeaders) &&
4276  {
4277  /* Let it know that it should display the hourglass mouse cursor */
4278  AddToHandle(CreateProcessMsg->ProcessHandle, 1);
4279  }
4280  }
4281 
4282  /* For all apps, if this flag is on, the hourglass mouse cursor is shown */
4283  if (StartupInfo.dwFlags & STARTF_FORCEONFEEDBACK)
4284  {
4285  AddToHandle(CreateProcessMsg->ProcessHandle, 1);
4286  }
4287 
4288  /* Likewise, the opposite holds as well */
4289  if (StartupInfo.dwFlags & STARTF_FORCEOFFFEEDBACK)
4290  {
4291  RemoveFromHandle(CreateProcessMsg->ProcessHandle, 1);
4292  }
4293 
4294  /* Also store which kind of VDM app (if any) this is */
4295  CreateProcessMsg->VdmBinaryType = VdmBinaryType;
4296 
4297  /* And if it really is a VDM app... */
4298  if (VdmBinaryType)
4299  {
4300  /* Store the task ID and VDM console handle */
4301  CreateProcessMsg->hVDM = VdmTask ? 0 : Peb->ProcessParameters->ConsoleHandle;
4302  CreateProcessMsg->VdmTask = VdmTask;
4303  }
4304  else if (VdmReserve)
4305  {
4306  /* Extended VDM, set a flag */
4307  CreateProcessMsg->VdmBinaryType |= BINARY_TYPE_WOW_EX;
4308  }
4309 
4310  /* Check if there's side-by-side assembly data associated with the process */
4311  if (CreateProcessMsg->Sxs.Flags)
4312  {
4313  /* This should not happen in ReactOS yet */
4314  DPRINT1("This is an SxS Message -- should not happen yet\n");
4317  Result = FALSE;
4318  goto Quickie;
4319  }
4320 
4321  /* We are finally ready to call CSRSS to tell it about our new process! */
4323  CaptureBuffer,
4326  sizeof(*CreateProcessMsg));
4327 
4328  /* CSRSS has returned, free the capture buffer now if we had one */
4329  if (CaptureBuffer)
4330  {
4331  CsrFreeCaptureBuffer(CaptureBuffer);
4332  CaptureBuffer = NULL;
4333  }
4334 
4335  /* Check if CSRSS failed to accept ownership of the new Windows process */
4336  if (!NT_SUCCESS(CsrMsg[0].Status))
4337  {
4338  /* Terminate the process and enter failure path with the CSRSS status */
4339  DPRINT1("Failed to tell csrss about new process\n");
4340  BaseSetLastNTError(CsrMsg[0].Status);
4342  Result = FALSE;
4343  goto Quickie;
4344  }
4345 
4346  /* Check if we have a token due to Authz/Safer, not passed by the user */
4347  if ((TokenHandle) && !(hUserToken))
4348  {
4349  /* Replace the process and/or thread token with the one from Safer */
4351  ProcessHandle,
4352  ThreadHandle);
4353  if (!NT_SUCCESS(Status))
4354  {
4355  /* If this failed, kill the process and enter the failure path */
4356  DPRINT1("Failed to update process token: %lx\n", Status);
4359  Result = FALSE;
4360  goto Quickie;
4361  }
4362  }
4363 
4364  /* Check if a job was associated with this process */
4365  if (JobHandle)
4366  {
4367  /* Bind the process and job together now */
4369  if (!NT_SUCCESS(Status))
4370  {
4371  /* Kill the process and enter the failure path if binding failed */
4372  DPRINT1("Failed to assign process to job: %lx\n", Status);
4375  Result = FALSE;
4376  goto Quickie;
4377  }
4378  }
4379 
4380  /* Finally, resume the thread to actually get the process started */
4381  if (!(dwCreationFlags & CREATE_SUSPENDED))
4382  {
4383  NtResumeThread(ThreadHandle, &ResumeCount);
4384  }
4385 
4386 VdmShortCircuit:
4387  /* We made it this far, meaning we have a fully created process and thread */
4388  Result = TRUE;
4389 
4390  /* Anyone doing a VDM undo should now undo everything, since we are done */
4391  if (VdmUndoLevel) VdmUndoLevel |= VDM_UNDO_COMPLETED;
4392 
4393  /* Having a VDM wait object implies this must be a VDM process */
4394  if (VdmWaitObject)
4395  {
4396  /* Check if it's a 16-bit separate WOW process */
4397  if (VdmBinaryType == BINARY_TYPE_SEPARATE_WOW)
4398  {
4399  /* OR-in the special flag to indicate this, and return to caller */
4400  AddToHandle(VdmWaitObject, 2);
4401  lpProcessInformation->hProcess = VdmWaitObject;
4402 
4403  /* Check if this was a re-used VDM */
4404  if (VdmUndoLevel & VDM_UNDO_REUSE)
4405  {
4406  /* No Client ID should be returned in this case */
4407  ClientId.UniqueProcess = 0;
4408  ClientId.UniqueThread = 0;
4409  }
4410  }
4411  else
4412  {
4413  /* OR-in the special flag to indicate this is not a separate VDM */
4414  AddToHandle(VdmWaitObject, 1);
4415 
4416  /* Return handle to the caller */
4417  lpProcessInformation->hProcess = VdmWaitObject;
4418  }
4419 
4420  /* Close the original process handle, since it's not needed for VDM */
4422  }
4423  else
4424  {
4425  /* This is a regular process, so return the real process handle */
4426  lpProcessInformation->hProcess = ProcessHandle;
4427  }
4428 
4429  /* Return the rest of the process information based on what we have so far */
4430  lpProcessInformation->hThread = ThreadHandle;
4431  lpProcessInformation->dwProcessId = HandleToUlong(ClientId.UniqueProcess);
4432  lpProcessInformation->dwThreadId = HandleToUlong(ClientId.UniqueThread);
4433 
4434  /* NULL these out here so we know to treat this as a success scenario */
4435  ProcessHandle = NULL;
4436  ThreadHandle = NULL;
4437 
4438 Quickie:
4439  /* Free the debugger command line if one was allocated */
4440  if (DebuggerCmdLine) RtlFreeHeap(RtlGetProcessHeap(), 0, DebuggerCmdLine);
4441 
4442  /* Check if an SxS full path as queried */
4443  if (PathBuffer)
4444  {
4445  /* Reinitialize the executable path */
4446  RtlInitEmptyUnicodeString(&SxsWin32ExePath, NULL, 0);
4447  SxsWin32ExePath.Length = 0;
4448 
4449  /* Free the path buffer */
4450  RtlFreeHeap(RtlGetProcessHeap(), 0, PathBuffer);
4451  }
4452 
4453 #if _SXS_SUPPORT_ENABLED_
4454  /* Check if this was a non-VDM process */
4455  if (!VdmBinaryType)
4456  {
4457  /* Then it must've had SxS data, so close the handles used for it */
4458  BasepSxsCloseHandles(&Handles);
4459  BasepSxsCloseHandles(&FileHandles);
4460 
4461  /* Check if we built SxS byte buffers for this create process request */
4462  if (SxsConglomeratedBuffer)
4463  {
4464  /* Loop all of them */
4465  for (i = 0; i < 5; i++)
4466  {
4467  /* Check if this one was allocated */
4468  ThisBuffer = SxsStaticBuffers[i];
4469  if (ThisBuffer)
4470  {
4471  /* Get the underlying RTL_BUFFER structure */
4472  ByteBuffer = &ThisBuffer->ByteBuffer;
4473  if ((ThisBuffer != (PVOID)-8) && (ByteBuffer->Buffer))
4474  {
4475  /* Check if it was dynamic */
4476  if (ByteBuffer->Buffer != ByteBuffer->StaticBuffer)
4477  {
4478  /* Free it from the heap */
4479  FreeString.Buffer = (PWCHAR)ByteBuffer->Buffer;
4480  RtlFreeUnicodeString(&FreeString);
4481  }
4482 
4483  /* Reset the buffer to its static data */
4484  ByteBuffer->Buffer = ByteBuffer->StaticBuffer;
4485  ByteBuffer->Size = ByteBuffer->StaticSize;
4486  }
4487 
4488  /* Reset the string to the static buffer */
4489  RtlInitEmptyUnicodeString(&ThisBuffer->String,
4490  (PWCHAR)ByteBuffer->StaticBuffer,
4491  ByteBuffer->StaticSize);
4492  if (ThisBuffer->String.Buffer)
4493  {
4494  /* Also NULL-terminate it */
4495  *ThisBuffer->String.Buffer = UNICODE_NULL;
4496  }
4497  }
4498  }
4499  }
4500  }
4501 #endif
4502  /* Check if an environment was passed in */
4503  if ((lpEnvironment) && !(dwCreationFlags & CREATE_UNICODE_ENVIRONMENT))
4504  {
4505  /* Destroy it */
4506  RtlDestroyEnvironment(lpEnvironment);
4507 
4508  /* If this was the VDM environment too, clear that as well */
4509  if (VdmUnicodeEnv.Buffer == lpEnvironment) VdmUnicodeEnv.Buffer = NULL;
4510  lpEnvironment = NULL;
4511  }
4512 
4513  /* Unconditionally free all the name parsing buffers we always allocate */
4514  RtlFreeHeap(RtlGetProcessHeap(), 0, QuotedCmdLine);
4515  RtlFreeHeap(RtlGetProcessHeap(), 0, NameBuffer);
4516  RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentDirectory);
4517  RtlFreeHeap(RtlGetProcessHeap(), 0, FreeBuffer);
4518 
4519  /* Close open file/section handles */
4521  if (SectionHandle) NtClose(SectionHandle);
4522 
4523  /* If we have a thread handle, this was a failure path */
4524  if (ThreadHandle)
4525  {
4526  /* So kill the process and close the thread handle */
4528  NtClose(ThreadHandle);
4529  }
4530 
4531  /* If we have a process handle, this was a failure path, so close it */
4533 
4534  /* Thread/process handles, if any, are now processed. Now close this one. */
4535  if (JobHandle) NtClose(JobHandle);
4536 
4537  /* Check if we had created a token */
4538  if (TokenHandle)
4539  {
4540  /* And if the user asked for one */
4541  if (hUserToken)
4542  {
4543  /* Then return it */
4544  *hNewToken = TokenHandle;
4545  }
4546  else
4547  {
4548  /* User didn't want it, so we used it temporarily -- close it */
4550  }
4551  }
4552 
4553  /* Free any temporary app compatibility data, it's no longer needed */
4554  BasepFreeAppCompatData(AppCompatData, AppCompatSxsData);
4555 
4556  /* Free a few strings. The API takes care of these possibly being NULL */
4557  RtlFreeUnicodeString(&VdmString);
4558  RtlFreeUnicodeString(&DebuggerString);
4559 
4560  /* Check if we had built any sort of VDM environment */
4561  if ((VdmAnsiEnv.Buffer) || (VdmUnicodeEnv.Buffer))
4562  {
4563  /* Free it */
4564  BaseDestroyVDMEnvironment(&VdmAnsiEnv, &VdmUnicodeEnv);
4565  }
4566 
4567  /* Check if this was any kind of VDM application that we ended up creating */
4568  if ((VdmUndoLevel) && (!(VdmUndoLevel & VDM_UNDO_COMPLETED)))
4569  {
4570  /* Send an undo */
4572  (PHANDLE)&VdmTask,
4573  VdmUndoLevel,
4574  VdmBinaryType);
4575 
4576  /* And close whatever VDM handle we were using for notifications */
4577  if (VdmWaitObject) NtClose(VdmWaitObject);
4578  }
4579 
4580  /* Check if we ended up here with an allocated search path, and free it */
4581  if (SearchPath) RtlFreeHeap(RtlGetProcessHeap(), 0, SearchPath);
4582 
4583  /* Finally, return the API's result */
4584  return Result;
4585 }
HANDLE NTAPI DbgUiGetThreadDebugObject(VOID)
Definition: dbgui.c:333
BASE_SXS_CREATEPROCESS_MSG Sxs
Definition: basemsg.h:96
signed char * PCHAR
Definition: retypes.h:7
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
VOID WINAPI BasepFreeAppCompatData(IN PVOID AppCompatData, IN PVOID AppCompatSxsData)
Definition: appcache.c:342
#define ERROR_CHILD_NOT_COMPLETE
Definition: winerror.h:201
PVOID WINAPI BasepIsRealtimeAllowed(IN BOOLEAN Keep)
Definition: utils.c:663
ULONG ImageSubsystemMajorVersion
Definition: ntddk_ex.h:305
VOID NTAPI CsrFreeCaptureBuffer(IN PCSR_CAPTURE_BUFFER CaptureBuffer)
Definition: capture.c:189
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
enum _RTL_PATH_TYPE RTL_PATH_TYPE
#define STATUS_INVALID_IMAGE_WIN_64
Definition: ntstatus.h:887
#define RemoveFromHandle(x, y)
Definition: proc.c:2226
NTSTATUS WINAPI BaseCreateStack(_In_ HANDLE hProcess, _In_opt_ SIZE_T StackCommit, _In_opt_ SIZE_T StackReserve, _Out_ PINITIAL_TEB InitialTeb)
Definition: utils.c:354
NTSTATUS NTAPI DbgUiConnectToDbg(VOID)
Definition: dbgui.c:25
NTSTATUS NTAPI LdrQueryImageFileKeyOption(IN HANDLE KeyHandle, IN PCWSTR ValueName, IN ULONG Type, OUT PVOID Buffer, IN ULONG BufferSize, OUT PULONG ReturnedLength OPTIONAL)
Definition: ldrinit.c:184
VOID WINAPI BaseInitializeContext(IN PCONTEXT Context, IN PVOID Parameter, IN PVOID StartAddress, IN PVOID StackAddress, IN ULONG ContextType)
Definition: utils.c:513
#define max(a, b)
Definition: svc.c:63
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
PVOID PVOID PWCHAR PVOID USHORT PULONG PVOID PULONG PVOID PULONG PULONG FusionFlags
Definition: env.c:45
#define REALTIME_PRIORITY_CLASS
Definition: winbase.h:184
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
#define IMAGE_SUBSYSTEM_POSIX_CUI
Definition: ntimage.h:440
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
PPEB Peb
Definition: dllmain.c:27
#define CREATE_FORCEDOS
Definition: winbase.h:189
#define PROCESS_PRIORITY_CLASS_INVALID
Definition: pstypes.h:106
#define PROCESS_ALL_ACCESS
Definition: nt_native.h:1324
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:3373
#define SEM_FAILCRITICALERRORS
Definition: rtltypes.h:69
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)
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:553
#define BINARY_TYPE_WOW
Definition: vdm.h:40
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define DbgPrint
Definition: loader.c:25
BOOL WINAPI BaseUpdateVDMEntry(IN ULONG UpdateIndex, IN OUT PHANDLE WaitHandle, IN ULONG IndexInfo, IN ULONG BinaryType)
Definition: vdm.c:534
SIZE_T Size
Definition: rtltypes.h:1809
PBASE_STATIC_SERVER_DATA BaseStaticServerData
Definition: dllmain.c:19
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define CREATE_SEPARATE_WOW_VDM
Definition: winbase.h:187
#define CREATE_UNICODE_ENVIRONMENT
Definition: winbase.h:186
#define PROCESSOR_ARCHITECTURE_UNKNOWN
Definition: ketypes.h:115
WCHAR CurrentDirectory[1024]
Definition: chkdsk.c:74
#define SE_LOCK_MEMORY_PRIVILEGE
Definition: security.c:658
#define AddToHandle(x, y)
Definition: proc.c:2225
NTSYSAPI VOID NTAPI RtlDestroyEnvironment(_In_ PWSTR Environment)
BOOL NTAPI BaseCreateVDMEnvironment(IN PWCHAR lpEnvironment, OUT PANSI_STRING AnsiEnv, OUT PUNICODE_STRING UnicodeEnv)
Definition: vdm.c:736
NTSTATUS WINAPI BasepCheckWinSaferRestrictions(IN HANDLE UserToken, IN LPWSTR ApplicationName, IN HANDLE FileHandle, OUT PBOOLEAN InJob, OUT PHANDLE NewToken, OUT PHANDLE JobHandle)
Definition: utils.c:919
static DWORD ResumeCount
Definition: database.c:32
NTSTATUS NTAPI CsrClientCallServer(IN OUT PCSR_API_MESSAGE ApiMessage, IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer OPTIONAL, IN CSR_API_NUMBER ApiNumber, IN ULONG DataLength)
Definition: connect.c:365
HANDLE ContainingDirectory
Definition: rtltypes.h:1375
#define VER_SUITE_BLADE
BOOL WINAPI BaseGetVdmConfigInfo(IN LPCWSTR CommandLineReserved, IN ULONG DosSeqId, IN ULONG BinaryType, IN PUNICODE_STRING CmdLineString, OUT PULONG VdmSize)
Definition: vdm.c:644
BASE_CREATE_PROCESS CreateProcessRequest
Definition: basemsg.h:283
BOOL NTAPI BaseDestroyVDMEnvironment(IN PANSI_STRING AnsiEnv, IN PUNICODE_STRING UnicodeEnv)
Definition: vdm.c:1026
VOID NTAPI RtlReleaseRelativeName(_In_ PRTL_RELATIVE_NAME_U RelativeName)
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN DefaultSeparateVDM
Definition: base.h:126
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define HandleToUlong(h)
Definition: basetsd.h:79
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
GLdouble n
Definition: glext.h:7729
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1105
#define ERROR_BAD_DEVICE
Definition: winerror.h:703
#define CREATE_DEFAULT_ERROR_MODE
Definition: winbase.h:194
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)
#define VDM_UNDO_COMPLETED
Definition: vdm.h:30
uint16_t * PWCHAR
Definition: typedefs.h:55
#define STARTF_FORCEONFEEDBACK
Definition: winbase.h:478
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define NORMAL_PRIORITY_CLASS
Definition: winbase.h:181
#define PROCESS_CREATE_FLAGS_LARGE_PAGES
Definition: pstypes.h:95
HANDLE UniqueProcess
Definition: compat.h:482
UNICODE_STRING DesktopInfo
Definition: rtltypes.h:1526
#define UNICODE_STRING_MAX_BYTES
#define ERROR_DIRECTORY
Definition: winerror.h:295
#define ERROR_ACCESS_DISABLED_WEBBLADE
Definition: winerror.h:774
#define MEM_COMMIT
Definition: nt_native.h:1313
#define VER_SUITE_DATACENTER
#define IMAGE_FILE_MACHINE_AMD64
Definition: ntimage.h:17
#define STATUS_VDM_DISALLOWED
Definition: ntstatus.h:943
#define VER_SUITE_PERSONAL
PVOID ArbitraryUserPointer
Definition: compat.h:387
NTSTATUS NTAPI LdrOpenImageFileOptionsKey(IN PUNICODE_STRING SubKey, IN BOOLEAN Wow64, OUT PHANDLE NewKeyHandle)
Definition: ldrinit.c:112
#define IMAGE_FILE_DLL
Definition: pedump.c:169
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
#define FILE_SHARE_READ
Definition: compat.h:125
#define STARTF_FORCEOFFFEEDBACK
Definition: winbase.h:479
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToRelativeNtPathName_U(_In_ PCWSTR DosName, _Out_ PUNICODE_STRING NtName, _Out_ PCWSTR *PartName, _Out_ PRTL_RELATIVE_NAME_U RelativeName)
#define SearchPath
Definition: winbase.h:3734
#define ABOVE_NORMAL_PRIORITY_CLASS
Definition: winbase.h:191
uint32_t ULONG_PTR
Definition: typedefs.h:64
#define PROCESSOR_ARCHITECTURE_IA64
Definition: ketypes.h:111
#define CREATE_NO_WINDOW
Definition: winbase.h:195
HANDLE ThreadHandle
Definition: basemsg.h:90
static IN ULONG IN PWSTR OUT PCWSTR OUT PBOOLEAN OUT PATH_TYPE_AND_UNKNOWN * PathType
#define VDM_READY
Definition: vdm.h:48
HANDLE FileHandle
Definition: stats.c:38
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
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 CREATE_SUSPENDED
Definition: winbase.h:178
#define UNICODE_NULL
#define ANSI_NULL
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
BOOLEAN WINAPI BasepIsImageVersionOk(IN ULONG ImageMajorVersion, IN ULONG ImageMinorVersion)
Definition: proc.c:123
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define STARTF_SHELLPRIVATE
Definition: kernel32.h:60
#define FILE_READ_DATA
Definition: nt_native.h:628
HANDLE WaitObjectForParent
Definition: basemsg.h:123
#define MEM_RESERVE
Definition: nt_native.h:1314
LPWSTR lpDesktop
Definition: winbase.h:826
BASE_CHECK_VDM CheckVDMRequest
Definition: basemsg.h:287
#define IMAGE_SUBSYSTEM_WINDOWS_CUI
Definition: ntimage.h:438
#define HIGH_PRIORITY_CLASS
Definition: winbase.h:183
unsigned char BOOLEAN
#define ERROR_BAD_EXE_FORMAT
Definition: winerror.h:251
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_NOT_READY
Definition: winerror.h:124
NTSYSAPI VOID NTAPI RtlReleasePrivilege(_In_ PVOID ReturnedState)
_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:426
#define PAGE_EXECUTE
Definition: nt_native.h:1306
PVOID StackBase
Definition: pstypes.h:678
void DPRINT(...)
Definition: polytest.cpp:61
_In_ ACCESS_MASK _In_ ULONG _Out_ PHANDLE TokenHandle
Definition: psfuncs.h:715
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define PROCESS_PRIORITY_CLASS_NORMAL
Definition: pstypes.h:108
void * PVOID
Definition: retypes.h:9
NTSTATUS WINAPI BasepReplaceProcessThreadTokens(IN HANDLE TokenHandle, IN HANDLE ProcessHandle, IN HANDLE ThreadHandle)
Definition: proc.c:354
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:4259
#define OPEN_EXISTING
Definition: compat.h:434
#define VDM_UNDO_FULL
Definition: vdm.h:28
#define STATUS_NAME_TOO_LONG
Definition: ntstatus.h:484
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define PCHAR
Definition: match.c:90
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define IMAGE_FILE_MACHINE_I386
Definition: pedump.c:174
#define PROCESS_PRIORITY_CLASS_ABOVE_NORMAL
Definition: pstypes.h:112
#define CREATE_SHARED_WOW_VDM
Definition: winbase.h:188
HANDLE hUserToken
Definition: install.c:39
#define STATUS_INVALID_IMAGE_PROTECT
Definition: ntstatus.h:526
#define STARTF_USESTDHANDLES
Definition: winbase.h:480
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
USHORT MaximumLength
Definition: env_spec_w32.h:377
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
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define STATUS_INVALID_IMAGE_NOT_MZ
Definition: ntstatus.h:525
#define CMD_STRING
Definition: proc.c:51
NTSTATUS NTAPI NtResumeThread(IN HANDLE ThreadHandle, OUT PULONG SuspendCount OPTIONAL)
Definition: state.c:290
#define IDLE_PRIORITY_CLASS
Definition: winbase.h:182
#define PROCESS_CREATE_FLAGS_INHERIT_HANDLES
Definition: pstypes.h:93
#define UNICODE_STRING_MAX_CHARS
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
#define CREATE_NEW_CONSOLE
Definition: winbase.h:180
#define PROCESS_PRIORITY_CLASS_REALTIME
Definition: pstypes.h:110
#define BASESRV_SERVERDLL_INDEX
Definition: basemsg.h:15
BOOLEAN IsWowTaskReady
Definition: base.h:127
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG WINAPI BaseIsDosApplication(IN PUNICODE_STRING PathName, IN NTSTATUS Status)
Definition: vdm.c:66
#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION
Definition: ntimage.h:458
#define MAX_PATH
Definition: compat.h:26
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define SetLastError(x)
Definition: compat.h:417
#define STATUS_IMAGE_MACHINE_TYPE_MISMATCH_EXE
Definition: ntstatus.h:149
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define BINARY_TYPE_SEPARATE_WOW
Definition: vdm.h:39
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define PROCESS_PRIORITY_CLASS_HIGH
Definition: pstypes.h:109
#define DEBUG_PROCESS
Definition: winbase.h:176
HANDLE ProcessHandle
Definition: basemsg.h:89
#define IsConsoleHandle(h)
Definition: console.h:14
NTSTATUS NTAPI NtReadVirtualMemory(IN HANDLE ProcessHandle, IN PVOID BaseAddress, OUT PVOID Buffer, IN SIZE_T NumberOfBytesToRead, OUT PSIZE_T NumberOfBytesRead OPTIONAL)
Definition: virtual.c:2691
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define PROCESSOR_ARCHITECTURE_AMD64
Definition: ketypes.h:114
HANDLE UniqueThread
Definition: compat.h:483
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define ERROR_EXE_MACHINE_TYPE_MISMATCH
Definition: winerror.h:271
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define SharedUserData
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
static const WCHAR L[]
Definition: oid.c:1250
UNICODE_STRING String
Definition: rtltypes.h:1817
PRTL_USER_PROCESS_PARAMETERS ProcessParameters
Definition: btrfs_drv.h:1890
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
#define FILE_EXECUTE
Definition: nt_native.h:642
PUNICODE_STRING Nt
Definition: kernel32.h:403
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define GENERIC_READ
Definition: compat.h:124
#define VDM_UNDO_REUSE
Definition: vdm.h:29
_In_ USHORT _In_ CCHAR StackSize
Definition: iofuncs.h:1056
#define SYNCHRONIZE
Definition: nt_native.h:61
#define PROCESS_CREATE_FLAGS_NO_DEBUG_INHERIT
Definition: pstypes.h:92
POBJECT_ATTRIBUTES WINAPI BaseFormatObjectAttributes(OUT POBJECT_ATTRIBUTES ObjectAttributes, IN PSECURITY_ATTRIBUTES SecurityAttributes OPTIONAL, IN PUNICODE_STRING ObjectName)
Definition: utils.c:304
NTSTATUS NTAPI NtAssignProcessToJobObject(HANDLE JobHandle, HANDLE ProcessHandle)
Definition: job.c:157
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:1297
Status
Definition: gdiplustypes.h:24
PUCHAR StaticBuffer
Definition: rtltypes.h:1808
#define PROCESSOR_ARCHITECTURE_INTEL
Definition: ketypes.h:105
#define STATUS_FILE_IS_OFFLINE
Definition: ntstatus.h:726
ULONG_PTR SIZE_T
Definition: typedefs.h:79
Definition: compat.h:492
#define ERROR_FILE_OFFLINE
Definition: winerror.h:1285
#define VER_SUITE_EMBEDDEDNT
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
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:4367
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112
LPVOID lpSecurityDescriptor
Definition: compat.h:181
#define GetModuleHandle
Definition: winbase.h:3661
#define ERROR_CANCELLED
Definition: winerror.h:726
#define NtCurrentPeb()
Definition: FLS.c:20
unsigned short USHORT
Definition: pedump.c:61
__kernel_entry _Inout_ _Inout_ PSIZE_T RegionSize
Definition: mmfuncs.h:172
VOID WINAPI StuffStdHandle(IN HANDLE ProcessHandle, IN HANDLE StandardHandle, IN PHANDLE Address)
Definition: proc.c:57
SIZE_T StaticSize
Definition: rtltypes.h:1810
NTSTATUS WINAPI BasepCheckWebBladeHashes(IN HANDLE FileHandle)
Definition: proc.c:149
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
#define VDM_NOT_LOADED
Definition: vdm.h:46
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define VDM_NOT_READY
Definition: vdm.h:47
#define DETACHED_PROCESS
Definition: winbase.h:179
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define VDM_UNDO_PARTIAL
Definition: vdm.h:27
union _BASE_API_MESSAGE::@3407 Data
#define PROCESS_CREATE_FLAGS_BREAKAWAY
Definition: pstypes.h:91
LPWSTR WINAPI BaseComputeProcessExePath(IN LPWSTR FullPath)
Definition: path.c:405
USHORT ProcessorArchitecture
Definition: basemsg.h:99
#define MAXUSHORT
Definition: typedefs.h:82
USHORT VDMState
Definition: basemsg.h:147
#define DPRINT1
Definition: precomp.h:8
#define RtlImageNtHeader
Definition: compat.h:465
#define CreateFileW
Definition: compat.h:408
PUNICODE_STRING Win32
Definition: kernel32.h:402
NTSYSAPI NTSTATUS NTAPI RtlAcquirePrivilege(_In_ PULONG Privilege, _In_ ULONG NumPriv, _In_ ULONG Flags, _Out_ PVOID *ReturnedState)
#define BINARY_TYPE_WOW_EX
Definition: vdm.h:41
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define MEM_RELEASE
Definition: nt_native.h:1316
PUCHAR Buffer
Definition: rtltypes.h:1807
#define STATUS_INVALID_IMAGE_NE_FORMAT
Definition: ntstatus.h:505
PVOID PebAddressNative
Definition: basemsg.h:97
#define BELOW_NORMAL_PRIORITY_CLASS
Definition: winbase.h:190
struct tagContext Context
Definition: acpixf.h:1030
ULONG PebAddressWow64
Definition: basemsg.h:98
CLIENT_ID ClientId
Definition: basemsg.h:91
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
NTSTATUS NTAPI NtTerminateProcess(HANDLE ProcessHandle, LONG ExitStatus)
#define ULONG_PTR
Definition: config.h:101
#define BINARY_TYPE_DOS
Definition: vdm.h:38
#define SEC_IMAGE
Definition: mmtypes.h:96
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
UNICODE_STRING RelativeName
Definition: rtltypes.h:1374
#define PROCESS_PRIORITY_CLASS_BELOW_NORMAL
Definition: pstypes.h:111
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
DWORD dwFlags
Definition: winbase.h:835
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define ERROR_ACCESS_DISABLED_WEBBLADE_TAMPER
Definition: winerror.h:775
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define ERROR_ACCESS_DISABLED_BY_POLICY
Definition: winerror.h:763
NTSTATUS NTAPI NtIsProcessInJob(IN HANDLE ProcessHandle, IN HANDLE JobHandle OPTIONAL)
Definition: job.c:361
#define PROCESS_PRIORITY_CLASS_IDLE
Definition: pstypes.h:107
#define CREATE_PRESERVE_CODE_AUTHZ_LEVEL
Definition: winbase.h:193
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
#define DEBUG_ONLY_THIS_PROCESS
Definition: winbase.h:177
return STATUS_SUCCESS
Definition: btrfs.c:2938
BOOLEAN WINAPI BuildSubSysCommandLine(IN LPCWSTR SubsystemName, IN LPCWSTR ApplicationName, IN LPCWSTR CommandLine, OUT PUNICODE_STRING SubsysCommandLine)
Definition: proc.c:89
#define REG_DWORD
Definition: sdbapi.c:596
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:1344
VOID WINAPI BasepSxsCloseHandles(IN PBASE_MSG_SXS_HANDLES Handles)
Definition: proc.c:417
#define STATUS_INVALID_IMAGE_WIN_16
Definition: ntstatus.h:527
#define IMAGE_FILE_MACHINE_IA64
Definition: ntimage.h:22
NT_TIB NtTib
Definition: ntddk_ex.h:332
NTSYSAPI ULONG NTAPI RtlIsDosDeviceName_U(_In_ PCWSTR Name)
NTSTATUS WINAPI BasepIsProcessAllowed(IN LPWSTR ApplicationName)
Definition: proc.c:202
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
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:484
#define BINARY_TYPE_EXE
Definition: vdm.h:35
#define PAGE_READWRITE
Definition: nt_native.h:1304
NTSYSAPI RTL_PATH_TYPE NTAPI RtlDetermineDosPathNameType_U(_In_ PCWSTR Path)
#define IMAGE_SUBSYSTEM_WINDOWS_GUI
Definition: ntimage.h:437
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:272
#define REG_SZ
Definition: layer.c:22
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5090

Referenced by CreateProcessInternalA(), and 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 4593 of file proc.c.

4603 {
4604  /* Call the internal (but exported) version */
4606  lpApplicationName,
4607  lpCommandLine,
4608  lpProcessAttributes,
4609  lpThreadAttributes,
4610  bInheritHandles,
4611  dwCreationFlags,
4612  lpEnvironment,
4613  lpCurrentDirectory,
4614  lpStartupInfo,
4615  lpProcessInformation,
4616  NULL);
4617 }
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:2234
smooth NULL
Definition: ftsmooth.c:416

Referenced by CorDebug_CreateProcess(), CProcess::CProcess(), create_server(), CreateClientProcess(), CreateProcessAsUserW(), CreateProcessWithTokenW(), do_register_dll(), execute_command(), HotkeyThread(), IDirectInputAImpl_RunControlPanel(), install_wine_gecko(), InstallDevice(), InstallLiveCD(), ITERATE_RemoveExistingProducts(), CNetConnectionPropertyUi::LANPropertiesUIDlg(), launch_exe(), CNewMenu::NewItemByCommand(), ProcessPage_OnDebug(), register_dll(), run_child(), run_winemenubuilder(), runCmd(), RunControlPanelApplet(), RunNextJob(), RunSetupThreadProc(), ScmStartUserModeService(), SHELL_ExecuteW(), START_TEST(), StartChild(), StartLsass(), StartProcess(), StartScreenSaver(), StartServicesManager(), Test_CommandLine(), TestStaticDestruct(), UnhandledExceptionFilter(), WshExec_create(), and wWinMain().

◆ ExitProcess()

VOID WINAPI ExitProcess ( IN UINT  uExitCode)

Definition at line 1487 of file proc.c.

1488 {
1489  BASE_API_MESSAGE ApiMessage;
1490  PBASE_EXIT_PROCESS ExitProcessRequest = &ApiMessage.Data.ExitProcessRequest;
1491 
1493 
1494  _SEH2_TRY
1495  {
1496  /* Acquire the PEB lock */
1498 
1499  /* Kill all the threads */
1500  NtTerminateProcess(NULL, uExitCode);
1501 
1502  /* Unload all DLLs */
1504 
1505  /* Notify Base Server of process termination */
1506  ExitProcessRequest->uExitCode = uExitCode;
1508  NULL,
1510  sizeof(*ExitProcessRequest));
1511 
1512  /* Now do it again */
1513  NtTerminateProcess(NtCurrentProcess(), uExitCode);
1514  }
1516  {
1517  /* Release the PEB lock */
1519  }
1520  _SEH2_END;
1521 
1522  /* should never get here */
1523  ASSERT(0);
1524  while(1);
1525 }
NTSTATUS NTAPI LdrShutdownProcess(VOID)
Definition: ldrinit.c:939
NTSTATUS NTAPI CsrClientCallServer(IN OUT PCSR_API_MESSAGE ApiMessage, IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer OPTIONAL, IN CSR_API_NUMBER ApiNumber, IN ULONG DataLength)
Definition: connect.c:365
VOID NTAPI RtlReleasePebLock(VOID)
Definition: libsupp.c:82
_SEH2_TRY
Definition: create.c:4250
smooth NULL
Definition: ftsmooth.c:416
BASE_EXIT_PROCESS ExitProcessRequest
Definition: basemsg.h:286
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
BOOLEAN BaseRunningInServerProcess
Definition: dllmain.c:20
#define BASESRV_SERVERDLL_INDEX
Definition: basemsg.h:15
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_SEH2_END
Definition: create.c:4424
_SEH2_FINALLY
Definition: create.c:4395
union _BASE_API_MESSAGE::@3407 Data
VOID NTAPI RtlAcquirePebLock(VOID)
Definition: libsupp.c:72
NTSTATUS NTAPI NtTerminateProcess(HANDLE ProcessHandle, LONG ExitStatus)

Referenced by __declspec(), _exit(), _font_assert(), _RunRemoteTest(), _tWinMain(), alarmThreadMain(), BaseProcessStartup(), child_process(), CLRMetaHost_ExitProcess(), ConsoleControlDispatcher(), CorExitProcess(), CtrlCIntercept(), DbgkExitProcess(), DefaultConsoleCtrlHandler(), CDesktopThread::DesktopThreadProc(), DevInstallW(), DisplayError(), dll_entry_point(), doChild(), doDebugger(), ErrorExit(), exit(), ExitThread(), FatalAppExitA(), FatalAppExitW(), FatalExit(), Host_Quit(), IEWinMain(), init(), LoadProc(), local_server_proc(), LogToFile(), main(), MyErrExit(), performUninstall(), RpcRaiseException(), ShowUsage(), START_TEST(), StringListAppend(), test__popen_child(), thread_1(), VdmShutdown(), WatchDirectory(), WinMain(), wmainCRTStartup(), and wWinMain().

◆ FatalAppExitA()

VOID WINAPI FatalAppExitA ( UINT  uAction,
LPCSTR  lpMessageText 
)

Definition at line 1562 of file proc.c.

1564 {
1565  PUNICODE_STRING MessageTextU;
1566  ANSI_STRING MessageText;
1567  NTSTATUS Status;
1568 
1569  /* Initialize the string using the static TEB pointer */
1570  MessageTextU = &NtCurrentTeb()->StaticUnicodeString;
1571  RtlInitAnsiString(&MessageText, (LPSTR)lpMessageText);
1572 
1573  /* Convert to unicode, or just exit normally if this failed */
1574  Status = RtlAnsiStringToUnicodeString(MessageTextU, &MessageText, FALSE);
1575  if (!NT_SUCCESS(Status)) ExitProcess(0);
1576 
1577  /* Call the Wide function */
1578  FatalAppExitW(uAction, MessageTextU->Buffer);
1579 }
LONG NTSTATUS
Definition: precomp.h:26
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1487
char * LPSTR
Definition: xmlstorage.h:182
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
VOID WINAPI FatalAppExitW(IN UINT uAction, IN LPCWSTR lpMessageText)
Definition: proc.c:1586
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)

◆ FatalAppExitW()

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

Definition at line 1586 of file proc.c.

1588 {
1590  ULONG Response;
1591  NTSTATUS Status;
1592 
1593  /* Setup the string to print out */
1594  RtlInitUnicodeString(&UnicodeString, lpMessageText);
1595 
1596  /* Display the hard error no matter what */
1598  1,
1599  1,
1601 #if DBG
1602  /* On Checked builds, Windows allows the user to cancel the operation */
1604 #else
1605  OptionOk,
1606 #endif
1607  &Response);
1608 
1609 #if DBG
1610  /* Give the user a chance to abort */
1611  if ((NT_SUCCESS(Status)) && (Response == ResponseCancel)) return;
1612 #endif
1613 
1614  /* Otherwise kill the process */
1615  ExitProcess(0);
1616 }
*BytesInUnicodeString PWCH UnicodeString
Definition: rtlfuncs.h:1980
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:553
LONG NTSTATUS
Definition: precomp.h:26
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1487
#define HARDERROR_OVERRIDE_ERRORMODE
Definition: extypes.h:146
#define DBG(x)
Definition: moztest.c:12
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Definition: ncftp.h:89
Status
Definition: gdiplustypes.h:24
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
struct Response Response
uint32_t * PULONG_PTR
Definition: typedefs.h:64
#define STATUS_FATAL_APP_EXIT
Definition: ntstatus.h:135

Referenced by FatalAppExitA().

◆ FatalExit()

VOID WINAPI FatalExit ( IN int  ExitCode)

Definition at line 1623 of file proc.c.

1624 {
1625 #if DBG
1626  /* On Checked builds, Windows gives the user a nice little debugger UI */
1627  CHAR ch[2];
1628  DbgPrint("FatalExit...\n");
1629  DbgPrint("\n");
1630 
1631  while (TRUE)
1632  {
1633  DbgPrompt( "A (Abort), B (Break), I (Ignore)? ", ch, sizeof(ch));
1634  switch (ch[0])
1635  {
1636  case 'B': case 'b':
1637  DbgBreakPoint();
1638  break;
1639 
1640  case 'A': case 'a':
1641  ExitProcess(ExitCode);
1642 
1643  case 'I': case 'i':
1644  return;
1645  }
1646  }
1647 #endif
1648  /* On other builds, just kill the process */
1649  ExitProcess(ExitCode);
1650 }
#define TRUE
Definition: types.h:120
#define DbgPrint
Definition: loader.c:25
NTSYSAPI ULONG NTAPI DbgPrompt(_In_z_ PCCH Prompt, _Out_writes_bytes_(MaximumResponseLength) PCH Response, _In_ ULONG MaximumResponseLength)
char CHAR
Definition: xmlstorage.h:175
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1487
void DbgBreakPoint()
Definition: mach.c:553

◆ FlushInstructionCache()

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

Definition at line 1463 of file proc.c.

1466 {
1467  NTSTATUS Status;
1468 
1469  /* Call the native function */
1470  Status = NtFlushInstructionCache(hProcess, (PVOID)lpBaseAddress, nSize);
1471  if (!NT_SUCCESS(Status))
1472  {
1473  /* Handle failure case */
1475  return FALSE;
1476  }
1477 
1478  /* All good */
1479  return TRUE;
1480 }
#define TRUE
Definition: types.h:120
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
LONG NTSTATUS
Definition: precomp.h:26
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
NTSTATUS NTAPI NtFlushInstructionCache(_In_ HANDLE ProcessHandle, _In_opt_ PVOID BaseAddress, _In_ SIZE_T FlushSize)
Definition: virtual.c:2919
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24

◆ GetCommandLineA()

LPSTR WINAPI GetCommandLineA ( VOID  )

Definition at line 2003 of file proc.c.

2004 {
2005  return BaseAnsiCommandLine.Buffer;
2006 }
ANSI_STRING BaseAnsiCommandLine
Definition: proc.c:22

Referenced by DllMain(), doChild(), and main().

◆ GetCommandLineW()

◆ GetCurrentProcess()

HANDLE WINAPI GetCurrentProcess ( VOID  )

Definition at line 1138 of file proc.c.

1139 {
1140  return (HANDLE)NtCurrentProcess();
1141 }
#define NtCurrentProcess()
Definition: nt_native.h:1657

Referenced by _dup2(), _SHGetCurrentVersionPath(), _SHGetDefaultValue(), _SHGetUserProfileDirectoryW(), AccpLookupCurrentUser(), AcquireRemoveRestorePrivilege(), ACTION_FinishCustomActions(), AddDeviceW(), AddUserProfiles(), AuthzpInitSelf(), child_process(), chm_dup(), cmd_ctty(), CoGetPSClsid(), ATL::CAtlFileMappingBase::CopyFrom(), CopySystemProfile(), CorDebugProcess_Create(), CPlApplet(), CreateLobbyMessageReceptionThread(), CRYPT_FileOpenStore(), CRYPT_RegOpenStore(), dll_entry_point(), DllMain(), doChild(), DoesUserHavePrivilege(), DP_CreatePlayer(), DPL_CreateAndSetLobbyHandles(), DwInitializeSdFromThreadToken(), EnablePrivilege(), EnablePrivilegeInCurrentProcess(), EnableProcessPrivileges(), ensure_useragent(), EnumOLEVERB_Clone(), CShellCommandSACL::Execute(), FormatEx2(), get_current_group(), get_current_owner(), get_droptarget_local_handle(), get_user_sid(), GetDriverVersion(), GetProfileType(), GetShellSecurityDescriptor(), GetSystemCPU(), GetUserAndDomainName(), GetUserNameW(), GetUserToken(), GetWriteWatch(), IDirectPlay4Impl_EnumSessions(), init_function_ptrs(), InitDbgHelp(), InitFunctionPtrs(), InstallReactOS(), is_process_elevated(), is_process_limited(), IsNTAdmin(), IsOS(), IsWow64(), LaunchProcess(), main(), MainWndProc(), make_impersonation_token(), map_view_of_file(), MyDuplicateHandle(), named_pipe_client_func(), ObjectFromLresult(), PauseBalanceW(), PerformRedirection(), Privilege(), proc(), pSetupEnablePrivilege(), read_pipe_test(), RecvSubvolGUIW(), RecvSubvolW(), RecycleBin5_Constructor(), reg_get_typelib_module(), RegenerateUserEnvironment(), RegisterTypeLib(), RemoveDeviceW(), ResetStatsW(), ResizeDeviceW(), RevertToPrinterSelf(), RunningAsSYSTEM(), SendSubvolGUIW(), SendSubvolW(), set_default_proxy_reg_value(), set_privileges(), SetDriverLoadPrivilege(), SetPrivilege(), SHCreateSessionKey(), SHMapHandle(), ShowScrubW(), ShutdownSystem(), START_TEST(), StartBalanceW(), StartScrubW(), StartupWindowThread(), sti_create(), StopBalanceW(), StopScrubW(), SystemSetLocalTime(), SystemSetTime(), TakeOwnershipOfFile(), test8(), test_AccessCheck(), test_AddSelfToJob(), test_AdjustTokenPrivileges(), test_affinity(), test_buffer(), test_buffer8(), test_CheckTokenMembership(), test_child_token_sd(), test_child_token_sd_medium(), test_child_token_sd_restricted(), test_CoGetPSClsid(), Test_CombineTransform(), test_Console(), test_create_env(), test_CreateDirectoryA(), test_CreateRemoteThread(), test_CreateRestrictedToken(), test_dpi_context(), Test_DuplicateHandle(), test_DuplicateHandle(), test_event_security(), test_ExitProcess(), test_file_access(), test_file_disposition_information(), test_file_security(), test_filemap_security(), test_flags_NtQueryDirectoryFile(), test_get_user_profile_dir(), test_GetMappedFileName(), test_GetNamedSecurityInfoA(), test_GetProcessImageFileNameA(), test_GetSecurityInfo(), test_GetTokenInformation(), test_GetWindowsAccountDomainSid(), test_handles(), test_Handles(), test_image_mapping(), test_impersonation(), test_impersonation_level(), test_kernel_objects_security(), test_LBS_NODATA(), test_LookupAccountSid(), test_lsa(), test_LsaLookupSids(), test_mapping(), test_mapprotection(), test_MapViewOfFile(), test_mutex_security(), test_named_pipe_security(), test_NtGetCurrentProcessorNumber(), test_NtMapViewOfSection(), test_NtSuspendProcess(), test_OutOfProcess(), test_pe_checksum(), test_Predefined(), test_process_access(), test_process_security(), test_process_security_child(), test_pseudo_tokens(), test_query_process_basic(), test_query_process_debug_flags(), test_query_process_debug_object_handle(), test_query_process_debug_port(), test_query_process_handlecount(), test_query_process_image_file_name(), test_query_process_io(), test_query_process_priority(), test_query_process_times(), test_query_process_vm(), test_query_process_wow64(), test_QueryFullProcessImageNameA(), test_QueryFullProcessImageNameW(), test_redirection(), test_register_typelib(), test_RemoteDebugger(), test_RtlThreadErrorMode(), test_semaphore_security(), test_SetFileValidData(), test_SHGetFolderPathA(), test_SHParseDisplayName(), test_stub(), test_system_security_access(), test_SystemInfo(), test_TerminateProcess(), test_thread_actctx(), test_thread_processor(), test_thread_security(), test_token_attr(), test_token_label(), test_token_security_descriptor(), test_TokenIntegrityLevel(), test_VirtualAlloc(), test_VirtualProtect(), test_WaitForMultipleObjects(), test_WaitForSingleObject(), TestGetUserObjectInfoW(), testK32GetModuleInformation(), UnRegisterTypeLib(), UpdateDriver(), UpdatePriority(), VfdIsValidPlatform(), VirtualAlloc(), VirtualFree(), VirtualProtect(), WahOpenCurrentThread(), WhoamiGetTokenInfo(), WinMain(), WSPDuplicateSocket(), WTSQueryUserToken(), wWinMain(), and xmlGetGlobalState().

◆ GetCurrentProcessId()

DWORD WINAPI GetCurrentProcessId ( VOID  )

Definition at line 1158 of file proc.c.

1159 {
1161 }
#define HandleToUlong(h)
Definition: basetsd.h:79
HANDLE UniqueProcess
Definition: compat.h:482
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420

Referenced by __security_init_cookie(), _getpid(), _mktemp(), _wmktemp(), _wtmpnam(), adns_getpid(), apartment_construct(), child_process(), ClientLoadLibrary(), CloseProcess(), CoGetCurrentProcess(), CreateToolhelp32Snapshot(), CURSORICON_CopyImage(), DirectDrawClipper_Initialize(), dll_entry_point(), doChild(), doCrash(), DPLAYX_CreateLobbyApplication(), DPLAYX_IsAppIdLobbied(), EnumWindowsProc(), generate_ipid(), get_cmdline(), GetProcessVersion(), handle_msi_break(), IcmpSendEcho(), IDirectPlayLobby3AImpl_SetConnectionSettings(), IDirectPlayLobby3Impl_SetConnectionSettings(), IMM_GetThreadData(), Internal_CreatePalette(), Internal_CreateSurface(), IsBlockFromHeap(), LresultFromObject(), main(), NotifyInfo::modify(), new_stub_manager(), NotifyLogon(), ole_server(), openlog(), OutputDebugStringA(), ParseSharedPacket(), RegisterDragDrop(), RPC_ExecuteCall(), rpcrt4_protseq_ncacn_np_open_endpoint(), rpcrt4_protseq_ncalrpc_open_endpoint(), ScConnectControlPipe(), send_close_messages(), CNotifyToolbar::SendNotifyCallback(), ServerThread(), service_main(), SHAllocShared(), SHChangeNotify(), SHFreeShared(), SHLockShared(), SHMapHandle(), START_TEST(), StartDirectDraw(), TelnetGetConsoleWindow(), terminate_processes(), test_AddSelfToJob(), test_alloc_shared(), test_alloc_shared_remote(), test_BreakawayOk(), Test_CloseDuplicatedSocket(), Test_CloseWhileSelectDuplicatedSocket(), test_completion_port(), test_debug_loop(), test_GetConsoleProcessList(), test_GetProcessVersion(), test_handles(), test_jobInheritance(), test_MessageBox(), test_OpenProcess(), test_process_info(), test_process_security_child(), test_query_handle(), test_query_handle_ex(), test_query_object_types(), test_query_process_vm(), test_QueryFullProcessImageNameW(), test_readvirtualmemory(), test_session_info(), test_set_hook(), test_SHCreateSessionKey(), test_tcp(), test_Toolhelp(), test_udp(), test_Win32_Process(), test_winevents(), test_WithWSAStartup(), test_ws_functions(), test_WSADuplicateSocket(), TestChannelHook_ClientFillBuffer(), TestChannelHook_ClientGetSize(), TestChannelHook_ClientNotify(), TestChannelHook_ServerGetSize(), TestChannelHook_ServerNotify(), ThemeDestroyWndData(), tmpnam(), WDML_AddServer(), WinMain(), NotifyArea::WndProc(), FlatButton::WndProc(), and wWinMain().

◆ GetCurrentThread()

◆ GetExitCodeProcess()

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

Definition at line 1168 of file proc.c.

1170 {
1171  PROCESS_BASIC_INFORMATION ProcessBasic;
1172  NTSTATUS Status;
1173 
1174  /* Ask the kernel */
1177  &ProcessBasic,
1178  sizeof(ProcessBasic),
1179  NULL);
1180  if (!NT_SUCCESS(Status))
1181  {
1182  /* We failed, was this because this is a VDM process? */
1183  if (BaseCheckForVDM(hProcess, lpExitCode) != FALSE) return TRUE;
1184 
1185  /* Not a VDM process, fail the call */
1187  return FALSE;
1188  }
1189 
1190  /* Succes case, return the exit code */
1191  *lpExitCode = (DWORD)ProcessBasic.ExitStatus;
1192  return TRUE;
1193 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
BOOL WINAPI BaseCheckForVDM(IN HANDLE ProcessHandle, OUT LPDWORD ExitCode)
Definition: vdm.c:610
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define DWORD
Definition: nt_native.h:44
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24

Referenced by _cwait(), _pclose(), CloseProcessAndVerify_(), cmd_start(), CommandThreadProc(), crash_and_debug(), crash_and_winedbg(), custom_get_process_return(), do_spawnT(), DoTestEntry(), Execute(), ExecutePipeline(), LauncherRoutine2(), MonitorChildThread(), ProcessRunning(), run_ex(), run_reg_exe_(), run_script_file(), runcmd(), runCmd(), RunSetupThreadProc(), shell_execute_ex_(), TerminateShell(), test_CreateProcessWithDesktop(), test_ddeml_server(), test_end_to_end_server(), test_ExitCode(), test_ExitProcess(), test_Handles(), test_msg_server(), test_TerminateJobObject(), WshExec_get_Status(), and WshShell3_Run().

◆ GetPriorityClass()

DWORD WINAPI GetPriorityClass ( IN HANDLE  hProcess)

Definition at line 1657 of file proc.c.

1658 {
1659  NTSTATUS Status;
1660  PROCESS_PRIORITY_CLASS PriorityClass;
1661 
1662  /* Query the kernel */
1665  &PriorityClass,
1666  sizeof(PriorityClass),
1667  NULL);
1668  if (NT_SUCCESS(Status))
1669  {
1670  /* Handle the conversion from NT to Win32 classes */
1671  switch (PriorityClass.PriorityClass)
1672  {
1679  }
1680  }
1681 
1682  /* Failure path */
1684  return FALSE;
1685 }
#define REALTIME_PRIORITY_CLASS
Definition: winbase.h:184
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define NORMAL_PRIORITY_CLASS
Definition: winbase.h:181
#define ABOVE_NORMAL_PRIORITY_CLASS
Definition: winbase.h:191
#define HIGH_PRIORITY_CLASS
Definition: winbase.h:183
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define PROCESS_PRIORITY_CLASS_NORMAL
Definition: pstypes.h:108
#define PROCESS_PRIORITY_CLASS_ABOVE_NORMAL
Definition: pstypes.h:112
#define IDLE_PRIORITY_CLASS
Definition: winbase.h:182
#define PROCESS_PRIORITY_CLASS_REALTIME
Definition: pstypes.h:110
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define PROCESS_PRIORITY_CLASS_HIGH
Definition: pstypes.h:109
Status
Definition: gdiplustypes.h:24
#define BELOW_NORMAL_PRIORITY_CLASS
Definition: winbase.h:190
#define PROCESS_PRIORITY_CLASS_BELOW_NORMAL
Definition: pstypes.h:111
#define PROCESS_PRIORITY_CLASS_IDLE
Definition: pstypes.h:107

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 863 of file proc.c.

866 {
867  PROCESS_BASIC_INFORMATION ProcessInfo;
869 
870  /* Query information on the process from the kernel */
873  &ProcessInfo,
874  sizeof(ProcessInfo),
875  NULL);
876  if (!NT_SUCCESS(Status))
877  {
878  /* Fail */
880  return FALSE;
881  }
882 
883  /* Copy the affinity mask, and get the system one from our shared data */
884  *lpProcessAffinityMask = (DWORD)ProcessInfo.AffinityMask;
886  return TRUE;
887 }
#define TRUE
Definition: types.h:120
PBASE_STATIC_SERVER_DATA BaseStaticServerData
Definition: dllmain.c:19
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define DWORD
Definition: nt_native.h:44
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
SYSTEM_BASIC_INFORMATION SysInfo
Definition: base.h:122
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:24
KAFFINITY ActiveProcessorsAffinityMask
Definition: ntddk_ex.h:167

Referenced by AffinityDialogWndProc(), and test_thread_processor().

◆ GetProcessHandleCount()

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

Definition at line 1945 of file proc.c.

1947 {
1948  ULONG phc;
1949  NTSTATUS Status;
1950 
1951  /* Query the kernel */
1954  &phc,
1955  sizeof(phc),
1956  NULL);
1957  if (NT_SUCCESS(Status))
1958  {
1959  /* Copy the count and return success */
1960  *pdwHandleCount = phc;
1961  return TRUE;
1962  }
1963 
1964  /* Handle error path */
1966  return FALSE;
1967 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
unsigned int ULONG
Definition: retypes.h:1

◆ GetProcessId()

DWORD WINAPI GetProcessId ( IN HANDLE  Process)

Definition at line 1200 of file proc.c.

1201 {
1202  PROCESS_BASIC_INFORMATION ProcessBasic;
1203  NTSTATUS Status;
1204 
1205  /* Query the kernel */
1208  &ProcessBasic,
1209  sizeof(ProcessBasic),
1210  NULL);
1211  if (!NT_SUCCESS(Status))
1212  {
1213  /* Handle failure */
1215  return 0;
1216  }
1217 
1218  /* Return the PID */
1219  return (DWORD)ProcessBasic.UniqueProcessId;
1220 }
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by check_live_target().

◆ GetProcessIoCounters()

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

Definition at line 1861 of file proc.c.

1863 {
1864  NTSTATUS Status;
1865 
1866  /* Query the kernel. Structures are identical, so let it do the copy too. */
1869  lpIoCounters,
1870  sizeof(IO_COUNTERS),
1871  NULL);
1872  if (!NT_SUCCESS(Status))
1873  {
1874  /* Handle error path */
1876  return FALSE;
1877  }
1878 
1879  /* All done */
1880  return TRUE;
1881 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24

Referenced by PerfDataRefresh().

◆ GetProcessPriorityBoost()

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

Definition at line 1888 of file proc.c.

1890 {
1891  NTSTATUS Status;
1893 
1894  /* Query the kernel */
1897  &PriorityBoost,
1898  sizeof(PriorityBoost),
1899  NULL);
1900  if (NT_SUCCESS(Status))
1901  {
1902  /* Convert from ULONG to a BOOL */
1903  *pDisablePriorityBoost = PriorityBoost ? TRUE : FALSE;
1904  return TRUE;
1905  }
1906 
1907  /* Handle error path */
1909  return FALSE;
1910 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
_In_ CCHAR PriorityBoost
Definition: iofuncs.h:763
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
unsigned int ULONG
Definition: retypes.h:1

◆ GetProcessShutdownParameters()

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

Definition at line 920 of file proc.c.

922 {
923  BASE_API_MESSAGE ApiMessage;
924  PBASE_GETSET_PROCESS_SHUTDOWN_PARAMS ShutdownParametersRequest = &ApiMessage.Data.ShutdownParametersRequest;
925 
926  /* Ask CSRSS for shutdown information */
928  NULL,
930  sizeof(*ShutdownParametersRequest));
931  if (!NT_SUCCESS(ApiMessage.Status))
932  {
933  /* Return the failure from CSRSS */
934  BaseSetLastNTError(ApiMessage.Status);
935  return FALSE;
936  }
937 
938  /* Get the data back */
939  *lpdwLevel = ShutdownParametersRequest->ShutdownLevel;
940  *lpdwFlags = ShutdownParametersRequest->ShutdownFlags;
941  return TRUE;
942 }
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI CsrClientCallServer(IN OUT PCSR_API_MESSAGE ApiMessage, IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer OPTIONAL, IN CSR_API_NUMBER ApiNumber, IN ULONG DataLength)
Definition: connect.c:365
NTSTATUS Status
Definition: csrmsg.h:112
BASE_GETSET_PROCESS_SHUTDOWN_PARAMS ShutdownParametersRequest
Definition: basemsg.h:294
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
#define BASESRV_SERVERDLL_INDEX
Definition: basemsg.h:15
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
union _BASE_API_MESSAGE::@3407 Data

◆ GetProcessTimes()

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

Definition at line 1099 of file proc.c.

1104 {
1105  KERNEL_USER_TIMES Kut;
1106  NTSTATUS Status;
1107 
1108  /* Query the times */
1110  ProcessTimes,
1111  &Kut,
1112  sizeof(Kut),
1113  NULL);
1114  if (!NT_SUCCESS(Status))
1115  {
1116  /* Handle failure */
1118  return FALSE;
1119  }
1120 
1121  /* Copy all the times and return success */
1122  lpCreationTime->dwLowDateTime = Kut.CreateTime.u.LowPart;
1123  lpCreationTime->dwHighDateTime = Kut.CreateTime.u.HighPart;
1124  lpExitTime->dwLowDateTime = Kut.ExitTime.u.LowPart;
1125  lpExitTime->dwHighDateTime = Kut.ExitTime.u.HighPart;
1126  lpKernelTime->dwLowDateTime = Kut.KernelTime.u.LowPart;
1127  lpKernelTime->dwHighDateTime = Kut.KernelTime.u.HighPart;
1128  lpUserTime->dwLowDateTime = Kut.UserTime.u.LowPart;
1129  lpUserTime->dwHighDateTime = Kut.UserTime.u.HighPart;
1130  return TRUE;
1131 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
LARGE_INTEGER UserTime
Definition: winternl.h:1063
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
LARGE_INTEGER ExitTime
Definition: winternl.h:1061
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LARGE_INTEGER CreateTime
Definition: winternl.h:1060
struct _LARGE_INTEGER::@2216 u
Status
Definition: gdiplustypes.h:24
LARGE_INTEGER KernelTime
Definition: winternl.h:1062

◆ GetProcessVersion()

DWORD WINAPI GetProcessVersion ( IN DWORD  ProcessId)

Definition at line 1760 of file proc.c.

1761 {
1762  DWORD Version = 0;
1763  PIMAGE_NT_HEADERS NtHeader;
1764  PIMAGE_DOS_HEADER DosHeader;
1765  PPEB Peb;
1766  PROCESS_BASIC_INFORMATION ProcessBasicInfo;
1768  ULONG e_lfanew;
1770  NTSTATUS Status;
1771  USHORT VersionData[2];
1772  BOOLEAN Result;
1773 
1774  /* We'll be accessing stuff that can fault, so protect everything with SEH */
1775  _SEH2_TRY
1776  {
1777  /* It this an in-process or out-of-process request? */
1778  if (!(ProcessId) || (GetCurrentProcessId() == ProcessId))
1779  {
1780  /* It's in-process, so just read our own header */
1781  NtHeader = RtlImageNtHeader(NtCurrentPeb()->ImageBaseAddress);
1782  if (!NtHeader)
1783  {
1784  /* Unable to read the NT header, something is wrong here... */
1786  goto Error;
1787  }
1788 
1789  /* Get the version straight out of the NT header */
1792  }
1793  else
1794  {
1795  /* Out-of-process, so open it */
1797  FALSE,
1798  ProcessId);
1799  if (!ProcessHandle) _SEH2_YIELD(return 0);
1800 
1801  /* Try to find out where its PEB lives */
1804  &ProcessBasicInfo,
1805  sizeof(ProcessBasicInfo),
1806  NULL);
1807 
1808  if (!NT_SUCCESS(Status)) goto Error;
1809  Peb = ProcessBasicInfo.PebBaseAddress;
1810 
1811  /* Now that we have the PEB, read the image base address out of it */
1814  &BaseAddress,
1815  sizeof(BaseAddress),
1816  NULL);
1817  if (!Result) goto Error;
1818 
1819  /* Now read the e_lfanew (offset to NT header) from the base */
1820  DosHeader = BaseAddress;
1822  &DosHeader->e_lfanew,
1823  &e_lfanew,
1824  sizeof(e_lfanew),
1825  NULL);
1826  if (!Result) goto Error;
1827 
1828  /* And finally, read the NT header itself by adding the offset */
1829  NtHeader = (PVOID)((ULONG_PTR)BaseAddress + e_lfanew);
1832  &VersionData,
1833  sizeof(VersionData),
1834  NULL);
1835  if (!Result) goto Error;
1836 
1837  /* Get the version straight out of the NT header */
1838  Version = MAKELONG(VersionData[0], VersionData[1]);
1839 
1840 Error:
1841  /* If there was an error anywhere, set the last error */
1843  }
1844  }
1846  {
1847  /* Close the process handle */
1849  }
1850  _SEH2_END;
1851 
1852  /* And return the version data */
1853  return Version;
1854 }
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2697
#define CloseHandle
Definition: compat.h:406
IN PVOID IN PVOID IN USHORT Version
Definition: pci.h:359
PPEB Peb
Definition: dllmain.c:27
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:158
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
_SEH2_TRY
Definition: create.c:4250
BOOL NTAPI ReadProcessMemory(IN HANDLE hProcess, IN LPCVOID lpBaseAddress, IN LPVOID lpBuffer, IN SIZE_T nSize, OUT SIZE_T *lpNumberOfBytesRead)
Definition: proc.c:2023
uint32_t ULONG_PTR
Definition: typedefs.h:64
PVOID ImageBaseAddress
Definition: ntddk_ex.h:245
DWORD e_lfanew
Definition: crypt.c:1156
#define MAKELONG(a, b)
Definition: typedefs.h:249
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_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:426
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
void * PVOID
Definition: retypes.h:9
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:345
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
Status
Definition: gdiplustypes.h:24
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1227
_SEH2_END
Definition: create.c:4424
#define NtCurrentPeb()
Definition: FLS.c:20
unsigned short USHORT
Definition: pedump.c:61
_SEH2_FINALLY
Definition: create.c:4395
#define RtlImageNtHeader
Definition: compat.h:465
#define PROCESS_VM_READ
Definition: pstypes.h:153
unsigned int ULONG
Definition: retypes.h:1
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1158

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

◆ GetProcessWorkingSetSize()

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

Definition at line 1011 of file proc.c.

1014 {
1015  DWORD Dummy;
1017  lpMinimumWorkingSetSize,
1018  lpMaximumWorkingSetSize,
1019  &Dummy);
1020 }
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI GetProcessWorkingSetSizeEx(IN HANDLE hProcess, OUT PSIZE_T lpMinimumWorkingSetSize, OUT PSIZE_T lpMaximumWorkingSetSize, OUT PDWORD Flags)
Definition: proc.c:978

◆ GetProcessWorkingSetSizeEx()

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

Definition at line 978 of file proc.c.

982 {
983  QUOTA_LIMITS_EX QuotaLimits;
985 
986  /* Query the kernel about this */
989  &QuotaLimits,
990  sizeof(QuotaLimits),
991  NULL);
992  if (!NT_SUCCESS(Status))
993  {
994  /* Return error */
996  return FALSE;
997  }
998 
999  /* Copy the quota information out */
1000  *lpMinimumWorkingSetSize = QuotaLimits.MinimumWorkingSetSize;
1001  *lpMaximumWorkingSetSize = QuotaLimits.MaximumWorkingSetSize;
1002  *Flags = QuotaLimits.Flags;
1003  return TRUE;
1004 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
SIZE_T MaximumWorkingSetSize
Definition: pstypes.h:71
SIZE_T MinimumWorkingSetSize
Definition: pstypes.h:70

Referenced by GetProcessWorkingSetSize().

◆ GetStartupInfoA()

VOID WINAPI GetStartupInfoA ( IN LPSTARTUPINFOA  lpStartupInfo)

Definition at line 1320 of file proc.c.

1321 {
1323  ANSI_STRING TitleString, ShellString, DesktopString;
1324  LPSTARTUPINFOA StartupInfo;
1325  NTSTATUS Status;
1326 
1327  /* Get the cached information as well as the PEB parameters */
1328  StartupInfo = BaseAnsiStartupInfo;
1329  Params = NtCurrentPeb()->ProcessParameters;
1330 
1331  /* Check if this is the first time we have to get the cached version */
1332  while (!StartupInfo)
1333  {
1334  /* Create new ANSI startup info */
1335  StartupInfo = RtlAllocateHeap(RtlGetProcessHeap(),
1336  0,
1337  sizeof(*StartupInfo));
1338  if (StartupInfo)
1339  {
1340  /* Zero out string pointers in case we fail to create them */
1341  StartupInfo->lpReserved = NULL;
1342  StartupInfo->lpDesktop = NULL;
1343  StartupInfo->lpTitle = NULL;
1344 
1345  /* Set the size */
1346  StartupInfo->cb = sizeof(*StartupInfo);
1347 
1348  /* Copy what's already stored in the PEB */
1349  StartupInfo->dwX = Params->StartingX;
1350  StartupInfo->dwY = Params->StartingY;
1351  StartupInfo->dwXSize = Params->CountX;
1352  StartupInfo->dwYSize = Params->CountY;
1353  StartupInfo->dwXCountChars = Params->CountCharsX;
1354  StartupInfo->dwYCountChars = Params->CountCharsY;
1355  StartupInfo->dwFillAttribute = Params->FillAttribute;
1356  StartupInfo->dwFlags = Params->WindowFlags;
1357  StartupInfo->wShowWindow = (WORD)Params->ShowWindowFlags;
1358  StartupInfo->cbReserved2 = Params->RuntimeData.Length;
1359  StartupInfo->lpReserved2 = (LPBYTE)Params->RuntimeData.Buffer;
1360  StartupInfo->hStdInput = Params->StandardInput;
1361  StartupInfo->hStdOutput = Params->StandardOutput;
1362  StartupInfo->hStdError = Params->StandardError;
1363 
1364  /* Copy shell info string */
1365  Status = RtlUnicodeStringToAnsiString(&ShellString,
1366  &Params->ShellInfo,
1367  TRUE);
1368  if (NT_SUCCESS(Status))
1369  {
1370  /* Save it */
1371  StartupInfo->lpReserved = ShellString.Buffer;
1372 
1373  /* Copy desktop info string */
1374  Status = RtlUnicodeStringToAnsiString(&DesktopString,
1375  &Params->DesktopInfo,
1376  TRUE);
1377  if (NT_SUCCESS(Status))
1378  {
1379  /* Save it */
1380  StartupInfo->lpDesktop = DesktopString.Buffer;
1381 
1382  /* Copy window title string */
1383  Status = RtlUnicodeStringToAnsiString(&TitleString,
1384  &Params->WindowTitle,
1385  TRUE);
1386  if (NT_SUCCESS(Status))
1387  {
1388  /* Save it */
1389  StartupInfo->lpTitle = TitleString.Buffer;
1390 
1391  /* We finished with the ANSI version, try to cache it */
1393  StartupInfo,
1394  NULL))
1395  {
1396  /* We were the first thread through, use the data */
1397  break;
1398  }
1399 
1400  /* Someone beat us to it, use their data instead */
1401  StartupInfo = BaseAnsiStartupInfo;
1403 
1404  /* We're going to free our own stuff, but not raise */
1405  RtlFreeAnsiString(&TitleString);
1406  }
1407  RtlFreeAnsiString(&DesktopString);
1408  }
1409  RtlFreeAnsiString(&ShellString);
1410  }
1411  RtlFreeHeap(RtlGetProcessHeap(), 0, StartupInfo);
1412  }
1413  else
1414  {
1415  /* No memory, fail */
1417  }
1418 
1419  /* Raise an error unless we got here due to the race condition */
1421  }
1422 
1423  /* Now copy from the cached ANSI version */
1424  lpStartupInfo->cb = StartupInfo->cb;
1425  lpStartupInfo->lpReserved = StartupInfo->lpReserved;
1426  lpStartupInfo->lpDesktop = StartupInfo->lpDesktop;
1427  lpStartupInfo->lpTitle = StartupInfo->lpTitle;
1428  lpStartupInfo->dwX = StartupInfo->dwX;
1429  lpStartupInfo->dwY = StartupInfo->dwY;
1430  lpStartupInfo->dwXSize = StartupInfo->dwXSize;
1431  lpStartupInfo->dwYSize = StartupInfo->dwYSize;
1432  lpStartupInfo->dwXCountChars = StartupInfo->dwXCountChars;
1433  lpStartupInfo->dwYCountChars = StartupInfo->dwYCountChars;
1434  lpStartupInfo->dwFillAttribute = StartupInfo->dwFillAttribute;
1435  lpStartupInfo->dwFlags = StartupInfo->dwFlags;
1436  lpStartupInfo->wShowWindow = StartupInfo->wShowWindow;
1437  lpStartupInfo->cbReserved2 = StartupInfo->cbReserved2;
1438  lpStartupInfo->lpReserved2 = StartupInfo->lpReserved2;
1439 
1440  /* Check if the shell is hijacking the handles for other features */
1441  if (lpStartupInfo->dwFlags &
1442  (STARTF_USESTDHANDLES | STARTF_USEHOTKEY | STARTF_SHELLPRIVATE))
1443  {
1444  /* It isn't, so we can return the raw values */
1445  lpStartupInfo->hStdInput = StartupInfo->hStdInput;
1446  lpStartupInfo->hStdOutput = StartupInfo->hStdOutput;
1447  lpStartupInfo->hStdError = StartupInfo->hStdError;
1448  }
1449  else
1450  {
1451  /* It is, so make sure nobody uses these as console handles */
1452  lpStartupInfo->hStdInput = INVALID_HANDLE_VALUE;
1453  lpStartupInfo->hStdOutput = INVALID_HANDLE_VALUE;
1454  lpStartupInfo->hStdError = INVALID_HANDLE_VALUE;
1455  }
1456 }
DWORD dwXSize
Definition: winbase.h:809
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
DWORD dwXCountChars
Definition: winbase.h:811
#define TRUE
Definition: types.h:120
LPSTR lpTitle
Definition: winbase.h:806
UNICODE_STRING WindowTitle
Definition: rtltypes.h:1525
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
DWORD dwYCountChars
Definition: winbase.h:812
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DWORD dwFlags
Definition: winbase.h:814
UNICODE_STRING ShellInfo
Definition: rtltypes.h:1527
UNICODE_STRING DesktopInfo
Definition: rtltypes.h:1526
DWORD dwY
Definition: winbase.h:808
unsigned char * LPBYTE
Definition: typedefs.h:53
#define STARTF_SHELLPRIVATE
Definition: kernel32.h:60
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
smooth NULL
Definition: ftsmooth.c:416
PBYTE lpReserved2
Definition: winbase.h:817
LPSTR lpReserved
Definition: winbase.h:804
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
LPSTARTUPINFOA BaseAnsiStartupInfo
Definition: proc.c:24
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
DWORD dwYSize
Definition: winbase.h:810
DWORD dwX
Definition: winbase.h:807
#define STARTF_USESTDHANDLES
Definition: winbase.h:480
DWORD cb
Definition: winbase.h:803
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI VOID NTAPI RtlFreeAnsiString(PANSI_STRING AnsiString)
unsigned short WORD
Definition: ntddk_ex.h:93
HANDLE hStdOutput
Definition: winbase.h:819
DWORD dwFillAttribute
Definition: winbase.h:813
UNICODE_STRING RuntimeData
Definition: rtltypes.h:1528
Status
Definition: gdiplustypes.h:24
LPSTR lpDesktop
Definition: winbase.h:805
WORD cbReserved2
Definition: winbase.h:816
#define NtCurrentPeb()
Definition: FLS.c:20
HANDLE hStdInput
Definition: winbase.h:818
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
WORD wShowWindow
Definition: winbase.h:815
return STATUS_SUCCESS
Definition: btrfs.c:2938
HANDLE hStdError
Definition: winbase.h:820

Referenced by doChild(), msvcrt_init_io(), test_Console(), test_DebuggingFlag(), test_Startup(), and test_SuspendFlag().

◆ GetStartupInfoW()

VOID WINAPI GetStartupInfoW ( IN LPSTARTUPINFOW  lpStartupInfo)

Definition at line 1279 of file proc.c.

1280 {
1282 
1283  /* Get the process parameters */
1284  Params = NtCurrentPeb()->ProcessParameters;
1285 
1286  /* Copy the data out of there */
1287  lpStartupInfo->cb = sizeof(STARTUPINFOW);
1288  lpStartupInfo->lpReserved = Params->ShellInfo.Buffer;
1289  lpStartupInfo->lpDesktop = Params->DesktopInfo.Buffer;
1290  lpStartupInfo->lpTitle = Params->WindowTitle.Buffer;
1291  lpStartupInfo->dwX = Params->StartingX;
1292  lpStartupInfo->dwY = Params->StartingY;
1293  lpStartupInfo->dwXSize = Params->CountX;
1294  lpStartupInfo->dwYSize = Params->CountY;
1295  lpStartupInfo->dwXCountChars = Params->CountCharsX;
1296  lpStartupInfo->dwYCountChars = Params->CountCharsY;
1297  lpStartupInfo->dwFillAttribute = Params->FillAttribute;
1298  lpStartupInfo->dwFlags = Params->WindowFlags;
1299  lpStartupInfo->wShowWindow = (WORD)Params->ShowWindowFlags;
1300  lpStartupInfo->cbReserved2 = Params->RuntimeData.Length;
1301  lpStartupInfo->lpReserved2 = (LPBYTE)Params->RuntimeData.Buffer;
1302 
1303  /* Check if the standard handles are being used for other features */
1304  if (lpStartupInfo->dwFlags & (STARTF_USESTDHANDLES |
1305  STARTF_USEHOTKEY |
1307  {
1308  /* These are, so copy the standard handles too */
1309  lpStartupInfo->hStdInput = Params->StandardInput;
1310  lpStartupInfo->hStdOutput = Params->StandardOutput;
1311  lpStartupInfo->hStdError = Params->StandardError;
1312  }
1313 }
UNICODE_STRING WindowTitle
Definition: rtltypes.h:1525
struct _STARTUPINFOW STARTUPINFOW
UNICODE_STRING ShellInfo
Definition: rtltypes.h:1527
UNICODE_STRING DesktopInfo
Definition: rtltypes.h:1526
unsigned char * LPBYTE
Definition: typedefs.h:53
#define STARTF_SHELLPRIVATE
Definition: kernel32.h:60
#define STARTF_USESTDHANDLES
Definition: winbase.h:480
unsigned short WORD
Definition: ntddk_ex.h:93
UNICODE_STRING RuntimeData
Definition: rtltypes.h:1528
#define NtCurrentPeb()
Definition: FLS.c:20

Referenced by doChild(), and wWinMain().

◆ InitCommandLines()

VOID WINAPI InitCommandLines ( VOID  )

Definition at line 842 of file proc.c.

843 {
845 
846  /* Read the UNICODE_STRING from the PEB */
847  BaseUnicodeCommandLine = NtCurrentPeb()->ProcessParameters->CommandLine;
848 
849  /* Convert to ANSI_STRING for the *A callers */
852  TRUE);
853  if (!NT_SUCCESS(Status)) RtlInitEmptyAnsiString(&BaseAnsiCommandLine, 0, 0);
854 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
ANSI_STRING BaseAnsiCommandLine
Definition: proc.c:22
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
UNICODE_STRING BaseUnicodeCommandLine
Definition: proc.c:21
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define NtCurrentPeb()
Definition: FLS.c:20

Referenced by DllMain().

◆ IsWow64Process()

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

Definition at line 1974 of file proc.c.

1976 {
1977  ULONG_PTR pbi;
1978  NTSTATUS Status;
1979 
1980  /* Query the kernel */
1983  &pbi,
1984  sizeof(pbi),
1985  NULL);
1986  if (!NT_SUCCESS(Status))
1987  {
1988  /* Handle error path */
1990  return FALSE;
1991  }
1992 
1993  /* Enforce this is a BOOL, and return success */
1994  *Wow64Process = (pbi != 0);
1995  return TRUE;
1996 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
uint32_t ULONG_PTR
Definition: typedefs.h:64
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PERBANDINFO * pbi
Definition: winddi.h:3917
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24

Referenced by _SHGetCurrentVersionPath(), _SHGetDefaultValue(), CoGetPSClsid(), DllMain(), ensure_useragent(), init_funcs(), init_functionpointers(), IsOS(), reg_get_typelib_module(), RegisterTypeLib(), set_default_proxy_reg_value(), START_TEST(), Test_CombineTransform(), test_LBS_NODATA(), and UnRegisterTypeLib().

◆ OpenProcess()

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

Definition at line 1227 of file proc.c.

1230 {
1231  NTSTATUS Status;
1235 
1236  /* Setup the input client ID structure */
1237  ClientId.UniqueProcess = UlongToHandle(dwProcessId);
1238  ClientId.UniqueThread = 0;
1239 
1240  /* This is needed just to define the inheritance flags */
1242  NULL,
1243  (bInheritHandle ? OBJ_INHERIT : 0),
1244  NULL,
1245  NULL);
1246 
1247  /* Now try to open the process */
1249  dwDesiredAccess,
1251  &ClientId);
1252  if (!NT_SUCCESS(Status))
1253  {
1254  /* Handle failure */
1256  return NULL;
1257  }
1258 
1259  /* Otherwise return a handle to the process */
1260  return ProcessHandle;
1261 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
LONG NTSTATUS
Definition: precomp.h:26
HANDLE UniqueProcess
Definition: compat.h:482
NTSTATUS NTAPI NtOpenProcess(OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN PCLIENT_ID ClientId)
Definition: process.c:1440
static BOOL bInheritHandle
Definition: pipe.c:82
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define UlongToHandle(ul)
Definition: basetsd.h:97
#define OBJ_INHERIT
Definition: winternl.h:225
HANDLE UniqueThread
Definition: compat.h:483
Status
Definition: gdiplustypes.h:24
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403

Referenced by _DoDLLInjection(), _tWinMain(), CIconWatcher::AddIconToWatcher(), child_process(), CloseProcess(), CloseProcessAndVerify_(), DebugChannels_FillList(), DebugChannels_OnNotify(), dll_entry_point(), doChild(), DoSetPriority(), ExecuteKill(), get_droptarget_local_handle(), get_process_name_from_pid(), GetOwnerModuleFromPidEntry(), GetProcessHandleFromHwnd(), GetProcessVersion(), GetThemeServiceProcessHandle(), Ghost_DestroyTarget(), ObjectFromLresult(), OpenUserRegistryPathPerProcessId(), PerfDataGetCommandLine(), PerfDataRefresh(), PNP_ReportLogOn(), ProcessKeys(), ProcessList_Update(), ProcessPage_OnEndProcess(), ProcessPage_OnEndProcessTree(), ProcessPage_OnSetAffinity(), ProcessPageShowContextMenu(), ProcessRunning(), SHMapHandle(), ShutdownProcessTreeHelper(), START_TEST(), terminate_processes(), test_ExitProcess(), test_OpenProcess(), test_process_info(), test_process_security_child(), test_query_process_handlecount(), test_query_process_times(), test_query_process_vm(), test_QueryFullProcessImageNameW(), test_readvirtualmemory(), test_RtlQueryPackageIdentity(), test_shell_window(), test_token_security_descriptor(), test_Toolhelp(), test_ws_functions(), Toolhelp32ReadProcessMemory(), WSPDuplicateSocket(), and wWinMain().

◆ ProcessIdToSessionId()

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

Definition at line 2175 of file proc.c.

2177 {
2178  PROCESS_SESSION_INFORMATION SessionInformation;
2182  NTSTATUS Status;
2183 
2184  /* Do a quick check if the pointer is not writable */
2185  if (IsBadWritePtr(pSessionId, sizeof(DWORD)))
2186  {
2187  /* Fail fast */
2189  return FALSE;
2190  }
2191 
2192  /* Open the process passed in by ID */
2193  ClientId.UniqueProcess = UlongToHandle(dwProcessId);
2194  ClientId.UniqueThread = 0;
2199  &ClientId);
2200  if (NT_SUCCESS(Status))
2201  {
2202  /* Query the session ID from the kernel */
2205  &SessionInformation,
2206  sizeof(SessionInformation),
2207  NULL);
2208 
2209  /* Close the handle and check if we succeeded */
2211  if (NT_SUCCESS(Status))
2212  {
2213  /* Return the session ID */
2214  *pSessionId = SessionInformation.SessionId;
2215  return TRUE;
2216  }
2217  }
2218 
2219  /* Set error code and fail */
2221  return FALSE;
2222 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define TRUE
Definition: types.h:120
BOOL NTAPI IsBadWritePtr(IN LPVOID lp, IN UINT_PTR ucb)
Definition: except.c:885
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:158
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
HANDLE UniqueProcess
Definition: compat.h:482
NTSTATUS NTAPI NtOpenProcess(OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN PCLIENT_ID ClientId)
Definition: process.c:1440
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define UlongToHandle(ul)
Definition: basetsd.h:97
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
HANDLE UniqueThread
Definition: compat.h:483
Status
Definition: gdiplustypes.h:24
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403

Referenced by 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 2023 of file proc.c.

2028 {
2029  NTSTATUS Status;
2030 
2031  /* Do the read */
2033  (PVOID)lpBaseAddress,
2034  lpBuffer,
2035  nSize,
2036  &nSize);
2037 
2038  /* In user-mode, this parameter is optional */
2039  if (lpNumberOfBytesRead) *lpNumberOfBytesRead = nSize;
2040  if (!NT_SUCCESS(Status))
2041  {
2042  /* We failed */
2044  return FALSE;
2045  }
2046 
2047  /* Return success */
2048  return TRUE;
2049 }
#define TRUE
Definition: types.h:120
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
LONG NTSTATUS
Definition: precomp.h:26
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtReadVirtualMemory(IN HANDLE ProcessHandle, IN PVOID BaseAddress, OUT PVOID Buffer, IN SIZE_T NumberOfBytesToRead, OUT PSIZE_T NumberOfBytesRead OPTIONAL)
Definition: virtual.c:2691
Status
Definition: gdiplustypes.h:24

Referenced by GetProcessVersion().

◆ RegisterWaitForInputIdle() [1/2]

VOID WINAPI RegisterWaitForInputIdle ( WaitForInputIdleType  lpfnRegisterWaitForInputIdle)

◆ RegisterWaitForInputIdle() [2/2]

VOID WINAPI RegisterWaitForInputIdle ( IN WaitForInputIdleType  lpfnRegisterWaitForInputIdle)

Definition at line 1268 of file proc.c.

1269 {
1270  /* Write the global function pointer */
1271  UserWaitForInputIdleRoutine = lpfnRegisterWaitForInputIdle;
1272 }
WaitForInputIdleType UserWaitForInputIdleRoutine
Definition: proc.c:20

◆ SetPriorityClass()

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

Definition at line 1692 of file proc.c.

1694 {
1695  NTSTATUS Status;
1696  PVOID State = NULL;
1697  PROCESS_PRIORITY_CLASS PriorityClass;
1698 
1699  /* Handle conversion from Win32 to NT priority classes */
1700  switch (dwPriorityClass)
1701  {
1702  case IDLE_PRIORITY_CLASS:
1704  break;
1705 
1708  break;
1709 
1710  case NORMAL_PRIORITY_CLASS:
1712  break;
1713 
1716  break;
1717 
1718  case HIGH_PRIORITY_CLASS:
1720  break;
1721 
1723  /* Try to acquire the privilege. If it fails, just use HIGH */
1726  PriorityClass.PriorityClass += (State != NULL);
1727  break;
1728 
1729  default:
1730  /* Unrecognized priority classes don't make it to the kernel */
1732  return FALSE;
1733  }
1734 
1735  /* Send the request to the kernel, and don't touch the foreground flag */
1736  PriorityClass.Foreground = FALSE;
1739  &PriorityClass,
1740  sizeof(PROCESS_PRIORITY_CLASS));
1741 
1742  /* Release the privilege if we had it */
1744  if (!NT_SUCCESS(Status))
1745  {
1746  /* Handle error path */
1748  return FALSE;
1749  }
1750 
1751  /* All done */
1752  return TRUE;
1753 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
PVOID WINAPI BasepIsRealtimeAllowed(IN BOOLEAN Keep)
Definition: utils.c:663
#define REALTIME_PRIORITY_CLASS
Definition: winbase.h:184
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define NORMAL_PRIORITY_CLASS
Definition: winbase.h:181
#define ABOVE_NORMAL_PRIORITY_CLASS
Definition: winbase.h:191
#define HIGH_PRIORITY_CLASS
Definition: winbase.h:183
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI VOID NTAPI RtlReleasePrivilege(_In_ PVOID ReturnedState)
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define PROCESS_PRIORITY_CLASS_NORMAL
Definition: pstypes.h:108
#define PROCESS_PRIORITY_CLASS_ABOVE_NORMAL
Definition: pstypes.h:112
#define IDLE_PRIORITY_CLASS
Definition: winbase.h:182
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:417
#define PROCESS_PRIORITY_CLASS_HIGH
Definition: pstypes.h:109
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112
#define BELOW_NORMAL_PRIORITY_CLASS
Definition: winbase.h:190
#define PROCESS_PRIORITY_CLASS_BELOW_NORMAL
Definition: pstypes.h:111
#define PROCESS_PRIORITY_CLASS_IDLE
Definition: pstypes.h:107

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 894 of file proc.c.

896 {
898 
899  /* Directly set the affinity mask */
902  (PVOID)&dwProcessAffinityMask,
903  sizeof(DWORD));
904  if (!NT_SUCCESS(Status))
905  {
906  /* Handle failure */
908  return FALSE;
909  }
910 
911  /* Everything was ok */
912  return TRUE;
913 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112

Referenced by AffinityDialogWndProc(), and cmd_start().

◆ SetProcessPriorityBoost()

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

Definition at line 1917 of file proc.c.

1919 {
1920  NTSTATUS Status;
1922 
1923  /* Enforce that this is a BOOL, and send it to the kernel as a ULONG */
1924  PriorityBoost = (bDisablePriorityBoost ? TRUE : FALSE);
1927  &PriorityBoost,
1928  sizeof(ULONG));
1929  if (!NT_SUCCESS(Status))
1930  {
1931  /* Handle error path */
1933  return FALSE;
1934  }
1935 
1936  /* All done */
1937  return TRUE;
1938 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
_In_ CCHAR PriorityBoost
Definition: iofuncs.h:763
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112
unsigned int ULONG
Definition: retypes.h:1

◆ SetProcessShutdownParameters()

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

Definition at line 949 of file proc.c.

951 {
952  BASE_API_MESSAGE ApiMessage;
953  PBASE_GETSET_PROCESS_SHUTDOWN_PARAMS ShutdownParametersRequest = &ApiMessage.Data.ShutdownParametersRequest;
954 
955  /* Write the data into the CSRSS request and send it */
956  ShutdownParametersRequest->ShutdownLevel = dwLevel;
957  ShutdownParametersRequest->ShutdownFlags = dwFlags;
959  NULL,
961  sizeof(*ShutdownParametersRequest));
962  if (!NT_SUCCESS(ApiMessage.Status))
963  {
964  /* Return the failure from CSRSS */
965  BaseSetLastNTError(ApiMessage.Status);
966  return FALSE;
967  }
968 
969  /* All went well */
970  return TRUE;
971 }
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI CsrClientCallServer(IN OUT PCSR_API_MESSAGE ApiMessage, IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer OPTIONAL, IN CSR_API_NUMBER ApiNumber, IN ULONG DataLength)
Definition: connect.c:365
NTSTATUS Status
Definition: csrmsg.h:112
BASE_GETSET_PROCESS_SHUTDOWN_PARAMS ShutdownParametersRequest
Definition: basemsg.h:294
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
#define BASESRV_SERVERDLL_INDEX
Definition: basemsg.h:15
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
union _BASE_API_MESSAGE::@3407 Data

Referenced by _tWinMain(), and wWinMain().

◆ SetProcessWorkingSetSize()

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

Definition at line 1083 of file proc.c.

1086 {
1087  /* Call the newer API */
1089  dwMinimumWorkingSetSize,
1090  dwMaximumWorkingSetSize,
1091  0);
1092 }
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
BOOL WINAPI SetProcessWorkingSetSizeEx(IN HANDLE hProcess, IN SIZE_T dwMinimumWorkingSetSize, IN SIZE_T dwMaximumWorkingSetSize, IN DWORD Flags)
Definition: proc.c:1027

◆ SetProcessWorkingSetSizeEx()

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

Definition at line 1027 of file proc.c.

1031 {
1032  QUOTA_LIMITS_EX QuotaLimits;
1033  NTSTATUS Status, ReturnStatus;
1034  BOOL Result;
1035  PVOID State;
1037 
1038  /* Zero out the input structure */
1039  RtlZeroMemory(&QuotaLimits, sizeof(QuotaLimits));
1040 
1041  /* Check if the caller sent any limits */
1042  if ((dwMinimumWorkingSetSize) && (dwMaximumWorkingSetSize))
1043  {
1044  /* Write the quota information */
1045  QuotaLimits.MinimumWorkingSetSize = dwMinimumWorkingSetSize;
1046  QuotaLimits.MaximumWorkingSetSize = dwMaximumWorkingSetSize;
1047  QuotaLimits.Flags = Flags;
1048 
1049  /* Acquire the required privilege */
1051 
1052  /* Request the new quotas */
1053  ReturnStatus = NtSetInformationProcess(hProcess,
1055  &QuotaLimits,
1056  sizeof(QuotaLimits));
1057  Result = NT_SUCCESS(ReturnStatus);
1058  if (NT_SUCCESS(Status))
1059  {
1060  /* Release the privilege and set succes code */
1061  ASSERT(State != NULL);
1063  State = NULL;
1064  }
1065  }
1066  else
1067  {
1068  /* No limits, fail the call */
1069  ReturnStatus = STATUS_INVALID_PARAMETER;
1070  Result = FALSE;
1071  }
1072 
1073  /* Return result code, set error code if this was a failure */
1074  if (!Result) BaseSetLastNTError(ReturnStatus);
1075  return Result;
1076 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI VOID NTAPI RtlReleasePrivilege(_In_ PVOID ReturnedState)
_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:426
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOL Privilege(LPTSTR pszPrivilege, BOOL bEnable)
Definition: user_lib.cpp:531
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define SE_INC_BASE_PRIORITY_PRIVILEGE
Definition: security.c:668
Status
Definition: gdiplustypes.h:24
SIZE_T MaximumWorkingSetSize
Definition: pstypes.h:71
enum State_ State
Definition: pofuncs.h:54
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1112
SIZE_T MinimumWorkingSetSize
Definition: pstypes.h:70
NTSYSAPI NTSTATUS NTAPI RtlAcquirePrivilege(_In_ PULONG Privilege, _In_ ULONG NumPriv, _In_ ULONG Flags, _Out_ PVOID *ReturnedState)
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by SetProcessWorkingSetSize().

◆ StuffStdHandle()

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

Definition at line 57 of file proc.c.

60 {
62  HANDLE DuplicatedHandle;
63  SIZE_T NumberOfBytesWritten;
64 
65  /* If there is no handle to duplicate, return immediately */
66  if (!StandardHandle) return;
67 
68  /* Duplicate the handle */
70  StandardHandle,
72  &DuplicatedHandle,
73  0,
74  0,
77  if (!NT_SUCCESS(Status)) return;
78 
79  /* Write it */
81  Address,
82  &DuplicatedHandle,
83  sizeof(HANDLE),
84  &NumberOfBytesWritten);
85 }
LONG NTSTATUS
Definition: precomp.h:26
#define DUPLICATE_SAME_ACCESS
static WCHAR Address[46]
Definition: ping.c:68
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:79
#define DUPLICATE_SAME_ATTRIBUTES
Definition: obtypes.h:153
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:3407
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
NTSTATUS NTAPI NtWriteVirtualMemory(IN HANDLE ProcessHandle, IN PVOID BaseAddress, IN PVOID Buffer, IN SIZE_T NumberOfBytesToWrite, OUT PSIZE_T NumberOfBytesWritten OPTIONAL)
Definition: virtual.c:2805

Referenced by CreateProcessInternalW().

◆ TerminateProcess()

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

Definition at line 1532 of file proc.c.

1534 {
1535  NTSTATUS Status;
1536 
1537  /* Check if no handle was passed in */
1538  if (!hProcess)
1539  {
1540  /* Set error code */
1542  }
1543  else
1544  {
1545  /* Otherwise, try to terminate the process */
1546  Status = NtTerminateProcess(hProcess, uExitCode);
1547  if (NT_SUCCESS(Status)) return TRUE;
1548 
1549  /* It failed, convert error code */
1551  }
1552 
1553  /* This is the failure path */
1554  return FALSE;
1555 }
#define TRUE
Definition: types.h:120
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
LONG NTSTATUS
Definition: precomp.h:26
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:417
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtTerminateProcess(HANDLE ProcessHandle, LONG ExitStatus)

Referenced by _tWinMain(), child_process(), Telnet::Close(), CloseProcess(), CorDebug_CreateProcess(), cordebugprocess_Terminate(), CPlApplet(), crash_and_debug(), CreateProcessAsUserCommon(), do_register_dll(), DoTestEntry(), ExecuteKill(), ExecutePipeline(), Ghost_DestroyTarget(), ProcessKeys(), ProcessPage_OnEndProcess(), run_ex(), run_reg_exe_(), run_regedit_exe_(), runcmd(), ScreensaverConfig(), ScreenSaverPageProc(), ScreensaverPreview(), SetScreenSaverPreviewBox(), ShutdownProcessTreeHelper(), START_TEST(), StartScreenSaver(), terminate_processes(), TerminateShell(), test_apc_deadlock(), test_BreakawayOk(), test_CompletionPort(), test_CreateRemoteThread(), test_Directory(), test_EnumProcessModules(), test_ExitProcess(), test_GetProcessVersion(), test_IsProcessInJob(), test_IsWow64Process(), test_KillOnJobClose(), Test_layers(), test_NtMapViewOfSection(), test_NtSuspendProcess(), test_overlapped_transport(), test_process_access(), test_QueryInformationJobObject(), Test_repeatlayer(), test_RtlQueryPackageIdentity(), test_RunSetupCommand(), test_section_access(), test_shell_window(), test_TerminateJobObject(), test_TerminateProcess(), test_VirtualAllocEx(), test_WaitForInputIdle(), test_WaitForJobObject(), TestShellExecuteEx(), TestTerminateProcess(), WshExec_Terminate(), wWinMain(), and CProcess::~CProcess().

◆ WinExec()

UINT WINAPI DECLSPEC_HOTPATCH WinExec ( LPCSTR  lpCmdLine,
UINT  uCmdShow 
)

Definition at line 4774 of file proc.c.

4776 {
4777  STARTUPINFOA StartupInfo;
4778  PROCESS_INFORMATION ProcessInformation;
4779  DWORD dosErr;
4780 
4781  RtlZeroMemory(&StartupInfo, sizeof(StartupInfo));
4782  StartupInfo.cb = sizeof(STARTUPINFOA);
4783  StartupInfo.wShowWindow = (WORD)uCmdShow;
4784  StartupInfo.dwFlags = 0;
4785 
4786  if (!CreateProcessA(NULL,
4787  (PVOID)lpCmdLine,
4788  NULL,
4789  NULL,
4790  FALSE,
4791  0,
4792  NULL,
4793  NULL,
4794  &StartupInfo,
4795  &ProcessInformation))
4796  {
4797  dosErr = GetLastError();
4798  return dosErr < 32 ? dosErr : ERROR_BAD_FORMAT;
4799  }
4800 
4802  {
4803  UserWaitForInputIdleRoutine(ProcessInformation.hProcess,
4804  10000);
4805  }
4806 
4807  NtClose(ProcessInformation.hProcess);
4808  NtClose(ProcessInformation.hThread);
4809 
4810  return 33; /* Something bigger than 31 means success. */
4811 }
struct _STARTUPINFOA STARTUPINFOA
#define ERROR_BAD_FORMAT
Definition: winerror.h:114
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD dwFlags
Definition: winbase.h:814
smooth NULL
Definition: ftsmooth.c:416
WaitForInputIdleType UserWaitForInputIdleRoutine
Definition: proc.c:20
DWORD cb
Definition: winbase.h:803
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4742
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
WORD wShowWindow
Definition: winbase.h:815
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by DefWndHandleSysCommand(), RunBatch(), RunBookmarkEditor(), ScreenSaverPageProc(), and WinHelpA().

◆ WriteProcessMemory()

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

Definition at line 2056 of file proc.c.

2061 {
2062  NTSTATUS Status;
2063  ULONG OldValue;
2065  PVOID Base;
2067 
2068  /* Set parameters for protect call */
2069  RegionSize = nSize;
2070  Base = lpBaseAddress;
2071 
2072  /* Check the current status */
2074  &Base,
2075  &RegionSize,
2077  &OldValue);
2078  if (NT_SUCCESS(Status))
2079  {
2080  /* Check if we are unprotecting */
2081  UnProtect = OldValue & (PAGE_READWRITE |
2082  PAGE_WRITECOPY |
2085  if (!UnProtect)
2086  {
2087  /* Set the new protection */
2089  &Base,
2090  &RegionSize,
2091  OldValue,
2092  &OldValue);
2093 
2094  /* Write the memory */
2096  lpBaseAddress,
2097  (LPVOID)lpBuffer,
2098  nSize,
2099  &nSize);
2100 
2101  /* In Win32, the parameter is optional, so handle this case */
2102  if (lpNumberOfBytesWritten) *lpNumberOfBytesWritten = nSize;
2103 
2104  if (!NT_SUCCESS(Status))
2105  {
2106  /* We failed */
2108  return FALSE;
2109  }
2110 
2111  /* Flush the ITLB */
2112  NtFlushInstructionCache(hProcess, lpBaseAddress, nSize);
2113  return TRUE;
2114  }
2115  else
2116  {
2117  /* Check if we were read only */
2118  if (OldValue & (PAGE_NOACCESS | PAGE_READONLY))
2119  {
2120  /* Restore protection and fail */
2122  &Base,
2123  &RegionSize,
2124  OldValue,
2125  &OldValue);
2127 
2128  /* Note: This is what Windows returns and code depends on it */
2129  return STATUS_ACCESS_VIOLATION;
2130  }
2131 
2132  /* Otherwise, do the write */
2134  lpBaseAddress,
2135  (LPVOID)lpBuffer,
2136  nSize,
2137  &nSize);
2138 
2139  /* In Win32, the parameter is optional, so handle this case */
2140  if (lpNumberOfBytesWritten) *lpNumberOfBytesWritten = nSize;
2141 
2142  /* And restore the protection */
2144  &Base,
2145  &RegionSize,
2146  OldValue,
2147  &OldValue);
2148  if (!NT_SUCCESS(Status))
2149  {
2150  /* We failed */
2152 
2153  /* Note: This is what Windows returns and code depends on it */
2154  return STATUS_ACCESS_VIOLATION;
2155  }
2156 
2157  /* Flush the ITLB */
2158  NtFlushInstructionCache(hProcess, lpBaseAddress, nSize);
2159  return TRUE;
2160  }
2161  }
2162  else
2163  {
2164  /* We failed */
2166  return FALSE;
2167  }
2168 }
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI NtProtectVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UnsafeBaseAddress, IN OUT SIZE_T *UnsafeNumberOfBytesToProtect, IN ULONG NewAccessProtection, OUT PULONG UnsafeOldAccessProtection)
Definition: virtual.c:2986
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
LONG NTSTATUS
Definition: precomp.h:26
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2374
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
NTSTATUS NTAPI NtFlushInstructionCache(_In_ HANDLE ProcessHandle, _In_opt_ PVOID BaseAddress, _In_ SIZE_T FlushSize)
Definition: virtual.c:2919
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
#define PAGE_NOACCESS
Definition: nt_native.h:1302
unsigned char BOOLEAN
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:79
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
__kernel_entry _Inout_ _Inout_ PSIZE_T RegionSize
Definition: mmfuncs.h:172
#define PAGE_READONLY
Definition: compat.h:127
#define PAGE_WRITECOPY
Definition: nt_native.h:1305
unsigned int ULONG
Definition: retypes.h:1
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
NTSTATUS NTAPI NtWriteVirtualMemory(IN HANDLE ProcessHandle, IN PVOID BaseAddress, IN PVOID Buffer, IN SIZE_T NumberOfBytesToWrite, OUT PSIZE_T NumberOfBytesWritten OPTIONAL)
Definition: virtual.c:2805
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by _DoDLLInjection(), change_channel_CB(), and test_VirtualAllocEx().

Variable Documentation

◆ BaseAnsiCommandLine

ANSI_STRING BaseAnsiCommandLine

Definition at line 22 of file proc.c.

Referenced by GetCommandLineA(), and InitCommandLines().

◆ BaseAnsiStartupInfo

LPSTARTUPINFOA BaseAnsiStartupInfo = NULL

Definition at line 24 of file proc.c.

Referenced by GetStartupInfoA().

◆ BasepAppCertDllsList

LIST_ENTRY BasepAppCertDllsList

Definition at line 28 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:189
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR L[]
Definition: oid.c:1250
LIST_ENTRY BasepAppCertDllsList
Definition: proc.c:28

Definition at line 32 of file proc.c.

Referenced by BasepIsProcessAllowed().

◆ BasePathVariableName

UNICODE_STRING BasePathVariableName = RTL_CONSTANT_STRING(L"PATH")

Definition at line 23 of file proc.c.

Referenced by BasepComputeProcessPath().

◆ BasepExeLdrEntry

PLDR_DATA_TABLE_ENTRY BasepExeLdrEntry

Definition at line 25 of file proc.c.

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

◆ BaseUnicodeCommandLine

UNICODE_STRING BaseUnicodeCommandLine

Definition at line 21 of file proc.c.

Referenced by GetCommandLineW(), and InitCommandLines().

◆ fEmbeddedCertFunc

PBASEP_APPCERT_EMBEDDED_FUNC fEmbeddedCertFunc

Definition at line 30 of file proc.c.

Referenced by BasepIsProcessAllowed().

◆ g_AppCertInitialized

BOOLEAN g_AppCertInitialized

Definition at line 26 of file proc.c.

Referenced by BasepIsProcessAllowed().

◆ g_AppCertStatus

NTSTATUS g_AppCertStatus

Definition at line 31 of file proc.c.

Referenced by BasepIsProcessAllowed().

◆ g_HaveAppCerts

BOOLEAN g_HaveAppCerts

Definition at line 27 of file proc.c.

Referenced by BasepIsProcessAllowed().

◆ g_SaferReplaceProcessThreadTokens

PSAFER_REPLACE_PROCESS_THREAD_TOKENS g_SaferReplaceProcessThreadTokens

Definition at line 45 of file proc.c.

Referenced by BasepReplaceProcessThreadTokens().

◆ gcsAppCert

Definition at line 29 of file proc.c.

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

◆ gSaferHandle

HMODULE gSaferHandle = (HMODULE)-1

Definition at line 46 of file proc.c.

Referenced by BasepReplaceProcessThreadTokens().

◆ UserWaitForInputIdleRoutine

WaitForInputIdleType UserWaitForInputIdleRoutine

Definition at line 20 of file proc.c.

Referenced by LoadModule(), RegisterWaitForInputIdle(), and WinExec().