Skip to content
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

wasmtime: Remove GET_WASM_TRAP indirection #8949

Merged
merged 1 commit into from
Jul 15, 2024

Conversation

jameysharp
Copy link
Contributor

In the past, the wasmtime-runtime crate couldn't directly call get_wasm_trap because the registry of loaded modules was in the wasmtime crate, so it called through a global function pointer registered with init_traps instead.

Since the two crates were merged in #8501, we no longer need this indirection.

While I'm here, I've also split the former get_wasm_trap function into two parts: lookup_code finds a loaded module that had been previously registered with register_code, and the lookup_trap_code step is now done by a helper on CodeMemory. This makes the module registry more broadly useful.

I also simplified the code lookup step in two ways:

  • I removed a redundant check from the code lookup. BTreeMap::range will only return entries where end >= pc, so the end < pc condition is always false.
  • I used checked_sub instead of writing both the comparison and subtraction explicitly.

@jameysharp jameysharp requested a review from fitzgen July 12, 2024 23:22
@jameysharp jameysharp requested a review from a team as a code owner July 12, 2024 23:22
In the past, the wasmtime-runtime crate couldn't directly call
`get_wasm_trap` because the registry of loaded modules was in the
wasmtime crate, so it called through a global function pointer
registered with `init_traps` instead.

Since the two crates were merged in bytecodealliance#8501, we no longer need this
indirection.

While I'm here, I've also split the former `get_wasm_trap` function into
two parts: `lookup_code` finds a loaded module that had been previously
registered with `register_code`, and the `lookup_trap_code` step is now
done by a helper on `CodeMemory`. This makes the module registry more
broadly useful.

I also simplified the code lookup step in two ways:
- I removed a redundant check from the code lookup. `BTreeMap::range`
  will only return entries where `end >= pc`, so the `end < pc`
  condition is always false.
- I used checked_sub instead of writing both the comparison and
  subtraction explicitly.
@jameysharp jameysharp force-pushed the inline-get-wasm-trap branch from aad8d67 to 80114dd Compare July 12, 2024 23:30
@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Jul 13, 2024
@alexcrichton alexcrichton added this pull request to the merge queue Jul 15, 2024
Merged via the queue into bytecodealliance:main with commit 66dfa36 Jul 15, 2024
37 checks passed
@jameysharp jameysharp deleted the inline-get-wasm-trap branch July 15, 2024 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:api Related to the API of the `wasmtime` crate itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants