Skip to content

Commit 33bde35

Browse files
author
Sangho Lee
committed
drop host (wip)
1 parent 40ec185 commit 33bde35

File tree

7 files changed

+114
-309
lines changed

7 files changed

+114
-309
lines changed

litebox_platform/src/host/hv_impl.rs

Lines changed: 0 additions & 144 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//! An implementation of [`HostInterface`] for (Virtual) Machine
2+
3+
use crate::host::per_cpu_variables::with_per_cpu_variables_mut;
4+
5+
pub type Machine = crate::LinuxKernel;
6+
7+
#[cfg(not(test))]
8+
mod alloc {
9+
const HEAP_ORDER: usize = 25;
10+
11+
#[global_allocator]
12+
static MACHINE_ALLOCATOR: litebox::mm::allocator::SafeZoneAllocator<
13+
'static,
14+
HEAP_ORDER,
15+
crate::host::Machine,
16+
> = litebox::mm::allocator::SafeZoneAllocator::new();
17+
18+
impl litebox::mm::allocator::MemoryProvider for super::Machine {
19+
fn alloc(_layout: &core::alloc::Layout) -> Option<(usize, usize)> {
20+
// dynamic memory allocation here implies memory ballooning or hotplugging
21+
unimplemented!()
22+
}
23+
24+
unsafe fn free(_addr: usize) {
25+
unimplemented!()
26+
}
27+
}
28+
29+
impl crate::mm::MemoryProvider for super::Machine {
30+
const GVA_OFFSET: x86_64::VirtAddr = x86_64::VirtAddr::new(0x18000000000);
31+
const PRIVATE_PTE_MASK: u64 = 0;
32+
33+
fn mem_allocate_pages(order: u32) -> Option<*mut u8> {
34+
MACHINE_ALLOCATOR.allocate_pages(order)
35+
}
36+
37+
unsafe fn mem_free_pages(ptr: *mut u8, order: u32) {
38+
unsafe {
39+
MACHINE_ALLOCATOR.free_pages(ptr, order);
40+
}
41+
}
42+
43+
unsafe fn mem_fill_pages(start: usize, size: usize) {
44+
unsafe { MACHINE_ALLOCATOR.fill_pages(start, size) };
45+
}
46+
}
47+
}
48+
49+
unsafe impl litebox::platform::ThreadLocalStorageProvider for Machine {
50+
fn get_thread_local_storage() -> *mut () {
51+
let tls = with_per_cpu_variables_mut(|pcv| pcv.tls);
52+
tls.as_mut_ptr::<()>()
53+
}
54+
55+
unsafe fn replace_thread_local_storage(value: *mut ()) -> *mut () {
56+
let tls = with_per_cpu_variables_mut(|pcv| pcv.tls);
57+
core::mem::replace(&mut tls.as_mut_ptr::<()>(), value.cast()).cast()
58+
}
59+
}

litebox_platform/src/host/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! Different host implementations of [`super::HostInterface`]
2-
pub mod hv_impl;
32
pub mod linux;
3+
pub mod machine_impl;
44
pub mod per_cpu_variables;
55

6-
pub use hv_impl::Hypervisor;
6+
pub use machine_impl::Machine;
77

88
#[cfg(test)]
99
pub mod mock;

0 commit comments

Comments
 (0)