diff --git a/osdk/tests/examples_in_book/write_a_kernel_in_100_lines_templates/lib.rs b/osdk/tests/examples_in_book/write_a_kernel_in_100_lines_templates/lib.rs index 889779f7b..52dde2534 100644 --- a/osdk/tests/examples_in_book/write_a_kernel_in_100_lines_templates/lib.rs +++ b/osdk/tests/examples_in_book/write_a_kernel_in_100_lines_templates/lib.rs @@ -13,7 +13,8 @@ use alloc::vec; use ostd::arch::qemu::{exit_qemu, QemuExitCode}; use ostd::cpu::UserContext; use ostd::mm::{ - FrameAllocOptions, PageFlags, Vaddr, VmIo, VmMapOptions, VmSpace, VmWriter, PAGE_SIZE, + CachePolicy, FrameAllocOptions, PageFlags, PageProperty, Vaddr, VmIo, VmSpace, VmWriter, + PAGE_SIZE, }; use ostd::prelude::*; use ostd::task::{Task, TaskOptions}; @@ -32,8 +33,8 @@ pub fn main() { } fn create_user_space(program: &[u8]) -> UserSpace { + let nframes = program.len().align_up(PAGE_SIZE) / PAGE_SIZE; let user_pages = { - let nframes = program.len().align_up(PAGE_SIZE) / PAGE_SIZE; let vm_frames = FrameAllocOptions::new(nframes).alloc().unwrap(); // Phyiscal memory pages can be only accessed // via the Frame abstraction. @@ -45,11 +46,15 @@ fn create_user_space(program: &[u8]) -> UserSpace { // The page table of the user space can be // created and manipulated safely through - // the VmSpace abstraction. + // the `VmSpace` abstraction. let vm_space = VmSpace::new(); - let mut options = VmMapOptions::new(); - options.addr(Some(MAP_ADDR)).flags(PageFlags::RWX); - vm_space.map(user_pages, &options).unwrap(); + let mut cursor = vm_space + .cursor_mut(&(MAP_ADDR..MAP_ADDR + nframes * PAGE_SIZE)) + .unwrap(); + let map_prop = PageProperty::new(PageFlags::RWX, CachePolicy::Writeback); + for frame in user_pages { + cursor.map(frame, map_prop); + } Arc::new(vm_space) }; let user_cpu_state = { diff --git a/tools/format_all.sh b/tools/format_all.sh index c66baa29f..eaf54478a 100755 --- a/tools/format_all.sh +++ b/tools/format_all.sh @@ -29,6 +29,14 @@ else cargo fmt fi +# Format the 100-line kernel demo as well +KERNEL_DEMO_FILE="$WORKSPACE_ROOT/osdk/tests/examples_in_book/write_a_kernel_in_100_lines_templates/lib.rs" +if [ "$CHECK_MODE" = true ]; then + cargo fmt --check -- $KERNEL_DEMO_FILE +else + cargo fmt -- $KERNEL_DEMO_FILE +fi + for CRATE in $EXCLUDED_CRATES; do CRATE_DIR="$WORKSPACE_ROOT/$CRATE"