Smart pointer and more Rust code for the Linux kernel 6.14

The Linux-Rust team has implemented new functions for kernel version 6.14 that promise a more stable use of core functions.

listen Print view
Cancer and penguin

(Image: Bild erstellt mit KI fĂĽr iX)

1 min. read

Miguel Ojeda, the lead developer of Rust for Linux, has announced a number of new features for kernel 6.14 in an email to Linus Torvalds. He cites the introduction of a macro for smart pointers with Rust 1.84: derive(CoercePointee) as an “important milestone on the way to building a kernel that only uses stable Rust functions”.

With this macro, kernel functions use Rust libraries such as Arc in a stable way, which were previously only accessible insecurely. Ojeda cites the example in the mail:

fn f(p: &Arc<dyn Display>) {
           pr_info!("{p}\n");
       }

       let a: Arc<dyn Display> = Arc::new(42i32, GFP_KERNEL)?;
       let b: Arc<dyn Display> = Arc::new("hello there", GFP_KERNEL)?;

       f(&a); // Prints "42".
       f(&b); // Prints "hello there".

As further innovations, he lists the switch to user-defined integer types in the Foreign Function Interface (FFI) and the mapping of the types long to isize and char to u8.

Videos by heise

With Android in mind, the Rust team has introduced the environment variable PROCMACROLDFLAGS, which allows Rust's proc macros to use flags other than those specified when linking host programs. And for kernel builds under macOS, the team has adapted the naming conventions for dynamic libraries (for example so instead of dylib).

Other updates affect kernel crate modules in particular, for example types receives an improved version of ForeignOwnable::borrow_mut and alloc implements Display for Box and aligns the [code] debug implementation accordingly.

(who)

Don't miss any news – follow us on Facebook, LinkedIn or Mastodon.

This article was originally published in German. It was translated with technical assistance and editorially reviewed before publication.