#include "ipc.hpp" #include "stdio.h" #include "string.h" #include "abi/syscalls.h" #define PROCMGR_ENDPOINT 4 #define PROC_OP_LIST 1 #define PROC_OP_KILL 2 #define PROC_OP_SPAWN 3 #define PROC_OP_STAT 4 struct ProcessInfo { uint64_t pid; char name[32]; uint32_t state; // 0=Running, 1=Sleeping, 2=Dead uint64_t mem_bytes; }; static __attribute__((unused)) ProcessInfo proc_table[8] = { { 0, "kernel_idle", 0, 4096 }, { 1, "init_server", 0, 65536 }, { 2, "uart_driver", 1, 65536 }, { 3, "sh", 0, 131072 }, { 4, "procmgr", 0, 65536 }, }; static size_t proc_count = 5; extern "C" void _start() { puts("[PROCMGR] Process & Server Manager Daemon Initialized (Ring 3)."); uint64_t last_client = 0; uint64_t reply_val0 = 0; uint64_t reply_val1 = 0; while (true) { uint64_t sender_tid = 0; uint64_t opcode = 0; uint64_t arg0 = 0; uint64_t arg1 = 0; sysret_t ret = sys_ipc_reply_recv_raw( PROCMGR_ENDPOINT, last_client, reply_val0, reply_val1, &sender_tid, &opcode, &arg0, &arg1 ); if (ret == 0 && sender_tid != 0) { last_client = sender_tid; if (opcode == PROC_OP_KILL) { // Terminate process with TID = arg0 register uint64_t rax __asm__("rax") = SYS_PROC_KILL; register uint64_t rdi __asm__("rdi") = arg0; __asm__ volatile("syscall" : "+r"(rax) : "r"(rdi) : "rcx", "r11", "memory"); reply_val0 = rax; // 0 = success, -1 = error reply_val1 = 0; } else if (opcode == PROC_OP_LIST) { reply_val0 = (uint64_t)proc_count; reply_val1 = 0; } else { reply_val0 = 0; reply_val1 = 0; } } else { last_client = 0; sys_yield(); } } }