mirror of
https://github.com/fluencelabs/wasmer
synced 2025-07-02 10:01:33 +00:00
Rename to experimental-io-devices and clean up for release
This commit is contained in:
@ -54,97 +54,6 @@ pub fn generate_import_object(
|
||||
envs: Vec<Vec<u8>>,
|
||||
preopened_files: Vec<PathBuf>,
|
||||
mapped_dirs: Vec<(String, PathBuf)>,
|
||||
) -> ImportObject {
|
||||
generate_import_object_for_version(
|
||||
WasiVersion::Latest,
|
||||
args,
|
||||
envs,
|
||||
preopened_files,
|
||||
mapped_dirs,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn generate_import_object_from_state(
|
||||
wasi_state: WasiState,
|
||||
_version: WasiVersion,
|
||||
) -> ImportObject {
|
||||
// THIS IS DEVELOPMENT CODE; DO NOT SHIP
|
||||
let wasi_state_bytes = wasi_state.freeze().unwrap();
|
||||
let state_gen = move || {
|
||||
fn state_destructor(data: *mut c_void) {
|
||||
unsafe {
|
||||
drop(std::rc::Rc::from_raw(data as *mut WasiState));
|
||||
}
|
||||
}
|
||||
|
||||
let wasi_state = Box::new(WasiState::unfreeze(&wasi_state_bytes).unwrap());
|
||||
dbg!(&wasi_state);
|
||||
|
||||
(
|
||||
Box::into_raw(wasi_state) as *mut c_void,
|
||||
state_destructor as fn(*mut c_void),
|
||||
)
|
||||
};
|
||||
imports! {
|
||||
// This generates the wasi state.
|
||||
state_gen,
|
||||
"wasi_unstable" => {
|
||||
"args_get" => func!(args_get),
|
||||
"args_sizes_get" => func!(args_sizes_get),
|
||||
"clock_res_get" => func!(clock_res_get),
|
||||
"clock_time_get" => func!(clock_time_get),
|
||||
"environ_get" => func!(environ_get),
|
||||
"environ_sizes_get" => func!(environ_sizes_get),
|
||||
"fd_advise" => func!(fd_advise),
|
||||
"fd_allocate" => func!(fd_allocate),
|
||||
"fd_close" => func!(fd_close),
|
||||
"fd_datasync" => func!(fd_datasync),
|
||||
"fd_fdstat_get" => func!(fd_fdstat_get),
|
||||
"fd_fdstat_set_flags" => func!(fd_fdstat_set_flags),
|
||||
"fd_fdstat_set_rights" => func!(fd_fdstat_set_rights),
|
||||
"fd_filestat_get" => func!(legacy::snapshot0::fd_filestat_get),
|
||||
"fd_filestat_set_size" => func!(fd_filestat_set_size),
|
||||
"fd_filestat_set_times" => func!(fd_filestat_set_times),
|
||||
"fd_pread" => func!(fd_pread),
|
||||
"fd_prestat_get" => func!(fd_prestat_get),
|
||||
"fd_prestat_dir_name" => func!(fd_prestat_dir_name),
|
||||
"fd_pwrite" => func!(fd_pwrite),
|
||||
"fd_read" => func!(fd_read),
|
||||
"fd_readdir" => func!(fd_readdir),
|
||||
"fd_renumber" => func!(fd_renumber),
|
||||
"fd_seek" => func!(legacy::snapshot0::fd_seek),
|
||||
"fd_sync" => func!(fd_sync),
|
||||
"fd_tell" => func!(fd_tell),
|
||||
"fd_write" => func!(fd_write),
|
||||
"path_create_directory" => func!(path_create_directory),
|
||||
"path_filestat_get" => func!(legacy::snapshot0::path_filestat_get),
|
||||
"path_filestat_set_times" => func!(path_filestat_set_times),
|
||||
"path_link" => func!(path_link),
|
||||
"path_open" => func!(path_open),
|
||||
"path_readlink" => func!(path_readlink),
|
||||
"path_remove_directory" => func!(path_remove_directory),
|
||||
"path_rename" => func!(path_rename),
|
||||
"path_symlink" => func!(path_symlink),
|
||||
"path_unlink_file" => func!(path_unlink_file),
|
||||
"poll_oneoff" => func!(legacy::snapshot0::poll_oneoff),
|
||||
"proc_exit" => func!(proc_exit),
|
||||
"proc_raise" => func!(proc_raise),
|
||||
"random_get" => func!(random_get),
|
||||
"sched_yield" => func!(sched_yield),
|
||||
"sock_recv" => func!(sock_recv),
|
||||
"sock_send" => func!(sock_send),
|
||||
"sock_shutdown" => func!(sock_shutdown),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn generate_import_object_with_fs_setup(
|
||||
args: Vec<Vec<u8>>,
|
||||
envs: Vec<Vec<u8>>,
|
||||
preopened_files: Vec<PathBuf>,
|
||||
mapped_dirs: Vec<(String, PathBuf)>,
|
||||
setup_fs: Option<Arc<dyn Fn(&mut WasiFs) -> Result<(), String> + Send>>,
|
||||
) -> ImportObject {
|
||||
let state_gen = move || {
|
||||
// TODO: look into removing all these unnecessary clones
|
||||
@ -155,12 +64,6 @@ pub fn generate_import_object_with_fs_setup(
|
||||
}
|
||||
let preopened_files = preopened_files.clone();
|
||||
let mapped_dirs = mapped_dirs.clone();
|
||||
//let wasi_builder = create_wasi_instance();
|
||||
|
||||
let mut fs = WasiFs::new(&preopened_files, &mapped_dirs).unwrap();
|
||||
if let Some(sfn) = &setup_fs {
|
||||
sfn(&mut fs).unwrap();
|
||||
}
|
||||
|
||||
let state = Box::new(WasiState {
|
||||
fs: WasiFs::new(&preopened_files, &mapped_dirs).expect("Could not create WASI FS"),
|
||||
@ -173,58 +76,41 @@ pub fn generate_import_object_with_fs_setup(
|
||||
state_destructor as fn(*mut c_void),
|
||||
)
|
||||
};
|
||||
imports! {
|
||||
// This generates the wasi state.
|
||||
state_gen,
|
||||
"wasi_snapshot_preview1" => {
|
||||
"args_get" => func!(args_get),
|
||||
"args_sizes_get" => func!(args_sizes_get),
|
||||
"clock_res_get" => func!(clock_res_get),
|
||||
"clock_time_get" => func!(clock_time_get),
|
||||
"environ_get" => func!(environ_get),
|
||||
"environ_sizes_get" => func!(environ_sizes_get),
|
||||
"fd_advise" => func!(fd_advise),
|
||||
"fd_allocate" => func!(fd_allocate),
|
||||
"fd_close" => func!(fd_close),
|
||||
"fd_datasync" => func!(fd_datasync),
|
||||
"fd_fdstat_get" => func!(fd_fdstat_get),
|
||||
"fd_fdstat_set_flags" => func!(fd_fdstat_set_flags),
|
||||
"fd_fdstat_set_rights" => func!(fd_fdstat_set_rights),
|
||||
"fd_filestat_get" => func!(fd_filestat_get),
|
||||
"fd_filestat_set_size" => func!(fd_filestat_set_size),
|
||||
"fd_filestat_set_times" => func!(fd_filestat_set_times),
|
||||
"fd_pread" => func!(fd_pread),
|
||||
"fd_prestat_get" => func!(fd_prestat_get),
|
||||
"fd_prestat_dir_name" => func!(fd_prestat_dir_name),
|
||||
"fd_pwrite" => func!(fd_pwrite),
|
||||
"fd_read" => func!(fd_read),
|
||||
"fd_readdir" => func!(fd_readdir),
|
||||
"fd_renumber" => func!(fd_renumber),
|
||||
"fd_seek" => func!(fd_seek),
|
||||
"fd_sync" => func!(fd_sync),
|
||||
"fd_tell" => func!(fd_tell),
|
||||
"fd_write" => func!(fd_write),
|
||||
"path_create_directory" => func!(path_create_directory),
|
||||
"path_filestat_get" => func!(path_filestat_get),
|
||||
"path_filestat_set_times" => func!(path_filestat_set_times),
|
||||
"path_link" => func!(path_link),
|
||||
"path_open" => func!(path_open),
|
||||
"path_readlink" => func!(path_readlink),
|
||||
"path_remove_directory" => func!(path_remove_directory),
|
||||
"path_rename" => func!(path_rename),
|
||||
"path_symlink" => func!(path_symlink),
|
||||
"path_unlink_file" => func!(path_unlink_file),
|
||||
"poll_oneoff" => func!(poll_oneoff),
|
||||
"proc_exit" => func!(proc_exit),
|
||||
"proc_raise" => func!(proc_raise),
|
||||
"random_get" => func!(random_get),
|
||||
"sched_yield" => func!(sched_yield),
|
||||
"sock_recv" => func!(sock_recv),
|
||||
"sock_send" => func!(sock_send),
|
||||
"sock_shutdown" => func!(sock_shutdown),
|
||||
},
|
||||
|
||||
generate_import_object_snapshot1_inner(state_gen)
|
||||
}
|
||||
|
||||
/// Create an [`ImportObject`] with an existing [`WasiState`]. [`WasiState`]
|
||||
/// can be constructed from a [`WasiStateBuilder`].
|
||||
pub fn generate_import_object_from_state(
|
||||
wasi_state: WasiState,
|
||||
version: WasiVersion,
|
||||
) -> ImportObject {
|
||||
// HACK(mark): this is really quite nasty and inefficient, a proper fix will
|
||||
// require substantial changes to the internals of the WasiFS
|
||||
// copy WasiState by serializing and deserializing
|
||||
let wasi_state_bytes = wasi_state.freeze().unwrap();
|
||||
let state_gen = move || {
|
||||
fn state_destructor(data: *mut c_void) {
|
||||
unsafe {
|
||||
drop(Box::from_raw(data as *mut WasiState));
|
||||
}
|
||||
}
|
||||
|
||||
let wasi_state = Box::new(WasiState::unfreeze(&wasi_state_bytes).unwrap());
|
||||
|
||||
(
|
||||
Box::into_raw(wasi_state) as *mut c_void,
|
||||
state_destructor as fn(*mut c_void),
|
||||
)
|
||||
};
|
||||
match version {
|
||||
WasiVersion::Snapshot0 => generate_import_object_snapshot0_inner(state_gen),
|
||||
WasiVersion::Snapshot1 | WasiVersion::Latest => {
|
||||
generate_import_object_snapshot1_inner(state_gen)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/// Creates a Wasi [`ImportObject`] with [`WasiState`] for the given [`WasiVersion`].
|
||||
pub fn generate_import_object_for_version(
|
||||
@ -273,8 +159,15 @@ fn generate_import_object_snapshot0(
|
||||
state_destructor as fn(*mut c_void),
|
||||
)
|
||||
};
|
||||
generate_import_object_snapshot0_inner(state_gen)
|
||||
}
|
||||
|
||||
/// Combines a state generating function with the import list for legacy WASI
|
||||
fn generate_import_object_snapshot0_inner<F>(state_gen: F) -> ImportObject
|
||||
where
|
||||
F: Fn() -> (*mut c_void, fn(*mut c_void)) + Send + Sync + 'static,
|
||||
{
|
||||
imports! {
|
||||
// This generates the wasi state.
|
||||
state_gen,
|
||||
"wasi_unstable" => {
|
||||
"args_get" => func!(args_get),
|
||||
@ -325,3 +218,60 @@ fn generate_import_object_snapshot0(
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Combines a state generating function with the import list for snapshot 1
|
||||
fn generate_import_object_snapshot1_inner<F>(state_gen: F) -> ImportObject
|
||||
where
|
||||
F: Fn() -> (*mut c_void, fn(*mut c_void)) + Send + Sync + 'static,
|
||||
{
|
||||
imports! {
|
||||
state_gen,
|
||||
"wasi_snapshot_preview1" => {
|
||||
"args_get" => func!(args_get),
|
||||
"args_sizes_get" => func!(args_sizes_get),
|
||||
"clock_res_get" => func!(clock_res_get),
|
||||
"clock_time_get" => func!(clock_time_get),
|
||||
"environ_get" => func!(environ_get),
|
||||
"environ_sizes_get" => func!(environ_sizes_get),
|
||||
"fd_advise" => func!(fd_advise),
|
||||
"fd_allocate" => func!(fd_allocate),
|
||||
"fd_close" => func!(fd_close),
|
||||
"fd_datasync" => func!(fd_datasync),
|
||||
"fd_fdstat_get" => func!(fd_fdstat_get),
|
||||
"fd_fdstat_set_flags" => func!(fd_fdstat_set_flags),
|
||||
"fd_fdstat_set_rights" => func!(fd_fdstat_set_rights),
|
||||
"fd_filestat_get" => func!(fd_filestat_get),
|
||||
"fd_filestat_set_size" => func!(fd_filestat_set_size),
|
||||
"fd_filestat_set_times" => func!(fd_filestat_set_times),
|
||||
"fd_pread" => func!(fd_pread),
|
||||
"fd_prestat_get" => func!(fd_prestat_get),
|
||||
"fd_prestat_dir_name" => func!(fd_prestat_dir_name),
|
||||
"fd_pwrite" => func!(fd_pwrite),
|
||||
"fd_read" => func!(fd_read),
|
||||
"fd_readdir" => func!(fd_readdir),
|
||||
"fd_renumber" => func!(fd_renumber),
|
||||
"fd_seek" => func!(fd_seek),
|
||||
"fd_sync" => func!(fd_sync),
|
||||
"fd_tell" => func!(fd_tell),
|
||||
"fd_write" => func!(fd_write),
|
||||
"path_create_directory" => func!(path_create_directory),
|
||||
"path_filestat_get" => func!(path_filestat_get),
|
||||
"path_filestat_set_times" => func!(path_filestat_set_times),
|
||||
"path_link" => func!(path_link),
|
||||
"path_open" => func!(path_open),
|
||||
"path_readlink" => func!(path_readlink),
|
||||
"path_remove_directory" => func!(path_remove_directory),
|
||||
"path_rename" => func!(path_rename),
|
||||
"path_symlink" => func!(path_symlink),
|
||||
"path_unlink_file" => func!(path_unlink_file),
|
||||
"poll_oneoff" => func!(poll_oneoff),
|
||||
"proc_exit" => func!(proc_exit),
|
||||
"proc_raise" => func!(proc_raise),
|
||||
"random_get" => func!(random_get),
|
||||
"sched_yield" => func!(sched_yield),
|
||||
"sock_recv" => func!(sock_recv),
|
||||
"sock_send" => func!(sock_send),
|
||||
"sock_shutdown" => func!(sock_shutdown),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user