Safe System Programming

This is the home page for the "Safe System Programming" course. Here, you will find (in a badly-organised form) all the material, slides, and information needed to attend the course

For the previous edition of the course, check the old websites (2020 or 2022).


Ideas about Possible Projects for the Exam

Links and other teaching material:

Here is a paper comparing the performance of user-space device drivers written in different languages.

In order to better understand Rust and some aspects of its design, it is important to know some concepts about programming languages (not directly related to Rust or to safe programming languages, but applicable to many different programming languages). Here is a simple document (in Italian) defining some of these important concepts.

The "inventor or NULL" apologizes for his billion dollar mistake (and here is a video of the presentation). Seriously speaking, the existence of NULL pointers/references can lead to many programming errors, and safe languages should not allow them; the solution to this issue is provided by the option types ("Nothing" cannot be dereferenced, and trying to dereference it results in a build-time error!).

Here is an example of NULL pointer derefencing in Java.

To understand where Rust's concept of ownership (and the move semantics) come from, have a look at Linear Types

On the internet it is possible to find a huge amount of tutorial showing how to write kernels, hypervisors or bare-metal applications in Rust. For example, look at Philipp Oppermann's blog (note: in the example showed during the course, Rust is used to code a library that is linked to some startup code written in Assembly; in the current version of the blog, Rust is used to write the main application, using a "bootloader" crate. The blog uses cargo --- in particular, cargo xbuild --- to cross-compile bare-metal Rust applications). The new version of the blog will show how to build and boot UEFI applications using rust. Other useful links can be toyos-rs and eduOS-rs.

Interesting news: QEMU developers are thinking about moving QEMU to Rust.

Check the infrastructure for building user-space VMMs in Rust.

Check the infrastructure for writing Linux kernel modules in Rust.

How to install Rust

The simplest way to install a Rust compiler is to use rustup: curl --proto '=https' --tlsv1.2 -sSf | sh.

For other possible installation methods, use the OS package manager or see the Rust installation page.

Code examples:

First of all, some examples about safety: we all know that C is not a safe programming language, as shown by this example about out-of-boud access to an array, or by this example about a bad printf usage. Languages like C++ introduce a vector type to (partly) address some issues. Here is how Rust address the previous issues: print and array.

Some more examples about Rust. Notice that the return type of the main() function is omitted (a function returns a "unit" value by default) and notice the ";" after "println!()" (can it be omitted?).

Some examples about ownership and move semantics in Rust (do not care about syntax, Box, and new yet):

Some examples about Rust's data types:

More complex examples:

And now, some examples about smart pointers:

Some experiments implementing lists in Rust (see this tutorial for a more detailed description of more appropriate approaches):

Examples about functions and closures:

Some final examples, about threads:

How to use the Option type, with some simplifications.

Very simple kernel written in Rust, and a similar one based on UEFI.