From e9618d9e2c561aba88ffb3de654c3062bc0d2d8e Mon Sep 17 00:00:00 2001 From: lynxnb Date: Wed, 17 Aug 2022 12:22:11 +0200 Subject: [PATCH] Use pragma pack directions for tightly packing structs containing `u128` Using `__attribute__((packed))` doesn't work in new NDKs when a struct contains 128-bit integer members, likely because of a ndk/compiler bug. We now enclose the requiring structs in `#pragma pack` directives to tightly pack them. --- app/src/main/cpp/skyline/services/timesrv/common.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/cpp/skyline/services/timesrv/common.h b/app/src/main/cpp/skyline/services/timesrv/common.h index 919fd1f5..cd4496e4 100644 --- a/app/src/main/cpp/skyline/services/timesrv/common.h +++ b/app/src/main/cpp/skyline/services/timesrv/common.h @@ -60,11 +60,17 @@ namespace skyline::service::timesrv { } }; + /* + * Using __attribute__((packed)) doesn't work in new NDKs when a struct contains 128-bit integer members, likely because of a ndk/compiler bug + * Use #pragma pack to ensure that the following structs are tightly packed + */ + #pragma pack(1) + /** * @brief Holds details about a point in time sourced from a steady clock (e.g. RTC) * @url https://switchbrew.org/w/index.php?title=PSC_services#SteadyClockTimePoint */ - struct __attribute__((packed)) SteadyClockTimePoint { + struct SteadyClockTimePoint { i64 timePoint; //!< Time in seconds UUID clockSourceId; //!< The UUID of the steady clock this timepoint comes from @@ -76,7 +82,7 @@ namespace skyline::service::timesrv { * @brief Describes a system clocks offset from its associated steady clock * @url https://switchbrew.org/w/index.php?title=PSC_services#SystemClockContext */ - struct __attribute__((packed)) SystemClockContext { + struct SystemClockContext { i64 offset; // Offset between the steady timepoint and the epoch SteadyClockTimePoint timestamp; //!< The steady timepoint this context was calibrated from @@ -84,6 +90,8 @@ namespace skyline::service::timesrv { }; static_assert(sizeof(SystemClockContext) == 0x20); + #pragma pack() + /** * @brief A particular time point in Nintendo's calendar format * @url https://switchbrew.org/w/index.php?title=PSC_services#CalendarTime