Skip to content

Commit 952309a

Browse files
authored
Merge branch 'master' into feature/llvm-on-arm
2 parents b84ff0e + 17aecf9 commit 952309a

File tree

23 files changed

+933
-439
lines changed

23 files changed

+933
-439
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
## **[Unreleased]**
44

5+
- [#1060](https://github.com/wasmerio/wasmer/pull/1060) Test the capi with all the backends
6+
- [#1058](https://github.com/wasmerio/wasmer/pull/1058) Fix minor panic issue when `wasmer::compile_with` called with llvm backend.
7+
- [#858](https://github.com/wasmerio/wasmer/pull/858) Minor panic fix when wasmer binary with `loader` option run a module without exported `_start` function.
8+
- [#1056](https://github.com/wasmerio/wasmer/pull/1056) Improved `--invoke` args parsing (supporting `i32`, `i64`, `f32` and `f32`) in Wasmer CLI
9+
- [#1054](https://github.com/wasmerio/wasmer/pull/1054) Improve `--invoke` output in Wasmer CLI
10+
- [#1053](https://github.com/wasmerio/wasmer/pull/1053) For RuntimeError and breakpoints, use Box<Any + Send> instead of Box<Any>.
11+
- [#1052](https://github.com/wasmerio/wasmer/pull/1052) Fix minor panic and improve Error handling in singlepass backend.
12+
- [#1050](https://github.com/wasmerio/wasmer/pull/1050) Attach C & C++ headers to releases.
513
- [#1033](https://github.com/wasmerio/wasmer/pull/1033) Set cranelift backend as default compiler backend again, require at least one backend to be enabled for Wasmer CLI
614
- [#1044](https://github.com/wasmerio/wasmer/pull/1044) Enable AArch64 support in the LLVM backend.
715
- [#1030](https://github.com/wasmerio/wasmer/pull/1030) Ability to generate `ImportObject` for a specific version WASI version with the C API.

Cargo.lock

+58-58
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

+27-5
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,34 @@ llvm: spectests-llvm emtests-llvm wasitests-llvm
102102

103103

104104
# All tests
105-
capi:
106-
cargo build --release --features backend-cranelift
107-
cargo build -p wasmer-runtime-c-api --release
105+
capi-singlepass:
106+
cargo build --manifest-path lib/runtime-c-api/Cargo.toml --release \
107+
--no-default-features --features singlepass-backend,wasi
108+
109+
capi-cranelift:
110+
cargo build --manifest-path lib/runtime-c-api/Cargo.toml --release \
111+
--no-default-features --features cranelift-backend,wasi
112+
113+
capi-llvm:
114+
cargo build --manifest-path lib/runtime-c-api/Cargo.toml --release \
115+
--no-default-features --features llvm-backend,wasi
116+
117+
# We use cranelift as the default backend for the capi for now
118+
capi: capi-cranelift
119+
120+
test-capi-singlepass: capi-singlepass
121+
cargo test --manifest-path lib/runtime-c-api/Cargo.toml --release \
122+
--no-default-features --features singlepass-backend,wasi
123+
124+
test-capi-cranelift: capi-cranelift
125+
cargo test --manifest-path lib/runtime-c-api/Cargo.toml --release \
126+
--no-default-features --features cranelift-backend,wasi
127+
128+
test-capi-llvm: capi-llvm
129+
cargo test --manifest-path lib/runtime-c-api/Cargo.toml --release \
130+
--no-default-features --features llvm-backend,wasi
108131

109-
test-capi: capi
110-
cargo test -p wasmer-runtime-c-api --release
132+
test-capi: test-capi-singlepass test-capi-cranelift test-capi-llvm
111133

112134
capi-test: test-capi
113135

azure-pipelines.yml

+6-5
Original file line numberDiff line numberDiff line change
@@ -180,29 +180,30 @@ jobs:
180180
- checkout: self
181181
submodules: true
182182
- template: .azure/install-rust.yml
183-
# - template: .azure/install-llvm.yml
183+
- template: .azure/install-llvm.yml
184184
- template: .azure/install-sccache.yml
185185
- template: .azure/install-cmake.yml
186186
- bash: |
187187
mkdir -p artifacts
188188
displayName: Create Artifacts Dir
189189
- bash: |
190-
make capi
191190
make test-capi
191+
displayName: Test c-api
192+
condition: and(succeeded(), not(eq(variables['Agent.OS'], 'Windows_NT')))
193+
- bash: |
194+
make capi
192195
cp target/release/libwasmer_runtime_c_api.so ./artifacts
196+
find target/release/build -name 'wasmer.h*' -exec cp {} ./artifacts ';'
193197
displayName: Build c-api (Linux)
194198
condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))
195199
- bash: |
196200
make capi
197-
make test-capi
198201
install_name_tool -id "@rpath/libwasmer_runtime_c_api.dylib" target/release/libwasmer_runtime_c_api.dylib
199202
cp target/release/libwasmer_runtime_c_api.dylib ./artifacts
200203
displayName: Build c-api (Darwin)
201204
condition: and(succeeded(), eq(variables['Agent.OS'], 'Darwin'))
202205
- bash: |
203206
make capi
204-
# Tests are failing on Windows, comment for now
205-
# make test-capi
206207
cp target/release/wasmer_runtime_c_api.dll ./artifacts
207208
displayName: Build c-api (Windows)
208209
condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT'))

bors.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
status = [
2-
"wasmerio.wasmer"
2+
"wasmerio.wasmer",
3+
"continuous-integration/travis-ci/push"
34
]
45
required_approvals = 1
56
timeout_sec = 7200

lib/clif-backend/src/signal/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ pub use self::unix::*;
2626
pub use self::windows::*;
2727

2828
thread_local! {
29-
pub static TRAP_EARLY_DATA: Cell<Option<Box<dyn Any>>> = Cell::new(None);
29+
pub static TRAP_EARLY_DATA: Cell<Option<Box<dyn Any + Send>>> = Cell::new(None);
3030
}
3131

3232
pub enum CallProtError {
3333
Trap(WasmTrapInfo),
34-
Error(Box<dyn Any>),
34+
Error(Box<dyn Any + Send>),
3535
}
3636

3737
pub struct Caller {
@@ -67,7 +67,7 @@ impl RunnableModule for Caller {
6767
args: *const u64,
6868
rets: *mut u64,
6969
trap_info: *mut WasmTrapInfo,
70-
user_error: *mut Option<Box<dyn Any>>,
70+
user_error: *mut Option<Box<dyn Any + Send>>,
7171
invoke_env: Option<NonNull<c_void>>,
7272
) -> bool {
7373
let handler_data = &*invoke_env.unwrap().cast().as_ptr();
@@ -108,7 +108,7 @@ impl RunnableModule for Caller {
108108
})
109109
}
110110

111-
unsafe fn do_early_trap(&self, data: Box<dyn Any>) -> ! {
111+
unsafe fn do_early_trap(&self, data: Box<dyn Any + Send>) -> ! {
112112
TRAP_EARLY_DATA.with(|cell| cell.set(Some(data)));
113113
trigger_trap()
114114
}

lib/llvm-backend/src/backend.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extern "C" {
6666
params: *const u64,
6767
results: *mut u64,
6868
trap_out: *mut WasmTrapInfo,
69-
user_error: *mut Option<Box<dyn Any>>,
69+
user_error: *mut Option<Box<dyn Any + Send>>,
7070
invoke_env: Option<NonNull<c_void>>,
7171
) -> bool;
7272
}
@@ -427,7 +427,7 @@ impl RunnableModule for LLVMBackend {
427427
self.msm.clone()
428428
}
429429

430-
unsafe fn do_early_trap(&self, data: Box<dyn Any>) -> ! {
430+
unsafe fn do_early_trap(&self, data: Box<dyn Any + Send>) -> ! {
431431
throw_any(Box::leak(data))
432432
}
433433
}

lib/llvm-backend/src/code.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,8 @@ pub unsafe extern "C" fn callback_trampoline(
856856
callback: *mut BreakpointHandler,
857857
) {
858858
let callback = Box::from_raw(callback);
859-
let result: Result<(), Box<dyn std::any::Any>> = callback(BreakpointInfo { fault: None });
859+
let result: Result<(), Box<dyn std::any::Any + Send>> =
860+
callback(BreakpointInfo { fault: None });
860861
match result {
861862
Ok(()) => *b = None,
862863
Err(e) => *b = Some(e),

lib/llvm-backend/src/state.rs

+34-31
Original file line numberDiff line numberDiff line change
@@ -231,33 +231,41 @@ impl<'ctx> State<'ctx> {
231231

232232
pub fn outermost_frame(&self) -> Result<&ControlFrame<'ctx>, BinaryReaderError> {
233233
self.control_stack.get(0).ok_or(BinaryReaderError {
234-
message: "invalid control stack depth",
234+
message: "outermost_frame: invalid control stack depth",
235235
offset: -1isize as usize,
236236
})
237237
}
238238

239239
pub fn frame_at_depth(&self, depth: u32) -> Result<&ControlFrame<'ctx>, BinaryReaderError> {
240-
let index = self.control_stack.len() - 1 - (depth as usize);
241-
self.control_stack.get(index).ok_or(BinaryReaderError {
242-
message: "invalid control stack depth",
243-
offset: -1isize as usize,
244-
})
240+
let index = self
241+
.control_stack
242+
.len()
243+
.checked_sub(1 + (depth as usize))
244+
.ok_or(BinaryReaderError {
245+
message: "frame_at_depth: invalid control stack depth",
246+
offset: -1isize as usize,
247+
})?;
248+
Ok(&self.control_stack[index])
245249
}
246250

247251
pub fn frame_at_depth_mut(
248252
&mut self,
249253
depth: u32,
250254
) -> Result<&mut ControlFrame<'ctx>, BinaryReaderError> {
251-
let index = self.control_stack.len() - 1 - (depth as usize);
252-
self.control_stack.get_mut(index).ok_or(BinaryReaderError {
253-
message: "invalid control stack depth",
254-
offset: -1isize as usize,
255-
})
255+
let index = self
256+
.control_stack
257+
.len()
258+
.checked_sub(1 + (depth as usize))
259+
.ok_or(BinaryReaderError {
260+
message: "frame_at_depth_mut: invalid control stack depth",
261+
offset: -1isize as usize,
262+
})?;
263+
Ok(&mut self.control_stack[index])
256264
}
257265

258266
pub fn pop_frame(&mut self) -> Result<ControlFrame<'ctx>, BinaryReaderError> {
259267
self.control_stack.pop().ok_or(BinaryReaderError {
260-
message: "cannot pop from control stack",
268+
message: "pop_frame: cannot pop from control stack",
261269
offset: -1isize as usize,
262270
})
263271
}
@@ -283,7 +291,7 @@ impl<'ctx> State<'ctx> {
283291

284292
pub fn pop1_extra(&mut self) -> Result<(BasicValueEnum<'ctx>, ExtraInfo), BinaryReaderError> {
285293
self.stack.pop().ok_or(BinaryReaderError {
286-
message: "invalid value stack",
294+
message: "pop1_extra: invalid value stack",
287295
offset: -1isize as usize,
288296
})
289297
}
@@ -327,13 +335,11 @@ impl<'ctx> State<'ctx> {
327335
}
328336

329337
pub fn peek1_extra(&self) -> Result<(BasicValueEnum<'ctx>, ExtraInfo), BinaryReaderError> {
330-
self.stack
331-
.get(self.stack.len() - 1)
332-
.ok_or(BinaryReaderError {
333-
message: "invalid value stack",
334-
offset: -1isize as usize,
335-
})
336-
.map(|v| *v)
338+
let index = self.stack.len().checked_sub(1).ok_or(BinaryReaderError {
339+
message: "peek1_extra: invalid value stack",
340+
offset: -1isize as usize,
341+
})?;
342+
Ok(self.stack[index])
337343
}
338344

339345
pub fn peekn(&self, n: usize) -> Result<Vec<BasicValueEnum<'ctx>>, BinaryReaderError> {
@@ -344,12 +350,12 @@ impl<'ctx> State<'ctx> {
344350
&self,
345351
n: usize,
346352
) -> Result<&[(BasicValueEnum<'ctx>, ExtraInfo)], BinaryReaderError> {
347-
let new_len = self.stack.len().checked_sub(n).ok_or(BinaryReaderError {
348-
message: "invalid value stack",
353+
let index = self.stack.len().checked_sub(n).ok_or(BinaryReaderError {
354+
message: "peekn_extra: invalid value stack",
349355
offset: -1isize as usize,
350356
})?;
351357

352-
Ok(&self.stack[new_len..])
358+
Ok(&self.stack[index..])
353359
}
354360

355361
pub fn popn_save_extra(
@@ -362,15 +368,12 @@ impl<'ctx> State<'ctx> {
362368
}
363369

364370
pub fn popn(&mut self, n: usize) -> Result<(), BinaryReaderError> {
365-
if self.stack.len() < n {
366-
return Err(BinaryReaderError {
367-
message: "invalid value stack",
368-
offset: -1isize as usize,
369-
});
370-
}
371+
let index = self.stack.len().checked_sub(n).ok_or(BinaryReaderError {
372+
message: "popn: invalid value stack",
373+
offset: -1isize as usize,
374+
})?;
371375

372-
let new_len = self.stack.len() - n;
373-
self.stack.truncate(new_len);
376+
self.stack.truncate(index);
374377
Ok(())
375378
}
376379

lib/runtime-c-api/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ optional = true
3535
[features]
3636
default = ["cranelift-backend", "wasi"]
3737
debug = ["wasmer-runtime/debug"]
38+
singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass"]
3839
cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift"]
3940
llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm"]
40-
singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass"]
4141
wasi = ["wasmer-wasi"]
4242

4343
[build-dependencies]

lib/runtime-core/src/backend.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ pub trait RunnableModule: Send + Sync {
271271
/// signature and an invoke function that can call the trampoline.
272272
fn get_trampoline(&self, info: &ModuleInfo, sig_index: SigIndex) -> Option<Wasm>;
273273

274-
unsafe fn do_early_trap(&self, data: Box<dyn Any>) -> !;
274+
unsafe fn do_early_trap(&self, data: Box<dyn Any + Send>) -> !;
275275

276276
/// Returns the machine code associated with this module.
277277
fn get_code(&self) -> Option<&[u8]> {

lib/runtime-core/src/codegen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use wasmparser::{Operator, Type as WpType};
2323

2424
/// A type that defines a function pointer, which is called when breakpoints occur.
2525
pub type BreakpointHandler =
26-
Box<dyn Fn(BreakpointInfo) -> Result<(), Box<dyn Any>> + Send + Sync + 'static>;
26+
Box<dyn Fn(BreakpointInfo) -> Result<(), Box<dyn Any + Send>> + Send + Sync + 'static>;
2727

2828
/// Maps instruction pointers to their breakpoint handlers.
2929
pub type BreakpointMap = Arc<HashMap<usize, BreakpointHandler>>;

lib/runtime-core/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub enum RuntimeError {
187187
/// Error.
188188
Error {
189189
/// Error data.
190-
data: Box<dyn Any>,
190+
data: Box<dyn Any + Send>,
191191
},
192192
}
193193

lib/runtime-core/src/fault.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type SetJmpBuffer = [i32; SETJMP_BUFFER_LEN];
6161
struct UnwindInfo {
6262
jmpbuf: SetJmpBuffer, // in
6363
breakpoints: Option<BreakpointMap>,
64-
payload: Option<Box<dyn Any>>, // out
64+
payload: Option<Box<dyn Any + Send>>, // out
6565
}
6666

6767
/// A store for boundary register preservation.
@@ -182,7 +182,7 @@ pub unsafe fn clear_wasm_interrupt() {
182182
pub unsafe fn catch_unsafe_unwind<R, F: FnOnce() -> R>(
183183
f: F,
184184
breakpoints: Option<BreakpointMap>,
185-
) -> Result<R, Box<dyn Any>> {
185+
) -> Result<R, Box<dyn Any + Send>> {
186186
let unwind = UNWIND.with(|x| x.get());
187187
let old = (*unwind).take();
188188
*unwind = Some(UnwindInfo {
@@ -205,7 +205,7 @@ pub unsafe fn catch_unsafe_unwind<R, F: FnOnce() -> R>(
205205
}
206206

207207
/// Begins an unsafe unwind.
208-
pub unsafe fn begin_unsafe_unwind(e: Box<dyn Any>) -> ! {
208+
pub unsafe fn begin_unsafe_unwind(e: Box<dyn Any + Send>) -> ! {
209209
let unwind = UNWIND.with(|x| x.get());
210210
let inner = (*unwind)
211211
.as_mut()
@@ -283,7 +283,7 @@ extern "C" fn signal_trap_handler(
283283
static ARCH: Architecture = Architecture::Aarch64;
284284

285285
let mut should_unwind = false;
286-
let mut unwind_result: Box<dyn Any> = Box::new(());
286+
let mut unwind_result: Box<dyn Any + Send> = Box::new(());
287287

288288
unsafe {
289289
let fault = get_fault_info(siginfo as _, ucontext);
@@ -307,7 +307,7 @@ extern "C" fn signal_trap_handler(
307307
match ib.ty {
308308
InlineBreakpointType::Trace => {}
309309
InlineBreakpointType::Middleware => {
310-
let out: Option<Result<(), Box<dyn Any>>> =
310+
let out: Option<Result<(), Box<dyn Any + Send>>> =
311311
with_breakpoint_map(|bkpt_map| {
312312
bkpt_map.and_then(|x| x.get(&ip)).map(|x| {
313313
x(BreakpointInfo {
@@ -348,13 +348,14 @@ extern "C" fn signal_trap_handler(
348348
match Signal::from_c_int(signum) {
349349
Ok(SIGTRAP) => {
350350
// breakpoint
351-
let out: Option<Result<(), Box<dyn Any>>> = with_breakpoint_map(|bkpt_map| {
352-
bkpt_map.and_then(|x| x.get(&(fault.ip.get()))).map(|x| {
353-
x(BreakpointInfo {
354-
fault: Some(&fault),
351+
let out: Option<Result<(), Box<dyn Any + Send>>> =
352+
with_breakpoint_map(|bkpt_map| {
353+
bkpt_map.and_then(|x| x.get(&(fault.ip.get()))).map(|x| {
354+
x(BreakpointInfo {
355+
fault: Some(&fault),
356+
})
355357
})
356-
})
357-
});
358+
});
358359
match out {
359360
Some(Ok(())) => {
360361
return false;

lib/runtime-core/src/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ pub mod x64 {
652652
image: InstanceImage,
653653
vmctx: &mut Ctx,
654654
breakpoints: Option<BreakpointMap>,
655-
) -> Result<u64, Box<dyn Any>> {
655+
) -> Result<u64, Box<dyn Any + Send>> {
656656
let mut stack: Vec<u64> = vec![0; 1048576 * 8 / 8]; // 8MB stack
657657
let mut stack_offset: usize = stack.len();
658658

0 commit comments

Comments
 (0)