text stringlengths 14 100k | source stringclasses 1
value | repo stringclasses 810
values | language stringclasses 13
values |
|---|---|---|---|
<|fim_suffix|>max_path_len = wasi_try_mem!(path_len.read(&memory));
let max_path_len64: u64 = max_path_len.into();
let path_slice = match (path.is_null(), max_path_len64) {
(true, _) => None,
(_, 0) => None,
(_, _) => Some(wasi_try_mem!(path.slice(&memory, max_path_len))),
};
Spa... | fim | wasmerio/wasmer | rust |
<|fim_suffix|> chdir::*;
pub use closure_allocate::*;
pub use closure_free::*;
pub use closure_prepare::*;
pub use context_create::*;
pub use context_destroy::*;
pub use context_switch::*;
pub use dl_invalid_handle::*;
pub use dlopen::*;
pub use dlsym::*;
pub use epoll_create::*;
pub use epoll_ctl::*;
pub use epoll_wai... | fim | wasmerio/wasmer | rust |
<|fim_suffix|> }
// strip end file name
let (parent_inode, new_entity_name) =
wasi_try_ok_ok!(state.fs.get_parent_inode_at_path(
inodes,
effective_dirfd,
&path_arg,
follow_symlinks
... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>ip_add(cidr.ip, cidr.prefix)
.await
.map_err(net_error_into_wasi_err)
})?);
Ok(Ok(()))
}
<|fim_prefix|>use virtual_net::IpCidr;
use super::*;
use crate::syscalls::*;
/// ### `port_addr_add()`
/// Adds another static address to the local port
///
/// ## Parameters
///
/// ... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>, async {
net.ip_clear().await.map_err(net_error_into_wasi_err)
})?);
Ok(Ok(()))
}
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `port_addr_clear()`
/// Clears all the addresses on the local port
#[instrument(level = "trace", skip_all, ret)]
pub fn port_addr_clear(mut ctx: F... | fim | wasmerio/wasmer | rust |
<|fim_suffix|> let ref_addrs = wasi_try_mem_ok!(
addrs_ptr.slice(&memory, wasi_try_ok!(to_offset::<M>(max_addrs as usize)))
);
for n in 0..addrs.len() {
let nip = ref_addrs.index(n as u64);
crate::net::write_cidr(&memory, nip.as_ptr::<M>(), *addrs.get(n).unwrap());
}
Ok(Errno... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>b fn port_addr_remove<M: MemorySize>(
mut ctx: FunctionEnvMut<'_, WasiEnv>,
ip: WasmPtr<__wasi_addr_t, M>,
) -> Result<Errno, WasiError> {
WasiEnv::do_pending_operations(&mut ctx)?;
let env = ctx.data();
let memory = unsafe { env.memory_view(&ctx) };
let ip = wasi_try_ok!(crate::... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `port_bridge()`
/// Securely connects to a particular remote network
///
/// ## Parameters
///
/// * `network` - Fully qualified identifier for the network
/// * `token` - Access token used to authenticate with the network
/// * `security` - Level of encrypti... | fim | wasmerio/wasmer | rust |
use super::*;
use crate::syscalls::*;
/// ### `port_dhcp_acquire()`
/// Acquires a set of IP addresses using DHCP
#[instrument(level = "trace", skip_all, ret)]
pub fn port_dhcp_acquire(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno, WasiError> {
WasiEnv::do_pending_operations(&mut ctx)?;
wasi_try_ok!(p... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `port_gateway_set()`
/// Adds a default gateway to the port
///
/// ##<|fim_suffix|>rrno::Fault))
})?;
}
Ok(Errno::Success)
}
pub(crate) fn port_gateway_set_internal(
ctx: &mut FunctionEnvMut<'_, WasiEnv>,
ip: IpAddr,
) -> Result<Res... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>the local port
#[instrument(level = "trace", skip_all, fields(max = field::Empty), ret)]
pub fn port_mac<M: MemorySize>(
mut ctx: FunctionEnvMut<'_, WasiEnv>,
ret_mac: WasmPtr<__wasi_hardwareaddress_t, M>,
) -> Result<Errno, WasiError> {
WasiEnv::do_pending_operations(&mut ctx)?;
let mut ... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use virtual_net::IpCidr;
use super::*;
use crate::syscalls::*;
/// ### `port_route_add()`
/// Adds a new route to the local port
#[instrument(level = "trace", skip_all, fields(cidr = field::Empty, via_router = field::Empty), ret)]
pub fn port_route_add<M: MemorySize>(
mut ctx: FunctionEnvMut<'_, Was... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `port_route_clear()`
/// Clears all the routes in the local port
#[instrument(level = "trace", skip_all, ret)]
pub fn port_route_clear(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno, WasiError> {
W<|fim_suffix|> let net = env.net().clone();
w... | fim | wasmerio/wasmer | rust |
use super::*;
use crate::syscalls::*;
/// ### `port_route_list()`
/// Returns a list of all the routes owned by the local port
/// This function fills the output buffer as much as possible.
/// If the buffer is too small this will return EOVERFLOW and
/// fill nroutes with the size of the buffer needed.
///
/// ## Par... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>et().clone();
wasi_try_ok_ok!(__asyncify(ctx, None, async {
net.route_remove(ip).await.map_err(net_error_into_wasi_err)
})?);
Ok(Ok(()))
}
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `port_route_remove()`
/// Removes an existing route from the local port
#[instrument(... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `port_unbridge()`
/// Disconnects from a remote network
#[instrument(level = "trace", skip_all, r<|fim_suffix|> ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno, WasiError> {
WasiEnv::do_pending_operations(&mut ctx)?;
wasi_try_ok!(port_unbridge_inte... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>n), ret)]
pub fn proc_exec<M: MemorySize>(
mut ctx: FunctionEnvMut<'_, WasiEnv>,
name: WasmPtr<u8, M>,
name_len: M::Offset,
args: WasmPtr<u8, M>,
args_len: M::Offset,
) -> Result<(), WasiError> {
proc_exec2(
ctx,
name,
name_len,
args,
args_le... | fim | wasmerio/wasmer | rust |
<|fim_suffix|> name,
name_len,
args,
args_len,
envs,
envs_len,
Bool::False,
WasmPtr::null(),
0u32.into(),
) {
Ok(e) => Err(WasiError::Exit(e.into())),
Err(e) => Err(e),
}
}
<|fim_prefix|>use wasmer::FromToNativeWasmType;
use super:... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>,
args: WasmPtr<u8, M>,
args_len: M::Offset,
envs: WasmPtr<u8, M>,
envs_len: M::Offset,
search_path: Bool,
path: WasmPtr<u8, M>,
path_len: M::Offset,
) -> Result<Errno, WasiError> {
WasiEnv::do_pending_operations(&mut ctx)?;
// If we were just restored the stack then w... | fim | wasmerio/wasmer | rust |
<|fim_suffix|> preopen = ctx.data().state.preopen.clone();
// Get the current working directory
let (_, cur_dir) = {
let (memory, state, inodes) =
unsafe { ctx.data().get_memory_and_wasi_state_and_inodes(&ctx, 0) };
match state.fs.get_current_dir(inodes, crate::VIRTUAL_ROOT_FD) {
... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::{WasiVForkAsyncify, syscalls::*};
/// ### `proc_exit2()`
/// Similar to `proc_exit()`
///
/// If used in a `proc_fork_env` (vfork) context it will exit the
/// child, switch the process back into the parent process and
/// return. If used for vforking, restoring the control to th... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::{
WasiThreadHandle, WasiVForkAsyncify, capture_store_snapshot,
os::task::OwnedTaskStatus,
runtime::task_manager::{TaskWasm, TaskWasmRunProperties},
state::context_switching::ContextSwitchingEnvironment,
syscalls::*,
};
use serde::{Deserialize, Serialize};
use w... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use crate::{WasiEnv, WasiError, WasiVFork};
use wasmer::{FunctionEnvMut, Memory, MemorySize, WasmPtr};
use wasmer_wasix_types::wasi::{Errno, Pid};
/// ### `proc_fork_env()`
/// Forks the environment of the current process into a new child process.
/// The child process will start with the sa<|fim_suffix|... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `proc_id()`
/// Returns the handle of the current process
#[instrument(level = "trace", skip_all, fields(pid = field::Empty), ret)]
pub fn proc_id<M: MemorySize>(ctx: FunctionEn<|fim_suffix|>!(ret_pid.write(&memory, pid.raw() as Pid));
Errno::Success
}
<|... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>;
JoinStatusResult::ExitNormal(pid, exit_code)
})?;
match res {
AsyncifyAction::Finish(ctx, result) => ret_result(ctx, result),
AsyncifyAction::Unwind => Ok(Errno::Success),
}
}
} else {
trace!(ret_id =... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `proc_parent()`
/// Returns the parent handle of the supplied process
#[instrument(level = "trace", skip_all, fields(%pid, parent = field::Empty), ret)]
pub fn proc_parent<M: MemorySize>(
ctx: FunctionEnvMut<'_, WasiEnv>,
pid: Pid,
ret_parent: Was... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `proc_signal()`
/// Sends a signal to a child process
///
/// ## Parameters
///
/// * `pid` - Handl<|fim_suffix|> process.signal_process(sig);
}
WasiEnv::do_pending_operations(&mut ctx)?;
Ok(Errno::Success)
}
<|fim_middle|>e of the child proc... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>asiEnv>,
buf: WasmPtr<SignalDisposition, M>,
) -> Result<Errno, WasiError> {
let env = ctx.data();
let (memory, mut state) = unsafe { env.get_memory_and_wasi_state(&ctx, 0) };
let signals = state.signals.lock().unwrap();
let buf = wasi_try_mem_ok!(buf.slice(&memory, wasi_try_ok!(to_o... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `proc_signals_count_get()`
/// Gets the number of signals with overridden handlers.
///
/// Outputs:
/// - `size_t *signal_count`
/// The number of signals.
#[instrument(level = "trace", skip_all, fields(signal_count = field::Empty), ret)]
pub fn proc_sig... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>tx = wasi_try_ok!(maybe_snapshot_once::<M>(ctx, SnapshotTrigger::Explicit)?);
// ... if not, we may still have an external request for a snapshot, so do that as well
ctx = wasi_try_ok!(maybe_snapshot::<M>(ctx)?);
Ok(Errno::Success)
}
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// Exp... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use virtual_fs::Pipe;
use wasmer_wasix_types::wasi::ProcessHandles;
use super::*;
use crate::syscalls::*;
/// Spawns a new process within the context of this machine.
///
/// This syscall was previously used by the Rust stdlib's `Command::spawn` on WASIX.
/// Rust now uses `posix_spawn` (backed by `proc... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>i_try_mem_ok!(fd_ops.slice(&memory, fd_ops_len));
let mut vec = Vec::with_capacity(fd_ops.len() as usize);
for s in wasi_try_mem_ok!(fd_ops.access()).iter() {
vec.push(*s);
}
vec
} else {
vec![]
};
let path = if path.is_null() {
None... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use virtual_mio::block_on;
use wasmer_wasix_types::wasi::ProcSpawnFdOpName;
use super::*;
use crate::{VIRTUAL_ROOT_FD, WasiFs, syscalls::*};
/// Spawns a new sub-process (posix-spawn style) with proper `WasmPtr<WasmPtr<u8>>` string lists.
///
/// Successor to `proc_spawn2`. `args` and `envs` are pointer... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>nv.memory_view(&store) };
let signature_info = result.deref(&memory);
// Look up the function in the indirect function table
let function = match function_lookup_result {
Ok(f) => f,
Err(e) => {
let cacheable = match e {
FunctionLookupError::Empty(_... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `resolve()`
/// Resolves a hostname and a port to one or more IP addresses.
///
/// Note: This is similar to `getaddrinfo` in POSIX
///
/// When successful, the contents of the output buffer consist of a sequence of
/// IPv4 and/or IPv6 addresses. Each addres... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>`
/// Yields execution of the thread
#[instrument(level = "trace", skip_all, ret)]
pub fn sched_yield<M: MemorySize + 'static>(
mut ctx: FunctionEnvMut<'_, WasiEnv>,
) -> Result<Errno, WasiError> {
WasiEnv::do_pending_operations(&mut ctx)?;
ctx = wasi_try_ok!(maybe_backoff::<M>(ctx)?);
/... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>}
<|fim_prefix|>use std::task::Waker;
use super::*;
use crate::{net::socket::TimeType, syscalls::*};
/// ### `sock_accept()`
/// Accept a new incoming connection.
/// Note: This is similar to `accept` in POSIX.
///
/// ## Parameters
///
/// * `fd` - The listening socket.
/// * `flags` - The desired valu... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use c<|fim_suffix|>ocket that the address is bound to
#[instrument(level = "trace", skip_all, fields(%sock, addr = field::Empty), ret)]
pub fn sock_addr_local<M: MemorySize>(
mut ctx: FunctionEnvMut<'_, WasiEnv>,
sock: WasiFd,
ret_addr: WasmPtr<__wasi_addr_port_t, M>,
) -> Errno ... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>utput buffer consist of an IP address,
/// either IP4 or IP6.
///
/// ## Parameters
///
/// * `fd` - Socket that the address is bound to
#[instrument(level = "trace", skip_all, fields(%sock, addr = field::Empty), ret)]
pub fn sock_addr_peer<M: MemorySize>(
mut ctx: FunctionEnvMut<'_, WasiEnv>,
soc... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `s<|fim_suffix|>x) };
let addr = wasi_try_ok!(crate::net::read_ip_port(&memory, addr));
let addr = SocketAddr::new(addr.0, addr.1);
Span::current().record("addr", format!("{addr:?}"));
wasi_try_ok!(sock_bind_internal(&mut ctx, sock, addr)?);... | fim | wasmerio/wasmer | rust |
<|fim_suffix|> nonblocking_connect_result(WasiSocketStatus::Failed),
Err(Errno::Notconn)
);
assert_eq!(
nonblocking_connect_result(WasiSocketStatus::Closed),
Err(Errno::Notconn)
);
}
}
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `sock_co... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `sock_get_opt_flag()`
/// Retrieve status of particular socket setting
/// Note: This is similar to `getsockopt` in POSIX for SO_REUSEADDR
///
/// ## Parameters
///
/// * `fd` - Socket descriptor
/// * `sockopt` - Socket option to be retrieved
#[instrument(le... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>ionEnvMut<'_, WasiEnv>,
sock: WasiFd,
opt: Sockoption,
ret_size: WasmPtr<Filesize, M>,
) -> Errno {
let size = wasi_try!(__sock_actor(
&mut ctx,
sock,
Rights::empty(),
|socket, _| match opt {
Sockoption::RecvBufSize => socket.recv_buf_size().map(... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>match time {
None => OptionTimestamp {
tag: OptionTag::None,
u: 0,
},
Some(timeout) => OptionTimestamp {
tag: OptionTag::Some,
u: timeout.as_nanos() as Timestamp,
},
};
wasi_try_mem!(ret_time.write(&memory, time));
... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>r: Ipv4Addr,
iface: Ipv4Addr,
) -> Result<Result<(), Errno>, WasiError> {
let env = ctx.data();
wasi_try_ok_ok!(__sock_actor_mut(ctx, sock, Rights::empty(), |socket, _| {
socket.join_multicast_v4(multiaddr, iface)
}));
Ok(Ok(()))
}
<|fim_prefix|>use super::*;
use crate::syscall... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>y = unsafe { env.memory_view(&ctx) };
let multiaddr = wasi_try_ok!(crate::net::read_ip_v6(&memory, multiaddr));
wasi_try_ok!(sock_join_multicast_v6_internal(
&mut ctx, sock, multiaddr, iface
)?);
#[cfg(feature = "journal")]
if ctx.data().enable_journal {
JournalEffect... | fim | wasmerio/wasmer | rust |
use super::*;
use crate::syscalls::*;
/// ### `sock_leave_multicast_v4()`
/// Leaves a particular multicast IPv4 group
///
/// ## Parameters
///
/// * `fd` - Socket descriptor
/// * `multiaddr` - Multicast group to leave
/// * `interface` - Interface that will left
#[instrument(level = "trace", skip_all, fields(%sock)... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>_ip6_t, M>,
iface: u32,
) -> Result<Errno, WasiError> {
WasiEnv::do_pending_operations(&mut ctx)?;
let env = ctx.data();
let memory = unsafe { env.memory_view(&ctx) };
let multiaddr = wasi_try_ok!(crate::net::read_ip_v6(&memory, multiaddr));
wasi_try_ok!(sock_leave_multicast_v6_i... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::{journal::SnapshotTrigger, syscalls::*};
/// ### `sock_listen()`
/// Listen for connections on a socket
///
/// Polling the socket handle will wait until a connection
/// attempt is made
///
/// Note: This is similar to `listen`
///
/// ## Parameters
///
/// * `fd` - File descrip... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::{net::socket::SocketProperties, syscalls::*};
/// ### `sock_open()`
/// Create an endpoint for communication.
///
/// creates an endpoint for communication and returns a file descriptor
/// tor that refers to that endpoint. The file descriptor returned by a successful
/// call wi... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>fd2).map_err(|err| {
tracing::error!("failed to save sock_pair event - {}", err);
WasiError::Exit(ExitCode::from(Errno::Fault))
})?;
}
let env = ctx.data();
let (memory, state, inodes) = unsafe { env.get_memory_and_wasi_state_and_inodes(&ctx, 0) };
wasi_try... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use std::{mem::MaybeUnini<|fim_suffix|>gh pipe-backed fds.
let use_read = matches!(guard.deref(), Kind::DuplexPipe { .. } | Kind::PipeRx { .. });
drop(guard);
if use_read {
fd_read(ctx, sock, ri_data, ri_data_len, ro_data_len)
} else {
let pid = ctx.data().pid();
le... | fim | wasmerio/wasmer | rust |
<|fim_suffix|> (0, peer)
}
}
};
Span::current()
.record("nread", bytes_read)
.record("peer", format!("{peer:?}"));
wasi_try_ok!(write_ip_port(&memory, ro_addr, peer.ip(), peer.port()));
let bytes_read: M::Offset = wasi_try_ok!(bytes_read.try_into().map_err(|... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use std::{mem::MaybeUninit, task::Waker};
use super::*;
use crate::{net::socket::TimeType, syscalls::*};
/// ### `sock_send()`
/// Send a message on a socket.
/// Note: This is similar to `send` in POSIX, though it also supports writing
/// the data from multiple buffers in the manner of `writev`.
///
/... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use virtual_fs::AsyncReadExt;
use super::*;
use crate::{WasiInodes, net::socket::TimeType, syscalls::*};
/// ### `sock_send_file()`
/// Sends the entire contents of a file down a socket
///
/// ## Parameters
///
/// * `in_fd` - Open file that has the data to be transmitted
/// * `offset` - Offset into t... | fim | wasmerio/wasmer | rust |
<|fim_suffix|> for iovs in iovs_arr.iter() {
let buf = WasmPtr::<u8, M>::new(iovs.buf)
.slice(&memory, iovs.buf_len)
.map_err(mem_error_to_wasi)?
.access()
... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>, flag).map_err(|err| {
tracing::error!("failed to save sock_set_opt_flag event - {}", err);
WasiError::Exit(ExitCode::from(Errno::Fault))
})?;
}
Ok(Errno::Success)
}
pub(crate) fn sock_set_opt_flag_internal(
ctx: &mut FunctionEnvMut<'_, WasiEnv>,
sock: Wa... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::{net::socket::WasiSocketOption, syscalls::*};
/// ### `sock_set_opt_size()
/// Set size of particular option for this socket
/// Note: This is similar to `setsockopt` in POSIX for SO_RCVBUF
///
/// ## Parameters
///
/// * `fd` - Socket descriptor
/// * `opt` - Socket option to be... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>(feature = "journal")]
if ctx.data().enable_journal {
JournalEffector::save_sock_set_opt_time(&mut ctx, sock, ty, time).map_err(|err| {
tracing::error!("failed to save sock_set_opt_time event - {}", err);
WasiError::Exit(ExitCode::from(Errno::Fault))
})?;
}
... | fim | wasmerio/wasmer | rust |
use std::net::Shutdown;
use super::*;
use crate::syscalls::*;
/// ### `sock_shutdown()`
/// Shut down socket send and receive channels.
/// Note: This is similar to `shutdown` in POSIX.
///
/// ## Parameters
///
/// * `how` - Which channels on the socket to shut down.
#[instrument(level = "trace", skip_all, fields(%s... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>("{status:?}"));
let env = ctx.data();
let memory = unsafe { env.memory_view(&ctx) };
wasi_try_mem!(ret_status.write(&memory, status));
Errno::Success
}
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `sock_status()`
/// Returns the current status of a socket
#[instrument(lev... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>!(
"failed checkpoint - could not rewind the stack - errno={}",
err
);
OnCalledAction::Trap(Box::new(WasiError::Exit(err.into())))
}
}
})
}
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `stack_ch... | fim | wasmerio/wasmer | rust |
use bincode::config;
use super::*;
use crate::syscalls::*;
/// ### `stack_restore()`
/// Restores the current stack to a previous stack described by its
/// stack hash.
///
/// ## Parameters
///
/// * `snapshot_ptr` - Contains a previously made snapshot
#[instrument(level = "trace", skip_all, ret)]
pub fn stack_resto... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `thread_exit()`
/// Terminates the current running thread, if this is the last thread then
/// the process will also exit with code 0.
/// The exit code parameter is a left over from a<|fim_suffix|>syscall backwards-compatible, but
/// is otherwise unused.
//... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>trace", skip_all, fields(tid = field::Empty), ret)]
pub fn thread_id<M: MemorySize>(
ctx: FunctionEnvMut<'_, WasiEnv>,
ret_tid: WasmPtr<Tid, M>,
) -> Errno {
let env = ctx.data();
let tid: Tid = env.thread.tid().into();
Span::current().record("tid", tid);
let memory = unsafe { env.... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use std::task::Waker;
<|fim_suffix|>code) = unsafe { handle_rewind::<M, i32>(&mut ctx) } {
return Ok(Errno::Success);
}
ctx = wasi_try_ok!(maybe_snapshot::<M>(ctx)?);
let env = ctx.data();
let tid: WasiThreadId = join_tid.into();
let other_thread = env.process.get_thread(&ti... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `thread_parallelism()`
/// Returns the available parallelism which is normally the
/// number of available cores that can run<|fim_suffix|>err: Errno = err.into();
err
}));
Span::current().record("parallelism", parallelism);
let parallelis... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
use crate::syscalls::*;
/// ### `thread_signal()`
/// Send a signal to a particular thread in the current process.
/// Note: This is similar to `signal` in POSIX.
/// Inputs:
///<|fim_suffix|>iEnv>,
tid: Tid,
sig: Signal,
) -> Result<Errno, WasiError> {
{
let tid: WasiTh... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use std::task::Waker;
use super::*;
use crate::syscalls::*;
/// ### `thread_sleep()`
/// Sends the current thread to sleep for a period of time
///
/// ## Parameters
///
/// * `duration` - Amount of time that the thread should sleep
#[instrument(level = "trace", skip_all, fields(%duration), ret)]
pub fn... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*;
#[cfg(feature = "journal")]
use crate::journal::JournalEffector;
use crate::{
WasiThreadHandle,
os::task::thread::WasiMemoryLayout,
runtime::{
TaintReason,
task_manager::{TaskWasm, TaskWasmRunProperties},
},
state::context_switching::ContextSwitchingEnviro... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use super::*<|fim_suffix|>Success
}
<|fim_middle|>;
use crate::syscalls::*;
/// ### `tty_get()`
/// Retrieves the current state of the TTY
#[instrument(level = "trace", skip_all, ret)]
pub fn tty_get<M: MemorySize>(
ctx: FunctionEnvMut<'_, WasiEnv>,
tty_state: WasmPtr<Tty, M>,
) -> Errno {
le... | fim | wasmerio/wasmer | rust |
<|fim_suffix|> } else {
return Err(Errno::Notsup);
};
bridge.tty_set(state);
Ok(())
}
<|fim_prefix|>use super::*;
use crate::{WasiTtyState, syscalls::*};
/// ### `tty_set()`
/// Updates the properties of the rect
#[instrument(level = "trace", skip_all, ret)]
pub fn tty_set<M: MemorySize>(
m... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use std::mem;
use chrono::prelude::*;
use wasmer::WasmRef;
use crate::syscalls::types::{
wasi::{Errno, Snapshot0Clockid, Timestamp},
*,
};
pub fn platform_clock_res_get(
clock_id: Snapshot0Clockid,
resolution: WasmRef<Timestamp>,
) -> Result<i64, Errno> {
let t_out = match clock_id ... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use tracing::debug;
use wasmer::WasmRef;
use crate::syscalls::types::wasi::{self, Timestamp};
pub fn platform_clock_res_get(
clock_id: wasi::Snapshot0Clockid,
resolution: WasmRef<Timestamp>,
) -> Result<i64, wasi::Errno> {
let resolution_val = match clock_id {
// resolution of monoto... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>{
std::ptr::null_mut()
}
unsafe fn from_raw(_ptr: *mut ()) -> Self {
WasiDummyWaker
}
}
<|fim_prefix|>/// A "mock" no-op [`std::task::Waker`] implementation.
///
/// Needed for polling futures outside of an async runtime, since the `poll()`
/// functions requires a `[std::task:... | fim | wasmerio/wasmer | rust |
<|fim_suffix|> assert!(WasiVersion::Latest > WasiVersion::Wasix64v1);
assert!(WasiVersion::Snapshot1 < WasiVersion::Wasix32v1);
assert!(WasiVersion::Wasix32v1 < WasiVersion::Wasix64v1);
assert!(WasiVersion::Wasix64v1 > WasiVersion::Wasix32v1);
}
}
<|fim_prefix|>mod dummy_waker;
mod owned... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>/// Extends the standard library RwLock to include an owned version of the read
/// and write locking functions.
///
/// This implementation contains unsafe code and has two levels of protection
/// that prevent the lock from being released after the memory is freed.
///
/// 1. The internals use a Option ... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>apshot(store: &mut impl wasmer::AsStoreMut, snapshot: &StoreSnapshot) {
let objs = store.objects_mut();
for (index, value) in snapshot.globals.iter().enumerate() {
objs.set_global_unchecked(index, *value);
}
}
<|fim_prefix|>use bincode::config;
/// A snapshot that ca<|fim_middle|>ptu... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>hread::current().id() != self.thread {
return Err(ThreadLocalSpawnerError::NotOnTheCorrectThread {
expected: self.thread,
found: std::thread::current().id(),
});
}
// As we now know that we are on the correct thread, we can use the s... | fim | wasmerio/wasmer | rust |
<|fim_suffix|> self.waker.wake_by_ref();
}
/// Will wait until either the reactor is triggered
/// or the timeout occurs
// TODO: review allow...
#[allow(dead_code)]
pub fn wait(&self, timeout: Duration) -> bool {
let mut run = self.run.0.lock().unwrap();
if *run {
... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>use wasm_bindgen::{JsCast, JsValue};
/// Try to extract the most appropriate error message from a [`<|fim_suffix|>e()))
} else if let Some(obj) = value.dyn_ref::<js_sys::Object>() {
return anyhow::Error::msg(String::from(obj.to_string()));
} else if let Some(s) = value.dyn_ref::<js_sys::J... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>one(), root_container),
]),
};
let mut runtime = PluggableRuntime::new(task_manager());
runtime.set_source(source);
runtime.set_package_loader(loader);
let specifier: PackageSource = "acme/app".parse().unwrap();
let pkg = BinaryPackage::from_registry(&specifier, &runtime)... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>// Exclude runner tests from wasm targets for now, since they don't run properly
// there.
#![cfg(not(target_family = "wasm"))]
use std::sync::Once;
use std::{
path::{Path, PathBuf},
sync::Arc,
time::Duration,
};
static INIT: Once = Once::new();
use reqwest::Client;
use tokio::runtime::Hand... | fim | wasmerio/wasmer | rust |
<|fim_suffix|>reate the `WasiEnv`.
let (mut pipe_tx, pipe_rx) = Pipe::channel();
// Write to STDIN
let buf = "Hello, stdin!\n".as_bytes().to_owned();
block_on(pipe_tx.write_all(&buf[..])).unwrap();
{
let mut runner = WasiRunner::new();
runner.with_stdin(Box::new(pipe_rx));
... | fim | wasmerio/wasmer | rust |
<|fim_prefix|>#i<|fim_suffix|>ain() {
printf("Hello, World!\n");
return 0;
}<|fim_middle|>nclude <stdio.h>
int m<|endoftext|> | fim | wasmerio/wasmer | c |
<|fim_prefix|>//#BuildEnv: WASIXCC_PIC=1
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <wasi/api_wasi.h>
#include <wasi/api_wasix.h>
static volatile int backing_calls = 0;
static volatile uint32_t seen_a = 0;
static volatile uint64_t seen_b<|fim_suffix|>_wasm_value_type_t arg_... | fim | wasmerio/wasmer | c |
<|fim_suffix|>
assert(ret == 0);
}
static void test_max_index(void) {
uint32_t max_index = 0xFFFFFFFFu;
__wasi_errno_t ret;
printf("Test 6: closure_free with u32::MAX\n");
ret = __wasi_closure_free(max_index);
assert(ret == 0);
}
static void test_multiple_allocations(void) {
const int count = 5;
__w... | fim | wasmerio/wasmer | c |
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <wasi/api_wasix.h>
#include <wasix/context.h>
static int context_supported = 0;
static void test_destroy_main_context(void) {
__wasi_context_id_t main_id = wasix_context_main;
__wasi_errno_t err;
printf("Test 1: destroy main context\n");
er... | fim | wasmerio/wasmer | c |
<|fim_prefix|>//#SkipEngine:V8:async functions are not supported yet
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <wasix/context.h>
static wasix_context_id_t ctx1;
static int phase = 0;
static void context1_fn(void) {
int ret;
ret = wasix_context_destroy(ctx1);
assert(ret == -1);
asser... | fim | wasmerio/wasmer | c |
<|fim_prefix|>//#UnixOnly: true
//#SkipEngine:V8:async functions are not supported yet
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wasix/context.h>
// Test context switching with environment variable operations
wasix_context_id_t ctx1, ctx2;
void context1_fn(void) {
//... | fim | wasmerio/wasmer | c |
<|fim_suffix|>red_mutex);
assert(ret == 0 && "Failed to unlock mutex in context 2");
shared_counter++;
assert(shared_counter == 2 && "Counter should be 2");
// Switch back to context 1 without the mutex locked
wasix_context_switch(ctx1);
}
int main() {
int ret;
// Initialize mutex
pthread_mutex_init... | fim | wasmerio/wasmer | c |
<|fim_prefix|>//#UnixOnly: true
//#SkipEngine:V8:async functions are not supported yet
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wasix/context.h>
// Test context switching with pipe I/O
wasix_context_id_t ctx1, ctx2;
int pipe_fds[2... | fim | wasmerio/wasmer | c |
<|fim_suffix|>har* buf = malloc(1024);
free(buf);
wasix_context_switch(ctx1);
}
int main() {
int ret;
ret = wasix_context_create(&ctx1, context1_fn);
assert(ret == 0 && "Failed to create context 1");
ret = wasix_context_create(&ctx2, context2_fn);
assert(ret == 0 && "Failed to create context 2");
/... | fim | wasmerio/wasmer | c |
<|fim_suffix|>Cleanup
wasix_context_destroy(ctx1);
wasix_context_destroy(ctx2);
fprintf(stderr, "Signal handling switching test passed\n");
return 0;
}
<|fim_prefix|>//#UnixOnly: true
//#SkipEngine:V8:async functions are not supported yet
#include <assert.h>
#include <signal.h>
#include <stdio.h>
#include <st... | fim | wasmerio/wasmer | c |
<|fim_prefix|>//#UnixOnly: true
//#SkipEngine:V8:async functions are not supported yet
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <wasix/context.h>
// Test context switching with time operations
wasix_context_id_t ctx1, ctx2;
void conte<|fim_suffix|> el... | fim | wasmerio/wasmer | c |
//#UnixOnly: true
//#SkipEngine:V8:async functions are not supported yet
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <wasix/context.h>
// Test error handling: invalid operations should fail with appropriate errors
wasix_context_id_t ctx1;
int test_phase = 0;
void context1_... | fim | wasmerio/wasmer | c |
<|fim_suffix|>fter_switching();
return 20;
}
int main(int argc, char** argv) {
if (argc < 2) {
return -1;
}
if (!strcmp(argv[1], "subprocess")) {
return subprocess();
} else if (!strcmp(argv[1], "subprocess_with_switching")) {
return subprocess_with_switching();
} else if (!strcmp(argv[1], "s... | fim | wasmerio/wasmer | c |
<|fim_prefix|>//#UnixOnly: true
//#SkipEngine:V8:async functions are not supported yet
// Test memory allocations during context switches
// This can trigger store context issues if malloc implementation
// does host calls while the store is borrowed
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include ... | fim | wasmerio/wasmer | c |
<|fim_prefix|>//#UnixOnly: true
//#SkipEngine:V8:async functions are not supported yet
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <wasix/context.h>
// Test creating multiple contexts and switching between them in various orders
// Expected execution order: 1 -> 2 -> 3 -> 4 ... | fim | wasmerio/wasmer | c |
<|fim_prefix|>//#UnixOnly: true
//#SkipEngine:V8:async functions are not supported yet
// Test switching contexts while nested in the middle of syscalls
// This directly tries to trigger "store context still borrowed" by
// calling wasix_context_switch during operations that hold a store borrow
#include <assert.h>
#in... | fim | wasmerio/wasmer | c |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.