-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rustc panicked struct cannot be packed and aligned #83107
Comments
Can't reproduce, can you provide the full code that's needed to reproduce this? |
Sure //! This file contains the source for the GDT (Global Descriptor Table).
//! The GDT contains entries telling the CPU about memory segments.
//!
//! **Notes**: https://wiki.osdev.org/Global_Descriptor_Table
use core::intrinsics::size_of;
use lazy_static::lazy_static;
// TODO: Each GDT for every different arch.
// TODO: https://github.com/rust-lang/rust/issues/83107
/// The GDT Descriptor containing the size of offset of the table.
#[repr(C, packed)]
struct GDTDescriptor {
/// The size of the table subtracted by 1.
/// The size of the table is subtracted by 1 as the maximum value
/// of `size` is 65535, while the GDT can be up to 65536 bytes.
size: u16,
/// The linear address of the table.
offset: u64,
}
impl GDTDescriptor {
/// Create a new GDT descriptor.
#[inline]
pub fn new(size: u16, offset: u64) -> Self {
Self { size, offset }
}
}
/// A GDT entry.
#[repr(C)]
struct GDTEntry {
limit_low: u16,
base_low: u16,
base_middle: u8,
access_byte: u8,
/// Four bits of the variable is the limit and rest four bits of the
/// variable are the flags.
limit_hi_flags: u8,
base_high: u8,
}
impl GDTEntry {
/// Create a new GDT entry.
#[inline]
fn new(
limit_low: u16,
base_low: u16,
base_middle: u8,
access_byte: u8,
limit_hi_flags: u8,
base_high: u8,
) -> Self {
Self {
limit_low,
base_low,
base_middle,
access_byte,
limit_hi_flags,
base_high,
}
}
}
/// The GDT.
#[repr(C, packed, align(0x1000))]
struct GDT {
/// The kernel null segment: `0x00`.
kernel_null: GDTEntry,
/// The kernel code segment: `0x08`.
kernel_code: GDTEntry,
/// The kernel data segment: `0x10`.
kernel_data: GDTEntry,
/// The user null segment.
user_null: GDTEntry,
/// The user code segment.
user_code: GDTEntry,
/// The user data segment.
user_data: GDTEntry,
}
/// Initialize the GDT.
pub fn init() {
unsafe {
let gdt_descriptor = GDTDescriptor::new(
(size_of::<GDT>() - 1) as u16,
(&GLOBAL_DESCRIPTOR_TABLE as *const _) as u64,
);
}
}
lazy_static! {
/// The GDT (Global Descriptor Table).
static ref GLOBAL_DESCRIPTOR_TABLE: GDT = GDT {
kernel_null: GDTEntry::new(0, 0, 0, 0x00, 0x00, 0),
kernel_code: GDTEntry::new(0, 0, 0, 0x9a, 0xa0, 0),
kernel_data: GDTEntry::new(0, 0, 0, 0x92, 0xa0, 0),
user_null: GDTEntry::new(0, 0, 0, 0x00, 0x00, 0),
user_code: GDTEntry::new(0, 0, 0, 0x9a, 0xa0, 0),
user_data: GDTEntry::new(0, 0, 0, 0x92, 0xa0, 0)
};
} |
MCVE: #[repr(packed, align(0x1000))]
pub struct Foo {
val: u16,
}
static BAR: Foo = Foo {
val: 0,
};
fn main() {} |
Assigning @rustbot label -I-prioritize +P-medium |
bisection: searched nightlies: from nightly-2020-06-01 to nightly-2021-03-17 bisected with cargo-bisect-rustc v0.6.0Host triple: x86_64-unknown-linux-gnu cargo bisect-rustc --start=2020-06-01 --regress=ice |
Issue: rust-lang/rust#83107
Layout error instead of an ICE for packed and aligned types Fixes rust-lang#83107.
Code
Meta
rustc --version --verbose
:Error output
Backtrace
The text was updated successfully, but these errors were encountered: