#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "interpreter-musttail-dispatch", feature(explicit_tail_calls))]
#![cfg_attr(feature = "interpreter-musttail-dispatch", allow(incomplete_features))]
#![forbid(unused_must_use)]
#![forbid(clippy::missing_safety_doc)]
#![deny(clippy::undocumented_unsafe_blocks)]
#![deny(clippy::exhaustive_structs)]
#[cfg(all(
not(miri),
target_arch = "x86_64",
any(
target_os = "linux",
all(feature = "generic-sandbox", any(target_os = "macos", target_os = "freebsd"))
),
feature = "std",
))]
macro_rules! if_compiler_is_supported {
({
$($if_true:tt)*
} else {
$($if_false:tt)*
}) => {
$($if_true)*
};
($($if_true:tt)*) => {
$($if_true)*
}
}
#[cfg(not(all(
not(miri),
target_arch = "x86_64",
any(
target_os = "linux",
all(feature = "generic-sandbox", any(target_os = "macos", target_os = "freebsd"))
),
feature = "std",
)))]
macro_rules! if_compiler_is_supported {
({
$($if_true:tt)*
} else {
$($if_false:tt)*
}) => {
$($if_false)*
};
($($if_true:tt)*) => {}
}
extern crate alloc;
mod error;
mod api;
mod config;
#[cfg(target_arch = "x86_64")]
mod cpuid;
mod gas;
mod interpreter;
mod linker;
#[cfg(feature = "std")]
mod source_cache;
mod utils;
#[cfg(feature = "std")]
mod mutex_std;
#[cfg(feature = "std")]
pub(crate) use mutex_std as mutex;
#[cfg(not(feature = "std"))]
mod mutex_no_std;
#[cfg(not(feature = "std"))]
pub(crate) use mutex_no_std as mutex;
impl<T> Default for crate::mutex::Mutex<T>
where
T: Default,
{
fn default() -> Self {
Self::new(Default::default())
}
}
#[cfg(feature = "module-cache")]
mod module_cache;
if_compiler_is_supported! {
mod compiler;
mod page_set;
mod sandbox;
#[cfg(all(target_os = "linux", not(feature = "export-internals-for-testing")))]
mod generic_allocator;
#[cfg(all(target_os = "linux", not(feature = "export-internals-for-testing")))]
mod bit_mask;
#[cfg(target_os = "linux")]
mod shm_allocator;
}
#[cfg(rustfmt)]
mod bit_mask;
#[cfg(rustfmt)]
mod compiler;
#[cfg(rustfmt)]
mod generic_allocator;
#[cfg(rustfmt)]
mod page_set;
#[cfg(rustfmt)]
mod sandbox;
#[cfg(rustfmt)]
mod shm_allocator;
pub use polkavm_common::{
abi::{MemoryMap, MemoryMapBuilder},
program::{ProgramBlob, ProgramCounter, ProgramParts, Reg},
utils::{ArcBytes, AsUninitSliceMut},
};
pub mod debug_info {
pub use polkavm_common::program::{FrameInfo, FrameKind, LineProgram, RegionInfo, SourceLocation};
#[cfg(feature = "std")]
pub use crate::source_cache::SourceCache;
}
pub mod program {
pub use polkavm_common::program::{
EstimateInterpreterMemoryUsageArgs, ISA_JamV1, ISA_Latest32, ISA_Latest64, ISA_ReviveV1, Imports, ImportsIter, Instruction,
InstructionSet, InstructionSetKind, Instructions, JumpTable, JumpTableIter, Opcode, ParsedInstruction, ProgramExport,
ProgramMemoryInfo, ProgramParseError, ProgramSymbol, RawReg,
};
#[doc(hidden)]
pub use polkavm_common::assembler::assemble;
}
pub type Gas = i64;
pub use crate::api::{CompileError, Engine, MemoryAccessError, MemoryProtection, Module, RawInstance, RegValue, SetCacheSizeLimitArgs};
pub use crate::config::{BackendKind, Config, CorePinning, CustomCodegen, GasMeteringKind, ModuleConfig, SandboxKind};
pub use crate::error::Error;
pub use crate::gas::{Cost, CostModel, CostModelKind, CostModelRef};
pub use crate::linker::{CallError, Caller, Instance, InstancePre, Linker};
pub use crate::utils::{InterruptKind, Segfault};
pub use polkavm_common::simulator::CacheModel;
pub const RETURN_TO_HOST: u64 = polkavm_common::abi::VM_ADDR_RETURN_TO_HOST as u64;
#[cfg(test)]
mod tests;
#[cfg(feature = "export-internals-for-testing")]
pub mod generic_allocator;
#[cfg(feature = "export-internals-for-testing")]
pub mod bit_mask;
#[cfg(feature = "export-internals-for-testing")]
#[doc(hidden)]
pub mod _for_testing {
#[cfg(target_os = "linux")]
if_compiler_is_supported! {
pub use crate::shm_allocator::{ShmAllocation, ShmAllocator};
pub fn create_shm_allocator() -> Result<crate::shm_allocator::ShmAllocator, polkavm_linux_raw::Error> {
crate::sandbox::init_native_page_size();
crate::shm_allocator::ShmAllocator::new()
}
pub use crate::page_set::PageSet;
}
}