Update no_std support.

This `no_std` support isn't complete though, as some dependencies
don't support it.
This commit is contained in:
Dan Gohman
2019-01-03 14:00:03 -08:00
parent f6c2fe7d2d
commit ca2fdc5ccb
21 changed files with 81 additions and 70 deletions

View File

@@ -13,16 +13,17 @@ use crate::vmcontext::{
VMGlobalImport, VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition,
VMTableImport,
};
use core::slice;
use core::{mem, ptr};
use cranelift_entity::EntityRef;
use cranelift_entity::{BoxedSlice, PrimaryMap};
use cranelift_wasm::{
DefinedFuncIndex, DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex, FuncIndex,
GlobalIndex, GlobalInit, MemoryIndex, SignatureIndex, TableIndex,
};
use std::borrow::ToOwned;
use std::rc::Rc;
use std::slice;
use std::string::String;
use std::{mem, ptr};
use wasmtime_environ::{DataInitializer, Module, TableElements, VMOffsets};
fn signature_id(

View File

@@ -21,15 +21,24 @@
clippy::use_self
)
)]
#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]
#![cfg_attr(not(feature = "std"), feature(alloc))]
#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc as std;
#[cfg(feature = "std")]
#[macro_use]
extern crate std;
#[cfg(not(feature = "std"))]
use hashmap_core::{map as hash_map, HashMap};
#[cfg(feature = "std")]
use std::collections::{hash_map, HashMap};
use errno;
use region;
#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;
#[macro_use]
extern crate lazy_static;
use libc;
@@ -66,10 +75,3 @@ pub use crate::vmcontext::{
VMContext, VMFunctionBody, VMFunctionImport, VMGlobalDefinition, VMGlobalImport,
VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport,
};
#[cfg(not(feature = "std"))]
mod std {
pub use alloc::{string, vec};
pub use core::*;
pub use core::{i32, str, u32};
}

View File

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

View File

@@ -1,10 +1,10 @@
//! Implement a registry of function signatures, for fast indirect call
//! signature checking.
use super::{hash_map, HashMap};
use crate::vmcontext::VMSharedSignatureIndex;
use cast;
use cranelift_codegen::ir;
use std::collections::{hash_map, HashMap};
/// WebAssembly requires that the caller and callee signatures in an indirect
/// call must match. To implement this efficiently, keep a registry of all

View File

@@ -5,8 +5,8 @@
#![allow(non_snake_case)]
use crate::vmcontext::VMContext;
use std::borrow::{Borrow, BorrowMut};
use std::cell::RefCell;
use core::borrow::{Borrow, BorrowMut};
use core::cell::RefCell;
use std::sync::RwLock;
include!(concat!(env!("OUT_DIR"), "/signalhandlers.rs"));

View File

@@ -4,6 +4,7 @@
use crate::vmcontext::{VMCallerCheckedAnyfunc, VMTableDefinition};
use cranelift_wasm::TableElementType;
use std::vec::Vec;
use wasmtime_environ::{TablePlan, TableStyle};
/// A table instance.

View File

@@ -3,11 +3,12 @@
use crate::signalhandlers::jmp_buf;
use crate::vmcontext::{VMContext, VMFunctionBody};
use core::cell::{Cell, RefCell};
use core::mem;
use core::ptr;
use libc::c_int;
use std::cell::{Cell, RefCell};
use std::mem;
use std::ptr;
use std::string::String;
use std::vec::Vec;
// Currently we uset setjmp/longjmp to unwind out of a signal handler
// and back to the point where WebAssembly was called (via `call_wasm`).

View File

@@ -2,7 +2,7 @@
//! fields that compiled wasm code accesses directly.
use crate::instance::InstanceContents;
use std::{ptr, u32};
use core::{ptr, u32};
/// An imported function.
#[derive(Debug, Copy, Clone)]
@@ -18,7 +18,7 @@ pub struct VMFunctionImport {
#[cfg(test)]
mod test_vmfunction_import {
use super::VMFunctionImport;
use std::mem::size_of;
use core::mem::size_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -50,7 +50,7 @@ pub struct VMFunctionBody(u8);
#[cfg(test)]
mod test_vmfunction_body {
use super::VMFunctionBody;
use std::mem::size_of;
use core::mem::size_of;
#[test]
fn check_vmfunction_body_offsets() {
@@ -73,7 +73,7 @@ pub struct VMTableImport {
#[cfg(test)]
mod test_vmtable_import {
use super::VMTableImport;
use std::mem::size_of;
use core::mem::size_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -110,7 +110,7 @@ pub struct VMMemoryImport {
#[cfg(test)]
mod test_vmmemory_import {
use super::VMMemoryImport;
use std::mem::size_of;
use core::mem::size_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -144,7 +144,7 @@ pub struct VMGlobalImport {
#[cfg(test)]
mod test_vmglobal_import {
use super::VMGlobalImport;
use std::mem::size_of;
use core::mem::size_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -178,7 +178,7 @@ pub struct VMMemoryDefinition {
#[cfg(test)]
mod test_vmmemory_definition {
use super::VMMemoryDefinition;
use std::mem::size_of;
use core::mem::size_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -221,7 +221,7 @@ pub struct VMTableDefinition {
#[cfg(test)]
mod test_vmtable_definition {
use super::VMTableDefinition;
use std::mem::size_of;
use core::mem::size_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -257,7 +257,7 @@ pub struct VMGlobalDefinition {
#[cfg(test)]
mod test_vmglobal_definition {
use super::VMGlobalDefinition;
use std::mem::{align_of, size_of};
use core::mem::{align_of, size_of};
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -391,7 +391,7 @@ pub struct VMSharedSignatureIndex(u32);
#[cfg(test)]
mod test_vmshared_signature_index {
use super::VMSharedSignatureIndex;
use std::mem::size_of;
use core::mem::size_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]
@@ -427,7 +427,7 @@ pub struct VMCallerCheckedAnyfunc {
#[cfg(test)]
mod test_vmcaller_checked_anyfunc {
use super::VMCallerCheckedAnyfunc;
use std::mem::size_of;
use core::mem::size_of;
use wasmtime_environ::{Module, VMOffsets};
#[test]