66 lines
2.0 KiB
C++
66 lines
2.0 KiB
C++
#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
|
|
|
|
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) {
|
|
// Query real thread count from kernel
|
|
thread_info_t list[16];
|
|
register uint64_t rax __asm__("rax") = SYS_PROC_LIST;
|
|
register uint64_t rdi __asm__("rdi") = (uint64_t)list;
|
|
register uint64_t rsi __asm__("rsi") = 16;
|
|
__asm__ volatile("syscall" : "+r"(rax) : "r"(rdi), "r"(rsi) : "rcx", "r11", "memory");
|
|
reply_val0 = (rax > 0) ? rax : 0;
|
|
reply_val1 = 0;
|
|
} else {
|
|
reply_val0 = 0;
|
|
reply_val1 = 0;
|
|
}
|
|
} else {
|
|
last_client = 0;
|
|
sys_yield();
|
|
}
|
|
}
|
|
}
|