OS in Rust
malloc stands eternal
malloc I think.stdx86-64 - the Intel/AMD architecture common for Linux and Windows - supports a “long double” float with 80 bits of precision.ARM64 - a competing formulation most popularized as “Apple silicon” with the M1 - lacks long doubles.stdoption and result
option and result:stdmalloc!These features make it possible to write a kernel in a very expressive, high level way without worrying about undefined behavior or memory safety.
no_stdlibc, which closely interacts with OS services.
no_stdno_std attribute.
32,42 etc.)git branch to create different developmental branches.osirs (OS in Rust) sounded heckin’ rad.![]()
Cargo.toml contains the crate configuration
src/main.rs file contains our main function.cargo build, find the compiled osirs binary in the target/debug subfolder.$ cargo build ; tree
Compiling osirs v0.1.0 (/home/user/tmp/32)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.54s
.
├── Cargo.lock
├── Cargo.toml
├── src
│ └── main.rs
└── target
├── CACHEDIR.TAG
└── debug
├── build
├── deps
│ ├── osirs-43412975b38d059d
│ └── osirs-43412975b38d059d.d
├── examples
├── incremental
│ └── osirs-3gae52yq1943v
│ ├── s-hfeunnoewq-0c8luu5-5dmhke08rl6h5l09ku3va3gkx
│ │ ├── 1tq3ts5gahvv7j1hzrmfdrzi6.o
│ │ ├── 6zk3flo890c0qhh6fykb6746g.o
│ │ ├── 8z45o15v3gxm5hydv3o63x07l.o
│ │ ├── 9itjtn00r7d8c6mknmav20oex.o
│ │ ├── bh9pj42wzikjd1ilqutnjbrx7.o
│ │ ├── dep-graph.bin
│ │ ├── eymyqxruzdb24suchgzd8ygxb.o
│ │ ├── query-cache.bin
│ │ └── work-products.bin
│ └── s-hfeunnoewq-0c8luu5.lock
├── osirs
└── osirs.d
9 directories, 18 filescargo run or even cargo run --releasebuild and then directly run the executable.no_std Attributeno_std attribute to src/main.rs to get the version of Rust that builds character!$ cargo build
Compiling osirs v0.1.0 (/home/user/tmp/32)
error: cannot find macro `println` in this scope
--> src/main.rs:6:5
|
6 | println!("ʙᴏᴡ ᴅᴏᴡɴ ʙᴇғᴏʀᴇ ᴛʜᴇ ɢᴏᴅ ᴏғ ᴅᴇᴀᴛʜ");
| ^^^^^^^
error: `#[panic_handler]` function required, but not found
error: unwinding panics are not supported without std
|
= help: using nightly cargo, use -Zbuild-std with panic="abort" to avoid unwinding
= note: since the core library is usually precompiled with panic="unwind", rebuilding your crate with panic="abort" may not be enough to fix the problem
error: could not compile `osirs` (bin "osirs") due to 3 previous errors ^^^^^^^error: cannot find macro `println` in this scope
--> src/main.rs:6:5
|
6 | println!("ʙᴏᴡ ᴅᴏᴡɴ ʙᴇғᴏʀᴇ ᴛʜᴇ ɢᴏᴅ ᴏғ ᴅᴇᴀᴛʜ");
| ^^^^^^^println macro is part of the standard library std.no_std.$ cargo build
Compiling osirs v0.1.0 (/home/user/tmp/32)
error: `#[panic_handler]` function required, but not found
error: unwinding panics are not supported without std
|
= help: using nightly cargo, use -Zbuild-std with panic="abort" to avoid unwinding
= note: since the core library is usually precompiled with panic="unwind", rebuilding your crate with panic="abort" may not be enough to fix the problem
error: could not compile `osirs` (bin "osirs") due to 2 previous errorserror: cannot find macro `println` in this scope
--> src/main.rs:6:5
|
6 | println!("ʙᴏᴡ ᴅᴏᴡɴ ʙᴇғᴏʀᴇ ᴛʜᴇ ɢᴏᴅ ᴏғ ᴅᴇᴀᴛʜ");
| ^^^^^^^std and is sad 😭panic_handler attribute defines the function that the compiler should invoke when a panic occurs.std provides its own panic handler function, but in a no_std environment we need to define it ourselves:PanicInfo parameter contains:
panic!("YOLO")!.$ cargo build
Compiling osirs v0.1.0 (/home/user/tmp/32)
error: unwinding panics are not supported without std
|
= help: using nightly cargo, use -Zbuild-std with panic="abort" to avoid unwinding
= note: since the core library is usually precompiled with panic="unwind", rebuilding your crate with panic="abort" may not be enough to fix the problem
error: could not compile `osirs` (bin "osirs") due to 1 previous error![]()
“The point of this joke is even more important now than it was when I first wrote it,” [Free Software Foundation president] Stallman wrote in a note posted to project mailing list, in reference to today’s political climate. “Please do not remove it. GNU is not a purely technical project, so the fact that this is not strictly and grimly technical is not a reason to remove this.”
= help: using nightly cargo, use -Zbuild-std with panic="abort" to avoid unwinding
= note: since the core library is usually precompiled with panic="unwind", rebuilding your crate with panic="abort" may not be enough to fix the problempanic="abort" syntax.tomlCargo.tomlThis sets the panic strategy to abort for both the dev profile (used for cargo build) and the release profile (used for cargo build --release).
I bet it will work now.
$ cargo build
Compiling osirs v0.1.0 (/home/user/tmp/32)
error: using `fn main` requires the standard library
|
= help: use `#![no_main]` to bypass the Rust generated entrypoint and declare a platform specific entrypoint yourself, usually with `#[no_mangle]`
error: could not compile `osirs` (bin "osirs") due to 1 previous errormain!