2 ms·
Start using your operating system directly instead of relying on libraries to do things for you. Learn Linux system calls and use them for everything. A great w
by matheusmoreira 5y ago
Start using your operating system directly instead of relying on libraries to do things for you. Learn Linux system calls and use them for everything. A great way to do this is to compile your C code in freestanding mode and with no libc. You'll have to do everything yourself.
It is easy to get started. Here's a system call function for x86_64 Linux:
https://github.com/matheusmoreira/liblinux/blob/master/source/arch/x86_64/system_call.c https://github.com/matheusmoreira/liblinux/blob/master/sourc...
With this single function, it is possible to do anything. You can rewrite the entire Linux user space with this.
The Linux kernel itself has a nolibc.h file that they use for their own freestanding tools:
https://github.com/torvalds/linux/blob/master/tools/include/nolibc/nolibc.h https://github.com/torvalds/linux/blob/master/tools/include/...
It's even better than what I came up with. Permissively licensed. Supports lots of architectures. There's process startup code so you don't even need GCC's startfiles in order to have a normal main function. The only missing feature is the auxiliary vector. You can just include it and start using Linux immediately.
You can absolutely do this with Rust as well. Rust supports programming with no standard library. If I remember correctly, the inline assembly macros are still an unstable feature. It's likely to change in the future though.