feat: add SYS_FUTEX_WAIT and SYS_FUTEX_WAKE syscalls; revamp desktop application categories

This commit is contained in:
daniel committed 2026-10-13 07:11:39 +02:00
1 parent 60ca9c78c7
commit abfd9de8f6
35 files changed
+545 -70

No files matched your search

+9 -3
View File
@@ -27,7 +27,9 @@ typedef enum {
NoSuchPath = 11,
Busy = 12,
BufferTooSmall = 13,
OutOfMemory = 14
OutOfMemory = 14,
TimedOut = 15,
WouldBlock = 16
} StatusCode;
inline const char* GetStatusText(StatusCode statusCode) {
@@ -47,9 +49,11 @@ inline const char* GetStatusText(StatusCode statusCode) {
"Busy", // 12
"Buffer too small", // 13
"Out of memory", // 14
"Timed out", // 15
"Operation would block", // 16
};
if (statusCode > 0 && statusCode <= 14) {
if (statusCode > 0 && statusCode <= 16) {
return statusText[statusCode];
} else {
return "Unknown error";
@@ -74,9 +78,11 @@ inline const char* GetStatusExplanationText(StatusCode statusCode) {
0, // 12
"The buffer supplied by the caller is too small.", // 13
0, // 14
0, // 15
0, // 16
};
if (statusCode > 0 && statusCode <= 14) {
if (statusCode > 0 && statusCode <= 16) {
if (explanationText[statusCode] != 0) {
return explanationText[statusCode];
}
+22
View File
@@ -148,6 +148,28 @@ namespace montauk {
return (int)syscall0(montauk::abi::SYS_THREAD_SELF);
}
// Block while *addr == expected. Returns 0 when woken by futex_wake,
// WouldBlock if *addr had already changed, TimedOut when timeout_ns
// elapsed (FUTEX_WAIT_FOREVER = no deadline, 0 = check only, otherwise
// rounded up to the 1 ms tick). Futexes are private to the process.
// A 0 return is never spurious, but always re-check the condition.
inline int futex_wait(uint32_t* addr, uint32_t expected,
uint64_t timeout_ns = montauk::abi::FUTEX_WAIT_FOREVER) {
int64_t r = syscall3(montauk::abi::SYS_FUTEX_WAIT, (uint64_t)addr,
(uint64_t)expected, timeout_ns);
return r < 0 ? (int)-r : 0;
}
// Wake up to `count` waiters on addr, longest-waiting first. Returns the
// number woken, or a negative status for a bad address.
inline int futex_wake(uint32_t* addr, uint32_t count = 1) {
return (int)syscall2(montauk::abi::SYS_FUTEX_WAKE, (uint64_t)addr, (uint64_t)count);
}
inline int futex_wake_all(uint32_t* addr) {
return futex_wake(addr, montauk::abi::FUTEX_WAKE_ALL);
}
// Lightweight mutex backed by a single atomic word + the kernel
// yield syscall. Adequate for short critical sections; a heavier
// primitive can wrap mailbox_recv when blocking semantics are needed.