1#![allow(clippy::result_large_err)]
4#![doc(html_favicon_url = "https://wasmer.io/images/icons/favicon-32x32.png")]
5#![doc(html_logo_url = "https://github.com/wasmerio.png?size=200")]
6#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
7
8#[cfg(all(
19 not(feature = "sys"),
20 not(feature = "js"),
21 not(feature = "sys-minimal")
22))]
23compile_error!(
24 "At least the `sys` or the `js` or `sys-minimal` feature must be enabled. Please, pick one."
25);
26
27#[cfg(any(
28 all(feature = "js", feature = "sys"),
29 all(feature = "js", feature = "sys-minimal")
30))]
31compile_error!(
32 "Cannot have both `sys` and `js` or `sys-minimal` and `sys` features enabled at the same time. Please, pick one."
33);
34
35#[cfg(all(feature = "sys", target_arch = "wasm32"))]
36compile_error!("The `sys` feature must be enabled only for non-`wasm32` target.");
37
38#[cfg(all(feature = "js", not(target_arch = "wasm32")))]
39compile_error!(
40 "The `js` feature must be enabled only for the `wasm32` target (either `wasm32-unknown-unknown` or `wasm32-wasip1`)."
41);
42
43#[cfg(all(test, target_arch = "wasm32"))]
44wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
45
46#[cfg(test)]
47#[macro_use]
48extern crate pretty_assertions;
49
50#[macro_use]
51mod macros;
52pub mod bin_factory;
53pub mod os;
54pub mod net;
56pub mod capabilities;
58pub mod fs;
59pub mod http;
60pub mod journal;
61mod rewind;
62pub mod runners;
63pub mod runtime;
64mod state;
65mod syscalls;
66mod utils;
67
68use std::sync::Arc;
69
70#[allow(unused_imports)]
71use bytes::{Bytes, BytesMut};
72use os::task::control_plane::ControlPlaneError;
73use thiserror::Error;
74use tracing::error;
75pub use wasmer;
77pub use wasmer_wasix_types;
78
79use wasmer::{
80 AsStoreMut, Exports, FunctionEnv, Imports, Memory32, MemoryAccessError, MemorySize,
81 RuntimeError, imports, namespace,
82};
83
84pub use virtual_fs;
85pub use virtual_fs::{DuplexPipe, FsError, Pipe, VirtualFile, WasiBidirectionalSharedPipePair};
86pub use virtual_net;
87pub use virtual_net::{UnsupportedVirtualNetworking, VirtualNetworking};
88
89#[cfg(feature = "host-vnet")]
90pub use virtual_net::{
91 host::{LocalNetworking, LocalTcpListener, LocalTcpStream, LocalUdpSocket},
92 io_err_into_net_error,
93};
94use wasmer_wasix_types::wasi::{Errno, ExitCode};
95
96pub use crate::{
97 fs::{Fd, VIRTUAL_ROOT_FD, WasiFs, WasiInodes, default_fs_backing},
98 os::{
99 WasiTtyState,
100 task::{
101 control_plane::WasiControlPlane,
102 process::{WasiProcess, WasiProcessId},
103 thread::{WasiThread, WasiThreadError, WasiThreadHandle, WasiThreadId},
104 },
105 },
106 rewind::*,
107 runtime::{PluggableRuntime, Runtime, task_manager::VirtualTaskManager},
108 state::{
109 ALL_RIGHTS, WasiEnv, WasiEnvBuilder, WasiEnvInit, WasiFunctionEnv,
110 WasiModuleInstanceHandles, WasiModuleTreeHandles, WasiStateCreationError,
111 },
112 syscalls::{journal::wait_for_snapshot, rewind, rewind_ext, types, unwind},
113 utils::is_wasix_module,
114 utils::{
115 WasiVersion, get_wasi_version, get_wasi_versions, is_wasi_module,
116 store::{StoreSnapshot, capture_store_snapshot, restore_store_snapshot},
117 },
118};
119
120#[derive(Error, Debug)]
123pub enum WasiError {
124 #[error("WASI exited with code: {0}")]
125 Exit(ExitCode),
126 #[error("WASI thread exited")]
127 ThreadExit,
128 #[error("WASI deep sleep: {0:?}")]
129 DeepSleep(DeepSleepWork),
130 #[error("The WASI version could not be determined")]
131 UnknownWasiVersion,
132 #[error("Dynamically-linked symbol not found or has bad type: {0}")]
133 DlSymbolResolutionFailed(String),
134}
135
136pub type WasiResult<T> = Result<Result<T, Errno>, WasiError>;
137
138#[deny(unused, dead_code)]
139#[derive(Error, Debug)]
140pub enum SpawnError {
141 #[error("serialization failed")]
143 Serialization,
144 #[error("deserialization failed")]
146 Deserialization,
147 #[error("invalid wasmer")]
149 InvalidWasmer,
150 #[error("fetch failed")]
152 FetchFailed,
153 #[error(transparent)]
154 CacheError(crate::runtime::module_cache::CacheError),
155 #[error("compile error: {error:?}")]
157 CompileError {
158 module_hash: wasmer_types::ModuleHash,
159 error: wasmer::CompileError,
160 },
161 #[error("Wasmer process has an invalid ABI")]
163 InvalidABI,
164 #[error("bad handle")]
166 BadHandle,
167 #[error("unsupported")]
169 Unsupported,
170 #[error("not found: {message}")]
172 NotFound { message: String },
173 #[error("could not find binary '{binary}'")]
176 BinaryNotFound { binary: String },
177 #[error("could not find an entrypoint in the package '{package_id}'")]
178 MissingEntrypoint {
179 package_id: wasmer_config::package::PackageId,
180 },
181 #[error("could not load ")]
182 ModuleLoad { message: String },
183 #[error("bad request")]
185 BadRequest,
186 #[error("access denied")]
188 AccessDenied,
189 #[error("internal error")]
191 InternalError,
192 #[error(transparent)]
194 FileSystemError(ExtendedFsError),
195 #[error("memory allocation failed")]
197 MemoryAllocationFailed,
198 #[error("memory access violation")]
200 MemoryAccessViolation,
201 #[error("unknown error found")]
203 UnknownError,
204 #[error("runtime error")]
205 Runtime(#[from] WasiRuntimeError),
206 #[error(transparent)]
207 Other(#[from] Box<dyn std::error::Error + Send + Sync>),
208}
209
210#[derive(Debug)]
211pub struct ExtendedFsError {
212 pub error: virtual_fs::FsError,
213 pub message: Option<String>,
214}
215
216impl ExtendedFsError {
217 pub fn with_msg(error: virtual_fs::FsError, msg: impl Into<String>) -> Self {
218 Self {
219 error,
220 message: Some(msg.into()),
221 }
222 }
223
224 pub fn new(error: virtual_fs::FsError) -> Self {
225 Self {
226 error,
227 message: None,
228 }
229 }
230}
231
232impl std::fmt::Display for ExtendedFsError {
233 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
234 write!(f, "fs error: {}", self.error)?;
235
236 if let Some(msg) = &self.message {
237 write!(f, " | {msg}")?;
238 }
239
240 Ok(())
241 }
242}
243
244impl std::error::Error for ExtendedFsError {
245 fn cause(&self) -> Option<&dyn std::error::Error> {
246 Some(&self.error)
247 }
248}
249
250impl SpawnError {
251 #[must_use]
255 pub fn is_not_found(&self) -> bool {
256 matches!(
257 self,
258 Self::NotFound { .. } | Self::MissingEntrypoint { .. } | Self::BinaryNotFound { .. }
259 )
260 }
261}
262
263#[derive(thiserror::Error, Debug)]
264pub enum WasiRuntimeError {
265 #[error("WASI state setup failed: {0}")]
266 Init(#[from] WasiStateCreationError),
267 #[error("Loading exports failed: {0}")]
268 Export(#[from] wasmer::ExportError),
269 #[error("Instantiation failed: {0}")]
270 Instantiation(#[from] wasmer::InstantiationError),
271 #[error("WASI error: {0}")]
272 Wasi(#[from] WasiError),
273 #[error("Process manager error: {0}")]
274 ControlPlane(#[from] ControlPlaneError),
275 #[error("{0}")]
276 Runtime(#[from] RuntimeError),
277 #[error("Memory access error: {0}")]
278 Thread(#[from] WasiThreadError),
279 #[error("{0}")]
280 Anyhow(#[from] Arc<anyhow::Error>),
281}
282
283impl WasiRuntimeError {
284 pub fn as_exit_code(&self) -> Option<ExitCode> {
288 if let WasiRuntimeError::Wasi(WasiError::Exit(code)) = self {
289 Some(*code)
290 } else if let WasiRuntimeError::Runtime(err) = self {
291 if let Some(WasiError::Exit(code)) = err.downcast_ref() {
292 Some(*code)
293 } else {
294 None
295 }
296 } else {
297 None
298 }
299 }
300
301 pub fn display<'a>(&'a self, store: &'a mut impl AsStoreMut) -> WasiRuntimeErrorDisplay<'a> {
302 if let WasiRuntimeError::Runtime(err) = self {
303 WasiRuntimeErrorDisplay::Runtime(err.display(store))
304 } else {
305 WasiRuntimeErrorDisplay::Other(self)
306 }
307 }
308}
309
310pub enum WasiRuntimeErrorDisplay<'a> {
311 Runtime(wasmer::RuntimeErrorDisplay<'a>),
312 Other(&'a WasiRuntimeError),
313}
314
315impl std::fmt::Display for WasiRuntimeErrorDisplay<'_> {
316 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
317 match self {
318 WasiRuntimeErrorDisplay::Runtime(display) => write!(f, "{display}"),
319 WasiRuntimeErrorDisplay::Other(err) => write!(f, "{err}"),
320 }
321 }
322}
323
324#[allow(clippy::result_large_err)]
325pub(crate) fn run_wasi_func(
326 func: &wasmer::Function,
327 store: &mut impl AsStoreMut,
328 params: &[wasmer::Value],
329) -> Result<Box<[wasmer::Value]>, WasiRuntimeError> {
330 func.call(store, params).map_err(|err| {
331 if let Some(_werr) = err.downcast_ref::<WasiError>() {
332 let werr = err.downcast::<WasiError>().unwrap();
333 WasiRuntimeError::Wasi(werr)
334 } else {
335 WasiRuntimeError::Runtime(err)
336 }
337 })
338}
339
340#[allow(clippy::result_large_err)]
347pub(crate) fn run_wasi_func_start(
348 func: &wasmer::Function,
349 store: &mut impl AsStoreMut,
350) -> Result<(), WasiRuntimeError> {
351 run_wasi_func(func, store, &[])?;
352 Ok(())
353}
354
355#[derive(Debug)]
356pub struct WasiVFork {
357 pub rewind_stack: BytesMut,
359 pub store_data: Bytes,
361 pub env: Box<WasiEnv>,
363
364 pub handle: WasiThreadHandle,
367
368 is_64bit: bool,
369}
370
371impl Clone for WasiVFork {
372 fn clone(&self) -> Self {
373 Self {
374 rewind_stack: self.rewind_stack.clone(),
375 store_data: self.store_data.clone(),
376 env: Box::new(self.env.as_ref().clone()),
377 handle: self.handle.clone(),
378 is_64bit: self.is_64bit,
379 }
380 }
381}
382
383pub fn generate_import_object_from_env(
386 store: &mut impl AsStoreMut,
387 ctx: &FunctionEnv<WasiEnv>,
388 version: WasiVersion,
389) -> Imports {
390 let mut imports = match version {
391 WasiVersion::Snapshot0 => generate_import_object_snapshot0(store, ctx),
392 WasiVersion::Snapshot1 | WasiVersion::Latest => {
393 generate_import_object_snapshot1(store, ctx)
394 }
395 WasiVersion::Wasix32v1 => generate_import_object_wasix32_v1(store, ctx),
396 WasiVersion::Wasix64v1 => generate_import_object_wasix64_v1(store, ctx),
397 };
398
399 let exports_wasi_generic = wasi_exports_generic(store, ctx);
400
401 let imports_wasi_generic = imports! {
402 "wasi" => exports_wasi_generic,
403 };
404
405 imports.extend(&imports_wasi_generic);
406
407 imports
408}
409
410fn wasi_exports_generic(mut store: &mut impl AsStoreMut, env: &FunctionEnv<WasiEnv>) -> Exports {
411 use syscalls::*;
412 let namespace = namespace! {
413 "thread-spawn" => Function::new_typed_with_env(&mut store, env, thread_spawn::<Memory32>),
414 };
415 namespace
416}
417
418fn wasi_unstable_exports(mut store: &mut impl AsStoreMut, env: &FunctionEnv<WasiEnv>) -> Exports {
419 use syscalls::*;
420 let namespace = namespace! {
421 "args_get" => Function::new_typed_with_env(&mut store, env, args_get::<Memory32>),
422 "args_sizes_get" => Function::new_typed_with_env(&mut store, env, args_sizes_get::<Memory32>),
423 "clock_res_get" => Function::new_typed_with_env(&mut store, env, clock_res_get::<Memory32>),
424 "clock_time_get" => Function::new_typed_with_env(&mut store, env, clock_time_get::<Memory32>),
425 "environ_get" => Function::new_typed_with_env(&mut store, env, environ_get::<Memory32>),
426 "environ_sizes_get" => Function::new_typed_with_env(&mut store, env, environ_sizes_get::<Memory32>),
427 "fd_advise" => Function::new_typed_with_env(&mut store, env, fd_advise),
428 "fd_allocate" => Function::new_typed_with_env(&mut store, env, fd_allocate),
429 "fd_close" => Function::new_typed_with_env(&mut store, env, fd_close),
430 "fd_datasync" => Function::new_typed_with_env(&mut store, env, fd_datasync),
431 "fd_fdstat_get" => Function::new_typed_with_env(&mut store, env, fd_fdstat_get::<Memory32>),
432 "fd_fdstat_set_flags" => Function::new_typed_with_env(&mut store, env, fd_fdstat_set_flags),
433 "fd_fdstat_set_rights" => Function::new_typed_with_env(&mut store, env, fd_fdstat_set_rights),
434 "fd_filestat_get" => Function::new_typed_with_env(&mut store, env, legacy::snapshot0::fd_filestat_get),
435 "fd_filestat_set_size" => Function::new_typed_with_env(&mut store, env, fd_filestat_set_size),
436 "fd_filestat_set_times" => Function::new_typed_with_env(&mut store, env, fd_filestat_set_times),
437 "fd_pread" => Function::new_typed_with_env(&mut store, env, fd_pread::<Memory32>),
438 "fd_prestat_get" => Function::new_typed_with_env(&mut store, env, fd_prestat_get::<Memory32>),
439 "fd_prestat_dir_name" => Function::new_typed_with_env(&mut store, env, fd_prestat_dir_name::<Memory32>),
440 "fd_pwrite" => Function::new_typed_with_env(&mut store, env, fd_pwrite::<Memory32>),
441 "fd_read" => Function::new_typed_with_env(&mut store, env, fd_read::<Memory32>),
442 "fd_readdir" => Function::new_typed_with_env(&mut store, env, fd_readdir::<Memory32>),
443 "fd_renumber" => Function::new_typed_with_env(&mut store, env, fd_renumber),
444 "fd_seek" => Function::new_typed_with_env(&mut store, env, legacy::snapshot0::fd_seek),
445 "fd_sync" => Function::new_typed_with_env(&mut store, env, fd_sync),
446 "fd_tell" => Function::new_typed_with_env(&mut store, env, fd_tell::<Memory32>),
447 "fd_write" => Function::new_typed_with_env(&mut store, env, fd_write::<Memory32>),
448 "path_create_directory" => Function::new_typed_with_env(&mut store, env, path_create_directory::<Memory32>),
449 "path_filestat_get" => Function::new_typed_with_env(&mut store, env, legacy::snapshot0::path_filestat_get),
450 "path_filestat_set_times" => Function::new_typed_with_env(&mut store, env, path_filestat_set_times::<Memory32>),
451 "path_link" => Function::new_typed_with_env(&mut store, env, path_link::<Memory32>),
452 "path_open" => Function::new_typed_with_env(&mut store, env, path_open::<Memory32>),
453 "path_readlink" => Function::new_typed_with_env(&mut store, env, path_readlink::<Memory32>),
454 "path_remove_directory" => Function::new_typed_with_env(&mut store, env, path_remove_directory::<Memory32>),
455 "path_rename" => Function::new_typed_with_env(&mut store, env, path_rename::<Memory32>),
456 "path_symlink" => Function::new_typed_with_env(&mut store, env, path_symlink::<Memory32>),
457 "path_unlink_file" => Function::new_typed_with_env(&mut store, env, path_unlink_file::<Memory32>),
458 "poll_oneoff" => Function::new_typed_with_env(&mut store, env, legacy::snapshot0::poll_oneoff::<Memory32>),
459 "proc_exit" => Function::new_typed_with_env(&mut store, env, proc_exit::<Memory32>),
460 "proc_raise" => Function::new_typed_with_env(&mut store, env, proc_raise),
461 "random_get" => Function::new_typed_with_env(&mut store, env, random_get::<Memory32>),
462 "sched_yield" => Function::new_typed_with_env(&mut store, env, sched_yield::<Memory32>),
463 "sock_recv" => Function::new_typed_with_env(&mut store, env, sock_recv::<Memory32>),
464 "sock_send" => Function::new_typed_with_env(&mut store, env, sock_send::<Memory32>),
465 "sock_shutdown" => Function::new_typed_with_env(&mut store, env, sock_shutdown),
466 "thread-spawn" => Function::new_typed_with_env(&mut store, env, thread_spawn::<Memory32>),
467 };
468 namespace
469}
470
471fn wasi_snapshot_preview1_exports(
472 mut store: &mut impl AsStoreMut,
473 env: &FunctionEnv<WasiEnv>,
474) -> Exports {
475 use syscalls::*;
476 let namespace = namespace! {
477 "args_get" => Function::new_typed_with_env(&mut store, env, args_get::<Memory32>),
478 "args_sizes_get" => Function::new_typed_with_env(&mut store, env, args_sizes_get::<Memory32>),
479 "clock_res_get" => Function::new_typed_with_env(&mut store, env, clock_res_get::<Memory32>),
480 "clock_time_get" => Function::new_typed_with_env(&mut store, env, clock_time_get::<Memory32>),
481 "environ_get" => Function::new_typed_with_env(&mut store, env, environ_get::<Memory32>),
482 "environ_sizes_get" => Function::new_typed_with_env(&mut store, env, environ_sizes_get::<Memory32>),
483 "fd_advise" => Function::new_typed_with_env(&mut store, env, fd_advise),
484 "fd_allocate" => Function::new_typed_with_env(&mut store, env, fd_allocate),
485 "fd_close" => Function::new_typed_with_env(&mut store, env, fd_close),
486 "fd_datasync" => Function::new_typed_with_env(&mut store, env, fd_datasync),
487 "fd_fdstat_get" => Function::new_typed_with_env(&mut store, env, fd_fdstat_get::<Memory32>),
488 "fd_fdstat_set_flags" => Function::new_typed_with_env(&mut store, env, fd_fdstat_set_flags),
489 "fd_fdstat_set_rights" => Function::new_typed_with_env(&mut store, env, fd_fdstat_set_rights),
490 "fd_filestat_get" => Function::new_typed_with_env(&mut store, env, fd_filestat_get::<Memory32>),
491 "fd_filestat_set_size" => Function::new_typed_with_env(&mut store, env, fd_filestat_set_size),
492 "fd_filestat_set_times" => Function::new_typed_with_env(&mut store, env, fd_filestat_set_times),
493 "fd_pread" => Function::new_typed_with_env(&mut store, env, fd_pread::<Memory32>),
494 "fd_prestat_get" => Function::new_typed_with_env(&mut store, env, fd_prestat_get::<Memory32>),
495 "fd_prestat_dir_name" => Function::new_typed_with_env(&mut store, env, fd_prestat_dir_name::<Memory32>),
496 "fd_pwrite" => Function::new_typed_with_env(&mut store, env, fd_pwrite::<Memory32>),
497 "fd_read" => Function::new_typed_with_env(&mut store, env, fd_read::<Memory32>),
498 "fd_readdir" => Function::new_typed_with_env(&mut store, env, fd_readdir::<Memory32>),
499 "fd_renumber" => Function::new_typed_with_env(&mut store, env, fd_renumber),
500 "fd_seek" => Function::new_typed_with_env(&mut store, env, fd_seek::<Memory32>),
501 "fd_sync" => Function::new_typed_with_env(&mut store, env, fd_sync),
502 "fd_tell" => Function::new_typed_with_env(&mut store, env, fd_tell::<Memory32>),
503 "fd_write" => Function::new_typed_with_env(&mut store, env, fd_write::<Memory32>),
504 "path_create_directory" => Function::new_typed_with_env(&mut store, env, path_create_directory::<Memory32>),
505 "path_filestat_get" => Function::new_typed_with_env(&mut store, env, path_filestat_get::<Memory32>),
506 "path_filestat_set_times" => Function::new_typed_with_env(&mut store, env, path_filestat_set_times::<Memory32>),
507 "path_link" => Function::new_typed_with_env(&mut store, env, path_link::<Memory32>),
508 "path_open" => Function::new_typed_with_env(&mut store, env, path_open::<Memory32>),
509 "path_readlink" => Function::new_typed_with_env(&mut store, env, path_readlink::<Memory32>),
510 "path_remove_directory" => Function::new_typed_with_env(&mut store, env, path_remove_directory::<Memory32>),
511 "path_rename" => Function::new_typed_with_env(&mut store, env, path_rename::<Memory32>),
512 "path_symlink" => Function::new_typed_with_env(&mut store, env, path_symlink::<Memory32>),
513 "path_unlink_file" => Function::new_typed_with_env(&mut store, env, path_unlink_file::<Memory32>),
514 "poll_oneoff" => Function::new_typed_with_env(&mut store, env, poll_oneoff::<Memory32>),
515 "proc_exit" => Function::new_typed_with_env(&mut store, env, proc_exit::<Memory32>),
516 "proc_raise" => Function::new_typed_with_env(&mut store, env, proc_raise),
517 "random_get" => Function::new_typed_with_env(&mut store, env, random_get::<Memory32>),
518 "sched_yield" => Function::new_typed_with_env(&mut store, env, sched_yield::<Memory32>),
519 "sock_accept" => Function::new_typed_with_env(&mut store, env, sock_accept::<Memory32>),
520 "sock_recv" => Function::new_typed_with_env(&mut store, env, sock_recv::<Memory32>),
521 "sock_send" => Function::new_typed_with_env(&mut store, env, sock_send::<Memory32>),
522 "sock_shutdown" => Function::new_typed_with_env(&mut store, env, sock_shutdown),
523 "thread-spawn" => Function::new_typed_with_env(&mut store, env, thread_spawn::<Memory32>),
524 };
525 namespace
526}
527
528fn wasix_exports_32(mut store: &mut impl AsStoreMut, env: &FunctionEnv<WasiEnv>) -> Exports {
529 use syscalls::*;
530 let namespace = namespace! {
531 "args_get" => Function::new_typed_with_env(&mut store, env, args_get::<Memory32>),
532 "args_sizes_get" => Function::new_typed_with_env(&mut store, env, args_sizes_get::<Memory32>),
533 "call_dynamic" => Function::new_typed_with_env(&mut store, env, call_dynamic::<Memory32>),
534 "reflect_signature" => Function::new_typed_with_env(&mut store, env, reflect_signature::<Memory32>),
535 "clock_res_get" => Function::new_typed_with_env(&mut store, env, clock_res_get::<Memory32>),
536 "clock_time_get" => Function::new_typed_with_env(&mut store, env, clock_time_get::<Memory32>),
537 "clock_time_set" => Function::new_typed_with_env(&mut store, env, clock_time_set),
538 "closure_prepare" => Function::new_typed_with_env(&mut store, env, closure_prepare::<Memory32>),
539 "closure_allocate" => Function::new_typed_with_env(&mut store, env, closure_allocate::<Memory32>),
540 "closure_free" => Function::new_typed_with_env(&mut store, env, closure_free),
541 "environ_get" => Function::new_typed_with_env(&mut store, env, environ_get::<Memory32>),
542 "environ_sizes_get" => Function::new_typed_with_env(&mut store, env, environ_sizes_get::<Memory32>),
543 "epoll_create" => Function::new_typed_with_env(&mut store, env, epoll_create::<Memory32>),
544 "epoll_ctl" => Function::new_typed_with_env(&mut store, env, epoll_ctl::<Memory32>),
545 "epoll_wait" => Function::new_typed_with_env(&mut store, env, epoll_wait::<Memory32>),
546 "fd_advise" => Function::new_typed_with_env(&mut store, env, fd_advise),
547 "fd_allocate" => Function::new_typed_with_env(&mut store, env, fd_allocate),
548 "fd_close" => Function::new_typed_with_env(&mut store, env, fd_close),
549 "fd_datasync" => Function::new_typed_with_env(&mut store, env, fd_datasync),
550 "fd_fdstat_get" => Function::new_typed_with_env(&mut store, env, fd_fdstat_get::<Memory32>),
551 "fd_fdstat_set_flags" => Function::new_typed_with_env(&mut store, env, fd_fdstat_set_flags),
552 "fd_fdstat_set_rights" => Function::new_typed_with_env(&mut store, env, fd_fdstat_set_rights),
553 "fd_filestat_get" => Function::new_typed_with_env(&mut store, env, fd_filestat_get::<Memory32>),
554 "fd_filestat_set_size" => Function::new_typed_with_env(&mut store, env, fd_filestat_set_size),
555 "fd_filestat_set_times" => Function::new_typed_with_env(&mut store, env, fd_filestat_set_times),
556 "fd_pread" => Function::new_typed_with_env(&mut store, env, fd_pread::<Memory32>),
557 "fd_prestat_get" => Function::new_typed_with_env(&mut store, env, fd_prestat_get::<Memory32>),
558 "fd_prestat_dir_name" => Function::new_typed_with_env(&mut store, env, fd_prestat_dir_name::<Memory32>),
559 "fd_pwrite" => Function::new_typed_with_env(&mut store, env, fd_pwrite::<Memory32>),
560 "fd_read" => Function::new_typed_with_env(&mut store, env, fd_read::<Memory32>),
561 "fd_readdir" => Function::new_typed_with_env(&mut store, env, fd_readdir::<Memory32>),
562 "fd_renumber" => Function::new_typed_with_env(&mut store, env, fd_renumber),
563 "fd_dup" => Function::new_typed_with_env(&mut store, env, fd_dup::<Memory32>),
564 "fd_dup2" => Function::new_typed_with_env(&mut store, env, fd_dup2::<Memory32>),
565 "fd_fdflags_get" => Function::new_typed_with_env(&mut store, env, fd_fdflags_get::<Memory32>),
566 "fd_fdflags_set" => Function::new_typed_with_env(&mut store, env, fd_fdflags_set),
567 "fd_event" => Function::new_typed_with_env(&mut store, env, fd_event::<Memory32>),
568 "fd_seek" => Function::new_typed_with_env(&mut store, env, fd_seek::<Memory32>),
569 "fd_sync" => Function::new_typed_with_env(&mut store, env, fd_sync),
570 "fd_tell" => Function::new_typed_with_env(&mut store, env, fd_tell::<Memory32>),
571 "fd_write" => Function::new_typed_with_env(&mut store, env, fd_write::<Memory32>),
572 "fd_pipe" => Function::new_typed_with_env(&mut store, env, fd_pipe::<Memory32>),
573 "path_create_directory" => Function::new_typed_with_env(&mut store, env, path_create_directory::<Memory32>),
574 "path_filestat_get" => Function::new_typed_with_env(&mut store, env, path_filestat_get::<Memory32>),
575 "path_filestat_set_times" => Function::new_typed_with_env(&mut store, env, path_filestat_set_times::<Memory32>),
576 "path_link" => Function::new_typed_with_env(&mut store, env, path_link::<Memory32>),
577 "path_open" => Function::new_typed_with_env(&mut store, env, path_open::<Memory32>),
578 "path_open2" => Function::new_typed_with_env(&mut store, env, path_open2::<Memory32>),
579 "path_readlink" => Function::new_typed_with_env(&mut store, env, path_readlink::<Memory32>),
580 "path_remove_directory" => Function::new_typed_with_env(&mut store, env, path_remove_directory::<Memory32>),
581 "path_rename" => Function::new_typed_with_env(&mut store, env, path_rename::<Memory32>),
582 "path_symlink" => Function::new_typed_with_env(&mut store, env, path_symlink::<Memory32>),
583 "path_unlink_file" => Function::new_typed_with_env(&mut store, env, path_unlink_file::<Memory32>),
584 "poll_oneoff" => Function::new_typed_with_env(&mut store, env, poll_oneoff::<Memory32>),
585 "proc_exit" => Function::new_typed_with_env(&mut store, env, proc_exit::<Memory32>),
586 "proc_fork" => Function::new_typed_with_env(&mut store, env, proc_fork::<Memory32>),
587 "proc_join" => Function::new_typed_with_env(&mut store, env, proc_join::<Memory32>),
588 "proc_signal" => Function::new_typed_with_env(&mut store, env, proc_signal),
589 "proc_signals_get" => Function::new_typed_with_env(&mut store, env, proc_signals_get::<Memory32>),
590 "proc_signals_sizes_get" => Function::new_typed_with_env(&mut store, env, proc_signals_sizes_get::<Memory32>),
591 "proc_exec" => Function::new_typed_with_env(&mut store, env, proc_exec::<Memory32>),
592 "proc_exec2" => Function::new_typed_with_env(&mut store, env, proc_exec2::<Memory32>),
593 "proc_exec3" => Function::new_typed_with_env(&mut store, env, proc_exec3::<Memory32>),
594 "proc_raise" => Function::new_typed_with_env(&mut store, env, proc_raise),
595 "proc_raise_interval" => Function::new_typed_with_env(&mut store, env, proc_raise_interval),
596 "proc_snapshot" => Function::new_typed_with_env(&mut store, env, proc_snapshot::<Memory32>),
597 "proc_spawn" => Function::new_typed_with_env(&mut store, env, proc_spawn::<Memory32>),
598 "proc_spawn2" => Function::new_typed_with_env(&mut store, env, proc_spawn2::<Memory32>),
599 "proc_id" => Function::new_typed_with_env(&mut store, env, proc_id::<Memory32>),
600 "proc_parent" => Function::new_typed_with_env(&mut store, env, proc_parent::<Memory32>),
601 "random_get" => Function::new_typed_with_env(&mut store, env, random_get::<Memory32>),
602 "tty_get" => Function::new_typed_with_env(&mut store, env, tty_get::<Memory32>),
603 "tty_set" => Function::new_typed_with_env(&mut store, env, tty_set::<Memory32>),
604 "getcwd" => Function::new_typed_with_env(&mut store, env, getcwd::<Memory32>),
605 "chdir" => Function::new_typed_with_env(&mut store, env, chdir::<Memory32>),
606 "dl_invalid_handle" => Function::new_typed_with_env(&mut store, env, dl_invalid_handle),
607 "dlopen" => Function::new_typed_with_env(&mut store, env, dlopen::<Memory32>),
608 "dlsym" => Function::new_typed_with_env(&mut store, env, dlsym::<Memory32>),
609 "callback_signal" => Function::new_typed_with_env(&mut store, env, callback_signal::<Memory32>),
610 "thread_spawn" => Function::new_typed_with_env(&mut store, env, thread_spawn_v2::<Memory32>),
611 "thread_spawn_v2" => Function::new_typed_with_env(&mut store, env, thread_spawn_v2::<Memory32>),
612 "thread_sleep" => Function::new_typed_with_env(&mut store, env, thread_sleep::<Memory32>),
613 "thread_id" => Function::new_typed_with_env(&mut store, env, thread_id::<Memory32>),
614 "thread_signal" => Function::new_typed_with_env(&mut store, env, thread_signal),
615 "thread_join" => Function::new_typed_with_env(&mut store, env, thread_join::<Memory32>),
616 "thread_parallelism" => Function::new_typed_with_env(&mut store, env, thread_parallelism::<Memory32>),
617 "thread_exit" => Function::new_typed_with_env(&mut store, env, thread_exit),
618 "sched_yield" => Function::new_typed_with_env(&mut store, env, sched_yield::<Memory32>),
619 "stack_checkpoint" => Function::new_typed_with_env(&mut store, env, stack_checkpoint::<Memory32>),
620 "stack_restore" => Function::new_typed_with_env(&mut store, env, stack_restore::<Memory32>),
621 "futex_wait" => Function::new_typed_with_env(&mut store, env, futex_wait::<Memory32>),
622 "futex_wake" => Function::new_typed_with_env(&mut store, env, futex_wake::<Memory32>),
623 "futex_wake_all" => Function::new_typed_with_env(&mut store, env, futex_wake_all::<Memory32>),
624 "port_bridge" => Function::new_typed_with_env(&mut store, env, port_bridge::<Memory32>),
625 "port_unbridge" => Function::new_typed_with_env(&mut store, env, port_unbridge),
626 "port_dhcp_acquire" => Function::new_typed_with_env(&mut store, env, port_dhcp_acquire),
627 "port_addr_add" => Function::new_typed_with_env(&mut store, env, port_addr_add::<Memory32>),
628 "port_addr_remove" => Function::new_typed_with_env(&mut store, env, port_addr_remove::<Memory32>),
629 "port_addr_clear" => Function::new_typed_with_env(&mut store, env, port_addr_clear),
630 "port_addr_list" => Function::new_typed_with_env(&mut store, env, port_addr_list::<Memory32>),
631 "port_mac" => Function::new_typed_with_env(&mut store, env, port_mac::<Memory32>),
632 "port_gateway_set" => Function::new_typed_with_env(&mut store, env, port_gateway_set::<Memory32>),
633 "port_route_add" => Function::new_typed_with_env(&mut store, env, port_route_add::<Memory32>),
634 "port_route_remove" => Function::new_typed_with_env(&mut store, env, port_route_remove::<Memory32>),
635 "port_route_clear" => Function::new_typed_with_env(&mut store, env, port_route_clear),
636 "port_route_list" => Function::new_typed_with_env(&mut store, env, port_route_list::<Memory32>),
637 "sock_status" => Function::new_typed_with_env(&mut store, env, sock_status::<Memory32>),
638 "sock_addr_local" => Function::new_typed_with_env(&mut store, env, sock_addr_local::<Memory32>),
639 "sock_addr_peer" => Function::new_typed_with_env(&mut store, env, sock_addr_peer::<Memory32>),
640 "sock_open" => Function::new_typed_with_env(&mut store, env, sock_open::<Memory32>),
641 "sock_pair" => Function::new_typed_with_env(&mut store, env, sock_pair::<Memory32>),
642 "sock_set_opt_flag" => Function::new_typed_with_env(&mut store, env, sock_set_opt_flag),
643 "sock_get_opt_flag" => Function::new_typed_with_env(&mut store, env, sock_get_opt_flag::<Memory32>),
644 "sock_set_opt_time" => Function::new_typed_with_env(&mut store, env, sock_set_opt_time::<Memory32>),
645 "sock_get_opt_time" => Function::new_typed_with_env(&mut store, env, sock_get_opt_time::<Memory32>),
646 "sock_set_opt_size" => Function::new_typed_with_env(&mut store, env, sock_set_opt_size),
647 "sock_get_opt_size" => Function::new_typed_with_env(&mut store, env, sock_get_opt_size::<Memory32>),
648 "sock_join_multicast_v4" => Function::new_typed_with_env(&mut store, env, sock_join_multicast_v4::<Memory32>),
649 "sock_leave_multicast_v4" => Function::new_typed_with_env(&mut store, env, sock_leave_multicast_v4::<Memory32>),
650 "sock_join_multicast_v6" => Function::new_typed_with_env(&mut store, env, sock_join_multicast_v6::<Memory32>),
651 "sock_leave_multicast_v6" => Function::new_typed_with_env(&mut store, env, sock_leave_multicast_v6::<Memory32>),
652 "sock_bind" => Function::new_typed_with_env(&mut store, env, sock_bind::<Memory32>),
653 "sock_listen" => Function::new_typed_with_env(&mut store, env, sock_listen::<Memory32>),
654 "sock_accept" => Function::new_typed_with_env(&mut store, env, sock_accept_v2::<Memory32>),
655 "sock_accept_v2" => Function::new_typed_with_env(&mut store, env, sock_accept_v2::<Memory32>),
656 "sock_connect" => Function::new_typed_with_env(&mut store, env, sock_connect::<Memory32>),
657 "sock_recv" => Function::new_typed_with_env(&mut store, env, sock_recv::<Memory32>),
658 "sock_recv_from" => Function::new_typed_with_env(&mut store, env, sock_recv_from::<Memory32>),
659 "sock_send" => Function::new_typed_with_env(&mut store, env, sock_send::<Memory32>),
660 "sock_send_to" => Function::new_typed_with_env(&mut store, env, sock_send_to::<Memory32>),
661 "sock_send_file" => Function::new_typed_with_env(&mut store, env, sock_send_file::<Memory32>),
662 "sock_shutdown" => Function::new_typed_with_env(&mut store, env, sock_shutdown),
663 "resolve" => Function::new_typed_with_env(&mut store, env, resolve::<Memory32>),
664 };
665 namespace
666}
667
668fn wasix_exports_64(mut store: &mut impl AsStoreMut, env: &FunctionEnv<WasiEnv>) -> Exports {
669 use syscalls::*;
670 let namespace = namespace! {
671 "args_get" => Function::new_typed_with_env(&mut store, env, args_get::<Memory64>),
672 "args_sizes_get" => Function::new_typed_with_env(&mut store, env, args_sizes_get::<Memory64>),
673 "call_dynamic" => Function::new_typed_with_env(&mut store, env, call_dynamic::<Memory64>),
674 "reflect_signature" => Function::new_typed_with_env(&mut store, env, reflect_signature::<Memory64>),
675 "clock_res_get" => Function::new_typed_with_env(&mut store, env, clock_res_get::<Memory64>),
676 "clock_time_get" => Function::new_typed_with_env(&mut store, env, clock_time_get::<Memory64>),
677 "clock_time_set" => Function::new_typed_with_env(&mut store, env, clock_time_set),
678 "closure_prepare" => Function::new_typed_with_env(&mut store, env, closure_prepare::<Memory64>),
679 "closure_allocate" => Function::new_typed_with_env(&mut store, env, closure_allocate::<Memory64>),
680 "closure_free" => Function::new_typed_with_env(&mut store, env, closure_free),
681 "environ_get" => Function::new_typed_with_env(&mut store, env, environ_get::<Memory64>),
682 "environ_sizes_get" => Function::new_typed_with_env(&mut store, env, environ_sizes_get::<Memory64>),
683 "epoll_create" => Function::new_typed_with_env(&mut store, env, epoll_create::<Memory64>),
684 "epoll_ctl" => Function::new_typed_with_env(&mut store, env, epoll_ctl::<Memory64>),
685 "epoll_wait" => Function::new_typed_with_env(&mut store, env, epoll_wait::<Memory64>),
686 "fd_advise" => Function::new_typed_with_env(&mut store, env, fd_advise),
687 "fd_allocate" => Function::new_typed_with_env(&mut store, env, fd_allocate),
688 "fd_close" => Function::new_typed_with_env(&mut store, env, fd_close),
689 "fd_datasync" => Function::new_typed_with_env(&mut store, env, fd_datasync),
690 "fd_fdstat_get" => Function::new_typed_with_env(&mut store, env, fd_fdstat_get::<Memory64>),
691 "fd_fdstat_set_flags" => Function::new_typed_with_env(&mut store, env, fd_fdstat_set_flags),
692 "fd_fdstat_set_rights" => Function::new_typed_with_env(&mut store, env, fd_fdstat_set_rights),
693 "fd_filestat_get" => Function::new_typed_with_env(&mut store, env, fd_filestat_get::<Memory64>),
694 "fd_filestat_set_size" => Function::new_typed_with_env(&mut store, env, fd_filestat_set_size),
695 "fd_filestat_set_times" => Function::new_typed_with_env(&mut store, env, fd_filestat_set_times),
696 "fd_pread" => Function::new_typed_with_env(&mut store, env, fd_pread::<Memory64>),
697 "fd_prestat_get" => Function::new_typed_with_env(&mut store, env, fd_prestat_get::<Memory64>),
698 "fd_prestat_dir_name" => Function::new_typed_with_env(&mut store, env, fd_prestat_dir_name::<Memory64>),
699 "fd_pwrite" => Function::new_typed_with_env(&mut store, env, fd_pwrite::<Memory64>),
700 "fd_read" => Function::new_typed_with_env(&mut store, env, fd_read::<Memory64>),
701 "fd_readdir" => Function::new_typed_with_env(&mut store, env, fd_readdir::<Memory64>),
702 "fd_renumber" => Function::new_typed_with_env(&mut store, env, fd_renumber),
703 "fd_dup" => Function::new_typed_with_env(&mut store, env, fd_dup::<Memory64>),
704 "fd_dup2" => Function::new_typed_with_env(&mut store, env, fd_dup2::<Memory64>),
705 "fd_fdflags_get" => Function::new_typed_with_env(&mut store, env, fd_fdflags_get::<Memory64>),
706 "fd_fdflags_set" => Function::new_typed_with_env(&mut store, env, fd_fdflags_set),
707 "fd_event" => Function::new_typed_with_env(&mut store, env, fd_event::<Memory64>),
708 "fd_seek" => Function::new_typed_with_env(&mut store, env, fd_seek::<Memory64>),
709 "fd_sync" => Function::new_typed_with_env(&mut store, env, fd_sync),
710 "fd_tell" => Function::new_typed_with_env(&mut store, env, fd_tell::<Memory64>),
711 "fd_write" => Function::new_typed_with_env(&mut store, env, fd_write::<Memory64>),
712 "fd_pipe" => Function::new_typed_with_env(&mut store, env, fd_pipe::<Memory64>),
713 "path_create_directory" => Function::new_typed_with_env(&mut store, env, path_create_directory::<Memory64>),
714 "path_filestat_get" => Function::new_typed_with_env(&mut store, env, path_filestat_get::<Memory64>),
715 "path_filestat_set_times" => Function::new_typed_with_env(&mut store, env, path_filestat_set_times::<Memory64>),
716 "path_link" => Function::new_typed_with_env(&mut store, env, path_link::<Memory64>),
717 "path_open" => Function::new_typed_with_env(&mut store, env, path_open::<Memory64>),
718 "path_open2" => Function::new_typed_with_env(&mut store, env, path_open2::<Memory64>),
719 "path_readlink" => Function::new_typed_with_env(&mut store, env, path_readlink::<Memory64>),
720 "path_remove_directory" => Function::new_typed_with_env(&mut store, env, path_remove_directory::<Memory64>),
721 "path_rename" => Function::new_typed_with_env(&mut store, env, path_rename::<Memory64>),
722 "path_symlink" => Function::new_typed_with_env(&mut store, env, path_symlink::<Memory64>),
723 "path_unlink_file" => Function::new_typed_with_env(&mut store, env, path_unlink_file::<Memory64>),
724 "poll_oneoff" => Function::new_typed_with_env(&mut store, env, poll_oneoff::<Memory64>),
725 "proc_exit" => Function::new_typed_with_env(&mut store, env, proc_exit::<Memory64>),
726 "proc_fork" => Function::new_typed_with_env(&mut store, env, proc_fork::<Memory64>),
727 "proc_join" => Function::new_typed_with_env(&mut store, env, proc_join::<Memory64>),
728 "proc_signal" => Function::new_typed_with_env(&mut store, env, proc_signal),
729 "proc_signals_get" => Function::new_typed_with_env(&mut store, env, proc_signals_get::<Memory64>),
730 "proc_signals_sizes_get" => Function::new_typed_with_env(&mut store, env, proc_signals_sizes_get::<Memory64>),
731 "proc_exec" => Function::new_typed_with_env(&mut store, env, proc_exec::<Memory64>),
732 "proc_exec2" => Function::new_typed_with_env(&mut store, env, proc_exec2::<Memory64>),
733 "proc_exec3" => Function::new_typed_with_env(&mut store, env, proc_exec3::<Memory64>),
734 "proc_raise" => Function::new_typed_with_env(&mut store, env, proc_raise),
735 "proc_raise_interval" => Function::new_typed_with_env(&mut store, env, proc_raise_interval),
736 "proc_snapshot" => Function::new_typed_with_env(&mut store, env, proc_snapshot::<Memory64>),
737 "proc_spawn" => Function::new_typed_with_env(&mut store, env, proc_spawn::<Memory64>),
738 "proc_spawn2" => Function::new_typed_with_env(&mut store, env, proc_spawn2::<Memory64>),
739 "proc_id" => Function::new_typed_with_env(&mut store, env, proc_id::<Memory64>),
740 "proc_parent" => Function::new_typed_with_env(&mut store, env, proc_parent::<Memory64>),
741 "random_get" => Function::new_typed_with_env(&mut store, env, random_get::<Memory64>),
742 "tty_get" => Function::new_typed_with_env(&mut store, env, tty_get::<Memory64>),
743 "tty_set" => Function::new_typed_with_env(&mut store, env, tty_set::<Memory64>),
744 "getcwd" => Function::new_typed_with_env(&mut store, env, getcwd::<Memory64>),
745 "chdir" => Function::new_typed_with_env(&mut store, env, chdir::<Memory64>),
746 "dl_invalid_handle" => Function::new_typed_with_env(&mut store, env, dl_invalid_handle),
747 "dlopen" => Function::new_typed_with_env(&mut store, env, dlopen::<Memory64>),
748 "dlsym" => Function::new_typed_with_env(&mut store, env, dlsym::<Memory64>),
749 "callback_signal" => Function::new_typed_with_env(&mut store, env, callback_signal::<Memory64>),
750 "thread_spawn" => Function::new_typed_with_env(&mut store, env, thread_spawn_v2::<Memory64>),
751 "thread_spawn_v2" => Function::new_typed_with_env(&mut store, env, thread_spawn_v2::<Memory64>),
752 "thread_sleep" => Function::new_typed_with_env(&mut store, env, thread_sleep::<Memory64>),
753 "thread_id" => Function::new_typed_with_env(&mut store, env, thread_id::<Memory64>),
754 "thread_signal" => Function::new_typed_with_env(&mut store, env, thread_signal),
755 "thread_join" => Function::new_typed_with_env(&mut store, env, thread_join::<Memory64>),
756 "thread_parallelism" => Function::new_typed_with_env(&mut store, env, thread_parallelism::<Memory64>),
757 "thread_exit" => Function::new_typed_with_env(&mut store, env, thread_exit),
758 "sched_yield" => Function::new_typed_with_env(&mut store, env, sched_yield::<Memory64>),
759 "stack_checkpoint" => Function::new_typed_with_env(&mut store, env, stack_checkpoint::<Memory64>),
760 "stack_restore" => Function::new_typed_with_env(&mut store, env, stack_restore::<Memory64>),
761 "futex_wait" => Function::new_typed_with_env(&mut store, env, futex_wait::<Memory64>),
762 "futex_wake" => Function::new_typed_with_env(&mut store, env, futex_wake::<Memory64>),
763 "futex_wake_all" => Function::new_typed_with_env(&mut store, env, futex_wake_all::<Memory64>),
764 "port_bridge" => Function::new_typed_with_env(&mut store, env, port_bridge::<Memory64>),
765 "port_unbridge" => Function::new_typed_with_env(&mut store, env, port_unbridge),
766 "port_dhcp_acquire" => Function::new_typed_with_env(&mut store, env, port_dhcp_acquire),
767 "port_addr_add" => Function::new_typed_with_env(&mut store, env, port_addr_add::<Memory64>),
768 "port_addr_remove" => Function::new_typed_with_env(&mut store, env, port_addr_remove::<Memory64>),
769 "port_addr_clear" => Function::new_typed_with_env(&mut store, env, port_addr_clear),
770 "port_addr_list" => Function::new_typed_with_env(&mut store, env, port_addr_list::<Memory64>),
771 "port_mac" => Function::new_typed_with_env(&mut store, env, port_mac::<Memory64>),
772 "port_gateway_set" => Function::new_typed_with_env(&mut store, env, port_gateway_set::<Memory64>),
773 "port_route_add" => Function::new_typed_with_env(&mut store, env, port_route_add::<Memory64>),
774 "port_route_remove" => Function::new_typed_with_env(&mut store, env, port_route_remove::<Memory64>),
775 "port_route_clear" => Function::new_typed_with_env(&mut store, env, port_route_clear),
776 "port_route_list" => Function::new_typed_with_env(&mut store, env, port_route_list::<Memory64>),
777 "sock_status" => Function::new_typed_with_env(&mut store, env, sock_status::<Memory64>),
778 "sock_addr_local" => Function::new_typed_with_env(&mut store, env, sock_addr_local::<Memory64>),
779 "sock_addr_peer" => Function::new_typed_with_env(&mut store, env, sock_addr_peer::<Memory64>),
780 "sock_open" => Function::new_typed_with_env(&mut store, env, sock_open::<Memory64>),
781 "sock_pair" => Function::new_typed_with_env(&mut store, env, sock_pair::<Memory64>),
782 "sock_set_opt_flag" => Function::new_typed_with_env(&mut store, env, sock_set_opt_flag),
783 "sock_get_opt_flag" => Function::new_typed_with_env(&mut store, env, sock_get_opt_flag::<Memory64>),
784 "sock_set_opt_time" => Function::new_typed_with_env(&mut store, env, sock_set_opt_time::<Memory64>),
785 "sock_get_opt_time" => Function::new_typed_with_env(&mut store, env, sock_get_opt_time::<Memory64>),
786 "sock_set_opt_size" => Function::new_typed_with_env(&mut store, env, sock_set_opt_size),
787 "sock_get_opt_size" => Function::new_typed_with_env(&mut store, env, sock_get_opt_size::<Memory64>),
788 "sock_join_multicast_v4" => Function::new_typed_with_env(&mut store, env, sock_join_multicast_v4::<Memory64>),
789 "sock_leave_multicast_v4" => Function::new_typed_with_env(&mut store, env, sock_leave_multicast_v4::<Memory64>),
790 "sock_join_multicast_v6" => Function::new_typed_with_env(&mut store, env, sock_join_multicast_v6::<Memory64>),
791 "sock_leave_multicast_v6" => Function::new_typed_with_env(&mut store, env, sock_leave_multicast_v6::<Memory64>),
792 "sock_bind" => Function::new_typed_with_env(&mut store, env, sock_bind::<Memory64>),
793 "sock_listen" => Function::new_typed_with_env(&mut store, env, sock_listen::<Memory64>),
794 "sock_accept" => Function::new_typed_with_env(&mut store, env, sock_accept_v2::<Memory64>),
795 "sock_accept_v2" => Function::new_typed_with_env(&mut store, env, sock_accept_v2::<Memory64>),
796 "sock_connect" => Function::new_typed_with_env(&mut store, env, sock_connect::<Memory64>),
797 "sock_recv" => Function::new_typed_with_env(&mut store, env, sock_recv::<Memory64>),
798 "sock_recv_from" => Function::new_typed_with_env(&mut store, env, sock_recv_from::<Memory64>),
799 "sock_send" => Function::new_typed_with_env(&mut store, env, sock_send::<Memory64>),
800 "sock_send_to" => Function::new_typed_with_env(&mut store, env, sock_send_to::<Memory64>),
801 "sock_send_file" => Function::new_typed_with_env(&mut store, env, sock_send_file::<Memory64>),
802 "sock_shutdown" => Function::new_typed_with_env(&mut store, env, sock_shutdown),
803 "resolve" => Function::new_typed_with_env(&mut store, env, resolve::<Memory64>),
804 };
805 namespace
806}
807
808fn import_object_for_all_wasi_versions(
811 _module: &wasmer::Module,
812 store: &mut impl AsStoreMut,
813 env: &FunctionEnv<WasiEnv>,
814) -> Imports {
815 let exports_wasi_generic = wasi_exports_generic(store, env);
816 let exports_wasi_unstable = wasi_unstable_exports(store, env);
817 let exports_wasi_snapshot_preview1 = wasi_snapshot_preview1_exports(store, env);
818 let exports_wasix_32v1 = wasix_exports_32(store, env);
819 let exports_wasix_64v1 = wasix_exports_64(store, env);
820
821 #[allow(unused_mut)]
823 let mut imports = imports! {
824 "wasi" => exports_wasi_generic,
825 "wasi_unstable" => exports_wasi_unstable,
826 "wasi_snapshot_preview1" => exports_wasi_snapshot_preview1,
827 "wasix_32v1" => exports_wasix_32v1,
828 "wasix_64v1" => exports_wasix_64v1,
829 };
830
831 imports
832}
833
834fn generate_import_object_snapshot0(
836 store: &mut impl AsStoreMut,
837 env: &FunctionEnv<WasiEnv>,
838) -> Imports {
839 let exports_unstable = wasi_unstable_exports(store, env);
840 imports! {
841 "wasi_unstable" => exports_unstable
842 }
843}
844
845fn generate_import_object_snapshot1(
846 store: &mut impl AsStoreMut,
847 env: &FunctionEnv<WasiEnv>,
848) -> Imports {
849 let exports_wasi_snapshot_preview1 = wasi_snapshot_preview1_exports(store, env);
850 imports! {
851 "wasi_snapshot_preview1" => exports_wasi_snapshot_preview1
852 }
853}
854
855fn generate_import_object_wasix32_v1(
857 store: &mut impl AsStoreMut,
858 env: &FunctionEnv<WasiEnv>,
859) -> Imports {
860 let exports_wasix_32v1 = wasix_exports_32(store, env);
861 imports! {
862 "wasix_32v1" => exports_wasix_32v1
863 }
864}
865
866fn generate_import_object_wasix64_v1(
867 store: &mut impl AsStoreMut,
868 env: &FunctionEnv<WasiEnv>,
869) -> Imports {
870 let exports_wasix_64v1 = wasix_exports_64(store, env);
871 imports! {
872 "wasix_64v1" => exports_wasix_64v1
873 }
874}
875
876fn mem_error_to_wasi(err: MemoryAccessError) -> Errno {
877 match err {
878 MemoryAccessError::HeapOutOfBounds => Errno::Memviolation,
879 MemoryAccessError::Overflow => Errno::Overflow,
880 MemoryAccessError::NonUtf8String => Errno::Inval,
881 _ => Errno::Unknown,
882 }
883}
884
885pub(crate) fn block_in_place<Ret>(thunk: impl FnOnce() -> Ret) -> Ret {
891 cfg_if::cfg_if! {
892 if #[cfg(feature = "sys-thread")] {
893 tokio::task::block_in_place(thunk)
894 } else {
895 thunk()
896 }
897 }
898}
899
900pub(crate) async fn spawn_blocking<F, R>(f: F) -> Result<R, tokio::task::JoinError>
906where
907 F: FnOnce() -> R + Send + 'static,
908 R: Send + 'static,
909{
910 cfg_if::cfg_if! {
911 if #[cfg(target_arch = "wasm32")] {
912 Ok(block_in_place(f))
913 } else {
914 tokio::task::spawn_blocking(f).await
915 }
916 }
917}
918
919pub(crate) fn flatten_runtime_error(err: RuntimeError) -> RuntimeError {
920 let e_ref = err.downcast_ref::<WasiRuntimeError>();
921 match e_ref {
922 Some(WasiRuntimeError::Wasi(_)) => {
923 let Ok(WasiRuntimeError::Wasi(err)) = err.downcast::<WasiRuntimeError>() else {
924 unreachable!()
925 };
926 RuntimeError::user(Box::new(err))
927 }
928 Some(WasiRuntimeError::Runtime(_)) => {
929 let Ok(WasiRuntimeError::Runtime(err)) = err.downcast::<WasiRuntimeError>() else {
930 unreachable!()
931 };
932 flatten_runtime_error(err)
933 }
934 _ => err,
935 }
936}