ReactOS  0.4.14-dev-77-gd9e7c48
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 PCONSOLE_SCREEN_BUFFER_VTBL Vtbl, 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 79 of file conoutput.c.

84 {
86 
87  if ( Console == NULL || Buffer == NULL ||
88  (BufferType != CONSOLE_TEXTMODE_BUFFER && BufferType != CONSOLE_GRAPHICS_BUFFER) )
89  {
91  }
92 
93  /* Use the current process if ProcessHandle is NULL */
94  if (ProcessHandle == NULL)
96 
97  if (BufferType == CONSOLE_TEXTMODE_BUFFER)
98  {
101  }
102  else if (BufferType == CONSOLE_GRAPHICS_BUFFER)
103  {
106  }
107  else
108  {
109  /* Never ever go there!! */
110  ASSERT(FALSE);
111  }
112 
113  /* Insert the newly created screen buffer into the list, if succeeded */
114  if (NT_SUCCESS(Status)) InsertHeadList(&Console->BufferList, &(*Buffer)->ListEntry);
115 
116  return Status;
117 }
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:62
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:44
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#define CONSOLE_TEXTMODE_BUFFER
Definition: wincon.h:59
#define CONSOLE_GRAPHICS_BUFFER
Definition: wincon.h:60
CConsole Console
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by ConDrvInitConsole(), and CSR_API().

◆ ConDrvDeleteScreenBuffer()

VOID NTAPI ConDrvDeleteScreenBuffer ( PCONSOLE_SCREEN_BUFFER  Buffer)

Definition at line 123 of file conoutput.c.

124 {
125  PCONSOLE Console = Buffer->Header.Console;
126  PCONSOLE_SCREEN_BUFFER NewBuffer;
127 
128  /*
129  * We should notify temporarily the frontend because we are susceptible
130  * to delete the screen buffer it is using (which may be different from
131  * the active screen buffer in some cases), and because, if it actually
132  * uses the active screen buffer, we are going to nullify its pointer to
133  * change it.
134  */
136 
137  RemoveEntryList(&Buffer->ListEntry);
138  if (Buffer == Console->ActiveBuffer)
139  {
140  /* Delete active buffer; switch to most recently created */
141  if (!IsListEmpty(&Console->BufferList))
142  {
143  NewBuffer = CONTAINING_RECORD(Console->BufferList.Flink,
145  ListEntry);
146 
147  /* Tie console to new buffer and signal the change to the frontend */
148  ConioSetActiveScreenBuffer(NewBuffer);
149  }
150  else
151  {
152  Console->ActiveBuffer = NULL;
153  // InterlockedExchangePointer(&Console->ActiveBuffer, NULL);
154  }
155  }
156 
158 }
_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:161
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 ConDrvDeleteConsole(), ConDrvSetConsoleActiveScreenBuffer(), and ConSrvCloseHandle().

◆ ConDrvGetActiveScreenBuffer()

◆ ConDrvGetConsoleCursorInfo()

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

Definition at line 263 of file conoutput.c.

266 {
267  if (Console == NULL || Buffer == NULL || CursorInfo == NULL)
269 
270  /* Validity check */
271  ASSERT(Console == Buffer->Header.Console);
272 
273  *CursorInfo = Buffer->CursorInfo;
274  // CursorInfo->bVisible = Buffer->CursorInfo.bVisible;
275  // CursorInfo->dwSize = Buffer->CursorInfo.dwSize;
276 
277  return STATUS_SUCCESS;
278 }
#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:2966

Referenced by CSR_API().

◆ ConDrvInvalidateBitMapRect()

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

Definition at line 202 of file conoutput.c.

205 {
206  if (Console == NULL || Buffer == NULL || Region == NULL)
208 
209  /* Validity check */
210  ASSERT(Console == Buffer->Header.Console);
211 
212  /* If the output buffer is the current one, redraw the correct portion of the screen */
213  if (Buffer == Console->ActiveBuffer) TermDrawRegion(Console, Region);
214 
215  return STATUS_SUCCESS;
216 }
#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:2966

Referenced by CSR_API().

◆ ConDrvSetConsoleActiveScreenBuffer()

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

Definition at line 170 of file conoutput.c.

172 {
173  if (Console == NULL || Buffer == NULL)
175 
176  /* Validity check */
177  ASSERT(Console == Buffer->Header.Console);
178 
179  if (Buffer == Console->ActiveBuffer) return STATUS_SUCCESS;
180 
181  /* If old buffer has no handles, it's now unreferenced */
182  if (Console->ActiveBuffer->Header.ReferenceCount == 0)
183  {
184  ConDrvDeleteScreenBuffer(Console->ActiveBuffer);
185  }
186 
187  /* Tie console to new buffer and signal the change to the frontend */
189 
190  return STATUS_SUCCESS;
191 }
VOID NTAPI ConDrvDeleteScreenBuffer(PCONSOLE_SCREEN_BUFFER Buffer)
Definition: conoutput.c:123
#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:161
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by CSR_API().

◆ ConDrvSetConsoleCursorInfo()

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

Definition at line 281 of file conoutput.c.

284 {
285  ULONG Size;
286  BOOLEAN Visible, Success = TRUE;
287 
288  if (Console == NULL || Buffer == NULL || CursorInfo == NULL)
290 
291  /* Validity check */
292  ASSERT(Console == Buffer->Header.Console);
293 
294  Size = min(max(CursorInfo->dwSize, 1), 100);
295  Visible = CursorInfo->bVisible;
296 
297  if ( (Size != Buffer->CursorInfo.dwSize) ||
298  (Visible && !Buffer->CursorInfo.bVisible) ||
299  (!Visible && Buffer->CursorInfo.bVisible) )
300  {
301  Buffer->CursorInfo.dwSize = Size;
302  Buffer->CursorInfo.bVisible = Visible;
303 
305  }
306 
308 }
#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:359
#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:2966

Referenced by CSR_API().

◆ ConDrvSetConsoleCursorPosition()

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

Definition at line 311 of file conoutput.c.

314 {
315  SHORT OldCursorX, OldCursorY;
316 
317  if (Console == NULL || Buffer == NULL || Position == NULL)
319 
320  /* Validity check */
321  ASSERT(Console == Buffer->Header.Console);
322 
323  if ( Position->X < 0 || Position->X >= Buffer->ScreenBufferSize.X ||
324  Position->Y < 0 || Position->Y >= Buffer->ScreenBufferSize.Y )
325  {
327  }
328 
329  OldCursorX = Buffer->CursorPosition.X;
330  OldCursorY = Buffer->CursorPosition.Y;
331  Buffer->CursorPosition = *Position;
332  // Buffer->CursorPosition.X = Position->X;
333  // Buffer->CursorPosition.Y = Position->Y;
334  if ( ((PCONSOLE_SCREEN_BUFFER)Buffer == Console->ActiveBuffer) &&
335  (!TermSetScreenInfo(Console, (PCONSOLE_SCREEN_BUFFER)Buffer, OldCursorX, OldCursorY)) )
336  {
337  return STATUS_UNSUCCESSFUL;
338  }
339 
340  return STATUS_SUCCESS;
341 }
#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:2966
ULONG Y
Definition: bl.h:1341

Referenced by CSR_API().

◆ ConDrvSetConsolePalette()

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

Definition at line 219 of file conoutput.c.

224 {
225  BOOL Success;
226 
227  /*
228  * Parameters validation
229  */
230  if (Console == NULL || Buffer == NULL)
232 
233  if ( PaletteUsage != SYSPAL_STATIC &&
234  PaletteUsage != SYSPAL_NOSTATIC &&
235  PaletteUsage != SYSPAL_NOSTATIC256 )
236  {
238  }
239 
240  /* Validity check */
241  ASSERT(Console == Buffer->Header.Console);
242 
243  /* Change the palette */
244  Success = TermSetPalette(Console, PaletteHandle, PaletteUsage);
245  if (Success)
246  {
247  /* Free the old palette handle if there was already one set */
248  if ( Buffer->PaletteHandle != NULL &&
249  Buffer->PaletteHandle != PaletteHandle )
250  {
251  DeleteObject(Buffer->PaletteHandle);
252  }
253 
254  /* Save the new palette in the screen buffer */
255  Buffer->PaletteHandle = PaletteHandle;
256  Buffer->PaletteUsage = PaletteUsage;
257  }
258 
260 }
#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:2966

Referenced by CSR_API().

◆ ConioSetActiveScreenBuffer()

static VOID ConioSetActiveScreenBuffer ( PCONSOLE_SCREEN_BUFFER  Buffer)
static

Definition at line 161 of file conoutput.c.

162 {
163  PCONSOLE Console = Buffer->Header.Console;
164  Console->ActiveBuffer = Buffer;
165  // InterlockedExchangePointer(&Console->ActiveBuffer, Buffer);
167 }
#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  if (Buffer->Header.Type == TEXTMODE_BUFFER)
58  {
60  }
61  else if (Buffer->Header.Type == GRAPHICS_BUFFER)
62  {
64  }
65  else if (Buffer->Header.Type == SCREEN_BUFFER)
66  {
67  /* Free the palette handle */
68  if (Buffer->PaletteHandle != NULL) DeleteObject(Buffer->PaletteHandle);
69 
70  /* Free the screen buffer memory */
72  }
73  // else
74  // do_nothing;
75 }
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define TEXTMODE_BUFFER
Definition: pccons.c:21
VOID TEXTMODE_BUFFER_Destroy(IN OUT PCONSOLE_SCREEN_BUFFER Buffer)
Definition: text.c:123
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:249

Referenced by ConDrvDeleteScreenBuffer(), and ConioDeleteScreenBuffer().

◆ CONSOLE_SCREEN_BUFFER_Initialize()

NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize ( OUT PCONSOLE_SCREEN_BUFFER Buffer,
IN PCONSOLE  Console,
IN PCONSOLE_SCREEN_BUFFER_VTBL  Vtbl,
IN SIZE_T  Size 
)

Definition at line 37 of file conoutput.c.

41 {
42  if (Buffer == NULL || Console == NULL)
44 
47 
48  /* Initialize the header with the default type */
49  ConSrvInitObject(&(*Buffer)->Header, SCREEN_BUFFER, Console);
50  (*Buffer)->Vtbl = Vtbl;
51  return STATUS_SUCCESS;
52 }
#define max(a, b)
Definition: svc.c:63
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#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:294
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
CConsole Console
return STATUS_SUCCESS
Definition: btrfs.c:2966

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 249 of file graphics.c.

250 {
252 
253  /*
254  * IMPORTANT !! Reinitialize the type so that we don't enter a recursive
255  * infinite loop when calling CONSOLE_SCREEN_BUFFER_Destroy.
256  */
257  Buffer->Header.Type = SCREEN_BUFFER;
258 
259  /*
260  * Uninitialize the graphics screen buffer
261  * in the reverse way we initialized it.
262  */
265  NtClose(Buff->hSection);
268  NtClose(Buff->Mutex);
270 
272 }
#define DUPLICATE_CLOSE_SOURCE
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3782
LPBITMAPINFO BitMapInfo
Definition: conio.h:175
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 44 of file graphics.c.

48 {
50  PGRAPHICS_SCREEN_BUFFER NewBuffer = NULL;
51 
52  LARGE_INTEGER SectionSize;
53  SIZE_T ViewSize = 0;
54 
55  if (Buffer == NULL || Console == NULL || GraphicsInfo == NULL)
57 
58  *Buffer = NULL;
59 
61  Console,
62  &GraphicsVtbl,
63  sizeof(GRAPHICS_SCREEN_BUFFER));
64  if (!NT_SUCCESS(Status)) return Status;
65  NewBuffer->Header.Type = GRAPHICS_BUFFER;
66 
67  /*
68  * Remember the handle to the process so that we can close or unmap
69  * correctly the allocated resources when the client releases the
70  * screen buffer.
71  */
72  NewBuffer->ClientProcess = ProcessHandle;
73 
74  /* Get infos from the graphics buffer information structure */
75  NewBuffer->BitMapInfoLength = GraphicsInfo->Info.dwBitMapInfoLength;
76 
77  NewBuffer->BitMapInfo = ConsoleAllocHeap(HEAP_ZERO_MEMORY, NewBuffer->BitMapInfoLength);
78  if (NewBuffer->BitMapInfo == NULL)
79  {
82  }
83 
84  /* Adjust the bitmap height if needed (bottom-top vs. top-bottom). Use always bottom-up. */
85  if (GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight > 0)
86  GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight = -GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight;
87 
88  /* We do not use anything else than uncompressed bitmaps */
89  if (GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biCompression != BI_RGB)
90  {
91  DPRINT1("biCompression == %d != BI_RGB, fix that!\n",
92  GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biCompression);
93  GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biCompression = BI_RGB;
94  }
95 
96  RtlCopyMemory(NewBuffer->BitMapInfo,
97  GraphicsInfo->Info.lpBitMapInfo,
98  GraphicsInfo->Info.dwBitMapInfoLength);
99 
100  NewBuffer->BitMapUsage = GraphicsInfo->Info.dwUsage;
101 
102  /* Set the screen buffer size. Fight against overflows. */
103  if ( GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biWidth <= 0xFFFF &&
104  -GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight <= 0xFFFF )
105  {
106  /* Be careful about the sign of biHeight */
107  NewBuffer->ScreenBufferSize.X = (SHORT)GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biWidth ;
108  NewBuffer->ScreenBufferSize.Y = (SHORT)-GraphicsInfo->Info.lpBitMapInfo->bmiHeader.biHeight;
109 
110  NewBuffer->OldViewSize = NewBuffer->ViewSize =
111  NewBuffer->OldScreenBufferSize = NewBuffer->ScreenBufferSize;
112  }
113  else
114  {
116  ConsoleFreeHeap(NewBuffer->BitMapInfo);
118  goto Quit;
119  }
120 
121  /*
122  * Create a mutex to synchronize bitmap memory access
123  * between ourselves and the client.
124  */
125  Status = NtCreateMutant(&NewBuffer->Mutex, MUTANT_ALL_ACCESS, NULL, FALSE);
126  if (!NT_SUCCESS(Status))
127  {
128  DPRINT1("NtCreateMutant() failed: %lu\n", Status);
129  ConsoleFreeHeap(NewBuffer->BitMapInfo);
131  goto Quit;
132  }
133 
134  /*
135  * Duplicate the Mutex for the client. We must keep a trace of it
136  * so that we can close it when the client releases the screen buffer.
137  */
139  NewBuffer->Mutex,
141  &NewBuffer->ClientMutex,
142  0, 0, DUPLICATE_SAME_ACCESS);
143  if (!NT_SUCCESS(Status))
144  {
145  DPRINT1("NtDuplicateObject() failed: %lu\n", Status);
146  NtClose(NewBuffer->Mutex);
147  ConsoleFreeHeap(NewBuffer->BitMapInfo);
149  goto Quit;
150  }
151 
152  /*
153  * Create a memory section for the bitmap area, to share with the client.
154  */
155  SectionSize.QuadPart = NewBuffer->BitMapInfo->bmiHeader.biSizeImage;
156  Status = NtCreateSection(&NewBuffer->hSection,
158  NULL,
159  &SectionSize,
161  SEC_COMMIT,
162  NULL);
163  if (!NT_SUCCESS(Status))
164  {
165  DPRINT1("Error: Impossible to create a shared section, Status = 0x%08lx\n", Status);
166  NtDuplicateObject(ProcessHandle, NewBuffer->ClientMutex,
168  NtClose(NewBuffer->Mutex);
169  ConsoleFreeHeap(NewBuffer->BitMapInfo);
171  goto Quit;
172  }
173 
174  /*
175  * Create a view for our needs.
176  */
177  ViewSize = 0;
178  NewBuffer->BitMap = NULL;
179  Status = NtMapViewOfSection(NewBuffer->hSection,
181  (PVOID*)&NewBuffer->BitMap,
182  0,
183  0,
184  NULL,
185  &ViewSize,
186  ViewUnmap,
187  0,
189  if (!NT_SUCCESS(Status))
190  {
191  DPRINT1("Error: Impossible to map the shared section, Status = 0x%08lx\n", Status);
192  NtClose(NewBuffer->hSection);
193  NtDuplicateObject(ProcessHandle, NewBuffer->ClientMutex,
195  NtClose(NewBuffer->Mutex);
196  ConsoleFreeHeap(NewBuffer->BitMapInfo);
198  goto Quit;
199  }
200 
201  /*
202  * Create a view for the client. We must keep a trace of it so that
203  * we can unmap it when the client releases the screen buffer.
204  */
205  ViewSize = 0;
206  NewBuffer->ClientBitMap = NULL;
207  Status = NtMapViewOfSection(NewBuffer->hSection,
209  (PVOID*)&NewBuffer->ClientBitMap,
210  0,
211  0,
212  NULL,
213  &ViewSize,
214  ViewUnmap,
215  0,
217  if (!NT_SUCCESS(Status))
218  {
219  DPRINT1("Error: Impossible to map the shared section, Status = 0x%08lx\n", Status);
220  NtUnmapViewOfSection(NtCurrentProcess(), NewBuffer->BitMap);
221  NtClose(NewBuffer->hSection);
222  NtDuplicateObject(ProcessHandle, NewBuffer->ClientMutex,
224  NtClose(NewBuffer->Mutex);
225  ConsoleFreeHeap(NewBuffer->BitMapInfo);
227  goto Quit;
228  }
229 
230  NewBuffer->ViewOrigin.X = NewBuffer->ViewOrigin.Y = 0;
231  NewBuffer->VirtualY = 0;
232 
233  NewBuffer->CursorBlinkOn = FALSE;
234  NewBuffer->ForceCursorOff = TRUE;
235  NewBuffer->CursorInfo.bVisible = FALSE;
236  NewBuffer->CursorInfo.dwSize = 0;
237  NewBuffer->CursorPosition.X = NewBuffer->CursorPosition.Y = 0;
238 
239  NewBuffer->Mode = 0;
240 
241  *Buffer = (PCONSOLE_SCREEN_BUFFER)NewBuffer;
243 
244 Quit:
245  return Status;
246 }
#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:99
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
COORD CursorPosition
Definition: conio.h:98
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
COORD OldScreenBufferSize
Definition: conio.h:90
CONSOLE_IO_OBJECT Header
Definition: conio.h:82
#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:87
#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
Definition: conio.h:70
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NtCurrentProcess()
Definition: nt_native.h:1657
ULONG X
Definition: bl.h:1340
BOOLEAN bVisible
Definition: blue.h:41
NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER_VTBL Vtbl, IN SIZE_T Size)
Definition: conoutput.c:37
#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
BOOLEAN ForceCursorOff
Definition: conio.h:100
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:78
static CONSOLE_SCREEN_BUFFER_VTBL GraphicsVtbl
Definition: graphics.c:28
#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
CONSOLE_IO_OBJECT_TYPE Type
Definition: conio.h:50
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
return STATUS_SUCCESS
Definition: btrfs.c:2966
CONSOLE_CURSOR_INFO CursorInfo
Definition: conio.h:102
ULONG Y
Definition: bl.h:1341
#define BI_RGB
Definition: precomp.h:34
LONGLONG QuadPart
Definition: typedefs.h:112
#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 123 of file text.c.

124 {
126 
127  /*
128  * IMPORTANT !! Reinitialize the type so that we don't enter a recursive
129  * infinite loop when calling CONSOLE_SCREEN_BUFFER_Destroy.
130  */
131  Buffer->Header.Type = SCREEN_BUFFER;
132 
133  ConsoleFreeHeap(Buff->Buffer);
134 
136 }
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:154
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 62 of file text.c.

66 {
68  PTEXTMODE_SCREEN_BUFFER NewBuffer = NULL;
69 
71 
72  if (Console == NULL || Buffer == NULL || TextModeInfo == NULL)
74 
75  *Buffer = NULL;
76 
78  Console,
79  &TextVtbl,
80  sizeof(TEXTMODE_SCREEN_BUFFER));
81  if (!NT_SUCCESS(Status)) return Status;
82  NewBuffer->Header.Type = TEXTMODE_BUFFER;
83 
84  NewBuffer->Buffer = ConsoleAllocHeap(HEAP_ZERO_MEMORY,
85  TextModeInfo->ScreenBufferSize.X *
86  TextModeInfo->ScreenBufferSize.Y *
87  sizeof(CHAR_INFO));
88  if (NewBuffer->Buffer == NULL)
89  {
92  }
93 
94  NewBuffer->ScreenBufferSize = NewBuffer->OldScreenBufferSize
95  = TextModeInfo->ScreenBufferSize;
96  NewBuffer->ViewSize = NewBuffer->OldViewSize
97  = Console->ConsoleSize;
98 
99  NewBuffer->ViewOrigin.X = NewBuffer->ViewOrigin.Y = 0;
100  NewBuffer->VirtualY = 0;
101 
102  NewBuffer->CursorBlinkOn = NewBuffer->ForceCursorOff = FALSE;
103  NewBuffer->CursorInfo.bVisible = (TextModeInfo->IsCursorVisible && (TextModeInfo->CursorSize != 0));
104  NewBuffer->CursorInfo.dwSize = min(max(TextModeInfo->CursorSize, 0), 100);
105 
106  NewBuffer->ScreenDefaultAttrib = TextModeInfo->ScreenAttrib;
107  NewBuffer->PopupDefaultAttrib = TextModeInfo->PopupAttrib;
108 
109  /* Initialize buffer to be empty with default attributes */
110  for (NewBuffer->CursorPosition.Y = 0 ; NewBuffer->CursorPosition.Y < NewBuffer->ScreenBufferSize.Y; NewBuffer->CursorPosition.Y++)
111  {
112  ClearLineBuffer(NewBuffer);
113  }
114  NewBuffer->CursorPosition.X = NewBuffer->CursorPosition.Y = 0;
115 
117 
118  *Buffer = (PCONSOLE_SCREEN_BUFFER)NewBuffer;
119  return STATUS_SUCCESS;
120 }
#define max(a, b)
Definition: svc.c:63
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
BOOLEAN CursorBlinkOn
Definition: conio.h:99
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
COORD CursorPosition
Definition: conio.h:98
#define ConsoleAllocHeap(Flags, Size)
Definition: heap.h:14
#define TEXTMODE_BUFFER
Definition: pccons.c:21
COORD OldScreenBufferSize
Definition: conio.h:90
CONSOLE_IO_OBJECT Header
Definition: conio.h:82
#define ENABLE_WRAP_AT_EOL_OUTPUT
Definition: blue.h:45
COORD ScreenBufferSize
Definition: conio.h:87
struct _CONSOLE_SCREEN_BUFFER * PCONSOLE_SCREEN_BUFFER
Definition: conio.h:70
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
NTSTATUS CONSOLE_SCREEN_BUFFER_Initialize(OUT PCONSOLE_SCREEN_BUFFER *Buffer, IN PCONSOLE Console, IN PCONSOLE_SCREEN_BUFFER_VTBL Vtbl, IN SIZE_T Size)
Definition: conoutput.c:37
BOOLEAN bVisible
Definition: blue.h:41
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOLEAN ForceCursorOff
Definition: conio.h:100
Status
Definition: gdiplustypes.h:24
#define ENABLE_PROCESSED_OUTPUT
Definition: blue.h:44
static CONSOLE_SCREEN_BUFFER_VTBL TextVtbl
Definition: text.c:42
#define min(a, b)
Definition: monoChain.cc:55
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
CConsole Console
CONSOLE_IO_OBJECT_TYPE Type
Definition: conio.h:50
VOID ClearLineBuffer(PTEXTMODE_SCREEN_BUFFER Buff)
Definition: text.c:146
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
return STATUS_SUCCESS
Definition: btrfs.c:2966
CONSOLE_CURSOR_INFO CursorInfo
Definition: conio.h:102
ULONG Y
Definition: bl.h:1341

Referenced by ConDrvCreateScreenBuffer().