94 points · by stevekemp · 6mo ago · 30 comments
Um, see The Second System Effect.
I also liked the color scheme.
[…]
mmap is awesome but Linux's got something even more awesome: mremap, which makes it almost trivial to manage the page-based heap.“*
⇒ they are using “freestanding” in a non-standard way. Usually, it means running on bare metal without an OS (https://en.wikipedia.org/wiki/Standalone_program: “A standalone program, also known as a freestanding program, is a computer program that does not load any external module, library function or program and that is designed to boot with the bootstrap procedure of the target processor – it runs on bare metal”
It's true that lone doesn't run on bare metal. I chose Linux for pragmatic and philosophical reasons. I'm not sure lone would ever have printed hello world if I hadn't chosen to build on top of Linux, which is also the only kernel with a stable binary interface. No other system lets you avoid the libc.
The reverse (running on bare metal and tweaking an existing malloc to run on it) looks way more logical to me.
> No other system lets you avoid the libc.
On most OSes [1] it’s relatively easy to write a libOS that just wraps the system calls. Your only dependency would be on the mapping to syscall numbers.
[1] OpenBSD is/may be (I don’t know the status of these) an exception. See https://man.openbsd.org/pinsyscalls.2, https://lwn.net/Articles/949078/
These are unstable in every operating system other than Linux.
I've written about it:
https://www.matheusmoreira.com/articles/linux-system-calls
Linux is the only kernel that promises stability in this area. On every other operating system, one must program against the system libraries.
"C built to compile with freestanding mode", rather than "C built to run bare metal".
[0] https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#in...
I only wish I could be as diligent and focused to do a thing like this, because I think it would be so much fun. I bought the Crafting Interpreters book a while ago, but still haven't got time to actually go through with it.
Well, maybe one day...
https://en.wikipedia.org/wiki/Heap_(data_structure)
That is indeed nowhere to be found in the article. Heap is also used to refer to dynamically allocated memory, which used to be implemented via a heap segment.
When they were doing a linear scan to find a large enough free block I was waiting for a heap to come into the picture, but apparently it’s not done that way.
Maybe actual heaps were used to implement this at some point. To be perfectly honest, I'm not sure.