Make more code work with no_std. (#407)

* Make more code work with no_std.

no_std support is still incomplete, but this patch takes care of the
bulk of the straightforward parts.
This commit is contained in:
Dan Gohman
2019-10-08 16:53:32 -07:00
committed by GitHub
parent c0b37bb713
commit 8e1b44b29c
100 changed files with 380 additions and 270 deletions

View File

@@ -204,7 +204,7 @@ fn ignore(testsuite: &str, name: &str, strategy: &str) -> bool {
if unsafe { if unsafe {
strtof( strtof(
b"8.8817847263968443574e-16" as *const u8 as *const libc::c_char, b"8.8817847263968443574e-16" as *const u8 as *const libc::c_char,
std::ptr::null_mut(), core::ptr::null_mut(),
) )
} }
.to_bits() .to_bits()

View File

@@ -8,10 +8,10 @@ extern crate wasmparser;
extern crate wasmtime_environ; extern crate wasmtime_environ;
extern crate wasmtime_jit; extern crate wasmtime_jit;
use alloc::rc::Rc;
use core::cell::RefCell;
use cranelift_codegen::settings; use cranelift_codegen::settings;
use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
use std::rc::Rc;
use wasmparser::validate; use wasmparser::validate;
use wasmtime_jit::{CompilationStrategy, CompiledModule, Compiler, NullResolver}; use wasmtime_jit::{CompilationStrategy, CompiledModule, Compiler, NullResolver};

View File

@@ -5,11 +5,12 @@ use crate::backend::{
use crate::error::Error; use crate::error::Error;
use crate::microwasm::*; use crate::microwasm::*;
use crate::module::{ModuleContext, SigType, Signature}; use crate::module::{ModuleContext, SigType, Signature};
use core::{fmt, mem};
use cranelift_codegen::binemit; use cranelift_codegen::binemit;
use dynasmrt::DynasmApi; use dynasmrt::DynasmApi;
use either::{Either, Left, Right}; use either::{Either, Left, Right};
use multi_mut::HashMapMultiMut; use multi_mut::HashMapMultiMut;
use std::{collections::HashMap, fmt, hash::Hash, mem}; use std::{collections::HashMap, hash::Hash};
#[derive(Debug)] #[derive(Debug)]
struct Block { struct Block {

View File

@@ -2,11 +2,11 @@ use crate::backend::TranslatedCodeSection;
use crate::error::Error; use crate::error::Error;
use crate::microwasm; use crate::microwasm;
use crate::translate_sections; use crate::translate_sections;
use core::{convert::TryInto, mem};
use cranelift_codegen::{ use cranelift_codegen::{
ir::{self, AbiParam, Signature as CraneliftSignature}, ir::{self, AbiParam, Signature as CraneliftSignature},
isa, isa,
}; };
use std::{convert::TryInto, mem};
use wasmparser::{FuncType, MemoryType, ModuleReader, SectionCode, Type}; use wasmparser::{FuncType, MemoryType, ModuleReader, SectionCode, Type};
pub trait AsValueType { pub trait AsValueType {
@@ -162,7 +162,7 @@ impl ExecutableModule {
self.context self.context
.as_ref() .as_ref()
.map(|ctx| (&**ctx) as *const VmCtx as *const u8) .map(|ctx| (&**ctx) as *const VmCtx as *const u8)
.unwrap_or(std::ptr::null()), .unwrap_or(core::ptr::null()),
) )
} }

View File

@@ -1,11 +1,13 @@
//! Support for a calling of a bounds (exported) function. //! Support for a calling of a bounds (exported) function.
extern crate alloc;
use pyo3::prelude::*; use pyo3::prelude::*;
use pyo3::types::PyTuple; use pyo3::types::PyTuple;
use crate::value::{pyobj_to_value, value_to_pyobj}; use crate::value::{pyobj_to_value, value_to_pyobj};
use std::cell::RefCell; use alloc::rc::Rc;
use std::rc::Rc; use core::cell::RefCell;
use cranelift_codegen::ir; use cranelift_codegen::ir;
use wasmtime_interface_types::ModuleData; use wasmtime_interface_types::ModuleData;

View File

@@ -1,5 +1,7 @@
//! Support for a calling of an imported function. //! Support for a calling of an imported function.
extern crate alloc;
use pyo3::prelude::*; use pyo3::prelude::*;
use pyo3::types::{PyAny, PyDict, PyTuple}; use pyo3::types::{PyAny, PyDict, PyTuple};
@@ -18,10 +20,10 @@ use target_lexicon::HOST;
use wasmtime_environ::{Export, Module}; use wasmtime_environ::{Export, Module};
use wasmtime_runtime::{Imports, InstanceHandle, VMContext, VMFunctionBody}; use wasmtime_runtime::{Imports, InstanceHandle, VMContext, VMFunctionBody};
use alloc::rc::Rc;
use core::cell::RefCell;
use core::cmp; use core::cmp;
use std::cell::RefCell;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::rc::Rc;
struct BoundPyFunction { struct BoundPyFunction {
name: String, name: String,

View File

@@ -1,12 +1,14 @@
//! WebAssembly Instance API object. //! WebAssembly Instance API object.
extern crate alloc;
use pyo3::prelude::*; use pyo3::prelude::*;
use pyo3::types::PyDict; use pyo3::types::PyDict;
use crate::function::Function; use crate::function::Function;
use crate::memory::Memory; use crate::memory::Memory;
use std::cell::RefCell; use alloc::rc::Rc;
use std::rc::Rc; use core::cell::RefCell;
use cranelift_codegen::ir; use cranelift_codegen::ir;
use cranelift_codegen::ir::types; use cranelift_codegen::ir::types;

View File

@@ -7,7 +7,7 @@ use crate::import::into_instance_from_obj;
use crate::instance::Instance; use crate::instance::Instance;
use crate::memory::Memory; use crate::memory::Memory;
use crate::module::Module; use crate::module::Module;
use std::cell::RefCell; use core::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
use wasmtime_interface_types::ModuleData; use wasmtime_interface_types::ModuleData;

View File

@@ -1,15 +1,17 @@
//! WebAssembly Memory API object. //! WebAssembly Memory API object.
extern crate alloc;
use pyo3::class::PyBufferProtocol; use pyo3::class::PyBufferProtocol;
use pyo3::exceptions::BufferError; use pyo3::exceptions::BufferError;
use pyo3::ffi; use pyo3::ffi;
use pyo3::prelude::*; use pyo3::prelude::*;
use std::cell::RefCell; use alloc::rc::Rc;
use core::cell::RefCell;
use core::ptr;
use std::ffi::CStr; use std::ffi::CStr;
use std::os::raw::{c_int, c_void}; use std::os::raw::{c_int, c_void};
use std::ptr;
use std::rc::Rc;
use wasmtime_environ::MemoryPlan; use wasmtime_environ::MemoryPlan;
use wasmtime_jit::{Context, InstanceHandle}; use wasmtime_jit::{Context, InstanceHandle};

View File

@@ -1,8 +1,10 @@
//! WebAssembly Module API object. //! WebAssembly Module API object.
extern crate alloc;
use pyo3::prelude::*; use pyo3::prelude::*;
use std::rc::Rc; use alloc::rc::Rc;
#[pyclass] #[pyclass]
pub struct Module { pub struct Module {

View File

@@ -4,8 +4,8 @@ use pyo3::exceptions::Exception;
use pyo3::prelude::*; use pyo3::prelude::*;
use pyo3::types::PyAny; use pyo3::types::PyAny;
use core::ptr;
use cranelift_codegen::ir; use cranelift_codegen::ir;
use std::ptr;
use wasmtime_interface_types::Value; use wasmtime_interface_types::Value;
pub fn pyobj_to_value(_: Python, p: &PyAny) -> PyResult<Value> { pub fn pyobj_to_value(_: Python, p: &PyAny) -> PyResult<Value> {

View File

@@ -1,12 +1,14 @@
extern crate alloc;
use alloc::rc::Rc;
use core::cell::RefCell;
use cranelift_codegen::settings; use cranelift_codegen::settings;
use cranelift_codegen::settings::Configurable; use cranelift_codegen::settings::Configurable;
use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
use std::fs::File; use std::fs::File;
use std::io; use std::io;
use std::io::Read; use std::io::Read;
use std::path::PathBuf; use std::path::PathBuf;
use std::rc::Rc;
use wabt; use wabt;
use wasmtime_jit::{instantiate, CompilationStrategy, Compiler, NullResolver}; use wasmtime_jit::{instantiate, CompilationStrategy, Compiler, NullResolver};

View File

@@ -20,15 +20,18 @@ cranelift-frontend = "0.44.0"
wasmtime-runtime = { path="../wasmtime-runtime" } wasmtime-runtime = { path="../wasmtime-runtime" }
wasmtime-environ = { path="../wasmtime-environ" } wasmtime-environ = { path="../wasmtime-environ" }
wasmtime-jit = { path="../wasmtime-jit" } wasmtime-jit = { path="../wasmtime-jit" }
wasmparser = "0.39.1" wasmparser = { version = "0.39.1", default-features = false }
failure = { version = "0.1.3", default-features = false } failure = { version = "0.1.3", default-features = false }
failure_derive = { version = "0.1.3", default-features = false } failure_derive = { version = "0.1.3", default-features = false }
target-lexicon = { version = "0.8.1", default-features = false } target-lexicon = { version = "0.8.1", default-features = false }
region = "2.0.0" region = "2.0.0"
hashbrown = { version = "0.6.0", optional = true }
[features] [features]
default = [] default = ["std"]
std = ["cranelift-codegen/std", "cranelift-wasm/std", "wasmtime-environ/std", "wasmparser/std"]
wasm-c-api = [] wasm-c-api = []
core = ["hashbrown/nightly", "cranelift-codegen/core", "cranelift-wasm/core", "wasmtime-environ/core", "wasmparser/core"]
[dev-dependencies] [dev-dependencies]
# for wasmtime.rs # for wasmtime.rs

View File

@@ -1,9 +1,11 @@
//! Translation of hello example //! Translation of hello example
extern crate alloc;
use alloc::rc::Rc;
use core::cell::Ref;
use failure::{bail, format_err, Error}; use failure::{bail, format_err, Error};
use std::cell::Ref;
use std::fs::read; use std::fs::read;
use std::rc::Rc;
use wasmtime_api::*; use wasmtime_api::*;
struct HelloCallback; struct HelloCallback;

View File

@@ -1,7 +1,7 @@
//! Translation of the memory example //! Translation of the memory example
use core::cell::Ref;
use failure::{bail, format_err, Error}; use failure::{bail, format_err, Error};
use std::cell::Ref;
use std::fs::read; use std::fs::read;
use wasmtime_api::*; use wasmtime_api::*;

View File

@@ -3,7 +3,8 @@ use crate::runtime::Store;
use crate::trap::Trap; use crate::trap::Trap;
use crate::types::FuncType; use crate::types::FuncType;
use crate::values::Val; use crate::values::Val;
use std::rc::Rc; use alloc::rc::Rc;
use alloc::vec::Vec;
use crate::trampoline::generate_func_export; use crate::trampoline::generate_func_export;
use cranelift_codegen::ir; use cranelift_codegen::ir;

View File

@@ -1,6 +1,6 @@
use std::cell::{RefCell, RefMut}; use alloc::rc::Rc;
use std::hash::{Hash, Hasher}; use core::cell::{RefCell, RefMut};
use std::rc::Rc; use core::hash::{Hash, Hasher};
use wasmtime_jit::{CompilationStrategy, Compiler, Features}; use wasmtime_jit::{CompilationStrategy, Compiler, Features};

View File

@@ -5,9 +5,10 @@ use crate::trampoline::{generate_global_export, generate_memory_export, generate
use crate::trap::Trap; use crate::trap::Trap;
use crate::types::{ExternType, FuncType, GlobalType, MemoryType, TableType, ValType}; use crate::types::{ExternType, FuncType, GlobalType, MemoryType, TableType, ValType};
use crate::values::{from_checked_anyfunc, into_checked_anyfunc, Val}; use crate::values::{from_checked_anyfunc, into_checked_anyfunc, Val};
use std::rc::Rc; use alloc::boxed::Box;
use std::result::Result; use alloc::rc::Rc;
use std::slice; use core::result::Result;
use core::slice;
use wasmtime_runtime::InstanceHandle; use wasmtime_runtime::InstanceHandle;
// Externals // Externals
@@ -171,8 +172,8 @@ impl Func {
} }
} }
impl std::fmt::Debug for Func { impl core::fmt::Debug for Func {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Func") write!(f, "Func")
} }
} }

View File

@@ -3,10 +3,14 @@ use crate::externals::Extern;
use crate::module::Module; use crate::module::Module;
use crate::r#ref::HostRef; use crate::r#ref::HostRef;
use crate::runtime::Store; use crate::runtime::Store;
use crate::{HashMap, HashSet};
use alloc::borrow::ToOwned;
use alloc::boxed::Box;
use alloc::rc::Rc;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::cell::RefCell;
use failure::Error; use failure::Error;
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::rc::Rc;
use wasmtime_jit::{instantiate, Resolver}; use wasmtime_jit::{instantiate, Resolver};
use wasmtime_runtime::{Export, InstanceHandle}; use wasmtime_runtime::{Export, InstanceHandle};

View File

@@ -1,5 +1,7 @@
//! Wasmtime embed API. Based on wasm-c-api. //! Wasmtime embed API. Based on wasm-c-api.
#![cfg_attr(not(feature = "std"), no_std)]
mod callable; mod callable;
mod context; mod context;
mod externals; mod externals;
@@ -17,6 +19,8 @@ pub mod wasm;
#[macro_use] #[macro_use]
extern crate failure_derive; extern crate failure_derive;
#[macro_use]
extern crate alloc;
pub use crate::callable::Callable; pub use crate::callable::Callable;
pub use crate::externals::*; pub use crate::externals::*;
@@ -27,3 +31,8 @@ pub use crate::runtime::{Config, Engine, Store};
pub use crate::trap::Trap; pub use crate::trap::Trap;
pub use crate::types::*; pub use crate::types::*;
pub use crate::values::*; pub use crate::values::*;
#[cfg(not(feature = "std"))]
use hashbrown::{hash_map, HashMap, HashSet};
#[cfg(feature = "std")]
use std::collections::{hash_map, HashMap, HashSet};

View File

@@ -4,6 +4,9 @@ use crate::types::{
ExportType, ExternType, FuncType, GlobalType, ImportType, Limits, MemoryType, Mutability, ExportType, ExternType, FuncType, GlobalType, ImportType, Limits, MemoryType, Mutability,
TableType, ValType, TableType, ValType,
}; };
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use failure::Error; use failure::Error;
use wasmparser::{validate, ExternalKind, ImportSectionEntryType, ModuleReader, SectionCode}; use wasmparser::{validate, ExternalKind, ImportSectionEntryType, ModuleReader, SectionCode};
@@ -12,7 +15,7 @@ fn into_memory_type(mt: wasmparser::MemoryType) -> MemoryType {
assert!(!mt.shared); assert!(!mt.shared);
MemoryType::new(Limits::new( MemoryType::new(Limits::new(
mt.limits.initial, mt.limits.initial,
mt.limits.maximum.unwrap_or(::std::u32::MAX), mt.limits.maximum.unwrap_or(::core::u32::MAX),
)) ))
} }
@@ -53,7 +56,7 @@ fn into_table_type(tt: wasmparser::TableType) -> TableType {
let ty = into_valtype(&tt.element_type); let ty = into_valtype(&tt.element_type);
let limits = Limits::new( let limits = Limits::new(
tt.limits.initial, tt.limits.initial,
tt.limits.maximum.unwrap_or(::std::u32::MAX), tt.limits.maximum.unwrap_or(::core::u32::MAX),
); );
TableType::new(ty, limits) TableType::new(ty, limits)
} }

View File

@@ -1,7 +1,8 @@
use std::any::Any; use alloc::boxed::Box;
use std::cell::{self, RefCell}; use alloc::rc::{Rc, Weak};
use std::fmt; use core::any::Any;
use std::rc::{Rc, Weak}; use core::cell::{self, RefCell};
use core::fmt;
pub trait HostInfo { pub trait HostInfo {
fn finalize(&mut self) {} fn finalize(&mut self) {}

View File

@@ -1,6 +1,8 @@
use std::cell::RefCell; use crate::HashMap;
use std::collections::HashMap; use alloc::boxed::Box;
use std::rc::Rc; use alloc::rc::Rc;
use alloc::string::String;
use core::cell::RefCell;
use crate::context::{create_compiler, Context}; use crate::context::{create_compiler, Context};
use crate::r#ref::HostRef; use crate::r#ref::HostRef;
@@ -132,7 +134,7 @@ impl Store {
&mut self, &mut self,
signature: &ir::Signature, signature: &ir::Signature,
) -> wasmtime_runtime::VMSharedSignatureIndex { ) -> wasmtime_runtime::VMSharedSignatureIndex {
use std::collections::hash_map::Entry; use crate::hash_map::Entry;
let index = self.context().compiler().signatures().register(signature); let index = self.context().compiler().signatures().register(signature);
match self.signature_cache.entry(index) { match self.signature_cache.entry(index) {
Entry::Vacant(v) => { Entry::Vacant(v) => {

View File

@@ -1,10 +1,10 @@
//! Memory management for executable code. //! Memory management for executable code.
// Copy of wasmtime's wasmtime-jit/src/code_memory.rs // Copy of wasmtime's wasmtime-jit/src/code_memory.rs
use alloc::string::String;
use alloc::vec::Vec;
use core::{cmp, mem}; use core::{cmp, mem};
use region; use region;
use std::string::String;
use std::vec::Vec;
use wasmtime_runtime::{Mmap, VMFunctionBody}; use wasmtime_runtime::{Mmap, VMFunctionBody};
/// Memory manager for executable code. /// Memory manager for executable code.

View File

@@ -7,10 +7,13 @@ use failure::Error;
use wasmtime_environ::Module; use wasmtime_environ::Module;
use wasmtime_runtime::{Imports, InstanceHandle, VMFunctionBody}; use wasmtime_runtime::{Imports, InstanceHandle, VMFunctionBody};
use std::any::Any; use crate::{HashMap, HashSet};
use std::cell::{RefCell, RefMut}; use alloc::boxed::Box;
use std::collections::{HashMap, HashSet}; use alloc::rc::Rc;
use std::rc::Rc; use alloc::string::String;
use alloc::vec::Vec;
use core::any::Any;
use core::cell::{RefCell, RefMut};
use crate::runtime::Store; use crate::runtime::Store;

View File

@@ -14,8 +14,11 @@ use failure::Error;
use wasmtime_environ::{Export, Module}; use wasmtime_environ::{Export, Module};
use wasmtime_runtime::{InstanceHandle, VMContext, VMFunctionBody}; use wasmtime_runtime::{InstanceHandle, VMContext, VMFunctionBody};
use alloc::boxed::Box;
use alloc::rc::Rc;
use alloc::string::ToString;
use alloc::vec::Vec;
use core::cmp; use core::cmp;
use std::rc::Rc;
use crate::{Callable, FuncType, Store, Trap, Val}; use crate::{Callable, FuncType, Store, Trap, Val};

View File

@@ -1,3 +1,4 @@
use alloc::boxed::Box;
use cranelift_entity::PrimaryMap; use cranelift_entity::PrimaryMap;
use failure::Error; use failure::Error;
use wasmtime_environ::Module; use wasmtime_environ::Module;

View File

@@ -1,3 +1,5 @@
use alloc::boxed::Box;
use alloc::string::ToString;
use cranelift_entity::PrimaryMap; use cranelift_entity::PrimaryMap;
use failure::Error; use failure::Error;
use wasmtime_environ::Module; use wasmtime_environ::Module;
@@ -13,7 +15,7 @@ pub fn create_handle_with_memory(memory: &MemoryType) -> Result<InstanceHandle,
let memory = cranelift_wasm::Memory { let memory = cranelift_wasm::Memory {
minimum: memory.limits().min(), minimum: memory.limits().min(),
maximum: if memory.limits().max() == std::u32::MAX { maximum: if memory.limits().max() == core::u32::MAX {
None None
} else { } else {
Some(memory.limits().max()) Some(memory.limits().max())

View File

@@ -8,8 +8,8 @@ mod memory;
mod table; mod table;
use crate::r#ref::HostRef; use crate::r#ref::HostRef;
use alloc::rc::Rc;
use failure::Error; use failure::Error;
use std::rc::Rc;
use self::func::create_handle_with_function; use self::func::create_handle_with_function;
use self::global::create_global; use self::global::create_global;

View File

@@ -1,3 +1,5 @@
use alloc::boxed::Box;
use alloc::string::ToString;
use cranelift_entity::PrimaryMap; use cranelift_entity::PrimaryMap;
use cranelift_wasm::TableElementType; use cranelift_wasm::TableElementType;
use failure::Error; use failure::Error;
@@ -12,7 +14,7 @@ pub fn create_handle_with_table(table: &TableType) -> Result<InstanceHandle, Err
let table = cranelift_wasm::Table { let table = cranelift_wasm::Table {
minimum: table.limits().min(), minimum: table.limits().min(),
maximum: if table.limits().max() == std::u32::MAX { maximum: if table.limits().max() == core::u32::MAX {
None None
} else { } else {
Some(table.limits().max()) Some(table.limits().max())

View File

@@ -1,3 +1,5 @@
use alloc::string::{String, ToString};
#[derive(Fail, Debug)] #[derive(Fail, Debug)]
#[fail(display = "Wasm trap")] #[fail(display = "Wasm trap")]
pub struct Trap { pub struct Trap {

View File

@@ -1,3 +1,7 @@
use alloc::borrow::ToOwned;
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use cranelift_codegen::ir; use cranelift_codegen::ir;
// Type Representations // Type Representations
@@ -24,7 +28,7 @@ impl Limits {
pub fn at_least(min: u32) -> Limits { pub fn at_least(min: u32) -> Limits {
Limits { Limits {
min, min,
max: ::std::u32::MAX, max: ::core::u32::MAX,
} }
} }
@@ -257,7 +261,7 @@ impl TableType {
false false
}); });
let ty = ValType::FuncRef; let ty = ValType::FuncRef;
let limits = Limits::new(table.minimum, table.maximum.unwrap_or(::std::u32::MAX)); let limits = Limits::new(table.minimum, table.maximum.unwrap_or(::core::u32::MAX));
TableType::new(ty, limits) TableType::new(ty, limits)
} }
} }
@@ -280,7 +284,7 @@ impl MemoryType {
pub(crate) fn from_cranelift_memory(memory: cranelift_wasm::Memory) -> MemoryType { pub(crate) fn from_cranelift_memory(memory: cranelift_wasm::Memory) -> MemoryType {
MemoryType::new(Limits::new( MemoryType::new(Limits::new(
memory.minimum, memory.minimum,
memory.maximum.unwrap_or(::std::u32::MAX), memory.maximum.unwrap_or(::core::u32::MAX),
)) ))
} }
} }
@@ -296,7 +300,7 @@ impl From<String> for Name {
} }
} }
impl ::std::string::ToString for Name { impl ::alloc::string::ToString for Name {
fn to_string(&self) -> String { fn to_string(&self) -> String {
self.0.to_owned() self.0.to_owned()
} }

View File

@@ -2,7 +2,7 @@ use crate::externals::Func;
use crate::r#ref::{AnyRef, HostRef}; use crate::r#ref::{AnyRef, HostRef};
use crate::runtime::Store; use crate::runtime::Store;
use crate::types::ValType; use crate::types::ValType;
use std::ptr; use core::ptr;
use cranelift_codegen::ir; use cranelift_codegen::ir;
use wasmtime_jit::RuntimeValue; use wasmtime_jit::RuntimeValue;

View File

@@ -10,11 +10,11 @@ use super::{
HostInfo, HostRef, ImportType, Instance, Limits, Memory, MemoryType, Module, Name, Store, HostInfo, HostRef, ImportType, Instance, Limits, Memory, MemoryType, Module, Name, Store,
Table, TableType, Trap, Val, ValType, Table, TableType, Trap, Val, ValType,
}; };
use std::boxed::Box; use alloc::boxed::Box;
use std::mem; use alloc::rc::Rc;
use std::ptr; use core::mem;
use std::rc::Rc; use core::ptr;
use std::slice; use core::slice;
macro_rules! declare_vec { macro_rules! declare_vec {
($name:ident, $elem_ty:path) => { ($name:ident, $elem_ty:path) => {
@@ -345,12 +345,12 @@ pub struct wasm_func_t {
func: HostRef<Func>, func: HostRef<Func>,
ext: Option<Box<wasm_extern_t>>, ext: Option<Box<wasm_extern_t>>,
} }
pub type wasm_func_callback_t = ::std::option::Option< pub type wasm_func_callback_t = ::core::option::Option<
unsafe extern "C" fn(args: *const wasm_val_t, results: *mut wasm_val_t) -> *mut wasm_trap_t, unsafe extern "C" fn(args: *const wasm_val_t, results: *mut wasm_val_t) -> *mut wasm_trap_t,
>; >;
pub type wasm_func_callback_with_env_t = ::std::option::Option< pub type wasm_func_callback_with_env_t = ::core::option::Option<
unsafe extern "C" fn( unsafe extern "C" fn(
env: *mut ::std::os::raw::c_void, env: *mut ::core::ffi::c_void,
args: *const wasm_val_t, args: *const wasm_val_t,
results: *mut wasm_val_t, results: *mut wasm_val_t,
) -> *mut wasm_trap_t, ) -> *mut wasm_trap_t,
@@ -569,8 +569,8 @@ impl Into<HostRef<Trap>> for wasm_trap_t {
struct CallbackWithEnv { struct CallbackWithEnv {
callback: wasm_func_callback_with_env_t, callback: wasm_func_callback_with_env_t,
env: *mut ::std::os::raw::c_void, env: *mut ::core::ffi::c_void,
finalizer: ::std::option::Option<unsafe extern "C" fn(env: *mut ::std::os::raw::c_void)>, finalizer: ::core::option::Option<unsafe extern "C" fn(env: *mut ::core::ffi::c_void)>,
} }
impl Callable for CallbackWithEnv { impl Callable for CallbackWithEnv {
@@ -801,8 +801,8 @@ pub unsafe extern "C" fn wasm_func_new_with_env(
store: *mut wasm_store_t, store: *mut wasm_store_t,
ty: *const wasm_functype_t, ty: *const wasm_functype_t,
callback: wasm_func_callback_with_env_t, callback: wasm_func_callback_with_env_t,
env: *mut ::std::os::raw::c_void, env: *mut ::core::ffi::c_void,
finalizer: ::std::option::Option<unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void)>, finalizer: ::core::option::Option<unsafe extern "C" fn(arg1: *mut ::core::ffi::c_void)>,
) -> *mut wasm_func_t { ) -> *mut wasm_func_t {
let store = (*store).store.clone(); let store = (*store).store.clone();
let ty = (*ty).functype.clone(); let ty = (*ty).functype.clone();
@@ -1618,8 +1618,8 @@ pub unsafe extern "C" fn wasm_tabletype_new(
} }
struct HostInfoState { struct HostInfoState {
info: *mut ::std::os::raw::c_void, info: *mut ::core::ffi::c_void,
finalizer: ::std::option::Option<unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void)>, finalizer: ::core::option::Option<unsafe extern "C" fn(arg1: *mut ::core::ffi::c_void)>,
} }
impl HostInfo for HostInfoState { impl HostInfo for HostInfoState {
@@ -1635,8 +1635,8 @@ impl HostInfo for HostInfoState {
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn wasm_instance_set_host_info_with_finalizer( pub unsafe extern "C" fn wasm_instance_set_host_info_with_finalizer(
instance: *mut wasm_instance_t, instance: *mut wasm_instance_t,
info: *mut ::std::os::raw::c_void, info: *mut ::core::ffi::c_void,
finalizer: ::std::option::Option<unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void)>, finalizer: ::core::option::Option<unsafe extern "C" fn(arg1: *mut ::core::ffi::c_void)>,
) { ) {
let info = if info.is_null() && finalizer.is_none() { let info = if info.is_null() && finalizer.is_none() {
None None

View File

@@ -1,6 +1,8 @@
use std::cell::{Ref, RefCell}; extern crate alloc;
use alloc::rc::Rc;
use core::cell::{Ref, RefCell};
use std::fs::read; use std::fs::read;
use std::rc::Rc;
use wasmtime_api::*; use wasmtime_api::*;
#[test] #[test]

View File

@@ -22,11 +22,12 @@ wasmtime-environ = { path = "../wasmtime-environ", default-features = false }
target-lexicon = { version = "0.8.1", default-features = false } target-lexicon = { version = "0.8.1", default-features = false }
failure = { version = "0.1.3", default-features = false } failure = { version = "0.1.3", default-features = false }
failure_derive = { version = "0.1.3", default-features = false } failure_derive = { version = "0.1.3", default-features = false }
hashbrown = { version = "0.6.0", optional = true }
[features] [features]
default = ["std"] default = ["std"]
std = ["cranelift-codegen/std", "cranelift-wasm/std", "wasmtime-environ/std"] std = ["cranelift-codegen/std", "cranelift-wasm/std", "wasmtime-environ/std"]
core = ["cranelift-codegen/core", "cranelift-wasm/core"] core = ["hashbrown/nightly", "cranelift-codegen/core", "cranelift-wasm/core"]
[badges] [badges]
maintenance = { status = "experimental" } maintenance = { status = "experimental" }

View File

@@ -1,9 +1,9 @@
use crate::transform::AddressTransform; use crate::transform::AddressTransform;
use crate::{HashMap, HashSet};
use alloc::vec::Vec;
use gimli::constants; use gimli::constants;
use gimli::read; use gimli::read;
use gimli::{Reader, UnitSectionOffset}; use gimli::{Reader, UnitSectionOffset};
use std::collections::{HashMap, HashSet};
use std::vec::Vec;
#[derive(Debug)] #[derive(Debug)]
pub struct Dependencies { pub struct Dependencies {
@@ -20,7 +20,7 @@ impl Dependencies {
} }
fn add_edge(&mut self, a: UnitSectionOffset, b: UnitSectionOffset) { fn add_edge(&mut self, a: UnitSectionOffset, b: UnitSectionOffset) {
use std::collections::hash_map::Entry; use crate::hash_map::Entry;
match self.edges.entry(a) { match self.edges.entry(a) {
Entry::Occupied(mut o) => { Entry::Occupied(mut o) => {
o.get_mut().insert(b); o.get_mut().insert(b);

View File

@@ -1,10 +1,18 @@
//! Debug utils for WebAssembly using Cranelift. //! Debug utils for WebAssembly using Cranelift.
use alloc::string::String;
use alloc::vec::Vec;
use cranelift_codegen::isa::TargetFrontendConfig; use cranelift_codegen::isa::TargetFrontendConfig;
use faerie::{Artifact, Decl}; use faerie::{Artifact, Decl};
use failure::Error; use failure::Error;
use target_lexicon::{BinaryFormat, Triple}; use target_lexicon::{BinaryFormat, Triple};
use wasmtime_environ::{ModuleAddressMap, ModuleVmctxInfo, ValueLabelsRanges}; use wasmtime_environ::{ModuleAddressMap, ModuleVmctxInfo, ValueLabelsRanges};
#[cfg(not(feature = "std"))]
use hashbrown::{hash_map, HashMap, HashSet};
#[cfg(feature = "std")]
use std::collections::{hash_map, HashMap, HashSet};
pub use crate::read_debuginfo::{read_debuginfo, DebugInfoData, WasmFileInfo}; pub use crate::read_debuginfo::{read_debuginfo, DebugInfoData, WasmFileInfo};
pub use crate::transform::transform_dwarf; pub use crate::transform::transform_dwarf;
pub use crate::write_debuginfo::{emit_dwarf, ResolvedSymbol, SymbolResolver}; pub use crate::write_debuginfo::{emit_dwarf, ResolvedSymbol, SymbolResolver};
@@ -16,6 +24,7 @@ mod write_debuginfo;
#[macro_use] #[macro_use]
extern crate failure_derive; extern crate failure_derive;
extern crate alloc;
struct FunctionRelocResolver {} struct FunctionRelocResolver {}
impl SymbolResolver for FunctionRelocResolver { impl SymbolResolver for FunctionRelocResolver {
@@ -71,12 +80,12 @@ pub fn emit_debugsections_image(
assert!(funcs.len() > 0); assert!(funcs.len() > 0);
let mut segment_body: (usize, usize) = (!0, 0); let mut segment_body: (usize, usize) = (!0, 0);
for (body_ptr, body_len) in funcs.iter() { for (body_ptr, body_len) in funcs.iter() {
segment_body.0 = ::std::cmp::min(segment_body.0, *body_ptr as usize); segment_body.0 = ::core::cmp::min(segment_body.0, *body_ptr as usize);
segment_body.1 = ::std::cmp::max(segment_body.1, *body_ptr as usize + body_len); segment_body.1 = ::core::cmp::max(segment_body.1, *body_ptr as usize + body_len);
} }
let segment_body = (segment_body.0 as *const u8, segment_body.1 - segment_body.0); let segment_body = (segment_body.0 as *const u8, segment_body.1 - segment_body.0);
let body = unsafe { ::std::slice::from_raw_parts(segment_body.0, segment_body.1) }; let body = unsafe { ::core::slice::from_raw_parts(segment_body.0, segment_body.1) };
obj.declare_with("all", Decl::function(), body.to_vec())?; obj.declare_with("all", Decl::function(), body.to_vec())?;
emit_dwarf(&mut obj, dwarf, &resolver)?; emit_dwarf(&mut obj, dwarf, &resolver)?;

View File

@@ -1,3 +1,6 @@
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use std::collections::HashMap; use std::collections::HashMap;
use std::path::PathBuf; use std::path::PathBuf;
use wasmparser::{self, ModuleReader, SectionCode}; use wasmparser::{self, ModuleReader, SectionCode};

View File

@@ -1,12 +1,13 @@
use crate::HashMap;
use crate::WasmFileInfo; use crate::WasmFileInfo;
use alloc::boxed::Box;
use alloc::collections::BTreeMap;
use alloc::vec::Vec;
use core::iter::FromIterator;
use cranelift_codegen::ir::SourceLoc; use cranelift_codegen::ir::SourceLoc;
use cranelift_entity::{EntityRef, PrimaryMap}; use cranelift_entity::{EntityRef, PrimaryMap};
use cranelift_wasm::DefinedFuncIndex; use cranelift_wasm::DefinedFuncIndex;
use gimli::write; use gimli::write;
use std::boxed::Box;
use std::collections::{BTreeMap, HashMap};
use std::iter::FromIterator;
use std::vec::Vec;
use wasmtime_environ::{FunctionAddressMap, ModuleAddressMap}; use wasmtime_environ::{FunctionAddressMap, ModuleAddressMap};
pub type GeneratedAddress = usize; pub type GeneratedAddress = usize;
@@ -160,7 +161,7 @@ fn build_function_lookup(
active_ranges.clone().into_boxed_slice(), active_ranges.clone().into_boxed_slice(),
); );
} }
active_ranges.retain(|r| ranges[*r].wasm_end.cmp(&wasm_start) != std::cmp::Ordering::Less); active_ranges.retain(|r| ranges[*r].wasm_end.cmp(&wasm_start) != core::cmp::Ordering::Less);
active_ranges.push(range_index); active_ranges.push(range_index);
last_wasm_pos = Some(wasm_start); last_wasm_pos = Some(wasm_start);
} }
@@ -491,10 +492,10 @@ impl AddressTransform {
mod tests { mod tests {
use super::{build_function_lookup, get_wasm_code_offset, AddressTransform}; use super::{build_function_lookup, get_wasm_code_offset, AddressTransform};
use crate::read_debuginfo::WasmFileInfo; use crate::read_debuginfo::WasmFileInfo;
use core::iter::FromIterator;
use cranelift_codegen::ir::SourceLoc; use cranelift_codegen::ir::SourceLoc;
use cranelift_entity::PrimaryMap; use cranelift_entity::PrimaryMap;
use gimli::write::Address; use gimli::write::Address;
use std::iter::FromIterator;
use wasmtime_environ::{FunctionAddressMap, InstructionAddressMap, ModuleAddressMap}; use wasmtime_environ::{FunctionAddressMap, InstructionAddressMap, ModuleAddressMap};
#[test] #[test]

View File

@@ -1,5 +1,6 @@
use crate::HashMap;
use alloc::vec::Vec;
use failure::Error; use failure::Error;
use std::collections::HashMap;
use gimli; use gimli;

View File

@@ -1,3 +1,5 @@
use crate::{HashMap, HashSet};
use alloc::vec::Vec;
use cranelift_codegen::ir::{StackSlots, ValueLabel, ValueLoc}; use cranelift_codegen::ir::{StackSlots, ValueLabel, ValueLoc};
use cranelift_codegen::isa::RegUnit; use cranelift_codegen::isa::RegUnit;
use cranelift_codegen::ValueLabelsRanges; use cranelift_codegen::ValueLabelsRanges;
@@ -6,7 +8,6 @@ use cranelift_wasm::{get_vmctx_value_label, DefinedFuncIndex};
use failure::Error; use failure::Error;
use gimli::write; use gimli::write;
use gimli::{self, Expression, Operation, Reader, ReaderOffset, Register, X86_64}; use gimli::{self, Expression, Operation, Reader, ReaderOffset, Register, X86_64};
use std::collections::{HashMap, HashSet};
use super::address_transform::AddressTransform; use super::address_transform::AddressTransform;
@@ -193,7 +194,7 @@ impl CompiledExpression {
addr_tr: &AddressTransform, addr_tr: &AddressTransform,
frame_info: Option<&FunctionFrameInfo>, frame_info: Option<&FunctionFrameInfo>,
endian: gimli::RunTimeEndian, endian: gimli::RunTimeEndian,
) -> std::vec::Vec<(write::Address, u64, write::Expression)> { ) -> alloc::vec::Vec<(write::Address, u64, write::Expression)> {
if scope.len() == 0 { if scope.len() == 0 {
return vec![]; return vec![];
} }

View File

@@ -1,7 +1,8 @@
use alloc::collections::BTreeMap;
use alloc::vec::Vec;
use core::iter::FromIterator;
use cranelift_entity::EntityRef; use cranelift_entity::EntityRef;
use failure::Error; use failure::Error;
use std::collections::BTreeMap;
use std::iter::FromIterator;
use gimli; use gimli;

View File

@@ -1,9 +1,9 @@
use crate::gc::build_dependencies; use crate::gc::build_dependencies;
use crate::DebugInfoData; use crate::DebugInfoData;
use crate::HashSet;
use cranelift_codegen::isa::TargetFrontendConfig; use cranelift_codegen::isa::TargetFrontendConfig;
use failure::Error; use failure::Error;
use simulate::generate_simulated_dwarf; use simulate::generate_simulated_dwarf;
use std::collections::HashSet;
use wasmtime_environ::{ModuleAddressMap, ModuleVmctxInfo, ValueLabelsRanges}; use wasmtime_environ::{ModuleAddressMap, ModuleVmctxInfo, ValueLabelsRanges};
use gimli; use gimli;

View File

@@ -1,3 +1,4 @@
use alloc::vec::Vec;
use cranelift_entity::EntityRef; use cranelift_entity::EntityRef;
use cranelift_wasm::DefinedFuncIndex; use cranelift_wasm::DefinedFuncIndex;
use failure::Error; use failure::Error;

View File

@@ -1,9 +1,11 @@
use crate::read_debuginfo::WasmFileInfo; use crate::read_debuginfo::WasmFileInfo;
pub use crate::read_debuginfo::{DebugInfoData, FunctionMetadata, WasmType}; pub use crate::read_debuginfo::{DebugInfoData, FunctionMetadata, WasmType};
use crate::{HashMap, HashSet};
use alloc::string::String;
use alloc::vec::Vec;
use cranelift_entity::EntityRef; use cranelift_entity::EntityRef;
use cranelift_wasm::get_vmctx_value_label; use cranelift_wasm::get_vmctx_value_label;
use failure::Error; use failure::Error;
use std::collections::{HashMap, HashSet};
use std::path::PathBuf; use std::path::PathBuf;
use wasmtime_environ::{ModuleVmctxInfo, ValueLabelsRanges}; use wasmtime_environ::{ModuleVmctxInfo, ValueLabelsRanges};

View File

@@ -1,6 +1,8 @@
use crate::{HashMap, HashSet};
use alloc::string::String;
use alloc::vec::Vec;
use cranelift_entity::EntityRef; use cranelift_entity::EntityRef;
use failure::Error; use failure::Error;
use std::collections::{HashMap, HashSet};
use wasmtime_environ::{ModuleVmctxInfo, ValueLabelsRanges}; use wasmtime_environ::{ModuleVmctxInfo, ValueLabelsRanges};
use gimli; use gimli;

View File

@@ -1,3 +1,4 @@
use alloc::vec::Vec;
use cranelift_wasm::DefinedFuncIndex; use cranelift_wasm::DefinedFuncIndex;
use failure::Error; use failure::Error;
use wasmtime_environ::{ModuleVmctxInfo, ValueLabelsRanges}; use wasmtime_environ::{ModuleVmctxInfo, ValueLabelsRanges};

View File

@@ -1,9 +1,11 @@
use alloc::string::String;
use alloc::vec::Vec;
use gimli::write::{Address, Dwarf, EndianVec, Result, Sections, Writer}; use gimli::write::{Address, Dwarf, EndianVec, Result, Sections, Writer};
use gimli::{RunTimeEndian, SectionId}; use gimli::{RunTimeEndian, SectionId};
use core::result;
use faerie::artifact::{Decl, SectionKind}; use faerie::artifact::{Decl, SectionKind};
use faerie::*; use faerie::*;
use std::result;
#[derive(Clone)] #[derive(Clone)]
struct DebugReloc { struct DebugReloc {

View File

@@ -1,11 +1,11 @@
//! Data structures to provide transformation of the source //! Data structures to provide transformation of the source
// addresses of a WebAssembly module into the native code. // addresses of a WebAssembly module into the native code.
use alloc::vec::Vec;
use cranelift_codegen::ir; use cranelift_codegen::ir;
use cranelift_entity::PrimaryMap; use cranelift_entity::PrimaryMap;
use cranelift_wasm::DefinedFuncIndex; use cranelift_wasm::DefinedFuncIndex;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::vec::Vec;
/// Single source location to generated address mapping. /// Single source location to generated address mapping.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]

View File

@@ -2,6 +2,7 @@ use crate::address_map::{ModuleAddressMap, ValueLabelsRanges};
use crate::compilation::{Compilation, Relocations, Traps}; use crate::compilation::{Compilation, Relocations, Traps};
use crate::module::Module; use crate::module::Module;
use crate::module_environ::FunctionBodyData; use crate::module_environ::FunctionBodyData;
use alloc::string::{String, ToString};
use core::hash::Hasher; use core::hash::Hasher;
use cranelift_codegen::{ir, isa}; use cranelift_codegen::{ir, isa};
use cranelift_entity::PrimaryMap; use cranelift_entity::PrimaryMap;
@@ -13,7 +14,6 @@ use sha2::{Digest, Sha256};
use std::fs; use std::fs;
use std::io::Write; use std::io::Write;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::string::{String, ToString};
#[macro_use] // for tests #[macro_use] // for tests
mod config; mod config;

View File

@@ -1,6 +1,9 @@
//! Module for configuring the cache system. //! Module for configuring the cache system.
use super::worker; use super::worker;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::time::Duration;
use directories::ProjectDirs; use directories::ProjectDirs;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use log::{debug, error, trace, warn}; use log::{debug, error, trace, warn};
@@ -13,10 +16,7 @@ use std::fmt::Debug;
use std::fs; use std::fs;
use std::mem; use std::mem;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::string::{String, ToString};
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::time::Duration;
use std::vec::Vec;
// wrapped, so we have named section in config, // wrapped, so we have named section in config,
// also, for possible future compatibility // also, for possible future compatibility

View File

@@ -1,7 +1,7 @@
use super::CacheConfig; use super::CacheConfig;
use core::time::Duration;
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
use std::time::Duration;
use tempfile::{self, TempDir}; use tempfile::{self, TempDir};
// note: config loading during validation creates cache directory to canonicalize its path, // note: config loading during validation creates cache directory to canonicalize its path,

View File

@@ -3,17 +3,17 @@ use super::*;
use crate::address_map::{FunctionAddressMap, InstructionAddressMap}; use crate::address_map::{FunctionAddressMap, InstructionAddressMap};
use crate::compilation::{CodeAndJTOffsets, Relocation, RelocationTarget, TrapInformation}; use crate::compilation::{CodeAndJTOffsets, Relocation, RelocationTarget, TrapInformation};
use crate::module::{MemoryPlan, MemoryStyle, Module}; use crate::module::{MemoryPlan, MemoryStyle, Module};
use alloc::boxed::Box;
use alloc::vec::Vec;
use core::cmp::min;
use cranelift_codegen::{binemit, ir, isa, settings, ValueLocRange}; use cranelift_codegen::{binemit, ir, isa, settings, ValueLocRange};
use cranelift_entity::EntityRef; use cranelift_entity::EntityRef;
use cranelift_entity::{PrimaryMap, SecondaryMap}; use cranelift_entity::{PrimaryMap, SecondaryMap};
use cranelift_wasm::{DefinedFuncIndex, FuncIndex, Global, GlobalInit, Memory, SignatureIndex}; use cranelift_wasm::{DefinedFuncIndex, FuncIndex, Global, GlobalInit, Memory, SignatureIndex};
use rand::rngs::SmallRng; use rand::rngs::SmallRng;
use rand::{Rng, SeedableRng}; use rand::{Rng, SeedableRng};
use std::boxed::Box;
use std::cmp::min;
use std::fs; use std::fs;
use std::str::FromStr; use std::str::FromStr;
use std::vec::Vec;
use target_lexicon::triple; use target_lexicon::triple;
// Since cache system is a global thing, each test needs to be run in seperate process. // Since cache system is a global thing, each test needs to be run in seperate process.

View File

@@ -6,10 +6,12 @@
//! Background tasks can be CPU intensive, but the worker thread has low priority. //! Background tasks can be CPU intensive, but the worker thread has low priority.
use super::{cache_config, fs_write_atomic, CacheConfig}; use super::{cache_config, fs_write_atomic, CacheConfig};
use alloc::vec::Vec;
use core::cmp;
use core::time::Duration;
use log::{debug, info, trace, warn}; use log::{debug, info, trace, warn};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use spin::Once; use spin::Once;
use std::cmp;
use std::collections::HashMap; use std::collections::HashMap;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::fs; use std::fs;
@@ -19,10 +21,8 @@ use std::sync::mpsc::{sync_channel, Receiver, SyncSender};
#[cfg(test)] #[cfg(test)]
use std::sync::{Arc, Condvar, Mutex}; use std::sync::{Arc, Condvar, Mutex};
use std::thread; use std::thread;
use std::time::Duration;
#[cfg(not(test))] #[cfg(not(test))]
use std::time::SystemTime; use std::time::SystemTime;
use std::vec::Vec;
#[cfg(test)] #[cfg(test)]
use tests::system_time_stub::SystemTimeStub as SystemTime; use tests::system_time_stub::SystemTimeStub as SystemTime;

View File

@@ -1,6 +1,6 @@
use super::*; use super::*;
use crate::cache::config::tests::test_prolog; use crate::cache::config::tests::test_prolog;
use std::iter::repeat; use core::iter::repeat;
use std::process; use std::process;
// load_config! comes from crate::cache(::config::tests); // load_config! comes from crate::cache(::config::tests);

View File

@@ -4,12 +4,12 @@
use crate::address_map::{ModuleAddressMap, ValueLabelsRanges}; use crate::address_map::{ModuleAddressMap, ValueLabelsRanges};
use crate::module; use crate::module;
use crate::module_environ::FunctionBodyData; use crate::module_environ::FunctionBodyData;
use alloc::vec::Vec;
use cranelift_codegen::{binemit, ir, isa, CodegenError}; use cranelift_codegen::{binemit, ir, isa, CodegenError};
use cranelift_entity::PrimaryMap; use cranelift_entity::PrimaryMap;
use cranelift_wasm::{DefinedFuncIndex, FuncIndex, WasmError}; use cranelift_wasm::{DefinedFuncIndex, FuncIndex, WasmError};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::ops::Range; use std::ops::Range;
use std::vec::Vec;
/// Compiled machine code: body and jump table offsets. /// Compiled machine code: body and jump table offsets.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]

View File

@@ -14,6 +14,7 @@ use crate::func_environ::{
}; };
use crate::module::Module; use crate::module::Module;
use crate::module_environ::FunctionBodyData; use crate::module_environ::FunctionBodyData;
use alloc::vec::Vec;
use cranelift_codegen::binemit; use cranelift_codegen::binemit;
use cranelift_codegen::ir; use cranelift_codegen::ir;
use cranelift_codegen::ir::ExternalName; use cranelift_codegen::ir::ExternalName;
@@ -22,7 +23,6 @@ use cranelift_codegen::Context;
use cranelift_entity::PrimaryMap; use cranelift_entity::PrimaryMap;
use cranelift_wasm::{DefinedFuncIndex, FuncIndex, FuncTranslator}; use cranelift_wasm::{DefinedFuncIndex, FuncIndex, FuncTranslator};
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
use std::vec::Vec;
/// Implementation of a relocation sink that just saves all the information for later /// Implementation of a relocation sink that just saves all the information for later
pub struct RelocSink { pub struct RelocSink {

View File

@@ -1,6 +1,7 @@
use crate::module::{MemoryPlan, MemoryStyle, Module, TableStyle}; use crate::module::{MemoryPlan, MemoryStyle, Module, TableStyle};
use crate::vmoffsets::VMOffsets; use crate::vmoffsets::VMOffsets;
use crate::WASM_PAGE_SIZE; use crate::WASM_PAGE_SIZE;
use alloc::vec::Vec;
use core::clone::Clone; use core::clone::Clone;
use core::convert::TryFrom; use core::convert::TryFrom;
use cranelift_codegen::cursor::FuncCursor; use cranelift_codegen::cursor::FuncCursor;
@@ -17,7 +18,6 @@ use cranelift_wasm::{
}; };
#[cfg(feature = "lightbeam")] #[cfg(feature = "lightbeam")]
use cranelift_wasm::{DefinedFuncIndex, DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex}; use cranelift_wasm::{DefinedFuncIndex, DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex};
use std::vec::Vec;
/// Compute an `ir::ExternalName` for a given wasm function index. /// Compute an `ir::ExternalName` for a given wasm function index.
pub fn get_func_name(func_index: FuncIndex) -> ir::ExternalName { pub fn get_func_name(func_index: FuncIndex) -> ir::ExternalName {

View File

@@ -24,14 +24,8 @@
clippy::use_self clippy::use_self
) )
)] )]
#![no_std]
#[cfg(not(feature = "std"))] extern crate alloc;
#[macro_use]
extern crate alloc as std;
#[cfg(feature = "std")]
#[macro_use]
extern crate std;
#[macro_use] #[macro_use]
extern crate failure_derive; extern crate failure_derive;

View File

@@ -2,6 +2,9 @@
use crate::module_environ::FunctionBodyData; use crate::module_environ::FunctionBodyData;
use crate::tunables::Tunables; use crate::tunables::Tunables;
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use core::hash::{Hash, Hasher}; use core::hash::{Hash, Hasher};
use cranelift_codegen::ir; use cranelift_codegen::ir;
use cranelift_entity::{EntityRef, PrimaryMap}; use cranelift_entity::{EntityRef, PrimaryMap};
@@ -10,9 +13,6 @@ use cranelift_wasm::{
GlobalIndex, Memory, MemoryIndex, SignatureIndex, Table, TableIndex, GlobalIndex, Memory, MemoryIndex, SignatureIndex, Table, TableIndex,
}; };
use indexmap::IndexMap; use indexmap::IndexMap;
use std::boxed::Box;
use std::string::String;
use std::vec::Vec;
/// A WebAssembly table initializer. /// A WebAssembly table initializer.
#[derive(Clone, Debug, Hash)] #[derive(Clone, Debug, Hash)]

View File

@@ -1,6 +1,9 @@
use crate::func_environ::FuncEnvironment; use crate::func_environ::FuncEnvironment;
use crate::module::{Export, MemoryPlan, Module, TableElements, TablePlan}; use crate::module::{Export, MemoryPlan, Module, TableElements, TablePlan};
use crate::tunables::Tunables; use crate::tunables::Tunables;
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use core::convert::TryFrom; use core::convert::TryFrom;
use cranelift_codegen::ir; use cranelift_codegen::ir;
use cranelift_codegen::ir::{AbiParam, ArgumentPurpose}; use cranelift_codegen::ir::{AbiParam, ArgumentPurpose};
@@ -10,9 +13,6 @@ use cranelift_wasm::{
self, translate_module, DefinedFuncIndex, FuncIndex, Global, GlobalIndex, Memory, MemoryIndex, self, translate_module, DefinedFuncIndex, FuncIndex, Global, GlobalIndex, Memory, MemoryIndex,
SignatureIndex, Table, TableIndex, WasmResult, SignatureIndex, Table, TableIndex, WasmResult,
}; };
use std::boxed::Box;
use std::string::String;
use std::vec::Vec;
/// Contains function data: byte code and its offset in the module. /// Contains function data: byte code and its offset in the module.
#[derive(Hash)] #[derive(Hash)]

View File

@@ -11,10 +11,10 @@ readme = "README.md"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
cranelift-codegen = "0.44.0" cranelift-codegen = { version = "0.44.0", default-features = false }
failure = "0.1" failure = { version = "0.1", default-features = false }
walrus = "0.12.0" walrus = "0.12.0"
wasmparser = "0.39.1" wasmparser = { version = "0.39.1", default-features = false }
wasm-webidl-bindings = "0.5.0" wasm-webidl-bindings = "0.5.0"
wasmtime-jit = { path = '../wasmtime-jit' } wasmtime-jit = { path = '../wasmtime-jit', default-features = false }
wasmtime-runtime = { path = '../wasmtime-runtime' } wasmtime-runtime = { path = '../wasmtime-runtime', default-features = false }

View File

@@ -7,11 +7,17 @@
#![deny(missing_docs)] #![deny(missing_docs)]
#[macro_use]
extern crate alloc;
use alloc::boxed::Box;
use alloc::string::ToString;
use alloc::vec::Vec;
use core::convert::TryFrom;
use core::slice;
use core::str;
use cranelift_codegen::ir; use cranelift_codegen::ir;
use failure::{bail, format_err, Error}; use failure::{bail, format_err, Error};
use std::convert::TryFrom;
use std::slice;
use std::str;
use wasm_webidl_bindings::ast; use wasm_webidl_bindings::ast;
use wasmtime_jit::{ActionOutcome, Context, RuntimeValue}; use wasmtime_jit::{ActionOutcome, Context, RuntimeValue};
use wasmtime_runtime::{Export, InstanceHandle}; use wasmtime_runtime::{Export, InstanceHandle};

View File

@@ -1,5 +1,6 @@
use std::convert::TryFrom; use alloc::string::{String, ToString};
use std::fmt; use core::convert::TryFrom;
use core::fmt;
/// The set of all possible WebAssembly Interface Types /// The set of all possible WebAssembly Interface Types
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@@ -23,12 +23,12 @@ failure = { version = "0.1.3", default-features = false }
failure_derive = { version = "0.1.3", default-features = false } failure_derive = { version = "0.1.3", default-features = false }
target-lexicon = { version = "0.8.1", default-features = false } target-lexicon = { version = "0.8.1", default-features = false }
hashbrown = { version = "0.6.0", optional = true } hashbrown = { version = "0.6.0", optional = true }
wasmparser = "0.39.1" wasmparser = { version = "0.39.1", default-features = false }
[features] [features]
default = ["std"] default = ["std"]
std = ["cranelift-codegen/std", "cranelift-wasm/std", "wasmtime-environ/std"] std = ["cranelift-codegen/std", "cranelift-wasm/std", "wasmtime-environ/std", "wasmtime-debug/std", "wasmparser/std"]
core = ["hashbrown/nightly", "cranelift-codegen/core", "cranelift-wasm/core", "wasmtime-environ/core"] core = ["hashbrown/nightly", "cranelift-codegen/core", "cranelift-wasm/core", "wasmtime-environ/core", "wasmtime-debug/core", "wasmparser/core"]
lightbeam = ["wasmtime-environ/lightbeam"] lightbeam = ["wasmtime-environ/lightbeam"]
[badges] [badges]

View File

@@ -2,11 +2,11 @@
use crate::compiler::Compiler; use crate::compiler::Compiler;
use crate::instantiate::SetupError; use crate::instantiate::SetupError;
use alloc::string::String;
use alloc::vec::Vec;
use core::cmp::max; use core::cmp::max;
use core::{fmt, mem, ptr, slice}; use core::{fmt, mem, ptr, slice};
use cranelift_codegen::ir; use cranelift_codegen::ir;
use std::string::String;
use std::vec::Vec;
use wasmtime_runtime::{wasmtime_call_trampoline, Export, InstanceHandle, VMInvokeArgument}; use wasmtime_runtime::{wasmtime_call_trampoline, Export, InstanceHandle, VMInvokeArgument};
/// A runtime value. /// A runtime value.

View File

@@ -1,10 +1,10 @@
//! Memory management for executable code. //! Memory management for executable code.
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use core::{cmp, mem}; use core::{cmp, mem};
use region; use region;
use std::boxed::Box;
use std::string::String;
use std::vec::Vec;
use wasmtime_runtime::{Mmap, VMFunctionBody}; use wasmtime_runtime::{Mmap, VMFunctionBody};
/// Memory manager for executable code. /// Memory manager for executable code.

View File

@@ -4,6 +4,9 @@ use super::HashMap;
use crate::code_memory::CodeMemory; use crate::code_memory::CodeMemory;
use crate::instantiate::SetupError; use crate::instantiate::SetupError;
use crate::target_tunables::target_tunables; use crate::target_tunables::target_tunables;
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use core::convert::TryFrom; use core::convert::TryFrom;
use cranelift_codegen::ir::InstBuilder; use cranelift_codegen::ir::InstBuilder;
use cranelift_codegen::isa::{TargetFrontendConfig, TargetIsa}; use cranelift_codegen::isa::{TargetFrontendConfig, TargetIsa};
@@ -12,9 +15,6 @@ use cranelift_codegen::{binemit, ir};
use cranelift_entity::{EntityRef, PrimaryMap}; use cranelift_entity::{EntityRef, PrimaryMap};
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext}; use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use cranelift_wasm::{DefinedFuncIndex, DefinedMemoryIndex}; use cranelift_wasm::{DefinedFuncIndex, DefinedMemoryIndex};
use std::boxed::Box;
use std::string::String;
use std::vec::Vec;
use wasmtime_debug::{emit_debugsections_image, DebugInfoData}; use wasmtime_debug::{emit_debugsections_image, DebugInfoData};
use wasmtime_environ::{ use wasmtime_environ::{
Compilation, CompileError, Compiler as _C, FunctionBodyData, Module, ModuleVmctxInfo, Compilation, CompileError, Compiler as _C, FunctionBodyData, Module, ModuleVmctxInfo,

View File

@@ -1,15 +1,15 @@
use crate::action::{get, inspect_memory, invoke}; use crate::action::{get, inspect_memory, invoke};
use crate::HashMap;
use crate::{ use crate::{
instantiate, ActionError, ActionOutcome, CompilationStrategy, Compiler, InstanceHandle, instantiate, ActionError, ActionOutcome, CompilationStrategy, Compiler, InstanceHandle,
Namespace, RuntimeValue, SetupError, Namespace, RuntimeValue, SetupError,
}; };
use alloc::boxed::Box;
use alloc::rc::Rc;
use alloc::string::{String, ToString};
use core::cell::RefCell;
use core::{fmt, str};
use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::isa::TargetIsa;
use std::boxed::Box;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
use std::string::{String, ToString};
use std::{fmt, str};
use wasmparser::{validate, OperatorValidatorConfig, ValidatingParserConfig}; use wasmparser::{validate, OperatorValidatorConfig, ValidatingParserConfig};
/// Indicates an unknown instance was specified. /// Indicates an unknown instance was specified.

View File

@@ -7,14 +7,15 @@ use super::HashMap;
use crate::compiler::Compiler; use crate::compiler::Compiler;
use crate::link::link_module; use crate::link::link_module;
use crate::resolver::Resolver; use crate::resolver::Resolver;
use alloc::boxed::Box;
use alloc::rc::Rc;
use alloc::string::String;
use alloc::vec::Vec;
use core::cell::RefCell; use core::cell::RefCell;
use cranelift_entity::{BoxedSlice, PrimaryMap}; use cranelift_entity::{BoxedSlice, PrimaryMap};
use cranelift_wasm::{DefinedFuncIndex, SignatureIndex}; use cranelift_wasm::{DefinedFuncIndex, SignatureIndex};
use std::boxed::Box; #[cfg(feature = "std")]
use std::io::Write; use std::io::Write;
use std::rc::Rc;
use std::string::String;
use std::vec::Vec;
use wasmtime_debug::read_debuginfo; use wasmtime_debug::read_debuginfo;
use wasmtime_environ::{ use wasmtime_environ::{
CompileError, DataInitializer, DataInitializerLocation, Module, ModuleEnvironment, CompileError, DataInitializer, DataInitializerLocation, Module, ModuleEnvironment,
@@ -117,6 +118,7 @@ impl<'data> RawCompiledModule<'data> {
// Make all code compiled thus far executable. // Make all code compiled thus far executable.
compiler.publish_compiled_code(); compiler.publish_compiled_code();
#[cfg(feature = "std")]
let dbg_jit_registration = if let Some(img) = dbg_image { let dbg_jit_registration = if let Some(img) = dbg_image {
let mut bytes = Vec::new(); let mut bytes = Vec::new();
bytes.write_all(&img).expect("all written"); bytes.write_all(&img).expect("all written");

View File

@@ -21,19 +21,14 @@
clippy::use_self clippy::use_self
) )
)] )]
#![no_std]
#[macro_use]
extern crate alloc;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
#[macro_use] use hashbrown::{hash_map, HashMap, HashSet};
extern crate alloc as std;
#[cfg(feature = "std")] #[cfg(feature = "std")]
#[macro_use] use std::collections::{hash_map, HashMap, HashSet};
extern crate std;
#[cfg(not(feature = "std"))]
use hashbrown::{hash_map, HashMap};
#[cfg(feature = "std")]
use std::collections::{hash_map, HashMap};
#[macro_use] #[macro_use]
extern crate failure_derive; extern crate failure_derive;

View File

@@ -1,13 +1,13 @@
//! Linking for JIT-compiled code. //! Linking for JIT-compiled code.
use crate::resolver::Resolver; use crate::resolver::Resolver;
use crate::HashSet;
use alloc::vec::Vec;
use core::ptr::write_unaligned; use core::ptr::write_unaligned;
use cranelift_codegen::binemit::Reloc; use cranelift_codegen::binemit::Reloc;
use cranelift_codegen::ir::JumpTableOffsets; use cranelift_codegen::ir::JumpTableOffsets;
use cranelift_entity::PrimaryMap; use cranelift_entity::PrimaryMap;
use cranelift_wasm::{DefinedFuncIndex, Global, GlobalInit, Memory, Table, TableElementType}; use cranelift_wasm::{DefinedFuncIndex, Global, GlobalInit, Memory, Table, TableElementType};
use std::collections::HashSet;
use std::vec::Vec;
use wasmtime_environ::{ use wasmtime_environ::{
MemoryPlan, MemoryStyle, Module, Relocation, RelocationTarget, Relocations, TablePlan, MemoryPlan, MemoryStyle, Module, Relocation, RelocationTarget, Relocations, TablePlan,
}; };

View File

@@ -4,7 +4,7 @@
use super::HashMap; use super::HashMap;
use crate::resolver::Resolver; use crate::resolver::Resolver;
use std::string::String; use alloc::string::String;
use wasmtime_runtime::{Export, InstanceHandle}; use wasmtime_runtime::{Export, InstanceHandle};
/// A namespace containing instances keyed by name. /// A namespace containing instances keyed by name.

View File

@@ -1,9 +1,11 @@
use alloc::boxed::Box;
use alloc::vec::Vec;
use core::ptr;
use cranelift_codegen::isa::TargetFrontendConfig; use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_entity::EntityRef; use cranelift_entity::EntityRef;
use cranelift_wasm::GlobalInit; use cranelift_wasm::GlobalInit;
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::collections::HashMap; use std::collections::HashMap;
use std::ptr;
use wasmtime_environ::{Module, TargetSharedSignatureIndex, VMOffsets}; use wasmtime_environ::{Module, TargetSharedSignatureIndex, VMOffsets};
pub struct TableRelocation { pub struct TableRelocation {
@@ -28,7 +30,7 @@ pub fn layout_vmcontext(
let target_index = match signature_registry.entry(sig) { let target_index = match signature_registry.entry(sig) {
Entry::Occupied(o) => *o.get(), Entry::Occupied(o) => *o.get(),
Entry::Vacant(v) => { Entry::Vacant(v) => {
assert!(signature_registry_len <= ::std::u32::MAX as usize); assert!(signature_registry_len <= ::core::u32::MAX as usize);
let id = TargetSharedSignatureIndex::new(signature_registry_len as u32); let id = TargetSharedSignatureIndex::new(signature_registry_len as u32);
signature_registry_len += 1; signature_registry_len += 1;
*v.insert(id) *v.insert(id)

View File

@@ -1,3 +1,5 @@
use alloc::string::String;
use alloc::vec::Vec;
use faerie::{Artifact, Decl}; use faerie::{Artifact, Decl};
use wasmtime_environ::DataInitializer; use wasmtime_environ::DataInitializer;

View File

@@ -1,3 +1,4 @@
use alloc::string::String;
use cranelift_codegen::settings; use cranelift_codegen::settings;
use cranelift_codegen::settings::Configurable; use cranelift_codegen::settings::Configurable;
use cranelift_entity::EntityRef; use cranelift_entity::EntityRef;

View File

@@ -26,6 +26,8 @@
) )
)] )]
extern crate alloc;
mod context; mod context;
mod data_segment; mod data_segment;
mod function; mod function;

View File

@@ -2,6 +2,7 @@ use crate::context::layout_vmcontext;
use crate::data_segment::{declare_data_segment, emit_data_segment}; use crate::data_segment::{declare_data_segment, emit_data_segment};
use crate::function::{declare_functions, emit_functions}; use crate::function::{declare_functions, emit_functions};
use crate::table::{declare_table, emit_table}; use crate::table::{declare_table, emit_table};
use alloc::string::String;
use cranelift_codegen::isa::TargetFrontendConfig; use cranelift_codegen::isa::TargetFrontendConfig;
use faerie::{Artifact, Decl, Link}; use faerie::{Artifact, Decl, Link};
use wasmtime_environ::{Compilation, DataInitializer, Module, Relocations}; use wasmtime_environ::{Compilation, DataInitializer, Module, Relocations};

View File

@@ -1,3 +1,5 @@
use alloc::string::String;
use alloc::vec::Vec;
use faerie::{Artifact, Decl}; use faerie::{Artifact, Decl};
/// Declares data segment symbol /// Declares data segment symbol

View File

@@ -23,6 +23,8 @@ memoffset = "0.5.1"
failure = { version = "0.1.3", default-features = false } failure = { version = "0.1.3", default-features = false }
failure_derive = { version = "0.1.3", default-features = false } failure_derive = { version = "0.1.3", default-features = false }
indexmap = "1.0.2" indexmap = "1.0.2"
hashbrown = { version = "0.6.0", optional = true }
spin = { version = "0.5.2", optional = true }
[target.'cfg(target_os = "windows")'.dependencies] [target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3.7", features = ["winbase", "memoryapi"] } winapi = { version = "0.3.7", features = ["winbase", "memoryapi"] }
@@ -33,6 +35,7 @@ cc = "1.0"
[features] [features]
default = ["std"] default = ["std"]
std = ["cranelift-codegen/std", "cranelift-wasm/std", "wasmtime-environ/std"] std = ["cranelift-codegen/std", "cranelift-wasm/std", "wasmtime-environ/std"]
core = ["hashbrown/nightly", "cranelift-codegen/core", "cranelift-wasm/core", "wasmtime-environ/core", "spin"]
[badges] [badges]
maintenance = { status = "experimental" } maintenance = { status = "experimental" }

View File

@@ -1,8 +1,8 @@
use crate::instance::InstanceHandle; use crate::instance::InstanceHandle;
use crate::vmcontext::{VMFunctionImport, VMGlobalImport, VMMemoryImport, VMTableImport}; use crate::vmcontext::{VMFunctionImport, VMGlobalImport, VMMemoryImport, VMTableImport};
use crate::HashSet;
use cranelift_entity::{BoxedSlice, PrimaryMap}; use cranelift_entity::{BoxedSlice, PrimaryMap};
use cranelift_wasm::{FuncIndex, GlobalIndex, MemoryIndex, TableIndex}; use cranelift_wasm::{FuncIndex, GlobalIndex, MemoryIndex, TableIndex};
use std::collections::HashSet;
/// Resolved import pointers. /// Resolved import pointers.
#[derive(Clone)] #[derive(Clone)]

View File

@@ -15,9 +15,15 @@ use crate::vmcontext::{
VMGlobalDefinition, VMGlobalImport, VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, VMGlobalDefinition, VMGlobalImport, VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex,
VMTableDefinition, VMTableImport, VMTableDefinition, VMTableImport,
}; };
use crate::{HashMap, HashSet};
use alloc::borrow::ToOwned;
use alloc::boxed::Box;
use alloc::rc::Rc;
use alloc::string::{String, ToString};
use core::any::Any; use core::any::Any;
use core::borrow::Borrow; use core::borrow::Borrow;
use core::cell::RefCell; use core::cell::RefCell;
use core::convert::TryFrom;
use core::slice; use core::slice;
use core::{mem, ptr}; use core::{mem, ptr};
use cranelift_entity::EntityRef; use cranelift_entity::EntityRef;
@@ -27,12 +33,6 @@ use cranelift_wasm::{
GlobalIndex, GlobalInit, MemoryIndex, SignatureIndex, TableIndex, GlobalIndex, GlobalInit, MemoryIndex, SignatureIndex, TableIndex,
}; };
use indexmap; use indexmap;
use std::borrow::ToOwned;
use std::boxed::Box;
use std::collections::{HashMap, HashSet};
use std::convert::TryFrom;
use std::rc::Rc;
use std::string::{String, ToString};
use wasmtime_environ::{DataInitializer, Module, TableElements, VMOffsets}; use wasmtime_environ::{DataInitializer, Module, TableElements, VMOffsets};
fn signature_id( fn signature_id(
@@ -613,9 +613,9 @@ impl Instance {
} }
pub(crate) fn lookup_global_export(&self, field: &str) -> Option<Export> { pub(crate) fn lookup_global_export(&self, field: &str) -> Option<Export> {
let cell: &RefCell<HashMap<std::string::String, core::option::Option<Export>>> = let cell: &RefCell<HashMap<alloc::string::String, core::option::Option<Export>>> =
self.global_exports.borrow(); self.global_exports.borrow();
let map: &mut HashMap<std::string::String, core::option::Option<Export>> = let map: &mut HashMap<alloc::string::String, core::option::Option<Export>> =
&mut cell.borrow_mut(); &mut cell.borrow_mut();
if let Some(Some(export)) = map.get(field) { if let Some(Some(export)) = map.get(field) {
return Some(export.clone()); return Some(export.clone());
@@ -790,10 +790,10 @@ impl InstanceHandle {
// Collect the exports for the global export map. // Collect the exports for the global export map.
for (field, decl) in &instance.module.exports { for (field, decl) in &instance.module.exports {
use std::collections::hash_map::Entry::*; use crate::hash_map::Entry::*;
let cell: &RefCell<HashMap<std::string::String, core::option::Option<Export>>> = let cell: &RefCell<HashMap<alloc::string::String, core::option::Option<Export>>> =
instance.global_exports.borrow(); instance.global_exports.borrow();
let map: &mut HashMap<std::string::String, core::option::Option<Export>> = let map: &mut HashMap<alloc::string::String, core::option::Option<Export>> =
&mut cell.borrow_mut(); &mut cell.borrow_mut();
match map.entry(field.to_string()) { match map.entry(field.to_string()) {
Vacant(entry) => { Vacant(entry) => {

View File

@@ -2,8 +2,9 @@
//! the __jit_debug_register_code() and __jit_debug_descriptor to register //! the __jit_debug_register_code() and __jit_debug_descriptor to register
//! or unregister generated object images with debuggers. //! or unregister generated object images with debuggers.
use std::boxed::Box; use alloc::boxed::Box;
use std::ptr; use alloc::vec::Vec;
use core::ptr;
#[repr(C)] #[repr(C)]
struct JITCodeEntry { struct JITCodeEntry {
@@ -40,7 +41,7 @@ extern "C" fn __jit_debug_register_code() {
// Hack to not allow inlining even when Rust wants to do it in release mode. // Hack to not allow inlining even when Rust wants to do it in release mode.
let x = 3; let x = 3;
unsafe { unsafe {
std::ptr::read_volatile(&x); core::ptr::read_volatile(&x);
} }
} }

View File

@@ -21,6 +21,7 @@
clippy::use_self clippy::use_self
) )
)] )]
#![cfg_attr(not(feature = "std"), no_std)]
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
@@ -28,6 +29,7 @@ extern crate lazy_static;
extern crate memoffset; extern crate memoffset;
#[macro_use] #[macro_use]
extern crate failure_derive; extern crate failure_derive;
extern crate alloc;
mod export; mod export;
mod imports; mod imports;
@@ -59,5 +61,15 @@ pub use crate::vmcontext::{
VMTableDefinition, VMTableImport, VMTableDefinition, VMTableImport,
}; };
#[cfg(not(feature = "std"))]
use hashbrown::{hash_map, HashMap, HashSet};
#[cfg(feature = "std")]
use std::collections::{hash_map, HashMap, HashSet};
#[cfg(not(feature = "std"))]
use spin::{RwLock, RwLockReadGuard, RwLockWriteGuard};
#[cfg(feature = "std")]
use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
/// Version number of this crate. /// Version number of this crate.
pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const VERSION: &str = env!("CARGO_PKG_VERSION");

View File

@@ -4,8 +4,8 @@
use crate::mmap::Mmap; use crate::mmap::Mmap;
use crate::vmcontext::VMMemoryDefinition; use crate::vmcontext::VMMemoryDefinition;
use std::convert::TryFrom; use alloc::string::String;
use std::string::String; use core::convert::TryFrom;
use wasmtime_environ::{MemoryPlan, MemoryStyle, WASM_MAX_PAGES, WASM_PAGE_SIZE}; use wasmtime_environ::{MemoryPlan, MemoryStyle, WASM_MAX_PAGES, WASM_PAGE_SIZE};
/// A linear memory instance. /// A linear memory instance.

View File

@@ -1,14 +1,14 @@
//! Low-level abstraction for allocating and managing zero-filled pages //! Low-level abstraction for allocating and managing zero-filled pages
//! of memory. //! of memory.
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::ptr; use core::ptr;
use core::slice; use core::slice;
use errno; use errno;
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
use libc; use libc;
use region; use region;
use std::string::{String, ToString};
use std::vec::Vec;
/// Round `size` up to the nearest multiple of `page_size`. /// Round `size` up to the nearest multiple of `page_size`.
fn round_up_to_page_size(size: usize, page_size: usize) -> usize { fn round_up_to_page_size(size: usize, page_size: usize) -> usize {

View File

@@ -2,9 +2,9 @@
//! signature checking. //! signature checking.
use crate::vmcontext::VMSharedSignatureIndex; use crate::vmcontext::VMSharedSignatureIndex;
use crate::{hash_map, HashMap};
use core::convert::TryFrom;
use cranelift_codegen::ir; use cranelift_codegen::ir;
use std::collections::{hash_map, HashMap};
use std::convert::TryFrom;
/// WebAssembly requires that the caller and callee signatures in an indirect /// WebAssembly requires that the caller and callee signatures in an indirect
/// call must match. To implement this efficiently, keep a registry of all /// call must match. To implement this efficiently, keep a registry of all
@@ -29,11 +29,11 @@ impl SignatureRegistry {
match self.signature_hash.entry(sig.clone()) { match self.signature_hash.entry(sig.clone()) {
hash_map::Entry::Occupied(entry) => *entry.get(), hash_map::Entry::Occupied(entry) => *entry.get(),
hash_map::Entry::Vacant(entry) => { hash_map::Entry::Vacant(entry) => {
// Keep `signature_hash` len under 2**32 -- VMSharedSignatureIndex::new(std::u32::MAX) // Keep `signature_hash` len under 2**32 -- VMSharedSignatureIndex::new(core::u32::MAX)
// is reserved for VMSharedSignatureIndex::default(). // is reserved for VMSharedSignatureIndex::default().
debug_assert!( debug_assert!(
len < std::u32::MAX as usize, len < core::u32::MAX as usize,
"Invariant check: signature_hash.len() < std::u32::MAX" "Invariant check: signature_hash.len() < core::u32::MAX"
); );
let sig_id = VMSharedSignatureIndex::new(u32::try_from(len).unwrap()); let sig_id = VMSharedSignatureIndex::new(u32::try_from(len).unwrap());
entry.insert(sig_id); entry.insert(sig_id);

View File

@@ -5,9 +5,9 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
use crate::vmcontext::VMContext; use crate::vmcontext::VMContext;
use crate::RwLock;
use core::borrow::{Borrow, BorrowMut}; use core::borrow::{Borrow, BorrowMut};
use core::cell::Cell; use core::cell::Cell;
use std::sync::RwLock;
#[derive(Default)] #[derive(Default)]
struct TrapContext { struct TrapContext {

View File

@@ -3,9 +3,9 @@
//! `Table` is to WebAssembly tables what `LinearMemory` is to WebAssembly linear memories. //! `Table` is to WebAssembly tables what `LinearMemory` is to WebAssembly linear memories.
use crate::vmcontext::{VMCallerCheckedAnyfunc, VMTableDefinition}; use crate::vmcontext::{VMCallerCheckedAnyfunc, VMTableDefinition};
use alloc::vec::Vec;
use core::convert::{TryFrom, TryInto};
use cranelift_wasm::TableElementType; use cranelift_wasm::TableElementType;
use std::convert::{TryFrom, TryInto};
use std::vec::Vec;
use wasmtime_environ::{TablePlan, TableStyle}; use wasmtime_environ::{TablePlan, TableStyle};
/// A table instance. /// A table instance.
@@ -25,7 +25,7 @@ impl Table {
} }
}; };
assert!( assert!(
plan.table.minimum <= std::u32::MAX, plan.table.minimum <= core::u32::MAX,
"Invariant check: vec.len() <= u32::MAX" "Invariant check: vec.len() <= u32::MAX"
); );
match plan.style { match plan.style {
@@ -60,7 +60,7 @@ impl Table {
} }
}; };
assert!( assert!(
new_len <= std::u32::MAX, new_len <= core::u32::MAX,
"Invariant check: vec.len() <= u32::MAX" "Invariant check: vec.len() <= u32::MAX"
); );
self.vec.resize( self.vec.resize(

View File

@@ -1,7 +1,7 @@
use crate::HashMap;
use crate::{RwLock, RwLockReadGuard, RwLockWriteGuard};
use cranelift_codegen::ir; use cranelift_codegen::ir;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use std::collections::HashMap;
use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard};
lazy_static! { lazy_static! {
static ref REGISTRY: RwLock<TrapRegistry> = RwLock::new(TrapRegistry::default()); static ref REGISTRY: RwLock<TrapRegistry> = RwLock::new(TrapRegistry::default());

View File

@@ -4,10 +4,10 @@
use crate::trap_registry::get_trap_registry; use crate::trap_registry::get_trap_registry;
use crate::trap_registry::TrapDescription; use crate::trap_registry::TrapDescription;
use crate::vmcontext::{VMContext, VMFunctionBody}; use crate::vmcontext::{VMContext, VMFunctionBody};
use alloc::string::{String, ToString};
use core::cell::Cell; use core::cell::Cell;
use core::ptr; use core::ptr;
use cranelift_codegen::ir; use cranelift_codegen::ir;
use std::string::String;
extern "C" { extern "C" {
fn WasmtimeCallTrampoline( fn WasmtimeCallTrampoline(

View File

@@ -2,17 +2,17 @@ use crate::host::{
argv_environ_init, argv_environ_values, fd_prestats, fd_prestats_init, fd_prestats_insert, argv_environ_init, argv_environ_values, fd_prestats, fd_prestats_init, fd_prestats_insert,
fd_table, fd_table_init, fd_table_insert_existing, fd_table, fd_table_init, fd_table_insert_existing,
}; };
use alloc::rc::Rc;
use core::cell::RefCell;
use cranelift_codegen::ir::types; use cranelift_codegen::ir::types;
use cranelift_codegen::{ir, isa}; use cranelift_codegen::{ir, isa};
use cranelift_entity::PrimaryMap; use cranelift_entity::PrimaryMap;
use cranelift_wasm::DefinedFuncIndex; use cranelift_wasm::DefinedFuncIndex;
use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
use std::ffi::CString; use std::ffi::CString;
use std::fs::File; use std::fs::File;
use std::mem; use std::mem;
use std::os::unix::io::AsRawFd; use std::os::unix::io::AsRawFd;
use std::rc::Rc;
use syscalls; use syscalls;
use target_lexicon::HOST; use target_lexicon::HOST;
use wasmtime_environ::{translate_signature, Export, Module}; use wasmtime_environ::{translate_signature, Export, Module};

View File

@@ -1,8 +1,8 @@
use crate::host::{argv_environ_values, fd_prestats, fd_table}; use crate::host::{argv_environ_values, fd_prestats, fd_table};
use crate::instantiate::WASIState; use crate::instantiate::WASIState;
use core::convert::TryFrom;
use cranelift_codegen::ir::types::{Type, I32, I64}; use cranelift_codegen::ir::types::{Type, I32, I64};
use host; use host;
use std::convert::TryFrom;
use std::{mem, ptr, slice, str}; use std::{mem, ptr, slice, str};
use translate::*; use translate::*;
use wasm32; use wasm32;

View File

@@ -1,5 +1,5 @@
use core::convert::TryFrom;
use host; use host;
use std::convert::TryFrom;
use std::mem::{align_of, size_of, zeroed}; use std::mem::{align_of, size_of, zeroed};
use std::slice; use std::slice;
use wasm32; use wasm32;

View File

@@ -107,7 +107,7 @@ fn bindgen_test_layout_fsid_t() {
concat!("Alignment of ", stringify!(fsid_t)) concat!("Alignment of ", stringify!(fsid_t))
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<fsid_t>())).__val as *const _ as usize }, unsafe { &(*(::core::ptr::null::<fsid_t>())).__val as *const _ as usize },
0usize, 0usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -166,7 +166,7 @@ fn bindgen_test_layout_wasi_dirent_t() {
concat!("Size of: ", stringify!(__wasi_dirent_t)) concat!("Size of: ", stringify!(__wasi_dirent_t))
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_next as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_dirent_t>())).d_next as *const _ as usize },
0usize, 0usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -176,7 +176,7 @@ fn bindgen_test_layout_wasi_dirent_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_ino as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_dirent_t>())).d_ino as *const _ as usize },
8usize, 8usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -186,7 +186,7 @@ fn bindgen_test_layout_wasi_dirent_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_namlen as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_dirent_t>())).d_namlen as *const _ as usize },
16usize, 16usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -196,7 +196,7 @@ fn bindgen_test_layout_wasi_dirent_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_dirent_t>())).d_type as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_dirent_t>())).d_type as *const _ as usize },
20usize, 20usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -248,7 +248,7 @@ fn bindgen_test_layout___wasi_event_t___wasi_event_u___wasi_event_u_fd_readwrite
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::<__wasi_event_t___wasi_event_u___wasi_event_u_fd_readwrite_t>())) &(*(::core::ptr::null::<__wasi_event_t___wasi_event_u___wasi_event_u_fd_readwrite_t>()))
.nbytes as *const _ as usize .nbytes as *const _ as usize
}, },
0usize, 0usize,
@@ -261,7 +261,7 @@ fn bindgen_test_layout___wasi_event_t___wasi_event_u___wasi_event_u_fd_readwrite
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::<__wasi_event_t___wasi_event_u___wasi_event_u_fd_readwrite_t>())) &(*(::core::ptr::null::<__wasi_event_t___wasi_event_u___wasi_event_u_fd_readwrite_t>()))
.flags as *const _ as usize .flags as *const _ as usize
}, },
8usize, 8usize,
@@ -287,7 +287,7 @@ fn bindgen_test_layout___wasi_event_t___wasi_event_u() {
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::<__wasi_event_t___wasi_event_u>())).fd_readwrite as *const _ &(*(::core::ptr::null::<__wasi_event_t___wasi_event_u>())).fd_readwrite as *const _
as usize as usize
}, },
0usize, 0usize,
@@ -312,7 +312,7 @@ fn bindgen_test_layout___wasi_event_t() {
concat!("Alignment of ", stringify!(__wasi_event_t)) concat!("Alignment of ", stringify!(__wasi_event_t))
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).userdata as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_event_t>())).userdata as *const _ as usize },
0usize, 0usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -322,7 +322,7 @@ fn bindgen_test_layout___wasi_event_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).error as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_event_t>())).error as *const _ as usize },
8usize, 8usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -332,7 +332,7 @@ fn bindgen_test_layout___wasi_event_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).type_ as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_event_t>())).type_ as *const _ as usize },
10usize, 10usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -342,7 +342,7 @@ fn bindgen_test_layout___wasi_event_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).u as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_event_t>())).u as *const _ as usize },
16usize, 16usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -388,7 +388,7 @@ fn bindgen_test_layout___wasi_prestat_t___wasi_prestat_u___wasi_prestat_u_dir_t(
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::<__wasi_prestat_t___wasi_prestat_u___wasi_prestat_u_dir_t>())) &(*(::core::ptr::null::<__wasi_prestat_t___wasi_prestat_u___wasi_prestat_u_dir_t>()))
.pr_name_len as *const _ as usize .pr_name_len as *const _ as usize
}, },
0usize, 0usize,
@@ -417,7 +417,7 @@ fn bindgen_test_layout___wasi_prestat_t___wasi_prestat_u() {
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::<__wasi_prestat_t___wasi_prestat_u>())).dir as *const _ as usize &(*(::core::ptr::null::<__wasi_prestat_t___wasi_prestat_u>())).dir as *const _ as usize
}, },
0usize, 0usize,
concat!( concat!(
@@ -441,7 +441,7 @@ fn bindgen_test_layout___wasi_prestat_t() {
concat!("Alignment of ", stringify!(__wasi_prestat_t)) concat!("Alignment of ", stringify!(__wasi_prestat_t))
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_prestat_t>())).pr_type as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_prestat_t>())).pr_type as *const _ as usize },
0usize, 0usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -451,7 +451,7 @@ fn bindgen_test_layout___wasi_prestat_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_prestat_t>())).u as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_prestat_t>())).u as *const _ as usize },
4usize, 4usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -488,7 +488,7 @@ fn bindgen_test_layout_wasi_event_t__bindgen_ty_1__bindgen_ty_1() {
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::<__wasi_event_t__bindgen_ty_1__bindgen_ty_1>())).nbytes &(*(::core::ptr::null::<__wasi_event_t__bindgen_ty_1__bindgen_ty_1>())).nbytes
as *const _ as usize as *const _ as usize
}, },
0usize, 0usize,
@@ -501,8 +501,8 @@ fn bindgen_test_layout_wasi_event_t__bindgen_ty_1__bindgen_ty_1() {
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::<__wasi_event_t__bindgen_ty_1__bindgen_ty_1>())).flags as *const _ &(*(::core::ptr::null::<__wasi_event_t__bindgen_ty_1__bindgen_ty_1>())).flags
as usize as *const _ as usize
}, },
8usize, 8usize,
concat!( concat!(
@@ -540,7 +540,7 @@ fn bindgen_test_layout_wasi_event_t__bindgen_ty_1__bindgen_ty_2() {
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::<__wasi_event_t__bindgen_ty_1__bindgen_ty_2>())).signal &(*(::core::ptr::null::<__wasi_event_t__bindgen_ty_1__bindgen_ty_2>())).signal
as *const _ as usize as *const _ as usize
}, },
0usize, 0usize,
@@ -553,7 +553,7 @@ fn bindgen_test_layout_wasi_event_t__bindgen_ty_1__bindgen_ty_2() {
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::<__wasi_event_t__bindgen_ty_1__bindgen_ty_2>())).exitcode &(*(::core::ptr::null::<__wasi_event_t__bindgen_ty_1__bindgen_ty_2>())).exitcode
as *const _ as usize as *const _ as usize
}, },
4usize, 4usize,
@@ -575,7 +575,7 @@ fn bindgen_test_layout_wasi_event_t__bindgen_ty_1() {
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::<__wasi_event_t__bindgen_ty_1>())).fd_readwrite as *const _ &(*(::core::ptr::null::<__wasi_event_t__bindgen_ty_1>())).fd_readwrite as *const _
as usize as usize
}, },
0usize, 0usize,
@@ -595,7 +595,7 @@ fn bindgen_test_layout_wasi_event_t() {
concat!("Size of: ", stringify!(__wasi_event_t)) concat!("Size of: ", stringify!(__wasi_event_t))
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).userdata as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_event_t>())).userdata as *const _ as usize },
0usize, 0usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -605,7 +605,7 @@ fn bindgen_test_layout_wasi_event_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).error as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_event_t>())).error as *const _ as usize },
8usize, 8usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -615,7 +615,7 @@ fn bindgen_test_layout_wasi_event_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_event_t>())).type_ as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_event_t>())).type_ as *const _ as usize },
10usize, 10usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -642,7 +642,7 @@ fn bindgen_test_layout_wasi_fdstat_t() {
concat!("Size of: ", stringify!(__wasi_fdstat_t)) concat!("Size of: ", stringify!(__wasi_fdstat_t))
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_filetype as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_fdstat_t>())).fs_filetype as *const _ as usize },
0usize, 0usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -652,7 +652,7 @@ fn bindgen_test_layout_wasi_fdstat_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_flags as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_fdstat_t>())).fs_flags as *const _ as usize },
2usize, 2usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -662,7 +662,7 @@ fn bindgen_test_layout_wasi_fdstat_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_rights_base as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_fdstat_t>())).fs_rights_base as *const _ as usize },
8usize, 8usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -673,7 +673,7 @@ fn bindgen_test_layout_wasi_fdstat_t() {
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::<__wasi_fdstat_t>())).fs_rights_inheriting as *const _ as usize &(*(::core::ptr::null::<__wasi_fdstat_t>())).fs_rights_inheriting as *const _ as usize
}, },
16usize, 16usize,
concat!( concat!(
@@ -704,7 +704,7 @@ fn bindgen_test_layout_wasi_filestat_t() {
concat!("Size of: ", stringify!(__wasi_filestat_t)) concat!("Size of: ", stringify!(__wasi_filestat_t))
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).st_dev as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_filestat_t>())).st_dev as *const _ as usize },
0usize, 0usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -714,7 +714,7 @@ fn bindgen_test_layout_wasi_filestat_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).st_ino as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_filestat_t>())).st_ino as *const _ as usize },
8usize, 8usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -724,7 +724,7 @@ fn bindgen_test_layout_wasi_filestat_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).st_filetype as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_filestat_t>())).st_filetype as *const _ as usize },
16usize, 16usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -734,7 +734,7 @@ fn bindgen_test_layout_wasi_filestat_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).st_nlink as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_filestat_t>())).st_nlink as *const _ as usize },
20usize, 20usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -744,7 +744,7 @@ fn bindgen_test_layout_wasi_filestat_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).st_size as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_filestat_t>())).st_size as *const _ as usize },
24usize, 24usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -754,7 +754,7 @@ fn bindgen_test_layout_wasi_filestat_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).st_atim as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_filestat_t>())).st_atim as *const _ as usize },
32usize, 32usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -764,7 +764,7 @@ fn bindgen_test_layout_wasi_filestat_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).st_mtim as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_filestat_t>())).st_mtim as *const _ as usize },
40usize, 40usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -774,7 +774,7 @@ fn bindgen_test_layout_wasi_filestat_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_filestat_t>())).st_ctim as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_filestat_t>())).st_ctim as *const _ as usize },
48usize, 48usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -803,7 +803,7 @@ fn bindgen_test_layout_wasi_ciovec_t() {
concat!("Alignment of ", stringify!(__wasi_ciovec_t)) concat!("Alignment of ", stringify!(__wasi_ciovec_t))
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_ciovec_t>())).buf as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_ciovec_t>())).buf as *const _ as usize },
0usize, 0usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -813,7 +813,7 @@ fn bindgen_test_layout_wasi_ciovec_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_ciovec_t>())).buf_len as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_ciovec_t>())).buf_len as *const _ as usize },
4usize, 4usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -842,7 +842,7 @@ fn bindgen_test_layout_wasi_iovec_t() {
concat!("Alignment of ", stringify!(__wasi_iovec_t)) concat!("Alignment of ", stringify!(__wasi_iovec_t))
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_iovec_t>())).buf as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_iovec_t>())).buf as *const _ as usize },
0usize, 0usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -852,7 +852,7 @@ fn bindgen_test_layout_wasi_iovec_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_iovec_t>())).buf_len as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_iovec_t>())).buf_len as *const _ as usize },
4usize, 4usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -913,7 +913,7 @@ fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u___wasi_subscr
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::< &(*(::core::ptr::null::<
__wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t, __wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t,
>())) >()))
.identifier as *const _ as usize .identifier as *const _ as usize
@@ -928,7 +928,7 @@ fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u___wasi_subscr
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::< &(*(::core::ptr::null::<
__wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t, __wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t,
>())) >()))
.clock_id as *const _ as usize .clock_id as *const _ as usize
@@ -943,7 +943,7 @@ fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u___wasi_subscr
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::< &(*(::core::ptr::null::<
__wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t, __wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t,
>())) >()))
.timeout as *const _ as usize .timeout as *const _ as usize
@@ -958,7 +958,7 @@ fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u___wasi_subscr
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::< &(*(::core::ptr::null::<
__wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t, __wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t,
>())) >()))
.precision as *const _ as usize .precision as *const _ as usize
@@ -973,7 +973,7 @@ fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u___wasi_subscr
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::< &(*(::core::ptr::null::<
__wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t, __wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t,
>())) >()))
.flags as *const _ as usize .flags as *const _ as usize
@@ -1021,7 +1021,7 @@ fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u___wasi_subscr
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::< &(*(::core::ptr::null::<
__wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_fd_readwrite_t, __wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_fd_readwrite_t,
>())) >()))
.fd as *const _ as usize .fd as *const _ as usize
@@ -1057,7 +1057,7 @@ fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u() {
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::<__wasi_subscription_t___wasi_subscription_u>())).clock &(*(::core::ptr::null::<__wasi_subscription_t___wasi_subscription_u>())).clock
as *const _ as usize as *const _ as usize
}, },
0usize, 0usize,
@@ -1070,7 +1070,7 @@ fn bindgen_test_layout___wasi_subscription_t___wasi_subscription_u() {
); );
assert_eq!( assert_eq!(
unsafe { unsafe {
&(*(::std::ptr::null::<__wasi_subscription_t___wasi_subscription_u>())).fd_readwrite &(*(::core::ptr::null::<__wasi_subscription_t___wasi_subscription_u>())).fd_readwrite
as *const _ as usize as *const _ as usize
}, },
0usize, 0usize,
@@ -1095,7 +1095,7 @@ fn bindgen_test_layout___wasi_subscription_t() {
concat!("Alignment of ", stringify!(__wasi_subscription_t)) concat!("Alignment of ", stringify!(__wasi_subscription_t))
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_subscription_t>())).userdata as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_subscription_t>())).userdata as *const _ as usize },
0usize, 0usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -1105,7 +1105,7 @@ fn bindgen_test_layout___wasi_subscription_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_subscription_t>())).type_ as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_subscription_t>())).type_ as *const _ as usize },
8usize, 8usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",
@@ -1115,7 +1115,7 @@ fn bindgen_test_layout___wasi_subscription_t() {
) )
); );
assert_eq!( assert_eq!(
unsafe { &(*(::std::ptr::null::<__wasi_subscription_t>())).u as *const _ as usize }, unsafe { &(*(::core::ptr::null::<__wasi_subscription_t>())).u as *const _ as usize },
16usize, 16usize,
concat!( concat!(
"Offset of field: ", "Offset of field: ",

View File

@@ -1,12 +1,12 @@
use super::syscalls; use super::syscalls;
use alloc::rc::Rc;
use core::cell::RefCell;
use cranelift_codegen::ir::types; use cranelift_codegen::ir::types;
use cranelift_codegen::{ir, isa}; use cranelift_codegen::{ir, isa};
use cranelift_entity::PrimaryMap; use cranelift_entity::PrimaryMap;
use cranelift_wasm::DefinedFuncIndex; use cranelift_wasm::DefinedFuncIndex;
use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
use std::fs::File; use std::fs::File;
use std::rc::Rc;
use target_lexicon::HOST; use target_lexicon::HOST;
use wasi_common::WasiCtxBuilder; use wasi_common::WasiCtxBuilder;
use wasmtime_environ::{translate_signature, Export, Module}; use wasmtime_environ::{translate_signature, Export, Module};

View File

@@ -1,3 +1,5 @@
extern crate alloc;
mod instantiate; mod instantiate;
mod syscalls; mod syscalls;

View File

@@ -22,6 +22,7 @@
) )
)] )]
extern crate alloc;
#[macro_use] #[macro_use]
extern crate failure_derive; extern crate failure_derive;

View File

@@ -1,10 +1,10 @@
use alloc::rc::Rc;
use core::cell::RefCell;
use cranelift_codegen::ir::types; use cranelift_codegen::ir::types;
use cranelift_codegen::{ir, isa}; use cranelift_codegen::{ir, isa};
use cranelift_entity::PrimaryMap; use cranelift_entity::PrimaryMap;
use cranelift_wasm::{DefinedFuncIndex, Global, GlobalInit, Memory, Table, TableElementType}; use cranelift_wasm::{DefinedFuncIndex, Global, GlobalInit, Memory, Table, TableElementType};
use std::cell::RefCell; use std::collections::hash_map::HashMap;
use std::collections::HashMap;
use std::rc::Rc;
use target_lexicon::HOST; use target_lexicon::HOST;
use wasmtime_environ::{translate_signature, Export, MemoryPlan, Module, TablePlan}; use wasmtime_environ::{translate_signature, Export, MemoryPlan, Module, TablePlan};
use wasmtime_jit::target_tunables; use wasmtime_jit::target_tunables;