feat: add userspace system logging, rename klog to syslog, rename relevant syscalls and API functions

This commit is contained in:
2026-08-14 18:37:27 +02:00
parent 8e45d43116
commit 724029cacb
26 changed files with 139 additions and 52 deletions
+1 -1
View File
@@ -12,4 +12,4 @@
#pragma once
#define MONTAUK_BUILD_NUMBER 120
#define MONTAUK_BUILD_NUMBER 141
+15 -2
View File
@@ -53,6 +53,8 @@ namespace montauk::abi {
static constexpr uint64_t kMaxWindowTitleBytes = 256;
static constexpr uint64_t kMaxHostnameBytes = 256;
static constexpr uint64_t kMaxUserNameBytes = 32;
static constexpr uint64_t kMaxUserspaceLogComponentNameBytes = 32;
static constexpr uint64_t kMaxUserspaceLogEntryBytes = 1024;
// ---- Dispatch ----
@@ -300,9 +302,9 @@ namespace montauk::abi {
case SYS_GETRANDOM:
if (!UserMemory::Range(frame->arg1, frame->arg2, true)) return -1;
return Sys_GetRandom((uint8_t*)frame->arg1, frame->arg2);
case SYS_KLOG:
case SYS_LOG:
if (!UserMemory::Range(frame->arg1, frame->arg2, true)) return -1;
return Kt::ReadKernelLog((char*)frame->arg1, frame->arg2);
return Kt::ReadKernelLogBuffer((char*)frame->arg1, frame->arg2);
case SYS_MOUSESTATE:
if (!UserMemory::Writable<MouseState>(frame->arg1)) return -1;
Sys_MouseState((MouseState*)frame->arg1);
@@ -609,6 +611,17 @@ namespace montauk::abi {
return Sys_ClipboardClear();
case SYS_INPUT_WAIT:
return (int64_t)Sys_InputWait(frame->arg1, frame->arg2);
case SYS_LOG_WRITE: { // "init" <---- component name (arg1)
// "started service ..." <---- log message (arg2)
if (!UserMemory::String(frame->arg1, kMaxUserspaceLogComponentNameBytes)
|| !UserMemory::String(frame->arg2, kMaxUserspaceLogEntryBytes)
) return -1;
Kt::UserspaceLogStream((const char*)frame->arg1) << (const char*)frame->arg2;
return 0;
}
default:
return -1;
}
+4 -1
View File
@@ -103,7 +103,7 @@ namespace montauk::abi {
/* Random.hpp */
static constexpr uint64_t SYS_GETRANDOM = 45;
static constexpr uint64_t SYS_KLOG = 46;
static constexpr uint64_t SYS_LOG = 46;
/* Mouse.hpp */
static constexpr uint64_t SYS_MOUSESTATE = 47;
@@ -157,6 +157,9 @@ namespace montauk::abi {
static constexpr uint64_t SYS_AUDIOWRITE = 82;
static constexpr uint64_t SYS_AUDIOCTL = 83;
/* Userspace log */
static constexpr uint64_t SYS_LOG_WRITE = 176;
// Audio control commands (for SYS_AUDIOCTL).
//
// Commands 0..3 act on the stream named by the handle argument.
+1 -1
View File
@@ -250,7 +250,7 @@ namespace Kt {
g_suppressKernelLog = false;
}
int64_t ReadKernelLog(char* buf, uint64_t size) {
int64_t ReadKernelLogBuffer(char* buf, uint64_t size) {
if (buf == nullptr || size == 0) return 0;
uint64_t toRead = g_klogCount;
+30 -2
View File
@@ -121,7 +121,7 @@ namespace Kt
// intentionally lock-free: a panic can occur while another CPU owns the
// terminal mutex, and the system is about to halt.
void EnablePanicOutput();
int64_t ReadKernelLog(char* buf, uint64_t size);
int64_t ReadKernelLogBuffer(char* buf, uint64_t size);
class KernelLogStream {
KernelOutStream localStream{};
@@ -151,7 +151,7 @@ public:
g_kernelLogDepth++;
componentName = desiredComponentName;
localStream << componentName << ": " << "[" << LogLevelToStringWithColor(level) << "] ";
localStream << "[kernel/" << componentName << "] " << LogLevelToStringWithColor(level) << ": ";
}
~KernelLogStream() {
@@ -168,6 +168,34 @@ public:
}
};
class UserspaceLogStream {
KernelOutStream localStream{};
const char* componentName = "";
public:
UserspaceLogStream(const char* desiredComponentName) {
g_termLock.Acquire();
g_kernelLogDepth++;
componentName = desiredComponentName;
localStream << "[userspace/" << componentName << "]" << ": ";
}
~UserspaceLogStream() {
localStream << newline;
g_kernelLogDepth--;
g_termLock.Release();
}
template<typename T>
UserspaceLogStream &operator<<(T item) {
localStream << item;
return *this;
}
};
};
extern Kt::KernelOutStream kout;