ReactOS 0.4.16-dev-2274-gc61d98f
procansi.c File Reference
#include <k32.h>
#include <debug.h>
Include dependency graph for procansi.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID WINAPI RegisterWaitForInputIdle (IN WaitForInputIdleType lpfnRegisterWaitForInputIdle)
 
VOID WINAPI GetStartupInfoA (IN LPSTARTUPINFOA lpStartupInfo)
 
UINT WINAPI DECLSPEC_HOTPATCH WinExec (LPCSTR lpCmdLine, UINT uCmdShow)
 

Variables

LPSTARTUPINFOA BaseAnsiStartupInfo = NULL
 
WaitForInputIdleType UserWaitForInputIdleRoutine
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file procansi.c.

Function Documentation

◆ GetStartupInfoA()

VOID WINAPI GetStartupInfoA ( IN LPSTARTUPINFOA  lpStartupInfo)

Definition at line 209 of file procansi.c.

210{
212 ANSI_STRING TitleString, ShellString, DesktopString;
213 LPSTARTUPINFOA StartupInfo;
215
216 /* Get the cached information as well as the PEB parameters */
217 StartupInfo = BaseAnsiStartupInfo;
218 Params = NtCurrentPeb()->ProcessParameters;
219
220 /* Check if this is the first time we have to get the cached version */
221 while (!StartupInfo)
222 {
223 /* Create new ANSI startup info */
224 StartupInfo = RtlAllocateHeap(RtlGetProcessHeap(),
225 0,
226 sizeof(*StartupInfo));
227 if (StartupInfo)
228 {
229 /* Zero out string pointers in case we fail to create them */
230 StartupInfo->lpReserved = NULL;
231 StartupInfo->lpDesktop = NULL;
232 StartupInfo->lpTitle = NULL;
233
234 /* Set the size */
235 StartupInfo->cb = sizeof(*StartupInfo);
236
237 /* Copy what's already stored in the PEB */
238 StartupInfo->dwX = Params->StartingX;
239 StartupInfo->dwY = Params->StartingY;
240 StartupInfo->dwXSize = Params->CountX;
241 StartupInfo->dwYSize = Params->CountY;
242 StartupInfo->dwXCountChars = Params->CountCharsX;
243 StartupInfo->dwYCountChars = Params->CountCharsY;
244 StartupInfo->dwFillAttribute = Params->FillAttribute;
245 StartupInfo->dwFlags = Params->WindowFlags;
246 StartupInfo->wShowWindow = (WORD)Params->ShowWindowFlags;
247 StartupInfo->cbReserved2 = Params->RuntimeData.Length;
248 StartupInfo->lpReserved2 = (LPBYTE)Params->RuntimeData.Buffer;
249 StartupInfo->hStdInput = Params->StandardInput;
250 StartupInfo->hStdOutput = Params->StandardOutput;
251 StartupInfo->hStdError = Params->StandardError;
252
253 /* Copy shell info string */
255 &Params->ShellInfo,
256 TRUE);
257 if (NT_SUCCESS(Status))
258 {
259 /* Save it */
260 StartupInfo->lpReserved = ShellString.Buffer;
261
262 /* Copy desktop info string */
263 Status = RtlUnicodeStringToAnsiString(&DesktopString,
264 &Params->DesktopInfo,
265 TRUE);
266 if (NT_SUCCESS(Status))
267 {
268 /* Save it */
269 StartupInfo->lpDesktop = DesktopString.Buffer;
270
271 /* Copy window title string */
273 &Params->WindowTitle,
274 TRUE);
275 if (NT_SUCCESS(Status))
276 {
277 /* Save it */
278 StartupInfo->lpTitle = TitleString.Buffer;
279
280 /* We finished with the ANSI version, try to cache it */
282 StartupInfo,
283 NULL))
284 {
285 /* We were the first thread through, use the data */
286 break;
287 }
288
289 /* Someone beat us to it, we will use their data instead */
291
292 /* We're going to free our own stuff, but not raise */
293 RtlFreeAnsiString(&TitleString);
294 }
295 RtlFreeAnsiString(&DesktopString);
296 }
297 RtlFreeAnsiString(&ShellString);
298 }
299 RtlFreeHeap(RtlGetProcessHeap(), 0, StartupInfo);
300
301 /* Get the cached information again: either still NULL or set by another thread */
302 StartupInfo = BaseAnsiStartupInfo;
303 }
304 else
305 {
306 /* No memory, fail */
308 }
309
310 /* Raise an error unless we got here due to the race condition */
311 if (!StartupInfo) RtlRaiseStatus(Status);
312 }
313
314 /* Now copy from the cached ANSI version */
315 lpStartupInfo->cb = StartupInfo->cb;
316 lpStartupInfo->lpReserved = StartupInfo->lpReserved;
317 lpStartupInfo->lpDesktop = StartupInfo->lpDesktop;
318 lpStartupInfo->lpTitle = StartupInfo->lpTitle;
319 lpStartupInfo->dwX = StartupInfo->dwX;
320 lpStartupInfo->dwY = StartupInfo->dwY;
321 lpStartupInfo->dwXSize = StartupInfo->dwXSize;
322 lpStartupInfo->dwYSize = StartupInfo->dwYSize;
323 lpStartupInfo->dwXCountChars = StartupInfo->dwXCountChars;
324 lpStartupInfo->dwYCountChars = StartupInfo->dwYCountChars;
325 lpStartupInfo->dwFillAttribute = StartupInfo->dwFillAttribute;
326 lpStartupInfo->dwFlags = StartupInfo->dwFlags;
327 lpStartupInfo->wShowWindow = StartupInfo->wShowWindow;
328 lpStartupInfo->cbReserved2 = StartupInfo->cbReserved2;
329 lpStartupInfo->lpReserved2 = StartupInfo->lpReserved2;
330
331 /* Check if the shell is hijacking the handles for other features */
332 if (lpStartupInfo->dwFlags &
333 (STARTF_USESTDHANDLES | STARTF_USEHOTKEY | STARTF_SHELLPRIVATE))
334 {
335 /* It isn't, so we can return the raw values */
336 lpStartupInfo->hStdInput = StartupInfo->hStdInput;
337 lpStartupInfo->hStdOutput = StartupInfo->hStdOutput;
338 lpStartupInfo->hStdError = StartupInfo->hStdError;
339 }
340 else
341 {
342 /* It is, so make sure nobody uses these as console handles */
343 lpStartupInfo->hStdInput = INVALID_HANDLE_VALUE;
344 lpStartupInfo->hStdOutput = INVALID_HANDLE_VALUE;
345 lpStartupInfo->hStdError = INVALID_HANDLE_VALUE;
346 }
347}
#define NtCurrentPeb()
Definition: FLS.c:22
LONG NTSTATUS
Definition: precomp.h:26
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:634
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
unsigned short WORD
Definition: ntddk_ex.h:93
Status
Definition: gdiplustypes.h:25
#define InterlockedCompareExchangePointer
Definition: interlocked.h:144
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlFreeAnsiString(PANSI_STRING AnsiString)
#define STARTF_USEHOTKEY
Definition: pch.h:41
LPSTARTUPINFOA BaseAnsiStartupInfo
Definition: procansi.c:19
#define STATUS_SUCCESS
Definition: shellext.h:65
unsigned char * LPBYTE
Definition: typedefs.h:53
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:308
#define STARTF_USESTDHANDLES
Definition: winbase.h:476

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

◆ RegisterWaitForInputIdle()

VOID WINAPI RegisterWaitForInputIdle ( IN WaitForInputIdleType  lpfnRegisterWaitForInputIdle)

Definition at line 29 of file procansi.c.

30{
31 /* Write the global function pointer */
32 UserWaitForInputIdleRoutine = lpfnRegisterWaitForInputIdle;
33}
WaitForInputIdleType UserWaitForInputIdleRoutine
Definition: procansi.c:20

◆ WinExec()

UINT WINAPI DECLSPEC_HOTPATCH WinExec ( LPCSTR  lpCmdLine,
UINT  uCmdShow 
)

Definition at line 355 of file procansi.c.

357{
358 STARTUPINFOA StartupInfo;
359 PROCESS_INFORMATION ProcessInformation;
360 DWORD dosErr;
361
362 RtlZeroMemory(&StartupInfo, sizeof(StartupInfo));
363 StartupInfo.cb = sizeof(STARTUPINFOA);
364 StartupInfo.wShowWindow = (WORD)uCmdShow;
365 StartupInfo.dwFlags = 0;
366
367 if (!CreateProcessA(NULL,
368 (PVOID)lpCmdLine,
369 NULL,
370 NULL,
371 FALSE,
372 0,
373 NULL,
374 NULL,
375 &StartupInfo,
376 &ProcessInformation))
377 {
378 dosErr = GetLastError();
379 return dosErr < 32 ? dosErr : ERROR_BAD_FORMAT;
380 }
381
383 {
384 UserWaitForInputIdleRoutine(ProcessInformation.hProcess,
385 10000);
386 }
387
388 NtClose(ProcessInformation.hProcess);
389 NtClose(ProcessInformation.hThread);
390
391 return 33; /* Something bigger than 31 means success. */
392}
#define FALSE
Definition: types.h:117
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(const char *app_name, char *cmd_line, SECURITY_ATTRIBUTES *process_attr, SECURITY_ATTRIBUTES *thread_attr, BOOL inherit, DWORD flags, void *env, const char *cur_dir, STARTUPINFOA *startup_info, PROCESS_INFORMATION *info)
Definition: process.c:686
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
struct _STARTUPINFOA STARTUPINFOA
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_BAD_FORMAT
Definition: winerror.h:236

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

Variable Documentation

◆ BaseAnsiStartupInfo

LPSTARTUPINFOA BaseAnsiStartupInfo = NULL

Definition at line 19 of file procansi.c.

Referenced by GetStartupInfoA().

◆ UserWaitForInputIdleRoutine

WaitForInputIdleType UserWaitForInputIdleRoutine

Definition at line 20 of file procansi.c.

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