mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-30 09:01:33 +00:00
Func::new_polymorphic
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
//! The loader module functions are used to load an instance.
|
||||
use crate::{backend::RunnableModule, module::ModuleInfo, types::Type, types::Value, vm::Ctx};
|
||||
#[cfg(unix)]
|
||||
use libc::{mmap, mprotect, munmap, MAP_ANON, MAP_PRIVATE, PROT_EXEC, PROT_READ, PROT_WRITE};
|
||||
use libc::{
|
||||
mmap, mprotect, munmap, MAP_ANON, MAP_NORESERVE, MAP_PRIVATE, PROT_EXEC, PROT_READ, PROT_WRITE,
|
||||
};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
ops::{Deref, DerefMut},
|
||||
@ -169,7 +171,7 @@ impl CodeMemory {
|
||||
std::ptr::null_mut(),
|
||||
size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON,
|
||||
MAP_PRIVATE | MAP_ANON | MAP_NORESERVE,
|
||||
-1,
|
||||
0,
|
||||
)
|
||||
@ -196,6 +198,20 @@ impl CodeMemory {
|
||||
panic!("cannot set code memory to writable");
|
||||
}
|
||||
}
|
||||
|
||||
/// Makes this code memory both writable and executable.
|
||||
///
|
||||
/// Avoid using this if a combination `make_executable` and `make_writable` can be used.
|
||||
pub fn make_writable_executable(&self) {
|
||||
if unsafe { mprotect(self.ptr as _, self.size, PROT_READ | PROT_WRITE | PROT_EXEC) } != 0 {
|
||||
panic!("cannot set code memory to writable and executable");
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the backing pointer of this code memory.
|
||||
pub fn get_backing_ptr(&self) -> *mut u8 {
|
||||
self.ptr
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
|
Reference in New Issue
Block a user