Skip to content

Commit 66ab0db

Browse files
committed
Fix panic from extern type KTable introduced by rust-lang/rust#118534
1 parent a592f60 commit 66ab0db

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

kernel_api/src/bridge.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@ pub mod hal {
2929
}
3030

3131
pub mod paging {
32+
use core::marker::PhantomData;
3233
use core::ops::DerefMut;
3334
use crate::memory::{Frame, Page, PhysicalAddress, VirtualAddress};
3435
use crate::memory::allocator::{AllocError, BackingAllocator, GlobalAllocator};
3536
use crate::sync::RwWriteGuard;
3637

38+
// FIXME: replace with extern type when alignment can be specified
39+
#[repr(align(8))]
40+
pub struct KTable((), PhantomData<KTableInner>);
41+
3742
extern "Rust" {
38-
pub type KTable;
43+
type KTableInner;
3944

4045
pub fn __popcorn_paging_ktable_translate_page(this: &KTable, page: Page) -> Option<Frame>;
4146
pub fn __popcorn_paging_ktable_translate_address(this: &KTable, addr: VirtualAddress) -> Option<PhysicalAddress>;

kernel_hal/src/arch/amd64/paging2/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub(crate) unsafe fn construct_tables() -> (Amd64KTable, Amd64TTable) {
3434
#[derive(Debug)]
3535
struct KTablePtr(Frame); // points to a [Table<PDPT>; 256]
3636

37+
#[repr(align(8))]
3738
pub struct Amd64KTable {
3839
tables: KTablePtr, // points to a [Table<PDPT>; 256]
3940
allocator: &'static dyn BackingAllocator,

kernel_hal/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ pub unsafe trait Hal {
5555
unsafe extern "C" fn switch_thread(from: &mut ThreadControlBlock, to: &ThreadControlBlock);
5656
}
5757

58+
const _: () = { if core::mem::align_of::<<HalTy as Hal>::KTableTy>() != 8 { panic!("for... reasons... KTables must be 8 byte aligned"); } };
59+
5860
pub trait FormatWriter {
5961
fn print(fmt: core::fmt::Arguments);
6062
}

0 commit comments

Comments
 (0)