Skip to content

Commit

Permalink
Fix vmimage for latest nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
jxors committed Oct 15, 2024
1 parent f32c301 commit 1cd41fb
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion arch/x64/build-vmimage/vmimage-x86-64/src/gdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub const STACKED_INTERRUPT_HANDLER_IST_INDEX: u16 = 1;
static mut TSS: (TaskStateSegment, [u8; 16]) = (TaskStateSegment::new(), [0xff; 16]);

fn init_tss() {
let mut tss = unsafe { &mut TSS.0 };
let tss = unsafe { &mut TSS.0 };
const STACK_SIZE: usize = 4096 * 5;
tss.interrupt_stack_table[MAIN_INTERRUPT_HANDLER_IST_INDEX as usize] = {
#[used]
Expand Down
5 changes: 2 additions & 3 deletions arch/x64/build-vmimage/vmimage-x86-64/src/interrupts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::{arch::asm, sync::atomic::{AtomicU32, Ordering}};
use core::{arch::naked_asm, sync::atomic::{AtomicU32, Ordering}};
use crate::{gdt, hlt_loop, serial_println, serial_print};
use lazy_static::lazy_static;
use pic8259::ChainedPics;
Expand Down Expand Up @@ -241,7 +241,7 @@ extern "C" fn check_timer_interrupt() -> bool {

#[naked]
unsafe extern "C" fn timer_interrupt_handler() {
asm!(
naked_asm!(
// If we're currently not in userspace, bail out to the kernel handler
"cmp qword ptr [rip + {RESTORE_STATE}], 0",
"jnz 3f",
Expand Down Expand Up @@ -288,7 +288,6 @@ unsafe extern "C" fn timer_interrupt_handler() {
c = sym crate::userspace::handle_interrupt,
check_timer_interrupt = sym check_timer_interrupt,
RESTORE_STATE = sym crate::userspace::RESTORE_STATE,
options(noreturn)
)
}

Expand Down
2 changes: 1 addition & 1 deletion arch/x64/build-vmimage/vmimage-x86-64/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#![no_std]
#![cfg_attr(test, no_main)]
#![feature(custom_test_frameworks, abi_x86_interrupt, const_ptr_offset_from, alloc_error_handler, naked_functions, asm_sym)]
#![feature(custom_test_frameworks, abi_x86_interrupt, alloc_error_handler, naked_functions)]
#![feature(generic_const_exprs)]
#![test_runner(crate::test_runner)]
#![reexport_test_harness_main = "test_main"]
Expand Down
4 changes: 2 additions & 2 deletions arch/x64/build-vmimage/vmimage-x86-64/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl ObservationMapper for ObsMapper {
let phys_addr = self.bar_base + page_offset;
let frame = PhysFrame::from_start_address(phys_addr).unwrap();
if self.qemu_cache_invalidate && permissions == Permissions::Executable {
let mut addr = if addr >= page.start_address().as_u64() && addr <= page.start_address().as_u64() + 4095 {
let addr = if addr >= page.start_address().as_u64() && addr <= page.start_address().as_u64() + 4095 {
addr
} else {
page.start_address().as_u64()
Expand Down Expand Up @@ -590,7 +590,7 @@ impl ObservationMapper for OffsetObsMapper {
});
}

fn map_executable(&mut self, frame_index: usize, page: x86_64::structures::paging::Page, addr: u64, permissions: Permissions) {
fn map_executable(&mut self, frame_index: usize, page: x86_64::structures::paging::Page, _addr: u64, permissions: Permissions) {
self.map(frame_index, page, permissions);
}

Expand Down
2 changes: 1 addition & 1 deletion arch/x64/build-vmimage/vmimage-x86-64/src/observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::arch::asm;

use liblisa_x64_observer_shmqueue::frame::command::{Permissions, CommandFrame};
use x86_64::{VirtAddr, structures::paging::Page};
use crate::{userspace::jmp_to_usermode, serial_println};
use crate::userspace::jmp_to_usermode;

pub struct Observer {}

Expand Down
14 changes: 5 additions & 9 deletions arch/x64/build-vmimage/vmimage-x86-64/src/userspace.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::{arch::asm, ptr};
use core::{arch::{asm, naked_asm}, ptr};
use liblisa_x64_observer_shmqueue::regs::GpRegs;

use crate::gdt;
Expand Down Expand Up @@ -154,14 +154,13 @@ macro_rules! generate_interrupt_entry {
($id:literal: $name:ident) => {
#[naked]
unsafe extern "C" fn $name() {
asm!(
naked_asm!(
"cld",
"push 0",
"push {id}",
"jmp {c}",
id = const $id,
c = sym crate::userspace::handle_interrupt,
options(noreturn)
)
}
};
Expand All @@ -172,7 +171,7 @@ macro_rules! generate_interrupt_entry {
let _: extern "x86-interrupt" fn(stack_frame: InterruptStackFrame) = $kernel_handler;
}

asm!(
naked_asm!(
// If we're currently not in userspace, bail out to the kernel handler
"cmp qword ptr [rip + {RESTORE_STATE}], 0",
"jnz 3f",
Expand All @@ -187,7 +186,6 @@ macro_rules! generate_interrupt_entry {
c = sym crate::userspace::handle_interrupt,
RESTORE_STATE = sym crate::userspace::RESTORE_STATE,
handler = sym $kernel_handler,
options(noreturn)
)
}
};
Expand All @@ -198,7 +196,7 @@ macro_rules! generate_interrupt_entry {
let _: extern "x86-interrupt" fn(stack_frame: InterruptStackFrame, error_code: $error_ty) = $kernel_handler;
}

asm!(
naked_asm!(
// If we're currently not in userspace, bail out to the kernel handler
"cmp qword ptr [rip + {RESTORE_STATE}], 0",
"jnz 3f",
Expand All @@ -211,7 +209,6 @@ macro_rules! generate_interrupt_entry {
c = sym crate::userspace::handle_interrupt,
RESTORE_STATE = sym crate::userspace::RESTORE_STATE,
handler = sym $kernel_handler,
options(noreturn)
)
}
}
Expand All @@ -229,7 +226,7 @@ pub unsafe extern "C" fn handle_interrupt() {
// - [+0x20] rflags
// - [+0x28] rsp
// - [+0x30] ss
asm!(
naked_asm!(
// push rbx so we have a scratch register for the GpRegs pointer.
// rbx will point to the memory region where we store the GPREGS.
"push rbx",
Expand Down Expand Up @@ -313,6 +310,5 @@ pub unsafe extern "C" fn handle_interrupt() {
exception_id_offset = const memoffset::offset_of!(GpRegs, exception_id),
error_code_offset = const memoffset::offset_of!(GpRegs, error_code),
access_address_offset = const memoffset::offset_of!(GpRegs, access_address),
options(noreturn)
)
}

0 comments on commit 1cd41fb

Please sign in to comment.