From bc80435dfcaf819bb0b745e55274e764e16d0cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 23 Feb 2024 19:19:24 +0100 Subject: [PATCH] fix(x86_64): explicitly decrease alignment of i128 to 8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/boot_info/kernel.rs | 5 ++++- src/boot_info/loader.rs | 2 +- src/boot_info/mod.rs | 13 ++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/boot_info/kernel.rs b/src/boot_info/kernel.rs index d39bcf5..9f55051 100644 --- a/src/boot_info/kernel.rs +++ b/src/boot_info/kernel.rs @@ -66,7 +66,10 @@ impl From for PlatformInfo { has_pci, num_cpus, cpu_freq, - boot_time: OffsetDateTime::from_unix_timestamp_nanos(boot_time).unwrap(), + boot_time: OffsetDateTime::from_unix_timestamp_nanos(i128::from_ne_bytes( + boot_time.0, + )) + .unwrap(), }, RawPlatformInfo::LinuxBootParams { command_line_data, diff --git a/src/boot_info/loader.rs b/src/boot_info/loader.rs index 23461ab..cca7a13 100644 --- a/src/boot_info/loader.rs +++ b/src/boot_info/loader.rs @@ -54,7 +54,7 @@ impl From for RawPlatformInfo { has_pci, num_cpus, cpu_freq, - boot_time: boot_time.unix_timestamp_nanos(), + boot_time: boot_time.unix_timestamp_nanos().to_ne_bytes().into(), }, PlatformInfo::LinuxBootParams { command_line, diff --git a/src/boot_info/mod.rs b/src/boot_info/mod.rs index af26a13..7a56bff 100644 --- a/src/boot_info/mod.rs +++ b/src/boot_info/mod.rs @@ -158,6 +158,17 @@ struct RawLoadInfo { tls_info: TlsInfo, } +#[derive(Clone, Copy, Debug)] +#[cfg_attr(target_arch = "x86_64", repr(C, align(8)))] +#[cfg_attr(not(target_arch = "x86_64"), repr(transparent))] +struct Align8(pub T); + +impl From for Align8 { + fn from(value: T) -> Self { + Self(value) + } +} + #[cfg_attr(not(all(feature = "loader", feature = "kernel")), allow(dead_code))] #[derive(Clone, Copy, Debug)] #[repr(C)] @@ -174,7 +185,7 @@ enum RawPlatformInfo { has_pci: bool, num_cpus: NonZeroU64, cpu_freq: Option, - boot_time: i128, + boot_time: Align8<[u8; 16]>, }, LinuxBootParams { command_line_data: *const u8,