Swap code lazily when tiering up from singlepass to LLVM.

Does not handle long-running functions, but should work at least.
This commit is contained in:
losfair
2019-08-09 04:26:17 +08:00
parent 0d604b754b
commit c1619026d5
10 changed files with 350 additions and 94 deletions

View File

@ -102,13 +102,20 @@ pub struct CodeMemory {
size: usize,
}
unsafe impl Send for CodeMemory {}
unsafe impl Sync for CodeMemory {}
#[cfg(not(unix))]
impl CodeMemory {
pub fn new(_size: usize) -> CodeMemory {
unimplemented!();
}
pub fn make_executable(&mut self) {
pub fn make_executable(&self) {
unimplemented!();
}
pub fn make_writable(&self) {
unimplemented!();
}
}
@ -139,11 +146,17 @@ impl CodeMemory {
}
}
pub fn make_executable(&mut self) {
pub fn make_executable(&self) {
if unsafe { mprotect(self.ptr as _, self.size, PROT_READ | PROT_EXEC) } != 0 {
panic!("cannot set code memory to executable");
}
}
pub fn make_writable(&self) {
if unsafe { mprotect(self.ptr as _, self.size, PROT_READ | PROT_WRITE) } != 0 {
panic!("cannot set code memory to writable");
}
}
}
#[cfg(unix)]