-
Notifications
You must be signed in to change notification settings - Fork 1.6k
c-api: add wasmtime_trap_code #3086
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
Merged
alexcrichton
merged 1 commit into
bytecodealliance:main
from
srenatus:sr/c-api/add-trap-code-accessor
Jul 15, 2021
Merged
Changes from all commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| use crate::{wasm_frame_vec_t, wasm_instance_t, wasm_name_t, wasm_store_t}; | ||
| use once_cell::unsync::OnceCell; | ||
| use wasmtime::Trap; | ||
| use wasmtime::{Trap, TrapCode}; | ||
|
|
||
| #[repr(C)] | ||
| #[derive(Clone)] | ||
|
|
@@ -91,6 +91,30 @@ pub extern "C" fn wasm_trap_trace(raw: &wasm_trap_t, out: &mut wasm_frame_vec_t) | |
| out.set_buffer(vec); | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| pub extern "C" fn wasmtime_trap_code(raw: &wasm_trap_t, code: &mut i32) -> bool { | ||
| match raw.trap.trap_code() { | ||
| Some(c) => { | ||
| *code = match c { | ||
| TrapCode::StackOverflow => 0, | ||
| TrapCode::MemoryOutOfBounds => 1, | ||
| TrapCode::HeapMisaligned => 2, | ||
| TrapCode::TableOutOfBounds => 3, | ||
| TrapCode::IndirectCallToNull => 4, | ||
| TrapCode::BadSignature => 5, | ||
| TrapCode::IntegerOverflow => 6, | ||
| TrapCode::IntegerDivisionByZero => 7, | ||
| TrapCode::BadConversionToInteger => 8, | ||
| TrapCode::UnreachableCodeReached => 9, | ||
| TrapCode::Interrupt => 10, | ||
| _ => unreachable!(), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you leave a comment near |
||
| }; | ||
| true | ||
| } | ||
| None => false, | ||
| } | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| pub extern "C" fn wasmtime_trap_exit_status(raw: &wasm_trap_t, status: &mut i32) -> bool { | ||
| match raw.trap.i32_exit_status() { | ||
|
|
||
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
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.
I think here it's ok to skip the
enum { .. }wrapper, and I think the value of each#defineconstant will need to be listed.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.
Oops, I had a bunch of
#defines first, then decided to model this after the config enums likewasmtime/crates/c-api/include/wasmtime/config.h
Lines 56 to 64 in 73fd702
...and didn't follow through properly 😬 I've updated the code using a proper enum instead of defines. What do you think?
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.
Eh I could go either way, I don't actually know enough about C to know whether these are really that different, and they feel like the same to me. I'm happy to defer to whichever you feel is more appropriate here!
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.
I'm not a C expert either -- it felt to be a tad more consistent going with the enum definition. Updated ✔️