Skip to content

Commit

Permalink
Fix panic from extern type KTable introduced by rust-lang/rust#118534
Browse files Browse the repository at this point in the history
  • Loading branch information
egkoppel committed Feb 11, 2024
1 parent a592f60 commit 66ab0db
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion kernel_api/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ pub mod hal {
}

pub mod paging {
use core::marker::PhantomData;
use core::ops::DerefMut;
use crate::memory::{Frame, Page, PhysicalAddress, VirtualAddress};
use crate::memory::allocator::{AllocError, BackingAllocator, GlobalAllocator};
use crate::sync::RwWriteGuard;

// FIXME: replace with extern type when alignment can be specified
#[repr(align(8))]
pub struct KTable((), PhantomData<KTableInner>);

extern "Rust" {
pub type KTable;
type KTableInner;

pub fn __popcorn_paging_ktable_translate_page(this: &KTable, page: Page) -> Option<Frame>;
pub fn __popcorn_paging_ktable_translate_address(this: &KTable, addr: VirtualAddress) -> Option<PhysicalAddress>;
Expand Down
1 change: 1 addition & 0 deletions kernel_hal/src/arch/amd64/paging2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub(crate) unsafe fn construct_tables() -> (Amd64KTable, Amd64TTable) {
#[derive(Debug)]
struct KTablePtr(Frame); // points to a [Table<PDPT>; 256]

#[repr(align(8))]
pub struct Amd64KTable {
tables: KTablePtr, // points to a [Table<PDPT>; 256]
allocator: &'static dyn BackingAllocator,
Expand Down
2 changes: 2 additions & 0 deletions kernel_hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ pub unsafe trait Hal {
unsafe extern "C" fn switch_thread(from: &mut ThreadControlBlock, to: &ThreadControlBlock);
}

const _: () = { if core::mem::align_of::<<HalTy as Hal>::KTableTy>() != 8 { panic!("for... reasons... KTables must be 8 byte aligned"); } };

pub trait FormatWriter {
fn print(fmt: core::fmt::Arguments);
}
Expand Down

0 comments on commit 66ab0db

Please sign in to comment.