-
Notifications
You must be signed in to change notification settings - Fork 406
Restore support for the wasm32-wasip2 target #4663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bjorn3
wants to merge
3
commits into
rust-lang:master
Choose a base branch
from
bjorn3:restore_wasi_support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+159
−4
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| use rustc_abi::CanonAbi; | ||
| use rustc_middle::ty::Ty; | ||
| use rustc_span::Symbol; | ||
| use rustc_target::callconv::FnAbi; | ||
|
|
||
| use crate::shims::alloc::EvalContextExt as _; | ||
| use crate::*; | ||
|
|
||
| pub fn is_dyn_sym(_name: &str) -> bool { | ||
| false | ||
| } | ||
|
|
||
| impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} | ||
| pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { | ||
| fn emulate_foreign_item_inner( | ||
| &mut self, | ||
| link_name: Symbol, | ||
| abi: &FnAbi<'tcx, Ty<'tcx>>, | ||
| args: &[OpTy<'tcx>], | ||
| dest: &MPlaceTy<'tcx>, | ||
| ) -> InterpResult<'tcx, EmulateItemResult> { | ||
| let this = self.eval_context_mut(); | ||
|
|
||
| let (interface, name) = if let Some((module, name)) = link_name.as_str().split_once("$$$") { | ||
| // According to the component model, the version should be matched as semver, but for | ||
| // simplicity we strip the version entirely for now. Once we support wasm-wasip3 it may | ||
| // become actually important to match on the version, but for now it shouldn't matter. | ||
| let (module, _version) = module | ||
| .split_once('@') | ||
| .ok_or_else(|| err_unsup_format!("module name {module} must contain a version"))?; | ||
| (Some(module), name) | ||
| } else { | ||
| // This item is provided by wasi-libc, not imported from the wasi runtime | ||
| (None, link_name.as_str()) | ||
| }; | ||
|
|
||
| match (interface, name) { | ||
| // Allocation | ||
| (None, "posix_memalign") => { | ||
| let [memptr, align, size] = | ||
| this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?; | ||
| let result = this.posix_memalign(memptr, align, size)?; | ||
| this.write_scalar(result, dest)?; | ||
| } | ||
| (None, "aligned_alloc") => { | ||
| let [align, size] = | ||
| this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?; | ||
| let res = this.aligned_alloc(align, size)?; | ||
| this.write_pointer(res, dest)?; | ||
| } | ||
|
|
||
| // Standard input/output | ||
| // FIXME: These shims are hacks that just get basic stdout/stderr working. We can't | ||
| // constrain them to "std" since std itself uses the wasi crate for this. | ||
| (Some("wasi:cli/stdout"), "get-stdout") => { | ||
| let [] = | ||
| this.check_shim_sig(shim_sig!(extern "C" fn() -> i32), link_name, abi, args)?; | ||
| this.write_scalar(Scalar::from_i32(1), dest)?; // POSIX FD number for stdout | ||
| } | ||
| (Some("wasi:cli/stderr"), "get-stderr") => { | ||
| let [] = | ||
| this.check_shim_sig(shim_sig!(extern "C" fn() -> i32), link_name, abi, args)?; | ||
| this.write_scalar(Scalar::from_i32(2), dest)?; // POSIX FD number for stderr | ||
| } | ||
| (Some("wasi:io/streams"), "[resource-drop]output-stream") => { | ||
| let [handle] = | ||
| this.check_shim_sig(shim_sig!(extern "C" fn(i32) -> ()), link_name, abi, args)?; | ||
| let handle = this.read_scalar(handle)?.to_i32()?; | ||
|
|
||
| if !(handle == 1 || handle == 2) { | ||
| throw_unsup_format!("wasm output-stream: unsupported handle"); | ||
| } | ||
| // We don't actually close these FDs, so this is a NOP. | ||
| } | ||
| (Some("wasi:io/streams"), "[method]output-stream.blocking-write-and-flush") => { | ||
| let [handle, buf, len, ret_area] = this.check_shim_sig( | ||
| shim_sig!(extern "C" fn(i32, *mut _, usize, *mut _) -> ()), | ||
| link_name, | ||
| abi, | ||
| args, | ||
| )?; | ||
| let handle = this.read_scalar(handle)?.to_i32()?; | ||
| let buf = this.read_pointer(buf)?; | ||
| let len = this.read_target_usize(len)?; | ||
| let ret_area = this.read_pointer(ret_area)?; | ||
|
|
||
| if len > 4096 { | ||
| throw_unsup_format!( | ||
| "wasm output-stream.blocking-write-and-flush: buffer too big" | ||
| ); | ||
| } | ||
| let len = usize::try_from(len).unwrap(); | ||
| let Some(fd) = this.machine.fds.get(handle) else { | ||
| throw_unsup_format!( | ||
| "wasm output-stream.blocking-write-and-flush: unsupported handle" | ||
| ); | ||
| }; | ||
| fd.write( | ||
| this.machine.communicate(), | ||
| buf, | ||
| len, | ||
| this, | ||
| callback!( | ||
| @capture<'tcx> { | ||
| len: usize, | ||
| ret_area: Pointer, | ||
| } | ||
| |this, result: Result<usize, IoError>| { | ||
| if !matches!(result, Ok(l) if l == len) { | ||
| throw_unsup_format!("wasm output-stream.blocking-write-and-flush: returning errors is not supported"); | ||
| } | ||
| // 0 in the first byte of the ret_area indicates success. | ||
| let ret = this.ptr_to_mplace(ret_area, this.machine.layouts.u8); | ||
| this.write_null(&ret)?; | ||
| interp_ok(()) | ||
| }), | ||
| )?; | ||
| } | ||
|
|
||
| _ => return interp_ok(EmulateItemResult::NotSupported), | ||
| } | ||
| interp_ok(EmulateItemResult::NeedsReturn) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pub mod foreign_items; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you willing to be listed as target maintainer for this?
I don't think I want to re-land this without a target maintainer.