Skip to content

Commit

Permalink
fix(x86_64): explicitly decrease alignment of i128 to 8
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Feb 23, 2024
1 parent d7a6340 commit bc80435
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/boot_info/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ impl From<RawPlatformInfo> 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,
Expand Down
2 changes: 1 addition & 1 deletion src/boot_info/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl From<PlatformInfo> 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,
Expand Down
13 changes: 12 additions & 1 deletion src/boot_info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(pub T);

impl<T> From<T> for Align8<T> {
fn from(value: T) -> Self {
Self(value)
}
}

#[cfg_attr(not(all(feature = "loader", feature = "kernel")), allow(dead_code))]
#[derive(Clone, Copy, Debug)]
#[repr(C)]
Expand All @@ -174,7 +185,7 @@ enum RawPlatformInfo {
has_pci: bool,
num_cpus: NonZeroU64,
cpu_freq: Option<NonZeroU32>,
boot_time: i128,
boot_time: Align8<[u8; 16]>,
},
LinuxBootParams {
command_line_data: *const u8,
Expand Down

0 comments on commit bc80435

Please sign in to comment.