Merge pull request #3010 from alexcrichton/fix-dylib

Connect helper C symbols to their static library
This commit is contained in:
Chris Fallin
2021-06-21 08:54:33 -07:00
committed by GitHub
6 changed files with 15 additions and 14 deletions

View File

@@ -9,5 +9,5 @@ fn main() {
None, None,
) )
.file("src/helpers.c") .file("src/helpers.c")
.compile("helpers"); .compile("wasmtime-helpers");
} }

View File

@@ -14,7 +14,7 @@
#define platform_jmp_buf sigjmp_buf #define platform_jmp_buf sigjmp_buf
#endif #endif
int RegisterSetjmp( int wasmtime_setjmp(
void **buf_storage, void **buf_storage,
void (*body)(void*, void*), void (*body)(void*, void*),
void *payload, void *payload,
@@ -28,7 +28,7 @@ int RegisterSetjmp(
return 1; return 1;
} }
void Unwind(void *JmpBuf) { void wasmtime_longjmp(void *JmpBuf) {
platform_jmp_buf *buf = (platform_jmp_buf*) JmpBuf; platform_jmp_buf *buf = (platform_jmp_buf*) JmpBuf;
platform_longjmp(*buf, 1); platform_longjmp(*buf, 1);
} }

View File

@@ -14,15 +14,16 @@ use wasmtime_environ::ir;
pub use self::tls::{tls_eager_initialize, TlsRestore}; pub use self::tls::{tls_eager_initialize, TlsRestore};
#[link(name = "wasmtime-helpers")]
extern "C" { extern "C" {
#[allow(improper_ctypes)] #[allow(improper_ctypes)]
fn RegisterSetjmp( fn wasmtime_setjmp(
jmp_buf: *mut *const u8, jmp_buf: *mut *const u8,
callback: extern "C" fn(*mut u8, *mut VMContext), callback: extern "C" fn(*mut u8, *mut VMContext),
payload: *mut u8, payload: *mut u8,
callee: *mut VMContext, callee: *mut VMContext,
) -> i32; ) -> i32;
fn Unwind(jmp_buf: *const u8) -> !; fn wasmtime_longjmp(jmp_buf: *const u8) -> !;
} }
cfg_if::cfg_if! { cfg_if::cfg_if! {
@@ -177,7 +178,7 @@ where
F: FnMut(*mut VMContext), F: FnMut(*mut VMContext),
{ {
return CallThreadState::new(signal_handler).with(vminterrupts, |cx| { return CallThreadState::new(signal_handler).with(vminterrupts, |cx| {
RegisterSetjmp( wasmtime_setjmp(
cx.jmp_buf.as_ptr(), cx.jmp_buf.as_ptr(),
call_closure::<F>, call_closure::<F>,
&mut closure as *mut F as *mut u8, &mut closure as *mut F as *mut u8,
@@ -251,7 +252,7 @@ impl CallThreadState {
fn unwind_with(&self, reason: UnwindReason) -> ! { fn unwind_with(&self, reason: UnwindReason) -> ! {
unsafe { unsafe {
(*self.unwind.get()).as_mut_ptr().write(reason); (*self.unwind.get()).as_mut_ptr().write(reason);
Unwind(self.jmp_buf.get()); wasmtime_longjmp(self.jmp_buf.get());
} }
} }
@@ -306,7 +307,7 @@ impl CallThreadState {
} }
// If all that passed then this is indeed a wasm trap, so return the // If all that passed then this is indeed a wasm trap, so return the
// `jmp_buf` passed to `Unwind` to resume. // `jmp_buf` passed to `wasmtime_longjmp` to resume.
self.jmp_buf.get() self.jmp_buf.get()
} }

View File

@@ -33,7 +33,7 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
use crate::traphandlers::{tls, Trap, Unwind}; use crate::traphandlers::{tls, wasmtime_longjmp, Trap};
use mach::exception_types::*; use mach::exception_types::*;
use mach::kern_return::*; use mach::kern_return::*;
use mach::mach_init::*; use mach::mach_init::*;
@@ -389,7 +389,7 @@ unsafe extern "C" fn unwind(wasm_pc: *const u8) -> ! {
state.jmp_buf.get() state.jmp_buf.get()
}); });
debug_assert!(!jmp_buf.is_null()); debug_assert!(!jmp_buf.is_null());
Unwind(jmp_buf); wasmtime_longjmp(jmp_buf);
} }
thread_local! { thread_local! {

View File

@@ -1,4 +1,4 @@
use crate::traphandlers::{tls, Trap, Unwind}; use crate::traphandlers::{tls, wasmtime_longjmp, Trap};
use std::cell::RefCell; use std::cell::RefCell;
use std::convert::TryInto; use std::convert::TryInto;
use std::io; use std::io;
@@ -99,7 +99,7 @@ unsafe extern "C" fn trap_handler(
return true; return true;
} }
info.capture_backtrace(pc); info.capture_backtrace(pc);
Unwind(jmp_buf) wasmtime_longjmp(jmp_buf)
}); });
if handled { if handled {

View File

@@ -1,4 +1,4 @@
use crate::traphandlers::{tls, Trap, Unwind}; use crate::traphandlers::{tls, wasmtime_longjmp, Trap};
use std::io; use std::io;
use winapi::um::errhandlingapi::*; use winapi::um::errhandlingapi::*;
use winapi::um::minwinbase::*; use winapi::um::minwinbase::*;
@@ -69,7 +69,7 @@ unsafe extern "system" fn exception_handler(exception_info: PEXCEPTION_POINTERS)
EXCEPTION_CONTINUE_EXECUTION EXCEPTION_CONTINUE_EXECUTION
} else { } else {
info.capture_backtrace(ip); info.capture_backtrace(ip);
Unwind(jmp_buf) wasmtime_longjmp(jmp_buf)
} }
}) })
} }