Implementing our own fibers 113 We start off the example by enabling a specific feature we need, importing the asm macro, and defining a few constants: ch05/c-fibers/main. rs #![feature(naked_functions)] use std::arch::asm; const DEFAULT_STACK_SIZE: usize = 1024 * 1024 * 2; const MAX_THREADS: usize = 4; static mut RUNTIME: usize = 0; The feature we want to enable is called the naked_functions feature. Let's explain what a naked function is right away. Naked functions If you remember when we talked about the operating system ABI and calling conventions earlier, you probably remember that each architecture and OS have different requirements. This is especially important when creating new stack frames, which is what happens when you call a function. So, the compiler knows about what each architecture/OS requires and adjusts layout, and parameter placement on the stack and saves/restores certain registers to make sure we satisfy the ABI on the platform we're on. This happens both when we enter and exit a function and is often called a function prologue and epilogue. In Rust, we can enable this feature and mark a function as #[naked]. A naked function tells the compiler that we don't want it to create a function prologue and epilogue and that we want to take care of this ourselves. Since we do the trick where we return over to a new stack and want to resume the old one at a later point we don't want the compiler to think it manages the stack layout at these points. It worked in our first example since we never switched back to the original stack, but it won't work going forward. Our DEFAULT_STACK_SIZE is set to 2 MB, which is more than enough for our use. We also set MAX_THREADS to 4 since we don't need more for our example. The last static constant, RUNTIME, is a pointer to our runtime (yeah, I know, it's not pretty with a mutable global variable, but it's making it easier for us to focus on the important parts of the example later on). The next thing we do is set up some data structures to represent the data we'll be working with: pub struct Runtime { threads: Vec<Thread>, current: usize, }