feat: make userspace StatusCodes positive; print status text along with code in shell exec; make init return BadInvocation on faulty launch

This commit is contained in:
daniel committed 2026-09-30 16:21:32 +02:00
1 parent 8a3ffb2be1
commit 5e4e8902c2
6 files changed
+96 -41

No files matched your search

+72 -18
View File
@@ -6,29 +6,83 @@
#pragma once
// Userspace mirror of kernel/src/Common/StatusCodes.hpp. Also usable from C
// (the libc includes it), where the enumerators are unqualified.
// Userspace status codes.
// Analogous to kernel/src/Common/StatusCodes.hpp, but positive numbers are used.
#ifdef __cplusplus
namespace montauk {
#endif
enum StatusCodes {
typedef enum {
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
};
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
} StatusCodes;
inline const char* GetStatusText(StatusCodes statusCode) {
const char* statusText[] = {
"Success", // 0
"Generic failure", // 1
"Permission denied", // 2
"Capability denied", // 3
"System integrity error", // 4
"Bad pointer", // 5
"Invalid argument", // 6
"Unsupported operation", // 7
"No device", // 8
"I/O failure", // 9
"Bad invocation", // 10
"No such path", // 11
"Busy", // 12
"Buffer too small", // 13
"Out of memory", // 14
};
if (statusCode > 0 && statusCode <= 14) {
return statusText[statusCode];
} else {
return "Unknown error";
}
}
inline const char* GetStatusExplanationText(StatusCodes statusCode) {
const char* explanationText[] = {
nullptr, // 0
nullptr, // 1
nullptr, // 2
nullptr, // 3
"The path is protected by the system and can't be modified.", // 4
nullptr, // 5
nullptr, // 6
nullptr, // 7
nullptr, // 8
nullptr, // 9
nullptr, // 10
nullptr, // 11
nullptr, // 12
"The buffer supplied by the caller is too small.", // 13
nullptr, // 14
};
if (statusCode > 0 && statusCode <= 14) {
if (explanationText[statusCode] != nullptr) {
return explanationText[statusCode];
}
}
return GetStatusText(statusCode);
}
#ifdef __cplusplus
}
+2 -1
View File
@@ -8,6 +8,7 @@
#include <montauk/syscall.h>
#include <montauk/config.h>
#include <montauk/capabilities.h>
#include <montauk/statuscodes.h>
#include <libc/stdio.h>
// ---- ANSI color codes ----
@@ -204,7 +205,7 @@ const char* getReleaseString(char* buffer, int n) {
extern "C" void _start() {
if (system_already_initialized()) {
montauk::exit(1);
montauk::exit(montauk::StatusCodes::BadInvocation);
}
char releaseString[128] = "";
+13 -1
View File
@@ -17,7 +17,9 @@ static bool file_exists(const char* path) {
// ---- Try to spawn an ELF at the given path ----
static void print_exit_code(int code) {
static void print_exit_code(const int exitCode) {
int code = exitCode;
if (code == 0) return;
char buf[16];
int n = 0;
@@ -36,6 +38,16 @@ static void print_exit_code(int code) {
char c[2] = { buf[--n], 0 };
montauk::print(c);
}
if (exitCode > 0 && exitCode <= 14) { // 0-14 - current range of status codes within StatusCodes enum
const char* statusText = montauk::GetStatusText((montauk::StatusCodes)exitCode);
if (statusText != nullptr) {
montauk::print(" - ");
montauk::print(statusText);
}
}
montauk::print("]\n");
}