mirror of
https://github.com/Leonmmcoset/cleonos.git
synced 2026-04-24 11:14:01 +00:00
吐槽
This commit is contained in:
@@ -11,10 +11,13 @@
|
||||
#include <clks/types.h>
|
||||
#include <clks/tty.h>
|
||||
|
||||
/* Process runtime core: this is where tiny mistakes become giant explosions. */
|
||||
|
||||
typedef u64 (*clks_exec_entry_fn)(void);
|
||||
|
||||
#define CLKS_EXEC_RUN_STACK_BYTES (1024ULL * 1024ULL)
|
||||
#define CLKS_EXEC_MAX_PROCS 64U
|
||||
/* 64 is a compromise: enough to be useful, small enough to not eat RAM for breakfast. */
|
||||
#define CLKS_EXEC_MAX_DEPTH 16U
|
||||
#define CLKS_EXEC_PATH_MAX 192U
|
||||
#define CLKS_EXEC_ARG_LINE_MAX 256U
|
||||
@@ -206,6 +209,7 @@ static void clks_exec_serial_write_hex64(u64 value) {
|
||||
}
|
||||
|
||||
static void clks_exec_log_info_serial(const char *message) {
|
||||
/* Serial logs stay because they save our ass when TTY is dead. */
|
||||
if (CLKS_CFG_EXEC_SERIAL_LOG == 0) {
|
||||
(void)message;
|
||||
return;
|
||||
@@ -886,6 +890,7 @@ static i32 clks_exec_proc_find_slot_by_pid(u64 pid) {
|
||||
static i32 clks_exec_proc_alloc_slot(void) {
|
||||
u32 i;
|
||||
|
||||
/* First pass: find free slot. Second pass: recycle corpses. Brutal but effective. */
|
||||
for (i = 0U; i < CLKS_EXEC_MAX_PROCS; i++) {
|
||||
if (clks_exec_proc_table[i].used == CLKS_FALSE) {
|
||||
return (i32)i;
|
||||
@@ -1569,6 +1574,7 @@ static clks_bool clks_exec_dispatch_pending_once(void) {
|
||||
return CLKS_FALSE;
|
||||
}
|
||||
|
||||
/* One pending process per tick keeps latency sane and avoids scheduler chaos. */
|
||||
for (i = 0U; i < CLKS_EXEC_MAX_PROCS; i++) {
|
||||
if (clks_exec_proc_table[i].used == CLKS_TRUE && clks_exec_proc_table[i].state == CLKS_EXEC_PROC_PENDING) {
|
||||
u64 ignored_status = (u64)-1;
|
||||
@@ -1600,6 +1606,7 @@ static clks_bool clks_exec_run_path_internal(const char *path, const char *argv_
|
||||
*out_pid = (u64)-1;
|
||||
}
|
||||
|
||||
/* Count every request, even bad ones, so metrics don't lie to our face. */
|
||||
clks_exec_requests++;
|
||||
|
||||
if (path == CLKS_NULL || path[0] != '/') {
|
||||
@@ -2701,6 +2708,7 @@ u64 clks_exec_yield(void) {
|
||||
|
||||
void clks_exec_tick(u64 tick) {
|
||||
(void)tick;
|
||||
/* Background pump: boring, repetitive, absolutely necessary. */
|
||||
(void)clks_exec_dispatch_pending_once();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include <clks/userland.h>
|
||||
#include <cleonos_version.h>
|
||||
|
||||
/* Yes, this file is a syscall kitchen sink and nobody is pretending otherwise. */
|
||||
|
||||
#define CLKS_SYSCALL_LOG_MAX_LEN 191U
|
||||
#define CLKS_SYSCALL_PATH_MAX 192U
|
||||
#define CLKS_SYSCALL_NAME_MAX 96U
|
||||
@@ -180,6 +182,7 @@ static inline void clks_syscall_outw(u16 port, u16 value) {
|
||||
#endif
|
||||
|
||||
static clks_bool clks_syscall_in_user_exec_context(void) {
|
||||
/* If this says "no", we're basically in trust-me-bro kernel mode. */
|
||||
return (clks_exec_is_running() == CLKS_TRUE && clks_exec_current_path_is_user() == CLKS_TRUE) ? CLKS_TRUE
|
||||
: CLKS_FALSE;
|
||||
}
|
||||
@@ -215,6 +218,7 @@ static clks_bool clks_syscall_copy_user_string(u64 src_addr, char *dst, usize ds
|
||||
return CLKS_FALSE;
|
||||
}
|
||||
|
||||
/* Byte-by-byte copy is slow as hell, but crashing on bad pointers is worse. */
|
||||
while (i + 1U < dst_size) {
|
||||
u64 char_addr = src_addr + (u64)i;
|
||||
char ch;
|
||||
@@ -263,6 +267,7 @@ static u64 clks_syscall_copy_text_to_user(u64 dst_addr, u64 dst_size, const char
|
||||
|
||||
copy_len = src_len;
|
||||
|
||||
/* Leave room for NUL, because "almost a string" is just pain. */
|
||||
if (copy_len + 1U > (usize)dst_size) {
|
||||
copy_len = (usize)dst_size - 1U;
|
||||
}
|
||||
@@ -469,6 +474,7 @@ static u64 clks_syscall_fb_blit(u64 arg0) {
|
||||
}
|
||||
|
||||
static u64 clks_syscall_kernel_version(u64 arg0, u64 arg1) {
|
||||
/* Version query: tiny syscall, huge bike-shed potential. */
|
||||
usize len = clks_strlen(CLKS_VERSION_STRING);
|
||||
return clks_syscall_copy_text_to_user(arg0, arg1, CLKS_VERSION_STRING, len);
|
||||
}
|
||||
@@ -2343,6 +2349,7 @@ u64 clks_syscall_dispatch(void *frame_ptr) {
|
||||
return (u64)-1;
|
||||
}
|
||||
|
||||
/* Giant switch, yeah. Ugly, explicit, and easy to grep at 3 AM. */
|
||||
switch (id) {
|
||||
case CLKS_SYSCALL_LOG_WRITE:
|
||||
return clks_syscall_log_write(frame->rbx, frame->rcx);
|
||||
|
||||
Reference in New Issue
Block a user