127 lines
5.7 KiB
C
127 lines
5.7 KiB
C
// RSSRV display authority. This component owns session display metadata, modeset, and transitional console authority.
|
|
|
|
#include "rssrv_internal.h"
|
|
#include <string.h>
|
|
|
|
// Initializes RSSRV display authority from the attenuated bootstrap manager capability.
|
|
KSTATUS RssrvDisplayInitialize(RSSRV_DISPLAY_STATE* display, RSSRV_NAMESPACE* namespaceState, SYS_HANDLE manager) {
|
|
if (!display || !namespaceState || manager == SYS_HANDLE_INVALID)
|
|
return NTLSTATUS_INVALID_PARAMETER;
|
|
memset(display, 0, sizeof(*display));
|
|
display->Manager = manager;
|
|
display->Namespace = namespaceState;
|
|
return NTLSTATUS_SUCCESS;
|
|
}
|
|
|
|
// Publishes read-only display metadata while keeping mode and transitional console authority private to RSSRV.
|
|
KSTATUS RssrvDisplayPublishDevice(RSSRV_DISPLAY_STATE* display) {
|
|
if (!display || !display->Namespace || display->Manager == SYS_HANDLE_INVALID)
|
|
return NTLSTATUS_INVALID_PARAMETER;
|
|
|
|
SYS_HANDLE deviceHandle = SYS_HANDLE_INVALID;
|
|
SYS_DERIVE_HANDLE_REQUEST derive;
|
|
memset(&derive, 0, sizeof(derive));
|
|
derive.Size = sizeof(derive);
|
|
derive.SourceHandle = display->Manager;
|
|
derive.DesiredRights = SYS_RIGHT_TRANSFER | SYS_RIGHT_QUERY | SYS_DISPLAY_MANAGER_RIGHT_ENUMERATE;
|
|
derive.DerivedHandleOut = &deviceHandle;
|
|
KSTATUS status = SysDeriveHandle(&derive);
|
|
if (!KSUCCESS(status)) return status;
|
|
|
|
status = RssrvNamespaceBindOwned(display->Namespace,
|
|
"/Device/Display0",
|
|
sizeof("/Device/Display0") - 1u,
|
|
NTL_RESOURCE_KIND_DEVICE,
|
|
deviceHandle,
|
|
SYS_RIGHT_QUERY | SYS_DISPLAY_MANAGER_RIGHT_ENUMERATE);
|
|
if (!KSUCCESS(status)) (void)SysCloseHandle(deviceHandle);
|
|
return status;
|
|
}
|
|
|
|
// Queries the primary display through RSSRV's delegated manager capability.
|
|
KSTATUS RssrvDisplayQueryInfo(RSSRV_DISPLAY_STATE* display, SYS_DISPLAY_INFO* infoOut) {
|
|
if (!display || display->Manager == SYS_HANDLE_INVALID || !infoOut)
|
|
return NTLSTATUS_INVALID_PARAMETER;
|
|
return SysQueryDisplayManagerInfo(display->Manager, infoOut);
|
|
}
|
|
|
|
// Writes text through RSSRV's delegated legacy-console bridge.
|
|
KSTATUS RssrvDisplayWriteConsole(RSSRV_DISPLAY_STATE* display, const char* data, size_t length) {
|
|
if (!display || display->Manager == SYS_HANDLE_INVALID || (length && !data))
|
|
return NTLSTATUS_INVALID_PARAMETER;
|
|
SYS_WRITE_CONSOLE_REQUEST request;
|
|
memset(&request, 0, sizeof(request));
|
|
request.Size = sizeof(request);
|
|
request.Text = SysSvFromParts(data, length);
|
|
return SysWriteDisplayManagerConsole(display->Manager, &request);
|
|
}
|
|
|
|
// Queries the kernel-backed console state during the RSSRV migration period.
|
|
KSTATUS RssrvDisplayQueryConsoleInfo(RSSRV_DISPLAY_STATE* display, SYS_CONSOLE_INFO* infoOut) {
|
|
if (!display || display->Manager == SYS_HANDLE_INVALID || !infoOut)
|
|
return NTLSTATUS_INVALID_PARAMETER;
|
|
return SysQueryDisplayManagerConsoleInfo(display->Manager, infoOut);
|
|
}
|
|
|
|
// Updates the kernel-backed console cursor through delegated authority.
|
|
KSTATUS RssrvDisplaySetConsoleCursor(RSSRV_DISPLAY_STATE* display, int x, int y) {
|
|
if (!display || display->Manager == SYS_HANDLE_INVALID)
|
|
return NTLSTATUS_INVALID_PARAMETER;
|
|
return SysSetDisplayManagerConsoleCursor(display->Manager, x, y);
|
|
}
|
|
|
|
// Fills kernel-backed console characters through delegated authority.
|
|
KSTATUS RssrvDisplayFillConsoleCharacter(RSSRV_DISPLAY_STATE* display, char character,
|
|
int x, int y, size_t length, size_t* writtenOut) {
|
|
if (!display || display->Manager == SYS_HANDLE_INVALID)
|
|
return NTLSTATUS_INVALID_PARAMETER;
|
|
SYS_FILL_CONSOLE_CHARACTER_REQUEST request;
|
|
memset(&request, 0, sizeof(request));
|
|
request.Size = sizeof(request);
|
|
request.Character = character;
|
|
request.X = x;
|
|
request.Y = y;
|
|
request.Length = length;
|
|
request.WrittenOut = writtenOut;
|
|
return SysFillDisplayManagerConsoleCharacter(display->Manager, &request);
|
|
}
|
|
|
|
// Fills kernel-backed console attributes through delegated authority.
|
|
KSTATUS RssrvDisplayFillConsoleAttribute(RSSRV_DISPLAY_STATE* display, uint16_t attribute,
|
|
int x, int y, size_t length, size_t* writtenOut) {
|
|
if (!display || display->Manager == SYS_HANDLE_INVALID)
|
|
return NTLSTATUS_INVALID_PARAMETER;
|
|
SYS_FILL_CONSOLE_ATTRIBUTE_REQUEST request;
|
|
memset(&request, 0, sizeof(request));
|
|
request.Size = sizeof(request);
|
|
request.Attribute = attribute;
|
|
request.X = x;
|
|
request.Y = y;
|
|
request.Length = length;
|
|
request.WrittenOut = writtenOut;
|
|
return SysFillDisplayManagerConsoleAttribute(display->Manager, &request);
|
|
}
|
|
|
|
// Draws one explicit glyph through delegated console authority.
|
|
KSTATUS RssrvDisplayPutConsoleCharacter(RSSRV_DISPLAY_STATE* display, char character,
|
|
int x, int y, uint32_t foreground, uint32_t background) {
|
|
if (!display || display->Manager == SYS_HANDLE_INVALID)
|
|
return NTLSTATUS_INVALID_PARAMETER;
|
|
SYS_PUT_SCREEN_CHAR_REQUEST request;
|
|
memset(&request, 0, sizeof(request));
|
|
request.Size = sizeof(request);
|
|
request.Character = character;
|
|
request.X = x;
|
|
request.Y = y;
|
|
request.Foreground = foreground;
|
|
request.Background = background;
|
|
return SysPutDisplayManagerConsoleCharacter(display->Manager, &request);
|
|
}
|
|
|
|
// Clears the current console target through delegated console authority.
|
|
KSTATUS RssrvDisplayClearConsole(RSSRV_DISPLAY_STATE* display, uint32_t color) {
|
|
if (!display || display->Manager == SYS_HANDLE_INVALID)
|
|
return NTLSTATUS_INVALID_PARAMETER;
|
|
return SysClearDisplayManagerConsole(display->Manager, color);
|
|
}
|