feat: unify system status codes

This commit is contained in:
daniel committed 2026-09-30 09:43:18 +02:00
1 parent 93894b8fe5
commit 8a3ffb2be1
46 files changed
+1499 -489

No files matched your search

+42 -37
View File
@@ -55,13 +55,13 @@ namespace WinServer {
}
static int UnmapRetiredSnapshotsLocked(int windowId, int callerPid, uint64_t callerPml4) {
int result = -1;
int result = InvalidArgument;
for (int i = 0; i < MaxRetiredSnapshots; i++) {
if (!g_retiredSnapshots[i].used || g_retiredSnapshots[i].windowId != windowId) continue;
if (g_retiredSnapshots[i].surface != nullptr) {
if (Ipc::UnmapSurfaceForPid(g_retiredSnapshots[i].surface, callerPid, callerPml4) == 0) {
result = 0;
result = Success;
}
Ipc::ReleaseSurface(g_retiredSnapshots[i].surface);
}
@@ -95,21 +95,22 @@ namespace WinServer {
}
static int SendEventLocked(int windowId, const montauk::abi::WinEvent* event) {
if (windowId < 0 || windowId >= MaxWindows || event == nullptr) return -1;
if (windowId < 0 || windowId >= MaxWindows || event == nullptr) return InvalidArgument;
WindowSlot& slot = g_slots[windowId];
if (!slot.used || slot.eventMailbox == nullptr) return -1;
if (!slot.used || slot.eventMailbox == nullptr) return InvalidArgument;
int rc = (event->type == 1)
? Ipc::MailboxSendCoalescedMouse(slot.eventMailbox, 0, event, sizeof(*event))
: Ipc::MailboxSend(slot.eventMailbox, 0, event, sizeof(*event));
return rc > 0 ? 0 : -1;
if (rc < 0) return GenericFailure;
return rc > 0 ? Success : Busy;
}
int Create(int ownerPid, uint64_t ownerPml4, const char* title, int w, int h,
uint64_t& heapNext, uint64_t& outVa) {
WsGuard guard;
if (w <= 0 || h <= 0 || w > 16384 || h > 16384) return -1;
if (w <= 0 || h <= 0 || w > 16384 || h > 16384) return InvalidArgument;
int slotIdx = -1;
for (int i = 0; i < MaxWindows; i++) {
@@ -118,7 +119,7 @@ namespace WinServer {
break;
}
}
if (slotIdx < 0) return -1;
if (slotIdx < 0) return GenericFailure;
uint64_t bufSize = (uint64_t)w * (uint64_t)h * 4ULL;
Ipc::Surface* live = Ipc::CreateSurface(bufSize);
@@ -128,7 +129,7 @@ namespace WinServer {
if (live != nullptr) Ipc::ReleaseSurface(live);
if (snapshot != nullptr) Ipc::ReleaseSurface(snapshot);
if (mailbox != nullptr) Ipc::ReleaseMailbox(mailbox, false, false);
return -1;
return OutOfMemory;
}
Ipc::RetainSurface(live);
@@ -146,7 +147,7 @@ namespace WinServer {
Ipc::ReleaseMailbox(mailbox, true, true);
Ipc::ReleaseSurface(snapshot);
Ipc::ReleaseSurface(live);
return -1;
return GenericFailure;
}
WindowSlot& slot = g_slots[slotIdx];
@@ -176,40 +177,41 @@ namespace WinServer {
int Destroy(int windowId, int callerPid) {
WsGuard guard;
if (windowId < 0 || windowId >= MaxWindows) return -1;
if (windowId < 0 || windowId >= MaxWindows) return InvalidArgument;
WindowSlot& slot = g_slots[windowId];
if (!slot.used || slot.ownerPid != callerPid) return -1;
if (!slot.used) return InvalidArgument;
if (slot.ownerPid != callerPid) return PermissionDenied;
ReleaseSlotResourcesLocked(slot, true);
return 0;
return Success;
}
int Present(int windowId, int callerPid) {
WsGuard guard;
if (windowId < 0 || windowId >= MaxWindows) return -1;
if (windowId < 0 || windowId >= MaxWindows) return InvalidArgument;
WindowSlot& slot = g_slots[windowId];
if (!slot.used || slot.ownerPid != callerPid ||
slot.liveSurface == nullptr || slot.snapshotSurface == nullptr) {
return -1;
}
if (!slot.used || slot.liveSurface == nullptr || slot.snapshotSurface == nullptr)
return InvalidArgument;
if (slot.ownerPid != callerPid) return PermissionDenied;
if (Ipc::CopySurface(slot.snapshotSurface, slot.liveSurface) != 0) return -1;
if (Ipc::CopySurface(slot.snapshotSurface, slot.liveSurface) != 0) return GenericFailure;
slot.dirty = true;
return 0;
return Success;
}
int Poll(int windowId, int callerPid, montauk::abi::WinEvent* outEvent) {
WsGuard guard;
if (windowId < 0 || windowId >= MaxWindows || outEvent == nullptr) return -1;
if (windowId < 0 || windowId >= MaxWindows || outEvent == nullptr) return InvalidArgument;
WindowSlot& slot = g_slots[windowId];
if (!slot.used || slot.ownerPid != callerPid || slot.eventMailbox == nullptr) return -1;
if (!slot.used || slot.eventMailbox == nullptr) return InvalidArgument;
if (slot.ownerPid != callerPid) return PermissionDenied;
uint16_t len = sizeof(*outEvent);
int rc = Ipc::MailboxRecv(slot.eventMailbox, nullptr, outEvent, &len, true);
if (rc < 0) return -1;
if (rc < 0) return GenericFailure;
return rc > 0 ? 1 : 0;
}
@@ -259,7 +261,7 @@ namespace WinServer {
if (!slot.used || slot.snapshotSurface == nullptr) return result;
int current = Ipc::UnmapSurfaceForPid(slot.snapshotSurface, callerPid, callerPml4);
if (current == 0) return 0;
if (current == 0) return Success;
return result;
}
@@ -271,14 +273,15 @@ namespace WinServer {
int Resize(int windowId, int callerPid, uint64_t ownerPml4, int newW, int newH,
uint64_t& heapNext, uint64_t& outVa) {
WsGuard guard;
if (windowId < 0 || windowId >= MaxWindows) return -1;
if (windowId < 0 || windowId >= MaxWindows) return InvalidArgument;
WindowSlot& slot = g_slots[windowId];
if (!slot.used || slot.ownerPid != callerPid) return -1;
if (newW <= 0 || newH <= 0 || newW > 16384 || newH > 16384) return -1;
if (!slot.used) return InvalidArgument;
if (slot.ownerPid != callerPid) return PermissionDenied;
if (newW <= 0 || newH <= 0 || newW > 16384 || newH > 16384) return InvalidArgument;
if (newW == slot.width && newH == slot.height) {
outVa = slot.ownerVa;
return 0;
return Success;
}
uint64_t bufSize = (uint64_t)newW * (uint64_t)newH * 4ULL;
@@ -287,7 +290,7 @@ namespace WinServer {
if (newLive == nullptr || newSnapshot == nullptr) {
if (newLive != nullptr) Ipc::ReleaseSurface(newLive);
if (newSnapshot != nullptr) Ipc::ReleaseSurface(newSnapshot);
return -1;
return OutOfMemory;
}
Ipc::RetainSurface(newLive);
@@ -297,7 +300,7 @@ namespace WinServer {
if (Ipc::MapSurfaceForPid(newLive, callerPid, ownerPml4, heapNext, newOwnerVa, false) != 0) {
Ipc::ReleaseSurface(newSnapshot);
Ipc::ReleaseSurface(newLive);
return -1;
return GenericFailure;
}
if (slot.liveSurface != nullptr) {
@@ -327,27 +330,29 @@ namespace WinServer {
slot.dirty = true;
outVa = newOwnerVa;
return 0;
return Success;
}
int SetCursor(int windowId, int callerPid, int cursor) {
WsGuard guard;
if (windowId < 0 || windowId >= MaxWindows) return -1;
if (windowId < 0 || windowId >= MaxWindows) return InvalidArgument;
WindowSlot& slot = g_slots[windowId];
if (!slot.used || slot.ownerPid != callerPid) return -1;
if (!slot.used) return InvalidArgument;
if (slot.ownerPid != callerPid) return PermissionDenied;
slot.cursor = (uint8_t)cursor;
return 0;
return Success;
}
int SetFlags(int windowId, int callerPid, uint32_t flags) {
WsGuard guard;
if (windowId < 0 || windowId >= MaxWindows) return -1;
if (windowId < 0 || windowId >= MaxWindows) return InvalidArgument;
WindowSlot& slot = g_slots[windowId];
if (!slot.used || slot.ownerPid != callerPid) return -1;
if (!slot.used) return InvalidArgument;
if (slot.ownerPid != callerPid) return PermissionDenied;
slot.flags = flags & montauk::abi::WIN_FLAG_FULLSCREEN;
return 0;
return Success;
}
int SetScale(int scale) {
@@ -364,7 +369,7 @@ namespace WinServer {
SendEventLocked(i, &ev);
}
}
return 0;
return Success;
}
int GetScale() {