Add lazy static and start initializing global state of the WX allocator
This commit is contained in:
parent
372777a64d
commit
b3509129c1
@ -14,3 +14,4 @@ flush_reload = { path = "../flush_reload" }
|
|||||||
basic_timing_cache_channel = { path = "../basic_timing_cache_channel" }
|
basic_timing_cache_channel = { path = "../basic_timing_cache_channel" }
|
||||||
nix = "0.20.0"
|
nix = "0.20.0"
|
||||||
rand = "0.8.3"
|
rand = "0.8.3"
|
||||||
|
lazy_static = "1.4.0"
|
||||||
|
@ -1,18 +1,68 @@
|
|||||||
|
use cache_utils::mmap::MMappedMemory;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use std::collections::LinkedList;
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
struct WXRange {
|
||||||
|
bitmap: Vec<bool>, // fixme bit vector
|
||||||
|
pages: Vec<MMappedMemory<u8>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct WXAllocator {
|
||||||
|
ranges: LinkedList<WXRange>,
|
||||||
|
// Possible improvement : a dedicated data structure, with optimised lookup of which range
|
||||||
|
// contains the right address, plus reasonably easy ability to merge nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WXAllocator {
|
||||||
|
fn new() -> Self {
|
||||||
|
WXAllocator {
|
||||||
|
ranges: LinkedList::<WXRange>::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct FunctionTemplate {
|
||||||
|
start: unsafe extern "C" fn(*const u8) -> u64,
|
||||||
|
ip: *const u8,
|
||||||
|
end: *const u8,
|
||||||
|
}
|
||||||
|
lazy_static! {
|
||||||
|
static ref wx_allocator: Mutex<WXAllocator> = Mutex::new(WXAllocator::new());
|
||||||
|
}
|
||||||
|
const TIMED_MACCESS: FunctionTemplate = FunctionTemplate {
|
||||||
|
start: timed_maccess_template,
|
||||||
|
ip: timed_maccess_template_ip as *const u8,
|
||||||
|
end: timed_maccess_template_end as *const u8,
|
||||||
|
};
|
||||||
|
|
||||||
|
const TIMED_CLFLUSH: FunctionTemplate = FunctionTemplate {
|
||||||
|
start: timed_clflush_template,
|
||||||
|
ip: timed_clflush_template_ip as *const u8,
|
||||||
|
end: timed_clflush_template_end as *const u8,
|
||||||
|
};
|
||||||
|
|
||||||
global_asm!(
|
global_asm!(
|
||||||
".global timed_maccess_template",
|
".global timed_maccess_template",
|
||||||
"timed_maccess_template:",
|
"timed_maccess_template:",
|
||||||
"mfence",
|
"mfence",
|
||||||
|
"lfence",
|
||||||
"rdtsc",
|
"rdtsc",
|
||||||
"shl rdx, 32",
|
"shl rdx, 32",
|
||||||
"mov rsi, rdx",
|
"mov rsi, rdx",
|
||||||
"add rsi, rax",
|
"add rsi, rax",
|
||||||
"mfence",
|
"mfence",
|
||||||
|
"lfence",
|
||||||
|
".global timed_maccess_template_ip",
|
||||||
|
"timed_maccess_template_ip:",
|
||||||
"mov rdi, [rdi]",
|
"mov rdi, [rdi]",
|
||||||
"mfence",
|
"mfence",
|
||||||
|
"lfence",
|
||||||
"rdtsc",
|
"rdtsc",
|
||||||
"shl rdx, 32",
|
"shl rdx, 32",
|
||||||
"add rax, rdx",
|
"add rax, rdx",
|
||||||
"mfence",
|
"mfence",
|
||||||
|
"lfence",
|
||||||
"sub rax, rsi",
|
"sub rax, rsi",
|
||||||
"ret",
|
"ret",
|
||||||
".global timed_maccess_template_end",
|
".global timed_maccess_template_end",
|
||||||
@ -21,17 +71,23 @@ global_asm!(
|
|||||||
".global timed_clflush_template",
|
".global timed_clflush_template",
|
||||||
"timed_clflush_template:",
|
"timed_clflush_template:",
|
||||||
"mfence",
|
"mfence",
|
||||||
|
"lfence",
|
||||||
"rdtsc",
|
"rdtsc",
|
||||||
"shl rdx, 32",
|
"shl rdx, 32",
|
||||||
"mov rsi, rdx",
|
"mov rsi, rdx",
|
||||||
"add rsi, rax",
|
"add rsi, rax",
|
||||||
"mfence",
|
"mfence",
|
||||||
|
"lfence",
|
||||||
|
".global timed_clflush_template_ip",
|
||||||
|
"timed_clflush_template_ip:",
|
||||||
"clflush [rdi]",
|
"clflush [rdi]",
|
||||||
"mfence",
|
"mfence",
|
||||||
|
"lfence",
|
||||||
"rdtsc",
|
"rdtsc",
|
||||||
"shl rdx, 32",
|
"shl rdx, 32",
|
||||||
"add rax, rdx",
|
"add rax, rdx",
|
||||||
"mfence",
|
"mfence",
|
||||||
|
"lfence",
|
||||||
"sub rax, rsi",
|
"sub rax, rsi",
|
||||||
"ret",
|
"ret",
|
||||||
".global timed_clflush_template_end",
|
".global timed_clflush_template_end",
|
||||||
@ -41,8 +97,10 @@ global_asm!(
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn timed_maccess_template(pointer: *const u8) -> u64;
|
fn timed_maccess_template(pointer: *const u8) -> u64;
|
||||||
|
fn timed_maccess_template_ip();
|
||||||
fn timed_maccess_template_end();
|
fn timed_maccess_template_end();
|
||||||
fn timed_clflush_template(pointer: *const u8) -> u64;
|
fn timed_clflush_template(pointer: *const u8) -> u64;
|
||||||
|
fn timed_clflush_template_ip();
|
||||||
fn timed_clflush_template_end();
|
fn timed_clflush_template_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user