···1919//! This crate exposes a single function [`merge_toml_documents`] which does
2020//! this for you!
21212222-use eyre::{Result, bail, eyre};
2322use std::collections::BTreeMap;
2424-use toml_edit::{visit::Visit, visit_mut::VisitMut};
2323+2424+use eyre::{Result, bail, eyre};
2525+use toml_edit::visit::Visit;
2626+use toml_edit::visit_mut::VisitMut;
25272628pub fn merge_toml_documents(
2729 original: &mut toml_edit::DocumentMut,
···270272271273#[cfg(test)]
272274mod tests {
275275+ use indoc::indoc;
276276+273277 use super::*;
274274- use indoc::indoc;
275278276279 fn patch_and_compare(a: &str, b: &str, out: &str) {
277280 let mut a: toml_edit::DocumentMut = a.parse().unwrap();
+6-4
build/xtask/src/build.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use std::path::{Path, PathBuf};
99+use std::process::Command;
1010+1111+use color_eyre::eyre::{Context, bail};
1212+use tracing_core::LevelFilter;
1313+814use crate::Options;
915use crate::profile::{LogLevel, Profile, RustTarget};
1016use crate::tracing::{ColorMode, OutputOptions};
1117use crate::util::KillOnDrop;
1212-use color_eyre::eyre::{Context, bail};
1313-use std::path::{Path, PathBuf};
1414-use std::process::Command;
1515-use tracing_core::LevelFilter;
16181719const DEFAULT_KERNEL_STACK_SIZE_PAGES: u32 = 256;
1820
+4-2
build/xtask/src/cmds/build.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use std::path::PathBuf;
99+1010+use clap::{Parser, ValueHint};
1111+812use crate::Options;
913use crate::profile::Profile;
1014use crate::tracing::OutputOptions;
1111-use clap::{Parser, ValueHint};
1212-use std::path::PathBuf;
13151416#[derive(Debug, Parser)]
1517pub struct Cmd {
+4-2
build/xtask/src/cmds/dist.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use std::path::PathBuf;
99+1010+use clap::{Parser, ValueHint};
1111+812use crate::Options;
913use crate::profile::Profile;
1014use crate::tracing::OutputOptions;
1111-use clap::{Parser, ValueHint};
1212-use std::path::PathBuf;
13151416#[derive(Debug, Parser)]
1517pub struct Cmd {
+6-4
build/xtask/src/cmds/lldb.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::profile::Profile;
99-use crate::tracing::OutputOptions;
1010-use crate::{Options, build, qemu};
1111-use clap::{Parser, ValueHint};
128use std::path::PathBuf;
139use std::process::{Command, Stdio};
1410use std::{fs, thread};
1111+1212+use clap::{Parser, ValueHint};
1313+1414+use crate::profile::Profile;
1515+use crate::tracing::OutputOptions;
1616+use crate::{Options, build, qemu};
15171618#[derive(Debug, Parser)]
1719pub struct Cmd {
+4-2
build/xtask/src/cmds/qemu.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use std::path::PathBuf;
99+1010+use clap::{Parser, ValueHint};
1111+812use crate::profile::Profile;
913use crate::tracing::OutputOptions;
1014use crate::{Options, qemu};
1111-use clap::{Parser, ValueHint};
1212-use std::path::PathBuf;
13151416#[derive(Debug, Parser)]
1517pub struct Cmd {
+4-2
build/xtask/src/cmds/run.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use std::path::PathBuf;
99+1010+use clap::{Parser, ValueHint};
1111+812use crate::profile::Profile;
913use crate::tracing::OutputOptions;
1014use crate::{Options, qemu};
1111-use clap::{Parser, ValueHint};
1212-use std::path::PathBuf;
13151416#[derive(Debug, Parser)]
1517pub struct Cmd {
+9-7
build/xtask/src/cmds/test.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use std::path::PathBuf;
99+use std::process::ExitStatus;
1010+use std::time::Duration;
1111+1212+use clap::{Parser, ValueHint};
1313+use color_eyre::Help;
1414+use color_eyre::eyre::{Context, format_err};
1515+use wait_timeout::ChildExt;
1616+817use crate::build::{Cargo, CrateToBuild};
918use crate::profile::{Architecture, Profile};
1019use crate::tracing::OutputOptions;
1120use crate::util::KillOnDrop;
1221use crate::{Options, qemu};
1313-use clap::{Parser, ValueHint};
1414-use color_eyre::Help;
1515-use color_eyre::eyre::{Context, format_err};
1616-use std::path::PathBuf;
1717-use std::process::ExitStatus;
1818-use std::time::Duration;
1919-use wait_timeout::ChildExt;
20222123#[derive(Debug, Parser)]
2224pub struct Cmd {
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::profile::{Architecture, Profile};
99-use crate::util::KillOnDrop;
1010-use clap::Parser;
118use std::path::Path;
129use std::process::{Command, Stdio};
1010+1111+use clap::Parser;
1212+1313+use crate::profile::{Architecture, Profile};
1414+use crate::util::KillOnDrop;
13151416#[derive(Debug, Parser)]
1517pub struct QemuOptions {
+3-2
build/xtask/src/tracing.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use std::fmt;
99+use std::io::IsTerminal;
1010+811use clap::{ArgGroup, Args};
912use color_eyre::owo_colors;
1013use color_eyre::owo_colors::{OwoColorize, Style, style};
1114use heck::ToTitleCase;
1212-use std::fmt;
1313-use std::io::IsTerminal;
1415use tracing_core::field::Visit;
1516use tracing_core::{Collect, Event, Field, Level};
1617use tracing_subscriber::fmt::format::Writer;
+4-2
kernel/src/allocator.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::mem::bootstrap_alloc::BootstrapAllocator;
99-use crate::{INITIAL_HEAP_SIZE_PAGES, arch};
108use core::alloc::Layout;
119use core::range::Range;
1010+1211use loader_api::BootInfo;
1312use talc::{ErrOnOom, Span, Talc, Talck};
1313+1414+use crate::mem::bootstrap_alloc::BootstrapAllocator;
1515+use crate::{INITIAL_HEAP_SIZE_PAGES, arch};
14161517#[global_allocator]
1618static KERNEL_ALLOCATOR: Talck<spin::Mutex<()>, ErrOnOom> = Talc::new(ErrOnOom).lock();
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::state;
98use alloc::sync::Arc;
109use core::arch::asm;
1110use core::mem::ManuallyDrop;
1211use core::sync::atomic::{AtomicBool, Ordering};
1312use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
1313+1414use cpu_local::cpu_local;
1515use futures::pin_mut;
1616use futures::task::WakerRef;
1717use riscv::sbi;
1818+1919+use crate::state;
18201921struct HartNotify {
2022 hartid: usize,
+3-1
kernel/src/arch/riscv64/device/clock.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::device_tree::Device;
98use core::ptr;
109use core::time::Duration;
1010+1111use kasync::time::{Clock, NANOS_PER_SEC, RawClock, RawClockVTable};
1212use riscv::sbi;
1313+1414+use crate::device_tree::Device;
13151416static CLOCK_VTABLE: RawClockVTable =
1517 RawClockVTable::new(clone_raw, now_raw, schedule_wakeup_raw, drop_raw);
+6-4
kernel/src/arch/riscv64/device/cpu.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch::device;
99-use crate::device_tree::DeviceTree;
1010-use crate::irq::InterruptController;
1111-use bitflags::bitflags;
128use core::cell::RefCell;
139use core::fmt;
1410use core::str::FromStr;
1111+1212+use bitflags::bitflags;
1313+1414+use crate::arch::device;
1515+use crate::device_tree::DeviceTree;
1616+use crate::irq::InterruptController;
15171618#[derive(Debug)]
1719pub struct Cpu {
+9-7
kernel/src/arch/riscv64/device/plic.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch::PAGE_SIZE;
99-use crate::device_tree::{Device, DeviceTree, IrqSource};
1010-use crate::irq::{InterruptController, IrqClaim};
1111-use crate::mem::{
1212- AddressRangeExt, AddressSpaceRegion, Permissions, PhysicalAddress, with_kernel_aspace,
1313-};
1414-use crate::util::either::Either;
158use alloc::string::ToString;
169use core::alloc::Layout;
1710use core::mem::{MaybeUninit, offset_of};
···1912use core::ops::{BitAnd, BitOr, Not};
2013use core::ptr;
2114use core::range::Range;
1515+2216use fallible_iterator::FallibleIterator;
2317use static_assertions::const_assert_eq;
1818+1919+use crate::arch::PAGE_SIZE;
2020+use crate::device_tree::{Device, DeviceTree, IrqSource};
2121+use crate::irq::{InterruptController, IrqClaim};
2222+use crate::mem::{
2323+ AddressRangeExt, AddressSpaceRegion, Permissions, PhysicalAddress, with_kernel_aspace,
2424+};
2525+use crate::util::either::Either;
24262527const MAX_CONTEXTS: usize = 64;
2628
+7-5
kernel/src/arch/riscv64/mem.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch::{mb, wmb};
99-use crate::mem::flush::Flush;
1010-use crate::mem::frame_alloc::{Frame, FrameAllocator};
1111-use crate::mem::{PhysicalAddress, VirtualAddress};
128use alloc::vec;
139use alloc::vec::Vec;
1414-use bitflags::bitflags;
1510use core::num::NonZeroUsize;
1611use core::ptr::NonNull;
1712use core::range::{Range, RangeInclusive};
1813use core::{fmt, slice};
1414+1515+use bitflags::bitflags;
1916use riscv::satp;
2017use riscv::sbi::rfence::sfence_vma_asid;
2118use static_assertions::const_assert_eq;
1919+2020+use crate::arch::{mb, wmb};
2121+use crate::mem::flush::Flush;
2222+use crate::mem::frame_alloc::{Frame, FrameAllocator};
2323+use crate::mem::{PhysicalAddress, VirtualAddress};
22242325pub const DEFAULT_ASID: u16 = 0;
2426
···4747use core::marker::{PhantomData, PhantomPinned};
4848use core::mem::{ManuallyDrop, MaybeUninit};
4949use core::ptr::addr_of_mut;
5050+5051use riscv::{load_fp, load_gp, save_fp, save_gp};
51525253/// A store for the register state used by `setjmp` and `longjmp`.
+10-7
kernel/src/arch/riscv64/trap_handler.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use alloc::boxed::Box;
99+use core::arch::{asm, naked_asm};
1010+use core::cell::Cell;
1111+1212+use cpu_local::cpu_local;
1313+use riscv::scause::{Exception, Interrupt};
1414+use riscv::{
1515+ load_fp, load_gp, save_fp, save_gp, scause, sepc, sip, sscratch, sstatus, stval, stvec,
1616+};
1717+818use crate::arch::PAGE_SIZE;
919use crate::arch::trap::Trap;
1020use crate::backtrace::Backtrace;
1121use crate::mem::VirtualAddress;
1222use crate::state::{cpu_local, global};
1323use crate::{TRAP_STACK_SIZE_PAGES, irq};
1414-use alloc::boxed::Box;
1515-use core::arch::{asm, naked_asm};
1616-use core::cell::Cell;
1717-use cpu_local::cpu_local;
1818-use riscv::scause::{Exception, Interrupt};
1919-use riscv::{load_fp, load_gp, save_fp, save_gp};
2020-use riscv::{scause, sepc, sip, sscratch, sstatus, stval, stvec};
21242225cpu_local! {
2326 static IN_TRAP: Cell<bool> = Cell::new(false);
···7788//! Printing of backtraces. This is adapted from the standard library.
991010+use core::fmt;
1111+1012use crate::backtrace::BacktraceStyle;
1113use crate::backtrace::symbolize::{Symbol, SymbolName};
1212-use core::fmt;
13141415const HEX_WIDTH: usize = 2 + 2 * size_of::<usize>();
1516
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use core::str::FromStr;
99+810use crate::backtrace::BacktraceStyle;
911use crate::device_tree::DeviceTree;
1012use crate::tracing::Filter;
1111-use core::str::FromStr;
12131314pub fn parse(devtree: &DeviceTree) -> crate::Result<Bootargs> {
1415 let chosen = devtree.find_by_path("/chosen").unwrap();
+2-1
kernel/src/device_tree.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use bumpalo::Bump;
98use core::ffi::CStr;
109use core::ptr::NonNull;
1110use core::{fmt, iter, mem, slice};
1111+1212+use bumpalo::Bump;
1213use fallible_iterator::FallibleIterator;
1314use fdt::{CellSizes, Error, Fdt, NodeName, StringList};
1415use hashbrown::HashMap;
+3-1
kernel/src/irq.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::state::cpu_local;
98use alloc::sync::Arc;
109use core::num::NonZero;
1010+1111use hashbrown::HashMap;
1212use kasync::sync::wait_queue::WaitQueue;
1313use spin::{LazyLock, RwLock};
1414+1515+use crate::state::cpu_local;
14161517pub trait InterruptController {
1618 fn irq_claim(&mut self) -> Option<IrqClaim>;
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
98use core::alloc::{Layout, LayoutError};
109use core::fmt;
1110use core::range::Range;
1111+1212+use crate::arch;
12131314macro_rules! address_impl {
1415 ($addr:ident) => {
+10-8
kernel/src/mem/address_space.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
99-use crate::mem::address_space_region::AddressSpaceRegion;
1010-use crate::mem::frame_alloc::FrameAllocator;
1111-use crate::mem::{
1212- AddressRangeExt, ArchAddressSpace, Flush, PageFaultFlags, Permissions, PhysicalAddress,
1313- VirtualAddress,
1414-};
158use alloc::boxed::Box;
169use alloc::string::String;
1710use alloc::vec;
1811use alloc::vec::Vec;
1919-use anyhow::{bail, ensure};
2012use core::alloc::Layout;
2113use core::fmt;
2214use core::num::NonZeroUsize;
···2416use core::pin::Pin;
2517use core::ptr::NonNull;
2618use core::range::{Bound, Range, RangeBounds, RangeInclusive};
1919+2020+use anyhow::{bail, ensure};
2721use rand::Rng;
2822use rand::distr::Uniform;
2923use rand_chacha::ChaCha20Rng;
2424+2525+use crate::arch;
2626+use crate::mem::address_space_region::AddressSpaceRegion;
2727+use crate::mem::frame_alloc::FrameAllocator;
2828+use crate::mem::{
2929+ AddressRangeExt, ArchAddressSpace, Flush, PageFaultFlags, Permissions, PhysicalAddress,
3030+ VirtualAddress,
3131+};
30323133// const VIRT_ALLOC_ENTROPY: u8 = u8::try_from((arch::VIRT_ADDR_BITS - arch::PAGE_SHIFT as u32) + 1).unwrap();
3234const VIRT_ALLOC_ENTROPY: u8 = 27;
+7-5
kernel/src/mem/address_space_region.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
99-use crate::mem::address::VirtualAddress;
1010-use crate::mem::frame_alloc::FrameAllocator;
1111-use crate::mem::{AddressRangeExt, Batch, PageFaultFlags, Permissions, PhysicalAddress, Vmo};
128use alloc::boxed::Box;
139use alloc::string::String;
1410use alloc::sync::Arc;
1515-use anyhow::bail;
1611use core::cmp;
1712use core::mem::offset_of;
1813use core::num::NonZeroUsize;
1914use core::pin::Pin;
2015use core::ptr::NonNull;
2116use core::range::Range;
1717+1818+use anyhow::bail;
2219use pin_project::pin_project;
2320use spin::LazyLock;
2121+2222+use crate::arch;
2323+use crate::mem::address::VirtualAddress;
2424+use crate::mem::frame_alloc::FrameAllocator;
2525+use crate::mem::{AddressRangeExt, Batch, PageFaultFlags, Permissions, PhysicalAddress, Vmo};
24262527/// A contiguous region of an address space
2628#[pin_project]
+3-2
kernel/src/mem/bootstrap_alloc.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
99-use crate::mem::address::{AddressRangeExt, PhysicalAddress};
108use core::alloc::Layout;
119use core::range::Range;
1210use core::{iter, ptr, slice};
1111+1212+use crate::arch;
1313+use crate::mem::address::{AddressRangeExt, PhysicalAddress};
13141415pub struct BootstrapAllocator<'a> {
1516 regions: &'a [Range<PhysicalAddress>],
+5-3
kernel/src/mem/flush.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
99-use crate::mem::address::VirtualAddress;
1010-use anyhow::bail;
118use core::range::Range;
129use core::{cmp, mem};
1010+1111+use anyhow::bail;
1212+1313+use crate::arch;
1414+use crate::mem::address::VirtualAddress;
13151416#[must_use]
1517pub struct Flush {
+6-4
kernel/src/mem/frame_alloc/arena.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use super::frame::FrameInfo;
99-use crate::arch;
1010-use crate::mem::address::{AddressRangeExt, PhysicalAddress, VirtualAddress};
1111-use cordyceps::List;
128use core::alloc::Layout;
139use core::mem::MaybeUninit;
1410use core::ptr::NonNull;
1511use core::range::Range;
1612use core::{cmp, fmt, mem, slice};
1313+1414+use cordyceps::List;
1715use fallible_iterator::FallibleIterator;
1816use smallvec::SmallVec;
1717+1818+use super::frame::FrameInfo;
1919+use crate::arch;
2020+use crate::mem::address::{AddressRangeExt, PhysicalAddress, VirtualAddress};
19212022const ARENA_PAGE_BOOKKEEPING_SIZE: usize = size_of::<FrameInfo>();
2123const MAX_WASTED_ARENA_BYTES: usize = 0x8_4000; // 528 KiB
+6-5
kernel/src/mem/frame_alloc/frame.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
99-use crate::mem::address::{PhysicalAddress, VirtualAddress};
1010-use crate::mem::frame_alloc::FRAME_ALLOC;
118use alloc::slice;
1212-use cordyceps::Linked;
1313-use cordyceps::list;
149use core::marker::PhantomData;
1510use core::mem::offset_of;
1611use core::ops::Deref;
···1813use core::sync::atomic;
1914use core::sync::atomic::{AtomicUsize, Ordering};
2015use core::{fmt, ptr};
1616+1717+use cordyceps::{Linked, list};
2118use static_assertions::assert_impl_all;
1919+2020+use crate::arch;
2121+use crate::mem::address::{PhysicalAddress, VirtualAddress};
2222+use crate::mem::frame_alloc::FRAME_ALLOC;
22232324/// Soft limit on the amount of references that may be made to a `Frame`.
2425const MAX_REFCOUNT: usize = isize::MAX as usize;
+4-2
kernel/src/mem/frame_alloc/frame_list.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
99-use crate::mem::frame_alloc::Frame;
108use alloc::boxed::Box;
119use core::fmt::Formatter;
1210use core::iter::{FlatMap, Flatten, FusedIterator};
···1412use core::pin::Pin;
1513use core::ptr::NonNull;
1614use core::{array, fmt};
1515+1716use pin_project::pin_project;
1817use wavltree::WAVLTree;
1818+1919+use crate::arch;
2020+use crate::mem::frame_alloc::Frame;
19212022const FRAME_LIST_NODE_FANOUT: usize = 16;
2123
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
99-use crate::mem::frame_alloc::{FRAME_ALLOC, FrameAllocator};
1010-use crate::mem::frame_alloc::{Frame, frame_list::FrameList};
118use alloc::sync::Arc;
129use core::alloc::Layout;
1310use core::fmt::Debug;
1411use core::iter;
1512use core::num::NonZeroUsize;
1313+1614use spin::{LazyLock, OnceLock};
1515+1616+use crate::arch;
1717+use crate::mem::frame_alloc::frame_list::FrameList;
1818+use crate::mem::frame_alloc::{FRAME_ALLOC, Frame, FrameAllocator};
17191820pub trait Provider: Debug {
1921 // TODO make async
+2-1
kernel/src/mem/trap_handler.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use core::ops::ControlFlow;
99+810use crate::arch::trap::Trap;
911use crate::mem::VirtualAddress;
1012use crate::state::global;
1111-use core::ops::ControlFlow;
12131314pub fn handle_page_fault(_trap: Trap, _tval: VirtualAddress) -> ControlFlow<()> {
1415 let current_task = global()
+8-11
kernel/src/mem/vmo.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
99-use crate::mem::frame_alloc::FrameAllocator;
1010-use crate::mem::provider::{Provider, THE_ZERO_FRAME};
1111-use crate::mem::{
1212- AddressRangeExt, PhysicalAddress,
1313- frame_alloc::{
1414- Frame,
1515- frame_list::{Entry, FrameList},
1616- },
1717-};
188use alloc::sync::Arc;
99+use core::range::Range;
1010+1911use anyhow::ensure;
2020-use core::range::Range;
2112use spin::RwLock;
1313+1414+use crate::arch;
1515+use crate::mem::frame_alloc::frame_list::{Entry, FrameList};
1616+use crate::mem::frame_alloc::{Frame, FrameAllocator};
1717+use crate::mem::provider::{Provider, THE_ZERO_FRAME};
1818+use crate::mem::{AddressRangeExt, PhysicalAddress};
22192320#[derive(Debug)]
2421pub enum Vmo {
+1
kernel/src/metrics.rs
···2626//! cpus.
27272828use core::sync::atomic::{AtomicU64, Ordering};
2929+2930use cpu_local::collection::CpuLocal;
30313132/// Declares a new counter.
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
99-use crate::device_tree::DeviceTree;
108use core::cell::OnceCell;
99+1110use cpu_local::cpu_local;
1211use kasync::executor::Executor;
1312use kasync::time::{Instant, Timer};
1413use loader_api::BootInfo;
1514use spin::OnceLock;
1515+1616+use crate::arch;
1717+use crate::device_tree::DeviceTree;
16181719static GLOBAL: OnceLock<Global> = OnceLock::new();
1820
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use super::args::FormatSetting;
99-use super::{Conclusion, Outcome};
108use alloc::boxed::Box;
119use core::sync::atomic::Ordering;
1010+1211use ktest::{Test, TestInfo};
1212+1313+use super::args::FormatSetting;
1414+use super::{Conclusion, Outcome};
13151416pub struct Printer {
1517 format: FormatSetting,
+7-5
kernel/src/tests/wast.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::wasm::{
99- ConstExprEvaluator, Engine, Extern, Instance, Linker, Module, PlaceholderAllocatorDontUse,
1010- Store, Val,
1111-};
128use alloc::string::ToString;
139use alloc::sync::Arc;
1410use alloc::vec::Vec;
1511use alloc::{format, vec};
1616-use anyhow::{Context, anyhow, bail};
1712use core::fmt::{Display, LowerHex};
1313+1414+use anyhow::{Context, anyhow, bail};
1815use spin::Mutex;
1916use wasmparser::Validator;
2017use wast::core::{EncodeOptions, NanPattern, V128Pattern, WastArgCore, WastRetCore};
···2219use wast::token::{F32, F64};
2320use wast::{
2421 Error, QuoteWat, Wast, WastArg, WastDirective, WastExecute, WastInvoke, WastRet, Wat, parser,
2222+};
2323+2424+use crate::wasm::{
2525+ ConstExprEvaluator, Engine, Extern, Instance, Linker, Module, PlaceholderAllocatorDontUse,
2626+ Store, Val,
2527};
26282729macro_rules! wast_tests {
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::tracing::color::{AnsiEscapes, Color, SetColor};
98use core::cell::UnsafeCell;
109use core::fmt::{Arguments, Write};
1110use core::{cmp, fmt};
1111+1212use spin::{ReentrantMutex, ReentrantMutexGuard};
1313use tracing_core::Metadata;
1414+1515+use crate::tracing::color::{AnsiEscapes, Color, SetColor};
14161517pub trait MakeWriter<'a> {
1618 type Writer: fmt::Write;
+3-1
kernel/src/wasm/code_registry.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::wasm::vm::CodeObject;
98use alloc::collections::BTreeMap;
109use alloc::sync::Arc;
1010+1111use spin::{OnceLock, RwLock};
1212+1313+use crate::wasm::vm::CodeObject;
12141315fn global_code() -> &'static RwLock<GlobalRegistry> {
1416 static GLOBAL_CODE: OnceLock<RwLock<GlobalRegistry>> = OnceLock::new();
+5-4
kernel/src/wasm/compile/compiled_function.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::wasm::builtins::BuiltinFunctionIndex;
99-use crate::wasm::compile::{FilePos, NS_BUILTIN, NS_WASM_FUNC};
1010-use crate::wasm::indices::FuncIndex;
1111-use crate::wasm::trap::TrapKind;
128use cranelift_codegen::ir::{ExternalName, StackSlots, UserExternalName, UserExternalNameRef};
139use cranelift_codegen::{
1410 Final, FinalizedMachReloc, FinalizedRelocTarget, MachBufferFinalized, ValueLabelsRanges,
1511 binemit,
1612};
1713use cranelift_entity::PrimaryMap;
1414+1515+use crate::wasm::builtins::BuiltinFunctionIndex;
1616+use crate::wasm::compile::{FilePos, NS_BUILTIN, NS_WASM_FUNC};
1717+use crate::wasm::indices::FuncIndex;
1818+use crate::wasm::trap::TrapKind;
18191920#[derive(Debug)]
2021pub struct CompiledFunction {
+11-9
kernel/src/wasm/compile/mod.rs
···88mod compile_key;
99mod compiled_function;
10101111-use crate::wasm::Engine;
1212-use crate::wasm::builtins::BuiltinFunctionIndex;
1313-use crate::wasm::compile::compiled_function::{RelocationTarget, TrapInfo};
1414-use crate::wasm::indices::{DefinedFuncIndex, ModuleInternedTypeIndex};
1515-use crate::wasm::translate::{
1616- FunctionBodyData, ModuleTranslation, ModuleTypes, TranslatedModule, WasmFuncType,
1717-};
1818-use crate::wasm::trap::TrapKind;
1919-use crate::wasm::vm::{CodeObject, MmapVec};
2011use alloc::boxed::Box;
2112use alloc::collections::BTreeMap;
2213use alloc::format;
2314use alloc::string::String;
2415use alloc::vec::Vec;
1616+2517use compile_key::CompileKey;
2618pub use compiled_function::CompiledFunction;
2719use cranelift_codegen::control::ControlPlane;
2820use cranelift_entity::{EntitySet, PrimaryMap};
2921use hashbrown::HashSet;
2222+2323+use crate::wasm::Engine;
2424+use crate::wasm::builtins::BuiltinFunctionIndex;
2525+use crate::wasm::compile::compiled_function::{RelocationTarget, TrapInfo};
2626+use crate::wasm::indices::{DefinedFuncIndex, ModuleInternedTypeIndex};
2727+use crate::wasm::translate::{
2828+ FunctionBodyData, ModuleTranslation, ModuleTypes, TranslatedModule, WasmFuncType,
2929+};
3030+use crate::wasm::trap::TrapKind;
3131+use crate::wasm::vm::{CodeObject, MmapVec};
30323133/// Namespace corresponding to wasm functions, the index is the index of the
3234/// defined function that's being referenced.
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::wasm::cranelift::code_translator::{bitcast_wasm_returns, translate_operator};
99-use crate::wasm::cranelift::env::TranslationEnvironment;
1010-use crate::wasm::cranelift::state::FuncTranslationState;
1111-use crate::wasm::cranelift::utils::get_vmctx_value_label;
128use cranelift_codegen::ir;
139use cranelift_codegen::ir::{InstBuilder, ValueLabel};
1410use cranelift_entity::EntityRef;
1511use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
1612use wasmparser::{BinaryReader, FuncValidator, FunctionBody, WasmModuleResources};
1313+1414+use crate::wasm::cranelift::code_translator::{bitcast_wasm_returns, translate_operator};
1515+use crate::wasm::cranelift::env::TranslationEnvironment;
1616+use crate::wasm::cranelift::state::FuncTranslationState;
1717+use crate::wasm::cranelift::utils::get_vmctx_value_label;
17181819pub struct FuncTranslator {
1920 func_ctx: FunctionBuilderContext,
+9-7
kernel/src/wasm/cranelift/memory.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::wasm::cranelift::code_translator::Reachability;
99-use crate::wasm::cranelift::env::TranslationEnvironment;
1010-use crate::wasm::cranelift::utils::index_type_to_ir_type;
1111-use crate::wasm::translate::IndexType;
1212-use crate::wasm::trap::TRAP_HEAP_MISALIGNED;
138use cranelift_codegen::cursor::{Cursor, FuncCursor};
149use cranelift_codegen::ir;
1515-use cranelift_codegen::ir::InstBuilder;
1610use cranelift_codegen::ir::condcodes::IntCC;
1717-use cranelift_codegen::ir::{Expr, Fact, MemFlags, RelSourceLoc, TrapCode, Type, Value};
1111+use cranelift_codegen::ir::{
1212+ Expr, Fact, InstBuilder, MemFlags, RelSourceLoc, TrapCode, Type, Value,
1313+};
1814use cranelift_frontend::FunctionBuilder;
1915use wasmparser::MemArg;
1616+1717+use crate::wasm::cranelift::code_translator::Reachability;
1818+use crate::wasm::cranelift::env::TranslationEnvironment;
1919+use crate::wasm::cranelift::utils::index_type_to_ir_type;
2020+use crate::wasm::translate::IndexType;
2121+use crate::wasm::trap::TRAP_HEAP_MISALIGNED;
20222123#[derive(Debug, Clone)]
2224pub struct CraneliftMemory {
+2-1
kernel/src/wasm/cranelift/mod.rs
···1414mod state;
1515mod utils;
16161717-use crate::wasm::trap::TRAP_TABLE_OUT_OF_BOUNDS;
1817pub use compiler::CraneliftCompiler;
1918use cranelift_codegen::ir;
2019use cranelift_codegen::ir::condcodes::IntCC;
2120use cranelift_codegen::ir::immediates::Imm64;
2221use cranelift_codegen::ir::{InstBuilder, MemFlags};
2322use cranelift_frontend::FunctionBuilder;
2323+2424+use crate::wasm::trap::TRAP_TABLE_OUT_OF_BOUNDS;
24252526/// The value of a WebAssembly global variable.
2627#[derive(Clone, Copy)]
+6-4
kernel/src/wasm/cranelift/state.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::wasm::cranelift::env::TranslationEnvironment;
99-use crate::wasm::cranelift::memory::CraneliftMemory;
1010-use crate::wasm::cranelift::{CraneliftGlobal, CraneliftTable};
1111-use crate::wasm::indices::{FuncIndex, GlobalIndex, MemoryIndex, TableIndex, TypeIndex};
128use alloc::vec::Vec;
99+1310use cranelift_codegen::ir;
1411use cranelift_codegen::ir::{Block, FuncRef, Function, Inst, SigRef, Value};
1512use hashbrown::HashMap;
1313+1414+use crate::wasm::cranelift::env::TranslationEnvironment;
1515+use crate::wasm::cranelift::memory::CraneliftMemory;
1616+use crate::wasm::cranelift::{CraneliftGlobal, CraneliftTable};
1717+use crate::wasm::indices::{FuncIndex, GlobalIndex, MemoryIndex, TableIndex, TypeIndex};
16181719pub struct FuncTranslationState {
1820 /// A stack of values corresponding to the active values in the input wasm function at this
+3-2
kernel/src/wasm/cranelift/utils.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::wasm::cranelift::env::TranslationEnvironment;
99-use crate::wasm::translate::IndexType;
108use cranelift_codegen::ir;
119use cranelift_codegen::ir::types;
1210use cranelift_frontend::FunctionBuilder;
1311use wasmparser::{FuncValidator, WasmModuleResources};
1212+1313+use crate::wasm::cranelift::env::TranslationEnvironment;
1414+use crate::wasm::translate::IndexType;
14151516/// Get the parameter and result types for the given Wasm blocktype.
1617pub fn blocktype_params_results<T>(
+6-4
kernel/src/wasm/engine.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
99-use crate::wasm::compile::Compiler;
1010-use crate::wasm::cranelift::CraneliftCompiler;
1111-use crate::wasm::type_registry::TypeRegistry;
128use alloc::sync::Arc;
139use core::sync::atomic::AtomicU64;
1010+1411use cranelift_codegen::settings::{Configurable, Flags};
1512use rand::{Rng, SeedableRng};
1613use rand_chacha::ChaCha20Rng;
1714use spin::{Mutex, MutexGuard};
1515+1616+use crate::arch;
1717+use crate::wasm::compile::Compiler;
1818+use crate::wasm::cranelift::CraneliftCompiler;
1919+use crate::wasm::type_registry::TypeRegistry;
18201921/// Global context for the runtime.
2022///
+8-6
kernel/src/wasm/func/host.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use alloc::boxed::Box;
99+use alloc::sync::Arc;
1010+use core::mem::MaybeUninit;
1111+use core::ptr::NonNull;
1212+use core::{iter, ptr};
1313+1414+use anyhow::bail;
1515+816use crate::wasm::func::typed::WasmTy;
917use crate::wasm::func::{FuncData, FuncKind};
1018use crate::wasm::store::{StoreInner, StoreOpaque};
···1321 InstanceAndStore, VMArrayCallHostFuncContext, VMContext, VMFuncRef, VMOpaqueContext, VMVal,
1422};
1523use crate::wasm::{Engine, Func};
1616-use alloc::boxed::Box;
1717-use alloc::sync::Arc;
1818-use anyhow::bail;
1919-use core::mem::MaybeUninit;
2020-use core::ptr::NonNull;
2121-use core::{iter, ptr};
22242325#[derive(Debug)]
2426pub struct HostFunc {
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::wasm::func::do_call;
99-use crate::wasm::store::StoreOpaque;
1010-use crate::wasm::types::{FuncType, HeapType, RefType, ValType};
1111-use crate::wasm::vm::VMVal;
1212-use crate::wasm::{Engine, Func};
138use core::ffi::c_void;
149use core::marker::PhantomData;
1510use core::mem::MaybeUninit;
1611use core::ptr;
1712use core::ptr::NonNull;
1313+1814use static_assertions::assert_impl_all;
1515+1616+use crate::wasm::func::do_call;
1717+use crate::wasm::store::StoreOpaque;
1818+use crate::wasm::types::{FuncType, HeapType, RefType, ValType};
1919+use crate::wasm::vm::VMVal;
2020+use crate::wasm::{Engine, Func};
19212022pub struct TypedFunc<Params, Results> {
2123 ty: FuncType,
+5-3
kernel/src/wasm/global.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use core::ptr;
99+use core::ptr::NonNull;
1010+1111+use anyhow::{Context, bail};
1212+813use crate::wasm::Func;
914use crate::wasm::store::{StoreOpaque, Stored};
1015use crate::wasm::types::{GlobalType, HeapTypeInner, Mutability, ValType};
1116use crate::wasm::values::{Ref, Val};
1217use crate::wasm::vm::{ExportedGlobal, VMGlobalDefinition, VMGlobalImport, VmPtr};
1313-use anyhow::{Context, bail};
1414-use core::ptr;
1515-use core::ptr::NonNull;
16181719#[derive(Clone, Copy, Debug)]
1820pub struct Global(Stored<ExportedGlobal>);
+2-1
kernel/src/wasm/indices.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use cranelift_entity::entity_impl;
99+810use crate::wasm::utils::enum_accessors;
99-use cranelift_entity::entity_impl;
10111112#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
1213pub struct TypeIndex(u32);
+3-2
kernel/src/wasm/instance.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use alloc::vec;
99+use alloc::vec::Vec;
1010+811use crate::util::zip_eq::IteratorExt;
912use crate::wasm::indices::EntityIndex;
1013use crate::wasm::module::Module;
1114use crate::wasm::store::{StoreOpaque, Stored};
1215use crate::wasm::vm::{ConstExprEvaluator, Imports, InstanceHandle};
1316use crate::wasm::{Extern, Func, Global, Memory, Table};
1414-use alloc::vec;
1515-use alloc::vec::Vec;
16171718/// An instantiated WebAssembly module.
1819///
+8-6
kernel/src/wasm/linker.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use alloc::sync::Arc;
99+use alloc::vec::Vec;
1010+use core::marker::PhantomData;
1111+1212+use anyhow::{Context, bail, format_err};
1313+use hashbrown::HashMap;
1414+use hashbrown::hash_map::Entry;
1515+816use crate::wasm::func::{HostFunc, IntoFunc, WasmParams, WasmResults};
917use crate::wasm::indices::VMSharedTypeIndex;
1018use crate::wasm::store::StoreOpaque;
···1220use crate::wasm::types::{GlobalType, MemoryType, TableType, TagType};
1321use crate::wasm::vm::{ConstExprEvaluator, Imports};
1422use crate::wasm::{Engine, Extern, Func, Global, Instance, Memory, Module, Store, Table, Tag};
1515-use alloc::sync::Arc;
1616-use alloc::vec::Vec;
1717-use anyhow::{Context, bail, format_err};
1818-use core::marker::PhantomData;
1919-use hashbrown::HashMap;
2020-use hashbrown::hash_map::Entry;
21232224/// A dynamic linker for WebAssembly modules.
2325#[derive(Debug)]
+3-3
kernel/src/wasm/mod.rs
···3131mod values;
3232mod vm;
33333434-use crate::wasm::store::StoreOpaque;
3535-use crate::wasm::utils::{enum_accessors, owned_enum_accessors};
3636-3734pub use engine::Engine;
3835pub use func::Func;
3936pub use global::Global;
···5047pub use values::Val;
5148#[cfg(test)]
5249pub use vm::{ConstExprEvaluator, PlaceholderAllocatorDontUse};
5050+5151+use crate::wasm::store::StoreOpaque;
5252+use crate::wasm::utils::{enum_accessors, owned_enum_accessors};
53535454/// The number of pages (for 32-bit modules) we can have before we run out of
5555/// byte index space.
+8-6
kernel/src/wasm/module.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use alloc::string::{String, ToString};
99+use alloc::sync::Arc;
1010+use core::mem;
1111+use core::ops::DerefMut;
1212+use core::ptr::NonNull;
1313+1414+use wasmparser::{Validator, WasmFeatures};
1515+816use crate::wasm::Engine;
917use crate::wasm::code_registry::{register_code, unregister_code};
1018use crate::wasm::compile::{CompileInputs, CompiledFunctionInfo};
···1321use crate::wasm::type_registry::RuntimeTypeCollection;
1422use crate::wasm::utils::u8_size_of;
1523use crate::wasm::vm::{CodeObject, MmapVec, VMArrayCallFunction, VMShape, VMWasmCallFunction};
1616-use alloc::string::{String, ToString};
1717-use alloc::sync::Arc;
1818-use core::mem;
1919-use core::ops::DerefMut;
2020-use core::ptr::NonNull;
2121-use wasmparser::{Validator, WasmFeatures};
22242325/// A compiled WebAssembly module, ready to be instantiated.
2426///
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use core::ptr::NonNull;
99+use core::sync::atomic::Ordering;
1010+1111+use anyhow::Context;
1212+use cranelift_entity::packed_option::ReservedValue;
1313+814use crate::wasm::indices::DefinedTableIndex;
915use crate::wasm::store::{StoreOpaque, Stored};
1016use crate::wasm::types::TableType;
1117use crate::wasm::values::Ref;
1218use crate::wasm::vm::{ExportedTable, InstanceAndStore, TableElement, VMTableImport, VmPtr};
1319use crate::wasm::{Func, vm};
1414-use anyhow::Context;
1515-use core::ptr::NonNull;
1616-use core::sync::atomic::Ordering;
1717-use cranelift_entity::packed_option::ReservedValue;
18201921#[derive(Clone, Copy, Debug)]
2022pub struct Table(Stored<ExportedTable>);
+2-1
kernel/src/wasm/translate/const_expr.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::wasm::indices::{FuncIndex, GlobalIndex, TypeIndex};
98use anyhow::bail;
109use smallvec::SmallVec;
1010+1111+use crate::wasm::indices::{FuncIndex, GlobalIndex, TypeIndex};
11121213/// A constant expression.
1314///
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::wasm::indices::{
99- CanonicalizedTypeIndex, DataIndex, ElemIndex, EntityIndex, FieldIndex, FuncIndex, FuncRefIndex,
1010- GlobalIndex, LabelIndex, LocalIndex, MemoryIndex, TableIndex, TagIndex, TypeIndex,
1111-};
1212-use crate::wasm::translate::module_types::{ModuleTypes, ModuleTypesBuilder};
1313-use crate::wasm::translate::type_convert::WasmparserTypeConverter;
1414-use crate::wasm::translate::types::EntityType;
1515-use crate::wasm::translate::{
1616- ConstExpr, Function, FunctionBodyData, Global, Import, Memory, MemoryInitializer,
1717- ModuleTranslation, ProducersLanguage, ProducersLanguageField, ProducersSdk, ProducersSdkField,
1818- ProducersTool, ProducersToolField, Table, TableInitialValue, TableSegment,
1919- TableSegmentElements, Tag,
2020-};
218use alloc::string::ToString;
229use alloc::sync::Arc;
2310use alloc::vec::Vec;
1111+2412use cranelift_entity::packed_option::ReservedValue;
2513use hashbrown::HashMap;
2614use wasmparser::{
···3018 NameSectionReader, Parser, Payload, ProducersFieldValue, ProducersSectionReader, TableInit,
3119 TableSectionReader, TagKind, TagSectionReader, TypeRef, TypeSectionReader, Validator,
3220 WasmFeatures,
2121+};
2222+2323+use crate::wasm::indices::{
2424+ CanonicalizedTypeIndex, DataIndex, ElemIndex, EntityIndex, FieldIndex, FuncIndex, FuncRefIndex,
2525+ GlobalIndex, LabelIndex, LocalIndex, MemoryIndex, TableIndex, TagIndex, TypeIndex,
2626+};
2727+use crate::wasm::translate::module_types::{ModuleTypes, ModuleTypesBuilder};
2828+use crate::wasm::translate::type_convert::WasmparserTypeConverter;
2929+use crate::wasm::translate::types::EntityType;
3030+use crate::wasm::translate::{
3131+ ConstExpr, Function, FunctionBodyData, Global, Import, Memory, MemoryInitializer,
3232+ ModuleTranslation, ProducersLanguage, ProducersLanguageField, ProducersSdk, ProducersSdkField,
3333+ ProducersTool, ProducersToolField, Table, TableInitialValue, TableSegment,
3434+ TableSegmentElements, Tag,
3335};
34363537/// A translator for converting the output of `wasmparser` into types used by this crate.
+8-6
kernel/src/wasm/translate/module_types.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::wasm::indices::{ModuleInternedRecGroupIndex, ModuleInternedTypeIndex};
99-use crate::wasm::translate::type_convert::WasmparserTypeConverter;
1010-use crate::wasm::translate::types::WasmSubType;
1111-use crate::wasm::translate::{
1212- TranslatedModule, WasmCompositeType, WasmCompositeTypeInner, WasmFuncType,
1313-};
148use alloc::borrow::Cow;
159use alloc::vec::Vec;
1610use core::fmt;
1711use core::range::Range;
1212+1813use cranelift_entity::packed_option::PackedOption;
1914use cranelift_entity::{EntityRef, PrimaryMap, SecondaryMap};
2015use hashbrown::HashMap;
2116use wasmparser::{Validator, ValidatorId};
1717+1818+use crate::wasm::indices::{ModuleInternedRecGroupIndex, ModuleInternedTypeIndex};
1919+use crate::wasm::translate::type_convert::WasmparserTypeConverter;
2020+use crate::wasm::translate::types::WasmSubType;
2121+use crate::wasm::translate::{
2222+ TranslatedModule, WasmCompositeType, WasmCompositeTypeInner, WasmFuncType,
2323+};
22242325/// Types defined within a single WebAssembly module.
2426#[derive(Debug, Default)]
+6-4
kernel/src/wasm/translate/type_convert.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use alloc::vec::Vec;
99+1010+use wasmparser::UnpackedIndex;
1111+812use crate::wasm::indices::{CanonicalizedTypeIndex, ModuleInternedTypeIndex, TypeIndex};
913use crate::wasm::translate::types::{
1014 WasmArrayType, WasmCompositeType, WasmCompositeTypeInner, WasmFieldType, WasmHeapType,
1115 WasmHeapTypeInner, WasmRefType, WasmStorageType, WasmStructType, WasmValType,
1216};
1317use crate::wasm::translate::{ModuleTypes, TranslatedModule, WasmFuncType, WasmSubType};
1414-use alloc::vec::Vec;
1515-use wasmparser::UnpackedIndex;
16181719/// A type that knows how to convert from `wasmparser` types to types in this crate.
1820pub struct WasmparserTypeConverter<'a> {
···4850 match ty {
4951 wasmparser::HeapType::Concrete(index) => self.lookup_heap_type(index),
5052 wasmparser::HeapType::Abstract { shared, ty } => {
5151- use crate::wasm::translate::types::WasmHeapTypeInner::*;
5252-5353 use wasmparser::AbstractHeapType;
5454+5555+ use crate::wasm::translate::types::WasmHeapTypeInner::*;
5456 let ty = match ty {
5557 AbstractHeapType::Func => Func,
5658 AbstractHeapType::Extern => Extern,
+4-3
kernel/src/wasm/translate/types.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use alloc::borrow::Cow;
99+use alloc::boxed::Box;
1010+use core::fmt;
1111+812use crate::wasm::indices::CanonicalizedTypeIndex;
913use crate::wasm::translate::{Global, Memory, Table};
1014use crate::wasm::type_registry::TypeTrace;
1115use crate::wasm::utils::enum_accessors;
1212-use alloc::borrow::Cow;
1313-use alloc::boxed::Box;
1414-use core::fmt;
15161617/// Represents the types of values in a WebAssembly module.
1718#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+1
kernel/src/wasm/trap.rs
···66// copied, modified, or distributed except according to those terms.
7788use core::fmt;
99+910use cranelift_codegen::ir::TrapCode;
10111112const TRAP_OFFSET: u8 = 1;
+8-6
kernel/src/wasm/trap_handler.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
99-use crate::mem::VirtualAddress;
1010-use crate::wasm::TrapKind;
1111-use crate::wasm::code_registry::lookup_code;
1212-use crate::wasm::store::StoreOpaque;
1313-use crate::wasm::vm::{VMContext, VMStoreContext};
148use alloc::boxed::Box;
159use alloc::vec;
1610use alloc::vec::Vec;
···2014use core::panic::AssertUnwindSafe;
2115use core::ptr::NonNull;
2216use core::{fmt, ptr};
1717+2318use cpu_local::cpu_local;
1919+2020+use crate::arch;
2121+use crate::mem::VirtualAddress;
2222+use crate::wasm::TrapKind;
2323+use crate::wasm::code_registry::lookup_code;
2424+use crate::wasm::store::StoreOpaque;
2525+use crate::wasm::vm::{VMContext, VMStoreContext};
24262527/// Description about a fault that occurred in WebAssembly.
2628#[derive(Debug)]
+9-7
kernel/src/wasm/type_registry.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::wasm::Engine;
99-use crate::wasm::indices::{
1010- CanonicalizedTypeIndex, ModuleInternedTypeIndex, RecGroupRelativeTypeIndex, VMSharedTypeIndex,
1111-};
1212-use crate::wasm::translate::{
1313- ModuleTypes, WasmCompositeType, WasmCompositeTypeInner, WasmRecGroup, WasmSubType,
1414-};
158use alloc::borrow::Cow;
169use alloc::boxed::Box;
1710use alloc::sync::Arc;
···2316use core::range::Range;
2417use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
2518use core::{fmt, iter};
1919+2620use cranelift_entity::packed_option::{PackedOption, ReservedValue};
2721use cranelift_entity::{PrimaryMap, SecondaryMap, iter_entity_range};
2822use hashbrown::HashSet;
2923use spin::RwLock;
3024use wasmtime_slab::Slab;
2525+2626+use crate::wasm::Engine;
2727+use crate::wasm::indices::{
2828+ CanonicalizedTypeIndex, ModuleInternedTypeIndex, RecGroupRelativeTypeIndex, VMSharedTypeIndex,
2929+};
3030+use crate::wasm::translate::{
3131+ ModuleTypes, WasmCompositeType, WasmCompositeTypeInner, WasmRecGroup, WasmSubType,
3232+};
31333234pub trait TypeTrace {
3335 /// Visit each edge.
+7-6
kernel/src/wasm/types.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use alloc::string::{String, ToString};
99+use alloc::vec::Vec;
1010+use core::fmt;
1111+use core::fmt::{Display, Write};
1212+1313+use anyhow::{bail, ensure};
1414+815use crate::wasm::Engine;
916use crate::wasm::indices::{CanonicalizedTypeIndex, VMSharedTypeIndex};
1017use crate::wasm::translate::{
···1320 WasmSubType, WasmValType,
1421};
1522use crate::wasm::type_registry::RegisteredType;
1616-use alloc::string::{String, ToString};
1717-use alloc::vec::Vec;
1818-use anyhow::{bail, ensure};
1919-use core::fmt;
2020-use core::fmt::Display;
2121-use core::fmt::Write;
22232324/// Indicator of whether a global value, struct's field, or array type's
2425/// elements are mutable or not.
+3-2
kernel/src/wasm/utils.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch::PAGE_SIZE;
99-use crate::wasm::translate::{WasmFuncType, WasmHeapTopType, WasmHeapType, WasmValType};
108use cranelift_codegen::ir;
119use cranelift_codegen::ir::{AbiParam, ArgumentPurpose, Signature};
1210use cranelift_codegen::isa::{CallConv, TargetIsa};
1111+1212+use crate::arch::PAGE_SIZE;
1313+use crate::wasm::translate::{WasmFuncType, WasmHeapTopType, WasmHeapType, WasmValType};
13141415/// Helper macro to generate accessors for an enum.
1516macro_rules! enum_accessors {
+4-2
kernel/src/wasm/values.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use core::ptr;
99+1010+use anyhow::bail;
1111+812use crate::wasm::Func;
913use crate::wasm::store::StoreOpaque;
1014use crate::wasm::types::{HeapType, HeapTypeInner, RefType, ValType};
1115use crate::wasm::utils::enum_accessors;
1216use crate::wasm::vm::{TableElement, VMVal};
1313-use anyhow::bail;
1414-use core::ptr;
15171618#[derive(Debug, Clone, Copy)]
1719pub enum Val {
+2-1
kernel/src/wasm/vm/builtins.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use core::ptr::NonNull;
99+810use crate::wasm::TrapKind;
911use crate::wasm::indices::{DataIndex, ElemIndex, MemoryIndex, TableIndex};
1012use crate::wasm::store::StoreOpaque;
···1214use crate::wasm::vm::instance::Instance;
1315use crate::wasm::vm::table::{TableElement, TableElementType};
1416use crate::wasm::vm::{Table, VMFuncRef};
1515-use core::ptr::NonNull;
16171718/// A helper structure to represent the return value of a memory or table growth
1819/// call.
+8-6
kernel/src/wasm/vm/code_object.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::mem::{AddressSpace, Mmap, VirtualAddress};
99-use crate::wasm::TrapKind;
1010-use crate::wasm::compile::{CompiledFunctionInfo, FunctionLoc};
1111-use crate::wasm::indices::{DefinedFuncIndex, ModuleInternedTypeIndex};
1212-use crate::wasm::vm::{MmapVec, VMWasmCallFunction};
138use alloc::vec;
149use alloc::vec::Vec;
1515-use anyhow::Context;
1610use core::ptr::NonNull;
1711use core::range::Range;
1812use core::slice;
1313+1414+use anyhow::Context;
1915use cranelift_entity::PrimaryMap;
1616+1717+use crate::mem::{AddressSpace, Mmap, VirtualAddress};
1818+use crate::wasm::TrapKind;
1919+use crate::wasm::compile::{CompiledFunctionInfo, FunctionLoc};
2020+use crate::wasm::indices::{DefinedFuncIndex, ModuleInternedTypeIndex};
2121+use crate::wasm::vm::{MmapVec, VMWasmCallFunction};
20222123#[derive(Debug)]
2224pub struct CodeObject {
+3-2
kernel/src/wasm/vm/const_eval.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use anyhow::bail;
99+use smallvec::SmallVec;
1010+811use crate::wasm::indices::{FuncIndex, GlobalIndex, VMSharedTypeIndex};
912use crate::wasm::store::StoreOpaque;
1013use crate::wasm::translate::{
···1316};
1417use crate::wasm::vm::instance::Instance;
1518use crate::wasm::vm::vmcontext::VMVal;
1616-use anyhow::bail;
1717-use smallvec::SmallVec;
18191920/// Simple interpreter for constant expressions.
2021#[derive(Debug, Default)]
+12-10
kernel/src/wasm/vm/instance.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use alloc::string::String;
99+use core::alloc::Layout;
1010+use core::marker::PhantomPinned;
1111+use core::ptr::NonNull;
1212+use core::sync::atomic::{AtomicU64, Ordering};
1313+use core::{fmt, ptr, slice};
1414+1515+use anyhow::{bail, ensure};
1616+use cranelift_entity::packed_option::ReservedValue;
1717+use cranelift_entity::{EntityRef, EntitySet, PrimaryMap};
1818+use static_assertions::const_assert_eq;
1919+820use crate::mem::VirtualAddress;
921use crate::wasm::TrapKind;
1022use crate::wasm::indices::{
···3042 VMOpaqueContext, VMShape, VMStoreContext, VMTableDefinition, VMTableImport, VMTagDefinition,
3143 VMTagImport,
3244};
3333-use alloc::string::String;
3434-use anyhow::{bail, ensure};
3535-use core::alloc::Layout;
3636-use core::marker::PhantomPinned;
3737-use core::ptr::NonNull;
3838-use core::sync::atomic::{AtomicU64, Ordering};
3939-use core::{fmt, ptr, slice};
4040-use cranelift_entity::packed_option::ReservedValue;
4141-use cranelift_entity::{EntityRef, EntitySet, PrimaryMap};
4242-use static_assertions::const_assert_eq;
43454446#[derive(Debug)]
4547pub struct InstanceHandle {
+8-6
kernel/src/wasm/vm/instance_alloc.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use core::alloc::Allocator;
99+use core::ops::DerefMut;
1010+use core::ptr::NonNull;
1111+use core::{cmp, mem};
1212+1313+use anyhow::Context;
1414+use cranelift_entity::PrimaryMap;
1515+816use crate::mem::Mmap;
917use crate::wasm::indices::{DefinedMemoryIndex, DefinedTableIndex};
1018use crate::wasm::module::Module;
···1422use crate::wasm::vm::mmap_vec::MmapVec;
1523use crate::wasm::vm::{InstanceHandle, TableElement, VMShape};
1624use crate::wasm::{MEMORY_MAX, TABLE_MAX, translate, vm};
1717-use anyhow::Context;
1818-use core::alloc::Allocator;
1919-use core::ops::DerefMut;
2020-use core::ptr::NonNull;
2121-use core::{cmp, mem};
2222-use cranelift_entity::PrimaryMap;
23252426/// A type that knows how to allocate backing memory for instance resources.
2527pub trait InstanceAllocator {
+3-2
kernel/src/wasm/vm/memory.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use core::ptr::NonNull;
99+use core::range::Range;
1010+811use crate::mem::{Mmap, VirtualAddress};
912use crate::wasm::vm::VMMemoryDefinition;
1013use crate::wasm::vm::provenance::VmPtr;
1111-use core::ptr::NonNull;
1212-use core::range::Range;
13141415#[derive(Debug)]
1516pub struct Memory {
+5-3
kernel/src/wasm/vm/mmap_vec.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
99-use crate::mem::{AddressSpace, Mmap};
108use alloc::sync::Arc;
1111-use anyhow::Context;
129use core::cmp::max;
1310use core::marker::PhantomData;
1411use core::ops::Deref;
1512use core::range::Range;
1613use core::slice;
1414+1515+use anyhow::Context;
1716use spin::Mutex;
1717+1818+use crate::arch;
1919+use crate::mem::{AddressSpace, Mmap};
18201921#[derive(Debug)]
2022pub struct MmapVec<T> {
+4-3
kernel/src/wasm/vm/mod.rs
···2020use alloc::vec::Vec;
2121use core::ptr::NonNull;
22222323-use crate::wasm::indices::DefinedMemoryIndex;
2424-use crate::wasm::translate;
2525-use crate::wasm::translate::TranslatedModule;
2623pub use code_object::CodeObject;
2724pub use const_eval::ConstExprEvaluator;
2825pub use instance::{Instance, InstanceAndStore, InstanceHandle};
···3532pub use table::{Table, TableElement};
3633pub use vmcontext::*;
3734pub use vmshape::{StaticVMShape, VMShape};
3535+3636+use crate::wasm::indices::DefinedMemoryIndex;
3737+use crate::wasm::translate;
3838+use crate::wasm::translate::TranslatedModule;
38393940/// The value of an export passed from one instance to another.
4041#[derive(Debug, Clone)]
+2-1
kernel/src/wasm/vm/provenance.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::wasm::indices::VMSharedTypeIndex;
98use core::fmt;
109use core::marker::PhantomData;
1110use core::num::NonZeroUsize;
1211use core::ptr::NonNull;
1312use core::sync::atomic::AtomicUsize;
1313+1414+use crate::wasm::indices::VMSharedTypeIndex;
14151516/// A pointer that is used by compiled code, or in other words is accessed
1617/// outside of Rust.
+6-4
kernel/src/wasm/vm/table.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use core::ptr;
99+use core::ptr::NonNull;
1010+use core::range::Range;
1111+1212+use anyhow::anyhow;
1313+814use crate::wasm::TrapKind;
915use crate::wasm::vm::mmap_vec::MmapVec;
1016use crate::wasm::vm::provenance::VmPtr;
1117use crate::wasm::vm::{VMFuncRef, VMTableDefinition};
1212-use anyhow::anyhow;
1313-use core::ptr;
1414-use core::ptr::NonNull;
1515-use core::range::Range;
16181719#[derive(Debug, Clone, Copy)]
1820pub enum TableElement {
+10-8
kernel/src/wasm/vm/vmcontext.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::mem::VirtualAddress;
99-use crate::wasm::builtins::{BuiltinFunctionIndex, foreach_builtin_function};
1010-use crate::wasm::indices::{DefinedMemoryIndex, VMSharedTypeIndex};
1111-use crate::wasm::store::StoreOpaque;
1212-use crate::wasm::translate::{WasmHeapTopType, WasmValType};
1313-use crate::wasm::type_registry::RegisteredType;
1414-use crate::wasm::types::FuncType;
1515-use crate::wasm::vm::provenance::{VmPtr, VmSafe};
168use alloc::boxed::Box;
179use core::any::Any;
1810use core::cell::UnsafeCell;
···2214use core::ptr::NonNull;
2315use core::sync::atomic::{AtomicUsize, Ordering};
2416use core::{fmt, ptr};
1717+2518use cranelift_entity::Unsigned;
2619use static_assertions::const_assert_eq;
2020+2121+use crate::mem::VirtualAddress;
2222+use crate::wasm::builtins::{BuiltinFunctionIndex, foreach_builtin_function};
2323+use crate::wasm::indices::{DefinedMemoryIndex, VMSharedTypeIndex};
2424+use crate::wasm::store::StoreOpaque;
2525+use crate::wasm::translate::{WasmHeapTopType, WasmValType};
2626+use crate::wasm::type_registry::RegisteredType;
2727+use crate::wasm::types::FuncType;
2828+use crate::wasm::vm::provenance::{VmPtr, VmSafe};
27292830/// Magic value for core Wasm VM contexts.
2931///
+5-3
libs/cpu-local/src/collection.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::cpu_local;
98use alloc::boxed::Box;
109use core::cell::UnsafeCell;
1110use core::iter::FusedIterator;
1211use core::panic::UnwindSafe;
1312use core::sync::atomic::{AtomicBool, AtomicPtr, AtomicUsize, Ordering};
1413use core::{fmt, mem, ptr, slice};
1414+1515use util::CheckedMaybeUninit;
1616+1717+use crate::cpu_local;
16181719/// The total number of buckets stored in each cpu-local storage.
1820/// All buckets combined can hold up to `usize::MAX - 1` entries.
···568570569571#[cfg(test)]
570572mod tests {
571571- use super::*;
572573 use alloc::string::String;
573573-574574 use alloc::sync::Arc;
575575 use core::cell::RefCell;
576576 use core::sync::atomic::AtomicUsize;
577577 use core::sync::atomic::Ordering::Relaxed;
578578 use std::thread;
579579+580580+ use super::*;
579581580582 fn make_create() -> Arc<dyn Fn() -> usize + Send + Sync> {
581583 let count = AtomicUsize::new(0);
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::{Error, Function, InlinedFunction, ResUnit, maybe_small};
98use core::iter;
99+1010use fallible_iterator::FallibleIterator;
1111+1212+use crate::{Error, Function, InlinedFunction, ResUnit, maybe_small};
11131214/// A source location.
1315pub struct Location<'a> {
+7-5
libs/kaddr2line/src/unit.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::{
99- Context, DebugFile, Error, Function, LazyFunctions, LazyLines, LazyResult,
1010- LineLocationRangeIter, Lines, Location, LookupContinuation, LookupResult, RangeAttributes,
1111- SimpleLookup, SplitDwarfLoad,
1212-};
138use alloc::boxed::Box;
149use alloc::sync::Arc;
1510use alloc::vec::Vec;
1611use core::cmp;
1212+1713use fallible_iterator::FallibleIterator;
1414+1515+use crate::{
1616+ Context, DebugFile, Error, Function, LazyFunctions, LazyLines, LazyResult,
1717+ LineLocationRangeIter, Lines, Location, LookupContinuation, LookupResult, RangeAttributes,
1818+ SimpleLookup, SplitDwarfLoad,
1919+};
18201921pub(crate) struct UnitRange {
2022 unit_id: usize,
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::executor::Scheduler;
99-use crate::loom::sync::atomic::{AtomicUsize, Ordering};
1010-use crate::task::{Header, Task, TaskRef};
118use alloc::boxed::Box;
1212-use cordyceps::{MpscQueue, mpsc_queue};
139use core::fmt::Debug;
1410use core::num::NonZeroUsize;
1111+1212+use cordyceps::{MpscQueue, mpsc_queue};
1313+1414+use crate::executor::Scheduler;
1515+use crate::loom::sync::atomic::{AtomicUsize, Ordering};
1616+use crate::task::{Header, Task, TaskRef};
15171618#[derive(Debug, Clone, Eq, PartialEq)]
1719#[non_exhaustive]
+3-2
libs/kasync/src/sync/oneshot.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::loom::cell::UnsafeCell;
99-use crate::sync::WaitCell;
108use alloc::sync::Arc;
119use core::fmt;
1210use core::pin::Pin;
1311use core::task::{Context, Poll, ready};
1212+1313+use crate::loom::cell::UnsafeCell;
1414+use crate::sync::WaitCell;
14151516pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
1617 let inner = Arc::new(Inner {
+6-4
libs/kasync/src/sync/wait_cell.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::error::Closed;
99-use crate::loom::cell::UnsafeCell;
1010-use crate::loom::sync::atomic::{AtomicUsize, Ordering};
1111-use bitflags::bitflags;
128use core::panic::{RefUnwindSafe, UnwindSafe};
139use core::pin::Pin;
1410use core::task::{Context, Poll, Waker};
1511use core::{fmt, task};
1212+1313+use bitflags::bitflags;
1614use static_assertions::const_assert_eq;
1715use util::{CachePadded, loom_const_fn};
1616+1717+use crate::error::Closed;
1818+use crate::loom::cell::UnsafeCell;
1919+use crate::loom::sync::atomic::{AtomicUsize, Ordering};
18201921/// An atomically registered [`Waker`].
2022///
+5-3
libs/kasync/src/sync/wait_queue.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::error::Closed;
99-use crate::sync::wake_batch::WakeBatch;
108use alloc::sync::Arc;
1111-use cordyceps::{Linked, List, list};
129use core::cell::UnsafeCell;
1310use core::marker::PhantomPinned;
1411use core::pin::Pin;
···1613use core::sync::atomic::{AtomicUsize, Ordering};
1714use core::task::{Context, Poll, Waker};
1815use core::{fmt, mem, ptr};
1616+1717+use cordyceps::{Linked, List, list};
1918use mycelium_bitfield::{FromBits, bitfield, enum_from_bits};
2019use pin_project::{pin_project, pinned_drop};
2120use spin::{Mutex, MutexGuard};
2221use util::{CachePadded, loom_const_fn};
2222+2323+use crate::error::Closed;
2424+use crate::sync::wake_batch::WakeBatch;
23252426/// A queue of waiting tasks which can be [woken in first-in, first-out
2527/// order][wake], or [all at once][wake_all].
+2-1
libs/kasync/src/sync/wake_batch.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use core::task::Waker;
99+810use arrayvec::ArrayVec;
99-use core::task::Waker;
10111112const NUM_WAKERS: usize = 32;
1213
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::error::Closed;
99-use crate::error::SpawnError;
1010-use crate::task::id::Id;
1111-use crate::task::join_handle::JoinHandle;
1212-use crate::task::{Task, TaskRef};
138use alloc::boxed::Box;
149use core::alloc::Allocator;
1510use core::any::type_name;
1611use core::panic::Location;
1212+1313+use crate::error::{Closed, SpawnError};
1414+use crate::task::id::Id;
1515+use crate::task::join_handle::JoinHandle;
1616+use crate::task::{Task, TaskRef};
17171818pub struct TaskBuilder<'a, S> {
1919 location: Option<Location<'a>>,
+2-1
libs/kasync/src/task/id.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use core::fmt;
99+810use crate::loom::sync::atomic::{AtomicU64, Ordering};
99-use core::fmt;
10111112/// An opaque ID that uniquely identifies a task relative to all other currently
1213/// running tasks.
+2-2
libs/kasync/src/task/join_handle.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::task::Id;
99-use crate::task::TaskRef;
108use alloc::boxed::Box;
119use alloc::string::String;
1210use core::any::Any;
···1715use core::panic::{RefUnwindSafe, UnwindSafe};
1816use core::pin::Pin;
1917use core::task::{Context, Poll};
1818+1919+use crate::task::{Id, TaskRef};
20202121pub struct JoinHandle<T> {
2222 state: JoinHandleState,
+4-2
libs/kasync/src/task/state.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::loom::sync::atomic::{self, AtomicUsize, Ordering};
99-use crate::task::PollResult;
108use core::fmt;
99+1110use spin::Backoff;
1211use util::loom_const_fn;
1212+1313+use crate::loom::sync::atomic::{self, AtomicUsize, Ordering};
1414+use crate::task::PollResult;
13151416/// Task state. The task stores its state in an atomic `usize` with various bitfields for the
1517/// necessary information. The state has the following layout:
+3-2
libs/kasync/src/test_util.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::loom::sync::Arc;
99-use crate::loom::sync::{Condvar, Mutex as StdMutex};
108use core::mem::ManuallyDrop;
119use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
1010+1211use futures::pin_mut;
1312use futures::task::WakerRef;
1413use util::loom_const_fn;
1414+1515+use crate::loom::sync::{Arc, Condvar, Mutex as StdMutex};
15161617#[derive(Debug)]
1718pub struct ThreadNotify {
+2-1
libs/kasync/src/time.rs
···1313mod timeout;
1414mod timer;
15151616-use core::{fmt, time::Duration};
1616+use core::fmt;
1717+use core::time::Duration;
17181819pub use clock::{Clock, RawClock, RawClockVTable};
1920pub use instant::Instant;
+2-1
libs/kasync/src/time/clock.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::time::max_duration;
98use core::fmt;
109use core::time::Duration;
1010+1111+use crate::time::max_duration;
11121213pub struct Clock {
1314 name: &'static str,
+2-1
libs/kasync/src/time/instant.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::time::{NANOS_PER_SEC, Ticks, TimeError, Timer};
98use core::fmt;
109use core::ops::{Add, AddAssign, Sub, SubAssign};
1110use core::time::Duration;
1111+1212+use crate::time::{NANOS_PER_SEC, Ticks, TimeError, Timer};
12131314/// A measurement of a monotonically nondecreasing clock.
1415#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
+16-16
libs/kasync/src/time/sleep.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use core::fmt;
99+use core::pin::Pin;
1010+use core::task::{Context, Poll, ready};
1111+use core::time::Duration;
1212+1313+use pin_project::{pin_project, pinned_drop};
1414+815use crate::loom::sync::atomic::Ordering;
99-use crate::time::Ticks;
1010-use crate::time::{TimeError, Timer, instant::Instant, timer::Entry};
1111-use core::{
1212- fmt,
1313- pin::Pin,
1414- task::{Context, Poll, ready},
1515- time::Duration,
1616-};
1717-use pin_project::{pin_project, pinned_drop};
1616+use crate::time::instant::Instant;
1717+use crate::time::timer::Entry;
1818+use crate::time::{Ticks, TimeError, Timer};
18191920/// Wait until duration has elapsed.
2021///
···139140140141#[cfg(test)]
141142mod tests {
143143+ use fastrand::FastRand;
144144+ use tracing_subscriber::EnvFilter;
145145+ use tracing_subscriber::fmt::format::FmtSpan;
146146+142147 use super::*;
148148+ use crate::executor::{Executor, Worker};
149149+ use crate::loom;
143150 use crate::loom::sync::atomic::{AtomicBool, Ordering};
144151 use crate::time::test_util::MockClock;
145145- use crate::{
146146- executor::{Executor, Worker},
147147- loom,
148148- };
149149- use fastrand::FastRand;
150150- use tracing_subscriber::EnvFilter;
151151- use tracing_subscriber::fmt::format::FmtSpan;
152152153153 // loom is not happy about this test. For whatever reason it triggers the "too many branches"
154154 // error. But both the regular test AND miri are fine with it
+3-3
libs/kasync/src/time/test_util.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::loom::sync::Arc;
99-use crate::loom::sync::Mutex as StdMutex;
1010-use crate::time::{Clock, RawClock, RawClockVTable};
118use core::ptr::NonNull;
129use core::time::Duration;
1310use std::time::Instant as StdInstant;
1111+1212+use crate::loom::sync::{Arc, Mutex as StdMutex};
1313+use crate::time::{Clock, RawClock, RawClockVTable};
14141515pub struct MockClock {
1616 time_anchor: StdInstant,
+7-10
libs/kasync/src/time/timeout.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use core::pin::Pin;
99+use core::task::{Context, Poll};
1010+use core::time::Duration;
1111+812use pin_project::pin_project;
9131010-use crate::time::{
1111- TimeError, Timer,
1212- instant::Instant,
1313- sleep::{Sleep, sleep, sleep_until},
1414-};
1515-use core::{
1616- pin::Pin,
1717- task::{Context, Poll},
1818- time::Duration,
1919-};
1414+use crate::time::instant::Instant;
1515+use crate::time::sleep::{Sleep, sleep, sleep_until};
1616+use crate::time::{TimeError, Timer};
20172118/// Requires a `Future` to complete before the specified duration has elapsed.
2219///
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::sync::wait_cell::WaitCell;
99-use crate::time::Ticks;
1010-use cordyceps::{Linked, list};
118use core::marker::PhantomPinned;
129use core::mem::offset_of;
1310use core::ptr::NonNull;
1411use core::sync::atomic::{AtomicBool, Ordering};
1212+1313+use cordyceps::{Linked, list};
1514use pin_project::pin_project;
1615use util::loom_const_fn;
1616+1717+use crate::sync::wait_cell::WaitCell;
1818+use crate::time::Ticks;
17191820/// An entry in a timing [`Wheel`][crate::time::timer::Wheel].
1921#[pin_project]
+6-4
libs/kasync/src/time/timer/wheel.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::time::Ticks;
99-use crate::time::timer::entry::Entry;
1010-use crate::time::timer::{Core, Deadline};
1111-use cordyceps::List;
128use core::pin::Pin;
139use core::ptr::NonNull;
1410use core::sync::atomic::Ordering;
1111+1212+use cordyceps::List;
1313+1414+use crate::time::Ticks;
1515+use crate::time::timer::entry::Entry;
1616+use crate::time::timer::{Core, Deadline};
15171618#[derive(Debug)]
1719pub(crate) struct Wheel {
···220220mod shard;
221221mod tid;
222222223223-pub use self::{
224224- cfg::{Config, DefaultConfig},
225225- clear::Clear,
226226- iter::UniqueIter,
227227-};
223223+use alloc::sync::Arc;
224224+use core::marker::PhantomData;
225225+use core::{fmt, ptr};
226226+227227+use cfg::CfgPrivate;
228228#[doc(inline)]
229229pub use pool::Pool;
230230-230230+use shard::Shard;
231231pub(crate) use tid::Tid;
232232233233-use alloc::sync::Arc;
234234-use cfg::CfgPrivate;
235235-use core::{fmt, marker::PhantomData, ptr};
236236-use shard::Shard;
233233+pub use self::cfg::{Config, DefaultConfig};
234234+pub use self::clear::Clear;
235235+pub use self::iter::UniqueIter;
237236238237/// A sharded slab.
239238///
+7-4
libs/ksharded-slab/src/page/mod.rs
···11+use alloc::boxed::Box;
22+use alloc::vec::Vec;
33+14use crate::Pack;
25use crate::cfg::{self, CfgPrivate};
36use crate::clear::Clear;
44-use alloc::boxed::Box;
55-use alloc::vec::Vec;
6778pub(crate) mod slot;
89mod stack;
9101111+use core::cell::UnsafeCell;
1212+use core::fmt;
1313+use core::marker::PhantomData;
1414+1015pub(crate) use self::slot::Slot;
1111-use core::cell::UnsafeCell;
1212-use core::{fmt, marker::PhantomData};
13161417/// A page address encodes the location of a slot within a shard (the page
1518/// number and offset within that page) as a single linear value.
···1919mod hook;
2020mod panic_count;
21212222-use crate::hook::{HOOK, Hook, PanicHookInfo, default_hook};
2323-use crate::panic_count::MustAbort;
2424-use abort::abort;
2522use alloc::boxed::Box;
2623use alloc::string::String;
2724use core::any::Any;
2825use core::panic::{PanicPayload, UnwindSafe};
2926use core::{fmt, mem};
2727+2828+use abort::abort;
3029pub use hook::{set_hook, take_hook};
3030+3131+use crate::hook::{HOOK, Hook, PanicHookInfo, default_hook};
3232+use crate::panic_count::MustAbort;
31333234/// Determines whether the current thread is unwinding because of panic.
3335#[inline]
+3-4
libs/panic-unwind2/src/panic_count.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use core::{
99- cell::Cell,
1010- sync::atomic::{AtomicUsize, Ordering},
1111-};
88+use core::cell::Cell;
99+use core::sync::atomic::{AtomicUsize, Ordering};
1010+1211use cpu_local::cpu_local;
13121413/// A reason for forcing an immediate abort on panic.
···2020pub mod trap;
21212222use core::arch::asm;
2323+2324pub use error::Error;
2425pub use register::*;
2526pub type Result<T> = core::result::Result<T, Error>;
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::Mutex;
98use core::hint;
99+1010use util::loom_const_fn;
1111+1212+use crate::Mutex;
11131214pub struct Barrier {
1315 lock: Mutex<BarrierState>,
···69717072#[cfg(test)]
7173mod tests {
7272- use super::*;
7373- use crate::loom::Arc;
7474- use crate::loom::thread;
7574 use std::sync::mpsc::{TryRecvError, channel};
7575+7676+ use super::*;
7777+ use crate::loom::{Arc, thread};
76787779 #[test]
7880 fn test_barrier() {
+12-12
libs/spin/src/lazy_lock.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use super::{Once, once::ExclusiveState};
99-use crate::loom::UnsafeCell;
1010-use core::{
1111- fmt,
1212- mem::ManuallyDrop,
1313- ops::Deref,
1414- panic::{RefUnwindSafe, UnwindSafe},
1515- ptr,
1616-};
88+use core::mem::ManuallyDrop;
99+use core::ops::Deref;
1010+use core::panic::{RefUnwindSafe, UnwindSafe};
1111+use core::{fmt, ptr};
1212+1713use util::loom_const_fn;
1414+1515+use super::Once;
1616+use super::once::ExclusiveState;
1717+use crate::loom::UnsafeCell;
18181919union Data<T, F> {
2020 value: ManuallyDrop<T>,
···167167168168#[cfg(test)]
169169mod tests {
170170+ use std::cell::LazyCell;
171171+170172 use super::*;
171171- use crate::loom::thread;
172172- use crate::loom::{AtomicUsize, Ordering};
173173+ use crate::loom::{AtomicUsize, Ordering, thread};
173174 use crate::{Mutex, OnceLock};
174174- use std::cell::LazyCell;
175175176176 fn spawn_and_wait<R: Send + 'static>(f: impl FnOnce() -> R + Send + 'static) -> R {
177177 thread::spawn(f).join().unwrap()
+7-6
libs/spin/src/mutex.rs
···1414// ArcMutexGuardarc_lock
1515// An RAII mutex guard returned by the Arc locking operations on Mutex.
16161717-use crate::backoff::Backoff;
1818-use crate::loom::Ordering;
1919-use crate::loom::{AtomicBool, UnsafeCell};
2017use core::marker::PhantomData;
2118use core::ops::{Deref, DerefMut};
2219use core::{fmt, mem};
2020+2321use util::loom_const_fn;
2222+2323+use crate::backoff::Backoff;
2424+use crate::loom::{AtomicBool, Ordering, UnsafeCell};
24252526/// A mutual exclusion primitive useful for protecting shared data
2627///
···335336336337#[cfg(test)]
337338mod tests {
338338- use super::*;
339339- use crate::loom::Arc;
340340- use crate::loom::AtomicUsize;
341339 use core::fmt::Debug;
342340 use std::{hint, mem};
341341+342342+ use super::*;
343343+ use crate::loom::{Arc, AtomicUsize};
343344344345 #[derive(Eq, PartialEq, Debug)]
345346 struct NonCopy(i32);
+5-2
libs/spin/src/once.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::loom::{AtomicU8, Ordering};
98use core::mem;
99+1010use util::loom_const_fn;
1111+1212+use crate::loom::{AtomicU8, Ordering};
11131214/// No initialization has run yet, and no thread is currently using the Once.
1315const STATUS_INCOMPLETE: u8 = 0;
···148150149151#[cfg(test)]
150152mod tests {
153153+ use std::sync::mpsc::channel;
154154+151155 use super::*;
152156 use crate::loom::thread;
153153- use std::sync::mpsc::channel;
154157155158 #[test]
156159 fn smoke_once() {
+9-9
libs/spin/src/once_lock.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use core::fmt;
99+use core::mem::MaybeUninit;
1010+use core::panic::{RefUnwindSafe, UnwindSafe};
1111+1212+use util::loom_const_fn;
1313+814use super::Once;
915use crate::loom::UnsafeCell;
1010-use core::{
1111- fmt,
1212- mem::MaybeUninit,
1313- panic::{RefUnwindSafe, UnwindSafe},
1414-};
1515-use util::loom_const_fn;
16161717/// A synchronization primitive which can be written to only once.
1818///
···316316317317#[cfg(test)]
318318mod tests {
319319- use super::*;
320320- use crate::loom::thread;
321321- use crate::loom::{AtomicUsize, Ordering};
322319 use std::sync::mpsc::channel;
320320+321321+ use super::*;
322322+ use crate::loom::{AtomicUsize, Ordering, thread};
323323324324 fn spawn_and_wait<R: Send + 'static>(f: impl FnOnce() -> R + Send + 'static) -> R {
325325 thread::spawn(f).join().unwrap()
+4-3
libs/spin/src/remutex.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::loom::AtomicUsize;
99-use crate::loom::{Ordering, UnsafeCell};
1010-use crate::{Backoff, GuardNoSend};
118use core::cell::Cell;
129use core::fmt;
1310use core::marker::PhantomData;
···1512use core::ops::Deref;
1613use core::ptr::addr_of;
1714use core::sync::atomic::AtomicBool;
1515+1816use util::loom_const_fn;
1717+1818+use crate::loom::{AtomicUsize, Ordering, UnsafeCell};
1919+use crate::{Backoff, GuardNoSend};
19202021/// A mutex which can be recursively locked by a single thread.
2122///
+7-5
libs/spin/src/rw_lock.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::Backoff;
99-use crate::loom::{AtomicUsize, Ordering, UnsafeCell};
108use core::ops::{Deref, DerefMut};
119use core::ptr::NonNull;
1210use core::{fmt, mem};
1111+1312use util::loom_const_fn;
1313+1414+use crate::Backoff;
1515+use crate::loom::{AtomicUsize, Ordering, UnsafeCell};
14161517const READER: usize = 1 << 2;
1618const UPGRADED: usize = 1 << 1;
···621623622624#[cfg(test)]
623625mod tests {
624624- use super::*;
625625- use crate::loom::Arc;
626626- use crate::loom::thread;
627626 use core::fmt::Debug;
628627 use core::mem;
629628 use std::hint;
630629 use std::sync::mpsc::channel;
630630+631631+ use super::*;
632632+ use crate::loom::{Arc, thread};
631633632634 #[derive(Eq, PartialEq, Debug)]
633635 struct NonCopy(i32);
···66// copied, modified, or distributed except according to those terms.
7788//! RISC-V specific unwinding code, mostly saving and restoring registers.
99-use cfg_if::cfg_if;
109use core::arch::{asm, naked_asm};
1111-use core::fmt;
1212-use core::ops;
1010+use core::{fmt, ops};
1111+1212+use cfg_if::cfg_if;
1313use gimli::{Register, RiscV};
14141515// Match DWARF_FRAME_REGISTERS in libgcc
+2-1
libs/unwind2/src/eh_action.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use gimli::{EndianSlice, NativeEndian, Pointer, Reader, constants};
99+810use crate::frame::Frame;
911use crate::utils::deref_pointer;
1010-use gimli::{EndianSlice, NativeEndian, Pointer, Reader, constants};
11121213#[derive(Debug)]
1314pub enum EHAction {
+2-1
libs/unwind2/src/eh_info.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use super::utils::{deref_pointer, get_unlimited_slice};
98use gimli::{BaseAddresses, EhFrame, EhFrameHdr, EndianSlice, NativeEndian, ParsedEhFrameHdr};
109use spin::LazyLock;
1010+1111+use super::utils::{deref_pointer, get_unlimited_slice};
11121213// Below is a fun hack: We need a reference to the `.eh_frame` and `.eh_frame_hdr` sections and
1314// must therefore force the linker to retain those even in release builds. By abusing mutable statics
+4-2
libs/unwind2/src/exception.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::Error;
99-use abort::abort;
108use alloc::boxed::Box;
119use core::any::Any;
1210use core::ffi::c_int;
1311use core::ptr;
1212+1313+use abort::abort;
1414+1515+use crate::Error;
14161517/// The C ABI UnwindReasonCode passed to the exception cleanup function when a foreign
1618/// (i.e. not originating from this crate) exception is caught. Since that exception might have
+4-3
libs/unwind2/src/frame.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
99-use crate::eh_info::obtain_eh_info;
1010-use crate::utils::{StoreOnStack, deref_pointer, get_unlimited_slice, with_context};
118use fallible_iterator::FallibleIterator;
129use gimli::{
1310 CfaRule, EhFrame, EndianSlice, EvaluationResult, FrameDescriptionEntry, NativeEndian, Register,
1411 RegisterRule, UnwindExpression, UnwindSection, UnwindTableRow, Value,
1512};
1313+1414+use crate::arch;
1515+use crate::eh_info::obtain_eh_info;
1616+use crate::utils::{StoreOnStack, deref_pointer, get_unlimited_slice, with_context};
16171718/// A frame in a stack.
1819///
+2-1
libs/unwind2/src/lang_items.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use abort::abort;
99+810use crate::exception::Exception;
911use crate::utils::with_context;
1012use crate::{Error, FrameIter, arch, raise_exception_phase2};
1111-use abort::abort;
12131314/// In traditional unwinders the personality routine is responsible for determining the unwinders
1415/// behaviour for each frame (stop unwinding because a handler has been found, continue etc.)
+5-4
libs/unwind2/src/lib.rs
···2121mod lang_items;
2222mod utils;
23232424-use abort::abort;
2524use alloc::boxed::Box;
2625use core::any::Any;
2726use core::intrinsics;
2827use core::mem::ManuallyDrop;
2928use core::panic::UnwindSafe;
3029use core::ptr::addr_of_mut;
3030+3131+use abort::abort;
3232+pub use arch::Registers;
3133use eh_action::{EHAction, find_eh_action};
3234pub use eh_info::EhInfo;
3335pub use error::Error;
···3638pub use frame::{Frame, FrameIter};
3739use lang_items::ensure_personality_stub;
3840pub use utils::with_context;
3939-4040-pub use arch::Registers;
41414242pub(crate) type Result<T> = core::result::Result<T, Error>;
4343···228228229229#[cfg(test)]
230230mod tests {
231231+ use alloc::boxed::Box;
232232+231233 use super::*;
232232- use alloc::boxed::Box;
233234234235 #[test]
235236 fn begin_and_catch_roundtrip() {
+3-1
libs/unwind2/src/utils.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
98use core::ptr;
99+1010use gimli::{Pointer, Register, RegisterRule, UnwindTableRow};
1111+1212+use crate::arch;
11131214pub struct StoreOnStack;
1315
+2-1
libs/util/src/checked_maybe_uninit.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use core::{fmt, mem::MaybeUninit};
88+use core::fmt;
99+use core::mem::MaybeUninit;
9101011/// A checked version of [`MaybeUninit`]. This type is taken from mycelium.
1112///
+5-4
libs/wast/src/error.rs
···11-use crate::lexer::LexError;
22-use crate::token::Span;
31use alloc::boxed::Box;
44-use alloc::string::String;
55-use alloc::string::ToString;
22+use alloc::string::{String, ToString};
63use core::fmt;
44+75use unicode_width::UnicodeWidthStr;
66+77+use crate::lexer::LexError;
88+use crate::token::Span;
89910/// A convenience error type to tie together all the detailed errors produced by
1011/// this crate.
···6262//! This module is heavily inspired by [`syn`](https://docs.rs/syn) so you can
6363//! likely also draw inspiration from the excellent examples in the `syn` crate.
64646565-use crate::Error;
6666-use crate::lexer::{Float, Integer, Lexer, Token, TokenKind};
6767-use crate::token::Span;
6865use alloc::borrow::Cow;
6966use alloc::boxed::Box;
7067use alloc::format;
7171-use alloc::string::String;
7272-use alloc::string::ToString;
6868+use alloc::string::{String, ToString};
7369use alloc::vec::Vec;
7474-use bumpalo::Bump;
7570use core::cell::{Cell, RefCell};
7671use core::fmt;
7272+7373+use bumpalo::Bump;
7774use hashbrown::HashMap;
7575+7676+use crate::Error;
7777+use crate::lexer::{Float, Integer, Lexer, Token, TokenKind};
7878+use crate::token::Span;
78797980/// The maximum recursive depth of parens to parse.
8081///
+4-5
libs/wast/src/token.rs
···22//! associated specifically with the wasm text format per se (useful in other
33//! contexts too perhaps).
4455+use alloc::string::{String, ToString};
66+use core::hash::{Hash, Hasher};
77+use core::{fmt, str};
88+59use crate::annotation;
610use crate::lexer::Float;
711use crate::parser::{Cursor, Parse, Parser, Peek, Result};
88-use alloc::string::String;
99-use alloc::string::ToString;
1010-use core::fmt;
1111-use core::hash::{Hash, Hasher};
1212-use core::str;
13121413/// A position in the original source stream, used to render errors.
1514#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)]
+2-1
libs/wast/tests/parse-fail.rs
···44//! Use `BLESS=1` in the environment to auto-update `*.err` files. Be sure to
55//! look at the diff!
6677-use libtest_mimic::{Arguments, Trial};
87use std::env;
98use std::path::{Path, PathBuf};
99+1010+use libtest_mimic::{Arguments, Trial};
10111112fn main() {
1213 let mut tests = Vec::new();
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use core::pin::Pin;
99+810use crate::{Link, Linked, WAVLTree, utils};
99-use core::pin::Pin;
10111112/// A cursor which provides read-only access to a [`WAVLTree`].
1213pub struct Cursor<'a, T>
+3-3
libs/wavltree/src/dot.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::Linked;
99-use crate::WAVLTree;
1010-use crate::utils::Side;
118use core::fmt;
129use core::ptr::NonNull;
1010+1111+use crate::utils::Side;
1212+use crate::{Linked, WAVLTree};
13131414pub struct Dot<'a, T>
1515where
+3-2
libs/wavltree/src/entry.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use core::pin::Pin;
99+use core::ptr::NonNull;
1010+811use crate::utils::Side;
912use crate::{Link, Linked, WAVLTree, utils};
1010-use core::pin::Pin;
1111-use core::ptr::NonNull;
12131314pub enum Entry<'a, T>
1415where
+2-2
libs/wavltree/src/iter.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::{Link, Linked};
99-use crate::{WAVLTree, utils};
108use core::iter::FusedIterator;
119use core::pin::Pin;
1010+1111+use crate::{Link, Linked, WAVLTree, utils};
12121313/// An iterator over references to the entries of a [`WAVLTree`].
1414pub struct Iter<'a, T: Linked + ?Sized> {
+8-6
libs/wavltree/src/lib.rs
···148148use core::ptr::NonNull;
149149use core::{fmt, mem, ptr};
150150151151-pub use crate::cursor::{Cursor, CursorMut};
152152-pub use crate::entry::{Entry, OccupiedEntry, VacantEntry};
153153-use crate::utils::get_sibling;
154151#[cfg(feature = "dot")]
155152pub use dot::Dot;
156156-pub use iter::IntoIter;
157157-pub use iter::{Iter, IterMut};
153153+pub use iter::{IntoIter, Iter, IterMut};
158154pub use utils::Side;
155155+156156+pub use crate::cursor::{Cursor, CursorMut};
157157+pub use crate::entry::{Entry, OccupiedEntry, VacantEntry};
158158+use crate::utils::get_sibling;
159159160160/// Trait implemented by types which can be members of an [intrusive WAVL tree][WAVLTree].
161161///
···16831683mod tests {
16841684 extern crate alloc;
1685168516861686- use super::*;
16871686 use alloc::boxed::Box;
16881687 use alloc::vec::Vec;
16891688 use core::mem::offset_of;
16901689 use core::pin::Pin;
16901690+16911691 use rand::prelude::SliceRandom;
16921692 use rand::rng;
16931693+16941694+ use super::*;
1693169516941696 #[derive(Default)]
16951697 struct TestEntry {
+2-1
libs/wavltree/src/utils.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::{Link, Linked};
98use core::ptr::NonNull;
109use core::{fmt, ptr};
1010+1111+use crate::{Link, Linked};
11121213#[derive(Debug, Copy, Clone, PartialEq)]
1314pub enum Side {
+2-1
loader/build.rs
···2222}
23232424fn copy_linker_script() {
2525- use std::{fs::File, io::Write};
2525+ use std::fs::File;
2626+ use std::io::Write;
26272728 let out_dir = env::var("OUT_DIR").unwrap();
2829 let dest_path = Path::new(&out_dir);
+8-6
loader/src/arch/riscv64.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::GlobalInitResult;
99-use crate::error::Error;
1010-use crate::frame_alloc::FrameAllocator;
1111-use crate::machine_info::MachineInfo;
1212-use crate::mapping::Flags;
1313-use bitflags::bitflags;
148use core::arch::{asm, naked_asm};
159use core::fmt;
1610use core::num::NonZero;
1711use core::ptr::NonNull;
1212+1313+use bitflags::bitflags;
1814use riscv::satp;
1515+1616+use crate::GlobalInitResult;
1717+use crate::error::Error;
1818+use crate::frame_alloc::FrameAllocator;
1919+use crate::machine_info::MachineInfo;
2020+use crate::mapping::Flags;
19212022pub const DEFAULT_ASID: u16 = 0;
2123pub const KERNEL_ASPACE_BASE: usize = 0xffffffc000000000;
+4-2
loader/src/boot_info.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
99-use crate::frame_alloc::FrameAllocator;
108use core::alloc::Layout;
119use core::mem::MaybeUninit;
1210use core::range::Range;
1311use core::slice;
1212+1413use loader_api::{BootInfo, MemoryRegion, MemoryRegionKind, MemoryRegions, TlsTemplate};
1414+1515+use crate::arch;
1616+use crate::frame_alloc::FrameAllocator;
15171618#[expect(clippy::too_many_arguments, reason = "")]
1719pub fn prepare_boot_info(
+4-2
loader/src/frame_alloc.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
99-use crate::error::Error;
108use core::alloc::Layout;
119use core::num::NonZeroUsize;
1210use core::range::Range;
1311use core::{cmp, iter, ptr, slice};
1212+1413use fallible_iterator::FallibleIterator;
1414+1515+use crate::arch;
1616+use crate::error::Error;
15171618pub struct FrameAllocator<'a> {
1719 regions: &'a [Range<usize>],
+3-1
loader/src/kernel.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::error::Error;
98use core::fmt::Formatter;
109use core::range::Range;
1110use core::{fmt, slice};
1111+1212use loader_api::LoaderConfig;
1313use xmas_elf::program::{ProgramHeader, Type};
1414+1515+use crate::error::Error;
14161517/// The inlined kernel
1618static INLINED_KERNEL_BYTES: KernelBytes = KernelBytes(*include_bytes!(env!("KERNEL")));
+6-4
loader/src/machine_info.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch::PAGE_SIZE;
99-use crate::error::Error;
1010-use crate::mapping::{align_down, checked_align_up};
1111-use arrayvec::ArrayVec;
128use core::cmp::Ordering;
139use core::ffi::{CStr, c_void};
1410use core::fmt;
1511use core::fmt::Formatter;
1612use core::range::Range;
1713use core::str::FromStr;
1414+1515+use arrayvec::ArrayVec;
1816use fallible_iterator::FallibleIterator;
1917use fdt::{CellSizes, Fdt, PropertiesIter};
1818+1919+use crate::arch::PAGE_SIZE;
2020+use crate::error::Error;
2121+use crate::mapping::{align_down, checked_align_up};
20222123/// Information about the machine we're running on.
2224/// This is collected from the FDT (flatting device tree) passed to us by the previous stage loader.
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::error::Error;
99-use crate::frame_alloc::FrameAllocator;
1010-use crate::kernel::Kernel;
1111-use crate::machine_info::MachineInfo;
1212-use crate::page_alloc::PageAllocator;
1313-use crate::{SelfRegions, arch};
1414-use bitflags::bitflags;
158use core::alloc::Layout;
169use core::num::NonZeroUsize;
1710use core::range::Range;
1811use core::{cmp, ptr, slice};
1212+1313+use bitflags::bitflags;
1914use fallible_iterator::FallibleIterator;
2015use loader_api::TlsTemplate;
2116use xmas_elf::P64;
2217use xmas_elf::dynamic::Tag;
2318use xmas_elf::program::{SegmentData, Type};
1919+2020+use crate::error::Error;
2121+use crate::frame_alloc::FrameAllocator;
2222+use crate::kernel::Kernel;
2323+use crate::machine_info::MachineInfo;
2424+use crate::page_alloc::PageAllocator;
2525+use crate::{SelfRegions, arch};
24262527bitflags! {
2628 #[derive(Debug, Copy, Clone, PartialEq)]
+3-1
loader/src/page_alloc.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788-use crate::arch;
98use core::alloc::Layout;
109use core::range::Range;
1010+1111use rand::distr::{Distribution, Uniform};
1212use rand::prelude::IteratorRandom;
1313use rand_chacha::ChaCha20Rng;
1414+1515+use crate::arch;
14161517pub fn init(prng: Option<ChaCha20Rng>) -> PageAllocator {
1618 PageAllocator {
+2-1
loader/src/panic.rs
···55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7788+use abort::abort;
99+810use crate::arch;
99-use abort::abort;
10111112#[panic_handler]
1213fn panic(info: &core::panic::PanicInfo) -> ! {