Skip to content

Commit

Permalink
Merge pull request #31 from hermit-os/i128-align8
Browse files Browse the repository at this point in the history
fix(x86_64): explicitly decrease alignment of i128 to 8
  • Loading branch information
mkroening authored Feb 23, 2024
2 parents d7a6340 + 6c77bd1 commit 544317d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hermit-entry"
version = "0.9.9"
version = "0.9.10"
authors = ["Martin Kröning <[email protected]>"]
edition = "2021"
description = "Hermit's loading and entry API."
Expand Down
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 544317d

Please sign in to comment.