ReactOS  0.4.14-dev-606-g14ebc0b
console.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define HANDLE_DETACHED_PROCESS   (HANDLE)-1
 
#define HANDLE_CREATE_NEW_CONSOLE   (HANDLE)-2
 
#define HANDLE_CREATE_NO_WINDOW   (HANDLE)-3
 
#define SetTEBLangID(p)   (p)
 

Functions

BOOLEAN WINAPI ConDllInitialize (IN ULONG Reason, IN PWSTR SessionDir)
 
VOID InitializeCtrlHandling (VOID)
 
DWORD WINAPI ConsoleControlDispatcher (IN LPVOID lpThreadParameter)
 
DWORD WINAPI PropDialogHandler (IN LPVOID lpThreadParameter)
 
HANDLE WINAPI DuplicateConsoleHandle (HANDLE hConsole, DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwOptions)
 
BOOL WINAPI GetConsoleHandleInformation (IN HANDLE hHandle, OUT LPDWORD lpdwFlags)
 
BOOL WINAPI SetConsoleHandleInformation (IN HANDLE hHandle, IN DWORD dwMask, IN DWORD dwFlags)
 
BOOL WINAPI VerifyConsoleIoHandle (HANDLE Handle)
 
BOOL WINAPI CloseConsoleHandle (HANDLE Handle)
 
HANDLE WINAPI GetConsoleInputWaitHandle (VOID)
 
HANDLE TranslateStdHandle (HANDLE hHandle)
 
VOID SetUpConsoleInfo (IN BOOLEAN CaptureTitle, IN OUT LPDWORD pTitleLength, IN OUT LPWSTR *lpTitle OPTIONAL, IN OUT LPDWORD pDesktopLength, IN OUT LPWSTR *lpDesktop OPTIONAL, IN OUT PCONSOLE_START_INFO ConsoleStartInfo)
 
VOID SetUpHandles (IN PCONSOLE_START_INFO ConsoleStartInfo)
 
VOID InitExeName (VOID)
 
VOID SetUpAppName (IN BOOLEAN CaptureStrings, IN OUT LPDWORD CurDirLength, IN OUT LPWSTR *CurDir, IN OUT LPDWORD AppNameLength, IN OUT LPWSTR *AppName)
 
USHORT GetCurrentExeName (OUT PWCHAR ExeName, IN USHORT BufferSize)
 
LPCWSTR IntCheckForConsoleFileName (IN LPCWSTR pszName, IN DWORD dwDesiredAccess)
 
HANDLE WINAPI OpenConsoleW (LPCWSTR wsName, DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwShareMode)
 

Macro Definition Documentation

◆ HANDLE_CREATE_NEW_CONSOLE

#define HANDLE_CREATE_NEW_CONSOLE   (HANDLE)-2

Definition at line 14 of file console.h.

◆ HANDLE_CREATE_NO_WINDOW

#define HANDLE_CREATE_NO_WINDOW   (HANDLE)-3

Definition at line 15 of file console.h.

◆ HANDLE_DETACHED_PROCESS

#define HANDLE_DETACHED_PROCESS   (HANDLE)-1

Definition at line 13 of file console.h.

◆ SetTEBLangID

#define SetTEBLangID (   p)    (p)

Definition at line 63 of file console.h.

Function Documentation

◆ CloseConsoleHandle()

BOOL WINAPI CloseConsoleHandle ( HANDLE  Handle)

Definition at line 1142 of file console.c.

1143 {
1144  CONSOLE_API_MESSAGE ApiMessage;
1145  PCONSOLE_CLOSEHANDLE CloseHandleRequest = &ApiMessage.Data.CloseHandleRequest;
1146 
1147  CloseHandleRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
1148  CloseHandleRequest->Handle = hHandle;
1149 
1151  NULL,
1153  sizeof(*CloseHandleRequest));
1154  if (!NT_SUCCESS(ApiMessage.Status))
1155  {
1156  BaseSetLastNTError(ApiMessage.Status);
1157  return FALSE;
1158  }
1159 
1160  return TRUE;
1161 }
#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
HANDLE ConsoleHandle
Definition: conmsg.h:626
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 NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NtCurrentPeb()
Definition: FLS.c:20
CONSOLE_CLOSEHANDLE CloseHandleRequest
Definition: conmsg.h:913
union _CONSOLE_API_MESSAGE::@3413 Data
#define CONSRV_SERVERDLL_INDEX
Definition: conmsg.h:15

Referenced by CloseHandle().

◆ ConDllInitialize()

BOOLEAN WINAPI ConDllInitialize ( IN ULONG  Reason,
IN PWSTR  SessionDir 
)

Definition at line 338 of file init.c.

340 {
343  BOOLEAN InServerProcess = FALSE;
344  CONSRV_API_CONNECTINFO ConnectInfo;
345  LCID lcid;
346 
347  if (Reason != DLL_PROCESS_ATTACH)
348  {
349  if ((Reason == DLL_THREAD_ATTACH) && IsConsoleApp())
350  {
351  /* Sets the current console locale for the new thread */
352  SetTEBLangID(lcid);
353  }
354  else if (Reason == DLL_PROCESS_DETACH)
355  {
356  /* Free our resources */
357  if (ConsoleInitialized != FALSE)
358  {
361  }
362  }
363 
364  return TRUE;
365  }
366 
367  DPRINT("ConDllInitialize for: %wZ\n"
368  "Our current console handles are: 0x%p, 0x%p, 0x%p 0x%p\n",
369  &Parameters->ImagePathName,
370  Parameters->ConsoleHandle,
371  Parameters->StandardInput,
372  Parameters->StandardOutput,
373  Parameters->StandardError);
374 
375  /* Initialize our global console DLL lock */
377  if (!NT_SUCCESS(Status)) return FALSE;
379 
380  /* Show by default the console window when applicable */
381  ConnectInfo.IsWindowVisible = TRUE;
382  /* If this is a console app, a console will be created/opened */
383  ConnectInfo.IsConsoleApp = IsConsoleApp();
384 
385  /* Do nothing if this is not a console app... */
386  if (!ConnectInfo.IsConsoleApp)
387  {
388  DPRINT("Image is not a console application\n");
389  }
390 
391  /*
392  * Handle the special flags given to us by BasePushProcessParameters.
393  */
394  if (Parameters->ConsoleHandle == HANDLE_DETACHED_PROCESS)
395  {
396  /* No console to create */
397  DPRINT("No console to create\n");
398  /*
399  * The new process does not inherit its parent's console and cannot
400  * attach to the console of its parent. The new process can call the
401  * AllocConsole function at a later time to create a console.
402  */
403  Parameters->ConsoleHandle = NULL; // Do not inherit the parent's console.
404  ConnectInfo.IsConsoleApp = FALSE; // Do not create any console.
405  }
406  else if (Parameters->ConsoleHandle == HANDLE_CREATE_NEW_CONSOLE)
407  {
408  /* We'll get the real one soon */
409  DPRINT("Creating a new separate console\n");
410  /*
411  * The new process has a new console, instead of inheriting
412  * its parent's console.
413  */
414  Parameters->ConsoleHandle = NULL; // Do not inherit the parent's console.
415  }
416  else if (Parameters->ConsoleHandle == HANDLE_CREATE_NO_WINDOW)
417  {
418  /* We'll get the real one soon */
419  DPRINT("Creating a new invisible console\n");
420  /*
421  * The process is a console application that is being run
422  * without a console window. Therefore, the console handle
423  * for the application is not set.
424  */
425  Parameters->ConsoleHandle = NULL; // Do not inherit the parent's console.
426  ConnectInfo.IsWindowVisible = FALSE; // A console is created but is not shown to the user.
427  }
428  else
429  {
430  DPRINT("Using existing console: 0x%p\n", Parameters->ConsoleHandle);
431  }
432 
433  /* Do nothing if this is not a console app... */
434  if (!ConnectInfo.IsConsoleApp)
435  {
436  /* Do not inherit the parent's console if we are not a console app */
437  Parameters->ConsoleHandle = NULL;
438  }
439 
440  /* Now use the proper console handle */
441  ConnectInfo.ConsoleStartInfo.ConsoleHandle = Parameters->ConsoleHandle;
442 
443  /* Initialize the console dispatchers */
445  ConnectInfo.PropRoutine = PropDialogHandler;
446  // ConnectInfo.ImeRoutine = ImeRoutine;
447 
448  /* Set up the console properties */
449  if (ConnectInfo.IsConsoleApp && Parameters->ConsoleHandle == NULL)
450  {
451  /*
452  * We can set up the console properties only if we create a new one
453  * (we do not inherit it from our parent).
454  */
455 
456  LPWSTR ConsoleTitle = ConnectInfo.ConsoleTitle;
457 
458  ConnectInfo.TitleLength = sizeof(ConnectInfo.ConsoleTitle);
459  ConnectInfo.DesktopLength = 0; // SetUpConsoleInfo will give us the real length.
460 
462  &ConnectInfo.TitleLength,
463  &ConsoleTitle,
464  &ConnectInfo.DesktopLength,
465  &ConnectInfo.Desktop,
466  &ConnectInfo.ConsoleStartInfo);
467  DPRINT("ConsoleTitle = '%S' - Desktop = '%S'\n",
468  ConsoleTitle, ConnectInfo.Desktop);
469  }
470  else
471  {
472  ConnectInfo.TitleLength = 0;
473  ConnectInfo.DesktopLength = 0;
474  }
475 
476  /* Initialize the Input EXE name */
477  if (ConnectInfo.IsConsoleApp)
478  {
479  LPWSTR CurDir = ConnectInfo.CurDir;
480  LPWSTR AppName = ConnectInfo.AppName;
481 
482  InitExeName();
483 
484  ConnectInfo.CurDirLength = sizeof(ConnectInfo.CurDir);
485  ConnectInfo.AppNameLength = sizeof(ConnectInfo.AppName);
486 
488  &ConnectInfo.CurDirLength,
489  &CurDir,
490  &ConnectInfo.AppNameLength,
491  &AppName);
492  DPRINT("CurDir = '%S' - AppName = '%S'\n",
493  CurDir, AppName);
494  }
495  else
496  {
497  ConnectInfo.CurDirLength = 0;
498  ConnectInfo.AppNameLength = 0;
499  }
500 
501  /*
502  * Initialize Console Ctrl Handling, that needs to be supported by
503  * all applications, especially because it is used at shutdown.
504  */
506 
507  /* Connect to the Console Server */
508  if (!ConnectConsole(SessionDir,
509  &ConnectInfo,
510  &InServerProcess))
511  {
512  // DPRINT1("Failed to connect to the Console Server (Status %lx)\n", Status);
513  return FALSE;
514  }
515 
516  /* If we are not doing server-to-server init and if this is a console app... */
517  if (!InServerProcess && ConnectInfo.IsConsoleApp)
518  {
519  /* ... set the handles that we got */
520  if (Parameters->ConsoleHandle == NULL)
521  SetUpHandles(&ConnectInfo.ConsoleStartInfo);
522 
524 
525  /* Sets the current console locale for this thread */
526  SetTEBLangID(lcid);
527  }
528 
529  DPRINT("Console setup: 0x%p, 0x%p, 0x%p, 0x%p\n",
530  Parameters->ConsoleHandle,
531  Parameters->StandardInput,
532  Parameters->StandardOutput,
533  Parameters->StandardError);
534 
535  return TRUE;
536 }
#define TRUE
Definition: types.h:120
BOOLEAN IsWindowVisible
Definition: conmsg.h:189
HANDLE InputWaitHandle
Definition: console.c:38
CONSOLE_START_INFO ConsoleStartInfo
Definition: conmsg.h:186
#define HANDLE_DETACHED_PROCESS
Definition: console.h:13
#define HANDLE_CREATE_NO_WINDOW
Definition: console.h:15
#define DLL_THREAD_ATTACH
Definition: compat.h:121
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN ConsoleInitialized
Definition: init.c:25
static CHAR AppName[MAX_PATH]
Definition: dem.c:252
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
VOID InitializeCtrlHandling(VOID)
Definition: console.c:204
DWORD LCID
Definition: nls.h:13
WCHAR AppName[128]
Definition: conmsg.h:204
VOID SetUpAppName(IN BOOLEAN CaptureStrings, IN OUT LPDWORD CurDirLength, IN OUT LPWSTR *CurDir, IN OUT LPDWORD AppNameLength, IN OUT LPWSTR *AppName)
Definition: console.c:264
LPTHREAD_START_ROUTINE CtrlRoutine
Definition: conmsg.h:193
VOID InitExeName(VOID)
Definition: console.c:216
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
VOID SetUpHandles(IN PCONSOLE_START_INFO ConsoleStartInfo)
Definition: init.c:250
void DPRINT(...)
Definition: polytest.cpp:61
VOID SetUpConsoleInfo(IN BOOLEAN CaptureTitle, IN OUT LPDWORD pTitleLength, IN OUT LPWSTR *lpTitle OPTIONAL, IN OUT LPDWORD pDesktopLength, IN OUT LPWSTR *lpDesktop OPTIONAL, IN OUT PCONSOLE_START_INFO ConsoleStartInfo)
Definition: init.c:134
#define DLL_PROCESS_DETACH
Definition: compat.h:119
#define SetTEBLangID(p)
Definition: console.h:63
DWORD WINAPI PropDialogHandler(IN LPVOID lpThreadParameter)
Definition: init.c:34
#define HANDLE_CREATE_NEW_CONSOLE
Definition: console.h:14
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
HANDLE ConsoleHandle
Definition: conmsg.h:170
static BOOLEAN IsConsoleApp(VOID)
Definition: init.c:276
static BOOLEAN ConnectConsole(IN PWSTR SessionDir, IN PCONSRV_API_CONNECTINFO ConnectInfo, OUT PBOOLEAN InServerProcess)
Definition: init.c:285
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
LPTHREAD_START_ROUTINE PropRoutine
Definition: conmsg.h:194
Status
Definition: gdiplustypes.h:24
WCHAR ConsoleTitle[MAX_PATH+1]
Definition: conmsg.h:198
#define NtCurrentPeb()
Definition: FLS.c:20
WCHAR CurDir[MAX_PATH+1]
Definition: conmsg.h:206
RTL_CRITICAL_SECTION ConsoleLock
Definition: init.c:24
HANDLE InputWaitHandle
Definition: conmsg.h:171
DWORD WINAPI ConsoleControlDispatcher(IN LPVOID lpThreadParameter)
Definition: console.c:89
WCHAR * LPWSTR
Definition: xmlstorage.h:184
NTSYSAPI NTSTATUS NTAPI RtlDeleteCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
PVOID PVOID PWCHAR PVOID USHORT PULONG Reason
Definition: env.c:45

Referenced by DllMain().

◆ ConsoleControlDispatcher()

DWORD WINAPI ConsoleControlDispatcher ( IN LPVOID  lpThreadParameter)

Definition at line 89 of file console.c.

90 {
91  DWORD nExitCode = 0;
92  DWORD CodeAndFlag = PtrToUlong(lpThreadParameter);
93  DWORD nCode = CodeAndFlag & MAXLONG;
94  UINT i;
95  EXCEPTION_RECORD erException;
96 
97  DPRINT1("Console Dispatcher Active: %lx %lx\n", CodeAndFlag, nCode);
99 
100  switch(nCode)
101  {
102  case CTRL_C_EVENT:
103  case CTRL_BREAK_EVENT:
104  {
105  if (IsDebuggerPresent())
106  {
107  erException.ExceptionCode = (nCode == CTRL_C_EVENT ?
109  erException.ExceptionFlags = 0;
110  erException.ExceptionRecord = NULL;
112  erException.NumberParameters = 0;
113 
114  _SEH2_TRY
115  {
116  RtlRaiseException(&erException);
117  }
119  {
121 
122  if ((nCode != CTRL_C_EVENT) ||
123  (NtCurrentPeb()->ProcessParameters->ConsoleFlags != 1))
124  {
125  for (i = NrCtrlHandlers; i > 0; i--)
126  {
127  if (CtrlHandlers[i - 1](nCode)) break;
128  }
129  }
130 
132  }
133  _SEH2_END;
134 
135  ExitThread(0);
136  }
137  break;
138  }
139 
140  case CTRL_CLOSE_EVENT:
141  case CTRL_LOGOFF_EVENT:
142  case CTRL_SHUTDOWN_EVENT:
143  break;
144 
146  /*
147  * In case the console app hasn't register for last close notification,
148  * just kill this console handler thread. We don't want that such apps
149  * get killed for unexpected reasons. On the contrary apps that registered
150  * can be killed because they expect to be.
151  */
152  if (!LastCloseNotify) ExitThread(0);
153  break;
154 
155  case 4:
157  break;
158 
159  default:
160  ASSERT(FALSE);
161  break;
162  }
163 
165 
167 
168  nExitCode = 0;
169  if ((nCode != CTRL_C_EVENT) || (NtCurrentPeb()->ProcessParameters->ConsoleFlags != 1))
170  {
171  for (i = NrCtrlHandlers; i > 0; i--)
172  {
173  if ((i == 1) &&
174  (CodeAndFlag & MINLONG) &&
175  ((nCode == CTRL_LOGOFF_EVENT) || (nCode == CTRL_SHUTDOWN_EVENT)))
176  {
177  DPRINT("Skipping system/service apps\n");
178  break;
179  }
180 
181  if (CtrlHandlers[i - 1](nCode))
182  {
183  switch(nCode)
184  {
185  case CTRL_CLOSE_EVENT:
187  case CTRL_LOGOFF_EVENT:
188  case CTRL_SHUTDOWN_EVENT:
189  nExitCode = CodeAndFlag;
190  break;
191  }
192  break;
193  }
194  }
195  }
196 
198 
199  ExitThread(nExitCode);
200  return STATUS_SUCCESS;
201 }
BOOL WINAPI IsDebuggerPresent(VOID)
Definition: debugger.c:615
#define CTRL_BREAK_EVENT
Definition: wincon.h:66
#define MAXLONG
Definition: umtypes.h:116
#define CTRL_CLOSE_EVENT
Definition: wincon.h:67
#define CTRL_C_EVENT
Definition: wincon.h:65
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1487
NTSYSAPI VOID NTAPI RtlRaiseException(_In_ PEXCEPTION_RECORD ExceptionRecord)
PVOID ExceptionAddress
Definition: compat.h:199
_SEH2_TRY
Definition: create.c:4250
DWORD ExceptionCode
Definition: compat.h:196
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
HANDLE WINAPI GetCurrentThread(VOID)
Definition: proc.c:1148
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
BOOLEAN ConsoleInitialized
Definition: init.c:25
#define THREAD_PRIORITY_HIGHEST
Definition: winbase.h:274
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define DBG_CONTROL_BREAK
Definition: ntstatus.h:55
void DPRINT(...)
Definition: polytest.cpp:61
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:364
#define PtrToUlong(u)
Definition: config.h:107
BOOL WINAPI SetThreadPriority(IN HANDLE hThread, IN int nPriority)
Definition: thread.c:699
static BOOL WINAPI DefaultConsoleCtrlHandler(DWORD Event)
Definition: console.c:53
static BOOLEAN LastCloseNotify
Definition: console.c:33
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DBG_CONTROL_C
Definition: ntstatus.h:52
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CTRL_LOGOFF_EVENT
Definition: wincon.h:69
#define MINLONG
Definition: umtypes.h:115
struct _EXCEPTION_RECORD * ExceptionRecord
Definition: compat.h:198
_SEH2_END
Definition: create.c:4424
#define CTRL_SHUTDOWN_EVENT
Definition: wincon.h:70
RTL_CRITICAL_SECTION ConsoleLock
Definition: init.c:24
#define NtCurrentPeb()
Definition: FLS.c:20
unsigned int UINT
Definition: ndis.h:50
#define CTRL_LAST_CLOSE_EVENT
Definition: wincon.h:68
#define DPRINT1
Definition: precomp.h:8
static ULONG NrCtrlHandlers
Definition: console.c:31
DWORD ExceptionFlags
Definition: compat.h:197
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
DWORD NumberParameters
Definition: compat.h:200
return STATUS_SUCCESS
Definition: btrfs.c:2938
static PHANDLER_ROUTINE * CtrlHandlers
Definition: console.c:30
#define CONTROL_C_EXIT
Definition: winbase.h:330

Referenced by AllocConsole(), AttachConsole(), and ConDllInitialize().

◆ DuplicateConsoleHandle()

HANDLE WINAPI DuplicateConsoleHandle ( HANDLE  hConsole,
DWORD  dwDesiredAccess,
BOOL  bInheritHandle,
DWORD  dwOptions 
)

Definition at line 424 of file console.c.

428 {
429  CONSOLE_API_MESSAGE ApiMessage;
430  PCONSOLE_DUPLICATEHANDLE DuplicateHandleRequest = &ApiMessage.Data.DuplicateHandleRequest;
431 
434  (dwDesiredAccess & ~(GENERIC_READ | GENERIC_WRITE))) )
435  {
437  return INVALID_HANDLE_VALUE;
438  }
439 
440  DuplicateHandleRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
441  DuplicateHandleRequest->SourceHandle = hConsole;
442  DuplicateHandleRequest->DesiredAccess = dwDesiredAccess;
443  DuplicateHandleRequest->InheritHandle = bInheritHandle;
444  DuplicateHandleRequest->Options = dwOptions;
445 
447  NULL,
449  sizeof(*DuplicateHandleRequest));
450  if (!NT_SUCCESS(ApiMessage.Status))
451  {
452  BaseSetLastNTError(ApiMessage.Status);
453  return INVALID_HANDLE_VALUE;
454  }
455 
456  return DuplicateHandleRequest->TargetHandle;
457 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
DWORD dwOptions
Definition: solitaire.cpp:23
CONSOLE_DUPLICATEHANDLE DuplicateHandleRequest
Definition: conmsg.h:915
#define DUPLICATE_CLOSE_SOURCE
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
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
NTSTATUS Status
Definition: csrmsg.h:112
#define DUPLICATE_SAME_ACCESS
static BOOL bInheritHandle
Definition: pipe.c:82
#define GENERIC_WRITE
Definition: nt_native.h:90
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 NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:417
#define GENERIC_READ
Definition: compat.h:124
#define NtCurrentPeb()
Definition: FLS.c:20
union _CONSOLE_API_MESSAGE::@3413 Data
#define CONSRV_SERVERDLL_INDEX
Definition: conmsg.h:15

Referenced by DuplicateHandle().

◆ GetConsoleHandleInformation()

BOOL WINAPI GetConsoleHandleInformation ( IN HANDLE  hHandle,
OUT LPDWORD  lpdwFlags 
)

Definition at line 465 of file console.c.

467 {
468  CONSOLE_API_MESSAGE ApiMessage;
469  PCONSOLE_GETHANDLEINFO GetHandleInfoRequest = &ApiMessage.Data.GetHandleInfoRequest;
470 
471  GetHandleInfoRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
472  GetHandleInfoRequest->Handle = hHandle;
473 
475  NULL,
477  sizeof(*GetHandleInfoRequest));
478  if (!NT_SUCCESS(ApiMessage.Status))
479  {
480  BaseSetLastNTError(ApiMessage.Status);
481  return FALSE;
482  }
483 
484  *lpdwFlags = GetHandleInfoRequest->Flags;
485 
486  return TRUE;
487 }
#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
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 NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CONSOLE_GETHANDLEINFO GetHandleInfoRequest
Definition: conmsg.h:916
#define NtCurrentPeb()
Definition: FLS.c:20
union _CONSOLE_API_MESSAGE::@3413 Data
#define CONSRV_SERVERDLL_INDEX
Definition: conmsg.h:15

Referenced by GetHandleInformation().

◆ GetConsoleInputWaitHandle()

HANDLE WINAPI GetConsoleInputWaitHandle ( VOID  )

Definition at line 683 of file console.c.

684 {
685  return InputWaitHandle;
686 }
HANDLE InputWaitHandle
Definition: console.c:38

◆ GetCurrentExeName()

USHORT GetCurrentExeName ( OUT PWCHAR  ExeName,
IN USHORT  BufferSize 
)

Definition at line 316 of file console.c.

318 {
319  USHORT ExeLength;
320 
321  if (ExeNameInitialized)
322  {
324 
325  if (BufferSize > ExeNameLength * sizeof(WCHAR))
326  BufferSize = ExeNameLength * sizeof(WCHAR);
327 
329 
331  ExeLength = BufferSize;
332  }
333  else
334  {
335  *ExeName = UNICODE_NULL;
336  ExeLength = 0;
337  }
338 
339  return ExeLength;
340 }
static RTL_CRITICAL_SECTION ExeNameLock
Definition: console.c:41
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
static WCHAR ExeNameBuffer[EXENAME_LENGTH]
Definition: console.c:43
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define UNICODE_NULL
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
static USHORT ExeNameLength
Definition: console.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define BufferSize
Definition: classpnp.h:419
unsigned short USHORT
Definition: pedump.c:61
static BOOLEAN ExeNameInitialized
Definition: console.c:42

Referenced by IntReadConsole().

◆ InitExeName()

VOID InitExeName ( VOID  )

Definition at line 216 of file console.c.

217 {
219  PPEB Peb = NtCurrentPeb();
221  PLDR_DATA_TABLE_ENTRY ImageEntry;
222 
223  if (ExeNameInitialized) return;
224 
225  /* Initialize the EXE name lock */
227  if (!NT_SUCCESS(Status)) return;
229 
232  InLoadOrderLinks);
233 
234  /* Retrieve the EXE name, NULL-terminate it... */
235  ExeNameLength = min(sizeof(ExeNameBuffer)/sizeof(ExeNameBuffer[0]),
236  ImageEntry->BaseDllName.Length / sizeof(WCHAR));
238  ImageEntry->BaseDllName.Buffer,
239  ImageEntry->BaseDllName.Length);
241 
242  /* ... and retrieve the current directory path and NULL-terminate it. */
243  StartDirLength = min(sizeof(StartDirBuffer)/sizeof(StartDirBuffer[0]),
244  CurrentDirectory->DosPath.Length / sizeof(WCHAR));
246  CurrentDirectory->DosPath.Buffer,
247  CurrentDirectory->DosPath.Length);
249 }
static RTL_CRITICAL_SECTION ExeNameLock
Definition: console.c:41
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
PPEB Peb
Definition: dllmain.c:27
static WCHAR ExeNameBuffer[EXENAME_LENGTH]
Definition: console.c:43
WCHAR CurrentDirectory[1024]
Definition: chkdsk.c:74
LIST_ENTRY InLoadOrderModuleList
Definition: ldrtypes.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define UNICODE_NULL
static USHORT ExeNameLength
Definition: console.c:44
static USHORT StartDirLength
Definition: console.c:46
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
__wchar_t WCHAR
Definition: xmlstorage.h:180
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PRTL_USER_PROCESS_PARAMETERS ProcessParameters
Definition: btrfs_drv.h:1890
Definition: btrfs_drv.h:1853
Status
Definition: gdiplustypes.h:24
static WCHAR StartDirBuffer[MAX_PATH+1]
Definition: console.c:45
#define NtCurrentPeb()
Definition: FLS.c:20
static BOOLEAN ExeNameInitialized
Definition: console.c:42
PPEB_LDR_DATA Ldr
Definition: btrfs_drv.h:1889
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:145
#define min(a, b)
Definition: monoChain.cc:55

Referenced by AllocConsole(), and ConDllInitialize().

◆ InitializeCtrlHandling()

VOID InitializeCtrlHandling ( VOID  )

Definition at line 204 of file console.c.

205 {
206  /* Initialize Console Ctrl Handler */
210 }
static ULONG NrAllocatedHandlers
Definition: console.c:32
static BOOL WINAPI DefaultConsoleCtrlHandler(DWORD Event)
Definition: console.c:53
static ULONG NrCtrlHandlers
Definition: console.c:31
static PHANDLER_ROUTINE InitialHandler[1]
Definition: console.c:29
static PHANDLER_ROUTINE * CtrlHandlers
Definition: console.c:30

Referenced by AllocConsole(), AttachConsole(), and ConDllInitialize().

◆ IntCheckForConsoleFileName()

LPCWSTR IntCheckForConsoleFileName ( IN LPCWSTR  pszName,
IN DWORD  dwDesiredAccess 
)

Definition at line 345 of file console.c.

347 {
348  LPCWSTR ConsoleName = pszName;
349  ULONG DeviceNameInfo;
350 
351  /*
352  * Check whether we deal with a DOS device, and if so,
353  * strip the path till the file name.
354  * Therefore, things like \\.\CON or C:\some_path\CONIN$
355  * are transformed into CON or CONIN$, for example.
356  */
357  DeviceNameInfo = RtlIsDosDeviceName_U(pszName);
358  if (DeviceNameInfo != 0)
359  {
360  ConsoleName = (LPCWSTR)((ULONG_PTR)ConsoleName + ((DeviceNameInfo >> 16) & 0xFFFF));
361  }
362 
363  /* Return a standard console "file" name according to what we passed in parameters */
364  if (_wcsicmp(ConsoleName, BaseConInputFileName) == 0)
365  {
366  return BaseConInputFileName;
367  }
368  else if (_wcsicmp(ConsoleName, BaseConOutputFileName) == 0)
369  {
370  return BaseConOutputFileName;
371  }
372  else if (_wcsicmp(ConsoleName, BaseConFileName) == 0)
373  {
374  if ((dwDesiredAccess & (GENERIC_READ | GENERIC_WRITE)) == GENERIC_READ)
375  {
376  return BaseConInputFileName;
377  }
378  else if ((dwDesiredAccess & (GENERIC_READ | GENERIC_WRITE)) == GENERIC_WRITE)
379  {
380  return BaseConOutputFileName;
381  }
382  }
383 
384  /* If we are there, that means that either the file name or the desired access are wrong */
385  return NULL;
386 }
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
static LPCWSTR BaseConOutputFileName
Definition: console.c:26
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define GENERIC_WRITE
Definition: nt_native.h:90
static LPCWSTR BaseConInputFileName
Definition: console.c:25
smooth NULL
Definition: ftsmooth.c:416
static LPCWSTR BaseConFileName
Definition: console.c:24
#define GENERIC_READ
Definition: compat.h:124
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI ULONG NTAPI RtlIsDosDeviceName_U(_In_ PCWSTR Name)
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by CreateFileW().

◆ OpenConsoleW()

HANDLE WINAPI OpenConsoleW ( LPCWSTR  wsName,
DWORD  dwDesiredAccess,
BOOL  bInheritHandle,
DWORD  dwShareMode 
)

Definition at line 791 of file console.c.

795 {
796  CONSOLE_API_MESSAGE ApiMessage;
797  PCONSOLE_OPENCONSOLE OpenConsoleRequest = &ApiMessage.Data.OpenConsoleRequest;
798  CONSOLE_HANDLE_TYPE HandleType;
799 
800  if (wsName && (_wcsicmp(wsName, BaseConInputFileName) == 0))
801  {
802  HandleType = HANDLE_INPUT;
803  }
804  else if (wsName && (_wcsicmp(wsName, BaseConOutputFileName) == 0))
805  {
806  HandleType = HANDLE_OUTPUT;
807  }
808  else
809  {
811  return INVALID_HANDLE_VALUE;
812  }
813 
814  if ( (dwDesiredAccess & ~(GENERIC_READ | GENERIC_WRITE)) ||
815  (dwShareMode & ~(FILE_SHARE_READ | FILE_SHARE_WRITE)) )
816  {
818  return INVALID_HANDLE_VALUE;
819  }
820 
821  OpenConsoleRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
822  OpenConsoleRequest->HandleType = HandleType;
823  OpenConsoleRequest->DesiredAccess = dwDesiredAccess;
824  OpenConsoleRequest->InheritHandle = bInheritHandle;
825  OpenConsoleRequest->ShareMode = dwShareMode;
826 
828  NULL,
830  sizeof(*OpenConsoleRequest));
831  if (!NT_SUCCESS(ApiMessage.Status))
832  {
833  BaseSetLastNTError(ApiMessage.Status);
834  return INVALID_HANDLE_VALUE;
835  }
836 
837  return OpenConsoleRequest->Handle;
838 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
CONSOLE_HANDLE_TYPE HandleType
Definition: conmsg.h:674
static LPCWSTR BaseConOutputFileName
Definition: console.c:26
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
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
CONSOLE_OPENCONSOLE OpenConsoleRequest
Definition: conmsg.h:912
NTSTATUS Status
Definition: csrmsg.h:112
static BOOL bInheritHandle
Definition: pipe.c:82
#define GENERIC_WRITE
Definition: nt_native.h:90
static LPCWSTR BaseConInputFileName
Definition: console.c:25
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
enum _CONSOLE_HANDLE_TYPE CONSOLE_HANDLE_TYPE
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:417
#define GENERIC_READ
Definition: compat.h:124
#define NtCurrentPeb()
Definition: FLS.c:20
union _CONSOLE_API_MESSAGE::@3413 Data
HANDLE ConsoleHandle
Definition: conmsg.h:673
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define CONSRV_SERVERDLL_INDEX
Definition: conmsg.h:15

Referenced by CreateFileW(), and init_function_pointers().

◆ PropDialogHandler()

DWORD WINAPI PropDialogHandler ( IN LPVOID  lpThreadParameter)

Definition at line 34 of file init.c.

35 {
36  // NOTE: lpThreadParameter corresponds to the client shared section handle.
37 
39  HMODULE hConsoleApplet = NULL;
41  static BOOL AlreadyDisplayingProps = FALSE;
42  WCHAR szBuffer[MAX_PATH];
43 
44  /*
45  * Do not launch more than once the console property dialog applet,
46  * or (albeit less probable), if we are not initialized.
47  */
48  if (!ConsoleInitialized || AlreadyDisplayingProps)
49  {
50  /* Close the associated client shared section handle if needed */
51  if (lpThreadParameter)
52  CloseHandle((HANDLE)lpThreadParameter);
53 
54  return STATUS_UNSUCCESSFUL;
55  }
56 
57  AlreadyDisplayingProps = TRUE;
58 
59  /* Load the control applet */
60  GetSystemDirectoryW(szBuffer, MAX_PATH);
61  wcscat(szBuffer, L"\\console.dll");
62  hConsoleApplet = LoadLibraryW(szBuffer);
63  if (hConsoleApplet == NULL)
64  {
65  DPRINT1("Failed to load console.dll\n");
67  goto Quit;
68  }
69 
70  /* Load its main function */
71  CPlApplet = (APPLET_PROC)GetProcAddress(hConsoleApplet, "CPlApplet");
72  if (CPlApplet == NULL)
73  {
74  DPRINT1("Error: console.dll misses CPlApplet export\n");
76  goto Quit;
77  }
78 
79  /* Initialize the applet */
80  if (CPlApplet(NULL, CPL_INIT, 0, 0) == FALSE)
81  {
82  DPRINT1("Error: failed to initialize console.dll\n");
84  goto Quit;
85  }
86 
87  /* Check the count */
88  if (CPlApplet(NULL, CPL_GETCOUNT, 0, 0) != 1)
89  {
90  DPRINT1("Error: console.dll returned unexpected CPL count\n");
92  goto Quit;
93  }
94 
95  /*
96  * Start the applet. For Windows compatibility purposes we need
97  * to pass the client shared section handle (lpThreadParameter)
98  * via the hWnd parameter of the CPlApplet function.
99  */
100  CPlApplet((HWND)lpThreadParameter, CPL_DBLCLK, 0, 0);
101 
102  /* We have finished */
103  CPlApplet(NULL, CPL_EXIT, 0, 0);
104 
105 Quit:
106  if (hConsoleApplet) FreeLibrary(hConsoleApplet);
107  AlreadyDisplayingProps = FALSE;
108  return Status;
109 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
LONG(APIENTRY * APPLET_PROC)(HWND, UINT, LPARAM, LPARAM)
Definition: cpl.h:23
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN ConsoleInitialized
Definition: init.c:25
#define CPL_DBLCLK
Definition: cpl.h:16
unsigned int BOOL
Definition: ntddk_ex.h:94
#define LoadLibraryW(x)
Definition: compat.h:412
smooth NULL
Definition: ftsmooth.c:416
#define FreeLibrary(x)
Definition: compat.h:413
#define CPL_EXIT
Definition: cpl.h:18
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
#define CPL_INIT
Definition: cpl.h:12
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2312
_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 DPRINT1
Definition: precomp.h:8
#define GetProcAddress(x, y)
Definition: compat.h:418
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define CPL_GETCOUNT
Definition: cpl.h:13
struct CPlApplet CPlApplet

Referenced by AllocConsole(), AttachConsole(), and ConDllInitialize().

◆ SetConsoleHandleInformation()

BOOL WINAPI SetConsoleHandleInformation ( IN HANDLE  hHandle,
IN DWORD  dwMask,
IN DWORD  dwFlags 
)

Definition at line 495 of file console.c.

498 {
499  CONSOLE_API_MESSAGE ApiMessage;
500  PCONSOLE_SETHANDLEINFO SetHandleInfoRequest = &ApiMessage.Data.SetHandleInfoRequest;
501 
502  SetHandleInfoRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
503  SetHandleInfoRequest->Handle = hHandle;
504  SetHandleInfoRequest->Mask = dwMask;
505  SetHandleInfoRequest->Flags = dwFlags;
506 
508  NULL,
510  sizeof(*SetHandleInfoRequest));
511  if (!NT_SUCCESS(ApiMessage.Status))
512  {
513  BaseSetLastNTError(ApiMessage.Status);
514  return FALSE;
515  }
516 
517  return TRUE;
518 }
CONSOLE_SETHANDLEINFO SetHandleInfoRequest
Definition: conmsg.h:917
#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
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 NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define NtCurrentPeb()
Definition: FLS.c:20
union _CONSOLE_API_MESSAGE::@3413 Data
#define CONSRV_SERVERDLL_INDEX
Definition: conmsg.h:15

Referenced by SetHandleInformation().

◆ SetUpAppName()

VOID SetUpAppName ( IN BOOLEAN  CaptureStrings,
IN OUT LPDWORD  CurDirLength,
IN OUT LPWSTR CurDir,
IN OUT LPDWORD  AppNameLength,
IN OUT LPWSTR AppName 
)

Definition at line 264 of file console.c.

269 {
270  DWORD Length;
271 
272  /* Retrieve the needed buffer size */
273  Length = (StartDirLength + 1) * sizeof(WCHAR);
274  if (*CurDirLength > 0) Length = min(Length, *CurDirLength);
275  *CurDirLength = Length;
276 
277  /* Capture the data if needed, or, return a pointer to it */
278  if (CaptureStrings)
279  {
280  /*
281  * Length is always >= sizeof(WCHAR). Copy everything but the
282  * possible trailing NULL character, and then NULL-terminate.
283  */
284  Length -= sizeof(WCHAR);
286  (*CurDir)[Length / sizeof(WCHAR)] = UNICODE_NULL;
287  }
288  else
289  {
290  *CurDir = StartDirBuffer;
291  }
292 
293  /* Retrieve the needed buffer size */
294  Length = (ExeNameLength + 1) * sizeof(WCHAR);
295  if (*AppNameLength > 0) Length = min(Length, *AppNameLength);
296  *AppNameLength = Length;
297 
298  /* Capture the data if needed, or, return a pointer to it */
299  if (CaptureStrings)
300  {
301  /*
302  * Length is always >= sizeof(WCHAR). Copy everything but the
303  * possible trailing NULL character, and then NULL-terminate.
304  */
305  Length -= sizeof(WCHAR);
307  (*AppName)[Length / sizeof(WCHAR)] = UNICODE_NULL;
308  }
309  else
310  {
312  }
313 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
static WCHAR ExeNameBuffer[EXENAME_LENGTH]
Definition: console.c:43
static CHAR AppName[MAX_PATH]
Definition: dem.c:252
#define UNICODE_NULL
static USHORT ExeNameLength
Definition: console.c:44
static USHORT StartDirLength
Definition: console.c:46
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static WCHAR StartDirBuffer[MAX_PATH+1]
Definition: console.c:45
#define min(a, b)
Definition: monoChain.cc:55

Referenced by AllocConsole(), and ConDllInitialize().

◆ SetUpConsoleInfo()

VOID SetUpConsoleInfo ( IN BOOLEAN  CaptureTitle,
IN OUT LPDWORD  pTitleLength,
IN OUT LPWSTR *lpTitle  OPTIONAL,
IN OUT LPDWORD  pDesktopLength,
IN OUT LPWSTR *lpDesktop  OPTIONAL,
IN OUT PCONSOLE_START_INFO  ConsoleStartInfo 
)

Definition at line 134 of file init.c.

140 {
142  DWORD Length;
143 
144  /* Initialize the fields */
145 
146  ConsoleStartInfo->IconIndex = 0;
147  ConsoleStartInfo->hIcon = NULL;
148  ConsoleStartInfo->hIconSm = NULL;
149  ConsoleStartInfo->dwStartupFlags = Parameters->WindowFlags;
150  ConsoleStartInfo->nFont = 0;
151  ConsoleStartInfo->nInputBufferSize = 0;
152  ConsoleStartInfo->uCodePage = GetOEMCP();
153 
154  if (lpTitle)
155  {
156  LPWSTR Title;
157 
158  /* If we don't have any title, use the default one */
159  if (Parameters->WindowTitle.Buffer == NULL)
160  {
162  Length = lstrlenW(DefaultConsoleTitle) * sizeof(WCHAR); // sizeof(DefaultConsoleTitle);
163  }
164  else
165  {
166  Title = Parameters->WindowTitle.Buffer;
167  Length = Parameters->WindowTitle.Length;
168  }
169 
170  /* Retrieve the needed buffer size */
171  Length += sizeof(WCHAR);
172  if (*pTitleLength > 0) Length = min(Length, *pTitleLength);
173  *pTitleLength = Length;
174 
175  /* Capture the data if needed, or, return a pointer to it */
176  if (CaptureTitle)
177  {
178  /*
179  * Length is always >= sizeof(WCHAR). Copy everything but the
180  * possible trailing NULL character, and then NULL-terminate.
181  */
182  Length -= sizeof(WCHAR);
184  (*lpTitle)[Length / sizeof(WCHAR)] = UNICODE_NULL;
185  }
186  else
187  {
188  *lpTitle = Title;
189  }
190  }
191  else
192  {
193  *pTitleLength = 0;
194  }
195 
196  if (lpDesktop && Parameters->DesktopInfo.Buffer && *Parameters->DesktopInfo.Buffer)
197  {
198  /* Retrieve the needed buffer size */
199  Length = Parameters->DesktopInfo.Length + sizeof(WCHAR);
200  if (*pDesktopLength > 0) Length = min(Length, *pDesktopLength);
201  *pDesktopLength = Length;
202 
203  /* Return a pointer to the data */
204  *lpDesktop = Parameters->DesktopInfo.Buffer;
205  }
206  else
207  {
208  *pDesktopLength = 0;
209  if (lpDesktop) *lpDesktop = NULL;
210  }
211 
212  if (Parameters->WindowFlags & STARTF_USEFILLATTRIBUTE)
213  {
214  ConsoleStartInfo->wFillAttribute = (WORD)Parameters->FillAttribute;
215  }
216  if (Parameters->WindowFlags & STARTF_USECOUNTCHARS)
217  {
218  ConsoleStartInfo->dwScreenBufferSize.X = (SHORT)Parameters->CountCharsX;
219  ConsoleStartInfo->dwScreenBufferSize.Y = (SHORT)Parameters->CountCharsY;
220  }
221  if (Parameters->WindowFlags & STARTF_USESHOWWINDOW)
222  {
223  ConsoleStartInfo->wShowWindow = (WORD)Parameters->ShowWindowFlags;
224  }
225  if (Parameters->WindowFlags & STARTF_USEPOSITION)
226  {
227  ConsoleStartInfo->dwWindowOrigin.X = (SHORT)Parameters->StartingX;
228  ConsoleStartInfo->dwWindowOrigin.Y = (SHORT)Parameters->StartingY;
229  }
230  if (Parameters->WindowFlags & STARTF_USESIZE)
231  {
232  ConsoleStartInfo->dwWindowSize.X = (SHORT)Parameters->CountX;
233  ConsoleStartInfo->dwWindowSize.Y = (SHORT)Parameters->CountY;
234  }
235 
236  /* Get shell information (ShellInfo.Buffer is NULL-terminated) */
237  if (Parameters->ShellInfo.Buffer != NULL)
238  {
239  ConsoleStartInfo->IconIndex = ParseShellInfo(Parameters->ShellInfo.Buffer, L"dde.");
240 
241  if ((Parameters->WindowFlags & STARTF_USEHOTKEY) == 0)
242  ConsoleStartInfo->dwHotKey = ParseShellInfo(Parameters->ShellInfo.Buffer, L"hotkey.");
243  else
244  ConsoleStartInfo->dwHotKey = HandleToUlong(Parameters->StandardInput);
245  }
246 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define HandleToUlong(h)
Definition: basetsd.h:79
#define STARTF_USEFILLATTRIBUTE
Definition: winbase.h:476
#define STARTF_USEPOSITION
Definition: winbase.h:474
#define lstrlenW
Definition: compat.h:415
static INT ParseShellInfo(LPCWSTR lpszShellInfo, LPCWSTR lpszKeyword)
Definition: init.c:113
#define UNICODE_NULL
short SHORT
Definition: pedump.c:59
smooth NULL
Definition: ftsmooth.c:416
#define STARTF_USESHOWWINDOW
Definition: winbase.h:472
static const WCHAR Title[]
Definition: oid.c:1259
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
static const WCHAR L[]
Definition: oid.c:1250
static const PWSTR DefaultConsoleTitle
Definition: init.c:28
#define STARTF_USECOUNTCHARS
Definition: winbase.h:475
#define NtCurrentPeb()
Definition: FLS.c:20
#define min(a, b)
Definition: monoChain.cc:55
#define STARTF_USESIZE
Definition: winbase.h:473
TCHAR lpTitle[80]
Definition: ctm.c:69
WCHAR * LPWSTR
Definition: xmlstorage.h:184
UINT WINAPI GetOEMCP(VOID)
Definition: nls.c:2195

Referenced by AllocConsole(), AttachConsole(), and ConDllInitialize().

◆ SetUpHandles()

VOID SetUpHandles ( IN PCONSOLE_START_INFO  ConsoleStartInfo)

Definition at line 250 of file init.c.

251 {
253 
254  if (ConsoleStartInfo->dwStartupFlags & STARTF_USEHOTKEY)
255  {
256  Parameters->WindowFlags &= ~STARTF_USEHOTKEY;
257  }
258  if (ConsoleStartInfo->dwStartupFlags & STARTF_SHELLPRIVATE)
259  {
260  Parameters->WindowFlags &= ~STARTF_SHELLPRIVATE;
261  }
262 
263  /* We got the handles, let's set them */
264  Parameters->ConsoleHandle = ConsoleStartInfo->ConsoleHandle;
265 
266  if ((ConsoleStartInfo->dwStartupFlags & STARTF_USESTDHANDLES) == 0)
267  {
268  Parameters->StandardInput = ConsoleStartInfo->InputHandle;
269  Parameters->StandardOutput = ConsoleStartInfo->OutputHandle;
270  Parameters->StandardError = ConsoleStartInfo->ErrorHandle;
271  }
272 }
#define STARTF_SHELLPRIVATE
Definition: kernel32.h:60
#define STARTF_USESTDHANDLES
Definition: winbase.h:480
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
#define NtCurrentPeb()
Definition: FLS.c:20

Referenced by AllocConsole(), AttachConsole(), and ConDllInitialize().

◆ TranslateStdHandle()

HANDLE TranslateStdHandle ( HANDLE  hHandle)

◆ VerifyConsoleIoHandle()

BOOL WINAPI VerifyConsoleIoHandle ( HANDLE  Handle)

Definition at line 1110 of file console.c.

1111 {
1112  CONSOLE_API_MESSAGE ApiMessage;
1113  PCONSOLE_VERIFYHANDLE VerifyHandleRequest = &ApiMessage.Data.VerifyHandleRequest;
1114 
1115  VerifyHandleRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
1116  VerifyHandleRequest->Handle = hIoHandle;
1117  VerifyHandleRequest->IsValid = FALSE;
1118 
1119  /* If the process is not attached to a console, return invalid handle */
1120  if (VerifyHandleRequest->ConsoleHandle == NULL) return FALSE;
1121 
1123  NULL,
1125  sizeof(*VerifyHandleRequest));
1126  if (!NT_SUCCESS(ApiMessage.Status))
1127  {
1128  BaseSetLastNTError(ApiMessage.Status);
1129  return FALSE;
1130  }
1131 
1132  return VerifyHandleRequest->IsValid;
1133 }
CONSOLE_VERIFYHANDLE VerifyHandleRequest
Definition: conmsg.h:914
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
HANDLE ConsoleHandle
Definition: conmsg.h:633
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 NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NtCurrentPeb()
Definition: FLS.c:20
union _CONSOLE_API_MESSAGE::@3413 Data
#define CONSRV_SERVERDLL_INDEX
Definition: conmsg.h:15

Referenced by GetFileType(), init_function_pointers(), RegisterWaitForSingleObject(), RegisterWaitForSingleObjectEx(), SignalObjectAndWait(), WaitForMultipleObjectsEx(), and WaitForSingleObjectEx().