Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions cranelift/jit/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct JITBuilder {
symbols: HashMap<String, SendWrapper<*const u8>>,
lookup_symbols: Vec<Box<dyn Fn(&str) -> Option<*const u8> + Send>>,
libcall_names: Box<dyn Fn(ir::LibCall) -> String + Send + Sync>,
memory: Option<Box<dyn JITMemoryProvider>>,
memory: Option<Box<dyn JITMemoryProvider + Send>>,
}

impl JITBuilder {
Expand Down Expand Up @@ -150,7 +150,7 @@ impl JITBuilder {
/// Set the memory provider for the module.
///
/// If unset, defaults to [`SystemMemoryProvider`].
pub fn memory_provider(&mut self, provider: Box<dyn JITMemoryProvider>) -> &mut Self {
pub fn memory_provider(&mut self, provider: Box<dyn JITMemoryProvider + Send>) -> &mut Self {
self.memory = Some(provider);
self
}
Expand All @@ -172,7 +172,7 @@ pub struct JITModule {
symbols: RefCell<HashMap<String, SendWrapper<*const u8>>>,
lookup_symbols: Vec<Box<dyn Fn(&str) -> Option<*const u8> + Send>>,
libcall_names: Box<dyn Fn(ir::LibCall) -> String + Send + Sync>,
memory: Box<dyn JITMemoryProvider>,
memory: Box<dyn JITMemoryProvider + Send>,
declarations: ModuleDeclarations,
compiled_functions: SecondaryMap<FuncId, Option<CompiledBlob>>,
compiled_data_objects: SecondaryMap<DataId, Option<CompiledBlob>>,
Expand Down Expand Up @@ -762,3 +762,14 @@ fn use_bti(isa_flags: &Vec<settings::Value>) -> bool {
.find(|&f| f.name == "use_bti")
.map_or(false, |f| f.as_bool().unwrap_or(false))
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_jit_module_is_send() {
fn assert_is_send<T: Send>() {}
assert_is_send::<JITModule>();
}
}
8 changes: 8 additions & 0 deletions cranelift/jit/src/memory/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ pub struct ArenaMemoryProvider {
segments: Vec<Segment>,
}

unsafe impl Send for ArenaMemoryProvider {}

impl ArenaMemoryProvider {
/// Create a new memory region with the given size.
pub fn new_with_size(reserve_size: usize) -> Result<Self, region::Error> {
Expand Down Expand Up @@ -281,4 +283,10 @@ mod tests {
let _ = arena.allocate_readwrite(900_000, 1).unwrap();
let _ = arena.allocate_readwrite(200_000, 1).unwrap_err();
}

#[test]
fn test_is_send() {
fn assert_is_send<T: Send>() {}
assert_is_send::<ArenaMemoryProvider>();
}
}