Kernel Allocations That Are Allowed to Fail
In ordinary Rust, asking for memory either succeeds or crashes the program, which is unacceptable inside an operating system that must survive running out of memory. The kernel therefore provides its own owning box and growable vector types whose creating and growing operations return a Result you have to handle, and there is deliberately no infallible constructor to reach for. Every allocation also takes a flag saying how hard the kernel may work to satisfy it. This turns the C bug of an unchecked allocation returning null, then being dereferenced, into a compile-time obligation.
Questions this Concept answers
- Why does the kernel crate deliberately offer no infallible constructor for its owning box and vector types?
This Concept is waiting for its first lesson!
In ordinary Rust, asking for memory either succeeds or crashes the program, which is unacceptable inside an operating system that must survive running out of memory. The kernel therefore provides its own owning box and growable vector types whose creating and growing operations return a Result you have to handle, and there is deliberately no infallible constructor to reach for. Every allocation also takes a flag saying how hard the kernel may work to satisfy it. This turns the C bug of an unchecked allocation returning null, then being dereferenced, into a compile-time obligation.
Are you a teacher? Sign in to start contributing.
Sign In