1262: Update to latest inkwell which adds context lifetime to basic blocks. r=nlewycky a=nlewycky
The latest inkwell adds lifetimes to basic blocks and also changes most APIs to pass them without reference.
Co-authored-by: Nick Lewycky <nick@wasmer.io>
1272: Fix WasmPtr to work with accesses accessing the final valid byte r=MarkMcCaskey a=MarkMcCaskey
Resolves#1258
The fix was to change `>=` into `>`. Doing this made us vulnerable to accessing memory to create an empty slice just out of bounds so we have to add some additional checks to make sure that that can't happen.
This PR also prevents accessing arrays of length 0 (the length bound is non-inclusive, so length 0 is never valid) and prevents access of zero-sized types.
The zero-sized type checks will probably be inlined (or will be in the future as `const fn` gets more mature) so provide no additional overhead. The checking of if length == 0 does add some overhead, but on modern CPUs it shouldn't be an issue as it's a branch that should be always false in normal use.
# Review
- [x] Add a short description of the the change to the CHANGELOG.md file
Co-authored-by: Mark McCaskey <mark@wasmer.io>
This also returns `None` for all accesses of zero sized types and
arrays of length 0. Because the array accesses have a non-inclusive
length, length of 0 is not valid. These checks prevent returning
empty slices that point just outside of memory bounds.
1268: Prepare for 0.15.0 release r=MarkMcCaskey a=MarkMcCaskey
# Review
- [x] Add a short description of the the change to the CHANGELOG.md file
Co-authored-by: Mark McCaskey <mark@wasmer.io>
1267: Improve support for preopened directories in WASI syscalls r=MarkMcCaskey a=MarkMcCaskey
Ported over from #1263
# Description
<!--
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->
# Review
- [x] Add a short description of the the change to the CHANGELOG.md file
Co-authored-by: Mark McCaskey <mark@wasmer.io>
1264: feat(interface-types) Implement lifting and lowering instructions r=Hywan a=Hywan
For the moment, WIT defines [a bunch of lifting and lowering instructions](https://github.com/WebAssembly/interface-types/blob/master/proposals/interface-types/working-notes/instr.md). The encoders, the decoders and the AST support them, but we didn't have any instruction implementations for them. This PR implements the instructions for real.
To handle casting failure, I decided to use the `TryFrom` trait, instead of `as`, such as:
```rust
let x: i32 = 128;
let y: i8 = x.try_into().unwrap(); // fails
```
while:
```rust
let x: i32 = 128;
let y: i8 = x as _; // just overflows silently
```
Not all `*x` instructions aren't implement _yet_.
Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
1265: Improve `WasmPtr` documentation r=MarkMcCaskey a=MarkMcCaskey
This came up multiple times when responding to people on our issue tracker.
Adds an example and a lot more information about `WasmPtr` and `ValueType`
Co-authored-by: Mark McCaskey <mark@wasmer.io>
1217: Polymorphic host functions based on dynamic trampoline generation. r=losfair a=losfair
This PR implements polymorphic host functions by dynamically generating the "glue" code that translates platform arguments to an array in `runtime-core`.
TODO:
- ~~Multiple return values.~~ Deferring to a future multivalue PR.
- [x] Dynamic signatures for polymorphic functions.
- [x] Use a proper executable memory allocator.
Co-authored-by: losfair <zhy20000919@hotmail.com>
Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
Co-authored-by: Heyang Zhou <zhy20000919@hotmail.com>
1261: Fix our side of wasmparser typo. r=MarkMcCaskey a=nlewycky
This is a `cargo update` plus change to fix for ac6df05378 .
Co-authored-by: Nick Lewycky <nick@wasmer.io>
1212: Add support for GDB JIT debugging r=MarkMcCaskey a=MarkMcCaskey
This PR adds support for JIT debugging to Wasmer with the Cranelift backend using a fork of `wasmtime-debug`.
The motivation for this change is partially inspired by the feature in Wasmtime and the implementation is largely derived from Wasmtime's `wasmtime-debug` crate and not included in this PR. This implementation is currently Cranelift-only (if LLVM has value tracking we can add this there too without too much effort; we'd have to do the value tracking ourselves in Singlepass and I don't have enough context to know how hard that would be) and is based on a generic fork of the `wasmtime-debug` -- which will be published and uploaded in another repo.
This PR started out implementing the [Wasm-DWARF](https://yurydelendik.github.io/webassembly-dwarf/) reading and writing with gimli but after working on it for a few days, reading a chunk of the DWARF spec, seeing that Wasmtime had solved this well, and realizing how long this would likely take, I decided that it didn't make sense to spend the engineering effort there so I made a copy of `wasmtime-debug` and removed some of the less portable Cranelift pieces (very minor changes) and all code relying on data structures from wasmtime. The resulting crate is completely generic and would work fine with Wasmtime or any other Wasm runtime at the cost of requiring some `transmute`s or a linear pass over the debug data to reconstruct it in terms of the new types exposed by the fork. Perhaps there's a cleaner way to handle that that I haven't considered.
The integration with the GDB JIT interface is from the LLVM examples (I don't remember if I properly attributed everything in this PR/version of the code -- I still have the other branches locally though which I'll review before shipping this) and some of the code in this PR is from Wasmtime/Cranelift source code such as the sorting of the `ebb`s in `clif_backend::resolver`. I spent a long time debugging some subtle bugs and ended up using a few things from Wasmtime's integration with `wasmtime-debug` and some bits from `cranelift-wasm` and `cranelift-codegen`.
If there's interest from other people in working on the generic `wasmtime-debug` fork, I'm happy to get other maintainers involved and/or move it to a shared organization.
Special thanks to [Yury Delendik](https://github.com/yurydelendik) and the other `wasmtime-debug` authors for their work on Wasm debugging. Also shout out to Cranelift for the nice API for tracking variables/data.
### TODO:
- [x] Update attributions file for LLVM, [wasm-dwarf](https://github.com/yurydelendik/wasm-dwarf), and Wasmtime/Cranelift and do another pass over code to make sure we're in compliance with the licenses from the relevant projects and have properly attributed the code used from other projects.
- [x] Adjust API of wasm-debug based on feedback
- [x] Discuss with Nick integration with LLVM
- [x] Discuss with Heyang integration with Singlepass
- [x] Adjust implementation based on feedback from team (traits modified, etc.)
- [x] Clean up some pointer wrangling code
- [x] Add opt-in feature to wasmer-runtime-core to enale wasm-debug so library users who won't use debug info are not affected
# Review
- [x] Add a short description of the the change to the CHANGELOG.md file
Co-authored-by: Mark McCaskey <mark@wasmer.io>
Co-authored-by: Mark McCaskey <5770194+MarkMcCaskey@users.noreply.github.com>