Migrate to wasi-common crate

This commit is contained in:
Jakub Konka
2019-05-04 14:23:47 +02:00
committed by Dan Gohman
parent 3dfeab50ad
commit e8142f076d
30 changed files with 477 additions and 7744 deletions

View File

@@ -37,11 +37,10 @@ use cranelift_codegen::settings;
use cranelift_codegen::settings::Configurable;
use cranelift_native;
use docopt::Docopt;
use errno::errno;
use file_per_thread_logger;
use pretty_env_logger;
use std::error::Error;
use std::ffi::{CString, OsStr};
use std::ffi::OsStr;
use std::fs::File;
use std::io;
use std::io::prelude::*;
@@ -114,22 +113,15 @@ fn read_wasm(path: PathBuf) -> Result<Vec<u8>, String> {
})
}
fn compute_preopen_dirs(flag_dir: &[String], flag_mapdir: &[String]) -> Vec<(String, libc::c_int)> {
fn compute_preopen_dirs(flag_dir: &[String], flag_mapdir: &[String]) -> Vec<(String, File)> {
let mut preopen_dirs = Vec::new();
for dir in flag_dir {
let fd = unsafe {
libc::open(
CString::new(dir.as_bytes()).unwrap().as_ptr(),
libc::O_RDONLY | libc::O_DIRECTORY,
)
};
if fd < 0 {
println!("error while pre-opening directory {}: {}", dir, errno());
let preopen_dir = File::open(dir).unwrap_or_else(|err| {
println!("error while pre-opening directory {}: {}", dir, err);
exit(1);
}
preopen_dirs.push((dir.clone(), fd));
});
preopen_dirs.push((dir.clone(), preopen_dir));
}
for mapdir in flag_mapdir {
@@ -139,18 +131,11 @@ fn compute_preopen_dirs(flag_dir: &[String], flag_mapdir: &[String]) -> Vec<(Str
exit(1);
}
let (key, value) = (parts[0], parts[1]);
let fd = unsafe {
libc::open(
CString::new(value.as_bytes()).unwrap().as_ptr(),
libc::O_RDONLY | libc::O_DIRECTORY,
)
};
if fd < 0 {
println!("error while pre-opening directory {}: {}", value, errno());
let preopen_dir = File::open(value).unwrap_or_else(|err| {
println!("error while pre-opening directory {}: {}", value, err);
exit(1);
}
preopen_dirs.push((key.to_string(), fd));
});
preopen_dirs.push((key.to_string(), preopen_dir));
}
preopen_dirs

View File

@@ -13,18 +13,12 @@ readme = "README.md"
wasmtime-runtime = { path = "../wasmtime-runtime" }
wasmtime-environ = { path = "../wasmtime-environ" }
wasmtime-jit = { path = "../wasmtime-jit" }
wasi-common = { git = "https://github.com/CraneStation/wasi-common" }
cranelift-codegen = "0.30.0"
cranelift-entity = "0.30.0"
cranelift-wasm = "0.30.0"
target-lexicon = "0.3.0"
cast = { version = "0.2.2", default-features = false }
log = { version = "0.4.6", default-features = false }
libc = "0.2.50"
errno = "0.2.4"
[build-dependencies]
cmake = "0.1.35"
bindgen = "0.49.0"
[badges]
maintenance = { status = "experimental" }

View File

@@ -1,118 +0,0 @@
extern crate bindgen;
extern crate cmake;
use cmake::Config;
use std::env;
use std::path::PathBuf;
fn main() {
let dst = Config::new("sandboxed-system-primitives")
.cflag("-std=gnu99")
.build();
println!("cargo:rustc-link-search=native={}", dst.display());
println!("cargo:rustc-link-lib=static=SandboxedSystemPrimitives");
let bindings_builder = bindgen::Builder::default()
.header("sandboxed-system-primitives/include/wasmtime_ssp.h")
.header("sandboxed-system-primitives/src/posix.h")
.whitelist_function("wasmtime_ssp_.*")
.whitelist_function("fd_table_init")
.whitelist_function("fd_table_insert_existing")
.whitelist_function("fd_prestats_init")
.whitelist_function("fd_prestats_insert")
.whitelist_function("argv_environ_init")
.whitelist_function("rwlock_.*")
.whitelist_type("__wasi_.*")
.whitelist_type("fd_table")
.whitelist_type("fd_prestat")
.whitelist_type("fd_prestats")
.whitelist_type("argv_environ_values")
.whitelist_var("__WASI_.*")
.blacklist_item("__WASI_ESUCCESS")
.blacklist_item("__WASI_E2BIG")
.blacklist_item("__WASI_EACCES")
.blacklist_item("__WASI_EADDRINUSE")
.blacklist_item("__WASI_EADDRNOTAVAIL")
.blacklist_item("__WASI_EAFNOSUPPORT")
.blacklist_item("__WASI_EAGAIN")
.blacklist_item("__WASI_EALREADY")
.blacklist_item("__WASI_EBADF")
.blacklist_item("__WASI_EBADMSG")
.blacklist_item("__WASI_EBUSY")
.blacklist_item("__WASI_ECANCELED")
.blacklist_item("__WASI_ECHILD")
.blacklist_item("__WASI_ECONNABORTED")
.blacklist_item("__WASI_ECONNREFUSED")
.blacklist_item("__WASI_ECONNRESET")
.blacklist_item("__WASI_EDEADLK")
.blacklist_item("__WASI_EDESTADDRREQ")
.blacklist_item("__WASI_EDOM")
.blacklist_item("__WASI_EDQUOT")
.blacklist_item("__WASI_EEXIST")
.blacklist_item("__WASI_EFAULT")
.blacklist_item("__WASI_EFBIG")
.blacklist_item("__WASI_EHOSTUNREACH")
.blacklist_item("__WASI_EIDRM")
.blacklist_item("__WASI_EILSEQ")
.blacklist_item("__WASI_EINPROGRESS")
.blacklist_item("__WASI_EINTR")
.blacklist_item("__WASI_EINVAL")
.blacklist_item("__WASI_EIO")
.blacklist_item("__WASI_EISCONN")
.blacklist_item("__WASI_EISDIR")
.blacklist_item("__WASI_ELOOP")
.blacklist_item("__WASI_EMFILE")
.blacklist_item("__WASI_EMLINK")
.blacklist_item("__WASI_EMSGSIZE")
.blacklist_item("__WASI_EMULTIHOP")
.blacklist_item("__WASI_ENAMETOOLONG")
.blacklist_item("__WASI_ENETDOWN")
.blacklist_item("__WASI_ENETRESET")
.blacklist_item("__WASI_ENETUNREACH")
.blacklist_item("__WASI_ENFILE")
.blacklist_item("__WASI_ENOBUFS")
.blacklist_item("__WASI_ENODEV")
.blacklist_item("__WASI_ENOENT")
.blacklist_item("__WASI_ENOEXEC")
.blacklist_item("__WASI_ENOLCK")
.blacklist_item("__WASI_ENOLINK")
.blacklist_item("__WASI_ENOMEM")
.blacklist_item("__WASI_ENOMSG")
.blacklist_item("__WASI_ENOPROTOOPT")
.blacklist_item("__WASI_ENOSPC")
.blacklist_item("__WASI_ENOSYS")
.blacklist_item("__WASI_ENOTCONN")
.blacklist_item("__WASI_ENOTDIR")
.blacklist_item("__WASI_ENOTEMPTY")
.blacklist_item("__WASI_ENOTRECOVERABLE")
.blacklist_item("__WASI_ENOTSOCK")
.blacklist_item("__WASI_ENOTSUP")
.blacklist_item("__WASI_ENOTTY")
.blacklist_item("__WASI_ENXIO")
.blacklist_item("__WASI_EOVERFLOW")
.blacklist_item("__WASI_EOWNERDEAD")
.blacklist_item("__WASI_EPERM")
.blacklist_item("__WASI_EPIPE")
.blacklist_item("__WASI_EPROTO")
.blacklist_item("__WASI_EPROTONOSUPPORT")
.blacklist_item("__WASI_EPROTOTYPE")
.blacklist_item("__WASI_ERANGE")
.blacklist_item("__WASI_EROFS")
.blacklist_item("__WASI_ESPIPE")
.blacklist_item("__WASI_ESRCH")
.blacklist_item("__WASI_ESTALE")
.blacklist_item("__WASI_ETIMEDOUT")
.blacklist_item("__WASI_ETXTBSY")
.blacklist_item("__WASI_EXDEV")
.blacklist_item("__WASI_ENOTCAPABLE")
.blacklist_item("__WASI_PREOPENTYPE_DIR");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings_builder
.generate()
.expect("Unable to generate bindings")
.write_to_file(out_path.join("wasmtime_ssp.rs"))
.expect("Couldn't write bindings!");
}

View File

@@ -1,8 +0,0 @@
cmake_minimum_required(VERSION 3.0)
project(SandboxedSystemPrimitives C)
include_directories(include)
add_library(SandboxedSystemPrimitives STATIC src/posix.c src/random.c src/str.c)
install(TARGETS SandboxedSystemPrimitives DESTINATION .)

View File

@@ -1,7 +0,0 @@
Please see the LICENSE file in each top-level directory for the terms applicable to that directory and its relative sub-directories.
The relevant directories and licenses are:
src/ - BSD-2-Clause; see src/LICENSE for details
include/ - CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
polyfill/clang/ - MIT; see the header of polyfill/clang/stdatomic.h for details

View File

@@ -1,9 +0,0 @@
This repository contains adapted forms of the CloudABI project's "libemulator"
library, which includes implementations the CloudABI system calls using
standard native platform support. See the README.md and LICENSE files in
the individual subdirectories for details.
src/ - cloudabi-utils' libemulator; see src/README.md for details
include/ - wasi headers
This is currently an experimental prototype.

View File

@@ -1,121 +0,0 @@
Creative Commons Legal Code
CC0 1.0 Universal
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.
For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:
i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.
4. Limitations and Disclaimers.
a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.

View File

@@ -1,842 +0,0 @@
/*
* Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
*
* This file declares an interface similar to WASI, but augmented to expose
* some implementation details such as the curfds arguments that we pass
* around to avoid storing them in TLS.
*/
#ifndef WASMTIME_SSP_H
#define WASMTIME_SSP_H
#include <stddef.h>
#include <stdint.h>
_Static_assert(_Alignof(int8_t) == 1, "non-wasi data layout");
_Static_assert(_Alignof(uint8_t) == 1, "non-wasi data layout");
_Static_assert(_Alignof(int16_t) == 2, "non-wasi data layout");
_Static_assert(_Alignof(uint16_t) == 2, "non-wasi data layout");
_Static_assert(_Alignof(int32_t) == 4, "non-wasi data layout");
_Static_assert(_Alignof(uint32_t) == 4, "non-wasi data layout");
_Static_assert(_Alignof(int64_t) == 8, "non-wasi data layout");
_Static_assert(_Alignof(uint64_t) == 8, "non-wasi data layout");
#ifdef __cplusplus
extern "C" {
#endif
typedef uint8_t __wasi_advice_t;
#define __WASI_ADVICE_NORMAL (0)
#define __WASI_ADVICE_SEQUENTIAL (1)
#define __WASI_ADVICE_RANDOM (2)
#define __WASI_ADVICE_WILLNEED (3)
#define __WASI_ADVICE_DONTNEED (4)
#define __WASI_ADVICE_NOREUSE (5)
typedef uint32_t __wasi_clockid_t;
#define __WASI_CLOCK_REALTIME (0)
#define __WASI_CLOCK_MONOTONIC (1)
#define __WASI_CLOCK_PROCESS_CPUTIME_ID (2)
#define __WASI_CLOCK_THREAD_CPUTIME_ID (3)
typedef uint64_t __wasi_device_t;
typedef uint64_t __wasi_dircookie_t;
#define __WASI_DIRCOOKIE_START (0)
typedef uint16_t __wasi_errno_t;
#define __WASI_ESUCCESS (0)
#define __WASI_E2BIG (1)
#define __WASI_EACCES (2)
#define __WASI_EADDRINUSE (3)
#define __WASI_EADDRNOTAVAIL (4)
#define __WASI_EAFNOSUPPORT (5)
#define __WASI_EAGAIN (6)
#define __WASI_EALREADY (7)
#define __WASI_EBADF (8)
#define __WASI_EBADMSG (9)
#define __WASI_EBUSY (10)
#define __WASI_ECANCELED (11)
#define __WASI_ECHILD (12)
#define __WASI_ECONNABORTED (13)
#define __WASI_ECONNREFUSED (14)
#define __WASI_ECONNRESET (15)
#define __WASI_EDEADLK (16)
#define __WASI_EDESTADDRREQ (17)
#define __WASI_EDOM (18)
#define __WASI_EDQUOT (19)
#define __WASI_EEXIST (20)
#define __WASI_EFAULT (21)
#define __WASI_EFBIG (22)
#define __WASI_EHOSTUNREACH (23)
#define __WASI_EIDRM (24)
#define __WASI_EILSEQ (25)
#define __WASI_EINPROGRESS (26)
#define __WASI_EINTR (27)
#define __WASI_EINVAL (28)
#define __WASI_EIO (29)
#define __WASI_EISCONN (30)
#define __WASI_EISDIR (31)
#define __WASI_ELOOP (32)
#define __WASI_EMFILE (33)
#define __WASI_EMLINK (34)
#define __WASI_EMSGSIZE (35)
#define __WASI_EMULTIHOP (36)
#define __WASI_ENAMETOOLONG (37)
#define __WASI_ENETDOWN (38)
#define __WASI_ENETRESET (39)
#define __WASI_ENETUNREACH (40)
#define __WASI_ENFILE (41)
#define __WASI_ENOBUFS (42)
#define __WASI_ENODEV (43)
#define __WASI_ENOENT (44)
#define __WASI_ENOEXEC (45)
#define __WASI_ENOLCK (46)
#define __WASI_ENOLINK (47)
#define __WASI_ENOMEM (48)
#define __WASI_ENOMSG (49)
#define __WASI_ENOPROTOOPT (50)
#define __WASI_ENOSPC (51)
#define __WASI_ENOSYS (52)
#define __WASI_ENOTCONN (53)
#define __WASI_ENOTDIR (54)
#define __WASI_ENOTEMPTY (55)
#define __WASI_ENOTRECOVERABLE (56)
#define __WASI_ENOTSOCK (57)
#define __WASI_ENOTSUP (58)
#define __WASI_ENOTTY (59)
#define __WASI_ENXIO (60)
#define __WASI_EOVERFLOW (61)
#define __WASI_EOWNERDEAD (62)
#define __WASI_EPERM (63)
#define __WASI_EPIPE (64)
#define __WASI_EPROTO (65)
#define __WASI_EPROTONOSUPPORT (66)
#define __WASI_EPROTOTYPE (67)
#define __WASI_ERANGE (68)
#define __WASI_EROFS (69)
#define __WASI_ESPIPE (70)
#define __WASI_ESRCH (71)
#define __WASI_ESTALE (72)
#define __WASI_ETIMEDOUT (73)
#define __WASI_ETXTBSY (74)
#define __WASI_EXDEV (75)
#define __WASI_ENOTCAPABLE (76)
typedef uint16_t __wasi_eventrwflags_t;
#define __WASI_EVENT_FD_READWRITE_HANGUP (0x0001)
typedef uint8_t __wasi_eventtype_t;
#define __WASI_EVENTTYPE_CLOCK (0)
#define __WASI_EVENTTYPE_FD_READ (1)
#define __WASI_EVENTTYPE_FD_WRITE (2)
typedef uint32_t __wasi_exitcode_t;
typedef uint32_t __wasi_fd_t;
typedef uint16_t __wasi_fdflags_t;
#define __WASI_FDFLAG_APPEND (0x0001)
#define __WASI_FDFLAG_DSYNC (0x0002)
#define __WASI_FDFLAG_NONBLOCK (0x0004)
#define __WASI_FDFLAG_RSYNC (0x0008)
#define __WASI_FDFLAG_SYNC (0x0010)
typedef int64_t __wasi_filedelta_t;
typedef uint64_t __wasi_filesize_t;
typedef uint8_t __wasi_filetype_t;
#define __WASI_FILETYPE_UNKNOWN (0)
#define __WASI_FILETYPE_BLOCK_DEVICE (1)
#define __WASI_FILETYPE_CHARACTER_DEVICE (2)
#define __WASI_FILETYPE_DIRECTORY (3)
#define __WASI_FILETYPE_REGULAR_FILE (4)
#define __WASI_FILETYPE_SOCKET_DGRAM (5)
#define __WASI_FILETYPE_SOCKET_STREAM (6)
#define __WASI_FILETYPE_SYMBOLIC_LINK (7)
typedef uint16_t __wasi_fstflags_t;
#define __WASI_FILESTAT_SET_ATIM (0x0001)
#define __WASI_FILESTAT_SET_ATIM_NOW (0x0002)
#define __WASI_FILESTAT_SET_MTIM (0x0004)
#define __WASI_FILESTAT_SET_MTIM_NOW (0x0008)
typedef uint64_t __wasi_inode_t;
typedef uint32_t __wasi_linkcount_t;
typedef uint32_t __wasi_lookupflags_t;
#define __WASI_LOOKUP_SYMLINK_FOLLOW (0x00000001)
typedef uint16_t __wasi_oflags_t;
#define __WASI_O_CREAT (0x0001)
#define __WASI_O_DIRECTORY (0x0002)
#define __WASI_O_EXCL (0x0004)
#define __WASI_O_TRUNC (0x0008)
typedef uint16_t __wasi_riflags_t;
#define __WASI_SOCK_RECV_PEEK (0x0001)
#define __WASI_SOCK_RECV_WAITALL (0x0002)
typedef uint64_t __wasi_rights_t;
#define __WASI_RIGHT_FD_DATASYNC (0x0000000000000001)
#define __WASI_RIGHT_FD_READ (0x0000000000000002)
#define __WASI_RIGHT_FD_SEEK (0x0000000000000004)
#define __WASI_RIGHT_FD_FDSTAT_SET_FLAGS (0x0000000000000008)
#define __WASI_RIGHT_FD_SYNC (0x0000000000000010)
#define __WASI_RIGHT_FD_TELL (0x0000000000000020)
#define __WASI_RIGHT_FD_WRITE (0x0000000000000040)
#define __WASI_RIGHT_FD_ADVISE (0x0000000000000080)
#define __WASI_RIGHT_FD_ALLOCATE (0x0000000000000100)
#define __WASI_RIGHT_PATH_CREATE_DIRECTORY (0x0000000000000200)
#define __WASI_RIGHT_PATH_CREATE_FILE (0x0000000000000400)
#define __WASI_RIGHT_PATH_LINK_SOURCE (0x0000000000000800)
#define __WASI_RIGHT_PATH_LINK_TARGET (0x0000000000001000)
#define __WASI_RIGHT_PATH_OPEN (0x0000000000002000)
#define __WASI_RIGHT_FD_READDIR (0x0000000000004000)
#define __WASI_RIGHT_PATH_READLINK (0x0000000000008000)
#define __WASI_RIGHT_PATH_RENAME_SOURCE (0x0000000000010000)
#define __WASI_RIGHT_PATH_RENAME_TARGET (0x0000000000020000)
#define __WASI_RIGHT_PATH_FILESTAT_GET (0x0000000000040000)
#define __WASI_RIGHT_PATH_FILESTAT_SET_SIZE (0x0000000000080000)
#define __WASI_RIGHT_PATH_FILESTAT_SET_TIMES (0x0000000000100000)
#define __WASI_RIGHT_FD_FILESTAT_GET (0x0000000000200000)
#define __WASI_RIGHT_FD_FILESTAT_SET_SIZE (0x0000000000400000)
#define __WASI_RIGHT_FD_FILESTAT_SET_TIMES (0x0000000000800000)
#define __WASI_RIGHT_PATH_SYMLINK (0x0000000001000000)
#define __WASI_RIGHT_PATH_REMOVE_DIRECTORY (0x0000000002000000)
#define __WASI_RIGHT_PATH_UNLINK_FILE (0x0000000004000000)
#define __WASI_RIGHT_POLL_FD_READWRITE (0x0000000008000000)
#define __WASI_RIGHT_SOCK_SHUTDOWN (0x0000000010000000)
typedef uint16_t __wasi_roflags_t;
#define __WASI_SOCK_RECV_DATA_TRUNCATED (0x0001)
typedef uint8_t __wasi_sdflags_t;
#define __WASI_SHUT_RD (0x01)
#define __WASI_SHUT_WR (0x02)
typedef uint16_t __wasi_siflags_t;
typedef uint8_t __wasi_signal_t;
// 0 is reserved; POSIX has special semantics for kill(pid, 0).
#define __WASI_SIGHUP (1)
#define __WASI_SIGINT (2)
#define __WASI_SIGQUIT (3)
#define __WASI_SIGILL (4)
#define __WASI_SIGTRAP (5)
#define __WASI_SIGABRT (6)
#define __WASI_SIGBUS (7)
#define __WASI_SIGFPE (8)
#define __WASI_SIGKILL (9)
#define __WASI_SIGUSR1 (10)
#define __WASI_SIGSEGV (11)
#define __WASI_SIGUSR2 (12)
#define __WASI_SIGPIPE (13)
#define __WASI_SIGALRM (14)
#define __WASI_SIGTERM (15)
#define __WASI_SIGCHLD (16)
#define __WASI_SIGCONT (17)
#define __WASI_SIGSTOP (18)
#define __WASI_SIGTSTP (19)
#define __WASI_SIGTTIN (20)
#define __WASI_SIGTTOU (21)
#define __WASI_SIGURG (22)
#define __WASI_SIGXCPU (23)
#define __WASI_SIGXFSZ (24)
#define __WASI_SIGVTALRM (25)
#define __WASI_SIGPROF (26)
#define __WASI_SIGWINCH (27)
#define __WASI_SIGPOLL (28)
#define __WASI_SIGPWR (29)
#define __WASI_SIGSYS (30)
typedef uint16_t __wasi_subclockflags_t;
#define __WASI_SUBSCRIPTION_CLOCK_ABSTIME (0x0001)
typedef uint64_t __wasi_timestamp_t;
typedef uint64_t __wasi_userdata_t;
typedef uint8_t __wasi_whence_t;
#define __WASI_WHENCE_CUR (0)
#define __WASI_WHENCE_END (1)
#define __WASI_WHENCE_SET (2)
typedef uint8_t __wasi_preopentype_t;
#define __WASI_PREOPENTYPE_DIR (0)
struct fd_table;
struct fd_prestats;
struct argv_environ_values;
typedef struct __wasi_dirent_t {
__wasi_dircookie_t d_next;
__wasi_inode_t d_ino;
uint32_t d_namlen;
__wasi_filetype_t d_type;
} __wasi_dirent_t;
_Static_assert(offsetof(__wasi_dirent_t, d_next) == 0, "non-wasi data layout");
_Static_assert(offsetof(__wasi_dirent_t, d_ino) == 8, "non-wasi data layout");
_Static_assert(offsetof(__wasi_dirent_t, d_namlen) == 16, "non-wasi data layout");
_Static_assert(offsetof(__wasi_dirent_t, d_type) == 20, "non-wasi data layout");
_Static_assert(sizeof(__wasi_dirent_t) == 24, "non-wasi data layout");
_Static_assert(_Alignof(__wasi_dirent_t) == 8, "non-wasi data layout");
typedef struct __wasi_event_t {
__wasi_userdata_t userdata;
__wasi_errno_t error;
__wasi_eventtype_t type;
union __wasi_event_u {
struct __wasi_event_u_fd_readwrite_t {
__wasi_filesize_t nbytes;
__wasi_eventrwflags_t flags;
} fd_readwrite;
} u;
} __wasi_event_t;
_Static_assert(offsetof(__wasi_event_t, userdata) == 0, "non-wasi data layout");
_Static_assert(offsetof(__wasi_event_t, error) == 8, "non-wasi data layout");
_Static_assert(offsetof(__wasi_event_t, type) == 10, "non-wasi data layout");
_Static_assert(
offsetof(__wasi_event_t, u.fd_readwrite.nbytes) == 16, "non-wasi data layout");
_Static_assert(
offsetof(__wasi_event_t, u.fd_readwrite.flags) == 24, "non-wasi data layout");
_Static_assert(sizeof(__wasi_event_t) == 32, "non-wasi data layout");
_Static_assert(_Alignof(__wasi_event_t) == 8, "non-wasi data layout");
typedef struct __wasi_prestat_t {
__wasi_preopentype_t pr_type;
union __wasi_prestat_u {
struct __wasi_prestat_u_dir_t {
size_t pr_name_len;
} dir;
} u;
} __wasi_prestat_t;
_Static_assert(offsetof(__wasi_prestat_t, pr_type) == 0, "non-wasi data layout");
_Static_assert(sizeof(void *) != 4 ||
offsetof(__wasi_prestat_t, u.dir.pr_name_len) == 4, "non-wasi data layout");
_Static_assert(sizeof(void *) != 8 ||
offsetof(__wasi_prestat_t, u.dir.pr_name_len) == 8, "non-wasi data layout");
_Static_assert(sizeof(void *) != 4 ||
sizeof(__wasi_prestat_t) == 8, "non-wasi data layout");
_Static_assert(sizeof(void *) != 8 ||
sizeof(__wasi_prestat_t) == 16, "non-wasi data layout");
_Static_assert(sizeof(void *) != 4 ||
_Alignof(__wasi_prestat_t) == 4, "non-wasi data layout");
_Static_assert(sizeof(void *) != 8 ||
_Alignof(__wasi_prestat_t) == 8, "non-wasi data layout");
typedef struct __wasi_fdstat_t {
__wasi_filetype_t fs_filetype;
__wasi_fdflags_t fs_flags;
__wasi_rights_t fs_rights_base;
__wasi_rights_t fs_rights_inheriting;
} __wasi_fdstat_t;
_Static_assert(
offsetof(__wasi_fdstat_t, fs_filetype) == 0, "non-wasi data layout");
_Static_assert(offsetof(__wasi_fdstat_t, fs_flags) == 2, "non-wasi data layout");
_Static_assert(
offsetof(__wasi_fdstat_t, fs_rights_base) == 8, "non-wasi data layout");
_Static_assert(
offsetof(__wasi_fdstat_t, fs_rights_inheriting) == 16,
"non-wasi data layout");
_Static_assert(sizeof(__wasi_fdstat_t) == 24, "non-wasi data layout");
_Static_assert(_Alignof(__wasi_fdstat_t) == 8, "non-wasi data layout");
typedef struct __wasi_filestat_t {
__wasi_device_t st_dev;
__wasi_inode_t st_ino;
__wasi_filetype_t st_filetype;
__wasi_linkcount_t st_nlink;
__wasi_filesize_t st_size;
__wasi_timestamp_t st_atim;
__wasi_timestamp_t st_mtim;
__wasi_timestamp_t st_ctim;
} __wasi_filestat_t;
_Static_assert(offsetof(__wasi_filestat_t, st_dev) == 0, "non-wasi data layout");
_Static_assert(offsetof(__wasi_filestat_t, st_ino) == 8, "non-wasi data layout");
_Static_assert(
offsetof(__wasi_filestat_t, st_filetype) == 16, "non-wasi data layout");
_Static_assert(
offsetof(__wasi_filestat_t, st_nlink) == 20, "non-wasi data layout");
_Static_assert(
offsetof(__wasi_filestat_t, st_size) == 24, "non-wasi data layout");
_Static_assert(
offsetof(__wasi_filestat_t, st_atim) == 32, "non-wasi data layout");
_Static_assert(
offsetof(__wasi_filestat_t, st_mtim) == 40, "non-wasi data layout");
_Static_assert(
offsetof(__wasi_filestat_t, st_ctim) == 48, "non-wasi data layout");
_Static_assert(sizeof(__wasi_filestat_t) == 56, "non-wasi data layout");
_Static_assert(_Alignof(__wasi_filestat_t) == 8, "non-wasi data layout");
typedef struct __wasi_ciovec_t {
const void *buf;
size_t buf_len;
} __wasi_ciovec_t;
_Static_assert(offsetof(__wasi_ciovec_t, buf) == 0, "non-wasi data layout");
_Static_assert(sizeof(void *) != 4 ||
offsetof(__wasi_ciovec_t, buf_len) == 4, "non-wasi data layout");
_Static_assert(sizeof(void *) != 8 ||
offsetof(__wasi_ciovec_t, buf_len) == 8, "non-wasi data layout");
_Static_assert(sizeof(void *) != 4 ||
sizeof(__wasi_ciovec_t) == 8, "non-wasi data layout");
_Static_assert(sizeof(void *) != 8 ||
sizeof(__wasi_ciovec_t) == 16, "non-wasi data layout");
_Static_assert(sizeof(void *) != 4 ||
_Alignof(__wasi_ciovec_t) == 4, "non-wasi data layout");
_Static_assert(sizeof(void *) != 8 ||
_Alignof(__wasi_ciovec_t) == 8, "non-wasi data layout");
typedef struct __wasi_iovec_t {
void *buf;
size_t buf_len;
} __wasi_iovec_t;
_Static_assert(offsetof(__wasi_iovec_t, buf) == 0, "non-wasi data layout");
_Static_assert(sizeof(void *) != 4 ||
offsetof(__wasi_iovec_t, buf_len) == 4, "non-wasi data layout");
_Static_assert(sizeof(void *) != 8 ||
offsetof(__wasi_iovec_t, buf_len) == 8, "non-wasi data layout");
_Static_assert(sizeof(void *) != 4 ||
sizeof(__wasi_iovec_t) == 8, "non-wasi data layout");
_Static_assert(sizeof(void *) != 8 ||
sizeof(__wasi_iovec_t) == 16, "non-wasi data layout");
_Static_assert(sizeof(void *) != 4 ||
_Alignof(__wasi_iovec_t) == 4, "non-wasi data layout");
_Static_assert(sizeof(void *) != 8 ||
_Alignof(__wasi_iovec_t) == 8, "non-wasi data layout");
typedef struct __wasi_subscription_t {
__wasi_userdata_t userdata;
__wasi_eventtype_t type;
union __wasi_subscription_u {
struct __wasi_subscription_u_clock_t {
__wasi_userdata_t identifier;
__wasi_clockid_t clock_id;
__wasi_timestamp_t timeout;
__wasi_timestamp_t precision;
__wasi_subclockflags_t flags;
} clock;
struct __wasi_subscription_u_fd_readwrite_t {
__wasi_fd_t fd;
} fd_readwrite;
} u;
} __wasi_subscription_t;
_Static_assert(
offsetof(__wasi_subscription_t, userdata) == 0, "non-wasi data layout");
_Static_assert(
offsetof(__wasi_subscription_t, type) == 8, "non-wasi data layout");
_Static_assert(
offsetof(__wasi_subscription_t, u.clock.identifier) == 16,
"non-wasi data layout");
_Static_assert(
offsetof(__wasi_subscription_t, u.clock.clock_id) == 24,
"non-wasi data layout");
_Static_assert(
offsetof(__wasi_subscription_t, u.clock.timeout) == 32, "non-wasi data layout");
_Static_assert(
offsetof(__wasi_subscription_t, u.clock.precision) == 40,
"non-wasi data layout");
_Static_assert(
offsetof(__wasi_subscription_t, u.clock.flags) == 48, "non-wasi data layout");
_Static_assert(
offsetof(__wasi_subscription_t, u.fd_readwrite.fd) == 16,
"non-wasi data layout");
_Static_assert(sizeof(__wasi_subscription_t) == 56, "non-wasi data layout");
_Static_assert(_Alignof(__wasi_subscription_t) == 8, "non-wasi data layout");
#if defined(WASMTIME_SSP_WASI_API)
#define WASMTIME_SSP_SYSCALL_NAME(name) \
asm("__wasi_" #name)
#else
#define WASMTIME_SSP_SYSCALL_NAME(name)
#endif
__wasi_errno_t wasmtime_ssp_args_get(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct argv_environ_values *arg_environ,
#endif
char **argv,
char *argv_buf
) WASMTIME_SSP_SYSCALL_NAME(args_get) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_args_sizes_get(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct argv_environ_values *arg_environ,
#endif
size_t *argc,
size_t *argv_buf_size
) WASMTIME_SSP_SYSCALL_NAME(args_sizes_get) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_clock_res_get(
__wasi_clockid_t clock_id,
__wasi_timestamp_t *resolution
) WASMTIME_SSP_SYSCALL_NAME(clock_res_get) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_clock_time_get(
__wasi_clockid_t clock_id,
__wasi_timestamp_t precision,
__wasi_timestamp_t *time
) WASMTIME_SSP_SYSCALL_NAME(clock_time_get) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_environ_get(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct argv_environ_values *arg_environ,
#endif
char **environ,
char *environ_buf
) WASMTIME_SSP_SYSCALL_NAME(environ_get) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_environ_sizes_get(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct argv_environ_values *arg_environ,
#endif
size_t *environ_count,
size_t *environ_buf_size
) WASMTIME_SSP_SYSCALL_NAME(environ_sizes_get) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_close(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
struct fd_prestats *prestats,
#endif
__wasi_fd_t fd
) WASMTIME_SSP_SYSCALL_NAME(fd_close) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_datasync(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd
) WASMTIME_SSP_SYSCALL_NAME(fd_datasync) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_pread(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
const __wasi_iovec_t *iovs,
size_t iovs_len,
__wasi_filesize_t offset,
size_t *nread
) WASMTIME_SSP_SYSCALL_NAME(fd_pread) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_pwrite(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
const __wasi_ciovec_t *iovs,
size_t iovs_len,
__wasi_filesize_t offset,
size_t *nwritten
) WASMTIME_SSP_SYSCALL_NAME(fd_pwrite) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_read(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
const __wasi_iovec_t *iovs,
size_t iovs_len,
size_t *nread
) WASMTIME_SSP_SYSCALL_NAME(fd_read) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_renumber(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
struct fd_prestats *prestats,
#endif
__wasi_fd_t from,
__wasi_fd_t to
) WASMTIME_SSP_SYSCALL_NAME(fd_renumber) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_seek(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_filedelta_t offset,
__wasi_whence_t whence,
__wasi_filesize_t *newoffset
) WASMTIME_SSP_SYSCALL_NAME(fd_seek) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_tell(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_filesize_t *newoffset
) WASMTIME_SSP_SYSCALL_NAME(fd_tell) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_fdstat_get(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_fdstat_t *buf
) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_get) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_fdstat_set_flags(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_fdflags_t flags
) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_set_flags) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_fdstat_set_rights(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_rights_t fs_rights_base,
__wasi_rights_t fs_rights_inheriting
) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_set_rights) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_sync(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd
) WASMTIME_SSP_SYSCALL_NAME(fd_sync) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_write(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
const __wasi_ciovec_t *iovs,
size_t iovs_len,
size_t *nwritten
) WASMTIME_SSP_SYSCALL_NAME(fd_write) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_advise(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_filesize_t offset,
__wasi_filesize_t len,
__wasi_advice_t advice
) WASMTIME_SSP_SYSCALL_NAME(fd_advise) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_allocate(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_filesize_t offset,
__wasi_filesize_t len
) WASMTIME_SSP_SYSCALL_NAME(fd_allocate) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_path_create_directory(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
const char *path,
size_t path_len
) WASMTIME_SSP_SYSCALL_NAME(path_create_directory) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_path_link(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t old_fd,
__wasi_lookupflags_t old_flags,
const char *old_path,
size_t old_path_len,
__wasi_fd_t new_fd,
const char *new_path,
size_t new_path_len
) WASMTIME_SSP_SYSCALL_NAME(path_link) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_path_open(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t dirfd,
__wasi_lookupflags_t dirflags,
const char *path,
size_t path_len,
__wasi_oflags_t oflags,
__wasi_rights_t fs_rights_base,
__wasi_rights_t fs_rights_inheriting,
__wasi_fdflags_t fs_flags,
__wasi_fd_t *fd
) WASMTIME_SSP_SYSCALL_NAME(path_open) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_readdir(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
void *buf,
size_t buf_len,
__wasi_dircookie_t cookie,
size_t *bufused
) WASMTIME_SSP_SYSCALL_NAME(fd_readdir) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_path_readlink(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
const char *path,
size_t path_len,
char *buf,
size_t buf_len,
size_t *bufused
) WASMTIME_SSP_SYSCALL_NAME(path_readlink) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_path_rename(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t old_fd,
const char *old_path,
size_t old_path_len,
__wasi_fd_t new_fd,
const char *new_path,
size_t new_path_len
) WASMTIME_SSP_SYSCALL_NAME(path_rename) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_filestat_get(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_filestat_t *buf
) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_get) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_filestat_set_times(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_timestamp_t st_atim,
__wasi_timestamp_t st_mtim,
__wasi_fstflags_t fstflags
) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_set_times) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_fd_filestat_set_size(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_filesize_t st_size
) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_set_size) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_path_filestat_get(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_lookupflags_t flags,
const char *path,
size_t path_len,
__wasi_filestat_t *buf
) WASMTIME_SSP_SYSCALL_NAME(path_filestat_get) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_path_filestat_set_times(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
__wasi_lookupflags_t flags,
const char *path,
size_t path_len,
__wasi_timestamp_t st_atim,
__wasi_timestamp_t st_mtim,
__wasi_fstflags_t fstflags
) WASMTIME_SSP_SYSCALL_NAME(path_filestat_set_times) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_path_symlink(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
const char *old_path,
size_t old_path_len,
__wasi_fd_t fd,
const char *new_path,
size_t new_path_len
) WASMTIME_SSP_SYSCALL_NAME(path_symlink) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_path_unlink_file(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
const char *path,
size_t path_len
) WASMTIME_SSP_SYSCALL_NAME(path_unlink_file) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_path_remove_directory(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t fd,
const char *path,
size_t path_len
) WASMTIME_SSP_SYSCALL_NAME(path_remove_directory) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_poll_oneoff(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
const __wasi_subscription_t *in,
__wasi_event_t *out,
size_t nsubscriptions,
size_t *nevents
) WASMTIME_SSP_SYSCALL_NAME(poll_oneoff) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_proc_raise(
__wasi_signal_t sig
) WASMTIME_SSP_SYSCALL_NAME(proc_raise) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_random_get(
void *buf,
size_t buf_len
) WASMTIME_SSP_SYSCALL_NAME(random_get) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_sock_recv(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
const __wasi_iovec_t *ri_data,
size_t ri_data_len,
__wasi_riflags_t ri_flags,
size_t *ro_datalen,
__wasi_roflags_t *ro_flags
) WASMTIME_SSP_SYSCALL_NAME(sock_recv) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_sock_send(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
const __wasi_ciovec_t *si_data,
size_t si_data_len,
__wasi_siflags_t si_flags,
size_t *so_datalen
) WASMTIME_SSP_SYSCALL_NAME(sock_send) __attribute__((__warn_unused_result__));
__wasi_errno_t wasmtime_ssp_sock_shutdown(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
__wasi_fd_t sock,
__wasi_sdflags_t how
) WASMTIME_SSP_SYSCALL_NAME(sock_shutdown) __attribute__((__warn_unused_result__));
#ifdef __cplusplus
}
#endif
#undef WASMTIME_SSP_SYSCALL_NAME
#endif

View File

@@ -1,24 +0,0 @@
All code is distributed under the following license:
Copyright (c) 2015 Nuxi, https://nuxi.nl/
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

View File

@@ -1,14 +0,0 @@
This directory consists of selected files copied from the [libemulator]
directory in the [cloudabi-utils] repository, with minor modifications,
along with the accompanying LICENSE file from that repository.
The modifications are marked with `WASMTIME_*` preprocessor macros.
The files were copied at git revision
be1ce21e1dded9c0c0a6ebe144cbea01cf44a874
which is dated
Sun Jan 13 23:26:03 2019 +0100
.
[libemulator]: https://github.com/NuxiNL/cloudabi-utils/tree/master/src/libemulator
[cloudabi-utils]: https://github.com/NuxiNL/cloudabi-utils

View File

@@ -1,100 +0,0 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
// for license information.
//
// The upstream file contains the following copyright notice:
//
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
#ifndef CONFIG_H
#define CONFIG_H
#include <stdlib.h>
#if defined(__FreeBSD__) || defined(__APPLE__)
#define CONFIG_HAS_ARC4RANDOM_BUF 1
#else
#define CONFIG_HAS_ARC4RANDOM_BUF 0
#endif
// On Linux, prefer to use getrandom, though it isn't available in
// GLIBC before 2.25.
#if defined(__linux__) && \
(!defined(__GLIBC__) || \
__GLIBC__ > 2 || \
(__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))
#define CONFIG_HAS_GETRANDOM 1
#else
#define CONFIG_HAS_GETRANDOM 0
#endif
#if defined(__CloudABI__)
#define CONFIG_HAS_CAP_ENTER 1
#else
#define CONFIG_HAS_CAP_ENTER 0
#endif
#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__EMSCRIPTEN__)
#define CONFIG_HAS_CLOCK_NANOSLEEP 1
#else
#define CONFIG_HAS_CLOCK_NANOSLEEP 0
#endif
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#define CONFIG_HAS_FDATASYNC 1
#else
#define CONFIG_HAS_FDATASYNC 0
#endif
#ifndef __CloudABI__
#define CONFIG_HAS_ISATTY 1
#else
#define CONFIG_HAS_ISATTY 0
#endif
#ifndef __APPLE__
#define CONFIG_HAS_POSIX_FALLOCATE 1
#else
#define CONFIG_HAS_POSIX_FALLOCATE 0
#endif
#ifndef __APPLE__
#define CONFIG_HAS_PREADV 1
#else
#define CONFIG_HAS_PREADV 0
#endif
#if defined(__APPLE__) || defined(__CloudABI__)
#define CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP 1
#else
#define CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP 0
#endif
#ifndef __APPLE__
#define CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK 1
#else
#define CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK 0
#endif
#ifndef __APPLE__
#define CONFIG_HAS_PWRITEV 1
#else
#define CONFIG_HAS_PWRITEV 0
#endif
#ifdef __APPLE__
#define st_atimespec st_atim
#define st_mtimespec st_mtim
#define st_ctimespec st_ctim
#endif
#ifdef __APPLE__
#define CONFIG_TLS_USE_GSBASE 1
#else
#define CONFIG_TLS_USE_GSBASE 0
#endif
#endif

View File

@@ -1,215 +0,0 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
// for license information.
//
// The upstream file contains the following copyright notice:
//
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
#ifndef LOCKING_H
#define LOCKING_H
#include "config.h"
#include <assert.h>
#include <errno.h>
#include <pthread.h>
#include <stdint.h>
#include <time.h>
#ifndef __has_extension
#define __has_extension(x) 0
#endif
#if __has_extension(c_thread_safety_attributes)
#define LOCK_ANNOTATE(x) __attribute__((x))
#else
#define LOCK_ANNOTATE(x)
#endif
// Lock annotation macros.
#define LOCKABLE LOCK_ANNOTATE(lockable)
#define LOCKS_EXCLUSIVE(...) LOCK_ANNOTATE(exclusive_lock_function(__VA_ARGS__))
#define LOCKS_SHARED(...) LOCK_ANNOTATE(shared_lock_function(__VA_ARGS__))
#define TRYLOCKS_EXCLUSIVE(...) \
LOCK_ANNOTATE(exclusive_trylock_function(__VA_ARGS__))
#define TRYLOCKS_SHARED(...) LOCK_ANNOTATE(shared_trylock_function(__VA_ARGS__))
#define UNLOCKS(...) LOCK_ANNOTATE(unlock_function(__VA_ARGS__))
#define REQUIRES_EXCLUSIVE(...) \
LOCK_ANNOTATE(exclusive_locks_required(__VA_ARGS__))
#define REQUIRES_SHARED(...) LOCK_ANNOTATE(shared_locks_required(__VA_ARGS__))
#define REQUIRES_UNLOCKED(...) LOCK_ANNOTATE(locks_excluded(__VA_ARGS__))
#define NO_LOCK_ANALYSIS LOCK_ANNOTATE(no_thread_safety_analysis)
// Mutex that uses the lock annotations.
struct LOCKABLE mutex {
pthread_mutex_t object;
};
#define MUTEX_INITIALIZER \
{ PTHREAD_MUTEX_INITIALIZER }
static inline void mutex_init(struct mutex *lock) REQUIRES_UNLOCKED(*lock) {
pthread_mutex_init(&lock->object, NULL);
}
static inline void mutex_destroy(struct mutex *lock) REQUIRES_UNLOCKED(*lock) {
pthread_mutex_destroy(&lock->object);
}
static inline void mutex_lock(struct mutex *lock)
LOCKS_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS {
pthread_mutex_lock(&lock->object);
}
static inline void mutex_unlock(struct mutex *lock)
UNLOCKS(*lock) NO_LOCK_ANALYSIS {
pthread_mutex_unlock(&lock->object);
}
// Read-write lock that uses the lock annotations.
struct LOCKABLE rwlock {
pthread_rwlock_t object;
};
void rwlock_init(struct rwlock *lock) REQUIRES_UNLOCKED(*lock) {
pthread_rwlock_init(&lock->object, NULL);
}
void rwlock_rdlock(struct rwlock *lock)
LOCKS_SHARED(*lock) NO_LOCK_ANALYSIS {
pthread_rwlock_rdlock(&lock->object);
}
void rwlock_wrlock(struct rwlock *lock)
LOCKS_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS {
pthread_rwlock_wrlock(&lock->object);
}
void rwlock_unlock(struct rwlock *lock)
UNLOCKS(*lock) NO_LOCK_ANALYSIS {
pthread_rwlock_unlock(&lock->object);
}
// Condition variable that uses the lock annotations.
struct LOCKABLE cond {
pthread_cond_t object;
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK || \
!CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
clockid_t clock;
#endif
};
static inline void cond_init_monotonic(struct cond *cond) {
#if CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK
pthread_condattr_t attr;
pthread_condattr_init(&attr);
pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
pthread_cond_init(&cond->object, &attr);
pthread_condattr_destroy(&attr);
#else
pthread_cond_init(&cond->object, NULL);
#endif
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK || \
!CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
cond->clock = CLOCK_MONOTONIC;
#endif
}
static inline void cond_init_realtime(struct cond *cond) {
pthread_cond_init(&cond->object, NULL);
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK || \
!CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
cond->clock = CLOCK_REALTIME;
#endif
}
static inline void cond_destroy(struct cond *cond) {
pthread_cond_destroy(&cond->object);
}
static inline void cond_signal(struct cond *cond) {
pthread_cond_signal(&cond->object);
}
static inline bool cond_timedwait(struct cond *cond, struct mutex *lock,
uint64_t timeout, bool abstime)
REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS {
struct timespec ts = {
.tv_sec = (time_t)(timeout / 1000000000),
.tv_nsec = (long)(timeout % 1000000000),
};
if (abstime) {
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK
// No native support for sleeping on monotonic clocks. Convert the
// timeout to a relative value and then to an absolute value for the
// realtime clock.
if (cond->clock != CLOCK_REALTIME) {
struct timespec ts_monotonic;
clock_gettime(cond->clock, &ts_monotonic);
ts.tv_sec -= ts_monotonic.tv_sec;
ts.tv_nsec -= ts_monotonic.tv_nsec;
if (ts.tv_nsec < 0) {
ts.tv_nsec += 1000000000;
--ts.tv_sec;
}
struct timespec ts_realtime;
clock_gettime(CLOCK_REALTIME, &ts_realtime);
ts.tv_sec += ts_realtime.tv_sec;
ts.tv_nsec += ts_realtime.tv_nsec;
if (ts.tv_nsec >= 1000000000) {
ts.tv_nsec -= 1000000000;
++ts.tv_sec;
}
}
#endif
} else {
#if CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
// Implementation supports relative timeouts.
int ret =
pthread_cond_timedwait_relative_np(&cond->object, &lock->object, &ts);
assert((ret == 0 || ret == ETIMEDOUT) &&
"pthread_cond_timedwait_relative_np() failed");
return ret == ETIMEDOUT;
#else
// Convert to absolute timeout.
struct timespec ts_now;
#if CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK
clock_gettime(cond->clock, &ts_now);
#else
clock_gettime(CLOCK_REALTIME, &ts_now);
#endif
ts.tv_sec += ts_now.tv_sec;
ts.tv_nsec += ts_now.tv_nsec;
if (ts.tv_nsec >= 1000000000) {
ts.tv_nsec -= 1000000000;
++ts.tv_sec;
}
#endif
}
int ret = pthread_cond_timedwait(&cond->object, &lock->object, &ts);
assert((ret == 0 || ret == ETIMEDOUT) && "pthread_cond_timedwait() failed");
return ret == ETIMEDOUT;
}
static inline void cond_wait(struct cond *cond, struct mutex *lock)
REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS {
pthread_cond_wait(&cond->object, &lock->object);
}
#endif

View File

@@ -1,42 +0,0 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
// for license information.
//
// The upstream file contains the following copyright notice:
//
// Copyright (c) 2015 Nuxi, https://nuxi.nl/
#ifndef COMMON_LIMITS_H
#define COMMON_LIMITS_H
#include <limits.h>
#define NUMERIC_MIN(t) \
_Generic((t)0, char \
: CHAR_MIN, signed char \
: SCHAR_MIN, unsigned char : 0, short \
: SHRT_MIN, unsigned short : 0, int \
: INT_MIN, unsigned int : 0, long \
: LONG_MIN, unsigned long : 0, long long \
: LLONG_MIN, unsigned long long : 0, default \
: (void)0)
#define NUMERIC_MAX(t) \
_Generic((t)0, char \
: CHAR_MAX, signed char \
: SCHAR_MAX, unsigned char \
: UCHAR_MAX, short \
: SHRT_MAX, unsigned short \
: USHRT_MAX, int \
: INT_MAX, unsigned int \
: UINT_MAX, long \
: LONG_MAX, unsigned long \
: ULONG_MAX, long long \
: LLONG_MAX, unsigned long long \
: ULLONG_MAX, default \
: (void)0)
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,63 +0,0 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
// for license information.
//
// The upstream file contains the following copyright notice:
//
// Copyright (c) 2016-2018 Nuxi, https://nuxi.nl/
#ifndef POSIX_H
#define POSIX_H
#include <stdbool.h>
#include <stddef.h>
#include "locking.h"
struct fd_entry;
struct syscalls;
struct fd_prestat {
const char *dir_name;
size_t dir_name_len;
};
struct fd_table {
struct rwlock lock;
struct fd_entry *entries;
size_t size;
size_t used;
};
struct fd_prestats {
struct rwlock lock;
struct fd_prestat *prestats;
size_t size;
size_t used;
};
struct argv_environ_values {
size_t argc;
size_t argv_buf_size;
char **argv;
char *argv_buf;
size_t environ_count;
size_t environ_buf_size;
char **environ;
char *environ_buf;
};
void fd_table_init(struct fd_table *);
bool fd_table_insert_existing(struct fd_table *, __wasi_fd_t, int);
void fd_prestats_init(struct fd_prestats *);
bool fd_prestats_insert(struct fd_prestats *, const char *, __wasi_fd_t);
void argv_environ_init(struct argv_environ_values *,
const size_t *argv_offsets, size_t argv_offsets_len,
const char *argv_buf, size_t argv_buf_len,
const size_t *environ_offsets, size_t environ_offsets_len,
const char *environ_buf, size_t environ_buf_len);
#endif

View File

@@ -1,92 +0,0 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
// for license information.
//
// The upstream file contains the following copyright notice:
//
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
#ifndef QUEUE_H
#define QUEUE_H
#include <stddef.h>
// LIST: Double-linked list.
#define LIST_HEAD(name, type) \
struct name { \
struct type *l_first; \
}
#define LIST_HEAD_INITIALIZER(head) \
{ NULL }
#define LIST_ENTRY(type) \
struct { \
struct type *l_next; \
struct type **l_prev; \
}
#define LIST_FOREACH(var, head, field) \
for ((var) = (head)->l_first; (var) != NULL; (var) = (var)->field.l_next)
#define LIST_INIT(head) \
do { \
(head)->l_first = NULL; \
} while (0)
#define LIST_INSERT_HEAD(head, element, field) \
do { \
(element)->field.l_next = (head)->l_first; \
if ((head)->l_first != NULL) \
(head)->l_first->field.l_prev = &(element)->field.l_next; \
(head)->l_first = (element); \
(element)->field.l_prev = &(head)->l_first; \
} while (0)
#define LIST_REMOVE(element, field) \
do { \
if ((element)->field.l_next != NULL) \
(element)->field.l_next->field.l_prev = (element)->field.l_prev; \
*(element)->field.l_prev = (element)->field.l_next; \
} while (0)
// TAILQ: Double-linked list with tail pointer.
#define TAILQ_HEAD(name, type) \
struct name { \
struct type *t_first; \
struct type **t_last; \
}
#define TAILQ_ENTRY(type) \
struct { \
struct type *t_next; \
struct type **t_prev; \
}
#define TAILQ_EMPTY(head) ((head)->t_first == NULL)
#define TAILQ_FIRST(head) ((head)->t_first)
#define TAILQ_FOREACH(var, head, field) \
for ((var) = (head)->t_first; (var) != NULL; (var) = (var)->field.t_next)
#define TAILQ_INIT(head) \
do { \
(head)->t_first = NULL; \
(head)->t_last = &(head)->t_first; \
} while (0)
#define TAILQ_INSERT_TAIL(head, elm, field) \
do { \
(elm)->field.t_next = NULL; \
(elm)->field.t_prev = (head)->t_last; \
*(head)->t_last = (elm); \
(head)->t_last = &(elm)->field.t_next; \
} while (0)
#define TAILQ_REMOVE(head, element, field) \
do { \
if ((element)->field.t_next != NULL) \
(element)->field.t_next->field.t_prev = (element)->field.t_prev; \
else \
(head)->t_last = (element)->field.t_prev; \
*(element)->field.t_prev = (element)->field.t_next; \
} while (0)
#endif

View File

@@ -1,92 +0,0 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
// for license information.
//
// The upstream file contains the following copyright notice:
//
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
#include "config.h"
#include <fcntl.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "random.h"
#if CONFIG_HAS_ARC4RANDOM_BUF
void random_buf(void *buf, size_t len) {
arc4random_buf(buf, len);
}
#elif CONFIG_HAS_GETRANDOM
#include <sys/random.h>
void random_buf(void *buf, size_t len) {
for (;;) {
ssize_t x = getrandom(buf, len, 0);
if (x < 0) {
if (errno == EINTR)
continue;
fprintf(stderr, "getrandom failed: %s", strerror(errno));
abort();
}
if (x == len)
return;
buf = (void *)((unsigned char *)buf + x);
len -= x;
}
}
#else
static int urandom;
static void open_urandom(void) {
urandom = open("/dev/urandom", O_RDONLY);
if (urandom < 0) {
fputs("Failed to open /dev/urandom\n", stderr);
abort();
}
}
void random_buf(void *buf, size_t len) {
static pthread_once_t open_once = PTHREAD_ONCE_INIT;
pthread_once(&open_once, open_urandom);
if (read(urandom, buf, len) != len) {
fputs("Short read on /dev/urandom\n", stderr);
abort();
}
}
#endif
// Calculates a random number within the range [0, upper - 1] without
// any modulo bias.
//
// The function below repeatedly obtains a random number from
// arc4random() until it lies within the range [2^k % upper, 2^k). As
// this range has length k * upper, we can safely obtain a number
// without any modulo bias.
uintmax_t random_uniform(uintmax_t upper) {
// Compute 2^k % upper
// == (2^k - upper) % upper
// == -upper % upper.
uintmax_t lower = -upper % upper;
for (;;) {
uintmax_t value;
random_buf(&value, sizeof(value));
if (value >= lower)
return value % upper;
}
}

View File

@@ -1,20 +0,0 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
// for license information.
//
// The upstream file contains the following copyright notice:
//
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
#ifndef RANDOM_H
#define RANDOM_H
#include <stdint.h>
void random_buf(void *, size_t);
uintmax_t random_uniform(uintmax_t);
#endif

View File

@@ -1,65 +0,0 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
// for license information.
//
// The upstream file contains the following copyright notice:
//
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
#ifndef REFCOUNT_H
#define REFCOUNT_H
#include <assert.h>
#if !defined(__GNUC__)
#include <stdatomic.h>
#endif
#include <stdbool.h>
#include "locking.h"
// Simple reference counter.
struct LOCKABLE refcount {
#if defined(__GNUC__)
unsigned count;
#else
atomic_uint count;
#endif
};
#define PRODUCES(...) LOCKS_SHARED(__VA_ARGS__) NO_LOCK_ANALYSIS
#define CONSUMES(...) UNLOCKS(__VA_ARGS__) NO_LOCK_ANALYSIS
// Initialize the reference counter.
static void refcount_init(struct refcount *r, unsigned int count) PRODUCES(*r) {
#if defined(__GNUC__)
__atomic_store_n(&r->count, count, __ATOMIC_SEQ_CST);
#else
atomic_init(&r->count, count);
#endif
}
// Increment the reference counter.
static inline void refcount_acquire(struct refcount *r) PRODUCES(*r) {
#if defined(__GNUC__)
__atomic_fetch_add(&r->count, 1, __ATOMIC_ACQUIRE);
#else
atomic_fetch_add_explicit(&r->count, 1, memory_order_acquire);
#endif
}
// Decrement the reference counter, returning whether the reference
// dropped to zero.
static inline bool refcount_release(struct refcount *r) CONSUMES(*r) {
#if defined(__GNUC__)
int old = __atomic_fetch_sub(&r->count, 1, __ATOMIC_RELEASE);
#else
int old = atomic_fetch_sub_explicit(&r->count, 1, memory_order_release);
#endif
assert(old != 0 && "Reference count becoming negative");
return old == 1;
}
#endif

View File

@@ -1,83 +0,0 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
// for license information.
//
// The upstream file contains the following copyright notice:
//
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
#ifndef RIGHTS_H
#define RIGHTS_H
#define RIGHTS_ALL \
(__WASI_RIGHT_FD_DATASYNC | __WASI_RIGHT_FD_READ | \
__WASI_RIGHT_FD_SEEK | __WASI_RIGHT_FD_FDSTAT_SET_FLAGS | \
__WASI_RIGHT_FD_SYNC | __WASI_RIGHT_FD_TELL | __WASI_RIGHT_FD_WRITE | \
__WASI_RIGHT_FD_ADVISE | __WASI_RIGHT_FD_ALLOCATE | \
__WASI_RIGHT_PATH_CREATE_DIRECTORY | __WASI_RIGHT_PATH_CREATE_FILE | \
__WASI_RIGHT_PATH_LINK_SOURCE | __WASI_RIGHT_PATH_LINK_TARGET | \
__WASI_RIGHT_PATH_OPEN | __WASI_RIGHT_FD_READDIR | \
__WASI_RIGHT_PATH_READLINK | __WASI_RIGHT_PATH_RENAME_SOURCE | \
__WASI_RIGHT_PATH_RENAME_TARGET | __WASI_RIGHT_PATH_FILESTAT_GET | \
__WASI_RIGHT_PATH_FILESTAT_SET_SIZE | \
__WASI_RIGHT_PATH_FILESTAT_SET_TIMES | \
__WASI_RIGHT_FD_FILESTAT_GET | __WASI_RIGHT_FD_FILESTAT_SET_TIMES | \
__WASI_RIGHT_FD_FILESTAT_SET_SIZE | \
__WASI_RIGHT_PATH_SYMLINK | __WASI_RIGHT_PATH_UNLINK_FILE | \
__WASI_RIGHT_PATH_REMOVE_DIRECTORY | \
__WASI_RIGHT_POLL_FD_READWRITE | __WASI_RIGHT_SOCK_SHUTDOWN)
// Block and character device interaction is outside the scope of
// CloudABI. Simply allow everything.
#define RIGHTS_BLOCK_DEVICE_BASE RIGHTS_ALL
#define RIGHTS_BLOCK_DEVICE_INHERITING RIGHTS_ALL
#define RIGHTS_CHARACTER_DEVICE_BASE RIGHTS_ALL
#define RIGHTS_CHARACTER_DEVICE_INHERITING RIGHTS_ALL
// Only allow directory operations on directories. Directories can only
// yield file descriptors to other directories and files.
#define RIGHTS_DIRECTORY_BASE \
(__WASI_RIGHT_FD_FDSTAT_SET_FLAGS | __WASI_RIGHT_FD_SYNC | \
__WASI_RIGHT_FD_ADVISE | __WASI_RIGHT_PATH_CREATE_DIRECTORY | \
__WASI_RIGHT_PATH_CREATE_FILE | __WASI_RIGHT_PATH_LINK_SOURCE | \
__WASI_RIGHT_PATH_LINK_TARGET | __WASI_RIGHT_PATH_OPEN | \
__WASI_RIGHT_FD_READDIR | __WASI_RIGHT_PATH_READLINK | \
__WASI_RIGHT_PATH_RENAME_SOURCE | __WASI_RIGHT_PATH_RENAME_TARGET | \
__WASI_RIGHT_PATH_FILESTAT_GET | \
__WASI_RIGHT_PATH_FILESTAT_SET_SIZE | \
__WASI_RIGHT_PATH_FILESTAT_SET_TIMES | \
__WASI_RIGHT_FD_FILESTAT_GET | __WASI_RIGHT_FD_FILESTAT_SET_TIMES | \
__WASI_RIGHT_PATH_SYMLINK | __WASI_RIGHT_PATH_UNLINK_FILE | \
__WASI_RIGHT_PATH_REMOVE_DIRECTORY | \
__WASI_RIGHT_POLL_FD_READWRITE)
#define RIGHTS_DIRECTORY_INHERITING \
(RIGHTS_DIRECTORY_BASE | RIGHTS_REGULAR_FILE_BASE)
// Operations that apply to regular files.
#define RIGHTS_REGULAR_FILE_BASE \
(__WASI_RIGHT_FD_DATASYNC | __WASI_RIGHT_FD_READ | \
__WASI_RIGHT_FD_SEEK | __WASI_RIGHT_FD_FDSTAT_SET_FLAGS | \
__WASI_RIGHT_FD_SYNC | __WASI_RIGHT_FD_TELL | __WASI_RIGHT_FD_WRITE | \
__WASI_RIGHT_FD_ADVISE | __WASI_RIGHT_FD_ALLOCATE | \
__WASI_RIGHT_FD_FILESTAT_GET | __WASI_RIGHT_FD_FILESTAT_SET_SIZE | \
__WASI_RIGHT_FD_FILESTAT_SET_TIMES | __WASI_RIGHT_POLL_FD_READWRITE)
#define RIGHTS_REGULAR_FILE_INHERITING 0
// Operations that apply to sockets and socket pairs.
#define RIGHTS_SOCKET_BASE \
(__WASI_RIGHT_FD_READ | __WASI_RIGHT_FD_FDSTAT_SET_FLAGS | \
__WASI_RIGHT_FD_WRITE | __WASI_RIGHT_FD_FILESTAT_GET | \
__WASI_RIGHT_POLL_FD_READWRITE | __WASI_RIGHT_SOCK_SHUTDOWN)
#define RIGHTS_SOCKET_INHERITING RIGHTS_ALL
// Operations that apply to TTYs.
#define RIGHTS_TTY_BASE \
(__WASI_RIGHT_FD_READ | __WASI_RIGHT_FD_FDSTAT_SET_FLAGS | \
__WASI_RIGHT_FD_WRITE | __WASI_RIGHT_FD_FILESTAT_GET | \
__WASI_RIGHT_POLL_FD_READWRITE)
#define RIGHTS_TTY_INHERITING 0
#endif

View File

@@ -1,17 +0,0 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
// for license information.
//
// The upstream file contains the following copyright notice:
//
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
#ifndef SIGNALS_H
#define SIGNALS_H
void signals_init(void);
#endif

View File

@@ -1,33 +0,0 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
// for license information.
//
// The upstream file contains the following copyright notice:
//
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
#include "config.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "str.h"
char *str_nullterminate(const char *s, size_t len) {
// Copy string.
char *ret = strndup(s, len);
if (ret == NULL)
return NULL;
// Ensure that it contains no null bytes within.
if (strlen(ret) != len) {
free(ret);
errno = EILSEQ;
return NULL;
}
return ret;
}

View File

@@ -1,19 +0,0 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/CraneStation/wasmtime/blob/master/LICENSE for license information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/CraneStation/wasmtime/blob/master/lib/wasi/sandboxed-system-primitives/src/LICENSE
// for license information.
//
// The upstream file contains the following copyright notice:
//
// Copyright (c) 2016 Nuxi, https://nuxi.nl/
#ifndef STR_H
#define STR_H
#include "config.h"
char *str_nullterminate(const char *, size_t);
#endif

View File

@@ -1,88 +0,0 @@
#![allow(non_camel_case_types, dead_code)]
include!(concat!(env!("OUT_DIR"), "/wasmtime_ssp.rs"));
pub type char = ::std::os::raw::c_char;
pub type void = ::std::os::raw::c_void;
// pub type __wasi_errno_t = u16;
pub const __WASI_ESUCCESS: __wasi_errno_t = 0;
pub const __WASI_E2BIG: __wasi_errno_t = 1;
pub const __WASI_EACCES: __wasi_errno_t = 2;
pub const __WASI_EADDRINUSE: __wasi_errno_t = 3;
pub const __WASI_EADDRNOTAVAIL: __wasi_errno_t = 4;
pub const __WASI_EAFNOSUPPORT: __wasi_errno_t = 5;
pub const __WASI_EAGAIN: __wasi_errno_t = 6;
pub const __WASI_EALREADY: __wasi_errno_t = 7;
pub const __WASI_EBADF: __wasi_errno_t = 8;
pub const __WASI_EBADMSG: __wasi_errno_t = 9;
pub const __WASI_EBUSY: __wasi_errno_t = 10;
pub const __WASI_ECANCELED: __wasi_errno_t = 11;
pub const __WASI_ECHILD: __wasi_errno_t = 12;
pub const __WASI_ECONNABORTED: __wasi_errno_t = 13;
pub const __WASI_ECONNREFUSED: __wasi_errno_t = 14;
pub const __WASI_ECONNRESET: __wasi_errno_t = 15;
pub const __WASI_EDEADLK: __wasi_errno_t = 16;
pub const __WASI_EDESTADDRREQ: __wasi_errno_t = 17;
pub const __WASI_EDOM: __wasi_errno_t = 18;
pub const __WASI_EDQUOT: __wasi_errno_t = 19;
pub const __WASI_EEXIST: __wasi_errno_t = 20;
pub const __WASI_EFAULT: __wasi_errno_t = 21;
pub const __WASI_EFBIG: __wasi_errno_t = 22;
pub const __WASI_EHOSTUNREACH: __wasi_errno_t = 23;
pub const __WASI_EIDRM: __wasi_errno_t = 24;
pub const __WASI_EILSEQ: __wasi_errno_t = 25;
pub const __WASI_EINPROGRESS: __wasi_errno_t = 26;
pub const __WASI_EINTR: __wasi_errno_t = 27;
pub const __WASI_EINVAL: __wasi_errno_t = 28;
pub const __WASI_EIO: __wasi_errno_t = 29;
pub const __WASI_EISCONN: __wasi_errno_t = 30;
pub const __WASI_EISDIR: __wasi_errno_t = 31;
pub const __WASI_ELOOP: __wasi_errno_t = 32;
pub const __WASI_EMFILE: __wasi_errno_t = 33;
pub const __WASI_EMLINK: __wasi_errno_t = 34;
pub const __WASI_EMSGSIZE: __wasi_errno_t = 35;
pub const __WASI_EMULTIHOP: __wasi_errno_t = 36;
pub const __WASI_ENAMETOOLONG: __wasi_errno_t = 37;
pub const __WASI_ENETDOWN: __wasi_errno_t = 38;
pub const __WASI_ENETRESET: __wasi_errno_t = 39;
pub const __WASI_ENETUNREACH: __wasi_errno_t = 40;
pub const __WASI_ENFILE: __wasi_errno_t = 41;
pub const __WASI_ENOBUFS: __wasi_errno_t = 42;
pub const __WASI_ENODEV: __wasi_errno_t = 43;
pub const __WASI_ENOENT: __wasi_errno_t = 44;
pub const __WASI_ENOEXEC: __wasi_errno_t = 45;
pub const __WASI_ENOLCK: __wasi_errno_t = 46;
pub const __WASI_ENOLINK: __wasi_errno_t = 47;
pub const __WASI_ENOMEM: __wasi_errno_t = 48;
pub const __WASI_ENOMSG: __wasi_errno_t = 49;
pub const __WASI_ENOPROTOOPT: __wasi_errno_t = 50;
pub const __WASI_ENOSPC: __wasi_errno_t = 51;
pub const __WASI_ENOSYS: __wasi_errno_t = 52;
pub const __WASI_ENOTCONN: __wasi_errno_t = 53;
pub const __WASI_ENOTDIR: __wasi_errno_t = 54;
pub const __WASI_ENOTEMPTY: __wasi_errno_t = 55;
pub const __WASI_ENOTRECOVERABLE: __wasi_errno_t = 56;
pub const __WASI_ENOTSOCK: __wasi_errno_t = 57;
pub const __WASI_ENOTSUP: __wasi_errno_t = 58;
pub const __WASI_ENOTTY: __wasi_errno_t = 59;
pub const __WASI_ENXIO: __wasi_errno_t = 60;
pub const __WASI_EOVERFLOW: __wasi_errno_t = 61;
pub const __WASI_EOWNERDEAD: __wasi_errno_t = 62;
pub const __WASI_EPERM: __wasi_errno_t = 63;
pub const __WASI_EPIPE: __wasi_errno_t = 64;
pub const __WASI_EPROTO: __wasi_errno_t = 65;
pub const __WASI_EPROTONOSUPPORT: __wasi_errno_t = 66;
pub const __WASI_EPROTOTYPE: __wasi_errno_t = 67;
pub const __WASI_ERANGE: __wasi_errno_t = 68;
pub const __WASI_EROFS: __wasi_errno_t = 69;
pub const __WASI_ESPIPE: __wasi_errno_t = 70;
pub const __WASI_ESRCH: __wasi_errno_t = 71;
pub const __WASI_ESTALE: __wasi_errno_t = 72;
pub const __WASI_ETIMEDOUT: __wasi_errno_t = 73;
pub const __WASI_ETXTBSY: __wasi_errno_t = 74;
pub const __WASI_EXDEV: __wasi_errno_t = 75;
pub const __WASI_ENOTCAPABLE: __wasi_errno_t = 76;
// pub type __wasi_preopentype_t = u8;
pub const __WASI_PREOPENTYPE_DIR: __wasi_preopentype_t = 0;

View File

@@ -1,183 +0,0 @@
use super::host;
use super::wasm32;
use errno::{errno, Errno};
/// Convert POSIX error code to host's WASI error code
fn convert_errno(error: Errno) -> host::__wasi_errno_t {
#[allow(unreachable_patterns)]
match error.into() {
libc::E2BIG => host::__WASI_E2BIG,
libc::EACCES => host::__WASI_EACCES,
libc::EADDRINUSE => host::__WASI_EADDRINUSE,
libc::EADDRNOTAVAIL => host::__WASI_EADDRNOTAVAIL,
libc::EAFNOSUPPORT => host::__WASI_EAFNOSUPPORT,
libc::EAGAIN | libc::EWOULDBLOCK => host::__WASI_EAGAIN,
libc::EALREADY => host::__WASI_EALREADY,
libc::EBADF => host::__WASI_EBADF,
libc::EBADMSG => host::__WASI_EBADMSG,
libc::EBUSY => host::__WASI_EBUSY,
libc::ECANCELED => host::__WASI_ECANCELED,
libc::ECHILD => host::__WASI_ECHILD,
libc::ECONNABORTED => host::__WASI_ECONNABORTED,
libc::ECONNREFUSED => host::__WASI_ECONNREFUSED,
libc::ECONNRESET => host::__WASI_ECONNRESET,
libc::EDEADLK => host::__WASI_EDEADLK,
libc::EDESTADDRREQ => host::__WASI_EDESTADDRREQ,
libc::EDOM => host::__WASI_EDOM,
libc::EDQUOT => host::__WASI_EDQUOT,
libc::EEXIST => host::__WASI_EEXIST,
libc::EFAULT => host::__WASI_EFAULT,
libc::EFBIG => host::__WASI_EFBIG,
libc::EHOSTUNREACH => host::__WASI_EHOSTUNREACH,
libc::EIDRM => host::__WASI_EIDRM,
libc::EILSEQ => host::__WASI_EILSEQ,
libc::EINPROGRESS => host::__WASI_EINPROGRESS,
libc::EINTR => host::__WASI_EINTR,
libc::EINVAL => host::__WASI_EINVAL,
libc::EIO => host::__WASI_EIO,
libc::EISCONN => host::__WASI_EISCONN,
libc::EISDIR => host::__WASI_EISDIR,
libc::ELOOP => host::__WASI_ELOOP,
libc::EMFILE => host::__WASI_EMFILE,
libc::EMLINK => host::__WASI_EMLINK,
libc::EMSGSIZE => host::__WASI_EMSGSIZE,
libc::EMULTIHOP => host::__WASI_EMULTIHOP,
libc::ENAMETOOLONG => host::__WASI_ENAMETOOLONG,
libc::ENETDOWN => host::__WASI_ENETDOWN,
libc::ENETRESET => host::__WASI_ENETRESET,
libc::ENETUNREACH => host::__WASI_ENETUNREACH,
libc::ENFILE => host::__WASI_ENFILE,
libc::ENOBUFS => host::__WASI_ENOBUFS,
libc::ENODEV => host::__WASI_ENODEV,
libc::ENOENT => host::__WASI_ENOENT,
libc::ENOEXEC => host::__WASI_ENOEXEC,
libc::ENOLCK => host::__WASI_ENOLCK,
libc::ENOLINK => host::__WASI_ENOLINK,
libc::ENOMEM => host::__WASI_ENOMEM,
libc::ENOMSG => host::__WASI_ENOMSG,
libc::ENOPROTOOPT => host::__WASI_ENOPROTOOPT,
libc::ENOSPC => host::__WASI_ENOSPC,
libc::ENOSYS => host::__WASI_ENOSYS,
// TODO: verify if this is correct
#[cfg(target_os = "freebsd")]
libc::ENOTCAPABLE => host::__WASI_ENOTCAPABLE,
libc::ENOTCONN => host::__WASI_ENOTCONN,
libc::ENOTDIR => host::__WASI_ENOTDIR,
libc::ENOTEMPTY => host::__WASI_ENOTEMPTY,
libc::ENOTRECOVERABLE => host::__WASI_ENOTRECOVERABLE,
libc::ENOTSOCK => host::__WASI_ENOTSOCK,
libc::ENOTSUP | libc::EOPNOTSUPP => host::__WASI_ENOTSUP,
libc::ENOTTY => host::__WASI_ENOTTY,
libc::ENXIO => host::__WASI_ENXIO,
libc::EOVERFLOW => host::__WASI_EOVERFLOW,
libc::EOWNERDEAD => host::__WASI_EOWNERDEAD,
libc::EPERM => host::__WASI_EPERM,
libc::EPIPE => host::__WASI_EPIPE,
libc::EPROTO => host::__WASI_EPROTO,
libc::EPROTONOSUPPORT => host::__WASI_EPROTONOSUPPORT,
libc::EPROTOTYPE => host::__WASI_EPROTOTYPE,
libc::ERANGE => host::__WASI_ERANGE,
libc::EROFS => host::__WASI_EROFS,
libc::ESPIPE => host::__WASI_ESPIPE,
libc::ESRCH => host::__WASI_ESRCH,
libc::ESTALE => host::__WASI_ESTALE,
libc::ETIMEDOUT => host::__WASI_ETIMEDOUT,
libc::ETXTBSY => host::__WASI_ETXTBSY,
libc::EXDEV => host::__WASI_EXDEV,
_ => host::__WASI_ENOSYS,
}
}
fn fd_prestats_get_entry(
pt: &host::fd_prestats,
fd: host::__wasi_fd_t,
) -> Option<&host::fd_prestat> {
// Test for file descriptor existence
if fd as usize >= pt.size {
return None;
}
let prestat = unsafe { &*pt.prestats.add(fd as usize) };
if prestat.dir_name == ::std::ptr::null() {
return None;
}
Some(prestat)
}
macro_rules! rwlock_rdlock {
($prestats:expr) => {
unsafe {
host::rwlock_rdlock(&mut (*$prestats).lock as *mut host::rwlock);
}
};
}
macro_rules! rwlock_unlock {
($prestats:expr) => {
unsafe {
host::rwlock_unlock(&mut (*$prestats).lock as *mut host::rwlock);
}
};
}
pub fn wasmtime_ssp_proc_exit(rval: wasm32::__wasi_exitcode_t) {
::std::process::exit(rval as i32)
}
pub fn wasmtime_ssp_fd_prestat_get(
prestats: &mut host::fd_prestats,
fd: host::__wasi_fd_t,
buf: &mut host::__wasi_prestat_t,
) -> host::__wasi_errno_t {
rwlock_rdlock!(prestats);
let ret_code = if let Some(prestat) = fd_prestats_get_entry(prestats, fd) {
buf.pr_type = host::__WASI_PREOPENTYPE_DIR;
unsafe {
buf.u.dir.pr_name_len = prestat.dir_name_len;
}
host::__WASI_ESUCCESS
} else {
host::__WASI_EBADF
};
rwlock_unlock!(prestats);
ret_code
}
pub fn wasmtime_ssp_fd_prestat_dir_name(
prestats: &mut host::fd_prestats,
fd: host::__wasi_fd_t,
path: &mut [host::char],
) -> host::__wasi_errno_t {
rwlock_rdlock!(prestats);
let ret_code = if let Some(prestat) = fd_prestats_get_entry(prestats, fd) {
if path.len() != prestat.dir_name_len {
host::__WASI_EINVAL
} else {
path.copy_from_slice(unsafe {
::std::slice::from_raw_parts(prestat.dir_name, prestat.dir_name_len)
});
host::__WASI_ESUCCESS
}
} else {
host::__WASI_EBADF
};
rwlock_unlock!(prestats);
ret_code
}
pub fn wasmtime_ssp_sched_yield() -> host::__wasi_errno_t {
unsafe {
if libc::sched_yield() < 0 {
return convert_errno(errno());
}
}
host::__WASI_ESUCCESS
}

View File

@@ -1,32 +1,22 @@
use crate::host::{
argv_environ_init, argv_environ_values, fd_prestats, fd_prestats_init, fd_prestats_insert,
fd_table, fd_table_init, fd_table_insert_existing,
};
use cranelift_codegen::ir::types;
use cranelift_codegen::{ir, isa};
use cranelift_entity::PrimaryMap;
use cranelift_wasm::DefinedFuncIndex;
use std::cell::RefCell;
use std::collections::HashMap;
use std::ffi::CString;
use std::mem;
use std::fs::File;
use std::rc::Rc;
use syscalls;
use target_lexicon::HOST;
use wasi_common::WasiCtxBuilder;
use wasmtime_environ::{translate_signature, Export, Module};
use wasmtime_runtime::{Imports, InstanceHandle, InstantiationError, VMFunctionBody};
pub(crate) struct WASIState {
pub curfds: Box<fd_table>,
pub prestats: Box<fd_prestats>,
pub argv_environ: Box<argv_environ_values>,
}
/// 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, libc::c_int)],
preopened_dirs: &[(String, File)],
argv: &[String],
environ: &[(String, String)],
) -> Result<InstanceHandle, InstantiationError> {
@@ -110,54 +100,29 @@ pub fn instantiate_wasi(
let imports = Imports::none();
let data_initializers = Vec::new();
let signatures = PrimaryMap::new();
let mut curfds = Box::new(unsafe { mem::zeroed::<fd_table>() });
let mut prestats = Box::new(unsafe { mem::zeroed::<fd_prestats>() });
let mut argv_environ = Box::new(unsafe { mem::zeroed::<argv_environ_values>() });
unsafe {
let argv_environ: &mut argv_environ_values = &mut *argv_environ;
let (argv_offsets, argv_buf, environ_offsets, environ_buf) =
allocate_argv_environ(argv, environ);
argv_environ_init(
argv_environ,
argv_offsets.as_ptr(),
argv_offsets.len(),
argv_buf.as_ptr(),
argv_buf.len(),
environ_offsets.as_ptr(),
environ_offsets.len(),
environ_buf.as_ptr(),
environ_buf.len(),
);
let args: Vec<&str> = argv.iter().map(AsRef::as_ref).collect();
let mut wasi_ctx_builder = WasiCtxBuilder::new().args(&args).inherit_stdio();
let curfds: *mut fd_table = &mut *curfds;
fd_table_init(curfds);
let prestats: *mut fd_prestats = &mut *prestats;
fd_prestats_init(prestats);
// Prepopulate curfds with stdin, stdout, and stderr file descriptors.
assert!(fd_table_insert_existing(curfds, 0, 0));
assert!(fd_table_insert_existing(curfds, 1, 1));
assert!(fd_table_insert_existing(curfds, 2, 2));
let mut wasm_fd = 3;
for (dir, fd) in preopened_dirs {
assert!(fd_table_insert_existing(curfds, wasm_fd, *fd));
assert!(fd_prestats_insert(
prestats,
CString::new(dir.as_str()).unwrap().as_ptr(),
wasm_fd,
));
wasm_fd += 1;
}
for (k, v) in environ {
wasi_ctx_builder = wasi_ctx_builder.env(k, v);
}
let host_state = WASIState {
curfds,
prestats,
argv_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))
})?;
InstanceHandle::new(
Rc::new(module),
@@ -167,37 +132,6 @@ pub fn instantiate_wasi(
&data_initializers,
signatures.into_boxed_slice(),
None,
Box::new(host_state),
Box::new(wasi_ctx),
)
}
fn allocate_argv_environ(
argv: &[String],
environ: &[(String, String)],
) -> (Vec<usize>, Vec<libc::c_char>, Vec<usize>, Vec<libc::c_char>) {
let mut argv_offsets = Vec::new();
let mut argv_buf = Vec::new();
let mut environ_offsets = Vec::new();
let mut environ_buf = Vec::new();
for arg in argv {
argv_offsets.push(argv_buf.len());
for c in arg.bytes() {
argv_buf.push(c as libc::c_char);
}
argv_buf.push('\0' as libc::c_char);
}
for (key, value) in environ {
environ_offsets.push(environ_buf.len());
for c in key.bytes() {
environ_buf.push(c as libc::c_char);
}
environ_buf.push('=' as libc::c_char);
for c in value.bytes() {
environ_buf.push(c as libc::c_char);
}
environ_buf.push('\0' as libc::c_char);
}
(argv_offsets, argv_buf, environ_offsets, environ_buf)
}

View File

@@ -1,4 +1,3 @@
extern crate cast;
extern crate cranelift_codegen;
extern crate cranelift_entity;
extern crate cranelift_wasm;
@@ -8,13 +7,9 @@ extern crate wasmtime_jit;
extern crate wasmtime_runtime;
#[macro_use]
extern crate log;
extern crate errno;
extern crate wasi_common;
mod host;
mod host_impls;
mod instantiate;
mod syscalls;
mod translate;
mod wasm32;
pub use instantiate::instantiate_wasi;

File diff suppressed because it is too large Load Diff

View File

@@ -1,573 +0,0 @@
use cast;
use cast::From as _0;
use host;
use std::mem::{align_of, size_of, zeroed};
use std::slice;
use wasm32;
use wasmtime_runtime::{Export, VMContext};
/// Translate a wasm pointer into a native pointer.
///
/// This is unsafe due to trusting the contents of vmctx. The pointer result
/// is bounds and alignment checked.
unsafe fn decode_ptr(
vmctx: &mut VMContext,
ptr: wasm32::uintptr_t,
len: usize,
align: usize,
) -> Result<*mut u8, host::__wasi_errno_t> {
match vmctx.lookup_global_export("memory") {
Some(Export::Memory {
definition,
vmctx: _,
memory: _,
}) => {
if len > 0 {
// Check for overflow within the access.
let last = match (ptr as usize).checked_add(len - 1) {
Some(sum) => sum,
None => {
println!("!!! overflow");
return Err(host::__WASI_EFAULT as host::__wasi_errno_t);
}
};
// Check for out of bounds.
if last >= (*definition).current_length {
println!("!!! out of bounds");
return Err(host::__WASI_EFAULT as host::__wasi_errno_t);
}
}
// Check alignment.
if (ptr as usize) % align != 0 {
println!("!!! bad alignment: {} % {}", ptr, align);
return Err(host::__WASI_EINVAL as host::__wasi_errno_t);
}
// Ok, translate the address.
Ok((((*definition).base as usize) + (ptr as usize)) as *mut u8)
}
// No export named "__wasi_memory", or the export isn't a memory.
// FIXME: Is EINVAL the best code here?
x => {
println!(
"!!! no export named __wasi_memory, or the export isn't a mem: {:?}",
x
);
Err(host::__WASI_EINVAL as host::__wasi_errno_t)
}
}
}
unsafe fn decode_ptr_to<T>(
vmctx: &mut VMContext,
ptr: wasm32::uintptr_t,
) -> Result<*mut T, host::__wasi_errno_t> {
decode_ptr(vmctx, ptr, size_of::<T>(), align_of::<T>()).map(|ptr| ptr as *mut T)
}
unsafe fn decode_pointee<T>(
vmctx: &mut VMContext,
ptr: wasm32::uintptr_t,
) -> Result<(), host::__wasi_errno_t> {
// Check bounds and alignment.
decode_ptr_to::<T>(vmctx, ptr)?;
Ok(())
}
pub unsafe fn encode_pointee<T>(vmctx: &mut VMContext, ptr: wasm32::uintptr_t, t: T) {
// Bounds and alignment are checked in `decode_pointee`.
let ptr = decode_ptr_to::<T>(vmctx, ptr).unwrap();
ptr.write(t);
}
pub unsafe fn decode_slice_of<T>(
vmctx: &mut VMContext,
ptr: wasm32::uintptr_t,
len: wasm32::size_t,
) -> Result<(*mut T, usize), host::__wasi_errno_t> {
let len = cast::usize(len);
let ptr = decode_ptr(
vmctx,
ptr,
size_of::<T>().checked_mul(len).unwrap(),
align_of::<T>(),
)? as *mut T;
Ok((ptr, len))
}
pub fn encode_usize(len: usize) -> wasm32::size_t {
cast::u32(len).unwrap()
}
pub fn encode_device(device: host::__wasi_device_t) -> wasm32::__wasi_device_t {
device
}
pub fn encode_inode(inode: host::__wasi_inode_t) -> wasm32::__wasi_inode_t {
inode
}
pub fn encode_linkcount(linkcount: host::__wasi_linkcount_t) -> wasm32::__wasi_linkcount_t {
linkcount
}
pub fn decode_userdata(userdata: wasm32::__wasi_userdata_t) -> host::__wasi_userdata_t {
userdata
}
pub fn encode_userdata(userdata: host::__wasi_userdata_t) -> wasm32::__wasi_userdata_t {
userdata
}
pub fn decode_eventtype(eventtype: wasm32::__wasi_eventtype_t) -> host::__wasi_eventtype_t {
eventtype
}
pub fn encode_eventtype(eventtype: host::__wasi_eventtype_t) -> wasm32::__wasi_eventtype_t {
eventtype
}
pub fn decode_filesize(filesize: wasm32::__wasi_filesize_t) -> host::__wasi_filesize_t {
filesize
}
pub fn encode_filesize(filesize: host::__wasi_filesize_t) -> wasm32::__wasi_filesize_t {
filesize
}
pub fn encode_eventrwflags(
eventrwflags: host::__wasi_eventrwflags_t,
) -> wasm32::__wasi_eventrwflags_t {
eventrwflags
}
pub fn decode_subclockflags(
subclockflags: wasm32::__wasi_subclockflags_t,
) -> host::__wasi_subclockflags_t {
subclockflags
}
pub fn decode_fd(fd: wasm32::__wasi_fd_t) -> host::__wasi_fd_t {
fd
}
pub fn decode_filedelta(filedelta: wasm32::__wasi_filedelta_t) -> host::__wasi_filedelta_t {
filedelta
}
pub fn decode_whence(whence: wasm32::__wasi_whence_t) -> host::__wasi_whence_t {
whence
}
pub fn decode_clockid(clockid: wasm32::__wasi_clockid_t) -> host::__wasi_clockid_t {
clockid
}
pub fn decode_timestamp(timestamp: wasm32::__wasi_timestamp_t) -> host::__wasi_timestamp_t {
timestamp
}
pub fn encode_timestamp(timestamp: host::__wasi_timestamp_t) -> wasm32::__wasi_timestamp_t {
timestamp
}
pub fn decode_exitcode(exitcode: wasm32::__wasi_exitcode_t) -> host::__wasi_exitcode_t {
exitcode
}
pub fn decode_lookupflags(lookupflags: wasm32::__wasi_lookupflags_t) -> host::__wasi_lookupflags_t {
lookupflags
}
pub fn decode_oflags(oflags: wasm32::__wasi_oflags_t) -> host::__wasi_oflags_t {
oflags
}
pub fn decode_advice(advice: wasm32::__wasi_advice_t) -> host::__wasi_advice_t {
advice
}
pub fn decode_dircookie(dircookie: wasm32::__wasi_dircookie_t) -> host::__wasi_dircookie_t {
dircookie
}
pub fn encode_preopentype(preopentype: host::__wasi_preopentype_t) -> wasm32::__wasi_preopentype_t {
preopentype
}
pub fn encode_filetype(filetype: host::__wasi_filetype_t) -> wasm32::__wasi_filetype_t {
filetype
}
pub fn decode_fstflags(fstflags: wasm32::__wasi_fstflags_t) -> host::__wasi_fstflags_t {
fstflags
}
#[allow(dead_code)]
pub fn encode_fstflags(fstflags: host::__wasi_fstflags_t) -> wasm32::__wasi_fstflags_t {
fstflags
}
pub fn decode_fdflags(fdflags: wasm32::__wasi_fdflags_t) -> host::__wasi_fdflags_t {
fdflags
}
pub fn encode_fdflags(fdflags: host::__wasi_fdflags_t) -> wasm32::__wasi_fdflags_t {
fdflags
}
pub fn decode_sdflags(sdflags: wasm32::__wasi_sdflags_t) -> host::__wasi_sdflags_t {
sdflags
}
pub fn decode_rights(rights: wasm32::__wasi_rights_t) -> host::__wasi_rights_t {
rights
}
pub fn encode_rights(rights: host::__wasi_rights_t) -> wasm32::__wasi_rights_t {
rights
}
pub fn decode_riflags(riflags: wasm32::__wasi_riflags_t) -> host::__wasi_riflags_t {
riflags
}
pub fn decode_siflags(siflags: wasm32::__wasi_siflags_t) -> host::__wasi_siflags_t {
siflags
}
pub unsafe fn decode_char_slice(
vmctx: &mut VMContext,
ptr: wasm32::uintptr_t,
len: wasm32::size_t,
) -> Result<(*mut host::char, usize), host::__wasi_errno_t> {
decode_slice_of::<wasm32::char>(vmctx, ptr, len)
}
pub unsafe fn decode_charstar_slice(
vmctx: &mut VMContext,
ptr: wasm32::uintptr_t,
count: wasm32::size_t,
) -> Result<(*mut wasm32::uintptr_t, usize), host::__wasi_errno_t> {
decode_slice_of::<wasm32::uintptr_t>(vmctx, ptr, count)
}
pub unsafe fn encode_charstar_slice(
ptr: *mut wasm32::uintptr_t,
host_vec: Vec<*mut libc::c_char>,
guest_base: wasm32::uintptr_t,
host_base: *mut libc::c_char,
) {
for (i, host) in host_vec.iter().enumerate() {
let guest = if host.is_null() {
0
} else {
guest_base + (*host as usize - host_base as usize) as wasm32::uintptr_t
};
ptr.add(i).write(guest);
}
}
pub unsafe fn decode_ciovec(
vmctx: &mut VMContext,
ciovec: &wasm32::__wasi_ciovec_t,
) -> Result<host::__wasi_ciovec_t, host::__wasi_errno_t> {
let len = cast::usize(ciovec.buf_len);
Ok(host::__wasi_ciovec_t {
buf: decode_ptr(vmctx, ciovec.buf, len, 1)? as *const host::void,
buf_len: len,
})
}
pub unsafe fn decode_iovec(
vmctx: &mut VMContext,
iovec: &wasm32::__wasi_iovec_t,
) -> Result<host::__wasi_iovec_t, host::__wasi_errno_t> {
let len = cast::usize(iovec.buf_len);
Ok(host::__wasi_iovec_t {
buf: decode_ptr(vmctx, iovec.buf, len, 1)? as *mut host::void,
buf_len: len,
})
}
pub unsafe fn decode_ciovec_slice(
vmctx: &mut VMContext,
ptr: wasm32::uintptr_t,
len: wasm32::size_t,
) -> Result<Vec<host::__wasi_ciovec_t>, host::__wasi_errno_t> {
let slice = decode_slice_of::<wasm32::__wasi_ciovec_t>(vmctx, ptr, len)?;
let slice = slice::from_raw_parts(slice.0, slice.1);
slice.iter().map(|iov| decode_ciovec(vmctx, iov)).collect()
}
pub unsafe fn decode_iovec_slice(
vmctx: &mut VMContext,
ptr: wasm32::uintptr_t,
len: wasm32::size_t,
) -> Result<Vec<host::__wasi_iovec_t>, host::__wasi_errno_t> {
let slice = decode_slice_of::<wasm32::__wasi_iovec_t>(vmctx, ptr, len)?;
let slice = slice::from_raw_parts(slice.0, slice.1);
slice.iter().map(|iov| decode_iovec(vmctx, iov)).collect()
}
pub fn decode_subscription(
guest_subscription: wasm32::__wasi_subscription_t,
) -> Result<host::__wasi_subscription_t, host::__wasi_errno_t> {
let mut host_subscription = host::__wasi_subscription_t {
userdata: decode_userdata(guest_subscription.userdata),
type_: decode_eventtype(guest_subscription.type_),
u: unsafe { zeroed() },
};
match guest_subscription.type_ {
wasm32::__WASI_EVENTTYPE_CLOCK => unsafe {
host_subscription.u.clock =
host::__wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_clock_t {
identifier: decode_userdata(guest_subscription.u.clock.identifier),
clock_id: decode_clockid(guest_subscription.u.clock.clock_id),
timeout: decode_timestamp(guest_subscription.u.clock.timeout),
precision: decode_timestamp(guest_subscription.u.clock.precision),
flags: decode_subclockflags(guest_subscription.u.clock.flags),
};
},
wasm32::__WASI_EVENTTYPE_FD_READ | wasm32::__WASI_EVENTTYPE_FD_WRITE => unsafe {
host_subscription
.u
.fd_readwrite =
host::__wasi_subscription_t___wasi_subscription_u___wasi_subscription_u_fd_readwrite_t {
fd: decode_fd(guest_subscription.u.fd_readwrite.fd),
}
},
_ => return Err(host::__WASI_EINVAL as host::__wasi_errno_t),
};
Ok(host_subscription)
}
pub unsafe fn decode_subscription_slice(
vmctx: &mut VMContext,
ptr: wasm32::uintptr_t,
len: wasm32::size_t,
) -> Result<Vec<host::__wasi_subscription_t>, host::__wasi_errno_t> {
let slice = decode_slice_of::<wasm32::__wasi_subscription_t>(vmctx, ptr, len)?;
let slice = slice::from_raw_parts(slice.0, slice.1);
slice
.iter()
.map(|subscription| decode_subscription(*subscription))
.collect()
}
pub fn encode_event(host_event: host::__wasi_event_t) -> wasm32::__wasi_event_t {
let mut guest_event = wasm32::__wasi_event_t {
userdata: encode_userdata(host_event.userdata),
error: encode_errno(host_event.error),
type_: encode_eventtype(host_event.type_),
u: unsafe { zeroed() },
__bindgen_padding_0: 0,
};
match u32::from(host_event.type_) {
host::__WASI_EVENTTYPE_CLOCK => {}
host::__WASI_EVENTTYPE_FD_READ | host::__WASI_EVENTTYPE_FD_WRITE => unsafe {
guest_event.u.fd_readwrite =
wasm32::__wasi_event_t___wasi_event_u___wasi_event_u_fd_readwrite_t {
nbytes: encode_filesize(host_event.u.fd_readwrite.nbytes),
flags: encode_eventrwflags(host_event.u.fd_readwrite.flags),
__bindgen_padding_0: zeroed(),
}
},
_ => panic!("unrecognized event type"),
};
guest_event
}
pub unsafe fn decode_event_slice(
vmctx: &mut VMContext,
ptr: wasm32::uintptr_t,
len: wasm32::size_t,
) -> Result<(*mut wasm32::__wasi_event_t, usize), host::__wasi_errno_t> {
decode_slice_of::<wasm32::__wasi_event_t>(vmctx, ptr, len)
}
pub unsafe fn encode_event_slice(
ptr: *mut wasm32::__wasi_event_t,
host_vec: Vec<host::__wasi_event_t>,
) {
for (i, host) in host_vec.iter().enumerate() {
let guest = encode_event(*host);
ptr.add(i * size_of::<wasm32::__wasi_event_t>())
.write(guest);
}
}
pub unsafe fn decode_fd_byref(
vmctx: &mut VMContext,
fd_ptr: wasm32::uintptr_t,
) -> Result<(), host::__wasi_errno_t> {
decode_pointee::<wasm32::__wasi_fd_t>(vmctx, fd_ptr)
}
pub unsafe fn encode_fd_byref(
vmctx: &mut VMContext,
fd_ptr: wasm32::uintptr_t,
fd: host::__wasi_fd_t,
) {
encode_pointee::<wasm32::__wasi_fd_t>(vmctx, fd_ptr, wasm32::size_t::cast(fd))
}
pub unsafe fn decode_timestamp_byref(
vmctx: &mut VMContext,
timestamp_ptr: wasm32::uintptr_t,
) -> Result<(), host::__wasi_errno_t> {
decode_pointee::<wasm32::__wasi_timestamp_t>(vmctx, timestamp_ptr)
}
pub unsafe fn encode_timestamp_byref(
vmctx: &mut VMContext,
timestamp_ptr: wasm32::uintptr_t,
host_timestamp: host::__wasi_timestamp_t,
) {
encode_pointee::<wasm32::__wasi_timestamp_t>(
vmctx,
timestamp_ptr,
wasm32::__wasi_timestamp_t::cast(host_timestamp),
)
}
pub unsafe fn decode_filesize_byref(
vmctx: &mut VMContext,
filesize_ptr: wasm32::uintptr_t,
) -> Result<(), host::__wasi_errno_t> {
decode_pointee::<wasm32::__wasi_filesize_t>(vmctx, filesize_ptr)
}
pub unsafe fn encode_filesize_byref(
vmctx: &mut VMContext,
filesize_ptr: wasm32::uintptr_t,
host_filesize: host::__wasi_filesize_t,
) {
encode_pointee::<wasm32::__wasi_filesize_t>(
vmctx,
filesize_ptr,
wasm32::__wasi_filesize_t::cast(host_filesize),
)
}
pub unsafe fn decode_roflags_byref(
vmctx: &mut VMContext,
roflags_ptr: wasm32::uintptr_t,
) -> Result<(), host::__wasi_errno_t> {
decode_pointee::<wasm32::__wasi_roflags_t>(vmctx, roflags_ptr)
}
pub unsafe fn encode_roflags_byref(
vmctx: &mut VMContext,
roflags_ptr: wasm32::uintptr_t,
host_roflags: host::__wasi_roflags_t,
) {
encode_pointee::<wasm32::__wasi_roflags_t>(
vmctx,
roflags_ptr,
wasm32::__wasi_roflags_t::cast(host_roflags),
)
}
pub unsafe fn decode_usize_byref(
vmctx: &mut VMContext,
usize_ptr: wasm32::uintptr_t,
) -> Result<(), host::__wasi_errno_t> {
decode_pointee::<wasm32::size_t>(vmctx, usize_ptr)
}
pub unsafe fn encode_usize_byref(
vmctx: &mut VMContext,
usize_ptr: wasm32::uintptr_t,
host_usize: usize,
) {
encode_pointee::<wasm32::size_t>(vmctx, usize_ptr, wasm32::size_t::cast(host_usize).unwrap())
}
pub unsafe fn decode_prestat_byref(
vmctx: &mut VMContext,
prestat_ptr: wasm32::uintptr_t,
) -> Result<(), host::__wasi_errno_t> {
decode_pointee::<wasm32::__wasi_prestat_t>(vmctx, prestat_ptr)?;
Ok(())
}
pub unsafe fn encode_prestat_byref(
vmctx: &mut VMContext,
prestat_ptr: wasm32::uintptr_t,
host_prestat: host::__wasi_prestat_t,
) {
let wasm32_prestat = wasm32::__wasi_prestat_t {
pr_type: encode_preopentype(host_prestat.pr_type),
u: wasm32::__wasi_prestat_t___wasi_prestat_u {
dir: wasm32::__wasi_prestat_t___wasi_prestat_u___wasi_prestat_u_dir_t {
pr_name_len: encode_usize(host_prestat.u.dir.pr_name_len),
},
},
};
encode_pointee::<wasm32::__wasi_prestat_t>(vmctx, prestat_ptr, wasm32_prestat)
}
pub unsafe fn decode_fdstat_byref(
vmctx: &mut VMContext,
fdstat_ptr: wasm32::uintptr_t,
) -> Result<(), host::__wasi_errno_t> {
decode_pointee::<wasm32::__wasi_fdstat_t>(vmctx, fdstat_ptr)?;
Ok(())
}
pub unsafe fn encode_fdstat_byref(
vmctx: &mut VMContext,
fdstat_ptr: wasm32::uintptr_t,
host_fdstat: host::__wasi_fdstat_t,
) {
let wasm32_fdstat = wasm32::__wasi_fdstat_t {
fs_filetype: encode_filetype(host_fdstat.fs_filetype),
fs_flags: encode_fdflags(host_fdstat.fs_flags),
__bindgen_padding_0: 0,
fs_rights_base: encode_rights(host_fdstat.fs_rights_base),
fs_rights_inheriting: encode_rights(host_fdstat.fs_rights_inheriting),
};
encode_pointee::<wasm32::__wasi_fdstat_t>(vmctx, fdstat_ptr, wasm32_fdstat)
}
pub unsafe fn decode_filestat_byref(
vmctx: &mut VMContext,
filestat_ptr: wasm32::uintptr_t,
) -> Result<(), host::__wasi_errno_t> {
decode_pointee::<wasm32::__wasi_filestat_t>(vmctx, filestat_ptr)?;
Ok(())
}
pub unsafe fn encode_filestat_byref(
vmctx: &mut VMContext,
filestat_ptr: wasm32::uintptr_t,
host_filestat: host::__wasi_filestat_t,
) {
let wasm32_filestat = wasm32::__wasi_filestat_t {
st_dev: encode_device(host_filestat.st_dev),
st_ino: encode_inode(host_filestat.st_ino),
st_filetype: encode_filetype(host_filestat.st_filetype),
st_nlink: encode_linkcount(host_filestat.st_nlink),
st_size: encode_filesize(host_filestat.st_size),
st_atim: encode_timestamp(host_filestat.st_atim),
st_mtim: encode_timestamp(host_filestat.st_mtim),
st_ctim: encode_timestamp(host_filestat.st_ctim),
};
encode_pointee::<wasm32::__wasi_filestat_t>(vmctx, filestat_ptr, wasm32_filestat)
}
pub fn encode_errno(e: host::__wasi_errno_t) -> wasm32::__wasi_errno_t {
assert!(e <= wasm32::__WASI_ENOTCAPABLE);
e
}

File diff suppressed because it is too large Load Diff