Skip to content

Commit

Permalink
Merge #2320
Browse files Browse the repository at this point in the history
2320: Remove unnecessary code r=syrusakbary a=syrusakbary


<!-- 
Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test:
https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests

-->

# Description
Cranelift has already fixed the SystemV ABI, so it’s safe to remove the WASI Wrappers
<!-- 
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->

# Review

- [ ] Add a short description of the change to the CHANGELOG.md file


Co-authored-by: Syrus Akbary <[email protected]>
  • Loading branch information
bors[bot] and syrusakbary authored May 18, 2021
2 parents 93a68be + c5fb503 commit 85c37e5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 70 deletions.
12 changes: 1 addition & 11 deletions lib/engine/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,7 @@ pub fn resolve_imports(
// TODO: We should check that the f.vmctx actually matches
// the shape of `VMDynamicFunctionImportContext`
}
VMFunctionKind::Static => {
// The native ABI for functions fails when defining a function natively in
// macos (Darwin) with the Apple Silicon ARM chip, for functions with more than 10 args
// TODO: Cranelift should have a good ABI for the ABI
if cfg!(all(target_os = "macos", target_arch = "aarch64")) {
let num_params = f.vm_function.signature.params().len();
assert!(num_params < 9, "Only native functions with less than 9 arguments are allowed in Apple Silicon (for now). Received {} in the import {}.{}", num_params, module_name, field);
}

f.vm_function.address
}
VMFunctionKind::Static => f.vm_function.address,
};

// Clone the host env for this `Instance`.
Expand Down
34 changes: 2 additions & 32 deletions lib/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ use wasmer::{
imports, ChainableNamedResolver, Function, ImportObject, LazyInit, Memory, Module,
NamedResolver, Store, WasmerEnv,
};
#[cfg(all(target_os = "macos", target_arch = "aarch64",))]
use wasmer::{FunctionType, ValType};

use std::sync::{Arc, Mutex, MutexGuard};

Expand Down Expand Up @@ -146,34 +144,6 @@ pub fn generate_import_object_from_env(
}
}

// Note: we use this wrapper because native functions with more than 9 params
// fail on Apple Silicon (with Cranelift).
fn get_path_open_for_store(store: &Store, env: WasiEnv) -> Function {
#[cfg(not(all(target_os = "macos", target_arch = "aarch64",)))]
let path_open = Function::new_native_with_env(store, env, path_open);
#[cfg(all(target_os = "macos", target_arch = "aarch64",))]
let path_open = Function::new_with_env(
store,
FunctionType::new(
vec![
ValType::I32,
ValType::I32,
ValType::I32,
ValType::I32,
ValType::I32,
ValType::I64,
ValType::I64,
ValType::I32,
ValType::I32,
],
vec![ValType::I32],
),
env.clone(),
path_open_dynamic,
);
path_open
}

/// Combines a state generating function with the import list for legacy WASI
fn generate_import_object_snapshot0(store: &Store, env: WasiEnv) -> ImportObject {
imports! {
Expand Down Expand Up @@ -209,7 +179,7 @@ fn generate_import_object_snapshot0(store: &Store, env: WasiEnv) -> ImportObject
"path_filestat_get" => Function::new_native_with_env(store, env.clone(), legacy::snapshot0::path_filestat_get),
"path_filestat_set_times" => Function::new_native_with_env(store, env.clone(), path_filestat_set_times),
"path_link" => Function::new_native_with_env(store, env.clone(), path_link),
"path_open" => get_path_open_for_store(store, env.clone()),
"path_open" => Function::new_native_with_env(store, env.clone(), path_open),
"path_readlink" => Function::new_native_with_env(store, env.clone(), path_readlink),
"path_remove_directory" => Function::new_native_with_env(store, env.clone(), path_remove_directory),
"path_rename" => Function::new_native_with_env(store, env.clone(), path_rename),
Expand Down Expand Up @@ -262,7 +232,7 @@ fn generate_import_object_snapshot1(store: &Store, env: WasiEnv) -> ImportObject
"path_filestat_get" => Function::new_native_with_env(store, env.clone(), path_filestat_get),
"path_filestat_set_times" => Function::new_native_with_env(store, env.clone(), path_filestat_set_times),
"path_link" => Function::new_native_with_env(store, env.clone(), path_link),
"path_open" => get_path_open_for_store(store, env.clone()),
"path_open" => Function::new_native_with_env(store, env.clone(), path_open),
"path_readlink" => Function::new_native_with_env(store, env.clone(), path_readlink),
"path_remove_directory" => Function::new_native_with_env(store, env.clone(), path_remove_directory),
"path_rename" => Function::new_native_with_env(store, env.clone(), path_rename),
Expand Down
27 changes: 0 additions & 27 deletions lib/wasi/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1886,33 +1886,6 @@ pub fn path_open(
__WASI_ESUCCESS
}

// Note: we define path_open_dynamic because native functions with more than 9 params
// fail on Apple Silicon (with Cranelift).
pub fn path_open_dynamic(env: &WasiEnv, params: &[Value]) -> Result<Vec<Value>, RuntimeError> {
let dirfd: __wasi_fd_t = params[0].unwrap_i32() as _;
let dirflags: __wasi_lookupflags_t = params[1].unwrap_i32() as _;
let path: WasmPtr<u8, Array> = params[2].unwrap_i32().into();
let path_len: u32 = params[3].unwrap_i32() as _;
let o_flags: __wasi_oflags_t = params[4].unwrap_i32() as _;
let fs_rights_base: __wasi_rights_t = params[5].unwrap_i64() as _;
let fs_rights_inheriting: __wasi_rights_t = params[6].unwrap_i64() as _;
let fs_flags: __wasi_fdflags_t = params[7].unwrap_i32() as _;
let fd: WasmPtr<__wasi_fd_t> = params[8].unwrap_i32().into();

Ok(vec![Value::I32(path_open(
env,
dirfd,
dirflags,
path,
path_len,
o_flags,
fs_rights_base,
fs_rights_inheriting,
fs_flags,
fd,
) as i32)])
}

/// ### `path_readlink()`
/// Read the value of a symlink
/// Inputs:
Expand Down

0 comments on commit 85c37e5

Please sign in to comment.