Next Generation WASM Microkernel Operating System

rustfmt items (#506)

authored by

Jonas Kruckenberg and committed by
GitHub
2b675973 c7abfb41

+965 -709
+6 -3
build/toml-patch/src/lib.rs
··· 19 19 //! This crate exposes a single function [`merge_toml_documents`] which does 20 20 //! this for you! 21 21 22 - use eyre::{Result, bail, eyre}; 23 22 use std::collections::BTreeMap; 24 - use toml_edit::{visit::Visit, visit_mut::VisitMut}; 23 + 24 + use eyre::{Result, bail, eyre}; 25 + use toml_edit::visit::Visit; 26 + use toml_edit::visit_mut::VisitMut; 25 27 26 28 pub fn merge_toml_documents( 27 29 original: &mut toml_edit::DocumentMut, ··· 270 272 271 273 #[cfg(test)] 272 274 mod tests { 275 + use indoc::indoc; 276 + 273 277 use super::*; 274 - use indoc::indoc; 275 278 276 279 fn patch_and_compare(a: &str, b: &str, out: &str) { 277 280 let mut a: toml_edit::DocumentMut = a.parse().unwrap();
+6 -4
build/xtask/src/build.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use std::path::{Path, PathBuf}; 9 + use std::process::Command; 10 + 11 + use color_eyre::eyre::{Context, bail}; 12 + use tracing_core::LevelFilter; 13 + 8 14 use crate::Options; 9 15 use crate::profile::{LogLevel, Profile, RustTarget}; 10 16 use crate::tracing::{ColorMode, OutputOptions}; 11 17 use crate::util::KillOnDrop; 12 - use color_eyre::eyre::{Context, bail}; 13 - use std::path::{Path, PathBuf}; 14 - use std::process::Command; 15 - use tracing_core::LevelFilter; 16 18 17 19 const DEFAULT_KERNEL_STACK_SIZE_PAGES: u32 = 256; 18 20
+4 -2
build/xtask/src/cmds/build.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use std::path::PathBuf; 9 + 10 + use clap::{Parser, ValueHint}; 11 + 8 12 use crate::Options; 9 13 use crate::profile::Profile; 10 14 use crate::tracing::OutputOptions; 11 - use clap::{Parser, ValueHint}; 12 - use std::path::PathBuf; 13 15 14 16 #[derive(Debug, Parser)] 15 17 pub struct Cmd {
+4 -2
build/xtask/src/cmds/dist.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use std::path::PathBuf; 9 + 10 + use clap::{Parser, ValueHint}; 11 + 8 12 use crate::Options; 9 13 use crate::profile::Profile; 10 14 use crate::tracing::OutputOptions; 11 - use clap::{Parser, ValueHint}; 12 - use std::path::PathBuf; 13 15 14 16 #[derive(Debug, Parser)] 15 17 pub struct Cmd {
+6 -4
build/xtask/src/cmds/lldb.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::profile::Profile; 9 - use crate::tracing::OutputOptions; 10 - use crate::{Options, build, qemu}; 11 - use clap::{Parser, ValueHint}; 12 8 use std::path::PathBuf; 13 9 use std::process::{Command, Stdio}; 14 10 use std::{fs, thread}; 11 + 12 + use clap::{Parser, ValueHint}; 13 + 14 + use crate::profile::Profile; 15 + use crate::tracing::OutputOptions; 16 + use crate::{Options, build, qemu}; 15 17 16 18 #[derive(Debug, Parser)] 17 19 pub struct Cmd {
+4 -2
build/xtask/src/cmds/qemu.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use std::path::PathBuf; 9 + 10 + use clap::{Parser, ValueHint}; 11 + 8 12 use crate::profile::Profile; 9 13 use crate::tracing::OutputOptions; 10 14 use crate::{Options, qemu}; 11 - use clap::{Parser, ValueHint}; 12 - use std::path::PathBuf; 13 15 14 16 #[derive(Debug, Parser)] 15 17 pub struct Cmd {
+4 -2
build/xtask/src/cmds/run.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use std::path::PathBuf; 9 + 10 + use clap::{Parser, ValueHint}; 11 + 8 12 use crate::profile::Profile; 9 13 use crate::tracing::OutputOptions; 10 14 use crate::{Options, qemu}; 11 - use clap::{Parser, ValueHint}; 12 - use std::path::PathBuf; 13 15 14 16 #[derive(Debug, Parser)] 15 17 pub struct Cmd {
+9 -7
build/xtask/src/cmds/test.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use std::path::PathBuf; 9 + use std::process::ExitStatus; 10 + use std::time::Duration; 11 + 12 + use clap::{Parser, ValueHint}; 13 + use color_eyre::Help; 14 + use color_eyre::eyre::{Context, format_err}; 15 + use wait_timeout::ChildExt; 16 + 8 17 use crate::build::{Cargo, CrateToBuild}; 9 18 use crate::profile::{Architecture, Profile}; 10 19 use crate::tracing::OutputOptions; 11 20 use crate::util::KillOnDrop; 12 21 use crate::{Options, qemu}; 13 - use clap::{Parser, ValueHint}; 14 - use color_eyre::Help; 15 - use color_eyre::eyre::{Context, format_err}; 16 - use std::path::PathBuf; 17 - use std::process::ExitStatus; 18 - use std::time::Duration; 19 - use wait_timeout::ChildExt; 20 22 21 23 #[derive(Debug, Parser)] 22 24 pub struct Cmd {
+2 -1
build/xtask/src/main.rs
··· 26 26 mod tracing; 27 27 mod util; 28 28 29 + use std::path::PathBuf; 30 + 29 31 use clap::{Parser, Subcommand, ValueHint}; 30 32 use color_eyre::eyre::Result; 31 - use std::path::PathBuf; 32 33 #[derive(Debug, Parser)] 33 34 struct Xtask { 34 35 #[clap(subcommand)]
+3 -2
build/xtask/src/profile.rs
··· 7 7 8 8 #![allow(unused)] 9 9 10 - use color_eyre::eyre::{Context, bail, eyre}; 11 - use serde::Deserialize; 12 10 use std::collections::BTreeSet; 13 11 use std::fmt::{Display, Formatter}; 14 12 use std::hash::{DefaultHasher, Hasher}; 15 13 use std::path::{Path, PathBuf}; 14 + 15 + use color_eyre::eyre::{Context, bail, eyre}; 16 + use serde::Deserialize; 16 17 17 18 #[derive(Clone, Debug, Deserialize)] 18 19 #[serde(rename_all = "kebab-case", deny_unknown_fields)]
+5 -3
build/xtask/src/qemu.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::profile::{Architecture, Profile}; 9 - use crate::util::KillOnDrop; 10 - use clap::Parser; 11 8 use std::path::Path; 12 9 use std::process::{Command, Stdio}; 10 + 11 + use clap::Parser; 12 + 13 + use crate::profile::{Architecture, Profile}; 14 + use crate::util::KillOnDrop; 13 15 14 16 #[derive(Debug, Parser)] 15 17 pub struct QemuOptions {
+3 -2
build/xtask/src/tracing.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use std::fmt; 9 + use std::io::IsTerminal; 10 + 8 11 use clap::{ArgGroup, Args}; 9 12 use color_eyre::owo_colors; 10 13 use color_eyre::owo_colors::{OwoColorize, Style, style}; 11 14 use heck::ToTitleCase; 12 - use std::fmt; 13 - use std::io::IsTerminal; 14 15 use tracing_core::field::Visit; 15 16 use tracing_core::{Collect, Event, Field, Level}; 16 17 use tracing_subscriber::fmt::format::Writer;
+4 -2
kernel/src/allocator.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::mem::bootstrap_alloc::BootstrapAllocator; 9 - use crate::{INITIAL_HEAP_SIZE_PAGES, arch}; 10 8 use core::alloc::Layout; 11 9 use core::range::Range; 10 + 12 11 use loader_api::BootInfo; 13 12 use talc::{ErrOnOom, Span, Talc, Talck}; 13 + 14 + use crate::mem::bootstrap_alloc::BootstrapAllocator; 15 + use crate::{INITIAL_HEAP_SIZE_PAGES, arch}; 14 16 15 17 #[global_allocator] 16 18 static KERNEL_ALLOCATOR: Talck<spin::Mutex<()>, ErrOnOom> = Talc::new(ErrOnOom).lock();
+1
kernel/src/arch/riscv64/asid_allocator.rs
··· 8 8 use alloc::vec; 9 9 use alloc::vec::Vec; 10 10 use core::fmt; 11 + 11 12 use riscv::satp; 12 13 use spin::OnceLock; 13 14
+3 -1
kernel/src/arch/riscv64/block_on.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::state; 9 8 use alloc::sync::Arc; 10 9 use core::arch::asm; 11 10 use core::mem::ManuallyDrop; 12 11 use core::sync::atomic::{AtomicBool, Ordering}; 13 12 use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; 13 + 14 14 use cpu_local::cpu_local; 15 15 use futures::pin_mut; 16 16 use futures::task::WakerRef; 17 17 use riscv::sbi; 18 + 19 + use crate::state; 18 20 19 21 struct HartNotify { 20 22 hartid: usize,
+3 -1
kernel/src/arch/riscv64/device/clock.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::device_tree::Device; 9 8 use core::ptr; 10 9 use core::time::Duration; 10 + 11 11 use kasync::time::{Clock, NANOS_PER_SEC, RawClock, RawClockVTable}; 12 12 use riscv::sbi; 13 + 14 + use crate::device_tree::Device; 13 15 14 16 static CLOCK_VTABLE: RawClockVTable = 15 17 RawClockVTable::new(clone_raw, now_raw, schedule_wakeup_raw, drop_raw);
+6 -4
kernel/src/arch/riscv64/device/cpu.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch::device; 9 - use crate::device_tree::DeviceTree; 10 - use crate::irq::InterruptController; 11 - use bitflags::bitflags; 12 8 use core::cell::RefCell; 13 9 use core::fmt; 14 10 use core::str::FromStr; 11 + 12 + use bitflags::bitflags; 13 + 14 + use crate::arch::device; 15 + use crate::device_tree::DeviceTree; 16 + use crate::irq::InterruptController; 15 17 16 18 #[derive(Debug)] 17 19 pub struct Cpu {
+9 -7
kernel/src/arch/riscv64/device/plic.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch::PAGE_SIZE; 9 - use crate::device_tree::{Device, DeviceTree, IrqSource}; 10 - use crate::irq::{InterruptController, IrqClaim}; 11 - use crate::mem::{ 12 - AddressRangeExt, AddressSpaceRegion, Permissions, PhysicalAddress, with_kernel_aspace, 13 - }; 14 - use crate::util::either::Either; 15 8 use alloc::string::ToString; 16 9 use core::alloc::Layout; 17 10 use core::mem::{MaybeUninit, offset_of}; ··· 19 12 use core::ops::{BitAnd, BitOr, Not}; 20 13 use core::ptr; 21 14 use core::range::Range; 15 + 22 16 use fallible_iterator::FallibleIterator; 23 17 use static_assertions::const_assert_eq; 18 + 19 + use crate::arch::PAGE_SIZE; 20 + use crate::device_tree::{Device, DeviceTree, IrqSource}; 21 + use crate::irq::{InterruptController, IrqClaim}; 22 + use crate::mem::{ 23 + AddressRangeExt, AddressSpaceRegion, Permissions, PhysicalAddress, with_kernel_aspace, 24 + }; 25 + use crate::util::either::Either; 24 26 25 27 const MAX_CONTEXTS: usize = 64; 26 28
+7 -5
kernel/src/arch/riscv64/mem.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch::{mb, wmb}; 9 - use crate::mem::flush::Flush; 10 - use crate::mem::frame_alloc::{Frame, FrameAllocator}; 11 - use crate::mem::{PhysicalAddress, VirtualAddress}; 12 8 use alloc::vec; 13 9 use alloc::vec::Vec; 14 - use bitflags::bitflags; 15 10 use core::num::NonZeroUsize; 16 11 use core::ptr::NonNull; 17 12 use core::range::{Range, RangeInclusive}; 18 13 use core::{fmt, slice}; 14 + 15 + use bitflags::bitflags; 19 16 use riscv::satp; 20 17 use riscv::sbi::rfence::sfence_vma_asid; 21 18 use static_assertions::const_assert_eq; 19 + 20 + use crate::arch::{mb, wmb}; 21 + use crate::mem::flush::Flush; 22 + use crate::mem::frame_alloc::{Frame, FrameAllocator}; 23 + use crate::mem::{PhysicalAddress, VirtualAddress}; 22 24 23 25 pub const DEFAULT_ASID: u16 = 0; 24 26
+6 -5
kernel/src/arch/riscv64/mod.rs
··· 13 13 pub mod state; 14 14 mod trap_handler; 15 15 16 - use crate::arch::device::cpu::Cpu; 17 - use crate::device_tree::DeviceTree; 18 - use crate::mem::VirtualAddress; 19 16 use core::arch::asm; 20 - use riscv::sstatus::FS; 21 - use riscv::{interrupt, scounteren, sie, sstatus}; 22 17 23 18 pub use asid_allocator::AsidAllocator; 24 19 pub use block_on::block_on; ··· 26 21 AddressSpace, CANONICAL_ADDRESS_MASK, DEFAULT_ASID, KERNEL_ASPACE_RANGE, PAGE_SHIFT, PAGE_SIZE, 27 22 USER_ASPACE_RANGE, invalidate_range, is_kernel_address, 28 23 }; 24 + use riscv::sstatus::FS; 25 + use riscv::{interrupt, scounteren, sie, sstatus}; 29 26 pub use setjmp_longjmp::{JmpBuf, JmpBufStruct, call_with_setjmp, longjmp}; 27 + 28 + use crate::arch::device::cpu::Cpu; 29 + use crate::device_tree::DeviceTree; 30 + use crate::mem::VirtualAddress; 30 31 31 32 pub const STACK_ALIGNMENT: usize = 16; 32 33
+1
kernel/src/arch/riscv64/setjmp_longjmp.rs
··· 47 47 use core::marker::{PhantomData, PhantomPinned}; 48 48 use core::mem::{ManuallyDrop, MaybeUninit}; 49 49 use core::ptr::addr_of_mut; 50 + 50 51 use riscv::{load_fp, load_gp, save_fp, save_gp}; 51 52 52 53 /// A store for the register state used by `setjmp` and `longjmp`.
+10 -7
kernel/src/arch/riscv64/trap_handler.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use alloc::boxed::Box; 9 + use core::arch::{asm, naked_asm}; 10 + use core::cell::Cell; 11 + 12 + use cpu_local::cpu_local; 13 + use riscv::scause::{Exception, Interrupt}; 14 + use riscv::{ 15 + load_fp, load_gp, save_fp, save_gp, scause, sepc, sip, sscratch, sstatus, stval, stvec, 16 + }; 17 + 8 18 use crate::arch::PAGE_SIZE; 9 19 use crate::arch::trap::Trap; 10 20 use crate::backtrace::Backtrace; 11 21 use crate::mem::VirtualAddress; 12 22 use crate::state::{cpu_local, global}; 13 23 use crate::{TRAP_STACK_SIZE_PAGES, irq}; 14 - use alloc::boxed::Box; 15 - use core::arch::{asm, naked_asm}; 16 - use core::cell::Cell; 17 - use cpu_local::cpu_local; 18 - use riscv::scause::{Exception, Interrupt}; 19 - use riscv::{load_fp, load_gp, save_fp, save_gp}; 20 - use riscv::{scause, sepc, sip, sscratch, sstatus, stval, stvec}; 21 24 22 25 cpu_local! { 23 26 static IN_TRAP: Cell<bool> = Cell::new(false);
+5 -3
kernel/src/backtrace/mod.rs
··· 8 8 mod print; 9 9 mod symbolize; 10 10 11 - use crate::backtrace::print::BacktraceFmt; 12 - use crate::mem::VirtualAddress; 13 - use arrayvec::ArrayVec; 14 11 use core::str::FromStr; 15 12 use core::{fmt, slice}; 13 + 14 + use arrayvec::ArrayVec; 16 15 use fallible_iterator::FallibleIterator; 17 16 use loader_api::BootInfo; 18 17 use spin::OnceLock; 19 18 use symbolize::SymbolizeContext; 20 19 use unwind2::FrameIter; 20 + 21 + use crate::backtrace::print::BacktraceFmt; 22 + use crate::mem::VirtualAddress; 21 23 22 24 static BACKTRACE_INFO: OnceLock<BacktraceInfo> = OnceLock::new(); 23 25
+2 -1
kernel/src/backtrace/print.rs
··· 7 7 8 8 //! Printing of backtraces. This is adapted from the standard library. 9 9 10 + use core::fmt; 11 + 10 12 use crate::backtrace::BacktraceStyle; 11 13 use crate::backtrace::symbolize::{Symbol, SymbolName}; 12 - use core::fmt; 13 14 14 15 const HEX_WIDTH: usize = 2 + 2 * size_of::<usize>(); 15 16
+1
kernel/src/backtrace/symbolize.rs
··· 7 7 8 8 use core::ffi::c_void; 9 9 use core::{fmt, str}; 10 + 10 11 use fallible_iterator::FallibleIterator; 11 12 use gimli::{EndianSlice, NativeEndian}; 12 13 use rustc_demangle::{Demangle, try_demangle};
+2 -1
kernel/src/bootargs.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use core::str::FromStr; 9 + 8 10 use crate::backtrace::BacktraceStyle; 9 11 use crate::device_tree::DeviceTree; 10 12 use crate::tracing::Filter; 11 - use core::str::FromStr; 12 13 13 14 pub fn parse(devtree: &DeviceTree) -> crate::Result<Bootargs> { 14 15 let chosen = devtree.find_by_path("/chosen").unwrap();
+2 -1
kernel/src/device_tree.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use bumpalo::Bump; 9 8 use core::ffi::CStr; 10 9 use core::ptr::NonNull; 11 10 use core::{fmt, iter, mem, slice}; 11 + 12 + use bumpalo::Bump; 12 13 use fallible_iterator::FallibleIterator; 13 14 use fdt::{CellSizes, Error, Fdt, NodeName, StringList}; 14 15 use hashbrown::HashMap;
+3 -1
kernel/src/irq.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::state::cpu_local; 9 8 use alloc::sync::Arc; 10 9 use core::num::NonZero; 10 + 11 11 use hashbrown::HashMap; 12 12 use kasync::sync::wait_queue::WaitQueue; 13 13 use spin::{LazyLock, RwLock}; 14 + 15 + use crate::state::cpu_local; 14 16 15 17 pub trait InterruptController { 16 18 fn irq_claim(&mut self) -> Option<IrqClaim>;
+10 -9
kernel/src/main.rs
··· 42 42 mod util; 43 43 mod wasm; 44 44 45 - use crate::backtrace::Backtrace; 46 - use crate::device_tree::DeviceTree; 47 - use crate::mem::bootstrap_alloc::BootstrapAllocator; 48 - use crate::state::{CpuLocal, Global}; 45 + use core::range::Range; 46 + use core::slice; 47 + use core::time::Duration; 48 + 49 49 use abort::abort; 50 50 use arrayvec::ArrayVec; 51 51 use cfg_if::cfg_if; 52 - use core::range::Range; 53 - use core::slice; 54 - use core::time::Duration; 55 52 use fastrand::FastRand; 56 53 use kasync::executor::{Executor, Worker}; 57 54 use kasync::time::{Instant, Ticks, Timer}; 58 55 use loader_api::{BootInfo, LoaderConfig, MemoryRegionKind}; 59 - use mem::PhysicalAddress; 60 - use mem::frame_alloc; 56 + use mem::{PhysicalAddress, frame_alloc}; 61 57 use rand::{RngCore, SeedableRng}; 62 58 use rand_chacha::ChaCha20Rng; 59 + 60 + use crate::backtrace::Backtrace; 61 + use crate::device_tree::DeviceTree; 62 + use crate::mem::bootstrap_alloc::BootstrapAllocator; 63 + use crate::state::{CpuLocal, Global}; 63 64 64 65 /// The size of the stack in pages 65 66 pub const STACK_SIZE_PAGES: u32 = 256; // TODO find a lower more appropriate value
+2 -1
kernel/src/mem/address.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 8 use core::alloc::{Layout, LayoutError}; 10 9 use core::fmt; 11 10 use core::range::Range; 11 + 12 + use crate::arch; 12 13 13 14 macro_rules! address_impl { 14 15 ($addr:ident) => {
+10 -8
kernel/src/mem/address_space.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 - use crate::mem::address_space_region::AddressSpaceRegion; 10 - use crate::mem::frame_alloc::FrameAllocator; 11 - use crate::mem::{ 12 - AddressRangeExt, ArchAddressSpace, Flush, PageFaultFlags, Permissions, PhysicalAddress, 13 - VirtualAddress, 14 - }; 15 8 use alloc::boxed::Box; 16 9 use alloc::string::String; 17 10 use alloc::vec; 18 11 use alloc::vec::Vec; 19 - use anyhow::{bail, ensure}; 20 12 use core::alloc::Layout; 21 13 use core::fmt; 22 14 use core::num::NonZeroUsize; ··· 24 16 use core::pin::Pin; 25 17 use core::ptr::NonNull; 26 18 use core::range::{Bound, Range, RangeBounds, RangeInclusive}; 19 + 20 + use anyhow::{bail, ensure}; 27 21 use rand::Rng; 28 22 use rand::distr::Uniform; 29 23 use rand_chacha::ChaCha20Rng; 24 + 25 + use crate::arch; 26 + use crate::mem::address_space_region::AddressSpaceRegion; 27 + use crate::mem::frame_alloc::FrameAllocator; 28 + use crate::mem::{ 29 + AddressRangeExt, ArchAddressSpace, Flush, PageFaultFlags, Permissions, PhysicalAddress, 30 + VirtualAddress, 31 + }; 30 32 31 33 // const VIRT_ALLOC_ENTROPY: u8 = u8::try_from((arch::VIRT_ADDR_BITS - arch::PAGE_SHIFT as u32) + 1).unwrap(); 32 34 const VIRT_ALLOC_ENTROPY: u8 = 27;
+7 -5
kernel/src/mem/address_space_region.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 - use crate::mem::address::VirtualAddress; 10 - use crate::mem::frame_alloc::FrameAllocator; 11 - use crate::mem::{AddressRangeExt, Batch, PageFaultFlags, Permissions, PhysicalAddress, Vmo}; 12 8 use alloc::boxed::Box; 13 9 use alloc::string::String; 14 10 use alloc::sync::Arc; 15 - use anyhow::bail; 16 11 use core::cmp; 17 12 use core::mem::offset_of; 18 13 use core::num::NonZeroUsize; 19 14 use core::pin::Pin; 20 15 use core::ptr::NonNull; 21 16 use core::range::Range; 17 + 18 + use anyhow::bail; 22 19 use pin_project::pin_project; 23 20 use spin::LazyLock; 21 + 22 + use crate::arch; 23 + use crate::mem::address::VirtualAddress; 24 + use crate::mem::frame_alloc::FrameAllocator; 25 + use crate::mem::{AddressRangeExt, Batch, PageFaultFlags, Permissions, PhysicalAddress, Vmo}; 24 26 25 27 /// A contiguous region of an address space 26 28 #[pin_project]
+3 -2
kernel/src/mem/bootstrap_alloc.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 - use crate::mem::address::{AddressRangeExt, PhysicalAddress}; 10 8 use core::alloc::Layout; 11 9 use core::range::Range; 12 10 use core::{iter, ptr, slice}; 11 + 12 + use crate::arch; 13 + use crate::mem::address::{AddressRangeExt, PhysicalAddress}; 13 14 14 15 pub struct BootstrapAllocator<'a> { 15 16 regions: &'a [Range<PhysicalAddress>],
+5 -3
kernel/src/mem/flush.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 - use crate::mem::address::VirtualAddress; 10 - use anyhow::bail; 11 8 use core::range::Range; 12 9 use core::{cmp, mem}; 10 + 11 + use anyhow::bail; 12 + 13 + use crate::arch; 14 + use crate::mem::address::VirtualAddress; 13 15 14 16 #[must_use] 15 17 pub struct Flush {
+6 -4
kernel/src/mem/frame_alloc/arena.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use super::frame::FrameInfo; 9 - use crate::arch; 10 - use crate::mem::address::{AddressRangeExt, PhysicalAddress, VirtualAddress}; 11 - use cordyceps::List; 12 8 use core::alloc::Layout; 13 9 use core::mem::MaybeUninit; 14 10 use core::ptr::NonNull; 15 11 use core::range::Range; 16 12 use core::{cmp, fmt, mem, slice}; 13 + 14 + use cordyceps::List; 17 15 use fallible_iterator::FallibleIterator; 18 16 use smallvec::SmallVec; 17 + 18 + use super::frame::FrameInfo; 19 + use crate::arch; 20 + use crate::mem::address::{AddressRangeExt, PhysicalAddress, VirtualAddress}; 19 21 20 22 const ARENA_PAGE_BOOKKEEPING_SIZE: usize = size_of::<FrameInfo>(); 21 23 const MAX_WASTED_ARENA_BYTES: usize = 0x8_4000; // 528 KiB
+6 -5
kernel/src/mem/frame_alloc/frame.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 - use crate::mem::address::{PhysicalAddress, VirtualAddress}; 10 - use crate::mem::frame_alloc::FRAME_ALLOC; 11 8 use alloc::slice; 12 - use cordyceps::Linked; 13 - use cordyceps::list; 14 9 use core::marker::PhantomData; 15 10 use core::mem::offset_of; 16 11 use core::ops::Deref; ··· 18 13 use core::sync::atomic; 19 14 use core::sync::atomic::{AtomicUsize, Ordering}; 20 15 use core::{fmt, ptr}; 16 + 17 + use cordyceps::{Linked, list}; 21 18 use static_assertions::assert_impl_all; 19 + 20 + use crate::arch; 21 + use crate::mem::address::{PhysicalAddress, VirtualAddress}; 22 + use crate::mem::frame_alloc::FRAME_ALLOC; 22 23 23 24 /// Soft limit on the amount of references that may be made to a `Frame`. 24 25 const MAX_REFCOUNT: usize = isize::MAX as usize;
+4 -2
kernel/src/mem/frame_alloc/frame_list.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 - use crate::mem::frame_alloc::Frame; 10 8 use alloc::boxed::Box; 11 9 use core::fmt::Formatter; 12 10 use core::iter::{FlatMap, Flatten, FusedIterator}; ··· 14 12 use core::pin::Pin; 15 13 use core::ptr::NonNull; 16 14 use core::{array, fmt}; 15 + 17 16 use pin_project::pin_project; 18 17 use wavltree::WAVLTree; 18 + 19 + use crate::arch; 20 + use crate::mem::frame_alloc::Frame; 19 21 20 22 const FRAME_LIST_NODE_FANOUT: usize = 16; 21 23
+7 -7
kernel/src/mem/frame_alloc/mod.rs
··· 9 9 mod frame; 10 10 pub mod frame_list; 11 11 12 - use crate::arch; 13 - use crate::mem::bootstrap_alloc::BootstrapAllocator; 14 - use crate::mem::{PhysicalAddress, VirtualAddress}; 15 12 use alloc::vec::Vec; 16 - use arena::Arena; 17 - use arena::select_arenas; 18 - use cordyceps::list::List; 19 13 use core::alloc::Layout; 20 14 use core::cell::RefCell; 21 15 use core::ptr::NonNull; 22 16 use core::range::Range; 23 17 use core::sync::atomic::AtomicUsize; 24 18 use core::{cmp, fmt, iter, slice}; 19 + 20 + use arena::{Arena, select_arenas}; 21 + use cordyceps::list::List; 25 22 use cpu_local::collection::CpuLocal; 26 23 use fallible_iterator::FallibleIterator; 24 + pub use frame::{Frame, FrameInfo}; 27 25 use spin::{Mutex, OnceLock}; 28 26 27 + use crate::arch; 28 + use crate::mem::bootstrap_alloc::BootstrapAllocator; 29 29 use crate::mem::frame_alloc::frame_list::FrameList; 30 - pub use frame::{Frame, FrameInfo}; 30 + use crate::mem::{PhysicalAddress, VirtualAddress}; 31 31 32 32 pub static FRAME_ALLOC: OnceLock<FrameAllocator> = OnceLock::new(); 33 33 pub fn init(
+8 -6
kernel/src/mem/mmap.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 - use crate::mem::address::AddressRangeExt; 10 - use crate::mem::{ 11 - AddressSpace, AddressSpaceRegion, ArchAddressSpace, Batch, Permissions, PhysicalAddress, 12 - VirtualAddress, 13 - }; 14 8 use alloc::string::String; 15 9 use alloc::sync::Arc; 16 10 use core::alloc::Layout; 17 11 use core::num::NonZeroUsize; 18 12 use core::range::Range; 19 13 use core::{ptr, slice}; 14 + 20 15 use spin::Mutex; 16 + 17 + use crate::arch; 18 + use crate::mem::address::AddressRangeExt; 19 + use crate::mem::{ 20 + AddressSpace, AddressSpaceRegion, ArchAddressSpace, Batch, Permissions, PhysicalAddress, 21 + VirtualAddress, 22 + }; 21 23 22 24 /// A memory mapping. 23 25 ///
+8 -7
kernel/src/mem/mod.rs
··· 16 16 mod trap_handler; 17 17 mod vmo; 18 18 19 - use crate::arch; 20 - use crate::mem::frame_alloc::FrameAllocator; 21 19 use alloc::format; 22 20 use alloc::string::ToString; 23 21 use alloc::sync::Arc; 24 22 use core::num::NonZeroUsize; 25 23 use core::range::Range; 26 24 use core::{fmt, slice}; 27 - use loader_api::BootInfo; 28 - use rand::SeedableRng; 29 - use rand_chacha::ChaCha20Rng; 30 - use spin::{Mutex, OnceLock}; 31 - use xmas_elf::program::Type; 32 25 33 26 pub use address::{AddressRangeExt, PhysicalAddress, VirtualAddress}; 34 27 pub use address_space::{AddressSpace, Batch}; 35 28 pub use address_space_region::AddressSpaceRegion; 36 29 pub use flush::Flush; 30 + use loader_api::BootInfo; 37 31 pub use mmap::Mmap; 32 + use rand::SeedableRng; 33 + use rand_chacha::ChaCha20Rng; 34 + use spin::{Mutex, OnceLock}; 38 35 pub use trap_handler::handle_page_fault; 39 36 pub use vmo::Vmo; 37 + use xmas_elf::program::Type; 38 + 39 + use crate::arch; 40 + use crate::mem::frame_alloc::FrameAllocator; 40 41 41 42 pub const KIB: usize = 1024; 42 43 pub const MIB: usize = KIB * 1024;
+5 -3
kernel/src/mem/provider.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 - use crate::mem::frame_alloc::{FRAME_ALLOC, FrameAllocator}; 10 - use crate::mem::frame_alloc::{Frame, frame_list::FrameList}; 11 8 use alloc::sync::Arc; 12 9 use core::alloc::Layout; 13 10 use core::fmt::Debug; 14 11 use core::iter; 15 12 use core::num::NonZeroUsize; 13 + 16 14 use spin::{LazyLock, OnceLock}; 15 + 16 + use crate::arch; 17 + use crate::mem::frame_alloc::frame_list::FrameList; 18 + use crate::mem::frame_alloc::{FRAME_ALLOC, Frame, FrameAllocator}; 17 19 18 20 pub trait Provider: Debug { 19 21 // TODO make async
+2 -1
kernel/src/mem/trap_handler.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use core::ops::ControlFlow; 9 + 8 10 use crate::arch::trap::Trap; 9 11 use crate::mem::VirtualAddress; 10 12 use crate::state::global; 11 - use core::ops::ControlFlow; 12 13 13 14 pub fn handle_page_fault(_trap: Trap, _tval: VirtualAddress) -> ControlFlow<()> { 14 15 let current_task = global()
+8 -11
kernel/src/mem/vmo.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 - use crate::mem::frame_alloc::FrameAllocator; 10 - use crate::mem::provider::{Provider, THE_ZERO_FRAME}; 11 - use crate::mem::{ 12 - AddressRangeExt, PhysicalAddress, 13 - frame_alloc::{ 14 - Frame, 15 - frame_list::{Entry, FrameList}, 16 - }, 17 - }; 18 8 use alloc::sync::Arc; 9 + use core::range::Range; 10 + 19 11 use anyhow::ensure; 20 - use core::range::Range; 21 12 use spin::RwLock; 13 + 14 + use crate::arch; 15 + use crate::mem::frame_alloc::frame_list::{Entry, FrameList}; 16 + use crate::mem::frame_alloc::{Frame, FrameAllocator}; 17 + use crate::mem::provider::{Provider, THE_ZERO_FRAME}; 18 + use crate::mem::{AddressRangeExt, PhysicalAddress}; 22 19 23 20 #[derive(Debug)] 24 21 pub enum Vmo {
+1
kernel/src/metrics.rs
··· 26 26 //! cpus. 27 27 28 28 use core::sync::atomic::{AtomicU64, Ordering}; 29 + 29 30 use cpu_local::collection::CpuLocal; 30 31 31 32 /// Declares a new counter.
+6 -4
kernel/src/shell.rs
··· 15 15 /_/\_\/____/____/ 16 16 "#; 17 17 18 - use crate::device_tree::DeviceTree; 19 - use crate::mem::{Mmap, PhysicalAddress, with_kernel_aspace}; 20 - use crate::state::global; 21 - use crate::{arch, irq}; 22 18 use alloc::string::{String, ToString}; 23 19 use core::fmt; 24 20 use core::fmt::Write; 25 21 use core::ops::DerefMut; 26 22 use core::range::Range; 27 23 use core::str::FromStr; 24 + 28 25 use fallible_iterator::FallibleIterator; 29 26 use kasync::executor::Executor; 30 27 use spin::{Barrier, OnceLock}; 28 + 29 + use crate::device_tree::DeviceTree; 30 + use crate::mem::{Mmap, PhysicalAddress, with_kernel_aspace}; 31 + use crate::state::global; 32 + use crate::{arch, irq}; 31 33 32 34 static COMMANDS: &[Command] = &[PANIC, FAULT, VERSION, SHUTDOWN]; 33 35
+4 -2
kernel/src/state.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 - use crate::device_tree::DeviceTree; 10 8 use core::cell::OnceCell; 9 + 11 10 use cpu_local::cpu_local; 12 11 use kasync::executor::Executor; 13 12 use kasync::time::{Instant, Timer}; 14 13 use loader_api::BootInfo; 15 14 use spin::OnceLock; 15 + 16 + use crate::arch; 17 + use crate::device_tree::DeviceTree; 16 18 17 19 static GLOBAL: OnceLock<Global> = OnceLock::new(); 18 20
+5 -3
kernel/src/tests/mod.rs
··· 11 11 mod spectest; 12 12 mod wast; 13 13 14 - use crate::tests::args::Arguments; 15 - use crate::tests::printer::Printer; 16 - use crate::{arch, state}; 17 14 use alloc::boxed::Box; 18 15 use alloc::sync::Arc; 19 16 use core::any::Any; 20 17 use core::ptr::addr_of; 21 18 use core::sync::atomic::{AtomicU64, Ordering}; 22 19 use core::{hint, slice}; 20 + 23 21 use futures::FutureExt; 24 22 use futures::future::try_join_all; 25 23 use ktest::Test; 24 + 25 + use crate::tests::args::Arguments; 26 + use crate::tests::printer::Printer; 27 + use crate::{arch, state}; 26 28 27 29 /// The outcome of performing a single test. 28 30 pub enum Outcome {
+4 -2
kernel/src/tests/printer.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use super::args::FormatSetting; 9 - use super::{Conclusion, Outcome}; 10 8 use alloc::boxed::Box; 11 9 use core::sync::atomic::Ordering; 10 + 12 11 use ktest::{Test, TestInfo}; 12 + 13 + use super::args::FormatSetting; 14 + use super::{Conclusion, Outcome}; 13 15 14 16 pub struct Printer { 15 17 format: FormatSetting,
+7 -5
kernel/src/tests/wast.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::wasm::{ 9 - ConstExprEvaluator, Engine, Extern, Instance, Linker, Module, PlaceholderAllocatorDontUse, 10 - Store, Val, 11 - }; 12 8 use alloc::string::ToString; 13 9 use alloc::sync::Arc; 14 10 use alloc::vec::Vec; 15 11 use alloc::{format, vec}; 16 - use anyhow::{Context, anyhow, bail}; 17 12 use core::fmt::{Display, LowerHex}; 13 + 14 + use anyhow::{Context, anyhow, bail}; 18 15 use spin::Mutex; 19 16 use wasmparser::Validator; 20 17 use wast::core::{EncodeOptions, NanPattern, V128Pattern, WastArgCore, WastRetCore}; ··· 22 19 use wast::token::{F32, F64}; 23 20 use wast::{ 24 21 Error, QuoteWat, Wast, WastArg, WastDirective, WastExecute, WastInvoke, WastRet, Wat, parser, 22 + }; 23 + 24 + use crate::wasm::{ 25 + ConstExprEvaluator, Engine, Extern, Instance, Linker, Module, PlaceholderAllocatorDontUse, 26 + Store, Val, 25 27 }; 26 28 27 29 macro_rules! wast_tests {
+1
kernel/src/tracing/filter.rs
··· 12 12 use core::fmt; 13 13 use core::fmt::Formatter; 14 14 use core::str::FromStr; 15 + 15 16 use fallible_iterator::{FallibleIterator, IteratorExt}; 16 17 use smallvec::SmallVec; 17 18 use tracing::level_filters::STATIC_MAX_LEVEL;
+6 -4
kernel/src/tracing/mod.rs
··· 11 11 mod registry; 12 12 mod writer; 13 13 14 - use crate::state::try_global; 15 - use crate::tracing::writer::{MakeWriter, Semihosting}; 16 - pub use ::tracing::*; 17 - use color::{Color, SetColor}; 18 14 use core::cell::{Cell, OnceCell}; 19 15 use core::fmt; 20 16 use core::fmt::Write; 17 + 18 + pub use ::tracing::*; 19 + use color::{Color, SetColor}; 21 20 use cpu_local::cpu_local; 22 21 pub use filter::Filter; 23 22 use registry::Registry; ··· 25 24 use tracing::field; 26 25 use tracing_core::span::{Attributes, Current, Id, Record}; 27 26 use tracing_core::{Collect, Dispatch, Event, Interest, Level, LevelFilter, Metadata}; 27 + 28 + use crate::state::try_global; 29 + use crate::tracing::writer::{MakeWriter, Semihosting}; 28 30 29 31 static SUBSCRIBER: OnceLock<Subscriber> = OnceLock::new(); 30 32
+1
kernel/src/tracing/registry.rs
··· 9 9 use core::cell::RefCell; 10 10 use core::sync::atomic; 11 11 use core::sync::atomic::{AtomicUsize, Ordering}; 12 + 12 13 use cpu_local::collection::CpuLocal; 13 14 use ksharded_slab::Pool; 14 15 use ksharded_slab::pool::Ref;
+3 -1
kernel/src/tracing/writer.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::tracing::color::{AnsiEscapes, Color, SetColor}; 9 8 use core::cell::UnsafeCell; 10 9 use core::fmt::{Arguments, Write}; 11 10 use core::{cmp, fmt}; 11 + 12 12 use spin::{ReentrantMutex, ReentrantMutexGuard}; 13 13 use tracing_core::Metadata; 14 + 15 + use crate::tracing::color::{AnsiEscapes, Color, SetColor}; 14 16 15 17 pub trait MakeWriter<'a> { 16 18 type Writer: fmt::Write;
+3 -1
kernel/src/wasm/code_registry.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::wasm::vm::CodeObject; 9 8 use alloc::collections::BTreeMap; 10 9 use alloc::sync::Arc; 10 + 11 11 use spin::{OnceLock, RwLock}; 12 + 13 + use crate::wasm::vm::CodeObject; 12 14 13 15 fn global_code() -> &'static RwLock<GlobalRegistry> { 14 16 static GLOBAL_CODE: OnceLock<RwLock<GlobalRegistry>> = OnceLock::new();
+5 -4
kernel/src/wasm/compile/compiled_function.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::wasm::builtins::BuiltinFunctionIndex; 9 - use crate::wasm::compile::{FilePos, NS_BUILTIN, NS_WASM_FUNC}; 10 - use crate::wasm::indices::FuncIndex; 11 - use crate::wasm::trap::TrapKind; 12 8 use cranelift_codegen::ir::{ExternalName, StackSlots, UserExternalName, UserExternalNameRef}; 13 9 use cranelift_codegen::{ 14 10 Final, FinalizedMachReloc, FinalizedRelocTarget, MachBufferFinalized, ValueLabelsRanges, 15 11 binemit, 16 12 }; 17 13 use cranelift_entity::PrimaryMap; 14 + 15 + use crate::wasm::builtins::BuiltinFunctionIndex; 16 + use crate::wasm::compile::{FilePos, NS_BUILTIN, NS_WASM_FUNC}; 17 + use crate::wasm::indices::FuncIndex; 18 + use crate::wasm::trap::TrapKind; 18 19 19 20 #[derive(Debug)] 20 21 pub struct CompiledFunction {
+11 -9
kernel/src/wasm/compile/mod.rs
··· 8 8 mod compile_key; 9 9 mod compiled_function; 10 10 11 - use crate::wasm::Engine; 12 - use crate::wasm::builtins::BuiltinFunctionIndex; 13 - use crate::wasm::compile::compiled_function::{RelocationTarget, TrapInfo}; 14 - use crate::wasm::indices::{DefinedFuncIndex, ModuleInternedTypeIndex}; 15 - use crate::wasm::translate::{ 16 - FunctionBodyData, ModuleTranslation, ModuleTypes, TranslatedModule, WasmFuncType, 17 - }; 18 - use crate::wasm::trap::TrapKind; 19 - use crate::wasm::vm::{CodeObject, MmapVec}; 20 11 use alloc::boxed::Box; 21 12 use alloc::collections::BTreeMap; 22 13 use alloc::format; 23 14 use alloc::string::String; 24 15 use alloc::vec::Vec; 16 + 25 17 use compile_key::CompileKey; 26 18 pub use compiled_function::CompiledFunction; 27 19 use cranelift_codegen::control::ControlPlane; 28 20 use cranelift_entity::{EntitySet, PrimaryMap}; 29 21 use hashbrown::HashSet; 22 + 23 + use crate::wasm::Engine; 24 + use crate::wasm::builtins::BuiltinFunctionIndex; 25 + use crate::wasm::compile::compiled_function::{RelocationTarget, TrapInfo}; 26 + use crate::wasm::indices::{DefinedFuncIndex, ModuleInternedTypeIndex}; 27 + use crate::wasm::translate::{ 28 + FunctionBodyData, ModuleTranslation, ModuleTypes, TranslatedModule, WasmFuncType, 29 + }; 30 + use crate::wasm::trap::TrapKind; 31 + use crate::wasm::vm::{CodeObject, MmapVec}; 30 32 31 33 /// Namespace corresponding to wasm functions, the index is the index of the 32 34 /// defined function that's being referenced.
+4 -2
kernel/src/wasm/cranelift/builtins.rs
··· 7 7 8 8 #![expect(unused, reason = "TODO")] 9 9 10 - use crate::wasm::builtins::{BuiltinFunctionIndex, foreach_builtin_function}; 11 - use crate::wasm::compile::NS_BUILTIN; 12 10 use alloc::vec; 11 + 13 12 use cranelift_codegen::ir::{self, AbiParam, ArgumentPurpose, Function, Signature, Type, types}; 14 13 use cranelift_codegen::isa::{CallConv, TargetIsa}; 15 14 use cranelift_entity::EntityRef; 15 + 16 + use crate::wasm::builtins::{BuiltinFunctionIndex, foreach_builtin_function}; 17 + use crate::wasm::compile::NS_BUILTIN; 16 18 17 19 pub struct BuiltinFunctions { 18 20 types: BuiltinFunctionSignatures,
+15 -13
kernel/src/wasm/cranelift/code_translator.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::util::zip_eq::IteratorExt; 9 - use crate::wasm::cranelift::CraneliftGlobal; 10 - use crate::wasm::cranelift::env::TranslationEnvironment; 11 - use crate::wasm::cranelift::state::{ControlStackFrame, ElseData, FuncTranslationState}; 12 - use crate::wasm::cranelift::utils::{ 13 - block_with_params, blocktype_params_results, f32_translation, f64_translation, 14 - }; 15 - use crate::wasm::indices::{ 16 - DataIndex, ElemIndex, FuncIndex, GlobalIndex, MemoryIndex, TableIndex, TypeIndex, 17 - }; 18 - use crate::wasm::trap::{TRAP_NULL_REFERENCE, TRAP_UNREACHABLE}; 19 8 use alloc::vec; 20 9 use alloc::vec::Vec; 10 + 21 11 use anyhow::bail; 22 12 use cranelift_codegen::ir; 23 13 use cranelift_codegen::ir::condcodes::{FloatCC, IntCC}; ··· 26 16 F32, F32X4, F64, F64X2, I8, I8X16, I16, I16X8, I32, I32X4, I64, I64X2, 27 17 }; 28 18 use cranelift_codegen::ir::{ 29 - AtomicRmwOp, ConstantData, JumpTableData, MemFlags, TrapCode, ValueLabel, 19 + AtomicRmwOp, ConstantData, InstBuilder, JumpTableData, MemFlags, TrapCode, Type, Value, 20 + ValueLabel, 30 21 }; 31 - use cranelift_codegen::ir::{InstBuilder, Type, Value}; 32 22 use cranelift_entity::packed_option::ReservedValue; 33 23 use cranelift_frontend::{FunctionBuilder, Variable}; 34 24 use hashbrown::{HashMap, hash_map}; 35 25 use smallvec::SmallVec; 36 26 use wasmparser::{FuncValidator, MemArg, Operator, WasmModuleResources}; 27 + 28 + use crate::util::zip_eq::IteratorExt; 29 + use crate::wasm::cranelift::CraneliftGlobal; 30 + use crate::wasm::cranelift::env::TranslationEnvironment; 31 + use crate::wasm::cranelift::state::{ControlStackFrame, ElseData, FuncTranslationState}; 32 + use crate::wasm::cranelift::utils::{ 33 + block_with_params, blocktype_params_results, f32_translation, f64_translation, 34 + }; 35 + use crate::wasm::indices::{ 36 + DataIndex, ElemIndex, FuncIndex, GlobalIndex, MemoryIndex, TableIndex, TypeIndex, 37 + }; 38 + use crate::wasm::trap::{TRAP_NULL_REFERENCE, TRAP_UNREACHABLE}; 37 39 38 40 /// Like `Option<T>` but specifically for passing information about transitions 39 41 /// from reachable to unreachable state and the like from callees to callers.
+20 -16
kernel/src/wasm/cranelift/compiler.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use alloc::boxed::Box; 9 + use alloc::vec::Vec; 10 + use core::fmt::Formatter; 11 + use core::{cmp, fmt, mem}; 12 + 13 + use anyhow::anyhow; 14 + use cranelift_codegen::control::ControlPlane; 15 + use cranelift_codegen::ir::condcodes::IntCC; 16 + use cranelift_codegen::ir::immediates::Offset32; 17 + use cranelift_codegen::ir::{ 18 + Endianness, GlobalValueData, InstBuilder, MemFlags, Signature, Type, UserExternalName, 19 + UserFuncName, Value, 20 + }; 21 + use cranelift_codegen::isa::{OwnedTargetIsa, TargetIsa}; 22 + use cranelift_codegen::{TextSectionBuilder, ir}; 23 + use cranelift_frontend::FunctionBuilder; 24 + use spin::Mutex; 25 + use target_lexicon::Triple; 26 + use wasmparser::{FuncValidatorAllocations, FunctionBody}; 27 + 8 28 use crate::arch; 9 29 use crate::wasm::builtins::BuiltinFunctionIndex; 10 30 use crate::wasm::compile::{CompiledFunction, Compiler, FilePos, NS_WASM_FUNC}; ··· 20 40 use crate::wasm::vm::{ 21 41 StaticVMShape, VMArrayCallHostFuncContext, VMCONTEXT_MAGIC, VMFuncRef, VMStoreContext, 22 42 }; 23 - use alloc::boxed::Box; 24 - use alloc::vec::Vec; 25 - use anyhow::anyhow; 26 - use core::fmt::Formatter; 27 - use core::{cmp, fmt, mem}; 28 - use cranelift_codegen::control::ControlPlane; 29 - use cranelift_codegen::ir::condcodes::IntCC; 30 - use cranelift_codegen::ir::immediates::Offset32; 31 - use cranelift_codegen::ir::{Endianness, InstBuilder, Type, Value}; 32 - use cranelift_codegen::ir::{GlobalValueData, MemFlags, Signature, UserExternalName, UserFuncName}; 33 - use cranelift_codegen::isa::{OwnedTargetIsa, TargetIsa}; 34 - use cranelift_codegen::{TextSectionBuilder, ir}; 35 - use cranelift_frontend::FunctionBuilder; 36 - use spin::Mutex; 37 - use target_lexicon::Triple; 38 - use wasmparser::{FuncValidatorAllocations, FunctionBody}; 39 43 40 44 pub struct CraneliftCompiler { 41 45 isa: OwnedTargetIsa,
+19 -17
kernel/src/wasm/cranelift/env.rs
··· 7 7 8 8 #![expect(unused, reason = "this module has a number of method stubs")] 9 9 10 + use alloc::vec; 11 + use alloc::vec::Vec; 12 + use core::cmp; 13 + use core::mem::offset_of; 14 + 15 + use cranelift_codegen::cursor::FuncCursor; 16 + use cranelift_codegen::ir; 17 + use cranelift_codegen::ir::condcodes::IntCC; 18 + use cranelift_codegen::ir::immediates::Offset32; 19 + use cranelift_codegen::ir::types::{I32, I64}; 20 + use cranelift_codegen::ir::{ 21 + ArgumentPurpose, ExtFuncData, ExternalName, FuncRef, Function, GlobalValue, GlobalValueData, 22 + Inst, InstBuilder, MemFlags, MemoryType, SigRef, Signature, TrapCode, Type, UserExternalName, 23 + Value, 24 + }; 25 + use cranelift_codegen::isa::TargetIsa; 26 + use cranelift_frontend::FunctionBuilder; 27 + use smallvec::SmallVec; 28 + 10 29 use crate::wasm::compile::NS_WASM_FUNC; 11 30 use crate::wasm::cranelift::builtins::BuiltinFunctions; 12 31 use crate::wasm::cranelift::code_translator::Reachability; ··· 29 48 StaticVMShape, VMFuncRef, VMFunctionImport, VMGlobalImport, VMMemoryDefinition, VMMemoryImport, 30 49 VMShape, VMTableDefinition, VMTableImport, 31 50 }; 32 - use alloc::vec; 33 - use alloc::vec::Vec; 34 - use core::cmp; 35 - use core::mem::offset_of; 36 - use cranelift_codegen::cursor::FuncCursor; 37 - use cranelift_codegen::ir; 38 - use cranelift_codegen::ir::condcodes::IntCC; 39 - use cranelift_codegen::ir::immediates::Offset32; 40 - use cranelift_codegen::ir::types::{I32, I64}; 41 - use cranelift_codegen::ir::{ 42 - ArgumentPurpose, ExtFuncData, ExternalName, FuncRef, GlobalValue, GlobalValueData, Inst, 43 - MemFlags, MemoryType, SigRef, Signature, TrapCode, Type, UserExternalName, Value, 44 - }; 45 - use cranelift_codegen::ir::{Function, InstBuilder}; 46 - use cranelift_codegen::isa::TargetIsa; 47 - use cranelift_frontend::FunctionBuilder; 48 - use smallvec::SmallVec; 49 51 50 52 /// A smallvec that holds the IR values for a struct's fields. 51 53 pub type StructFieldsVec = SmallVec<[Value; 4]>;
+5 -4
kernel/src/wasm/cranelift/func_translator.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::wasm::cranelift::code_translator::{bitcast_wasm_returns, translate_operator}; 9 - use crate::wasm::cranelift::env::TranslationEnvironment; 10 - use crate::wasm::cranelift::state::FuncTranslationState; 11 - use crate::wasm::cranelift::utils::get_vmctx_value_label; 12 8 use cranelift_codegen::ir; 13 9 use cranelift_codegen::ir::{InstBuilder, ValueLabel}; 14 10 use cranelift_entity::EntityRef; 15 11 use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable}; 16 12 use wasmparser::{BinaryReader, FuncValidator, FunctionBody, WasmModuleResources}; 13 + 14 + use crate::wasm::cranelift::code_translator::{bitcast_wasm_returns, translate_operator}; 15 + use crate::wasm::cranelift::env::TranslationEnvironment; 16 + use crate::wasm::cranelift::state::FuncTranslationState; 17 + use crate::wasm::cranelift::utils::get_vmctx_value_label; 17 18 18 19 pub struct FuncTranslator { 19 20 func_ctx: FunctionBuilderContext,
+9 -7
kernel/src/wasm/cranelift/memory.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::wasm::cranelift::code_translator::Reachability; 9 - use crate::wasm::cranelift::env::TranslationEnvironment; 10 - use crate::wasm::cranelift::utils::index_type_to_ir_type; 11 - use crate::wasm::translate::IndexType; 12 - use crate::wasm::trap::TRAP_HEAP_MISALIGNED; 13 8 use cranelift_codegen::cursor::{Cursor, FuncCursor}; 14 9 use cranelift_codegen::ir; 15 - use cranelift_codegen::ir::InstBuilder; 16 10 use cranelift_codegen::ir::condcodes::IntCC; 17 - use cranelift_codegen::ir::{Expr, Fact, MemFlags, RelSourceLoc, TrapCode, Type, Value}; 11 + use cranelift_codegen::ir::{ 12 + Expr, Fact, InstBuilder, MemFlags, RelSourceLoc, TrapCode, Type, Value, 13 + }; 18 14 use cranelift_frontend::FunctionBuilder; 19 15 use wasmparser::MemArg; 16 + 17 + use crate::wasm::cranelift::code_translator::Reachability; 18 + use crate::wasm::cranelift::env::TranslationEnvironment; 19 + use crate::wasm::cranelift::utils::index_type_to_ir_type; 20 + use crate::wasm::translate::IndexType; 21 + use crate::wasm::trap::TRAP_HEAP_MISALIGNED; 20 22 21 23 #[derive(Debug, Clone)] 22 24 pub struct CraneliftMemory {
+2 -1
kernel/src/wasm/cranelift/mod.rs
··· 14 14 mod state; 15 15 mod utils; 16 16 17 - use crate::wasm::trap::TRAP_TABLE_OUT_OF_BOUNDS; 18 17 pub use compiler::CraneliftCompiler; 19 18 use cranelift_codegen::ir; 20 19 use cranelift_codegen::ir::condcodes::IntCC; 21 20 use cranelift_codegen::ir::immediates::Imm64; 22 21 use cranelift_codegen::ir::{InstBuilder, MemFlags}; 23 22 use cranelift_frontend::FunctionBuilder; 23 + 24 + use crate::wasm::trap::TRAP_TABLE_OUT_OF_BOUNDS; 24 25 25 26 /// The value of a WebAssembly global variable. 26 27 #[derive(Clone, Copy)]
+6 -4
kernel/src/wasm/cranelift/state.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::wasm::cranelift::env::TranslationEnvironment; 9 - use crate::wasm::cranelift::memory::CraneliftMemory; 10 - use crate::wasm::cranelift::{CraneliftGlobal, CraneliftTable}; 11 - use crate::wasm::indices::{FuncIndex, GlobalIndex, MemoryIndex, TableIndex, TypeIndex}; 12 8 use alloc::vec::Vec; 9 + 13 10 use cranelift_codegen::ir; 14 11 use cranelift_codegen::ir::{Block, FuncRef, Function, Inst, SigRef, Value}; 15 12 use hashbrown::HashMap; 13 + 14 + use crate::wasm::cranelift::env::TranslationEnvironment; 15 + use crate::wasm::cranelift::memory::CraneliftMemory; 16 + use crate::wasm::cranelift::{CraneliftGlobal, CraneliftTable}; 17 + use crate::wasm::indices::{FuncIndex, GlobalIndex, MemoryIndex, TableIndex, TypeIndex}; 16 18 17 19 pub struct FuncTranslationState { 18 20 /// A stack of values corresponding to the active values in the input wasm function at this
+3 -2
kernel/src/wasm/cranelift/utils.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::wasm::cranelift::env::TranslationEnvironment; 9 - use crate::wasm::translate::IndexType; 10 8 use cranelift_codegen::ir; 11 9 use cranelift_codegen::ir::types; 12 10 use cranelift_frontend::FunctionBuilder; 13 11 use wasmparser::{FuncValidator, WasmModuleResources}; 12 + 13 + use crate::wasm::cranelift::env::TranslationEnvironment; 14 + use crate::wasm::translate::IndexType; 14 15 15 16 /// Get the parameter and result types for the given Wasm blocktype. 16 17 pub fn blocktype_params_results<T>(
+6 -4
kernel/src/wasm/engine.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 - use crate::wasm::compile::Compiler; 10 - use crate::wasm::cranelift::CraneliftCompiler; 11 - use crate::wasm::type_registry::TypeRegistry; 12 8 use alloc::sync::Arc; 13 9 use core::sync::atomic::AtomicU64; 10 + 14 11 use cranelift_codegen::settings::{Configurable, Flags}; 15 12 use rand::{Rng, SeedableRng}; 16 13 use rand_chacha::ChaCha20Rng; 17 14 use spin::{Mutex, MutexGuard}; 15 + 16 + use crate::arch; 17 + use crate::wasm::compile::Compiler; 18 + use crate::wasm::cranelift::CraneliftCompiler; 19 + use crate::wasm::type_registry::TypeRegistry; 18 20 19 21 /// Global context for the runtime. 20 22 ///
+8 -6
kernel/src/wasm/func/host.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use alloc::boxed::Box; 9 + use alloc::sync::Arc; 10 + use core::mem::MaybeUninit; 11 + use core::ptr::NonNull; 12 + use core::{iter, ptr}; 13 + 14 + use anyhow::bail; 15 + 8 16 use crate::wasm::func::typed::WasmTy; 9 17 use crate::wasm::func::{FuncData, FuncKind}; 10 18 use crate::wasm::store::{StoreInner, StoreOpaque}; ··· 13 21 InstanceAndStore, VMArrayCallHostFuncContext, VMContext, VMFuncRef, VMOpaqueContext, VMVal, 14 22 }; 15 23 use crate::wasm::{Engine, Func}; 16 - use alloc::boxed::Box; 17 - use alloc::sync::Arc; 18 - use anyhow::bail; 19 - use core::mem::MaybeUninit; 20 - use core::ptr::NonNull; 21 - use core::{iter, ptr}; 22 24 23 25 #[derive(Debug)] 24 26 pub struct HostFunc {
+10 -8
kernel/src/wasm/func/mod.rs
··· 8 8 mod host; 9 9 mod typed; 10 10 11 + use alloc::boxed::Box; 12 + use alloc::sync::Arc; 13 + use core::ffi::c_void; 14 + use core::mem; 15 + use core::ptr::NonNull; 16 + 17 + use anyhow::ensure; 18 + pub use host::{HostFunc, IntoFunc}; 19 + pub use typed::{TypedFunc, WasmParams, WasmResults, WasmTy}; 20 + 11 21 use crate::arch; 12 22 use crate::mem::VirtualAddress; 13 23 use crate::util::zip_eq::IteratorExt; ··· 21 31 VMVal, VmPtr, 22 32 }; 23 33 use crate::wasm::{MAX_WASM_STACK, Module, Store}; 24 - use alloc::boxed::Box; 25 - use alloc::sync::Arc; 26 - use anyhow::ensure; 27 - use core::ffi::c_void; 28 - use core::mem; 29 - use core::ptr::NonNull; 30 - pub use host::{HostFunc, IntoFunc}; 31 - pub use typed::{TypedFunc, WasmParams, WasmResults, WasmTy}; 32 34 33 35 #[derive(Clone, Copy, Debug)] 34 36 pub struct Func(pub(super) Stored<FuncData>);
+7 -5
kernel/src/wasm/func/typed.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::wasm::func::do_call; 9 - use crate::wasm::store::StoreOpaque; 10 - use crate::wasm::types::{FuncType, HeapType, RefType, ValType}; 11 - use crate::wasm::vm::VMVal; 12 - use crate::wasm::{Engine, Func}; 13 8 use core::ffi::c_void; 14 9 use core::marker::PhantomData; 15 10 use core::mem::MaybeUninit; 16 11 use core::ptr; 17 12 use core::ptr::NonNull; 13 + 18 14 use static_assertions::assert_impl_all; 15 + 16 + use crate::wasm::func::do_call; 17 + use crate::wasm::store::StoreOpaque; 18 + use crate::wasm::types::{FuncType, HeapType, RefType, ValType}; 19 + use crate::wasm::vm::VMVal; 20 + use crate::wasm::{Engine, Func}; 19 21 20 22 pub struct TypedFunc<Params, Results> { 21 23 ty: FuncType,
+5 -3
kernel/src/wasm/global.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use core::ptr; 9 + use core::ptr::NonNull; 10 + 11 + use anyhow::{Context, bail}; 12 + 8 13 use crate::wasm::Func; 9 14 use crate::wasm::store::{StoreOpaque, Stored}; 10 15 use crate::wasm::types::{GlobalType, HeapTypeInner, Mutability, ValType}; 11 16 use crate::wasm::values::{Ref, Val}; 12 17 use crate::wasm::vm::{ExportedGlobal, VMGlobalDefinition, VMGlobalImport, VmPtr}; 13 - use anyhow::{Context, bail}; 14 - use core::ptr; 15 - use core::ptr::NonNull; 16 18 17 19 #[derive(Clone, Copy, Debug)] 18 20 pub struct Global(Stored<ExportedGlobal>);
+2 -1
kernel/src/wasm/indices.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use cranelift_entity::entity_impl; 9 + 8 10 use crate::wasm::utils::enum_accessors; 9 - use cranelift_entity::entity_impl; 10 11 11 12 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] 12 13 pub struct TypeIndex(u32);
+3 -2
kernel/src/wasm/instance.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use alloc::vec; 9 + use alloc::vec::Vec; 10 + 8 11 use crate::util::zip_eq::IteratorExt; 9 12 use crate::wasm::indices::EntityIndex; 10 13 use crate::wasm::module::Module; 11 14 use crate::wasm::store::{StoreOpaque, Stored}; 12 15 use crate::wasm::vm::{ConstExprEvaluator, Imports, InstanceHandle}; 13 16 use crate::wasm::{Extern, Func, Global, Memory, Table}; 14 - use alloc::vec; 15 - use alloc::vec::Vec; 16 17 17 18 /// An instantiated WebAssembly module. 18 19 ///
+8 -6
kernel/src/wasm/linker.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use alloc::sync::Arc; 9 + use alloc::vec::Vec; 10 + use core::marker::PhantomData; 11 + 12 + use anyhow::{Context, bail, format_err}; 13 + use hashbrown::HashMap; 14 + use hashbrown::hash_map::Entry; 15 + 8 16 use crate::wasm::func::{HostFunc, IntoFunc, WasmParams, WasmResults}; 9 17 use crate::wasm::indices::VMSharedTypeIndex; 10 18 use crate::wasm::store::StoreOpaque; ··· 12 20 use crate::wasm::types::{GlobalType, MemoryType, TableType, TagType}; 13 21 use crate::wasm::vm::{ConstExprEvaluator, Imports}; 14 22 use crate::wasm::{Engine, Extern, Func, Global, Instance, Memory, Module, Store, Table, Tag}; 15 - use alloc::sync::Arc; 16 - use alloc::vec::Vec; 17 - use anyhow::{Context, bail, format_err}; 18 - use core::marker::PhantomData; 19 - use hashbrown::HashMap; 20 - use hashbrown::hash_map::Entry; 21 23 22 24 /// A dynamic linker for WebAssembly modules. 23 25 #[derive(Debug)]
+3 -3
kernel/src/wasm/mod.rs
··· 31 31 mod values; 32 32 mod vm; 33 33 34 - use crate::wasm::store::StoreOpaque; 35 - use crate::wasm::utils::{enum_accessors, owned_enum_accessors}; 36 - 37 34 pub use engine::Engine; 38 35 pub use func::Func; 39 36 pub use global::Global; ··· 50 47 pub use values::Val; 51 48 #[cfg(test)] 52 49 pub use vm::{ConstExprEvaluator, PlaceholderAllocatorDontUse}; 50 + 51 + use crate::wasm::store::StoreOpaque; 52 + use crate::wasm::utils::{enum_accessors, owned_enum_accessors}; 53 53 54 54 /// The number of pages (for 32-bit modules) we can have before we run out of 55 55 /// byte index space.
+8 -6
kernel/src/wasm/module.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use alloc::string::{String, ToString}; 9 + use alloc::sync::Arc; 10 + use core::mem; 11 + use core::ops::DerefMut; 12 + use core::ptr::NonNull; 13 + 14 + use wasmparser::{Validator, WasmFeatures}; 15 + 8 16 use crate::wasm::Engine; 9 17 use crate::wasm::code_registry::{register_code, unregister_code}; 10 18 use crate::wasm::compile::{CompileInputs, CompiledFunctionInfo}; ··· 13 21 use crate::wasm::type_registry::RuntimeTypeCollection; 14 22 use crate::wasm::utils::u8_size_of; 15 23 use crate::wasm::vm::{CodeObject, MmapVec, VMArrayCallFunction, VMShape, VMWasmCallFunction}; 16 - use alloc::string::{String, ToString}; 17 - use alloc::sync::Arc; 18 - use core::mem; 19 - use core::ops::DerefMut; 20 - use core::ptr::NonNull; 21 - use wasmparser::{Validator, WasmFeatures}; 22 24 23 25 /// A compiled WebAssembly module, ready to be instantiated. 24 26 ///
+10 -8
kernel/src/wasm/store/mod.rs
··· 7 7 8 8 mod stored; 9 9 10 - use crate::mem::VirtualAddress; 11 - use crate::wasm::trap_handler::WasmFault; 12 - use crate::wasm::vm::{ 13 - InstanceAllocator, InstanceHandle, VMContext, VMFuncRef, VMGlobalDefinition, VMStoreContext, 14 - VMTableDefinition, VMVal, 15 - }; 16 - use crate::wasm::{Engine, Module, vm}; 17 - use abort::abort; 18 10 use alloc::boxed::Box; 19 11 use alloc::vec; 20 12 use alloc::vec::Vec; ··· 23 15 use core::pin::Pin; 24 16 use core::ptr::NonNull; 25 17 use core::{fmt, mem}; 18 + 19 + use abort::abort; 26 20 use pin_project::pin_project; 27 21 use static_assertions::{assert_impl_all, const_assert}; 28 22 pub use stored::{Stored, StoredData}; 23 + 24 + use crate::mem::VirtualAddress; 25 + use crate::wasm::trap_handler::WasmFault; 26 + use crate::wasm::vm::{ 27 + InstanceAllocator, InstanceHandle, VMContext, VMFuncRef, VMGlobalDefinition, VMStoreContext, 28 + VMTableDefinition, VMVal, 29 + }; 30 + use crate::wasm::{Engine, Module, vm}; 29 31 30 32 pub struct Store<T>(Pin<Box<StoreInner<T>>>); 31 33
+6 -4
kernel/src/wasm/table.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use core::ptr::NonNull; 9 + use core::sync::atomic::Ordering; 10 + 11 + use anyhow::Context; 12 + use cranelift_entity::packed_option::ReservedValue; 13 + 8 14 use crate::wasm::indices::DefinedTableIndex; 9 15 use crate::wasm::store::{StoreOpaque, Stored}; 10 16 use crate::wasm::types::TableType; 11 17 use crate::wasm::values::Ref; 12 18 use crate::wasm::vm::{ExportedTable, InstanceAndStore, TableElement, VMTableImport, VmPtr}; 13 19 use crate::wasm::{Func, vm}; 14 - use anyhow::Context; 15 - use core::ptr::NonNull; 16 - use core::sync::atomic::Ordering; 17 - use cranelift_entity::packed_option::ReservedValue; 18 20 19 21 #[derive(Clone, Copy, Debug)] 20 22 pub struct Table(Stored<ExportedTable>);
+2 -1
kernel/src/wasm/translate/const_expr.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::wasm::indices::{FuncIndex, GlobalIndex, TypeIndex}; 9 8 use anyhow::bail; 10 9 use smallvec::SmallVec; 10 + 11 + use crate::wasm::indices::{FuncIndex, GlobalIndex, TypeIndex}; 11 12 12 13 /// A constant expression. 13 14 ///
+12 -11
kernel/src/wasm/translate/mod.rs
··· 11 11 mod type_convert; 12 12 mod types; 13 13 14 - use crate::wasm::indices::{ 15 - CanonicalizedTypeIndex, DataIndex, DefinedFuncIndex, DefinedGlobalIndex, DefinedMemoryIndex, 16 - DefinedTableIndex, DefinedTagIndex, ElemIndex, EntityIndex, FieldIndex, FuncIndex, 17 - FuncRefIndex, GlobalIndex, LabelIndex, LocalIndex, MemoryIndex, ModuleInternedTypeIndex, 18 - OwnedMemoryIndex, TableIndex, TagIndex, TypeIndex, 19 - }; 20 - use crate::wasm::{DEFAULT_OFFSET_GUARD_SIZE, WASM32_MAX_SIZE}; 21 14 use alloc::boxed::Box; 22 15 use alloc::string::String; 23 16 use alloc::vec::Vec; 17 + 24 18 use anyhow::Context; 19 + pub use const_expr::{ConstExpr, ConstOp}; 25 20 use cranelift_entity::packed_option::ReservedValue; 26 21 use cranelift_entity::{EntityRef, EntitySet, PrimaryMap}; 27 22 use hashbrown::HashMap; 28 - use wasmparser::WasmFeatures; 29 - use wasmparser::collections::IndexMap; 30 - 31 - pub use const_expr::{ConstExpr, ConstOp}; 32 23 pub use module_translator::ModuleTranslator; 33 24 pub use module_types::ModuleTypes; 34 25 pub use type_convert::WasmparserTypeConverter; ··· 37 28 WasmHeapTopType, WasmHeapType, WasmHeapTypeInner, WasmRecGroup, WasmRefType, WasmStorageType, 38 29 WasmSubType, WasmValType, 39 30 }; 31 + use wasmparser::WasmFeatures; 32 + use wasmparser::collections::IndexMap; 33 + 34 + use crate::wasm::indices::{ 35 + CanonicalizedTypeIndex, DataIndex, DefinedFuncIndex, DefinedGlobalIndex, DefinedMemoryIndex, 36 + DefinedTableIndex, DefinedTagIndex, ElemIndex, EntityIndex, FieldIndex, FuncIndex, 37 + FuncRefIndex, GlobalIndex, LabelIndex, LocalIndex, MemoryIndex, ModuleInternedTypeIndex, 38 + OwnedMemoryIndex, TableIndex, TagIndex, TypeIndex, 39 + }; 40 + use crate::wasm::{DEFAULT_OFFSET_GUARD_SIZE, WASM32_MAX_SIZE}; 40 41 41 42 #[derive(Debug)] 42 43 pub struct ModuleTranslation<'data> {
+15 -13
kernel/src/wasm/translate/module_translator.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::wasm::indices::{ 9 - CanonicalizedTypeIndex, DataIndex, ElemIndex, EntityIndex, FieldIndex, FuncIndex, FuncRefIndex, 10 - GlobalIndex, LabelIndex, LocalIndex, MemoryIndex, TableIndex, TagIndex, TypeIndex, 11 - }; 12 - use crate::wasm::translate::module_types::{ModuleTypes, ModuleTypesBuilder}; 13 - use crate::wasm::translate::type_convert::WasmparserTypeConverter; 14 - use crate::wasm::translate::types::EntityType; 15 - use crate::wasm::translate::{ 16 - ConstExpr, Function, FunctionBodyData, Global, Import, Memory, MemoryInitializer, 17 - ModuleTranslation, ProducersLanguage, ProducersLanguageField, ProducersSdk, ProducersSdkField, 18 - ProducersTool, ProducersToolField, Table, TableInitialValue, TableSegment, 19 - TableSegmentElements, Tag, 20 - }; 21 8 use alloc::string::ToString; 22 9 use alloc::sync::Arc; 23 10 use alloc::vec::Vec; 11 + 24 12 use cranelift_entity::packed_option::ReservedValue; 25 13 use hashbrown::HashMap; 26 14 use wasmparser::{ ··· 30 18 NameSectionReader, Parser, Payload, ProducersFieldValue, ProducersSectionReader, TableInit, 31 19 TableSectionReader, TagKind, TagSectionReader, TypeRef, TypeSectionReader, Validator, 32 20 WasmFeatures, 21 + }; 22 + 23 + use crate::wasm::indices::{ 24 + CanonicalizedTypeIndex, DataIndex, ElemIndex, EntityIndex, FieldIndex, FuncIndex, FuncRefIndex, 25 + GlobalIndex, LabelIndex, LocalIndex, MemoryIndex, TableIndex, TagIndex, TypeIndex, 26 + }; 27 + use crate::wasm::translate::module_types::{ModuleTypes, ModuleTypesBuilder}; 28 + use crate::wasm::translate::type_convert::WasmparserTypeConverter; 29 + use crate::wasm::translate::types::EntityType; 30 + use crate::wasm::translate::{ 31 + ConstExpr, Function, FunctionBodyData, Global, Import, Memory, MemoryInitializer, 32 + ModuleTranslation, ProducersLanguage, ProducersLanguageField, ProducersSdk, ProducersSdkField, 33 + ProducersTool, ProducersToolField, Table, TableInitialValue, TableSegment, 34 + TableSegmentElements, Tag, 33 35 }; 34 36 35 37 /// A translator for converting the output of `wasmparser` into types used by this crate.
+8 -6
kernel/src/wasm/translate/module_types.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::wasm::indices::{ModuleInternedRecGroupIndex, ModuleInternedTypeIndex}; 9 - use crate::wasm::translate::type_convert::WasmparserTypeConverter; 10 - use crate::wasm::translate::types::WasmSubType; 11 - use crate::wasm::translate::{ 12 - TranslatedModule, WasmCompositeType, WasmCompositeTypeInner, WasmFuncType, 13 - }; 14 8 use alloc::borrow::Cow; 15 9 use alloc::vec::Vec; 16 10 use core::fmt; 17 11 use core::range::Range; 12 + 18 13 use cranelift_entity::packed_option::PackedOption; 19 14 use cranelift_entity::{EntityRef, PrimaryMap, SecondaryMap}; 20 15 use hashbrown::HashMap; 21 16 use wasmparser::{Validator, ValidatorId}; 17 + 18 + use crate::wasm::indices::{ModuleInternedRecGroupIndex, ModuleInternedTypeIndex}; 19 + use crate::wasm::translate::type_convert::WasmparserTypeConverter; 20 + use crate::wasm::translate::types::WasmSubType; 21 + use crate::wasm::translate::{ 22 + TranslatedModule, WasmCompositeType, WasmCompositeTypeInner, WasmFuncType, 23 + }; 22 24 23 25 /// Types defined within a single WebAssembly module. 24 26 #[derive(Debug, Default)]
+6 -4
kernel/src/wasm/translate/type_convert.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use alloc::vec::Vec; 9 + 10 + use wasmparser::UnpackedIndex; 11 + 8 12 use crate::wasm::indices::{CanonicalizedTypeIndex, ModuleInternedTypeIndex, TypeIndex}; 9 13 use crate::wasm::translate::types::{ 10 14 WasmArrayType, WasmCompositeType, WasmCompositeTypeInner, WasmFieldType, WasmHeapType, 11 15 WasmHeapTypeInner, WasmRefType, WasmStorageType, WasmStructType, WasmValType, 12 16 }; 13 17 use crate::wasm::translate::{ModuleTypes, TranslatedModule, WasmFuncType, WasmSubType}; 14 - use alloc::vec::Vec; 15 - use wasmparser::UnpackedIndex; 16 18 17 19 /// A type that knows how to convert from `wasmparser` types to types in this crate. 18 20 pub struct WasmparserTypeConverter<'a> { ··· 48 50 match ty { 49 51 wasmparser::HeapType::Concrete(index) => self.lookup_heap_type(index), 50 52 wasmparser::HeapType::Abstract { shared, ty } => { 51 - use crate::wasm::translate::types::WasmHeapTypeInner::*; 52 - 53 53 use wasmparser::AbstractHeapType; 54 + 55 + use crate::wasm::translate::types::WasmHeapTypeInner::*; 54 56 let ty = match ty { 55 57 AbstractHeapType::Func => Func, 56 58 AbstractHeapType::Extern => Extern,
+4 -3
kernel/src/wasm/translate/types.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use alloc::borrow::Cow; 9 + use alloc::boxed::Box; 10 + use core::fmt; 11 + 8 12 use crate::wasm::indices::CanonicalizedTypeIndex; 9 13 use crate::wasm::translate::{Global, Memory, Table}; 10 14 use crate::wasm::type_registry::TypeTrace; 11 15 use crate::wasm::utils::enum_accessors; 12 - use alloc::borrow::Cow; 13 - use alloc::boxed::Box; 14 - use core::fmt; 15 16 16 17 /// Represents the types of values in a WebAssembly module. 17 18 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+1
kernel/src/wasm/trap.rs
··· 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 8 use core::fmt; 9 + 9 10 use cranelift_codegen::ir::TrapCode; 10 11 11 12 const TRAP_OFFSET: u8 = 1;
+8 -6
kernel/src/wasm/trap_handler.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 - use crate::mem::VirtualAddress; 10 - use crate::wasm::TrapKind; 11 - use crate::wasm::code_registry::lookup_code; 12 - use crate::wasm::store::StoreOpaque; 13 - use crate::wasm::vm::{VMContext, VMStoreContext}; 14 8 use alloc::boxed::Box; 15 9 use alloc::vec; 16 10 use alloc::vec::Vec; ··· 20 14 use core::panic::AssertUnwindSafe; 21 15 use core::ptr::NonNull; 22 16 use core::{fmt, ptr}; 17 + 23 18 use cpu_local::cpu_local; 19 + 20 + use crate::arch; 21 + use crate::mem::VirtualAddress; 22 + use crate::wasm::TrapKind; 23 + use crate::wasm::code_registry::lookup_code; 24 + use crate::wasm::store::StoreOpaque; 25 + use crate::wasm::vm::{VMContext, VMStoreContext}; 24 26 25 27 /// Description about a fault that occurred in WebAssembly. 26 28 #[derive(Debug)]
+9 -7
kernel/src/wasm/type_registry.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::wasm::Engine; 9 - use crate::wasm::indices::{ 10 - CanonicalizedTypeIndex, ModuleInternedTypeIndex, RecGroupRelativeTypeIndex, VMSharedTypeIndex, 11 - }; 12 - use crate::wasm::translate::{ 13 - ModuleTypes, WasmCompositeType, WasmCompositeTypeInner, WasmRecGroup, WasmSubType, 14 - }; 15 8 use alloc::borrow::Cow; 16 9 use alloc::boxed::Box; 17 10 use alloc::sync::Arc; ··· 23 16 use core::range::Range; 24 17 use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; 25 18 use core::{fmt, iter}; 19 + 26 20 use cranelift_entity::packed_option::{PackedOption, ReservedValue}; 27 21 use cranelift_entity::{PrimaryMap, SecondaryMap, iter_entity_range}; 28 22 use hashbrown::HashSet; 29 23 use spin::RwLock; 30 24 use wasmtime_slab::Slab; 25 + 26 + use crate::wasm::Engine; 27 + use crate::wasm::indices::{ 28 + CanonicalizedTypeIndex, ModuleInternedTypeIndex, RecGroupRelativeTypeIndex, VMSharedTypeIndex, 29 + }; 30 + use crate::wasm::translate::{ 31 + ModuleTypes, WasmCompositeType, WasmCompositeTypeInner, WasmRecGroup, WasmSubType, 32 + }; 31 33 32 34 pub trait TypeTrace { 33 35 /// Visit each edge.
+7 -6
kernel/src/wasm/types.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use alloc::string::{String, ToString}; 9 + use alloc::vec::Vec; 10 + use core::fmt; 11 + use core::fmt::{Display, Write}; 12 + 13 + use anyhow::{bail, ensure}; 14 + 8 15 use crate::wasm::Engine; 9 16 use crate::wasm::indices::{CanonicalizedTypeIndex, VMSharedTypeIndex}; 10 17 use crate::wasm::translate::{ ··· 13 20 WasmSubType, WasmValType, 14 21 }; 15 22 use crate::wasm::type_registry::RegisteredType; 16 - use alloc::string::{String, ToString}; 17 - use alloc::vec::Vec; 18 - use anyhow::{bail, ensure}; 19 - use core::fmt; 20 - use core::fmt::Display; 21 - use core::fmt::Write; 22 23 23 24 /// Indicator of whether a global value, struct's field, or array type's 24 25 /// elements are mutable or not.
+3 -2
kernel/src/wasm/utils.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch::PAGE_SIZE; 9 - use crate::wasm::translate::{WasmFuncType, WasmHeapTopType, WasmHeapType, WasmValType}; 10 8 use cranelift_codegen::ir; 11 9 use cranelift_codegen::ir::{AbiParam, ArgumentPurpose, Signature}; 12 10 use cranelift_codegen::isa::{CallConv, TargetIsa}; 11 + 12 + use crate::arch::PAGE_SIZE; 13 + use crate::wasm::translate::{WasmFuncType, WasmHeapTopType, WasmHeapType, WasmValType}; 13 14 14 15 /// Helper macro to generate accessors for an enum. 15 16 macro_rules! enum_accessors {
+4 -2
kernel/src/wasm/values.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use core::ptr; 9 + 10 + use anyhow::bail; 11 + 8 12 use crate::wasm::Func; 9 13 use crate::wasm::store::StoreOpaque; 10 14 use crate::wasm::types::{HeapType, HeapTypeInner, RefType, ValType}; 11 15 use crate::wasm::utils::enum_accessors; 12 16 use crate::wasm::vm::{TableElement, VMVal}; 13 - use anyhow::bail; 14 - use core::ptr; 15 17 16 18 #[derive(Debug, Clone, Copy)] 17 19 pub enum Val {
+2 -1
kernel/src/wasm/vm/builtins.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use core::ptr::NonNull; 9 + 8 10 use crate::wasm::TrapKind; 9 11 use crate::wasm::indices::{DataIndex, ElemIndex, MemoryIndex, TableIndex}; 10 12 use crate::wasm::store::StoreOpaque; ··· 12 14 use crate::wasm::vm::instance::Instance; 13 15 use crate::wasm::vm::table::{TableElement, TableElementType}; 14 16 use crate::wasm::vm::{Table, VMFuncRef}; 15 - use core::ptr::NonNull; 16 17 17 18 /// A helper structure to represent the return value of a memory or table growth 18 19 /// call.
+8 -6
kernel/src/wasm/vm/code_object.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::mem::{AddressSpace, Mmap, VirtualAddress}; 9 - use crate::wasm::TrapKind; 10 - use crate::wasm::compile::{CompiledFunctionInfo, FunctionLoc}; 11 - use crate::wasm::indices::{DefinedFuncIndex, ModuleInternedTypeIndex}; 12 - use crate::wasm::vm::{MmapVec, VMWasmCallFunction}; 13 8 use alloc::vec; 14 9 use alloc::vec::Vec; 15 - use anyhow::Context; 16 10 use core::ptr::NonNull; 17 11 use core::range::Range; 18 12 use core::slice; 13 + 14 + use anyhow::Context; 19 15 use cranelift_entity::PrimaryMap; 16 + 17 + use crate::mem::{AddressSpace, Mmap, VirtualAddress}; 18 + use crate::wasm::TrapKind; 19 + use crate::wasm::compile::{CompiledFunctionInfo, FunctionLoc}; 20 + use crate::wasm::indices::{DefinedFuncIndex, ModuleInternedTypeIndex}; 21 + use crate::wasm::vm::{MmapVec, VMWasmCallFunction}; 20 22 21 23 #[derive(Debug)] 22 24 pub struct CodeObject {
+3 -2
kernel/src/wasm/vm/const_eval.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use anyhow::bail; 9 + use smallvec::SmallVec; 10 + 8 11 use crate::wasm::indices::{FuncIndex, GlobalIndex, VMSharedTypeIndex}; 9 12 use crate::wasm::store::StoreOpaque; 10 13 use crate::wasm::translate::{ ··· 13 16 }; 14 17 use crate::wasm::vm::instance::Instance; 15 18 use crate::wasm::vm::vmcontext::VMVal; 16 - use anyhow::bail; 17 - use smallvec::SmallVec; 18 19 19 20 /// Simple interpreter for constant expressions. 20 21 #[derive(Debug, Default)]
+12 -10
kernel/src/wasm/vm/instance.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use alloc::string::String; 9 + use core::alloc::Layout; 10 + use core::marker::PhantomPinned; 11 + use core::ptr::NonNull; 12 + use core::sync::atomic::{AtomicU64, Ordering}; 13 + use core::{fmt, ptr, slice}; 14 + 15 + use anyhow::{bail, ensure}; 16 + use cranelift_entity::packed_option::ReservedValue; 17 + use cranelift_entity::{EntityRef, EntitySet, PrimaryMap}; 18 + use static_assertions::const_assert_eq; 19 + 8 20 use crate::mem::VirtualAddress; 9 21 use crate::wasm::TrapKind; 10 22 use crate::wasm::indices::{ ··· 30 42 VMOpaqueContext, VMShape, VMStoreContext, VMTableDefinition, VMTableImport, VMTagDefinition, 31 43 VMTagImport, 32 44 }; 33 - use alloc::string::String; 34 - use anyhow::{bail, ensure}; 35 - use core::alloc::Layout; 36 - use core::marker::PhantomPinned; 37 - use core::ptr::NonNull; 38 - use core::sync::atomic::{AtomicU64, Ordering}; 39 - use core::{fmt, ptr, slice}; 40 - use cranelift_entity::packed_option::ReservedValue; 41 - use cranelift_entity::{EntityRef, EntitySet, PrimaryMap}; 42 - use static_assertions::const_assert_eq; 43 45 44 46 #[derive(Debug)] 45 47 pub struct InstanceHandle {
+8 -6
kernel/src/wasm/vm/instance_alloc.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use core::alloc::Allocator; 9 + use core::ops::DerefMut; 10 + use core::ptr::NonNull; 11 + use core::{cmp, mem}; 12 + 13 + use anyhow::Context; 14 + use cranelift_entity::PrimaryMap; 15 + 8 16 use crate::mem::Mmap; 9 17 use crate::wasm::indices::{DefinedMemoryIndex, DefinedTableIndex}; 10 18 use crate::wasm::module::Module; ··· 14 22 use crate::wasm::vm::mmap_vec::MmapVec; 15 23 use crate::wasm::vm::{InstanceHandle, TableElement, VMShape}; 16 24 use crate::wasm::{MEMORY_MAX, TABLE_MAX, translate, vm}; 17 - use anyhow::Context; 18 - use core::alloc::Allocator; 19 - use core::ops::DerefMut; 20 - use core::ptr::NonNull; 21 - use core::{cmp, mem}; 22 - use cranelift_entity::PrimaryMap; 23 25 24 26 /// A type that knows how to allocate backing memory for instance resources. 25 27 pub trait InstanceAllocator {
+3 -2
kernel/src/wasm/vm/memory.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use core::ptr::NonNull; 9 + use core::range::Range; 10 + 8 11 use crate::mem::{Mmap, VirtualAddress}; 9 12 use crate::wasm::vm::VMMemoryDefinition; 10 13 use crate::wasm::vm::provenance::VmPtr; 11 - use core::ptr::NonNull; 12 - use core::range::Range; 13 14 14 15 #[derive(Debug)] 15 16 pub struct Memory {
+5 -3
kernel/src/wasm/vm/mmap_vec.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 - use crate::mem::{AddressSpace, Mmap}; 10 8 use alloc::sync::Arc; 11 - use anyhow::Context; 12 9 use core::cmp::max; 13 10 use core::marker::PhantomData; 14 11 use core::ops::Deref; 15 12 use core::range::Range; 16 13 use core::slice; 14 + 15 + use anyhow::Context; 17 16 use spin::Mutex; 17 + 18 + use crate::arch; 19 + use crate::mem::{AddressSpace, Mmap}; 18 20 19 21 #[derive(Debug)] 20 22 pub struct MmapVec<T> {
+4 -3
kernel/src/wasm/vm/mod.rs
··· 20 20 use alloc::vec::Vec; 21 21 use core::ptr::NonNull; 22 22 23 - use crate::wasm::indices::DefinedMemoryIndex; 24 - use crate::wasm::translate; 25 - use crate::wasm::translate::TranslatedModule; 26 23 pub use code_object::CodeObject; 27 24 pub use const_eval::ConstExprEvaluator; 28 25 pub use instance::{Instance, InstanceAndStore, InstanceHandle}; ··· 35 32 pub use table::{Table, TableElement}; 36 33 pub use vmcontext::*; 37 34 pub use vmshape::{StaticVMShape, VMShape}; 35 + 36 + use crate::wasm::indices::DefinedMemoryIndex; 37 + use crate::wasm::translate; 38 + use crate::wasm::translate::TranslatedModule; 38 39 39 40 /// The value of an export passed from one instance to another. 40 41 #[derive(Debug, Clone)]
+2 -1
kernel/src/wasm/vm/provenance.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::wasm::indices::VMSharedTypeIndex; 9 8 use core::fmt; 10 9 use core::marker::PhantomData; 11 10 use core::num::NonZeroUsize; 12 11 use core::ptr::NonNull; 13 12 use core::sync::atomic::AtomicUsize; 13 + 14 + use crate::wasm::indices::VMSharedTypeIndex; 14 15 15 16 /// A pointer that is used by compiled code, or in other words is accessed 16 17 /// outside of Rust.
+6 -4
kernel/src/wasm/vm/table.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use core::ptr; 9 + use core::ptr::NonNull; 10 + use core::range::Range; 11 + 12 + use anyhow::anyhow; 13 + 8 14 use crate::wasm::TrapKind; 9 15 use crate::wasm::vm::mmap_vec::MmapVec; 10 16 use crate::wasm::vm::provenance::VmPtr; 11 17 use crate::wasm::vm::{VMFuncRef, VMTableDefinition}; 12 - use anyhow::anyhow; 13 - use core::ptr; 14 - use core::ptr::NonNull; 15 - use core::range::Range; 16 18 17 19 #[derive(Debug, Clone, Copy)] 18 20 pub enum TableElement {
+10 -8
kernel/src/wasm/vm/vmcontext.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::mem::VirtualAddress; 9 - use crate::wasm::builtins::{BuiltinFunctionIndex, foreach_builtin_function}; 10 - use crate::wasm::indices::{DefinedMemoryIndex, VMSharedTypeIndex}; 11 - use crate::wasm::store::StoreOpaque; 12 - use crate::wasm::translate::{WasmHeapTopType, WasmValType}; 13 - use crate::wasm::type_registry::RegisteredType; 14 - use crate::wasm::types::FuncType; 15 - use crate::wasm::vm::provenance::{VmPtr, VmSafe}; 16 8 use alloc::boxed::Box; 17 9 use core::any::Any; 18 10 use core::cell::UnsafeCell; ··· 22 14 use core::ptr::NonNull; 23 15 use core::sync::atomic::{AtomicUsize, Ordering}; 24 16 use core::{fmt, ptr}; 17 + 25 18 use cranelift_entity::Unsigned; 26 19 use static_assertions::const_assert_eq; 20 + 21 + use crate::mem::VirtualAddress; 22 + use crate::wasm::builtins::{BuiltinFunctionIndex, foreach_builtin_function}; 23 + use crate::wasm::indices::{DefinedMemoryIndex, VMSharedTypeIndex}; 24 + use crate::wasm::store::StoreOpaque; 25 + use crate::wasm::translate::{WasmHeapTopType, WasmValType}; 26 + use crate::wasm::type_registry::RegisteredType; 27 + use crate::wasm::types::FuncType; 28 + use crate::wasm::vm::provenance::{VmPtr, VmSafe}; 27 29 28 30 /// Magic value for core Wasm VM contexts. 29 31 ///
+5 -3
libs/cpu-local/src/collection.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::cpu_local; 9 8 use alloc::boxed::Box; 10 9 use core::cell::UnsafeCell; 11 10 use core::iter::FusedIterator; 12 11 use core::panic::UnwindSafe; 13 12 use core::sync::atomic::{AtomicBool, AtomicPtr, AtomicUsize, Ordering}; 14 13 use core::{fmt, mem, ptr, slice}; 14 + 15 15 use util::CheckedMaybeUninit; 16 + 17 + use crate::cpu_local; 16 18 17 19 /// The total number of buckets stored in each cpu-local storage. 18 20 /// All buckets combined can hold up to `usize::MAX - 1` entries. ··· 568 570 569 571 #[cfg(test)] 570 572 mod tests { 571 - use super::*; 572 573 use alloc::string::String; 573 - 574 574 use alloc::sync::Arc; 575 575 use core::cell::RefCell; 576 576 use core::sync::atomic::AtomicUsize; 577 577 use core::sync::atomic::Ordering::Relaxed; 578 578 use std::thread; 579 + 580 + use super::*; 579 581 580 582 fn make_create() -> Arc<dyn Fn() -> usize + Send + Sync> { 581 583 let count = AtomicUsize::new(0);
+4 -2
libs/fdt/src/lib.rs
··· 10 10 mod error; 11 11 mod parser; 12 12 13 - pub use crate::error::Error; 14 - use crate::parser::{BigEndianToken, Parser, StringsBlock, StructsBlock}; 15 13 use core::ffi::CStr; 16 14 use core::{fmt, slice}; 15 + 17 16 use fallible_iterator::FallibleIterator; 17 + 18 + pub use crate::error::Error; 19 + use crate::parser::{BigEndianToken, Parser, StringsBlock, StructsBlock}; 18 20 19 21 const DTB_MAGIC: u32 = 0xD00D_FEED; 20 22
+3 -1
libs/kaddr2line/src/frame.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::{Error, Function, InlinedFunction, ResUnit, maybe_small}; 9 8 use core::iter; 9 + 10 10 use fallible_iterator::FallibleIterator; 11 + 12 + use crate::{Error, Function, InlinedFunction, ResUnit, maybe_small}; 11 13 12 14 /// A source location. 13 15 pub struct Location<'a> {
+7 -5
libs/kaddr2line/src/unit.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::{ 9 - Context, DebugFile, Error, Function, LazyFunctions, LazyLines, LazyResult, 10 - LineLocationRangeIter, Lines, Location, LookupContinuation, LookupResult, RangeAttributes, 11 - SimpleLookup, SplitDwarfLoad, 12 - }; 13 8 use alloc::boxed::Box; 14 9 use alloc::sync::Arc; 15 10 use alloc::vec::Vec; 16 11 use core::cmp; 12 + 17 13 use fallible_iterator::FallibleIterator; 14 + 15 + use crate::{ 16 + Context, DebugFile, Error, Function, LazyFunctions, LazyLines, LazyResult, 17 + LineLocationRangeIter, Lines, Location, LookupContinuation, LookupResult, RangeAttributes, 18 + SimpleLookup, SplitDwarfLoad, 19 + }; 18 20 19 21 pub(crate) struct UnitRange { 20 22 unit_id: usize,
+2 -1
libs/kasync/benches/spawn.rs
··· 1 + use std::hint::black_box; 2 + 1 3 use criterion::{Criterion, criterion_group, criterion_main}; 2 4 use fastrand::FastRand; 3 5 use kasync2::executor::{Executor, Worker}; 4 - use std::hint::black_box; 5 6 6 7 async fn work() -> usize { 7 8 let val = 1 + 1;
+13 -10
libs/kasync/src/executor.rs
··· 7 7 8 8 mod steal; 9 9 10 - use crate::error::Closed; 11 - use crate::error::SpawnError; 12 - use crate::executor::steal::{Injector, Stealer, TryStealError}; 13 - use crate::future::Either; 14 - use crate::loom::sync::atomic::{AtomicPtr, AtomicUsize}; 15 - use crate::sync::wait_queue::WaitQueue; 16 - use crate::task::{Header, JoinHandle, PollResult, Task, TaskBuilder, TaskRef}; 17 10 use alloc::boxed::Box; 18 - use cordyceps::mpsc_queue::{MpscQueue, TryDequeueError}; 19 11 use core::alloc::Allocator; 20 12 use core::num::NonZeroUsize; 21 13 use core::ptr; 22 14 use core::ptr::NonNull; 23 15 use core::sync::atomic::Ordering; 16 + 17 + use cordyceps::mpsc_queue::{MpscQueue, TryDequeueError}; 24 18 use cpu_local::collection::CpuLocal; 25 19 use fastrand::FastRand; 26 20 use futures::pin_mut; 27 21 use spin::Backoff; 22 + 23 + use crate::error::{Closed, SpawnError}; 24 + use crate::executor::steal::{Injector, Stealer, TryStealError}; 25 + use crate::future::Either; 26 + use crate::loom::sync::atomic::{AtomicPtr, AtomicUsize}; 27 + use crate::sync::wait_queue::WaitQueue; 28 + use crate::task::{Header, JoinHandle, PollResult, Task, TaskBuilder, TaskRef}; 28 29 29 30 #[derive(Debug)] 30 31 pub struct Executor { ··· 491 492 492 493 #[cfg(test)] 493 494 mod tests { 494 - use super::*; 495 - use crate::{loom, test_util}; 496 495 use core::hint::black_box; 497 496 use core::sync::atomic::AtomicBool; 497 + 498 498 use tracing_subscriber::EnvFilter; 499 499 use tracing_subscriber::util::SubscriberInitExt; 500 + 501 + use super::*; 502 + use crate::{loom, test_util}; 500 503 501 504 async fn work() -> usize { 502 505 let val = 1 + 1;
+6 -4
libs/kasync/src/executor/steal.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::executor::Scheduler; 9 - use crate::loom::sync::atomic::{AtomicUsize, Ordering}; 10 - use crate::task::{Header, Task, TaskRef}; 11 8 use alloc::boxed::Box; 12 - use cordyceps::{MpscQueue, mpsc_queue}; 13 9 use core::fmt::Debug; 14 10 use core::num::NonZeroUsize; 11 + 12 + use cordyceps::{MpscQueue, mpsc_queue}; 13 + 14 + use crate::executor::Scheduler; 15 + use crate::loom::sync::atomic::{AtomicUsize, Ordering}; 16 + use crate::task::{Header, Task, TaskRef}; 15 17 16 18 #[derive(Debug, Clone, Eq, PartialEq)] 17 19 #[non_exhaustive]
+3 -2
libs/kasync/src/sync/oneshot.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::loom::cell::UnsafeCell; 9 - use crate::sync::WaitCell; 10 8 use alloc::sync::Arc; 11 9 use core::fmt; 12 10 use core::pin::Pin; 13 11 use core::task::{Context, Poll, ready}; 12 + 13 + use crate::loom::cell::UnsafeCell; 14 + use crate::sync::WaitCell; 14 15 15 16 pub fn channel<T>() -> (Sender<T>, Receiver<T>) { 16 17 let inner = Arc::new(Inner {
+6 -4
libs/kasync/src/sync/wait_cell.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::error::Closed; 9 - use crate::loom::cell::UnsafeCell; 10 - use crate::loom::sync::atomic::{AtomicUsize, Ordering}; 11 - use bitflags::bitflags; 12 8 use core::panic::{RefUnwindSafe, UnwindSafe}; 13 9 use core::pin::Pin; 14 10 use core::task::{Context, Poll, Waker}; 15 11 use core::{fmt, task}; 12 + 13 + use bitflags::bitflags; 16 14 use static_assertions::const_assert_eq; 17 15 use util::{CachePadded, loom_const_fn}; 16 + 17 + use crate::error::Closed; 18 + use crate::loom::cell::UnsafeCell; 19 + use crate::loom::sync::atomic::{AtomicUsize, Ordering}; 18 20 19 21 /// An atomically registered [`Waker`]. 20 22 ///
+5 -3
libs/kasync/src/sync/wait_queue.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::error::Closed; 9 - use crate::sync::wake_batch::WakeBatch; 10 8 use alloc::sync::Arc; 11 - use cordyceps::{Linked, List, list}; 12 9 use core::cell::UnsafeCell; 13 10 use core::marker::PhantomPinned; 14 11 use core::pin::Pin; ··· 16 13 use core::sync::atomic::{AtomicUsize, Ordering}; 17 14 use core::task::{Context, Poll, Waker}; 18 15 use core::{fmt, mem, ptr}; 16 + 17 + use cordyceps::{Linked, List, list}; 19 18 use mycelium_bitfield::{FromBits, bitfield, enum_from_bits}; 20 19 use pin_project::{pin_project, pinned_drop}; 21 20 use spin::{Mutex, MutexGuard}; 22 21 use util::{CachePadded, loom_const_fn}; 22 + 23 + use crate::error::Closed; 24 + use crate::sync::wake_batch::WakeBatch; 23 25 24 26 /// A queue of waiting tasks which can be [woken in first-in, first-out 25 27 /// order][wake], or [all at once][wake_all].
+2 -1
libs/kasync/src/sync/wake_batch.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use core::task::Waker; 9 + 8 10 use arrayvec::ArrayVec; 9 - use core::task::Waker; 10 11 11 12 const NUM_WAKERS: usize = 32; 12 13
+6 -5
libs/kasync/src/task.rs
··· 11 11 mod state; 12 12 mod yield_now; 13 13 14 - use crate::loom::cell::UnsafeCell; 15 - use crate::task::state::{JoinAction, StartPollAction, State, WakeByRefAction, WakeByValAction}; 16 14 use alloc::boxed::Box; 17 - use cordyceps::mpsc_queue; 18 15 use core::alloc::Allocator; 19 16 use core::any::type_name; 20 17 use core::mem::offset_of; ··· 24 21 use core::sync::atomic::Ordering; 25 22 use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; 26 23 use core::{fmt, mem}; 27 - use util::{CachePadded, CheckedMaybeUninit, loom_const_fn}; 28 24 29 - use crate::executor::Scheduler; 30 25 pub use builder::TaskBuilder; 26 + use cordyceps::mpsc_queue; 31 27 pub use id::Id; 32 28 pub use join_handle::{JoinError, JoinHandle}; 29 + use util::{CachePadded, CheckedMaybeUninit, loom_const_fn}; 33 30 pub use yield_now::yield_now; 31 + 32 + use crate::executor::Scheduler; 33 + use crate::loom::cell::UnsafeCell; 34 + use crate::task::state::{JoinAction, StartPollAction, State, WakeByRefAction, WakeByValAction}; 34 35 35 36 /// Outcome of calling [`Task::poll`]. 36 37 ///
+5 -5
libs/kasync/src/task/builder.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::error::Closed; 9 - use crate::error::SpawnError; 10 - use crate::task::id::Id; 11 - use crate::task::join_handle::JoinHandle; 12 - use crate::task::{Task, TaskRef}; 13 8 use alloc::boxed::Box; 14 9 use core::alloc::Allocator; 15 10 use core::any::type_name; 16 11 use core::panic::Location; 12 + 13 + use crate::error::{Closed, SpawnError}; 14 + use crate::task::id::Id; 15 + use crate::task::join_handle::JoinHandle; 16 + use crate::task::{Task, TaskRef}; 17 17 18 18 pub struct TaskBuilder<'a, S> { 19 19 location: Option<Location<'a>>,
+2 -1
libs/kasync/src/task/id.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use core::fmt; 9 + 8 10 use crate::loom::sync::atomic::{AtomicU64, Ordering}; 9 - use core::fmt; 10 11 11 12 /// An opaque ID that uniquely identifies a task relative to all other currently 12 13 /// running tasks.
+2 -2
libs/kasync/src/task/join_handle.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::task::Id; 9 - use crate::task::TaskRef; 10 8 use alloc::boxed::Box; 11 9 use alloc::string::String; 12 10 use core::any::Any; ··· 17 15 use core::panic::{RefUnwindSafe, UnwindSafe}; 18 16 use core::pin::Pin; 19 17 use core::task::{Context, Poll}; 18 + 19 + use crate::task::{Id, TaskRef}; 20 20 21 21 pub struct JoinHandle<T> { 22 22 state: JoinHandleState,
+4 -2
libs/kasync/src/task/state.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::loom::sync::atomic::{self, AtomicUsize, Ordering}; 9 - use crate::task::PollResult; 10 8 use core::fmt; 9 + 11 10 use spin::Backoff; 12 11 use util::loom_const_fn; 12 + 13 + use crate::loom::sync::atomic::{self, AtomicUsize, Ordering}; 14 + use crate::task::PollResult; 13 15 14 16 /// Task state. The task stores its state in an atomic `usize` with various bitfields for the 15 17 /// necessary information. The state has the following layout:
+3 -2
libs/kasync/src/test_util.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::loom::sync::Arc; 9 - use crate::loom::sync::{Condvar, Mutex as StdMutex}; 10 8 use core::mem::ManuallyDrop; 11 9 use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; 10 + 12 11 use futures::pin_mut; 13 12 use futures::task::WakerRef; 14 13 use util::loom_const_fn; 14 + 15 + use crate::loom::sync::{Arc, Condvar, Mutex as StdMutex}; 15 16 16 17 #[derive(Debug)] 17 18 pub struct ThreadNotify {
+2 -1
libs/kasync/src/time.rs
··· 13 13 mod timeout; 14 14 mod timer; 15 15 16 - use core::{fmt, time::Duration}; 16 + use core::fmt; 17 + use core::time::Duration; 17 18 18 19 pub use clock::{Clock, RawClock, RawClockVTable}; 19 20 pub use instant::Instant;
+2 -1
libs/kasync/src/time/clock.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::time::max_duration; 9 8 use core::fmt; 10 9 use core::time::Duration; 10 + 11 + use crate::time::max_duration; 11 12 12 13 pub struct Clock { 13 14 name: &'static str,
+2 -1
libs/kasync/src/time/instant.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::time::{NANOS_PER_SEC, Ticks, TimeError, Timer}; 9 8 use core::fmt; 10 9 use core::ops::{Add, AddAssign, Sub, SubAssign}; 11 10 use core::time::Duration; 11 + 12 + use crate::time::{NANOS_PER_SEC, Ticks, TimeError, Timer}; 12 13 13 14 /// A measurement of a monotonically nondecreasing clock. 14 15 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
+16 -16
libs/kasync/src/time/sleep.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use core::fmt; 9 + use core::pin::Pin; 10 + use core::task::{Context, Poll, ready}; 11 + use core::time::Duration; 12 + 13 + use pin_project::{pin_project, pinned_drop}; 14 + 8 15 use crate::loom::sync::atomic::Ordering; 9 - use crate::time::Ticks; 10 - use crate::time::{TimeError, Timer, instant::Instant, timer::Entry}; 11 - use core::{ 12 - fmt, 13 - pin::Pin, 14 - task::{Context, Poll, ready}, 15 - time::Duration, 16 - }; 17 - use pin_project::{pin_project, pinned_drop}; 16 + use crate::time::instant::Instant; 17 + use crate::time::timer::Entry; 18 + use crate::time::{Ticks, TimeError, Timer}; 18 19 19 20 /// Wait until duration has elapsed. 20 21 /// ··· 139 140 140 141 #[cfg(test)] 141 142 mod tests { 143 + use fastrand::FastRand; 144 + use tracing_subscriber::EnvFilter; 145 + use tracing_subscriber::fmt::format::FmtSpan; 146 + 142 147 use super::*; 148 + use crate::executor::{Executor, Worker}; 149 + use crate::loom; 143 150 use crate::loom::sync::atomic::{AtomicBool, Ordering}; 144 151 use crate::time::test_util::MockClock; 145 - use crate::{ 146 - executor::{Executor, Worker}, 147 - loom, 148 - }; 149 - use fastrand::FastRand; 150 - use tracing_subscriber::EnvFilter; 151 - use tracing_subscriber::fmt::format::FmtSpan; 152 152 153 153 // loom is not happy about this test. For whatever reason it triggers the "too many branches" 154 154 // error. But both the regular test AND miri are fine with it
+3 -3
libs/kasync/src/time/test_util.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::loom::sync::Arc; 9 - use crate::loom::sync::Mutex as StdMutex; 10 - use crate::time::{Clock, RawClock, RawClockVTable}; 11 8 use core::ptr::NonNull; 12 9 use core::time::Duration; 13 10 use std::time::Instant as StdInstant; 11 + 12 + use crate::loom::sync::{Arc, Mutex as StdMutex}; 13 + use crate::time::{Clock, RawClock, RawClockVTable}; 14 14 15 15 pub struct MockClock { 16 16 time_anchor: StdInstant,
+7 -10
libs/kasync/src/time/timeout.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use core::pin::Pin; 9 + use core::task::{Context, Poll}; 10 + use core::time::Duration; 11 + 8 12 use pin_project::pin_project; 9 13 10 - use crate::time::{ 11 - TimeError, Timer, 12 - instant::Instant, 13 - sleep::{Sleep, sleep, sleep_until}, 14 - }; 15 - use core::{ 16 - pin::Pin, 17 - task::{Context, Poll}, 18 - time::Duration, 19 - }; 14 + use crate::time::instant::Instant; 15 + use crate::time::sleep::{Sleep, sleep, sleep_until}; 16 + use crate::time::{TimeError, Timer}; 20 17 21 18 /// Requires a `Future` to complete before the specified duration has elapsed. 22 19 ///
+8 -4
libs/kasync/src/time/timer.rs
··· 8 8 mod entry; 9 9 mod wheel; 10 10 11 - use crate::time::{Clock, NANOS_PER_SEC, TimeError, max_duration}; 12 - use crate::{loom::sync::atomic::Ordering, time::Instant}; 11 + use core::pin::Pin; 12 + use core::ptr::NonNull; 13 + use core::task::Poll; 14 + use core::time::Duration; 15 + 13 16 use cordyceps::List; 14 - use core::{pin::Pin, ptr::NonNull, task::Poll, time::Duration}; 17 + pub(in crate::time) use entry::Entry; 15 18 use spin::Mutex; 16 19 use util::loom_const_fn; 17 20 use wheel::Wheel; 18 21 19 - pub(in crate::time) use entry::Entry; 22 + use crate::loom::sync::atomic::Ordering; 23 + use crate::time::{Clock, Instant, NANOS_PER_SEC, TimeError, max_duration}; 20 24 21 25 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 22 26 pub struct Ticks(pub u64);
+5 -3
libs/kasync/src/time/timer/entry.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::sync::wait_cell::WaitCell; 9 - use crate::time::Ticks; 10 - use cordyceps::{Linked, list}; 11 8 use core::marker::PhantomPinned; 12 9 use core::mem::offset_of; 13 10 use core::ptr::NonNull; 14 11 use core::sync::atomic::{AtomicBool, Ordering}; 12 + 13 + use cordyceps::{Linked, list}; 15 14 use pin_project::pin_project; 16 15 use util::loom_const_fn; 16 + 17 + use crate::sync::wait_cell::WaitCell; 18 + use crate::time::Ticks; 17 19 18 20 /// An entry in a timing [`Wheel`][crate::time::timer::Wheel]. 19 21 #[pin_project]
+6 -4
libs/kasync/src/time/timer/wheel.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::time::Ticks; 9 - use crate::time::timer::entry::Entry; 10 - use crate::time::timer::{Core, Deadline}; 11 - use cordyceps::List; 12 8 use core::pin::Pin; 13 9 use core::ptr::NonNull; 14 10 use core::sync::atomic::Ordering; 11 + 12 + use cordyceps::List; 13 + 14 + use crate::time::Ticks; 15 + use crate::time::timer::entry::Entry; 16 + use crate::time::timer::{Core, Deadline}; 15 17 16 18 #[derive(Debug)] 17 19 pub(crate) struct Wheel {
+2 -1
libs/kbacktrace/src/lib.rs
··· 10 10 11 11 mod symbolize; 12 12 13 - use arrayvec::ArrayVec; 14 13 use core::fmt; 15 14 use core::fmt::Formatter; 15 + 16 + use arrayvec::ArrayVec; 16 17 use fallible_iterator::FallibleIterator; 17 18 use unwind2::FrameIter; 18 19
+1
libs/kbacktrace/src/symbolize.rs
··· 7 7 8 8 use core::ffi::c_void; 9 9 use core::{fmt, str}; 10 + 10 11 use fallible_iterator::FallibleIterator; 11 12 use gimli::{EndianSlice, NativeEndian}; 12 13 use rustc_demangle::{Demangle, try_demangle};
+5 -5
libs/ksharded-slab/src/cfg.rs
··· 1 + use core::fmt; 2 + use core::marker::PhantomData; 3 + 1 4 use crate::Pack; 2 - use crate::page::{ 3 - Addr, 4 - slot::{Generation, RefCount}, 5 - }; 6 - use core::{fmt, marker::PhantomData}; 5 + use crate::page::Addr; 6 + use crate::page::slot::{Generation, RefCount}; 7 7 8 8 /// Configuration parameters which can be overridden to tune the behavior of a slab. 9 9 pub trait Config: Sized {
+2 -1
libs/ksharded-slab/src/iter.rs
··· 1 - use core::{iter::FusedIterator, slice}; 1 + use core::iter::FusedIterator; 2 + use core::slice; 2 3 3 4 use crate::{cfg, page, shard}; 4 5
+9 -10
libs/ksharded-slab/src/lib.rs
··· 220 220 mod shard; 221 221 mod tid; 222 222 223 - pub use self::{ 224 - cfg::{Config, DefaultConfig}, 225 - clear::Clear, 226 - iter::UniqueIter, 227 - }; 223 + use alloc::sync::Arc; 224 + use core::marker::PhantomData; 225 + use core::{fmt, ptr}; 226 + 227 + use cfg::CfgPrivate; 228 228 #[doc(inline)] 229 229 pub use pool::Pool; 230 - 230 + use shard::Shard; 231 231 pub(crate) use tid::Tid; 232 232 233 - use alloc::sync::Arc; 234 - use cfg::CfgPrivate; 235 - use core::{fmt, marker::PhantomData, ptr}; 236 - use shard::Shard; 233 + pub use self::cfg::{Config, DefaultConfig}; 234 + pub use self::clear::Clear; 235 + pub use self::iter::UniqueIter; 237 236 238 237 /// A sharded slab. 239 238 ///
+7 -4
libs/ksharded-slab/src/page/mod.rs
··· 1 + use alloc::boxed::Box; 2 + use alloc::vec::Vec; 3 + 1 4 use crate::Pack; 2 5 use crate::cfg::{self, CfgPrivate}; 3 6 use crate::clear::Clear; 4 - use alloc::boxed::Box; 5 - use alloc::vec::Vec; 6 7 7 8 pub(crate) mod slot; 8 9 mod stack; 9 10 11 + use core::cell::UnsafeCell; 12 + use core::fmt; 13 + use core::marker::PhantomData; 14 + 10 15 pub(crate) use self::slot::Slot; 11 - use core::cell::UnsafeCell; 12 - use core::{fmt, marker::PhantomData}; 13 16 14 17 /// A page address encodes the location of a slot within a shard (the page 15 18 /// number and offset within that page) as a single linear value.
+7 -3
libs/ksharded-slab/src/page/slot.rs
··· 1 - use super::FreeList; 2 - use crate::{Pack, Tid, cfg, clear::Clear}; 3 1 use core::cell::UnsafeCell; 2 + use core::marker::PhantomData; 4 3 use core::sync::atomic::{AtomicUsize, Ordering}; 5 - use core::{fmt, marker::PhantomData, mem, ptr}; 4 + use core::{fmt, mem, ptr}; 5 + 6 6 use spin::Backoff; 7 + 8 + use super::FreeList; 9 + use crate::clear::Clear; 10 + use crate::{Pack, Tid, cfg}; 7 11 8 12 pub(crate) struct Slot<T, C> { 9 13 lifecycle: AtomicUsize,
+4 -2
libs/ksharded-slab/src/page/stack.rs
··· 1 - use crate::cfg; 1 + use core::fmt; 2 + use core::marker::PhantomData; 2 3 use core::sync::atomic::{AtomicUsize, Ordering}; 3 - use core::{fmt, marker::PhantomData}; 4 + 5 + use crate::cfg; 4 6 5 7 pub(super) struct TransferStack<C = cfg::DefaultConfig> { 6 8 head: AtomicUsize,
+7 -9
libs/ksharded-slab/src/pool.rs
··· 5 5 //! 6 6 //! [pool]: ../struct.Pool.html 7 7 //! [`Slab`]: ../struct.Slab.html 8 - use crate::{ 9 - Pack, Shard, 10 - cfg::{self, CfgPrivate, DefaultConfig}, 11 - clear::Clear, 12 - page, shard, 13 - tid::Tid, 14 - }; 15 - 16 8 use alloc::sync::Arc; 17 - use core::{fmt, marker::PhantomData}; 9 + use core::fmt; 10 + use core::marker::PhantomData; 11 + 12 + use crate::cfg::{self, CfgPrivate, DefaultConfig}; 13 + use crate::clear::Clear; 14 + use crate::tid::Tid; 15 + use crate::{Pack, Shard, page, shard}; 18 16 19 17 /// A lock-free concurrent object pool. 20 18 ///
+5 -7
libs/ksharded-slab/src/shard.rs
··· 1 - use crate::{ 2 - Pack, 3 - cfg::{self, CfgPrivate}, 4 - clear::Clear, 5 - page, 6 - tid::Tid, 7 - }; 8 1 use alloc::boxed::Box; 9 2 use alloc::vec::Vec; 10 3 use core::sync::atomic; 11 4 use core::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; 12 5 use core::{fmt, ptr, slice}; 6 + 7 + use crate::cfg::{self, CfgPrivate}; 8 + use crate::clear::Clear; 9 + use crate::tid::Tid; 10 + use crate::{Pack, page}; 13 11 14 12 // ┌─────────────┐ ┌────────┐ 15 13 // │ page 1 │ │ │
+7 -10
libs/ksharded-slab/src/tid.rs
··· 1 - use crate::{ 2 - Pack, 3 - cfg::{self, CfgPrivate}, 4 - page, 5 - }; 6 1 use alloc::collections::VecDeque; 2 + use core::cell::{Cell, UnsafeCell}; 3 + use core::fmt; 4 + use core::marker::PhantomData; 7 5 use core::sync::atomic::{AtomicUsize, Ordering}; 8 - use core::{ 9 - cell::{Cell, UnsafeCell}, 10 - fmt, 11 - marker::PhantomData, 12 - }; 6 + 13 7 use cpu_local::cpu_local; 14 8 use spin::{LazyLock, Mutex}; 9 + 10 + use crate::cfg::{self, CfgPrivate}; 11 + use crate::{Pack, page}; 15 12 16 13 /// Uniquely identifies a thread. 17 14 pub(crate) struct Tid<C> {
+1
libs/ktest/src/lib.rs
··· 11 11 12 12 use alloc::boxed::Box; 13 13 use core::pin::Pin; 14 + 14 15 pub use ktest_macros::*; 15 16 16 17 /// A single test case
+1
libs/panic-unwind2/src/hook.rs
··· 9 9 use core::any::Any; 10 10 use core::panic::Location; 11 11 use core::{fmt, mem}; 12 + 12 13 use spin::RwLock; 13 14 14 15 #[derive(Debug)]
+5 -3
libs/panic-unwind2/src/lib.rs
··· 19 19 mod hook; 20 20 mod panic_count; 21 21 22 - use crate::hook::{HOOK, Hook, PanicHookInfo, default_hook}; 23 - use crate::panic_count::MustAbort; 24 - use abort::abort; 25 22 use alloc::boxed::Box; 26 23 use alloc::string::String; 27 24 use core::any::Any; 28 25 use core::panic::{PanicPayload, UnwindSafe}; 29 26 use core::{fmt, mem}; 27 + 28 + use abort::abort; 30 29 pub use hook::{set_hook, take_hook}; 30 + 31 + use crate::hook::{HOOK, Hook, PanicHookInfo, default_hook}; 32 + use crate::panic_count::MustAbort; 31 33 32 34 /// Determines whether the current thread is unwinding because of panic. 33 35 #[inline]
+3 -4
libs/panic-unwind2/src/panic_count.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use core::{ 9 - cell::Cell, 10 - sync::atomic::{AtomicUsize, Ordering}, 11 - }; 8 + use core::cell::Cell; 9 + use core::sync::atomic::{AtomicUsize, Ordering}; 10 + 12 11 use cpu_local::cpu_local; 13 12 14 13 /// A reason for forcing an immediate abort on panic.
+3 -1
libs/riscv/src/hio.rs
··· 7 7 8 8 //! Host I/O 9 9 10 - use super::semihosting::syscall; 11 10 use core::fmt::{Error, Write}; 12 11 use core::{fmt, slice}; 12 + 13 13 use spin::Mutex; 14 + 15 + use super::semihosting::syscall; 14 16 15 17 const OPEN: usize = 0x01; 16 18 const WRITE: usize = 0x05;
+1
libs/riscv/src/lib.rs
··· 20 20 pub mod trap; 21 21 22 22 use core::arch::asm; 23 + 23 24 pub use error::Error; 24 25 pub use register::*; 25 26 pub type Result<T> = core::result::Result<T, Error>;
+2 -1
libs/riscv/src/register/satp.rs
··· 7 7 8 8 //! Supervisor Address Translation and Protection Register 9 9 10 + use core::fmt; 11 + 10 12 use super::{read_csr_as, write_csr}; 11 13 use crate::Error; 12 - use core::fmt; 13 14 14 15 /// satp register 15 16 #[derive(Clone, Copy)]
+3 -2
libs/riscv/src/register/scause.rs
··· 7 7 8 8 //! Supervisor Cause Register 9 9 10 + use core::fmt; 11 + use core::fmt::Formatter; 12 + 10 13 use super::{read_csr_as, write_csr}; 11 14 use crate::trap::Trap; 12 - use core::fmt; 13 - use core::fmt::Formatter; 14 15 15 16 /// scause register 16 17 #[derive(Clone, Copy)]
+2 -1
libs/riscv/src/register/sie.rs
··· 7 7 8 8 //! Supervisor Interrupt Enable Register 9 9 10 - use super::{clear_csr, read_csr_as, set_csr}; 11 10 use core::fmt; 12 11 use core::fmt::Formatter; 12 + 13 + use super::{clear_csr, read_csr_as, set_csr}; 13 14 14 15 /// sie register 15 16 #[derive(Clone, Copy)]
+3 -2
libs/riscv/src/register/sstatus.rs
··· 7 7 8 8 //! Supervisor Status Register 9 9 10 + use core::fmt; 11 + use core::fmt::Formatter; 12 + 10 13 use super::{clear_csr, read_csr_as, set_clear_csr_field, set_csr}; 11 14 use crate::set_csr_field; 12 - use core::fmt; 13 - use core::fmt::Formatter; 14 15 15 16 /// Supervisor Status Register 16 17 #[derive(Clone, Copy)]
+2 -1
libs/riscv/src/register/stvec.rs
··· 7 7 8 8 //! Supervisor Trap Vector Base Address Register 9 9 10 - use super::{read_csr_as, set_csr}; 11 10 use core::fmt; 12 11 use core::fmt::Formatter; 12 + 13 + use super::{read_csr_as, set_csr}; 13 14 14 15 #[derive(Clone, Copy)] 15 16 pub struct Stvec {
+6 -4
libs/spin/src/barrier.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::Mutex; 9 8 use core::hint; 9 + 10 10 use util::loom_const_fn; 11 + 12 + use crate::Mutex; 11 13 12 14 pub struct Barrier { 13 15 lock: Mutex<BarrierState>, ··· 69 71 70 72 #[cfg(test)] 71 73 mod tests { 72 - use super::*; 73 - use crate::loom::Arc; 74 - use crate::loom::thread; 75 74 use std::sync::mpsc::{TryRecvError, channel}; 75 + 76 + use super::*; 77 + use crate::loom::{Arc, thread}; 76 78 77 79 #[test] 78 80 fn test_barrier() {
+12 -12
libs/spin/src/lazy_lock.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use super::{Once, once::ExclusiveState}; 9 - use crate::loom::UnsafeCell; 10 - use core::{ 11 - fmt, 12 - mem::ManuallyDrop, 13 - ops::Deref, 14 - panic::{RefUnwindSafe, UnwindSafe}, 15 - ptr, 16 - }; 8 + use core::mem::ManuallyDrop; 9 + use core::ops::Deref; 10 + use core::panic::{RefUnwindSafe, UnwindSafe}; 11 + use core::{fmt, ptr}; 12 + 17 13 use util::loom_const_fn; 14 + 15 + use super::Once; 16 + use super::once::ExclusiveState; 17 + use crate::loom::UnsafeCell; 18 18 19 19 union Data<T, F> { 20 20 value: ManuallyDrop<T>, ··· 167 167 168 168 #[cfg(test)] 169 169 mod tests { 170 + use std::cell::LazyCell; 171 + 170 172 use super::*; 171 - use crate::loom::thread; 172 - use crate::loom::{AtomicUsize, Ordering}; 173 + use crate::loom::{AtomicUsize, Ordering, thread}; 173 174 use crate::{Mutex, OnceLock}; 174 - use std::cell::LazyCell; 175 175 176 176 fn spawn_and_wait<R: Send + 'static>(f: impl FnOnce() -> R + Send + 'static) -> R { 177 177 thread::spawn(f).join().unwrap()
+7 -6
libs/spin/src/mutex.rs
··· 14 14 // ArcMutexGuardarc_lock 15 15 // An RAII mutex guard returned by the Arc locking operations on Mutex. 16 16 17 - use crate::backoff::Backoff; 18 - use crate::loom::Ordering; 19 - use crate::loom::{AtomicBool, UnsafeCell}; 20 17 use core::marker::PhantomData; 21 18 use core::ops::{Deref, DerefMut}; 22 19 use core::{fmt, mem}; 20 + 23 21 use util::loom_const_fn; 22 + 23 + use crate::backoff::Backoff; 24 + use crate::loom::{AtomicBool, Ordering, UnsafeCell}; 24 25 25 26 /// A mutual exclusion primitive useful for protecting shared data 26 27 /// ··· 335 336 336 337 #[cfg(test)] 337 338 mod tests { 338 - use super::*; 339 - use crate::loom::Arc; 340 - use crate::loom::AtomicUsize; 341 339 use core::fmt::Debug; 342 340 use std::{hint, mem}; 341 + 342 + use super::*; 343 + use crate::loom::{Arc, AtomicUsize}; 343 344 344 345 #[derive(Eq, PartialEq, Debug)] 345 346 struct NonCopy(i32);
+5 -2
libs/spin/src/once.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::loom::{AtomicU8, Ordering}; 9 8 use core::mem; 9 + 10 10 use util::loom_const_fn; 11 + 12 + use crate::loom::{AtomicU8, Ordering}; 11 13 12 14 /// No initialization has run yet, and no thread is currently using the Once. 13 15 const STATUS_INCOMPLETE: u8 = 0; ··· 148 150 149 151 #[cfg(test)] 150 152 mod tests { 153 + use std::sync::mpsc::channel; 154 + 151 155 use super::*; 152 156 use crate::loom::thread; 153 - use std::sync::mpsc::channel; 154 157 155 158 #[test] 156 159 fn smoke_once() {
+9 -9
libs/spin/src/once_lock.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use core::fmt; 9 + use core::mem::MaybeUninit; 10 + use core::panic::{RefUnwindSafe, UnwindSafe}; 11 + 12 + use util::loom_const_fn; 13 + 8 14 use super::Once; 9 15 use crate::loom::UnsafeCell; 10 - use core::{ 11 - fmt, 12 - mem::MaybeUninit, 13 - panic::{RefUnwindSafe, UnwindSafe}, 14 - }; 15 - use util::loom_const_fn; 16 16 17 17 /// A synchronization primitive which can be written to only once. 18 18 /// ··· 316 316 317 317 #[cfg(test)] 318 318 mod tests { 319 - use super::*; 320 - use crate::loom::thread; 321 - use crate::loom::{AtomicUsize, Ordering}; 322 319 use std::sync::mpsc::channel; 320 + 321 + use super::*; 322 + use crate::loom::{AtomicUsize, Ordering, thread}; 323 323 324 324 fn spawn_and_wait<R: Send + 'static>(f: impl FnOnce() -> R + Send + 'static) -> R { 325 325 thread::spawn(f).join().unwrap()
+4 -3
libs/spin/src/remutex.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::loom::AtomicUsize; 9 - use crate::loom::{Ordering, UnsafeCell}; 10 - use crate::{Backoff, GuardNoSend}; 11 8 use core::cell::Cell; 12 9 use core::fmt; 13 10 use core::marker::PhantomData; ··· 15 12 use core::ops::Deref; 16 13 use core::ptr::addr_of; 17 14 use core::sync::atomic::AtomicBool; 15 + 18 16 use util::loom_const_fn; 17 + 18 + use crate::loom::{AtomicUsize, Ordering, UnsafeCell}; 19 + use crate::{Backoff, GuardNoSend}; 19 20 20 21 /// A mutex which can be recursively locked by a single thread. 21 22 ///
+7 -5
libs/spin/src/rw_lock.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::Backoff; 9 - use crate::loom::{AtomicUsize, Ordering, UnsafeCell}; 10 8 use core::ops::{Deref, DerefMut}; 11 9 use core::ptr::NonNull; 12 10 use core::{fmt, mem}; 11 + 13 12 use util::loom_const_fn; 13 + 14 + use crate::Backoff; 15 + use crate::loom::{AtomicUsize, Ordering, UnsafeCell}; 14 16 15 17 const READER: usize = 1 << 2; 16 18 const UPGRADED: usize = 1 << 1; ··· 621 623 622 624 #[cfg(test)] 623 625 mod tests { 624 - use super::*; 625 - use crate::loom::Arc; 626 - use crate::loom::thread; 627 626 use core::fmt::Debug; 628 627 use core::mem; 629 628 use std::hint; 630 629 use std::sync::mpsc::channel; 630 + 631 + use super::*; 632 + use crate::loom::{Arc, thread}; 631 633 632 634 #[derive(Eq, PartialEq, Debug)] 633 635 struct NonCopy(i32);
+2 -1
libs/uart-16550/src/lib.rs
··· 7 7 8 8 #![cfg_attr(not(test), no_std)] 9 9 10 - use bitflags::bitflags; 11 10 use core::fmt; 12 11 use core::sync::atomic::{AtomicPtr, Ordering}; 12 + 13 + use bitflags::bitflags; 13 14 use spin::Backoff; 14 15 15 16 macro_rules! wait_for {
+3 -3
libs/unwind2/src/arch/riscv64.rs
··· 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 8 //! RISC-V specific unwinding code, mostly saving and restoring registers. 9 - use cfg_if::cfg_if; 10 9 use core::arch::{asm, naked_asm}; 11 - use core::fmt; 12 - use core::ops; 10 + use core::{fmt, ops}; 11 + 12 + use cfg_if::cfg_if; 13 13 use gimli::{Register, RiscV}; 14 14 15 15 // Match DWARF_FRAME_REGISTERS in libgcc
+2 -1
libs/unwind2/src/eh_action.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use gimli::{EndianSlice, NativeEndian, Pointer, Reader, constants}; 9 + 8 10 use crate::frame::Frame; 9 11 use crate::utils::deref_pointer; 10 - use gimli::{EndianSlice, NativeEndian, Pointer, Reader, constants}; 11 12 12 13 #[derive(Debug)] 13 14 pub enum EHAction {
+2 -1
libs/unwind2/src/eh_info.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use super::utils::{deref_pointer, get_unlimited_slice}; 9 8 use gimli::{BaseAddresses, EhFrame, EhFrameHdr, EndianSlice, NativeEndian, ParsedEhFrameHdr}; 10 9 use spin::LazyLock; 10 + 11 + use super::utils::{deref_pointer, get_unlimited_slice}; 11 12 12 13 // Below is a fun hack: We need a reference to the `.eh_frame` and `.eh_frame_hdr` sections and 13 14 // must therefore force the linker to retain those even in release builds. By abusing mutable statics
+4 -2
libs/unwind2/src/exception.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::Error; 9 - use abort::abort; 10 8 use alloc::boxed::Box; 11 9 use core::any::Any; 12 10 use core::ffi::c_int; 13 11 use core::ptr; 12 + 13 + use abort::abort; 14 + 15 + use crate::Error; 14 16 15 17 /// The C ABI UnwindReasonCode passed to the exception cleanup function when a foreign 16 18 /// (i.e. not originating from this crate) exception is caught. Since that exception might have
+4 -3
libs/unwind2/src/frame.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 - use crate::eh_info::obtain_eh_info; 10 - use crate::utils::{StoreOnStack, deref_pointer, get_unlimited_slice, with_context}; 11 8 use fallible_iterator::FallibleIterator; 12 9 use gimli::{ 13 10 CfaRule, EhFrame, EndianSlice, EvaluationResult, FrameDescriptionEntry, NativeEndian, Register, 14 11 RegisterRule, UnwindExpression, UnwindSection, UnwindTableRow, Value, 15 12 }; 13 + 14 + use crate::arch; 15 + use crate::eh_info::obtain_eh_info; 16 + use crate::utils::{StoreOnStack, deref_pointer, get_unlimited_slice, with_context}; 16 17 17 18 /// A frame in a stack. 18 19 ///
+2 -1
libs/unwind2/src/lang_items.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use abort::abort; 9 + 8 10 use crate::exception::Exception; 9 11 use crate::utils::with_context; 10 12 use crate::{Error, FrameIter, arch, raise_exception_phase2}; 11 - use abort::abort; 12 13 13 14 /// In traditional unwinders the personality routine is responsible for determining the unwinders 14 15 /// behaviour for each frame (stop unwinding because a handler has been found, continue etc.)
+5 -4
libs/unwind2/src/lib.rs
··· 21 21 mod lang_items; 22 22 mod utils; 23 23 24 - use abort::abort; 25 24 use alloc::boxed::Box; 26 25 use core::any::Any; 27 26 use core::intrinsics; 28 27 use core::mem::ManuallyDrop; 29 28 use core::panic::UnwindSafe; 30 29 use core::ptr::addr_of_mut; 30 + 31 + use abort::abort; 32 + pub use arch::Registers; 31 33 use eh_action::{EHAction, find_eh_action}; 32 34 pub use eh_info::EhInfo; 33 35 pub use error::Error; ··· 36 38 pub use frame::{Frame, FrameIter}; 37 39 use lang_items::ensure_personality_stub; 38 40 pub use utils::with_context; 39 - 40 - pub use arch::Registers; 41 41 42 42 pub(crate) type Result<T> = core::result::Result<T, Error>; 43 43 ··· 228 228 229 229 #[cfg(test)] 230 230 mod tests { 231 + use alloc::boxed::Box; 232 + 231 233 use super::*; 232 - use alloc::boxed::Box; 233 234 234 235 #[test] 235 236 fn begin_and_catch_roundtrip() {
+3 -1
libs/unwind2/src/utils.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 8 use core::ptr; 9 + 10 10 use gimli::{Pointer, Register, RegisterRule, UnwindTableRow}; 11 + 12 + use crate::arch; 11 13 12 14 pub struct StoreOnStack; 13 15
+2 -1
libs/util/src/checked_maybe_uninit.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use core::{fmt, mem::MaybeUninit}; 8 + use core::fmt; 9 + use core::mem::MaybeUninit; 9 10 10 11 /// A checked version of [`MaybeUninit`]. This type is taken from mycelium. 11 12 ///
+5 -4
libs/wast/src/error.rs
··· 1 - use crate::lexer::LexError; 2 - use crate::token::Span; 3 1 use alloc::boxed::Box; 4 - use alloc::string::String; 5 - use alloc::string::ToString; 2 + use alloc::string::{String, ToString}; 6 3 use core::fmt; 4 + 7 5 use unicode_width::UnicodeWidthStr; 6 + 7 + use crate::lexer::LexError; 8 + use crate::token::Span; 8 9 9 10 /// A convenience error type to tie together all the detailed errors produced by 10 11 /// this crate.
+3 -1
libs/wast/src/gensym.rs
··· 1 - use crate::token::{Id, Span}; 2 1 use core::cell::Cell; 2 + 3 3 use cpu_local::cpu_local; 4 + 5 + use crate::token::{Id, Span}; 4 6 5 7 cpu_local!(static NEXT: Cell<u32> = Cell::new(0)); 6 8
+5 -8
libs/wast/src/lexer.rs
··· 24 24 //! 25 25 //! [`Lexer`]: crate::lexer::Lexer 26 26 27 - use crate::Error; 28 - use crate::token::Span; 29 27 use alloc::borrow::Cow; 30 - use alloc::string::String; 31 - use alloc::string::ToString; 28 + use alloc::string::{String, ToString}; 32 29 use alloc::vec::Vec; 33 - use core::char; 34 - use core::fmt; 35 - use core::slice; 36 - use core::str; 37 30 use core::str::Utf8Error; 31 + use core::{char, fmt, slice, str}; 32 + 33 + use crate::Error; 34 + use crate::token::Span; 38 35 39 36 /// A structure used to lex the s-expression syntax of WAT files. 40 37 ///
+4 -2
libs/wast/src/names.rs
··· 1 - use crate::Error; 2 - use crate::token::{Id, Index}; 3 1 use alloc::format; 2 + 4 3 use hashbrown::HashMap; 4 + 5 + use crate::Error; 6 + use crate::token::{Id, Index}; 5 7 6 8 #[derive(Default)] 7 9 pub struct Namespace<'a> {
+7 -6
libs/wast/src/parser.rs
··· 62 62 //! This module is heavily inspired by [`syn`](https://docs.rs/syn) so you can 63 63 //! likely also draw inspiration from the excellent examples in the `syn` crate. 64 64 65 - use crate::Error; 66 - use crate::lexer::{Float, Integer, Lexer, Token, TokenKind}; 67 - use crate::token::Span; 68 65 use alloc::borrow::Cow; 69 66 use alloc::boxed::Box; 70 67 use alloc::format; 71 - use alloc::string::String; 72 - use alloc::string::ToString; 68 + use alloc::string::{String, ToString}; 73 69 use alloc::vec::Vec; 74 - use bumpalo::Bump; 75 70 use core::cell::{Cell, RefCell}; 76 71 use core::fmt; 72 + 73 + use bumpalo::Bump; 77 74 use hashbrown::HashMap; 75 + 76 + use crate::Error; 77 + use crate::lexer::{Float, Integer, Lexer, Token, TokenKind}; 78 + use crate::token::Span; 78 79 79 80 /// The maximum recursive depth of parens to parse. 80 81 ///
+4 -5
libs/wast/src/token.rs
··· 2 2 //! associated specifically with the wasm text format per se (useful in other 3 3 //! contexts too perhaps). 4 4 5 + use alloc::string::{String, ToString}; 6 + use core::hash::{Hash, Hasher}; 7 + use core::{fmt, str}; 8 + 5 9 use crate::annotation; 6 10 use crate::lexer::Float; 7 11 use crate::parser::{Cursor, Parse, Parser, Peek, Result}; 8 - use alloc::string::String; 9 - use alloc::string::ToString; 10 - use core::fmt; 11 - use core::hash::{Hash, Hasher}; 12 - use core::str; 13 12 14 13 /// A position in the original source stream, used to render errors. 15 14 #[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)]
+2 -1
libs/wast/tests/parse-fail.rs
··· 4 4 //! Use `BLESS=1` in the environment to auto-update `*.err` files. Be sure to 5 5 //! look at the diff! 6 6 7 - use libtest_mimic::{Arguments, Trial}; 8 7 use std::env; 9 8 use std::path::{Path, PathBuf}; 9 + 10 + use libtest_mimic::{Arguments, Trial}; 10 11 11 12 fn main() { 12 13 let mut tests = Vec::new();
+4 -3
libs/wavltree/benches/insertions_deletions.rs
··· 1 - use criterion::{Criterion, criterion_group, criterion_main}; 2 - use rand::prelude::SliceRandom; 3 - use rand::thread_rng; 4 1 use std::fmt; 5 2 use std::mem::offset_of; 6 3 use std::pin::Pin; 7 4 use std::ptr::NonNull; 5 + 6 + use criterion::{Criterion, criterion_group, criterion_main}; 7 + use rand::prelude::SliceRandom; 8 + use rand::thread_rng; 8 9 use wavltree::{Linked, Links, WAVLTree}; 9 10 10 11 #[derive(Default)]
+2 -1
libs/wavltree/src/cursor.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use core::pin::Pin; 9 + 8 10 use crate::{Link, Linked, WAVLTree, utils}; 9 - use core::pin::Pin; 10 11 11 12 /// A cursor which provides read-only access to a [`WAVLTree`]. 12 13 pub struct Cursor<'a, T>
+3 -3
libs/wavltree/src/dot.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::Linked; 9 - use crate::WAVLTree; 10 - use crate::utils::Side; 11 8 use core::fmt; 12 9 use core::ptr::NonNull; 10 + 11 + use crate::utils::Side; 12 + use crate::{Linked, WAVLTree}; 13 13 14 14 pub struct Dot<'a, T> 15 15 where
+3 -2
libs/wavltree/src/entry.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use core::pin::Pin; 9 + use core::ptr::NonNull; 10 + 8 11 use crate::utils::Side; 9 12 use crate::{Link, Linked, WAVLTree, utils}; 10 - use core::pin::Pin; 11 - use core::ptr::NonNull; 12 13 13 14 pub enum Entry<'a, T> 14 15 where
+2 -2
libs/wavltree/src/iter.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::{Link, Linked}; 9 - use crate::{WAVLTree, utils}; 10 8 use core::iter::FusedIterator; 11 9 use core::pin::Pin; 10 + 11 + use crate::{Link, Linked, WAVLTree, utils}; 12 12 13 13 /// An iterator over references to the entries of a [`WAVLTree`]. 14 14 pub struct Iter<'a, T: Linked + ?Sized> {
+8 -6
libs/wavltree/src/lib.rs
··· 148 148 use core::ptr::NonNull; 149 149 use core::{fmt, mem, ptr}; 150 150 151 - pub use crate::cursor::{Cursor, CursorMut}; 152 - pub use crate::entry::{Entry, OccupiedEntry, VacantEntry}; 153 - use crate::utils::get_sibling; 154 151 #[cfg(feature = "dot")] 155 152 pub use dot::Dot; 156 - pub use iter::IntoIter; 157 - pub use iter::{Iter, IterMut}; 153 + pub use iter::{IntoIter, Iter, IterMut}; 158 154 pub use utils::Side; 155 + 156 + pub use crate::cursor::{Cursor, CursorMut}; 157 + pub use crate::entry::{Entry, OccupiedEntry, VacantEntry}; 158 + use crate::utils::get_sibling; 159 159 160 160 /// Trait implemented by types which can be members of an [intrusive WAVL tree][WAVLTree]. 161 161 /// ··· 1683 1683 mod tests { 1684 1684 extern crate alloc; 1685 1685 1686 - use super::*; 1687 1686 use alloc::boxed::Box; 1688 1687 use alloc::vec::Vec; 1689 1688 use core::mem::offset_of; 1690 1689 use core::pin::Pin; 1690 + 1691 1691 use rand::prelude::SliceRandom; 1692 1692 use rand::rng; 1693 + 1694 + use super::*; 1693 1695 1694 1696 #[derive(Default)] 1695 1697 struct TestEntry {
+2 -1
libs/wavltree/src/utils.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::{Link, Linked}; 9 8 use core::ptr::NonNull; 10 9 use core::{fmt, ptr}; 10 + 11 + use crate::{Link, Linked}; 11 12 12 13 #[derive(Debug, Copy, Clone, PartialEq)] 13 14 pub enum Side {
+2 -1
loader/build.rs
··· 22 22 } 23 23 24 24 fn copy_linker_script() { 25 - use std::{fs::File, io::Write}; 25 + use std::fs::File; 26 + use std::io::Write; 26 27 27 28 let out_dir = env::var("OUT_DIR").unwrap(); 28 29 let dest_path = Path::new(&out_dir);
+8 -6
loader/src/arch/riscv64.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::GlobalInitResult; 9 - use crate::error::Error; 10 - use crate::frame_alloc::FrameAllocator; 11 - use crate::machine_info::MachineInfo; 12 - use crate::mapping::Flags; 13 - use bitflags::bitflags; 14 8 use core::arch::{asm, naked_asm}; 15 9 use core::fmt; 16 10 use core::num::NonZero; 17 11 use core::ptr::NonNull; 12 + 13 + use bitflags::bitflags; 18 14 use riscv::satp; 15 + 16 + use crate::GlobalInitResult; 17 + use crate::error::Error; 18 + use crate::frame_alloc::FrameAllocator; 19 + use crate::machine_info::MachineInfo; 20 + use crate::mapping::Flags; 19 21 20 22 pub const DEFAULT_ASID: u16 = 0; 21 23 pub const KERNEL_ASPACE_BASE: usize = 0xffffffc000000000;
+4 -2
loader/src/boot_info.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 - use crate::frame_alloc::FrameAllocator; 10 8 use core::alloc::Layout; 11 9 use core::mem::MaybeUninit; 12 10 use core::range::Range; 13 11 use core::slice; 12 + 14 13 use loader_api::{BootInfo, MemoryRegion, MemoryRegionKind, MemoryRegions, TlsTemplate}; 14 + 15 + use crate::arch; 16 + use crate::frame_alloc::FrameAllocator; 15 17 16 18 #[expect(clippy::too_many_arguments, reason = "")] 17 19 pub fn prepare_boot_info(
+4 -2
loader/src/frame_alloc.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 - use crate::error::Error; 10 8 use core::alloc::Layout; 11 9 use core::num::NonZeroUsize; 12 10 use core::range::Range; 13 11 use core::{cmp, iter, ptr, slice}; 12 + 14 13 use fallible_iterator::FallibleIterator; 14 + 15 + use crate::arch; 16 + use crate::error::Error; 15 17 16 18 pub struct FrameAllocator<'a> { 17 19 regions: &'a [Range<usize>],
+3 -1
loader/src/kernel.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::error::Error; 9 8 use core::fmt::Formatter; 10 9 use core::range::Range; 11 10 use core::{fmt, slice}; 11 + 12 12 use loader_api::LoaderConfig; 13 13 use xmas_elf::program::{ProgramHeader, Type}; 14 + 15 + use crate::error::Error; 14 16 15 17 /// The inlined kernel 16 18 static INLINED_KERNEL_BYTES: KernelBytes = KernelBytes(*include_bytes!(env!("KERNEL")));
+6 -4
loader/src/machine_info.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch::PAGE_SIZE; 9 - use crate::error::Error; 10 - use crate::mapping::{align_down, checked_align_up}; 11 - use arrayvec::ArrayVec; 12 8 use core::cmp::Ordering; 13 9 use core::ffi::{CStr, c_void}; 14 10 use core::fmt; 15 11 use core::fmt::Formatter; 16 12 use core::range::Range; 17 13 use core::str::FromStr; 14 + 15 + use arrayvec::ArrayVec; 18 16 use fallible_iterator::FallibleIterator; 19 17 use fdt::{CellSizes, Fdt, PropertiesIter}; 18 + 19 + use crate::arch::PAGE_SIZE; 20 + use crate::error::Error; 21 + use crate::mapping::{align_down, checked_align_up}; 20 22 21 23 /// Information about the machine we're running on. 22 24 /// This is collected from the FDT (flatting device tree) passed to us by the previous stage loader.
+8 -6
loader/src/main.rs
··· 11 11 #![feature(maybe_uninit_slice)] 12 12 #![feature(alloc_layout_extra)] 13 13 14 + use core::ffi::c_void; 15 + use core::range::Range; 16 + 17 + use arrayvec::ArrayVec; 18 + use rand::SeedableRng; 19 + use rand_chacha::ChaCha20Rng; 20 + use spin::{Barrier, OnceLock}; 21 + 14 22 use crate::boot_info::prepare_boot_info; 15 23 use crate::error::Error; 16 24 use crate::frame_alloc::FrameAllocator; ··· 20 28 StacksAllocation, TlsAllocation, identity_map_self, map_kernel, map_kernel_stacks, 21 29 map_physical_memory, 22 30 }; 23 - use arrayvec::ArrayVec; 24 - use core::ffi::c_void; 25 - use core::range::Range; 26 - use rand::SeedableRng; 27 - use rand_chacha::ChaCha20Rng; 28 - use spin::{Barrier, OnceLock}; 29 31 30 32 mod arch; 31 33 mod boot_info;
+9 -7
loader/src/mapping.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::error::Error; 9 - use crate::frame_alloc::FrameAllocator; 10 - use crate::kernel::Kernel; 11 - use crate::machine_info::MachineInfo; 12 - use crate::page_alloc::PageAllocator; 13 - use crate::{SelfRegions, arch}; 14 - use bitflags::bitflags; 15 8 use core::alloc::Layout; 16 9 use core::num::NonZeroUsize; 17 10 use core::range::Range; 18 11 use core::{cmp, ptr, slice}; 12 + 13 + use bitflags::bitflags; 19 14 use fallible_iterator::FallibleIterator; 20 15 use loader_api::TlsTemplate; 21 16 use xmas_elf::P64; 22 17 use xmas_elf::dynamic::Tag; 23 18 use xmas_elf::program::{SegmentData, Type}; 19 + 20 + use crate::error::Error; 21 + use crate::frame_alloc::FrameAllocator; 22 + use crate::kernel::Kernel; 23 + use crate::machine_info::MachineInfo; 24 + use crate::page_alloc::PageAllocator; 25 + use crate::{SelfRegions, arch}; 24 26 25 27 bitflags! { 26 28 #[derive(Debug, Copy, Clone, PartialEq)]
+3 -1
loader/src/page_alloc.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use crate::arch; 9 8 use core::alloc::Layout; 10 9 use core::range::Range; 10 + 11 11 use rand::distr::{Distribution, Uniform}; 12 12 use rand::prelude::IteratorRandom; 13 13 use rand_chacha::ChaCha20Rng; 14 + 15 + use crate::arch; 14 16 15 17 pub fn init(prng: Option<ChaCha20Rng>) -> PageAllocator { 16 18 PageAllocator {
+2 -1
loader/src/panic.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 + use abort::abort; 9 + 8 10 use crate::arch; 9 - use abort::abort; 10 11 11 12 #[panic_handler] 12 13 fn panic(info: &core::panic::PanicInfo) -> ! {
+2
rustfmt.toml
··· 1 + group_imports = "StdExternalCrate" 2 + imports_granularity = "Module"