Initial reorg.
This is largely the same as #305, but updated for the current tree.
This commit is contained in:
25
crates/wasi/Cargo.toml
Normal file
25
crates/wasi/Cargo.toml
Normal file
@@ -0,0 +1,25 @@
|
||||
[package]
|
||||
name = "wasmtime-wasi"
|
||||
version = "0.2.0"
|
||||
authors = ["The Cranelift Project Developers"]
|
||||
description = "WASI API support for Wasmtime"
|
||||
categories = ["wasm"]
|
||||
repository = "https://github.com/CraneStation/wasmtime"
|
||||
license = "Apache-2.0 WITH LLVM-exception"
|
||||
readme = "README.md"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
wasmtime-runtime = { path = "../runtime" }
|
||||
wasmtime-environ = { path = "../environ" }
|
||||
wasmtime-jit = { path = "../jit" }
|
||||
wasi-common = { path = "../wasi-common" }
|
||||
cranelift-codegen = { version = "0.49", features = ["enable-serde"] }
|
||||
cranelift-entity = { version = "0.49", features = ["enable-serde"] }
|
||||
cranelift-wasm = { version = "0.49", features = ["enable-serde"] }
|
||||
target-lexicon = "0.9.0"
|
||||
log = { version = "0.4.8", default-features = false }
|
||||
|
||||
[badges]
|
||||
maintenance = { status = "experimental" }
|
||||
travis-ci = { repository = "CraneStation/wasmtime" }
|
||||
220
crates/wasi/LICENSE
Normal file
220
crates/wasi/LICENSE
Normal file
@@ -0,0 +1,220 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
--- LLVM Exceptions to the Apache 2.0 License ----
|
||||
|
||||
As an exception, if, as a result of your compiling your source code, portions
|
||||
of this Software are embedded into an Object form of such source code, you
|
||||
may redistribute such embedded portions in such Object form without complying
|
||||
with the conditions of Sections 4(a), 4(b) and 4(d) of the License.
|
||||
|
||||
In addition, if you combine or link compiled forms of this Software with
|
||||
software that is licensed under the GPLv2 ("Combined Software") and if a
|
||||
court of competent jurisdiction determines that the patent provision (Section
|
||||
3), the indemnity provision (Section 9) or other Section of the License
|
||||
conflicts with the conditions of the GPLv2, you may retroactively and
|
||||
prospectively choose to deem waived or otherwise exclude such Section(s) of
|
||||
the License, but only in their entirety and only with respect to the Combined
|
||||
Software.
|
||||
|
||||
8
crates/wasi/README.md
Normal file
8
crates/wasi/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
This is the `wasmtime-wasi` crate, which implements the
|
||||
WebAssembly System Interface (WASI) API in Rust.
|
||||
|
||||
WASI is greatly inspired by and directly derived from [CloudABI].
|
||||
It differs in that it has aspirations to expand to a greater
|
||||
scope, and to better support the needs of WebAssembly engines.
|
||||
|
||||
[CloudABI]: https://cloudabi.org/
|
||||
2
crates/wasi/js-polyfill/README.md
Normal file
2
crates/wasi/js-polyfill/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
For the current polyfill sources, please checkout this same directory in
|
||||
[the polyfill branch](https://github.com/CraneStation/wasmtime/tree/polyfill/).
|
||||
BIN
crates/wasi/js-polyfill/WASI-small.png
Normal file
BIN
crates/wasi/js-polyfill/WASI-small.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
145
crates/wasi/src/instantiate.rs
Normal file
145
crates/wasi/src/instantiate.rs
Normal file
@@ -0,0 +1,145 @@
|
||||
use super::syscalls;
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
use cranelift_codegen::ir::types;
|
||||
use cranelift_codegen::{ir, isa};
|
||||
use cranelift_entity::PrimaryMap;
|
||||
use cranelift_wasm::DefinedFuncIndex;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use target_lexicon::HOST;
|
||||
use wasi_common::{WasiCtx, WasiCtxBuilder};
|
||||
use wasmtime_environ::{translate_signature, Export, Module};
|
||||
use wasmtime_runtime::{Imports, InstanceHandle, InstantiationError, VMFunctionBody};
|
||||
|
||||
/// Return an instance implementing the "wasi" interface.
|
||||
pub fn instantiate_wasi(
|
||||
prefix: &str,
|
||||
global_exports: Rc<RefCell<HashMap<String, Option<wasmtime_runtime::Export>>>>,
|
||||
preopened_dirs: &[(String, File)],
|
||||
argv: &[String],
|
||||
environ: &[(String, String)],
|
||||
) -> Result<InstanceHandle, InstantiationError> {
|
||||
let mut wasi_ctx_builder = WasiCtxBuilder::new()
|
||||
.inherit_stdio()
|
||||
.args(argv)
|
||||
.envs(environ);
|
||||
|
||||
for (dir, f) in preopened_dirs {
|
||||
wasi_ctx_builder = wasi_ctx_builder.preopened_dir(
|
||||
f.try_clone().map_err(|err| {
|
||||
InstantiationError::Resource(format!(
|
||||
"couldn't clone an instance handle to pre-opened dir: {}",
|
||||
err
|
||||
))
|
||||
})?,
|
||||
dir,
|
||||
);
|
||||
}
|
||||
|
||||
let wasi_ctx = wasi_ctx_builder.build().map_err(|err| {
|
||||
InstantiationError::Resource(format!("couldn't assemble WASI context object: {}", err))
|
||||
})?;
|
||||
instantiate_wasi_with_context(prefix, global_exports, wasi_ctx)
|
||||
}
|
||||
|
||||
/// Return an instance implementing the "wasi" interface.
|
||||
///
|
||||
/// The wasi context is configured by
|
||||
pub fn instantiate_wasi_with_context(
|
||||
prefix: &str,
|
||||
global_exports: Rc<RefCell<HashMap<String, Option<wasmtime_runtime::Export>>>>,
|
||||
wasi_ctx: WasiCtx,
|
||||
) -> Result<InstanceHandle, InstantiationError> {
|
||||
let pointer_type = types::Type::triple_pointer_type(&HOST);
|
||||
let mut module = Module::new();
|
||||
let mut finished_functions: PrimaryMap<DefinedFuncIndex, *const VMFunctionBody> =
|
||||
PrimaryMap::new();
|
||||
let call_conv = isa::CallConv::triple_default(&HOST);
|
||||
|
||||
macro_rules! signature {
|
||||
($name:ident) => {{
|
||||
let sig = module.signatures.push(translate_signature(
|
||||
ir::Signature {
|
||||
params: syscalls::$name::params()
|
||||
.into_iter()
|
||||
.map(ir::AbiParam::new)
|
||||
.collect(),
|
||||
returns: syscalls::$name::results()
|
||||
.into_iter()
|
||||
.map(ir::AbiParam::new)
|
||||
.collect(),
|
||||
call_conv,
|
||||
},
|
||||
pointer_type,
|
||||
));
|
||||
let func = module.functions.push(sig);
|
||||
module.exports.insert(
|
||||
prefix.to_owned() + stringify!($name),
|
||||
Export::Function(func),
|
||||
);
|
||||
finished_functions.push(syscalls::$name::SHIM as *const VMFunctionBody);
|
||||
}};
|
||||
}
|
||||
|
||||
signature!(args_get);
|
||||
signature!(args_sizes_get);
|
||||
signature!(clock_res_get);
|
||||
signature!(clock_time_get);
|
||||
signature!(environ_get);
|
||||
signature!(environ_sizes_get);
|
||||
signature!(fd_prestat_get);
|
||||
signature!(fd_prestat_dir_name);
|
||||
signature!(fd_close);
|
||||
signature!(fd_datasync);
|
||||
signature!(fd_pread);
|
||||
signature!(fd_pwrite);
|
||||
signature!(fd_read);
|
||||
signature!(fd_renumber);
|
||||
signature!(fd_seek);
|
||||
signature!(fd_tell);
|
||||
signature!(fd_fdstat_get);
|
||||
signature!(fd_fdstat_set_flags);
|
||||
signature!(fd_fdstat_set_rights);
|
||||
signature!(fd_sync);
|
||||
signature!(fd_write);
|
||||
signature!(fd_advise);
|
||||
signature!(fd_allocate);
|
||||
signature!(path_create_directory);
|
||||
signature!(path_link);
|
||||
signature!(path_open);
|
||||
signature!(fd_readdir);
|
||||
signature!(path_readlink);
|
||||
signature!(path_rename);
|
||||
signature!(fd_filestat_get);
|
||||
signature!(fd_filestat_set_times);
|
||||
signature!(fd_filestat_set_size);
|
||||
signature!(path_filestat_get);
|
||||
signature!(path_filestat_set_times);
|
||||
signature!(path_symlink);
|
||||
signature!(path_unlink_file);
|
||||
signature!(path_remove_directory);
|
||||
signature!(poll_oneoff);
|
||||
signature!(proc_exit);
|
||||
signature!(proc_raise);
|
||||
signature!(random_get);
|
||||
signature!(sched_yield);
|
||||
signature!(sock_recv);
|
||||
signature!(sock_send);
|
||||
signature!(sock_shutdown);
|
||||
|
||||
let imports = Imports::none();
|
||||
let data_initializers = Vec::new();
|
||||
let signatures = PrimaryMap::new();
|
||||
|
||||
InstanceHandle::new(
|
||||
Rc::new(module),
|
||||
global_exports,
|
||||
finished_functions.into_boxed_slice(),
|
||||
imports,
|
||||
&data_initializers,
|
||||
signatures.into_boxed_slice(),
|
||||
None,
|
||||
Box::new(wasi_ctx),
|
||||
)
|
||||
}
|
||||
6
crates/wasi/src/lib.rs
Normal file
6
crates/wasi/src/lib.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
extern crate alloc;
|
||||
|
||||
mod instantiate;
|
||||
mod syscalls;
|
||||
|
||||
pub use instantiate::{instantiate_wasi, instantiate_wasi_with_context};
|
||||
977
crates/wasi/src/syscalls.rs
Normal file
977
crates/wasi/src/syscalls.rs
Normal file
@@ -0,0 +1,977 @@
|
||||
use cranelift_codegen::ir::types::{Type, I32, I64};
|
||||
use log::{error, trace};
|
||||
use wasi_common::{hostcalls, wasi, wasi32, WasiCtx};
|
||||
use wasmtime_runtime::{Export, VMContext};
|
||||
|
||||
pub trait AbiRet {
|
||||
type Abi;
|
||||
fn convert(self) -> Self::Abi;
|
||||
fn codegen_tys() -> Vec<Type>;
|
||||
}
|
||||
|
||||
pub trait AbiParam {
|
||||
type Abi;
|
||||
fn convert(arg: Self::Abi) -> Self;
|
||||
fn codegen_ty() -> Type;
|
||||
}
|
||||
|
||||
macro_rules! cast32 {
|
||||
($($i:ident)*) => ($(
|
||||
impl AbiRet for $i {
|
||||
type Abi = i32;
|
||||
|
||||
fn convert(self) -> Self::Abi {
|
||||
self as i32
|
||||
}
|
||||
|
||||
fn codegen_tys() -> Vec<Type> { vec![I32] }
|
||||
}
|
||||
|
||||
impl AbiParam for $i {
|
||||
type Abi = i32;
|
||||
|
||||
fn convert(param: i32) -> Self {
|
||||
param as $i
|
||||
}
|
||||
|
||||
fn codegen_ty() -> Type { I32 }
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
||||
macro_rules! cast64 {
|
||||
($($i:ident)*) => ($(
|
||||
impl AbiRet for $i {
|
||||
type Abi = i64;
|
||||
|
||||
fn convert(self) -> Self::Abi {
|
||||
self as i64
|
||||
}
|
||||
|
||||
fn codegen_tys() -> Vec<Type> { vec![I64] }
|
||||
}
|
||||
|
||||
impl AbiParam for $i {
|
||||
type Abi = i64;
|
||||
|
||||
fn convert(param: i64) -> Self {
|
||||
param as $i
|
||||
}
|
||||
|
||||
fn codegen_ty() -> Type { I64 }
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
||||
cast32!(i8 i16 i32 u8 u16 u32);
|
||||
cast64!(i64 u64);
|
||||
|
||||
impl AbiRet for () {
|
||||
type Abi = ();
|
||||
fn convert(self) {}
|
||||
fn codegen_tys() -> Vec<Type> {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
fn get_wasi_ctx(vmctx: &mut VMContext) -> Result<&mut WasiCtx, wasi::__wasi_errno_t> {
|
||||
unsafe {
|
||||
vmctx
|
||||
.host_state()
|
||||
.downcast_mut::<WasiCtx>()
|
||||
.ok_or_else(|| panic!("no host state named WasiCtx available"))
|
||||
}
|
||||
}
|
||||
|
||||
fn get_memory(vmctx: &mut VMContext) -> Result<&mut [u8], wasi::__wasi_errno_t> {
|
||||
unsafe {
|
||||
match vmctx.lookup_global_export("memory") {
|
||||
Some(Export::Memory {
|
||||
definition,
|
||||
vmctx: _,
|
||||
memory: _,
|
||||
}) => Ok(std::slice::from_raw_parts_mut(
|
||||
(*definition).base,
|
||||
(*definition).current_length,
|
||||
)),
|
||||
x => {
|
||||
error!(
|
||||
"no export named \"memory\", or the export isn't a mem: {:?}",
|
||||
x
|
||||
);
|
||||
Err(wasi::__WASI_EINVAL)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! ok_or_errno {
|
||||
($expr:expr) => {
|
||||
match $expr {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
trace!(" -> errno={}", wasi::strerror(e));
|
||||
return e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! syscalls {
|
||||
($(pub unsafe extern "C" fn $name:ident($ctx:ident: *mut VMContext $(, $arg:ident: $ty:ty)*,) -> $ret:ty {
|
||||
$($body:tt)*
|
||||
})*) => ($(
|
||||
pub mod $name {
|
||||
use super::*;
|
||||
|
||||
/// Returns the codegen types of all the parameters to the shim
|
||||
/// generated
|
||||
pub fn params() -> Vec<Type> {
|
||||
vec![$(<$ty as AbiParam>::codegen_ty()),*]
|
||||
}
|
||||
|
||||
/// Returns the codegen types of all the results of the shim
|
||||
/// generated
|
||||
pub fn results() -> Vec<Type> {
|
||||
<$ret as AbiRet>::codegen_tys()
|
||||
}
|
||||
|
||||
/// The actual function pointer to the shim for a syscall.
|
||||
///
|
||||
/// NB: ideally we'd expose `shim` below, but it seems like there's
|
||||
/// a compiler bug which prvents that from being cast to a `usize`.
|
||||
pub static SHIM: unsafe extern "C" fn(
|
||||
*mut VMContext,
|
||||
$(<$ty as AbiParam>::Abi),*
|
||||
) -> <$ret as AbiRet>::Abi = shim;
|
||||
|
||||
unsafe extern "C" fn shim(
|
||||
$ctx: *mut VMContext,
|
||||
$($arg: <$ty as AbiParam>::Abi,)*
|
||||
) -> <$ret as AbiRet>::Abi {
|
||||
let r = super::$name($ctx, $(<$ty as AbiParam>::convert($arg),)*);
|
||||
<$ret as AbiRet>::convert(r)
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn $name($ctx: *mut VMContext, $($arg: $ty,)*) -> $ret {
|
||||
$($body)*
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
||||
syscalls! {
|
||||
pub unsafe extern "C" fn args_get(
|
||||
vmctx: *mut VMContext,
|
||||
argv: wasi32::uintptr_t,
|
||||
argv_buf: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"args_get(argv={:#x?}, argv_buf={:#x?})",
|
||||
argv,
|
||||
argv_buf,
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::args_get(wasi_ctx, memory, argv, argv_buf)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn args_sizes_get(
|
||||
vmctx: *mut VMContext,
|
||||
argc: wasi32::uintptr_t,
|
||||
argv_buf_size: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"args_sizes_get(argc={:#x?}, argv_buf_size={:#x?})",
|
||||
argc,
|
||||
argv_buf_size,
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::args_sizes_get(wasi_ctx, memory, argc, argv_buf_size)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn clock_res_get(
|
||||
vmctx: *mut VMContext,
|
||||
clock_id: wasi::__wasi_clockid_t,
|
||||
resolution: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"clock_res_get(clock_id={:?}, resolution={:#x?})",
|
||||
clock_id,
|
||||
resolution,
|
||||
);
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::clock_res_get(memory, clock_id, resolution)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn clock_time_get(
|
||||
vmctx: *mut VMContext,
|
||||
clock_id: wasi::__wasi_clockid_t,
|
||||
precision: wasi::__wasi_timestamp_t,
|
||||
time: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"clock_time_get(clock_id={:?}, precision={:?}, time={:#x?})",
|
||||
clock_id,
|
||||
precision,
|
||||
time,
|
||||
);
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::clock_time_get(memory, clock_id, precision, time)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn environ_get(
|
||||
vmctx: *mut VMContext,
|
||||
environ: wasi32::uintptr_t,
|
||||
environ_buf: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"environ_get(environ={:#x?}, environ_buf={:#x?})",
|
||||
environ,
|
||||
environ_buf,
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::environ_get(wasi_ctx, memory, environ, environ_buf)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn environ_sizes_get(
|
||||
vmctx: *mut VMContext,
|
||||
environ_count: wasi32::uintptr_t,
|
||||
environ_buf_size: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"environ_sizes_get(environ_count={:#x?}, environ_buf_size={:#x?})",
|
||||
environ_count,
|
||||
environ_buf_size,
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::environ_sizes_get(wasi_ctx, memory, environ_count, environ_buf_size)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_prestat_get(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
buf: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!("fd_prestat_get(fd={:?}, buf={:#x?})", fd, buf);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::fd_prestat_get(wasi_ctx, memory, fd, buf)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_prestat_dir_name(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
path: wasi32::uintptr_t,
|
||||
path_len: wasi32::size_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!("fd_prestat_dir_name(fd={:?}, path={:#x?}, path_len={})", fd, path, path_len);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::fd_prestat_dir_name(wasi_ctx, memory, fd, path, path_len)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_close(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!("fd_close(fd={:?})", fd);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
hostcalls::fd_close(wasi_ctx, fd)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_datasync(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!("fd_datasync(fd={:?})", fd);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
hostcalls::fd_datasync(wasi_ctx, fd)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_pread(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
iovs: wasi32::uintptr_t,
|
||||
iovs_len: wasi32::size_t,
|
||||
offset: wasi::__wasi_filesize_t,
|
||||
nread: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"fd_pread(fd={:?}, iovs={:#x?}, iovs_len={:?}, offset={}, nread={:#x?})",
|
||||
fd,
|
||||
iovs,
|
||||
iovs_len,
|
||||
offset,
|
||||
nread
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::fd_pread(
|
||||
wasi_ctx,
|
||||
memory,
|
||||
fd,
|
||||
iovs,
|
||||
iovs_len,
|
||||
offset,
|
||||
nread
|
||||
)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_pwrite(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
iovs: wasi32::uintptr_t,
|
||||
iovs_len: wasi32::size_t,
|
||||
offset: wasi::__wasi_filesize_t,
|
||||
nwritten: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"fd_pwrite(fd={:?}, iovs={:#x?}, iovs_len={:?}, offset={}, nwritten={:#x?})",
|
||||
fd,
|
||||
iovs,
|
||||
iovs_len,
|
||||
offset,
|
||||
nwritten
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::fd_pwrite(
|
||||
wasi_ctx,
|
||||
memory,
|
||||
fd,
|
||||
iovs,
|
||||
iovs_len,
|
||||
offset,
|
||||
nwritten
|
||||
)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_read(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
iovs: wasi32::uintptr_t,
|
||||
iovs_len: wasi32::size_t,
|
||||
nread: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"fd_read(fd={:?}, iovs={:#x?}, iovs_len={:?}, nread={:#x?})",
|
||||
fd,
|
||||
iovs,
|
||||
iovs_len,
|
||||
nread
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::fd_read(wasi_ctx, memory, fd, iovs, iovs_len, nread)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_renumber(
|
||||
vmctx: *mut VMContext,
|
||||
from: wasi::__wasi_fd_t,
|
||||
to: wasi::__wasi_fd_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!("fd_renumber(from={:?}, to={:?})", from, to);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
hostcalls::fd_renumber(wasi_ctx, from, to)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_seek(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
offset: wasi::__wasi_filedelta_t,
|
||||
whence: wasi::__wasi_whence_t,
|
||||
newoffset: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"fd_seek(fd={:?}, offset={:?}, whence={}, newoffset={:#x?})",
|
||||
fd,
|
||||
offset,
|
||||
wasi::whence_to_str(whence),
|
||||
newoffset
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::fd_seek(wasi_ctx, memory, fd, offset, whence, newoffset)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_tell(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
newoffset: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!("fd_tell(fd={:?}, newoffset={:#x?})", fd, newoffset);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::fd_tell(wasi_ctx, memory, fd, newoffset)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_fdstat_get(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
buf: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!("fd_fdstat_get(fd={:?}, buf={:#x?})", fd, buf);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::fd_fdstat_get(wasi_ctx, memory, fd, buf)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_fdstat_set_flags(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
flags: wasi::__wasi_fdflags_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"fd_fdstat_set_flags(fd={:?}, flags={:#x?})",
|
||||
fd,
|
||||
flags
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
hostcalls::fd_fdstat_set_flags(wasi_ctx, fd, flags)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_fdstat_set_rights(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
fs_rights_base: wasi::__wasi_rights_t,
|
||||
fs_rights_inheriting: wasi::__wasi_rights_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"fd_fdstat_set_rights(fd={:?}, fs_rights_base={:#x?}, fs_rights_inheriting={:#x?})",
|
||||
fd,
|
||||
fs_rights_base,
|
||||
fs_rights_inheriting
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
hostcalls::fd_fdstat_set_rights(
|
||||
wasi_ctx,
|
||||
fd,
|
||||
fs_rights_base,
|
||||
fs_rights_inheriting
|
||||
)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_sync(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!("fd_sync(fd={:?})", fd);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
hostcalls::fd_sync(wasi_ctx, fd)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_write(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
iovs: wasi32::uintptr_t,
|
||||
iovs_len: wasi32::size_t,
|
||||
nwritten: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"fd_write(fd={:?}, iovs={:#x?}, iovs_len={:?}, nwritten={:#x?})",
|
||||
fd,
|
||||
iovs,
|
||||
iovs_len,
|
||||
nwritten
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::fd_write(wasi_ctx, memory, fd, iovs, iovs_len, nwritten)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_advise(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
offset: wasi::__wasi_filesize_t,
|
||||
len: wasi::__wasi_filesize_t,
|
||||
advice: wasi::__wasi_advice_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"fd_advise(fd={:?}, offset={}, len={}, advice={:?})",
|
||||
fd,
|
||||
offset,
|
||||
len,
|
||||
advice
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
hostcalls::fd_advise(wasi_ctx, fd, offset, len, advice)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_allocate(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
offset: wasi::__wasi_filesize_t,
|
||||
len: wasi::__wasi_filesize_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!("fd_allocate(fd={:?}, offset={}, len={})", fd, offset, len);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
hostcalls::fd_allocate(wasi_ctx, fd, offset, len)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn path_create_directory(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
path: wasi32::uintptr_t,
|
||||
path_len: wasi32::size_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"path_create_directory(fd={:?}, path={:#x?}, path_len={})",
|
||||
fd,
|
||||
path,
|
||||
path_len,
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::path_create_directory(wasi_ctx, memory, fd, path, path_len)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn path_link(
|
||||
vmctx: *mut VMContext,
|
||||
fd0: wasi::__wasi_fd_t,
|
||||
flags0: wasi::__wasi_lookupflags_t,
|
||||
path0: wasi32::uintptr_t,
|
||||
path_len0: wasi32::size_t,
|
||||
fd1: wasi::__wasi_fd_t,
|
||||
path1: wasi32::uintptr_t,
|
||||
path_len1: wasi32::size_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"path_link(fd0={:?}, flags0={:?}, path0={:#x?}, path_len0={}, fd1={:?}, path1={:#x?}, path_len1={})",
|
||||
fd0,
|
||||
flags0,
|
||||
path0,
|
||||
path_len0,
|
||||
fd1,
|
||||
path1,
|
||||
path_len1
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::path_link(
|
||||
wasi_ctx,
|
||||
memory,
|
||||
fd0,
|
||||
flags0,
|
||||
path0,
|
||||
path_len0,
|
||||
fd1,
|
||||
path1,
|
||||
path_len1
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: When multi-value happens, switch to that instead of passing
|
||||
// the `fd` by reference?
|
||||
pub unsafe extern "C" fn path_open(
|
||||
vmctx: *mut VMContext,
|
||||
dirfd: wasi::__wasi_fd_t,
|
||||
dirflags: wasi::__wasi_lookupflags_t,
|
||||
path: wasi32::uintptr_t,
|
||||
path_len: wasi32::size_t,
|
||||
oflags: wasi::__wasi_oflags_t,
|
||||
fs_rights_base: wasi::__wasi_rights_t,
|
||||
fs_rights_inheriting: wasi::__wasi_rights_t,
|
||||
fs_flags: wasi::__wasi_fdflags_t,
|
||||
fd: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"path_open(dirfd={:?}, dirflags={:?}, path={:#x?}, path_len={:?}, oflags={:#x?}, fs_rights_base={:#x?}, fs_rights_inheriting={:#x?}, fs_flags={:#x?}, fd={:#x?})",
|
||||
dirfd,
|
||||
dirflags,
|
||||
path,
|
||||
path_len,
|
||||
oflags,
|
||||
fs_rights_base,
|
||||
fs_rights_inheriting,
|
||||
fs_flags,
|
||||
fd
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::path_open(
|
||||
wasi_ctx,
|
||||
memory,
|
||||
dirfd,
|
||||
dirflags,
|
||||
path,
|
||||
path_len,
|
||||
oflags,
|
||||
fs_rights_base,
|
||||
fs_rights_inheriting,
|
||||
fs_flags,
|
||||
fd
|
||||
)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_readdir(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
buf: wasi32::uintptr_t,
|
||||
buf_len: wasi32::size_t,
|
||||
cookie: wasi::__wasi_dircookie_t,
|
||||
buf_used: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"fd_readdir(fd={:?}, buf={:#x?}, buf_len={}, cookie={:#x?}, buf_used={:#x?})",
|
||||
fd,
|
||||
buf,
|
||||
buf_len,
|
||||
cookie,
|
||||
buf_used,
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::fd_readdir(
|
||||
wasi_ctx,
|
||||
memory,
|
||||
fd,
|
||||
buf,
|
||||
buf_len,
|
||||
cookie,
|
||||
buf_used
|
||||
)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn path_readlink(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
path: wasi32::uintptr_t,
|
||||
path_len: wasi32::size_t,
|
||||
buf: wasi32::uintptr_t,
|
||||
buf_len: wasi32::size_t,
|
||||
buf_used: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"path_readlink(fd={:?}, path={:#x?}, path_len={:?}, buf={:#x?}, buf_len={}, buf_used={:#x?})",
|
||||
fd,
|
||||
path,
|
||||
path_len,
|
||||
buf,
|
||||
buf_len,
|
||||
buf_used,
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::path_readlink(
|
||||
wasi_ctx,
|
||||
memory,
|
||||
fd,
|
||||
path,
|
||||
path_len,
|
||||
buf,
|
||||
buf_len,
|
||||
buf_used
|
||||
)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn path_rename(
|
||||
vmctx: *mut VMContext,
|
||||
fd0: wasi::__wasi_fd_t,
|
||||
path0: wasi32::uintptr_t,
|
||||
path_len0: wasi32::size_t,
|
||||
fd1: wasi::__wasi_fd_t,
|
||||
path1: wasi32::uintptr_t,
|
||||
path_len1: wasi32::size_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"path_rename(fd0={:?}, path0={:#x?}, path_len0={:?}, fd1={:?}, path1={:#x?}, path_len1={:?})",
|
||||
fd0,
|
||||
path0,
|
||||
path_len0,
|
||||
fd1,
|
||||
path1,
|
||||
path_len1,
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::path_rename(
|
||||
wasi_ctx,
|
||||
memory,
|
||||
fd0,
|
||||
path0,
|
||||
path_len0,
|
||||
fd1,
|
||||
path1,
|
||||
path_len1
|
||||
)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_filestat_get(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
buf: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!("fd_filestat_get(fd={:?}, buf={:#x?})", fd, buf);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::fd_filestat_get(wasi_ctx, memory, fd, buf)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_filestat_set_times(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
st_atim: wasi::__wasi_timestamp_t,
|
||||
st_mtim: wasi::__wasi_timestamp_t,
|
||||
fstflags: wasi::__wasi_fstflags_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"fd_filestat_set_times(fd={:?}, st_atim={}, st_mtim={}, fstflags={:#x?})",
|
||||
fd,
|
||||
st_atim, st_mtim,
|
||||
fstflags
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
hostcalls::fd_filestat_set_times(wasi_ctx, fd, st_atim, st_mtim, fstflags)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn fd_filestat_set_size(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
size: wasi::__wasi_filesize_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"fd_filestat_set_size(fd={:?}, size={})",
|
||||
fd,
|
||||
size
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
hostcalls::fd_filestat_set_size(wasi_ctx, fd, size)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn path_filestat_get(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
flags: wasi::__wasi_lookupflags_t,
|
||||
path: wasi32::uintptr_t,
|
||||
path_len: wasi32::size_t,
|
||||
buf: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"path_filestat_get(fd={:?}, flags={:?}, path={:#x?}, path_len={}, buf={:#x?})",
|
||||
fd,
|
||||
flags,
|
||||
path,
|
||||
path_len,
|
||||
buf
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::path_filestat_get(wasi_ctx, memory, fd, flags, path, path_len, buf)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn path_filestat_set_times(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
flags: wasi::__wasi_lookupflags_t,
|
||||
path: wasi32::uintptr_t,
|
||||
path_len: wasi32::size_t,
|
||||
st_atim: wasi::__wasi_timestamp_t,
|
||||
st_mtim: wasi::__wasi_timestamp_t,
|
||||
fstflags: wasi::__wasi_fstflags_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"path_filestat_set_times(fd={:?}, flags={:?}, path={:#x?}, path_len={}, st_atim={}, st_mtim={}, fstflags={:#x?})",
|
||||
fd,
|
||||
flags,
|
||||
path,
|
||||
path_len,
|
||||
st_atim, st_mtim,
|
||||
fstflags
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::path_filestat_set_times(
|
||||
wasi_ctx,
|
||||
memory,
|
||||
fd,
|
||||
flags,
|
||||
path,
|
||||
path_len,
|
||||
st_atim,
|
||||
st_mtim,
|
||||
fstflags
|
||||
)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn path_symlink(
|
||||
vmctx: *mut VMContext,
|
||||
path0: wasi32::uintptr_t,
|
||||
path_len0: wasi32::size_t,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
path1: wasi32::uintptr_t,
|
||||
path_len1: wasi32::size_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"path_symlink(path0={:#x?}, path_len0={}, fd={:?}, path1={:#x?}, path_len1={})",
|
||||
path0,
|
||||
path_len0,
|
||||
fd,
|
||||
path1,
|
||||
path_len1
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::path_symlink(
|
||||
wasi_ctx,
|
||||
memory,
|
||||
path0,
|
||||
path_len0,
|
||||
fd,
|
||||
path1,
|
||||
path_len1
|
||||
)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn path_unlink_file(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
path: wasi32::uintptr_t,
|
||||
path_len: wasi32::size_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"path_unlink_file(fd={:?}, path={:#x?}, path_len={})",
|
||||
fd,
|
||||
path,
|
||||
path_len
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::path_unlink_file(wasi_ctx, memory, fd, path, path_len)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn path_remove_directory(
|
||||
vmctx: *mut VMContext,
|
||||
fd: wasi::__wasi_fd_t,
|
||||
path: wasi32::uintptr_t,
|
||||
path_len: wasi32::size_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"path_remove_directory(fd={:?}, path={:#x?}, path_len={})",
|
||||
fd,
|
||||
path,
|
||||
path_len
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::path_remove_directory(wasi_ctx, memory, fd, path, path_len)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn poll_oneoff(
|
||||
vmctx: *mut VMContext,
|
||||
in_: wasi32::uintptr_t,
|
||||
out: wasi32::uintptr_t,
|
||||
nsubscriptions: wasi32::size_t,
|
||||
nevents: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"poll_oneoff(in={:#x?}, out={:#x?}, nsubscriptions={}, nevents={:#x?})",
|
||||
in_,
|
||||
out,
|
||||
nsubscriptions,
|
||||
nevents,
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::poll_oneoff(wasi_ctx, memory, in_, out, nsubscriptions, nevents)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn proc_exit(_vmctx: *mut VMContext, rval: u32,) -> () {
|
||||
trace!("proc_exit(rval={:?})", rval);
|
||||
hostcalls::proc_exit(rval)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn proc_raise(
|
||||
vmctx: *mut VMContext,
|
||||
sig: wasi::__wasi_signal_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!("proc_raise(sig={:?})", sig);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::proc_raise(wasi_ctx, memory, sig)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn random_get(
|
||||
vmctx: *mut VMContext,
|
||||
buf: wasi32::uintptr_t,
|
||||
buf_len: wasi32::size_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!("random_get(buf={:#x?}, buf_len={:?})", buf, buf_len);
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::random_get(memory, buf, buf_len)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn sched_yield(_vmctx: *mut VMContext,) -> wasi::__wasi_errno_t {
|
||||
trace!("sched_yield(void)");
|
||||
hostcalls::sched_yield()
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn sock_recv(
|
||||
vmctx: *mut VMContext,
|
||||
sock: wasi::__wasi_fd_t,
|
||||
ri_data: wasi32::uintptr_t,
|
||||
ri_data_len: wasi32::size_t,
|
||||
ri_flags: wasi::__wasi_riflags_t,
|
||||
ro_datalen: wasi32::uintptr_t,
|
||||
ro_flags: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"sock_recv(sock={:?}, ri_data={:#x?}, ri_data_len={}, ri_flags={:#x?}, ro_datalen={:#x?}, ro_flags={:#x?})",
|
||||
sock,
|
||||
ri_data, ri_data_len, ri_flags,
|
||||
ro_datalen, ro_flags
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::sock_recv(
|
||||
wasi_ctx,
|
||||
memory,
|
||||
sock,
|
||||
ri_data,
|
||||
ri_data_len,
|
||||
ri_flags,
|
||||
ro_datalen,
|
||||
ro_flags
|
||||
)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn sock_send(
|
||||
vmctx: *mut VMContext,
|
||||
sock: wasi::__wasi_fd_t,
|
||||
si_data: wasi32::uintptr_t,
|
||||
si_data_len: wasi32::size_t,
|
||||
si_flags: wasi::__wasi_siflags_t,
|
||||
so_datalen: wasi32::uintptr_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!(
|
||||
"sock_send(sock={:?}, si_data={:#x?}, si_data_len={}, si_flags={:#x?}, so_datalen={:#x?})",
|
||||
sock,
|
||||
si_data, si_data_len, si_flags, so_datalen,
|
||||
);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::sock_send(
|
||||
wasi_ctx,
|
||||
memory,
|
||||
sock,
|
||||
si_data,
|
||||
si_data_len,
|
||||
si_flags,
|
||||
so_datalen
|
||||
)
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn sock_shutdown(
|
||||
vmctx: *mut VMContext,
|
||||
sock: wasi::__wasi_fd_t,
|
||||
how: wasi::__wasi_sdflags_t,
|
||||
) -> wasi::__wasi_errno_t {
|
||||
trace!("sock_shutdown(sock={:?}, how={:?})", sock, how);
|
||||
let wasi_ctx = ok_or_errno!(get_wasi_ctx(&mut *vmctx));
|
||||
let memory = ok_or_errno!(get_memory(&mut *vmctx));
|
||||
hostcalls::sock_shutdown(wasi_ctx, memory, sock, how)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user