Philipp Oppermann's awesome [Writing an OS in Rust]
Current main.rs:
```rust
extern crate alloc; extern crate bootloader; extern crate rustos; extern crate x8664; use alloc::{boxed::Box, rc::Rc, vec, vec::Vec}; use bootloader::{entrypoint, BootInfo}; use core::panic::PanicInfo; use rustos::println;
entrypoint!(startkernel);
fn startkernel(bootinfo: &'static BootInfo) -> ! { println!("Welcome to the real world!");
// Initialize the kernel.
rustos::init();
rustos::memory::init(boot_info);
// Let's box it on heap!
let x = Box::new(41);
println!("x={:p}", x);
// and then vector!
let mut vec = Vec::new();
for i in 0..500 {
vec.push(i);
}
println!("vec at {:p}", vec.as_slice());
// now, a reference counted vector.
let reference = Rc::new(vec![1, 2, 3]);
let cloned = Rc::clone(&reference);
println!("current reference count is {}", Rc::strong_count(&cloned));
core::mem::drop(reference);
println!("reference count is {} now", Rc::strong_count(&cloned));
// Long lived many boxes allocation!
let long_lived = Box::new(1);
for i in 0..rustos::HEAP_SIZE {
let x = Box::new(i);
assert_eq!(*x, i);
}
assert_eq!(*long_lived, 1);
#[cfg(test)]
test_main();
println!("It did not crash!!!");
rustos::hlt_loop();
}
fn panic(info: &PanicInfo) -> ! { println!("{}", info); rustos::hlt_loop(); }
fn panic(info: &PanicInfo) -> ! { rustos::testpanichandler(info) } ```
You can run the current [main.rs] with make run
:
sh
make run
or the previous posts, e.g. [post01.rs] with make run-post_name
as:
sh
make run-post01
You can run all the integration test with make test
:
sh
make test
or specific tests with `make tsst-test_name as:
sh
make test-heap_allocation
Happy Hackin'!