Skip to content

Commit

Permalink
kthd: stub for message handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Sep 30, 2024
1 parent 6fadebd commit 5833ef3
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion kthd/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,42 @@
* kthd: Kernel Thread Helper Daemon
*/

#include <liblux/liblux.h>
#include <stdlib.h>

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);
}
}
}
}

0 comments on commit 5833ef3

Please sign in to comment.