Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dash fixes and pthreads #3663

Merged
merged 70 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
dd8c902
Fixed the signals and error codes
john-sharratt Mar 3, 2023
e39c438
Staging changes ready for WASIX syscall changes
john-sharratt Mar 3, 2023
1eba7cf
Fixed the proc_join syscall
john-sharratt Mar 3, 2023
010e7a2
Added the missing join flags to proc_join
john-sharratt Mar 3, 2023
f365bb6
Added extra debug information on the closing of files
john-sharratt Mar 3, 2023
5c2f001
Added the new thread start routines
john-sharratt Mar 6, 2023
65eed0d
Implemented the threads spec (pthreads) for WASIX
john-sharratt Mar 6, 2023
949a4bd
Merge branch 'master' into dash-fixes
john-sharratt Mar 6, 2023
33d87eb
Merge branch 'master' into dash-fixes
john-sharratt Mar 7, 2023
ea76a73
Merge remote-tracking branch 'origin' into dash-fixes
john-sharratt Mar 7, 2023
be5242d
Now implementing TTY and getcwd properly which is needed for bash and…
john-sharratt Mar 7, 2023
e4187d7
Restructured the subprocesses so that they will be easier to join on
john-sharratt Mar 7, 2023
b881e5b
Joining an an explicit process will now remove it as a child and be r…
john-sharratt Mar 7, 2023
90bedfc
Fixed the TTY for both dash and bash
john-sharratt Mar 7, 2023
5442c48
Fixes for the dash and bash snapshot tests
john-sharratt Mar 8, 2023
dc8f86e
Fixed the snapshot tests
john-sharratt Mar 9, 2023
1c85b34
Removed tracing dependency that should not have been added
john-sharratt Mar 9, 2023
80b10fc
Updates for the review comments
john-sharratt Mar 9, 2023
4abbec7
Merge remote-tracking branch 'origin/master' into dash-fixes-and-pthr…
john-sharratt Mar 9, 2023
dbacbb9
refactor(wasi): Move capabilities into root submodule
theduke Mar 8, 2023
6009b05
Fixed the joining of subprocesses which was blocking due to a race co…
john-sharratt Mar 10, 2023
1e68b6f
Fixed the lint errors
john-sharratt Mar 10, 2023
1a19cbc
Fixes so that windows compiles again with the new TTY changes
john-sharratt Mar 10, 2023
761fff3
More lint and non-unix compile fixes
john-sharratt Mar 10, 2023
86e0ad0
Fixed the last snapshot integration tests
john-sharratt Mar 10, 2023
981962a
cargo fmt --all
john-sharratt Mar 10, 2023
1dfddf8
No longer causing a panic when globals are set to null in JS
john-sharratt Mar 10, 2023
6308144
Fixed create-exe WASI programs that will fail to exit properly
ptitSeb Mar 10, 2023
a41bf19
Refactored the exit codes so they can be strongly typed and arbitary
john-sharratt Mar 11, 2023
7e0055b
Clippy fixes
john-sharratt Mar 11, 2023
5f3619b
More lint fixes
john-sharratt Mar 11, 2023
e38fd33
On single threading apps the PID == TID
john-sharratt Mar 11, 2023
beadf18
Fixed a memory corruption issue due to an incorrectly implemented mem…
john-sharratt Mar 11, 2023
6f69912
Fix for partially written files which cause the snapshot tests to fail
john-sharratt Mar 11, 2023
dce7aaa
Fixed an issue with the forking fixes on JS builds
john-sharratt Mar 11, 2023
665230f
Improvements to the snapshot tests and added extra validation of the …
john-sharratt Mar 11, 2023
61d0972
Improved the fork and fork-longjmp unit tests
john-sharratt Mar 11, 2023
09c6805
The snapshot tests now order the debug messages for consistency and r…
john-sharratt Mar 11, 2023
d1dc0fd
Fork snapshot tests now check the exit code on subprocesses
john-sharratt Mar 11, 2023
7b8fcff
Added extra validations on the fork unit test and some stability to t…
john-sharratt Mar 11, 2023
e0d884b
Fixed an issue where the exit codes were not being properly returned …
john-sharratt Mar 11, 2023
f39353b
Fixed some linting issues
john-sharratt Mar 11, 2023
8b21135
Added some extra parameters to pass to the web threading pool
john-sharratt Mar 12, 2023
43052d2
fix(wasi): Fix TaskJoinHandle::set_finished
theduke Mar 13, 2023
0c88654
Merge branch 'capability-threading' into deploy
theduke Mar 13, 2023
f32ed3b
Merge remote-tracking branch 'origin/master' into dash-fixes-and-pthr…
theduke Mar 13, 2023
46a0388
Merge branch 'master' into deploy
john-sharratt Mar 14, 2023
02fc138
Merge branch 'deploy' of github.com:wasmerio/wasmer into deploy
john-sharratt Mar 14, 2023
e13b5a1
Merge branch 'dash-fixes-and-pthreads' of github.com:wasmerio/wasmer …
john-sharratt Mar 14, 2023
3c57b84
Merge branch 'vectored-io-fix' into dash-fixes-and-pthreads
john-sharratt Mar 14, 2023
ca7be7a
Merge branch 'master' into dash-fixes-and-pthreads
john-sharratt Mar 15, 2023
76ca48b
Added tests for python in dash and bash and reenabled the vfork test
john-sharratt Mar 14, 2023
9c20584
Merge branch 'master' into dash-fixes-and-pthreads
john-sharratt Mar 16, 2023
e1fe620
Now using real temporary files that are unique to prevent a concurren…
john-sharratt Mar 16, 2023
0537a7c
Merge branch 'dash-fixes-and-pthreads' of github.com:wasmerio/wasmer …
john-sharratt Mar 16, 2023
8312c2e
Fixes for snapshot tests
john-sharratt Mar 16, 2023
987bc4a
Fixed a bug where the signals were not being properly processed
john-sharratt Mar 16, 2023
d7e2129
Added more snapshot tests for different scenarios
john-sharratt Mar 16, 2023
0b8d2b1
Added more tests for the dev files and added urandom support
john-sharratt Mar 16, 2023
21023a3
Added a HTTP server snapshot test
john-sharratt Mar 16, 2023
3ba3f41
Merge branch 'master' into dash-fixes-and-pthreads
john-sharratt Mar 16, 2023
7afc869
Merge branch 'master' into dash-fixes-and-pthreads
john-sharratt Mar 16, 2023
461c208
Moved the process exit to after the WASI cleanup and added some flush…
john-sharratt Mar 16, 2023
781d861
Added the ability to supply ones own webc packages to wasmer
john-sharratt Mar 16, 2023
34486b7
Updated the snapshot tests with the first part of offline webc packag…
john-sharratt Mar 16, 2023
e2bf8de
Merge branch 'master' into dash-fixes-and-pthreads
john-sharratt Mar 16, 2023
739aa0c
Snapshot tests can now work offline and are more deterministic
john-sharratt Mar 16, 2023
1531645
Fixed linting issues
john-sharratt Mar 16, 2023
fc7a5ad
Fixed the error code check - someone really needs to refactor this
john-sharratt Mar 16, 2023
bdc41ec
Targeting environments that the snapshot tests work on
john-sharratt Mar 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/types/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ pub unsafe trait MemorySize: Copy {
+ TryFrom<u32>
+ TryFrom<u16>
+ TryFrom<u8>
+ TryFrom<i32>
+ TryInto<usize>
+ TryInto<u64>
+ TryInto<u32>
+ TryInto<u16>
+ TryInto<u8>
+ TryInto<i32>
+ TryFrom<usize>
+ Add<Self::Offset>
+ Sum<Self::Offset>
Expand Down
1 change: 1 addition & 0 deletions lib/wasi-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ cfg-if = "1.0.0"
anyhow = "1.0.66"
byteorder = "1.3"
time = "0.2"
tracing = "0.1"
theduke marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies.pretty_assertions]
version = "1.3.0"
Expand Down
75 changes: 74 additions & 1 deletion lib/wasi-types/schema/wasi/typenames.wit
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
///
/// Note: This is similar to `size_t` in POSIX.
// TODO: This is defined as `usize` in the original witx file. Should verify that this type is good as it is defined here
// TODO: This is not good as it breaks 64bit builds - it will need to be externalized
type size = u32

/// Non-negative file size or length of a region within a file.
Expand Down Expand Up @@ -247,6 +248,10 @@ enum errno {
notcapable,
/// Cannot send after socket shutdown.
shutdown,
/// Memory access violation.
memviolation,
/// An unknown error has occured
unknown,
}

enum bus-errno {
Expand Down Expand Up @@ -813,12 +818,17 @@ record option-cid {
cid: cid
}

record option-pid {
tag: option-tag,
pid: pid
}

record option-fd {
tag: option-tag,
fd: fd
}

type exit-code = u32
type exit-code = errno

type event-fd-flags = u16

Expand Down Expand Up @@ -1132,6 +1142,7 @@ record option-timestamp {
}

enum signal {
sigunknown,
sighup,
sigint,
sigquit,
Expand All @@ -1147,6 +1158,7 @@ enum signal {
sigpipe,
sigalrm,
sigterm,
sigstkflt,
sigchld,
sigcont,
sigstop,
Expand Down Expand Up @@ -1205,3 +1217,64 @@ enum timeout {
connect,
accept,
}

/// join flags.
flags join-flags {
/// Non-blocking join on the process
non-blocking,
/// Return if a process is stopped
wake-stopped
}

/// What has happened with the proccess when we joined on it
enum join-status-type {
/// Nothing has happened
nothing,
/// The process has exited by a normal exit code
exit-normal,
/// The process was terminated by a signal
exit-signal,
/// The process was stopped by a signal and can be resumed with SIGCONT
stopped
}

/// Represents an errno and a signal
record errno-signal {
/// The exit code that was returned
exit-code: errno,
/// The signal that was returned
signal: signal
}

/// The contents of an `event`.
variant join-status {
// TODO: wit appears to not have support for tag type
//(@witx tag $join_status_type)
nothing(u8),
exit-normal(errno),
exit-signal(errno-signal),
stopped(signal)
}

/// thread state flags
flags thread-state-flags {
// TODO: wit doesnt appear to support repr
// flags (@witx repr u16)

// tsd_used
tsd-used,
// dlerror_flag
dlerror-flag
}

/// Represents the thread start object
record thread-start {
// Address where the stack starts
stack: size,
// Address where the TLS starts
tls-base: size,
// Function that will be invoked when the thread starts
start-funct: size,
// Arguments to pass the callback function
start-args: size,
}
410 changes: 366 additions & 44 deletions lib/wasi-types/src/wasi/bindings.rs

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions lib/wasi-types/src/wasi/bindings_manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,20 @@ impl From<std::io::Error> for Errno {
}
}
}

// TODO: if necessary, must be implemented in wit-bindgen
unsafe impl wasmer::FromToNativeWasmType for JoinFlags {
type Native = i32;

fn to_native(self) -> Self::Native {
self.bits() as i32
}
fn from_native(n: Self::Native) -> Self {
Self::from_bits_truncate(n as u32)
}

fn is_from_store(&self, _store: &impl wasmer::AsStoreRef) -> bool {
// TODO: find correct implementation
false
}
}
71 changes: 68 additions & 3 deletions lib/wasi-types/src/wasi/wasix_manual.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::mem::MaybeUninit;

use wasmer::ValueType;
use wasmer::{MemorySize, ValueType};

use super::{
Errno, EventFdReadwrite, Eventtype, Snapshot0SubscriptionClock, SubscriptionClock,
SubscriptionFsReadwrite, Userdata,
Errno, ErrnoSignal, EventFdReadwrite, Eventtype, JoinStatusType, Signal,
Snapshot0SubscriptionClock, SubscriptionClock, SubscriptionFsReadwrite, Userdata,
};

/// Thread local key
Expand Down Expand Up @@ -175,3 +175,68 @@ unsafe impl ValueType for StackSnapshot {
#[inline]
fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit<u8>]) {}
}

#[repr(C)]
#[derive(Clone, Copy)]
pub union JoinStatusUnion {
pub nothing: u8,
pub exit_normal: Errno,
pub exit_signal: ErrnoSignal,
pub stopped: Signal,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct JoinStatus {
pub tag: JoinStatusType,
pub u: JoinStatusUnion,
}
impl core::fmt::Debug for JoinStatus {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let mut binding = f.debug_struct("JoinStatus");
let mut f = binding.field("tag", &self.tag);
f = unsafe {
match self.tag {
JoinStatusType::Nothing => f.field("pid", &self.u.nothing),
JoinStatusType::ExitNormal => f.field("exit_normal", &self.u.exit_normal),
JoinStatusType::ExitSignal => f.field("exit_signal", &self.u.exit_signal),
JoinStatusType::Stopped => f.field("stopped", &self.u.stopped),
}
};
f.finish()
}
}
unsafe impl ValueType for JoinStatus {
#[inline]
fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit<u8>]) {}
}

#[doc = " Represents the thread start object"]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct ThreadStart<M: MemorySize> {
pub stack_start: M::Offset,
pub tls_base: M::Offset,
pub start_funct: M::Offset,
pub start_args: M::Offset,
pub reserved: [M::Offset; 10],
pub stack_size: M::Offset,
pub guard_size: M::Offset,
}
impl<M: MemorySize> core::fmt::Debug for ThreadStart<M> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("ThreadStart")
.field("stack_start", &self.stack_start)
.field("tls-base", &self.tls_base)
.field("start-funct", &self.start_funct)
.field("start-args", &self.start_args)
.field("stack_size", &self.stack_size)
.field("guard_size", &self.guard_size)
.finish()
}
}

// TODO: if necessary, must be implemented in wit-bindgen
unsafe impl<M: MemorySize> ValueType for ThreadStart<M> {
#[inline]
fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit<u8>]) {}
}
2 changes: 1 addition & 1 deletion lib/wasi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ webc_runner_rt_wcgi = ["hyper", "wcgi", "wcgi-host"]
webc_runner_rt_emscripten = ["wasmer-emscripten"]

sys = ["wasmer/sys", "wasmer-wasi-types/sys", "webc/mmap", "wasmer-vm", "time"]
sys-default = ["wasmer/wat", "wasmer/compiler", "sys", "logging", "host-fs", "sys-poll", "sys-thread", "host-vnet", "host-threads", "host-reqwest" ]
sys-default = ["wasmer/wat", "wasmer/compiler", "sys", "logging", "host-fs", "sys-poll", "sys-thread", "host-vnet", "host-threads", "host-reqwest", "host-termios" ]
sys-poll = []
sys-thread = ["tokio/rt", "tokio/time", "tokio/rt-multi-thread"]

Expand Down
8 changes: 4 additions & 4 deletions lib/wasi/src/bin_factory/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,17 @@ pub fn spawn_exec_module(
start
.call(&mut store, &[])
.map_err(WasiRuntimeError::from)
.map(|_| 0)
.map(|_| Errno::Success)
} else {
debug!("wasi[{}]::exec-failed: missing _start function", pid);
Ok(Errno::Noexec as u32)
Ok(Errno::Noexec)
john-sharratt marked this conversation as resolved.
Show resolved Hide resolved
};
debug!("wasi[{pid}]::main() has exited with {ret:?}");

let code = if let Err(err) = &ret {
err.as_exit_code().unwrap_or(Errno::Child as u32)
err.as_exit_code().unwrap_or(Errno::Child)
} else {
0
Errno::Success
};
thread.thread.set_status_finished(ret);

Expand Down
6 changes: 5 additions & 1 deletion lib/wasi/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ impl InodeGuard {
inner: Arc::downgrade(&self.inner),
}
}
pub fn ref_cnt(&self) -> usize {
Arc::strong_count(&self.inner)
}
}
impl std::ops::Deref for InodeGuard {
type Target = InodeVal;
Expand Down Expand Up @@ -1740,7 +1743,8 @@ impl WasiFs {
match pfd {
Ok(fd_ref) => {
let inode = fd_ref.inode.ino().as_u64();
trace!(%fd, %inode, "closing file descriptor");
let ref_cnt = fd_ref.inode.ref_cnt();
trace!(%fd, %inode, %ref_cnt, "closing file descriptor");
}
Err(err) => {
trace!(%fd, "closing file descriptor failed - {}", err);
Expand Down
4 changes: 2 additions & 2 deletions lib/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,10 +821,10 @@ fn generate_import_object_wasix64_v1(

fn mem_error_to_wasi(err: MemoryAccessError) -> Errno {
match err {
MemoryAccessError::HeapOutOfBounds => Errno::Fault,
MemoryAccessError::HeapOutOfBounds => Errno::Memviolation,
MemoryAccessError::Overflow => Errno::Overflow,
MemoryAccessError::NonUtf8String => Errno::Inval,
_ => Errno::Inval,
_ => Errno::Unknown,
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/wasi/src/os/command/builtins/cmd_wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ impl CmdWasmer {
)
.await;
});
let handle = OwnedTaskStatus::new_finished_with_code(Errno::Noent as u32).handle();
let handle = OwnedTaskStatus::new_finished_with_code(Errno::Noent).handle();
Ok(handle)
}
} else {
parent_ctx.data().tasks().block_on(async move {
let _ = stderr_write(parent_ctx, HELP_RUN.as_bytes()).await;
});
let handle = OwnedTaskStatus::new_finished_with_code(0).handle();
let handle = OwnedTaskStatus::new_finished_with_code(Errno::Success).handle();
Ok(handle)
}
}
Expand Down Expand Up @@ -135,7 +135,7 @@ impl VirtualCommand for CmdWasmer {
parent_ctx.data().tasks().block_on(async move {
let _ = stderr_write(parent_ctx, HELP.as_bytes()).await;
});
let handle = OwnedTaskStatus::new_finished_with_code(0).handle();
let handle = OwnedTaskStatus::new_finished_with_code(Errno::Success).handle();
Ok(handle)
}
Some(what) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/wasi/src/os/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Commands {
format!("wasm command unknown - {}\r\n", path).as_bytes(),
);

let res = OwnedTaskStatus::new(TaskStatus::Finished(Ok(Errno::Noent as u32)));
let res = OwnedTaskStatus::new(TaskStatus::Finished(Ok(Errno::Noent)));
Ok(res.handle())
}
}
Expand Down
Loading