Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Writing a Unix-Like OS in Rust (vmm.dev)
38 points by redbell on April 6, 2024 | hide | past | favorite | 5 comments


> Userland includes a library with usability similar to Rust's std, with Unix commands, including the shell, implemented using this library.

It's not clear to me if this is or isn't what octox is doing, but I always found it odd that unix tools weren't a thin wrapper over underlying libraries. Like, `mkdir foo` just calling (psudocode) `mkdir(name="foo", mode=0x0755);`


I’m a bit perplexed how you mean. Mkdir is a thin wrapper around `mkdir(const char*pathname, int mode)` from libc, or at least was before things like -p were added. Everything else is handling arguments and various failure modes. Famously /bin/true used to be an empty file with the executable bit set. Now, why exactly `ls` isn’t, or why `rm` was named unlink in the lib remains confusing, but the original commands were pretty much what you describe.


In simple terms, userland just issues syscalls to the kernel. For a command, this could be as straightforward as mkdir dir in the shell or mkdir("dir") in Rust code. While this seems simple, it's not particularly convenient. To enhance usability, we're modeling it after Rust's standard library. For example, having access to handy features like `DirBuilder` makes developing in userland more efficient (see https://doc.rust-lang.org/std/fs/struct.DirBuilder.html). Aligning with Rust's standard library has other benefits, too. One is the absorption of compatibility issues. Rust is compatible with various platforms, and handling compatibility at the level of the Rust standard library, rather than through syscalls or libc, can be more efficient. The goal is that Rust code used on one OS can be recompiled to work on my OS. From a unikernel perspective, recompilation is natural, and if we're only using Rust for development, it enhances safety. By the way, in my OS, libc does not exist. The user library, akin to Rust's std, acts entirely as a wrapper over syscalls.


A lot of the code in basic utilities like that is handling the command line and reporting errors. The standard ways of doing those tasks in Unix (e.g. getopt(3) and strerror(3)) are fairly limited.


cool project and nice reading! congrats!!




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: