From fc60790dd4100dc84760e5658aad935141b85986 Mon Sep 17 00:00:00 2001 From: Jernej Kos Date: Sun, 28 Nov 2021 12:51:32 +0100 Subject: [PATCH 1/4] wasm3-sys: Compile with -fno-stack-protector on SGX --- wasm3-sys/build.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/wasm3-sys/build.rs b/wasm3-sys/build.rs index 0eb18c3..aae4ba5 100644 --- a/wasm3-sys/build.rs +++ b/wasm3-sys/build.rs @@ -106,8 +106,20 @@ fn main() { .extra_warnings(false) .include(WASM3_SOURCE); + let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); + let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap(); + let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap(); + + // Set options specific for x86_64-fortanix-unknown-sgx target. + if target_arch == "x86_64" && target_env == "sgx" && target_vendor == "fortanix" { + // Disable the stack protector as the Fortanix ABI currently sets FS and GS bases to the + // same value and the stack protector assumes the canary value is at FS:0x28 but with the + // Fortanix ABI that contains a copy of RSP. + cfg.flag("-fno-stack-protector"); + } + // Add any extra arguments from the environment to the CC command line. - if let Ok(extra_clang_args) = std::env::var("BINDGEN_EXTRA_CLANG_ARGS") { + if let Ok(extra_clang_args) = env::var("BINDGEN_EXTRA_CLANG_ARGS") { // Try to parse it with shell quoting. If we fail, make it one single big argument. if let Some(strings) = shlex::split(&extra_clang_args) { strings.iter().for_each(|string| { From 23b41109f495cb7e9423c510ee1533ec9dff9b89 Mon Sep 17 00:00:00 2001 From: Jernej Kos Date: Sun, 28 Nov 2021 13:05:20 +0100 Subject: [PATCH 2/4] wasm3-sys: Cleanup --- wasm3-sys/Cargo.toml | 10 +++++----- wasm3-sys/build.rs | 46 ++++---------------------------------------- 2 files changed, 9 insertions(+), 47 deletions(-) diff --git a/wasm3-sys/Cargo.toml b/wasm3-sys/Cargo.toml index d20a23e..2a787ba 100644 --- a/wasm3-sys/Cargo.toml +++ b/wasm3-sys/Cargo.toml @@ -1,11 +1,12 @@ [package] name = "wasm3-sys" version = "0.2.0" -authors = ["Lukas Tobias Wirth "] +authors = [ + "Oasis Protocol Foundation ", + "Lukas Tobias Wirth " +] edition = "2018" -description = "Raw ffi bindings for wasm3" -homepage = "https://github.com/veykril/wasm3-rs" -repository = "https://github.com/veykril/wasm3-rs" +description = "Raw FFI bindings for wasm3" categories = ["external-ffi-bindings"] build = "build.rs" license = "MIT" @@ -13,7 +14,6 @@ links = "wasm3" include = ["wasm3/source/**/*", "src/**/*", "Cargo.toml", "build.rs"] [features] -wasi = [] use-32bit-slots = [] floats = [] diff --git a/wasm3-sys/build.rs b/wasm3-sys/build.rs index aae4ba5..9b69f0e 100644 --- a/wasm3-sys/build.rs +++ b/wasm3-sys/build.rs @@ -1,8 +1,4 @@ -use std::env; -use std::ffi::OsStr; -use std::fmt::Write as _; -use std::fs; -use std::path::{Path, PathBuf}; +use std::{env, ffi::OsStr, fs, path::PathBuf}; static WASM3_SOURCE: &str = "wasm3/source"; const WHITELIST_REGEX_FUNCTION: &str = "([A-Z]|m3_).*"; @@ -12,36 +8,12 @@ const PRIMITIVES: &[&str] = &[ "f64", "f32", "u64", "i64", "u32", "i32", "u16", "i16", "u8", "i8", ]; -fn gen_wrapper(out_path: &Path) -> PathBuf { - // TODO: we currently need the field definitions of the structs of wasm3. These aren't exposed - // in the wasm3.h header so we have to generate bindings for more. - let wrapper_file = out_path.join("wrapper.h"); - - let mut buffer = String::new(); - fs::read_dir(WASM3_SOURCE) - .unwrap_or_else(|_| panic!("failed to read {} directory", WASM3_SOURCE)) - .filter_map(Result::ok) - .map(|entry| entry.path()) - .filter(|path| path.extension().and_then(OsStr::to_str) == Some("h")) - .for_each(|path| { - writeln!( - &mut buffer, - "#include \"{}\"", - path.file_name().unwrap().to_str().unwrap() - ) - .unwrap() - }); - fs::write(&wrapper_file, buffer).expect("failed to create wasm3 wrapper file"); - wrapper_file -} - fn gen_bindings() { let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); - let wrapper_file = gen_wrapper(&out_path); - let mut bindgen = bindgen::builder() - .header(wrapper_file.to_str().unwrap()) + .header("wasm3/source/wasm3.h") + .header("wasm3/source/m3_env.h") .use_core() .ctypes_prefix("cty") .layout_tests(false) @@ -69,13 +41,8 @@ fn gen_bindings() { ), &format!( "-Dd_m3HasFloat={}", - if cfg!(feature = "floats") { - 1 - } else { - 0 - } + if cfg!(feature = "floats") { 1 } else { 0 } ), - "-Dd_m3LogOutput=0", "-Dd_m3VerboseErrorMessages=0", "-Iwasm3/source", ] @@ -101,7 +68,6 @@ fn main() { ); cfg.cpp(false) - .define("d_m3LogOutput", Some("0")) .warnings(false) .extra_warnings(false) .include(WASM3_SOURCE); @@ -130,10 +96,6 @@ fn main() { }; } - if cfg!(feature = "wasi") { - cfg.define("d_m3HasWASI", None); - } - cfg.define( "d_m3Use32BitSlots", if cfg!(feature = "use-32bit-slots") { From 86399a9bf78cbb00904b1d6ea6a2339e3d9af637 Mon Sep 17 00:00:00 2001 From: Jernej Kos Date: Sun, 28 Nov 2021 13:06:03 +0100 Subject: [PATCH 3/4] Add rustfmt configuration file --- .rustfmt.toml | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 18 ++++++++------- 2 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 .rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..715b2b1 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,63 @@ +max_width = 100 +hard_tabs = false +tab_spaces = 4 +newline_style = "Auto" +use_small_heuristics = "Default" +indent_style = "Block" +wrap_comments = false +format_code_in_doc_comments = false +comment_width = 80 +normalize_comments = false +normalize_doc_attributes = false +format_strings = false +format_macro_matchers = false +format_macro_bodies = true +empty_item_single_line = true +struct_lit_single_line = true +fn_single_line = false +where_single_line = false +imports_indent = "Block" +imports_layout = "Mixed" +imports_granularity = "Crate" +reorder_imports = true +reorder_modules = true +reorder_impl_items = false +type_punctuation_density = "Wide" +space_before_colon = false +space_after_colon = true +spaces_around_ranges = false +binop_separator = "Front" +remove_nested_parens = true +combine_control_expr = true +overflow_delimited_expr = false +struct_field_align_threshold = 0 +enum_discrim_align_threshold = 0 +match_arm_blocks = true +force_multiline_blocks = false +fn_args_layout = "Tall" +brace_style = "SameLineWhere" +control_brace_style = "AlwaysSameLine" +trailing_semicolon = true +trailing_comma = "Vertical" +match_block_trailing_comma = false +blank_lines_upper_bound = 1 +blank_lines_lower_bound = 0 +edition = "2015" +version = "One" +merge_derives = true +use_try_shorthand = false +use_field_init_shorthand = false +force_explicit_abi = true +condense_wildcard_suffixes = false +color = "Auto" +unstable_features = false +disable_all_formatting = false +skip_children = false +hide_parse_errors = false +error_on_line_overflow = false +error_on_unformatted = false +report_todo = "Never" +report_fixme = "Never" +ignore = [] +emit_mode = "Files" +make_backup = false diff --git a/src/lib.rs b/src/lib.rs index a6835ee..d64b7a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,14 +5,16 @@ #[allow(unused_extern_crates)] extern crate rs_libc; -use std::any::Any; -use std::boxed::Box; -use std::cell::{RefCell, UnsafeCell}; -use std::convert::TryInto; -use std::ffi::{CStr, CString}; -use std::marker::PhantomData; -use std::pin::Pin; -use std::ptr::{self, NonNull}; +use std::{ + any::Any, + boxed::Box, + cell::{RefCell, UnsafeCell}, + convert::TryInto, + ffi::{CStr, CString}, + marker::PhantomData, + pin::Pin, + ptr::{self, NonNull}, +}; use impl_trait_for_tuples::impl_for_tuples; use thiserror::Error; From 93bb9f2b1a0789099c7eab6c96c92e47b065f8f8 Mon Sep 17 00:00:00 2001 From: Jernej Kos Date: Sun, 28 Nov 2021 13:06:45 +0100 Subject: [PATCH 4/4] Bump version to 0.3.0 --- Cargo.toml | 2 +- wasm3-sys/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 470b65a..cd0474a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm3" -version = "0.2.0" +version = "0.3.0" authors = [ "Oasis Protocol Foundation ", "Lukas Tobias Wirth " diff --git a/wasm3-sys/Cargo.toml b/wasm3-sys/Cargo.toml index 2a787ba..b95f2cb 100644 --- a/wasm3-sys/Cargo.toml +++ b/wasm3-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm3-sys" -version = "0.2.0" +version = "0.3.0" authors = [ "Oasis Protocol Foundation ", "Lukas Tobias Wirth "