From 5833ef3971ad4818e5e4ca49d06128f0921f3e0f Mon Sep 17 00:00:00 2001 From: jewelcodes Date: Mon, 30 Sep 2024 17:57:00 -0400 Subject: [PATCH] kthd: stub for message handling --- kthd/src/main.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/kthd/src/main.c b/kthd/src/main.c index ae6b580..4566fb8 100644 --- a/kthd/src/main.c +++ b/kthd/src/main.c @@ -5,6 +5,42 @@ * kthd: Kernel Thread Helper Daemon */ +#include +#include + int main() { - return 0; // stub + luxInit("kthd"); + + SyscallHeader *msg = calloc(1, sizeof(SyscallHeader)); + if(!msg) { + luxLogf(KPRINT_LEVEL_ERROR, "unable to allocate memory for message handling\n"); + return -1; + } + + // notify lumen that we're ready + // there isn't anything to do until we receive requests + luxReady(); + + for(;;) { + // receive requests from lumen + ssize_t s = luxRecvLumen(msg, SERVER_MAX_SIZE, false, true); + if(s > 0 && s <= SERVER_MAX_SIZE) { + if(msg->header.length > SERVER_MAX_SIZE) { + void *newptr = realloc(msg, msg->header.length); + if(!newptr) { + luxLogf(KPRINT_LEVEL_ERROR, "unable to allocate memory for message handling\n"); + return -1; + } + + msg = newptr; + } + + luxRecvLumen(msg, SERVER_MAX_SIZE, false, false); + + switch(msg->header.command) { + default: + luxLogf(KPRINT_LEVEL_WARNING, "unimplemented command 0x%04X, dropping message...\n", msg->header.command); + } + } + } } \ No newline at end of file