Maestro, a kernel and a Unix-like OS written from scratch in Rust

Teacher

Maestro screenshot

Rust has gained enough popularity to such a degree that it has become one of those chosen to be integrated as a secondary language in Linux, as well as in other operating systems, such is the case of Android, which already has part of the code in Rust, Windows that also has given the approval, among others.

Peace has proven to be a robust language and has generated such trust Some operating systems have even been created with this programming language and just to mention a few we have: Redox, We also have Kernels written from scratch such as Kerla or the Kernel used in the satellite that China recently launched.

The reason for mentioning this is that I recently came across a piece of news that caught my attention and that is that A project was presented in which a Kernel written in Rust is developed and which is partially compatible with Linux.

The name of this project is "Teacher" and as mentioned, is a Unix-like kernel written in Rust implementing a subset of system calls from the Linux kernel sufficient to create standard work environments. As such, the "Maestro" project is not something new, since the developer mentions that the project was born in 2018, but at that time it was written in C and due to the different benefits and characteristics of Rust, the project was rewritten from zero.

On the project page The reasons for the change are described:

At that moment I decided to switch to Rust (my first project in this language), which represented several advantages:

  • Restart the project from the beginning, using lessons learned from previous mistakes.
  • Be a little more innovative than just writing a Linux-like kernel in C. After all, just use Linux at the time.
  • Use the security of the Rust language to take advantage of some kernel programming difficulties. Using the Rust writing system allows you to transfer some of the responsibility for memory safety from the programmer to the compiler.

In kernel development, debugging is very difficult for several reasons:

  • Documentation is often difficult to find and BIOS implementations can be buggy (more often than you think).
  • At boot, the kernel has full access to memory and can write where it shouldn't (its own code, for example).
  • Troubleshooting memory leaks is not easy. Tools like valgrind cannot be used.
  • gdb can be used with QEMU and VMWare, but the kernel may behave differently when run on a different emulator or virtual machine. Also, those emulators may not support gdb (e.g. VirtualBox).
  • Some features are missing from gdb support in QEMU or VMWare and gdb may even crash sometimes

In relation to characteristics of the project, it stands out that the Kernel is monolithic and is currently only supported on x86 systems in 32-bit mode. The kernel code base covers about 49 thousand lines, being executable both on real hardware and in virtualized environments, such as QEMU or VirtualBox.

In the current development of «Maestro», 31% have been implemented (135 of 437) of Linux system calls. This is enough to load a console environment based on Bash and the Musl standard C library. Additionally, the Maestro-based environment can run some utilities from the GNU coreutils suite and basic packaging from any Unix system. Currently, work is being done on implementing a networking stack and work is also being done on developing an

Among the Maestro's available features stand out the following::

  • Controllers for PS/2 keyboard and terminal with text mode and partial support for ANSI sequences.
  • Memory allocation system with support for virtual memory.
  • Task scheduler based on the round-robin algorithm with support for POSIX signals.
  • Definition of PCI devices.
  • IDE/PATA controller.
  • Ext2 file system.
  • Support for /tmp and /proc virtual file systems.
  • Ability to mount FS, MBR and GPT disk partitions.
  • initramfs support.
  • RTC controller for timer and precise time.
  • Support for loading kernel modules.
  • Ability to run executable files in ELF format.

For interested in learning a little more about the project, you can check the details In the following link.  As for those interested in the project code, they should know that it is distributed under the MIT license.