Follow

Designed a kernel with only one system call, but the one system call is basically ioctl so it doesn’t really count.

I have now mostly implemented a userspace version of this kernel in C.

I didn't do it in Rust because C is faster for the prototyping of stupid and low-level ideas no one will actually use.

The basic idea has two parts:

1. Microkernel where communication with the kernel is also via message-passing, even for task and memory management.
2. Tight binding between IPC and CPU scheduling; each "port" has an associated function which runs when the port receives a packet. This is the only way of getting CPU time in userspace. A port can be set to get empty "idle" packets from the kernel.

There seems to be some interest in this. I’ll MIT the code and stick it on my GitLab (I’ll self-host Gitea or something at some point, but still on GL for now) once I have a working demo.

You don’t want to use this thing. free(buf) turns into

struct unmapspace_frm del = {
.frm = {
.dst = SPACEMGR,
.typid = UNMAPSPACE,
.frmsz = sizeof(unmapspace_frm),
.pktsz = sizeof(unmapspace_pkt)
},
.pkt = {
.here = buf
}
}
del.frm.data = &del.pkt;

send(&del);

I mean it could be improved with macros and wrapper functions but still.

It is very difficult to program when memory allocation is asynchronous.

It took me almost 40 lines across two functions to implement a single realloc.

Please never use this thing. I’ll post the code still, but please never use it for anything serious.

@wmww I think you should see this whole thread. It makes a good example of what happens when I let myself pursue my crazy spur-of-the-moment ideas.

@alexbuzzbee

Please come up with another word than, "port," otherwise that will be superconfusing forever. Cool project.

@alexbuzzbee It seems like async memory allocation would be like trying to install headlights while the car is driving. Am I wrong in that assumption? (I'm not good with lower level memory mechanics, just some basic C)

@ndegruchy It’s like if you drove by a gas station when your tank is nearly empty and they threw you a bottle which you then have to lean out the window and tip into the car while still driving.

@ndegruchy Except that it’s the passenger who asks for the gas and you don’t know it’s coming until the bottle flies through the window.

@ndegruchy Vaguely? It’s just generally a mess and involves a lot of nonintuitive control flow and crossed fingers. You have to know you’ll need the memory before you need it, and if you don’t, you have no choice but to error and hope the retry comes after the memory has arrived.

@alexbuzzbee Or maybe:

Me: Hey, can I have some memory?
Computer: Sure!
Me: Ok, so I'm putting some stuff in my memory!
Computer: Hol up.

Sign in to participate in the conversation
Fosstodon

Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.