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

Go to the source code of this file.

Functions

VOID NTAPI ConDrvInitConsoleSupport (VOID)
 
NTSTATUS NTAPI ConDrvInitConsole (OUT PCONSOLE *NewConsole, IN PCONSOLE_INFO ConsoleInfo)
 
NTSTATUS NTAPI ConDrvAttachTerminal (IN PCONSOLE Console, IN PTERMINAL Terminal)
 
NTSTATUS NTAPI ConDrvDetachTerminal (IN PCONSOLE Console)
 
VOID NTAPI ConDrvDeleteConsole (IN PCONSOLE Console)
 
BOOLEAN NTAPI ConDrvValidateConsoleState (IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState)
 
BOOLEAN NTAPI ConDrvValidateConsoleUnsafe (IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
 

Function Documentation

◆ ConDrvAttachTerminal()

NTSTATUS NTAPI ConDrvAttachTerminal ( IN PCONSOLE  Console,
IN PTERMINAL  Terminal 
)

Definition at line 271 of file console.c.

273 {
275 
276  if (Console == NULL || Terminal == NULL)
278 
279  /* FIXME: Lock the console before ?? */
280 
281  /*
282  * Attach the terminal to the console. Use now the TermIFace of the console,
283  * and not the user-defined temporary Terminal pointer.
284  */
285  Console->TermIFace = *Terminal;
286  Console->TermIFace.Console = Console;
287 
288  /* Initialize the terminal AFTER having attached it to the console */
289  DPRINT("Finish initialization of terminal\n");
290  Status = Console->TermIFace.Vtbl->InitTerminal(&Console->TermIFace, Console);
291  if (!NT_SUCCESS(Status))
292  {
293  DPRINT1("Terminal initialization failed, Status = 0x%08lx\n", Status);
294 
295  /* We failed, detach the terminal from the console */
296  Terminal->Console = NULL; // For the caller
298  return Status;
299  }
300 
301  /* Copy buffer contents to screen */
302  // Terminal.Draw();
303 
304  DPRINT("Terminal initialization done\n");
305  return STATUS_SUCCESS;
306 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID ResetTerminal(IN PCONSOLE Console)
Definition: dummyterm.c:156
Status
Definition: gdiplustypes.h:24
CConsole Console
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by ConSrvInitConsole().

◆ ConDrvDeleteConsole()

VOID NTAPI ConDrvDeleteConsole ( IN PCONSOLE  Console)

Definition at line 329 of file console.c.

330 {
331  DPRINT("ConDrvDeleteConsole(0x%p)\n", Console);
332 
333  /*
334  * Forbid validation of any console by other threads
335  * during the deletion of this console.
336  */
338 
339  /*
340  * If the console is already being destroyed, i.e. not running
341  * or finishing to be initialized, just return.
342  */
345  {
346  /* Unlock the console list and return */
348  return;
349  }
350 
351  /*
352  * We are about to be destroyed. Signal it to other people
353  * so that they can terminate what they are doing, and that
354  * they cannot longer validate the console.
355  */
356  Console->State = CONSOLE_TERMINATING;
357 
358  /*
359  * Allow other threads to finish their job: basically, unlock
360  * all other calls to EnterCriticalSection(&Console->Lock); by
361  * ConDrvValidateConsoleUnsafe functions so that they just see
362  * that we are not in CONSOLE_RUNNING state anymore, or unlock
363  * other concurrent calls to ConDrvDeleteConsole so that they
364  * can see that we are in fact already deleting the console.
365  */
368 
369  /* Deregister the terminal */
370  DPRINT("Deregister terminal\n");
372  DPRINT("Terminal deregistered\n");
373 
374  /***
375  * Check that the console is in terminating state before continuing
376  * (the cleanup code must not change the state of the console...
377  * ...unless to cancel console deletion ?).
378  ***/
379 
381 
383  {
385  return;
386  }
387 
388  /* We are now in destruction */
390 
391  /* We really delete the console. Reset the count to be sure. */
392  Console->ReferenceCount = 0;
393 
394  /* Remove the console from the list */
396 
397  /* Delete the last screen buffer */
398  ConDrvDeleteScreenBuffer(Console->ActiveBuffer);
399  Console->ActiveBuffer = NULL;
400  if (!IsListEmpty(&Console->BufferList))
401  {
402  /***ConDrvUnlockConsoleList();***/
403  ASSERTMSG("BUGBUGBUG!! screen buffer list not empty\n", FALSE);
404  }
405 
406  /* Deinitialize the input buffer */
408 
409  if (Console->UnpauseEvent) CloseHandle(Console->UnpauseEvent);
410 
411  DPRINT("ConDrvDeleteConsole - Unlocking\n");
413  DPRINT("ConDrvDeleteConsole - Destroying lock\n");
415  DPRINT("ConDrvDeleteConsole - Lock destroyed ; freeing console\n");
416 
418  DPRINT("ConDrvDeleteConsole - Console destroyed\n");
419 
420  /* Unlock the console list and return */
422 }
#define ConDrvUnlockConsoleList()
Definition: console.c:35
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
#define ConDrvLockConsoleListExclusive()
Definition: console.c:29
VOID NTAPI ConDrvDeleteScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:123
NTSTATUS NTAPI ConDrvDetachTerminal(IN PCONSOLE Console)
Definition: console.c:309
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
VOID NTAPI ConDrvDeinitInputBuffer(IN PCONSOLE Console)
Definition: coninput.c:217
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
BOOLEAN NTAPI ConDrvValidateConsoleUnsafe(IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState, IN BOOLEAN LockConsole)
Definition: console.c:120
CConsole Console
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
static NTSTATUS RemoveConsole(IN PCONSOLE Console)
Definition: console.c:61
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

◆ ConDrvDetachTerminal()

NTSTATUS NTAPI ConDrvDetachTerminal ( IN PCONSOLE  Console)

Definition at line 309 of file console.c.

310 {
311  if (Console == NULL) return STATUS_INVALID_PARAMETER;
312 
313  /* FIXME: Lock the console before ?? */
314 
315  /* Deinitialize the terminal BEFORE detaching it from the console */
316  Console->TermIFace.Vtbl->DeinitTerminal(&Console->TermIFace/*, Console*/);
317 
318  /*
319  * Detach the terminal from the console:
320  * reinitialize the terminal interface.
321  */
323 
324  DPRINT("Terminal unregistered\n");
325  return STATUS_SUCCESS;
326 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
VOID ResetTerminal(IN PCONSOLE Console)
Definition: dummyterm.c:156
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by ConDrvDeleteConsole().

◆ ConDrvInitConsole()

NTSTATUS NTAPI ConDrvInitConsole ( OUT PCONSOLE NewConsole,
IN PCONSOLE_INFO  ConsoleInfo 
)

Definition at line 163 of file console.c.

165 {
167  // CONSOLE_INFO CapturedConsoleInfo;
170  PCONSOLE_SCREEN_BUFFER NewBuffer;
171 
172  if (NewConsole == NULL || ConsoleInfo == NULL)
174 
175  *NewConsole = NULL;
176 
177  /*
178  * Allocate a new console
179  */
181  if (NULL == Console)
182  {
183  DPRINT1("Not enough memory for console creation.\n");
184  return STATUS_NO_MEMORY;
185  }
186 
187  /*
188  * Fix the screen buffer size if needed. The rule is:
189  * ScreenBufferSize >= ConsoleSize
190  */
191  if (ConsoleInfo->ScreenBufferSize.X < ConsoleInfo->ConsoleSize.X)
192  ConsoleInfo->ScreenBufferSize.X = ConsoleInfo->ConsoleSize.X;
193  if (ConsoleInfo->ScreenBufferSize.Y < ConsoleInfo->ConsoleSize.Y)
194  ConsoleInfo->ScreenBufferSize.Y = ConsoleInfo->ConsoleSize.Y;
195 
196  /*
197  * Initialize the console
198  */
199  Console->State = CONSOLE_INITIALIZING;
200  Console->ReferenceCount = 0;
202 
203  /* Initialize the terminal interface */
205 
206  Console->ConsoleSize = ConsoleInfo->ConsoleSize;
207  Console->FixedSize = FALSE; // Value by default; is reseted by the terminals if needed.
208 
209  /* Initialize the input buffer */
210  Status = ConDrvInitInputBuffer(Console, 0 /* ConsoleInfo->InputBufferSize */);
211  if (!NT_SUCCESS(Status))
212  {
213  DPRINT1("ConDrvInitInputBuffer: failed, Status = 0x%08lx\n", Status);
216  return Status;
217  }
218 
219  /* Set-up the code page */
220  if (IsValidCodePage(ConsoleInfo->CodePage))
221  Console->InputCodePage = Console->OutputCodePage = ConsoleInfo->CodePage;
222 
223  Console->IsCJK = IsCJKCodePage(Console->OutputCodePage);
224 
225  /* Initialize a new text-mode screen buffer with default settings */
226  ScreenBufferInfo.ScreenBufferSize = ConsoleInfo->ScreenBufferSize;
227  ScreenBufferInfo.ScreenAttrib = ConsoleInfo->ScreenAttrib;
228  ScreenBufferInfo.PopupAttrib = ConsoleInfo->PopupAttrib;
229  ScreenBufferInfo.IsCursorVisible = TRUE;
230  ScreenBufferInfo.CursorSize = ConsoleInfo->CursorSize;
231 
232  InitializeListHead(&Console->BufferList);
233  Status = ConDrvCreateScreenBuffer(&NewBuffer,
234  Console,
235  NULL,
238  if (!NT_SUCCESS(Status))
239  {
240  DPRINT1("ConDrvCreateScreenBuffer: failed, Status = 0x%08lx\n", Status);
244  return Status;
245  }
246  /* Make the new screen buffer active */
247  Console->ActiveBuffer = NewBuffer;
248  Console->UnpauseEvent = NULL;
249 
250  DPRINT("Console initialized\n");
251 
252  /* All went right, so add the console to the list */
254  if (!NT_SUCCESS(Status))
255  {
256  /* Fail */
258  return Status;
259  }
260 
261  /* The initialization is finished */
262  DPRINT("Change state\n");
263  Console->State = CONSOLE_RUNNING;
264 
265  /* Return the newly created console to the caller and a success code too */
266  *NewConsole = Console;
267  return STATUS_SUCCESS;
268 }
#define TRUE
Definition: types.h:120
CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo
Definition: notevil.c:38
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
NTSTATUS ConDrvCreateScreenBuffer(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle OPTIONAL, IN ULONG BufferType, IN PVOID ScreenBufferInfo)
Definition: conoutput.c:79
#define IsCJKCodePage(CodePage)
Definition: font.h:23
VOID NTAPI ConDrvDeleteConsole(IN PCONSOLE Console)
Definition: console.c:329
VOID NTAPI ConDrvDeinitInputBuffer(IN PCONSOLE Console)
Definition: coninput.c:217
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
static NTSTATUS ConDrvInsertConsole(IN PCONSOLE Console)
Definition: console.c:40
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID ResetTerminal(IN PCONSOLE Console)
Definition: dummyterm.c:156
Status
Definition: gdiplustypes.h:24
BOOL WINAPI IsValidCodePage(UINT CodePage)
Definition: nls.c:1479
NTSTATUS NTAPI ConDrvInitInputBuffer(IN PCONSOLE Console, IN ULONG InputBufferSize)
Definition: coninput.c:189
#define CONSOLE_TEXTMODE_BUFFER
Definition: wincon.h:59
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo
Definition: video.c:47
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
CConsole Console
#define DPRINT1
Definition: precomp.h:8
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by ConSrvInitConsole().

◆ ConDrvInitConsoleSupport()

VOID NTAPI ConDrvInitConsoleSupport ( VOID  )

Definition at line 150 of file console.c.

151 {
152  DPRINT("CONSRV: ConDrvInitConsoleSupport()\n");
153 
154  /* Initialize the console list and its lock */
157 }
static RTL_RESOURCE ListLock
Definition: console.c:27
void DPRINT(...)
Definition: polytest.cpp:61
NTSYSAPI VOID NTAPI RtlInitializeResource(_In_ PRTL_RESOURCE Resource)
static LIST_ENTRY ConDrvConsoleList
Definition: console.c:26
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944

◆ ConDrvValidateConsoleState()

BOOLEAN NTAPI ConDrvValidateConsoleState ( IN PCONSOLE  Console,
IN CONSOLE_STATE  ExpectedState 
)

Definition at line 108 of file console.c.

110 {
111  // if (!Console) return FALSE;
112 
113  /* The console must be locked */
114  // ASSERT(Console_locked);
115 
116  return (Console->State == ExpectedState);
117 }
CConsole Console

◆ ConDrvValidateConsoleUnsafe()

BOOLEAN NTAPI ConDrvValidateConsoleUnsafe ( IN PCONSOLE  Console,
IN CONSOLE_STATE  ExpectedState,
IN BOOLEAN  LockConsole 
)

Definition at line 120 of file console.c.

123 {
124  if (!Console) return FALSE;
125 
126  /*
127  * Lock the console to forbid possible console's state changes
128  * (which must be done when the console is already locked).
129  * If we don't want to lock it, it's because the lock is already
130  * held. So there must be no problems.
131  */
132  if (LockConsole) EnterCriticalSection(&Console->Lock);
133 
134  // ASSERT(Console_locked);
135 
136  /* Check whether the console's state is what we expect */
137  if (!ConDrvValidateConsoleState(Console, ExpectedState))
138  {
139  if (LockConsole) LeaveCriticalSection(&Console->Lock);
140  return FALSE;
141  }
142 
143  return TRUE;
144 }
BOOLEAN NTAPI ConDrvValidateConsoleState(IN PCONSOLE Console, IN CONSOLE_STATE ExpectedState)
Definition: console.c:108
#define TRUE
Definition: types.h:120
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
CConsole Console
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)