-
Notifications
You must be signed in to change notification settings - Fork 831
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
Take into account requirements for "isolate" or single-threaded runtimes #5284
base: wasmer-5.1.0
Are you sure you want to change the base?
Changes from all commits
915252e
bf76d61
f4cd60b
4a564b1
86833eb
fe17f57
2218373
9221246
c04fffc
a352602
20c161a
cff7a39
5277d33
c64f421
c463031
1aaf081
89c4a4c
9038db9
c2815b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,6 +240,11 @@ impl crate::Engine { | |
_ => panic!("Not a `jsc` engine!"), | ||
} | ||
} | ||
|
||
/// Return true if [`self`] is an engine from the `jsc` runtime. | ||
pub fn is_jsc(&self) -> bool { | ||
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. Why does the js engine have a is_jsc method? 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. This is in |
||
matches!(self.rt, crate::RuntimeEngine::Jsc(_)) | ||
} | ||
} | ||
|
||
impl Into<crate::Engine> for Engine { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,13 @@ impl Function { | |
+ Send | ||
+ Sync, | ||
{ | ||
let mut store = store.as_store_mut(); | ||
let v8_store = store.inner.store.as_v8(); | ||
|
||
if v8_store.thread_id != std::thread::current().id() { | ||
panic!("Cannot create new function: current thread is different from the thread the store was created in!"); | ||
} | ||
|
||
let fn_ty: FunctionType = ty.into(); | ||
let params = fn_ty.params(); | ||
|
||
|
@@ -121,8 +128,7 @@ impl Function { | |
) | ||
}; | ||
|
||
let mut store = store.as_store_mut(); | ||
let inner = store.inner.store.as_v8().inner; | ||
let inner = v8_store.inner; | ||
|
||
let callback: CCallback = make_fn_callback(&func, param_types.len()); | ||
|
||
|
@@ -159,6 +165,13 @@ impl Function { | |
Args: WasmTypeList, | ||
Rets: WasmTypeList, | ||
{ | ||
let mut store = store.as_store_mut(); | ||
let v8_store = store.inner.store.as_v8(); | ||
|
||
if v8_store.thread_id != std::thread::current().id() { | ||
panic!("Cannot create new typed function: current thread is different from the thread the store was created in!"); | ||
} | ||
|
||
let mut param_types = Args::wasm_types() | ||
.into_iter() | ||
.map(|param| { | ||
|
@@ -190,11 +203,11 @@ impl Function { | |
let wasm_functype = | ||
unsafe { wasm_functype_new(&mut wasm_param_types, &mut wasm_result_types) }; | ||
|
||
let mut store = store.as_store_mut(); | ||
let inner = store.inner.store.as_v8().inner; | ||
let inner = v8_store.inner; | ||
|
||
let callback: CCallback = | ||
unsafe { std::mem::transmute(func.function_callback(crate::Runtime::V8).into_v8()) }; | ||
let callback: CCallback = unsafe { | ||
std::mem::transmute(func.function_callback(crate::RuntimeKind::V8).into_v8()) | ||
}; | ||
|
||
let mut callback_env: *mut FunctionCallbackEnv<'_, F> = | ||
Box::into_raw(Box::new(FunctionCallbackEnv { | ||
|
@@ -233,6 +246,13 @@ impl Function { | |
Rets: WasmTypeList, | ||
T: Send + 'static, | ||
{ | ||
let mut store = store.as_store_mut(); | ||
let v8_store = store.inner.store.as_v8(); | ||
|
||
if v8_store.thread_id != std::thread::current().id() { | ||
panic!("Cannot create new typed function with env: current thread is different from the thread the store was created in!"); | ||
} | ||
|
||
let mut param_types = Args::wasm_types() | ||
.into_iter() | ||
.map(|param| { | ||
|
@@ -268,11 +288,11 @@ impl Function { | |
) | ||
}; | ||
|
||
let mut store = store.as_store_mut(); | ||
let inner = store.inner.store.as_v8().inner; | ||
let inner = v8_store.inner; | ||
|
||
let callback: CCallback = | ||
unsafe { std::mem::transmute(func.function_callback(crate::Runtime::V8).into_v8()) }; | ||
let callback: CCallback = unsafe { | ||
std::mem::transmute(func.function_callback(crate::RuntimeKind::V8).into_v8()) | ||
}; | ||
|
||
let mut callback_env: *mut FunctionCallbackEnv<'_, F> = | ||
Box::into_raw(Box::new(FunctionCallbackEnv { | ||
|
@@ -300,7 +320,13 @@ impl Function { | |
} | ||
} | ||
|
||
pub fn ty(&self, _store: &impl AsStoreRef) -> FunctionType { | ||
pub fn ty(&self, store: &impl AsStoreRef) -> FunctionType { | ||
let store_ref = store.as_store_ref(); | ||
let v8_store = store_ref.inner.store.as_v8(); | ||
|
||
if v8_store.thread_id != std::thread::current().id() { | ||
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. This is used a lot... how about making it a method? |
||
panic!("Cannot get the function's type: current thread is different from the thread the store was created in!"); | ||
} | ||
let type_ = unsafe { wasm_func_type(self.handle) }; | ||
let params: *const wasm_valtype_vec_t = unsafe { wasm_functype_params(type_) }; | ||
let returns: *const wasm_valtype_vec_t = unsafe { wasm_functype_results(type_) }; | ||
|
@@ -341,6 +367,11 @@ impl Function { | |
params: &[Value], | ||
) -> Result<Box<[Value]>, RuntimeError> { | ||
let store_mut = store.as_store_mut(); | ||
let v8_store = store_mut.inner.store.as_v8(); | ||
|
||
if v8_store.thread_id != std::thread::current().id() { | ||
return Err(RuntimeError::new("Cannot call function: current thread is different from the thread the store was created in!")); | ||
} | ||
|
||
let mut args = { | ||
let params = params | ||
|
@@ -366,7 +397,34 @@ impl Function { | |
ptr | ||
}; | ||
|
||
let trap = unsafe { wasm_func_call(self.handle, args as *const _, results as *mut _) }; | ||
let mut trap; | ||
|
||
loop { | ||
trap = unsafe { wasm_func_call(self.handle, args as *const _, results) }; | ||
let store_mut = store.as_store_mut(); | ||
if let Some(callback) = store_mut.inner.on_called.take() { | ||
match callback(store_mut) { | ||
Ok(wasmer_types::OnCalledAction::InvokeAgain) => { | ||
continue; | ||
} | ||
Ok(wasmer_types::OnCalledAction::Finish) => { | ||
break; | ||
} | ||
Ok(wasmer_types::OnCalledAction::Trap(trap)) => { | ||
return Err(RuntimeError::user(trap)) | ||
} | ||
Err(trap) => return Err(RuntimeError::user(trap)), | ||
} | ||
} | ||
break; | ||
} | ||
|
||
if !trap.is_null() { | ||
unsafe { | ||
let trap: Trap = trap.into(); | ||
return Err(RuntimeError::from(trap)); | ||
} | ||
} | ||
|
||
if !trap.is_null() { | ||
return Err(Into::<Trap>::into(trap).into()); | ||
|
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.
If this is public, it needs to be
#[non_exhaustive]
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.
9038db9