feat: unify system status codes
This commit is contained in:
1 parent
93894b8fe5
commit
8a3ffb2be1
46 files changed
+1499
-489
No files matched your search
@@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <montauk/statuscodes.h>
|
||||
|
||||
namespace montauk::abi {
|
||||
|
||||
@@ -312,6 +313,9 @@ namespace montauk::abi {
|
||||
static_assert((CAP_ADMIN_SESSION & CAP_COMPOSITOR) == 0,
|
||||
"a session must not delegate the compositor's authority; "
|
||||
"login grants it to the desktop directly");
|
||||
// Capability denial for the Wi-Fi and USB syscalls only, which keep their
|
||||
// own WIFI_ERR_* / USB_ERR_* spaces; everything else returns
|
||||
// CapabilityDenied from StatusCodes.
|
||||
static constexpr int SYS_ERR_PERMISSION = -13;
|
||||
|
||||
// A process holds two independent sets: what it may use (effective) and
|
||||
|
||||
@@ -219,6 +219,27 @@ extern "C" {
|
||||
#define MTK_SYS_CONSENT_REPLY 193
|
||||
/* @SYSCALLS-END */
|
||||
|
||||
/* Syscall status codes (montauk/statuscodes.h for C++). */
|
||||
/* @STATUS-BEGIN
|
||||
Generated from Common/StatusCodes.hpp by scripts/montauk-syscalls.py.
|
||||
Do not edit by hand; run 'make gen-syscalls' to refresh. */
|
||||
#define MTK_STATUS_SUCCESS (0)
|
||||
#define MTK_STATUS_GENERIC_FAILURE (-1)
|
||||
#define MTK_STATUS_PERMISSION_DENIED (-2)
|
||||
#define MTK_STATUS_CAPABILITY_DENIED (-3)
|
||||
#define MTK_STATUS_SYSTEM_INTEGRITY_ERROR (-4)
|
||||
#define MTK_STATUS_BAD_POINTER (-5)
|
||||
#define MTK_STATUS_INVALID_ARGUMENT (-6)
|
||||
#define MTK_STATUS_UNSUPPORTED_OP (-7)
|
||||
#define MTK_STATUS_NO_DEVICE (-8)
|
||||
#define MTK_STATUS_IO_FAILURE (-9)
|
||||
#define MTK_STATUS_BAD_INVOCATION (-10)
|
||||
#define MTK_STATUS_NO_SUCH_PATH (-11)
|
||||
#define MTK_STATUS_BUSY (-12)
|
||||
#define MTK_STATUS_BUFFER_TOO_SMALL (-13)
|
||||
#define MTK_STATUS_OUT_OF_MEMORY (-14)
|
||||
/* @STATUS-END */
|
||||
|
||||
#define MTK_SOCK_TCP 1
|
||||
#define MTK_SOCK_UDP 2
|
||||
#define MTK_IPC_SIGNAL_READABLE (1u << 0)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* statuscodes.h
|
||||
* MontaukOS status codes
|
||||
* Copyright (c) 2026 Daniel Hammer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Userspace mirror of kernel/src/Common/StatusCodes.hpp. Also usable from C
|
||||
// (the libc includes it), where the enumerators are unqualified.
|
||||
#ifdef __cplusplus
|
||||
namespace montauk {
|
||||
#endif
|
||||
|
||||
enum StatusCodes {
|
||||
Success = 0,
|
||||
GenericFailure = -1,
|
||||
PermissionDenied = -2,
|
||||
CapabilityDenied = -3,
|
||||
SystemIntegrityError = -4,
|
||||
BadPointer = -5,
|
||||
InvalidArgument = -6,
|
||||
UnsupportedOp = -7,
|
||||
NoDevice = -8,
|
||||
IoFailure = -9,
|
||||
BadInvocation = -10,
|
||||
NoSuchPath = -11,
|
||||
Busy = -12,
|
||||
BufferTooSmall = -13,
|
||||
OutOfMemory = -14
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
#include <Api/Syscall.hpp>
|
||||
#include <montauk/statuscodes.h>
|
||||
|
||||
namespace montauk {
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include "../../include/montauk/statuscodes.h"
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
@@ -2476,7 +2477,7 @@ char *getcwd(char *buf, size_t size) {
|
||||
}
|
||||
int result = (int)_mtk_syscall2(SYS_GETCWD, (long)buf, (long)size);
|
||||
if (result < 0) {
|
||||
errno = result == -2 ? ERANGE : EIO;
|
||||
errno = result == BufferTooSmall ? ERANGE : EIO;
|
||||
return NULL;
|
||||
}
|
||||
return buf;
|
||||
@@ -3566,9 +3567,10 @@ int utime(const char *path, const struct utimbuf *times) {
|
||||
times != NULL ? (long)times->modtime : 0,
|
||||
times == NULL);
|
||||
if (result == 0) return 0;
|
||||
if (result == -2) errno = ENOTSUP;
|
||||
else if (result == -3) errno = EOVERFLOW;
|
||||
else if (result == -4) errno = EIO;
|
||||
if (result == UnsupportedOp) errno = ENOTSUP;
|
||||
else if (result == InvalidArgument) errno = EOVERFLOW;
|
||||
else if (result == IoFailure) errno = EIO;
|
||||
else if (result == SystemIntegrityError) errno = EPERM;
|
||||
else errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -500,7 +500,7 @@ static void apply_changes() {
|
||||
if (g_driver_available && g_selected_mode != g_info.currentMode) {
|
||||
int result = montauk::display_set_mode(g_selected_mode);
|
||||
if (result < 0) {
|
||||
set_status(result == -2
|
||||
set_status(result == montauk::UnsupportedOp
|
||||
? "Mode needs unsupported display-link training"
|
||||
: "Mode change failed; previous mode restored");
|
||||
refresh_state(true);
|
||||
|
||||
@@ -262,7 +262,7 @@ void perform_graceful_shutdown(LoginState* ls, int action) {
|
||||
// A successful power-control syscall never returns. If it does return,
|
||||
// keep the trusted supervisor alive and make the authorization failure
|
||||
// visible instead of falling through an unreachable-code assumption.
|
||||
show_stage(ls, heading, rc == montauk::abi::SYS_ERR_PERMISSION
|
||||
show_stage(ls, heading, rc == montauk::CapabilityDenied
|
||||
? "Power control permission denied."
|
||||
: "Power control failed.");
|
||||
for (;;) montauk::sleep_ms(1000);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
extern "C" void _start() {
|
||||
montauk::print("Rebooting...\n");
|
||||
int rc = montauk::reset();
|
||||
if (rc == montauk::abi::SYS_ERR_PERMISSION)
|
||||
if (rc == montauk::CapabilityDenied)
|
||||
montauk::print("reset: permission denied\n");
|
||||
else
|
||||
montauk::print("reset: reboot failed\n");
|
||||
|
||||
@@ -194,7 +194,7 @@ static int process_command(const char* line) {
|
||||
: montauk::abi::POWER_REQ_SHUTDOWN;
|
||||
int rc = montauk::power_request(action);
|
||||
if (rc == 0) montauk::exit(0);
|
||||
montauk::print(rc == montauk::abi::SYS_ERR_PERMISSION
|
||||
montauk::print(rc == montauk::CapabilityDenied
|
||||
? "power: permission denied\n"
|
||||
: "power: request failed\n");
|
||||
return 1;
|
||||
@@ -202,7 +202,7 @@ static int process_command(const char* line) {
|
||||
|
||||
if (streq(cmd, "suspend")) {
|
||||
int rc = montauk::suspend();
|
||||
if (rc == montauk::abi::SYS_ERR_PERMISSION)
|
||||
if (rc == montauk::CapabilityDenied)
|
||||
montauk::print("suspend: permission denied\n");
|
||||
return rc == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user