ReactOS  0.4.15-dev-439-g292f67a
conoutput.c File Reference
#include <consrv.h>
#include <debug.h>
Include dependency graph for conoutput.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS TEXTMODE_BUFFER_Initialize (OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle, IN PTEXTMODE_BUFFER_INFO TextModeInfo)
 
NTSTATUS GRAPHICS_BUFFER_Initialize (OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle, IN PGRAPHICS_BUFFER_INFO GraphicsInfo)
 
VOID TEXTMODE_BUFFER_Destroy (IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
 
VOID GRAPHICS_BUFFER_Destroy (IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
 
NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize (OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN CONSOLE_IO_OBJECT_TYPE Type, IN SIZE_T Size)
 
VOID CONSOLE_SCREEN_BUFFER_Destroy (IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
 
NTSTATUS ConDrvCreateScreenBuffer (OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle OPTIONAL, IN ULONG BufferType, IN PVOID ScreenBufferInfo)
 
static VOID ConioSetActiveScreenBuffer (PCONSOLE_SCREEN_BUFFER Buffer)
 
VOID NTAPI ConDrvDeleteScreenBuffer (PCONSOLE_SCREEN_BUFFER Buffer)
 
NTSTATUS NTAPI ConDrvSetConsoleActiveScreenBuffer (IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER Buffer)
 
PCONSOLE_SCREEN_BUFFER ConDrvGetActiveScreenBuffer (IN PCONSOLE Console)
 
NTSTATUS NTAPI ConDrvInvalidateBitMapRect (IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER Buffer, IN PSMALL_RECT Region)
 
NTSTATUS NTAPI ConDrvSetConsolePalette (IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER Buffer, IN HPALETTE PaletteHandle, IN UINT PaletteUsage)
 
NTSTATUS NTAPI ConDrvGetConsoleCursorInfo (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, OUT PCONSOLE_CURSOR_INFO CursorInfo)
 
NTSTATUS NTAPI ConDrvSetConsoleCursorInfo (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN PCONSOLE_CURSOR_INFO CursorInfo)
 
NTSTATUS NTAPI ConDrvSetConsoleCursorPosition (IN PCONSOLE Console, IN PTEXTMODE_SCREEN_BUFFER Buffer, IN PCOORD Position)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file conoutput.c.

Function Documentation

◆ ConDrvCreateScreenBuffer()

NTSTATUS ConDrvCreateScreenBuffer ( OUT PCONSOLE_SCREEN_BUFFER Buffer,
IN PCONSOLE  Console,
IN HANDLE ProcessHandle  OPTIONAL,
IN ULONG  BufferType,
IN PVOID  ScreenBufferInfo 
)

Definition at line 85 of file conoutput.c.

90 {
92 
93  if ( Console == NULL || Buffer == NULL ||
94  (BufferType != CONSOLE_TEXTMODE_BUFFER && BufferType != CONSOLE_GRAPHICS_BUFFER) )
95  {
97  }
98 
99  /* Use the current process if ProcessHandle is NULL */
100  if (ProcessHandle == NULL)
102 
103  switch (BufferType)
104  {
108  break;
109 
113  break;
114 
115  default:
116  /* Never ever go there!! */
117  ASSERT(FALSE);
118  }
119 
120  /* Insert the newly created screen buffer into the list, if succeeded */
121  if (NT_SUCCESS(Status)) InsertHeadList(&Console->BufferList, &(*Buffer)->ListEntry);
122 
123  return Status;
124 }
CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo
Definition: notevil.c:38
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS TEXTMODE_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle, IN PTEXTMODE_BUFFER_INFO TextModeInfo)
Definition: text.c:54
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS GRAPHICS_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN HANDLE ProcessHandle, IN PGRAPHICS_BUFFER_INFO GraphicsInfo)
Definition: graphics.c:33
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
#define CONSOLE_TEXTMODE_BUFFER
Definition: wincon.h:62
#define CONSOLE_GRAPHICS_BUFFER
Definition: wincon.h:63
CConsole Console
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403

Referenced by CON_API(), and ConDrvInitConsole().

◆ ConDrvDeleteScreenBuffer()

VOID NTAPI ConDrvDeleteScreenBuffer ( PCONSOLE_SCREEN_BUFFER  Buffer)

Definition at line 130 of file conoutput.c.

131 {
132  PCONSOLE Console = Buffer->Header.Console;
133  PCONSOLE_SCREEN_BUFFER NewBuffer;
134 
135  /*
136  * We should notify temporarily the frontend because we are susceptible
137  * to delete the screen buffer it is using (which may be different from
138  * the active screen buffer in some cases), and because, if it actually
139  * uses the active screen buffer, we are going to nullify its pointer to
140  * change it.
141  */
143 
144  RemoveEntryList(&Buffer->ListEntry);
145  if (Buffer == Console->ActiveBuffer)
146  {
147  /* Delete active buffer; switch to most recently created */
148  if (!IsListEmpty(&Console->BufferList))
149  {
150  NewBuffer = CONTAINING_RECORD(Console->BufferList.Flink,
152  ListEntry);
153 
154  /* Tie console to new buffer and signal the change to the frontend */
155  ConioSetActiveScreenBuffer(NewBuffer);
156  }
157  else
158  {
159  Console->ActiveBuffer = NULL;
160  // InterlockedExchangePointer(&Console->ActiveBuffer, NULL);
161  }
162  }
163 
165 }
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
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
static VOID ConioSetActiveScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:168
CConsole Console
VOID CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:55
#define TermReleaseScreenBuffer(Console, ScreenBuffer)
Definition: term.h:32

Referenced by CON_API(), ConDrvDeleteConsole(), ConDrvSetConsoleActiveScreenBuffer(), and ConSrvCloseHandle().

◆ ConDrvGetActiveScreenBuffer()

PCONSOLE_SCREEN_BUFFER ConDrvGetActiveScreenBuffer ( IN PCONSOLE  Console)

Definition at line 201 of file conoutput.c.

202 {
203  return (Console ? Console->ActiveBuffer : NULL);
204 }
smooth NULL
Definition: ftsmooth.c:416
CConsole Console

Referenced by GuiSetActiveScreenBuffer().

◆ ConDrvGetConsoleCursorInfo()

NTSTATUS NTAPI ConDrvGetConsoleCursorInfo ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
OUT PCONSOLE_CURSOR_INFO  CursorInfo 
)

Definition at line 270 of file conoutput.c.

273 {
274  if (Console == NULL || Buffer == NULL || CursorInfo == NULL)
276 
277  /* Validity check */
278  ASSERT(Console == Buffer->Header.Console);
279 
280  *CursorInfo = Buffer->CursorInfo;
281  // CursorInfo->bVisible = Buffer->CursorInfo.bVisible;
282  // CursorInfo->dwSize = Buffer->CursorInfo.dwSize;
283 
284  return STATUS_SUCCESS;
285 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CON_API().

◆ ConDrvInvalidateBitMapRect()

NTSTATUS NTAPI ConDrvInvalidateBitMapRect ( IN PCONSOLE  Console,
IN PCONSOLE_SCREEN_BUFFER  Buffer,
IN PSMALL_RECT  Region 
)

Definition at line 209 of file conoutput.c.

212 {
213  if (Console == NULL || Buffer == NULL || Region == NULL)
215 
216  /* Validity check */
217  ASSERT(Console == Buffer->Header.Console);
218 
219  /* If the output buffer is the current one, redraw the correct portion of the screen */
220  if (Buffer == Console->ActiveBuffer) TermDrawRegion(Console, Region);
221 
222  return STATUS_SUCCESS;
223 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define TermDrawRegion(Console, Region)
Definition: term.h:22
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CON_API().

◆ ConDrvSetConsoleActiveScreenBuffer()

NTSTATUS NTAPI ConDrvSetConsoleActiveScreenBuffer ( IN PCONSOLE  Console,
IN PCONSOLE_SCREEN_BUFFER  Buffer 
)

Definition at line 177 of file conoutput.c.

179 {
180  if (Console == NULL || Buffer == NULL)
182 
183  /* Validity check */
184  ASSERT(Console == Buffer->Header.Console);
185 
186  if (Buffer == Console->ActiveBuffer) return STATUS_SUCCESS;
187 
188  /* If old buffer has no handles, it's now unreferenced */
189  if (Console->ActiveBuffer->Header.ReferenceCount == 0)
190  {
191  ConDrvDeleteScreenBuffer(Console->ActiveBuffer);
192  }
193 
194  /* Tie console to new buffer and signal the change to the frontend */
196 
197  return STATUS_SUCCESS;
198 }
VOID NTAPI ConDrvDeleteScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:130
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
static VOID ConioSetActiveScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:168
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CON_API().

◆ ConDrvSetConsoleCursorInfo()

NTSTATUS NTAPI ConDrvSetConsoleCursorInfo ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN PCONSOLE_CURSOR_INFO  CursorInfo 
)

Definition at line 288 of file conoutput.c.

291 {
292  ULONG Size;
293  BOOLEAN Visible, Success = TRUE;
294 
295  if (Console == NULL || Buffer == NULL || CursorInfo == NULL)
297 
298  /* Validity check */
299  ASSERT(Console == Buffer->Header.Console);
300 
301  Size = min(max(CursorInfo->dwSize, 1), 100);
302  Visible = CursorInfo->bVisible;
303 
304  if ( (Size != Buffer->CursorInfo.dwSize) ||
305  (Visible && !Buffer->CursorInfo.bVisible) ||
306  (!Visible && Buffer->CursorInfo.bVisible) )
307  {
308  Buffer->CursorInfo.dwSize = Size;
309  Buffer->CursorInfo.bVisible = Visible;
310 
312  }
313 
315 }
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define TermSetCursorInfo(Console, ScreenBuffer)
Definition: term.h:24
#define min(a, b)
Definition: monoChain.cc:55
CConsole Console
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CON_API().

◆ ConDrvSetConsoleCursorPosition()

NTSTATUS NTAPI ConDrvSetConsoleCursorPosition ( IN PCONSOLE  Console,
IN PTEXTMODE_SCREEN_BUFFER  Buffer,
IN PCOORD  Position 
)

Definition at line 318 of file conoutput.c.

321 {
322  SHORT OldCursorX, OldCursorY;
323 
324  if (Console == NULL || Buffer == NULL || Position == NULL)
326 
327  /* Validity check */
328  ASSERT(Console == Buffer->Header.Console);
329 
330  if ( Position->X < 0 || Position->X >= Buffer->ScreenBufferSize.X ||
331  Position->Y < 0 || Position->Y >= Buffer->ScreenBufferSize.Y )
332  {
334  }
335 
336  OldCursorX = Buffer->CursorPosition.X;
337  OldCursorY = Buffer->CursorPosition.Y;
338  Buffer->CursorPosition = *Position;
339 
340  if ( ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer) &&
341  (!TermSetScreenInfo(Console, (PCONSOLE_SCREEN_BUFFER)Buffer, OldCursorX, OldCursorY)) )
342  {
343  return STATUS_UNSUCCESSFUL;
344  }
345 
346  return STATUS_SUCCESS;
347 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
static COORD Position
Definition: mouse.c:34
#define TermSetScreenInfo(Console, ScreenBuffer, OldCursorX, OldCursorY)
Definition: term.h:26
short SHORT
Definition: pedump.c:59
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
ULONG X
Definition: bl.h:1340
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014
ULONG Y
Definition: bl.h:1341

Referenced by CON_API().

◆ ConDrvSetConsolePalette()

NTSTATUS NTAPI ConDrvSetConsolePalette ( IN PCONSOLE  Console,
IN PCONSOLE_SCREEN_BUFFER  Buffer,
IN HPALETTE  PaletteHandle,
IN UINT  PaletteUsage 
)

Definition at line 226 of file conoutput.c.

231 {
232  BOOL Success;
233 
234  /*
235  * Parameters validation
236  */
237  if (Console == NULL || Buffer == NULL)
239 
240  if ( PaletteUsage != SYSPAL_STATIC &&
241  PaletteUsage != SYSPAL_NOSTATIC &&
242  PaletteUsage != SYSPAL_NOSTATIC256 )
243  {
245  }
246 
247  /* Validity check */
248  ASSERT(Console == Buffer->Header.Console);
249 
250  /* Change the palette */
251  Success = TermSetPalette(Console, PaletteHandle, PaletteUsage);
252  if (Success)
253  {
254  /* Free the old palette handle if there was already one set */
255  if ( Buffer->PaletteHandle != NULL &&
256  Buffer->PaletteHandle != PaletteHandle )
257  {
258  DeleteObject(Buffer->PaletteHandle);
259  }
260 
261  /* Save the new palette in the screen buffer */
262  Buffer->PaletteHandle = PaletteHandle;
263  Buffer->PaletteUsage = PaletteUsage;
264  }
265 
267 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
static HPALETTE PaletteHandle
Definition: svga.c:215
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define SYSPAL_NOSTATIC256
Definition: wingdi.h:21
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define SYSPAL_STATIC
Definition: wingdi.h:925
#define TermSetPalette(Console, PaletteHandle, PaletteUsage)
Definition: term.h:36
#define SYSPAL_NOSTATIC
Definition: wingdi.h:924
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CON_API().

◆ ConioSetActiveScreenBuffer()

static VOID ConioSetActiveScreenBuffer ( PCONSOLE_SCREEN_BUFFER  Buffer)
static

Definition at line 168 of file conoutput.c.

169 {
170  PCONSOLE Console = Buffer->Header.Console;
171  Console->ActiveBuffer = Buffer;
172  // InterlockedExchangePointer(&Console->ActiveBuffer, Buffer);
174 }
#define TermSetActiveScreenBuffer(Console)
Definition: term.h:30
Definition: bufpool.h:45
CConsole Console
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by ConDrvDeleteScreenBuffer(), and ConDrvSetConsoleActiveScreenBuffer().

◆ CONSOLE_SCREEN_BUFFER_Destroy()

VOID CONSOLE_SCREEN_BUFFER_Destroy ( IN OUT PCONSOLE_SCREEN_BUFFER  Buffer)

Definition at line 55 of file conoutput.c.

56 {
57  switch (Buffer->Header.Type)
58  {
59  case TEXTMODE_BUFFER:
61  break;
62 
63  case GRAPHICS_BUFFER:
65  break;
66 
67  case SCREEN_BUFFER:
68  {
69  /* Free the palette handle */
70  if (Buffer->PaletteHandle != NULL)
71  DeleteObject(Buffer->PaletteHandle);
72 
73  /* Free the screen buffer memory */
75  break;
76  }
77 
78  default:
79  break;
80  }
81 }
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
VOID TEXTMODE_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: text.c:126
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
VOID GRAPHICS_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: graphics.c:236

Referenced by ConDrvDeleteScreenBuffer(), GRAPHICS_BUFFER_Destroy(), GRAPHICS_BUFFER_Initialize(), TEXTMODE_BUFFER_Destroy(), and TEXTMODE_BUFFER_Initialize().

◆ CONSOLE_SCREEN_BUFFER_Initialize()

NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize ( OUT PCONSOLE_SCREEN_BUFFER Buffer,
IN PCONSOLE  Console,
IN CONSOLE_IO_OBJECT_TYPE  Type,
IN SIZE_T  Size 
)

Definition at line 37 of file conoutput.c.

42 {
43  if (Buffer == NULL || Console == NULL)
45 
48 
49  /* Initialize the header with the default type */
50  ConSrvInitObject(&(*Buffer)->Header, Type /* SCREEN_BUFFER */, Console);
51  return STATUS_SUCCESS;
52 }
#define max(a, b)
Definition: svc.c:63
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
Type
Definition: Type.h:6
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
VOID ConSrvInitObject(IN OUT PCONSOLE_IO_OBJECT Object, IN CONSOLE_IO_OBJECT_TYPE Type, IN PCONSOLE Console)
Definition: handle.c:211
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by GRAPHICS_BUFFER_Initialize(), and TEXTMODE_BUFFER_Initialize().

◆ GRAPHICS_BUFFER_Destroy()

VOID GRAPHICS_BUFFER_Destroy ( IN OUT PCONSOLE_SCREEN_BUFFER  Buffer)

Definition at line 236 of file graphics.c.

237 {
239 
240  /*
241  * IMPORTANT !! Reinitialize the type so that we don't enter a recursive
242  * infinite loop when calling CONSOLE_SCREEN_BUFFER_Destroy.
243  */
244  Buffer->Header.Type = SCREEN_BUFFER;
245 
246  /*
247  * Uninitialize the graphics screen buffer
248  * in the reverse way we initialized it.
249  */
252  NtClose(Buff->hSection);
255  NtClose(Buff->Mutex);
257 
259 }
#define DUPLICATE_CLOSE_SOURCE
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3782
LPBITMAPINFO BitMapInfo
Definition: conio.h:150
VOID CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:55
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
struct _GRAPHICS_SCREEN_BUFFER * PGRAPHICS_SCREEN_BUFFER
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
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

Referenced by CONSOLE_SCREEN_BUFFER_Destroy().

◆ GRAPHICS_BUFFER_Initialize()

NTSTATUS GRAPHICS_BUFFER_Initialize ( OUT PCONSOLE_SCREEN_BUFFER Buffer,
IN PCONSOLE  Console,
IN HANDLE  ProcessHandle,
IN PGRAPHICS_BUFFER_INFO  GraphicsInfo 
)

Definition at line 33 of file graphics.c.

37 {
39  PGRAPHICS_SCREEN_BUFFER NewBuffer = NULL;
40 
41  LARGE_INTEGER SectionSize;
42  SIZE_T ViewSize = 0;
43 
44  if (Buffer == NULL || Console == NULL || GraphicsInfo == NULL)
46 
47  *Buffer = NULL;
48 
50  Console,
52  sizeof(GRAPHICS_SCREEN_BUFFER));
53  if (!NT_SUCCESS(Status)) return Status;
54 
55  /*
56  * Remember the handle to the process so that we can close or unmap
57  * correctly the allocated resources when the client releases the
58  * screen buffer.
59  */
60  NewBuffer->ClientProcess = ProcessHandle;
61 
62  /* Get information from the graphics buffer information structure */
63  NewBuffer->BitMapInfoLength = GraphicsInfo->Info.dwBitMapInfoLength;
64 
65  NewBuffer->BitMapInfo = ConsoleAllocHeap(HEAP_ZERO_MEMORY, NewBuffer->BitMapInfoLength);
66  if (NewBuffer->BitMapInfo == NULL)
67  {
70  }
71 
72  /* Adjust the bitmap height if needed (bottom-top vs. top-bottom). Use always bottom-up. */
73  if (GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight > 0)
74  GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight = -GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight;
75 
76  /* We do not use anything else than uncompressed bitmaps */
77  if (GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biCompression != BI_RGB)
78  {
79  DPRINT1("biCompression == %d != BI_RGB, fix that!\n",
80  GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biCompression);
81  GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biCompression = BI_RGB;
82  }
83 
84  RtlCopyMemory(NewBuffer->BitMapInfo,
85  GraphicsInfo->Info.lpBitMapInfo,
86  GraphicsInfo->Info.dwBitMapInfoLength);
87 
88  NewBuffer->BitMapUsage = GraphicsInfo->Info.dwUsage;
89 
90  /* Set the screen buffer size. Fight against overflows. */
91  if ( GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biWidth <= 0xFFFF &&
92  -GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight <= 0xFFFF )
93  {
94  /* Be careful about the sign of biHeight */
95  NewBuffer->ScreenBufferSize.X = (SHORT)GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biWidth ;
96  NewBuffer->ScreenBufferSize.Y = (SHORT)-GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight;
97 
98  NewBuffer->OldViewSize = NewBuffer->ViewSize =
99  NewBuffer->OldScreenBufferSize = NewBuffer->ScreenBufferSize;
100  }
101  else
102  {
104  ConsoleFreeHeap(NewBuffer->BitMapInfo);
106  goto Quit;
107  }
108 
109  /*
110  * Create a mutex to synchronize bitmap memory access
111  * between ourselves and the client.
112  */
113  Status = NtCreateMutant(&NewBuffer->Mutex, MUTANT_ALL_ACCESS, NULL, FALSE);
114  if (!NT_SUCCESS(Status))
115  {
116  DPRINT1("NtCreateMutant() failed: %lu\n", Status);
117  ConsoleFreeHeap(NewBuffer->BitMapInfo);
119  goto Quit;
120  }
121 
122  /*
123  * Duplicate the Mutex for the client. We must keep a trace of it
124  * so that we can close it when the client releases the screen buffer.
125  */
127  NewBuffer->Mutex,
129  &NewBuffer->ClientMutex,
130  0, 0, DUPLICATE_SAME_ACCESS);
131  if (!NT_SUCCESS(Status))
132  {
133  DPRINT1("NtDuplicateObject() failed: %lu\n", Status);
134  NtClose(NewBuffer->Mutex);
135  ConsoleFreeHeap(NewBuffer->BitMapInfo);
137  goto Quit;
138  }
139 
140  /*
141  * Create a memory section for the bitmap area, to share with the client.
142  */
143  SectionSize.QuadPart = NewBuffer->BitMapInfo->bmiHeader.biSizeImage;
144  Status = NtCreateSection(&NewBuffer->hSection,
146  NULL,
147  &SectionSize,
149  SEC_COMMIT,
150  NULL);
151  if (!NT_SUCCESS(Status))
152  {
153  DPRINT1("Error: Impossible to create a shared section, Status = 0x%08lx\n", Status);
154  NtDuplicateObject(ProcessHandle, NewBuffer->ClientMutex,
156  NtClose(NewBuffer->Mutex);
157  ConsoleFreeHeap(NewBuffer->BitMapInfo);
159  goto Quit;
160  }
161 
162  /*
163  * Create a view for our needs.
164  */
165  ViewSize = 0;
166  NewBuffer->BitMap = NULL;
167  Status = NtMapViewOfSection(NewBuffer->hSection,
169  (PVOID*)&NewBuffer->BitMap,
170  0,
171  0,
172  NULL,
173  &ViewSize,
174  ViewUnmap,
175  0,
177  if (!NT_SUCCESS(Status))
178  {
179  DPRINT1("Error: Impossible to map the shared section, Status = 0x%08lx\n", Status);
180  NtClose(NewBuffer->hSection);
181  NtDuplicateObject(ProcessHandle, NewBuffer->ClientMutex,
183  NtClose(NewBuffer->Mutex);
184  ConsoleFreeHeap(NewBuffer->BitMapInfo);
186  goto Quit;
187  }
188 
189  /*
190  * Create a view for the client. We must keep a trace of it so that
191  * we can unmap it when the client releases the screen buffer.
192  */
193  ViewSize = 0;
194  NewBuffer->ClientBitMap = NULL;
195  Status = NtMapViewOfSection(NewBuffer->hSection,
197  (PVOID*)&NewBuffer->ClientBitMap,
198  0,
199  0,
200  NULL,
201  &ViewSize,
202  ViewUnmap,
203  0,
205  if (!NT_SUCCESS(Status))
206  {
207  DPRINT1("Error: Impossible to map the shared section, Status = 0x%08lx\n", Status);
208  NtUnmapViewOfSection(NtCurrentProcess(), NewBuffer->BitMap);
209  NtClose(NewBuffer->hSection);
210  NtDuplicateObject(ProcessHandle, NewBuffer->ClientMutex,
212  NtClose(NewBuffer->Mutex);
213  ConsoleFreeHeap(NewBuffer->BitMapInfo);
215  goto Quit;
216  }
217 
218  NewBuffer->ViewOrigin.X = NewBuffer->ViewOrigin.Y = 0;
219 
220  NewBuffer->CursorBlinkOn = FALSE;
221  NewBuffer->ForceCursorOff = TRUE;
222  NewBuffer->CursorInfo.bVisible = FALSE;
223  NewBuffer->CursorInfo.dwSize = 0;
224  NewBuffer->CursorPosition.X = NewBuffer->CursorPosition.Y = 0;
225 
226  NewBuffer->Mode = 0;
227 
228  *Buffer = (PCONSOLE_SCREEN_BUFFER)NewBuffer;
230 
231 Quit:
232  return Status;
233 }
#define DUPLICATE_CLOSE_SOURCE
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3782
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
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
BOOLEAN CursorBlinkOn
Definition: conio.h:72
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
COORD CursorPosition
Definition: conio.h:71
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
COORD OldScreenBufferSize
Definition: conio.h:65
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define DUPLICATE_SAME_ACCESS
#define SEC_COMMIT
Definition: mmtypes.h:99
COORD ScreenBufferSize
Definition: conio.h:62
#define MUTANT_ALL_ACCESS
Definition: extypes.h:110
short SHORT
Definition: pedump.c:59
NTSTATUS NTAPI NtMapViewOfSection(IN HANDLE SectionHandle, IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits, IN SIZE_T CommitSize, IN OUT PLARGE_INTEGER SectionOffset OPTIONAL, IN OUT PSIZE_T ViewSize, IN SECTION_INHERIT InheritDisposition, IN ULONG AllocationType, IN ULONG Protect)
Definition: section.c:3554
VOID CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:55
struct _CONSOLE_SCREEN_BUFFER * PCONSOLE_SCREEN_BUFFER
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NtCurrentProcess()
Definition: nt_native.h:1657
ULONG X
Definition: bl.h:1340
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtCreateMutant(OUT PHANDLE MutantHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN BOOLEAN InitialOwner)
Definition: mutant.c:83
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN CONSOLE_IO_OBJECT_TYPE Type, IN SIZE_T Size)
Definition: conoutput.c:37
BOOLEAN ForceCursorOff
Definition: conio.h:73
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:79
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
CConsole Console
#define DPRINT1
Definition: precomp.h:8
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
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 _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
return STATUS_SUCCESS
Definition: btrfs.c:3014
CONSOLE_CURSOR_INFO CursorInfo
Definition: conio.h:75
ULONG Y
Definition: bl.h:1341
#define BI_RGB
Definition: precomp.h:47
LONGLONG QuadPart
Definition: typedefs.h:113
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by ConDrvCreateScreenBuffer().

◆ TEXTMODE_BUFFER_Destroy()

VOID TEXTMODE_BUFFER_Destroy ( IN OUT PCONSOLE_SCREEN_BUFFER  Buffer)

Definition at line 126 of file text.c.

127 {
129 
130  /*
131  * IMPORTANT !! Reinitialize the type so that we don't enter a recursive
132  * infinite loop when calling CONSOLE_SCREEN_BUFFER_Destroy.
133  */
134  Buffer->Header.Type = SCREEN_BUFFER;
135 
136  ConsoleFreeHeap(Buff->Buffer);
137 
139 }
Definition: bufpool.h:45
VOID CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:55
#define ConsoleFreeHeap(HeapBase)
Definition: heap.h:15
PCHAR_INFO Buffer
Definition: conio.h:129
struct _TEXTMODE_SCREEN_BUFFER * PTEXTMODE_SCREEN_BUFFER

Referenced by CONSOLE_SCREEN_BUFFER_Destroy().

◆ TEXTMODE_BUFFER_Initialize()

NTSTATUS TEXTMODE_BUFFER_Initialize ( OUT PCONSOLE_SCREEN_BUFFER Buffer,
IN PCONSOLE  Console,
IN HANDLE  ProcessHandle,
IN PTEXTMODE_BUFFER_INFO  TextModeInfo 
)

Definition at line 54 of file text.c.

58 {
60  PTEXTMODE_SCREEN_BUFFER NewBuffer = NULL;
61 
63 
64  if (Console == NULL || Buffer == NULL || TextModeInfo == NULL)
66 
67  if ((TextModeInfo->ScreenBufferSize.X == 0) ||
68  (TextModeInfo->ScreenBufferSize.Y == 0))
69  {
71  }
72 
73  *Buffer = NULL;
74 
76  Console,
78  sizeof(TEXTMODE_SCREEN_BUFFER));
79  if (!NT_SUCCESS(Status)) return Status;
80 
81  NewBuffer->Buffer = ConsoleAllocHeap(HEAP_ZERO_MEMORY,
82  TextModeInfo->ScreenBufferSize.X *
83  TextModeInfo->ScreenBufferSize.Y *
84  sizeof(CHAR_INFO));
85  if (NewBuffer->Buffer == NULL)
86  {
89  }
90 
91  NewBuffer->ScreenBufferSize = TextModeInfo->ScreenBufferSize;
92  NewBuffer->OldScreenBufferSize = NewBuffer->ScreenBufferSize;
93 
94  /*
95  * Set and fix the view size if needed.
96  * The rule is: ScreenBufferSize >= ViewSize (== ConsoleSize)
97  */
98  NewBuffer->ViewSize.X = min(max(TextModeInfo->ViewSize.X, 1), NewBuffer->ScreenBufferSize.X);
99  NewBuffer->ViewSize.Y = min(max(TextModeInfo->ViewSize.Y, 1), NewBuffer->ScreenBufferSize.Y);
100  NewBuffer->OldViewSize = NewBuffer->ViewSize;
101 
102  NewBuffer->ViewOrigin.X = NewBuffer->ViewOrigin.Y = 0;
103  NewBuffer->VirtualY = 0;
104 
105  NewBuffer->CursorBlinkOn = NewBuffer->ForceCursorOff = FALSE;
106  NewBuffer->CursorInfo.bVisible = (TextModeInfo->IsCursorVisible && (TextModeInfo->CursorSize != 0));
107  NewBuffer->CursorInfo.dwSize = min(max(TextModeInfo->CursorSize, 0), 100);
108 
109  NewBuffer->ScreenDefaultAttrib = (TextModeInfo->ScreenAttrib & ~COMMON_LVB_SBCSDBCS);
110  NewBuffer->PopupDefaultAttrib = (TextModeInfo->PopupAttrib & ~COMMON_LVB_SBCSDBCS);
111 
112  /* Initialize buffer to be empty with default attributes */
113  for (NewBuffer->CursorPosition.Y = 0 ; NewBuffer->CursorPosition.Y < NewBuffer->ScreenBufferSize.Y; NewBuffer->CursorPosition.Y++)
114  {
115  ClearLineBuffer(NewBuffer);
116  }
117  NewBuffer->CursorPosition.X = NewBuffer->CursorPosition.Y = 0;
118 
120 
121  *Buffer = (PCONSOLE_SCREEN_BUFFER)NewBuffer;
122  return STATUS_SUCCESS;
123 }
#define max(a, b)
Definition: svc.c:63
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
BOOLEAN CursorBlinkOn
Definition: conio.h:72
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN CONSOLE_IO_OBJECT_TYPE Type, IN SIZE_T Size)
Definition: conoutput.c:37
LONG NTSTATUS
Definition: precomp.h:26
#define COMMON_LVB_SBCSDBCS
Definition: wincon.h:56
COORD CursorPosition
Definition: conio.h:71
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
COORD OldScreenBufferSize
Definition: conio.h:65
#define ENABLE_WRAP_AT_EOL_OUTPUT
Definition: blue.h:54
COORD ScreenBufferSize
Definition: conio.h:62
struct _CONSOLE_SCREEN_BUFFER * PCONSOLE_SCREEN_BUFFER
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
VOID CONSOLE_SCREEN_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:55
ULONG X
Definition: bl.h:1340
VOID ClearLineBuffer(PTEXTMODE_SCREEN_BUFFER Buff)
Definition: text.c:151
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOLEAN ForceCursorOff
Definition: conio.h:73
Status
Definition: gdiplustypes.h:24
#define ENABLE_PROCESSED_OUTPUT
Definition: blue.h:53
#define min(a, b)
Definition: monoChain.cc:55
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
CConsole Console
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
return STATUS_SUCCESS
Definition: btrfs.c:3014
CONSOLE_CURSOR_INFO CursorInfo
Definition: conio.h:75
ULONG Y
Definition: bl.h:1341

Referenced by ConDrvCreateScreenBuffer().