diff --git a/fusee/program/source/fusee_overlay_manager.cpp b/fusee/program/source/fusee_overlay_manager.cpp index a3f32a79b..109d3e0d5 100644 --- a/fusee/program/source/fusee_overlay_manager.cpp +++ b/fusee/program/source/fusee_overlay_manager.cpp @@ -33,11 +33,11 @@ namespace ams::nxboot { u32 verif_hash; u32 store_hash; if (fuse::GetSocType() == fuse::SocType_Erista) { - result = fs::ReadFile(archive_file, __builtin_offsetof(ExternalPackage, ovl_mtc_erista), GetOverlayDestination(), sizeof(ExternalPackage{}.ovl_mtc_erista)); + result = fs::ReadFile(archive_file, AMS_OFFSETOF(ExternalPackage, ovl_mtc_erista), GetOverlayDestination(), sizeof(ExternalPackage{}.ovl_mtc_erista)); verif_hash = reinterpret_cast(GetOverlayDestination())[-2]; store_hash = reinterpret_cast(GetOverlayDestination())[(sizeof(ExternalPackage{}.ovl_mtc_erista) / sizeof(u32)) - 1]; } else /* if (fuse::GetSocType() == fuse::SocType_Mariko) */ { - result = fs::ReadFile(archive_file, __builtin_offsetof(ExternalPackage, ovl_mtc_mariko), GetOverlayDestination(), sizeof(ExternalPackage{}.ovl_mtc_mariko)); + result = fs::ReadFile(archive_file, AMS_OFFSETOF(ExternalPackage, ovl_mtc_mariko), GetOverlayDestination(), sizeof(ExternalPackage{}.ovl_mtc_mariko)); verif_hash = reinterpret_cast(GetOverlayDestination())[-1]; store_hash = reinterpret_cast(GetOverlayDestination())[(sizeof(ExternalPackage{}.ovl_mtc_mariko) / sizeof(u32)) - 1]; } diff --git a/fusee/program/source/fusee_setup_horizon.cpp b/fusee/program/source/fusee_setup_horizon.cpp index fbf51784a..d360ed85a 100644 --- a/fusee/program/source/fusee_setup_horizon.cpp +++ b/fusee/program/source/fusee_setup_horizon.cpp @@ -270,7 +270,7 @@ namespace ams::nxboot { u8 *package2; size_t package2_size; { - constexpr s64 Package2Offset = __builtin_offsetof(pkg2::StorageLayout, package2_header); + constexpr s64 Package2Offset = AMS_OFFSETOF(pkg2::StorageLayout, package2_header); pkg2::Package2Header header; if (R_FAILED((result = ReadPackage2(Package2Offset, std::addressof(header), sizeof(header))))) { diff --git a/libraries/config/common.mk b/libraries/config/common.mk index 9e6448df9..a39ad73be 100644 --- a/libraries/config/common.mk +++ b/libraries/config/common.mk @@ -21,7 +21,8 @@ export ATMOSPHERE_DEFINES := -DATMOSPHERE export ATMOSPHERE_SETTINGS := -fPIE -g -gdwarf-4 $(ATMOSPHERE_BUILD_SETTINGS) export ATMOSPHERE_CFLAGS := -Wall -ffunction-sections -fdata-sections -fno-strict-aliasing -fwrapv \ -fno-asynchronous-unwind-tables -fno-unwind-tables -fno-stack-protector \ - -Wno-format-truncation -Wno-format-zero-length -Wno-stringop-truncation + -Wno-format-truncation -Wno-format-zero-length -Wno-stringop-truncation \ + -Wno-invalid-offsetof export ATMOSPHERE_CXXFLAGS := -fno-rtti -fno-exceptions -std=gnu++20 export ATMOSPHERE_ASFLAGS := @@ -45,7 +46,7 @@ export ATMOSPHERE_BOARD_DIR := nintendo/nx_bpmp export ATMOSPHERE_OS_DIR := horizon export ATMOSPHERE_ARCH_NAME := arm -export ATMOSPHERE_BOARD_NAME := nintendo_nx +export ATMOSPHERE_BOARD_NAME := nintendo_nx_bpmp export ATMOSPHERE_OS_NAME := horizon export ATMOSPHERE_CPU_EXTENSIONS := diff --git a/libraries/libexosphere/include/exosphere/pkg1/pkg1_bootloader_parameters.hpp b/libraries/libexosphere/include/exosphere/pkg1/pkg1_bootloader_parameters.hpp index 42c6aed74..b3de1ea49 100644 --- a/libraries/libexosphere/include/exosphere/pkg1/pkg1_bootloader_parameters.hpp +++ b/libraries/libexosphere/include/exosphere/pkg1/pkg1_bootloader_parameters.hpp @@ -55,9 +55,9 @@ namespace ams::pkg1 { static_assert(util::is_pod::value); static_assert(sizeof(SecureMonitorParameters) == 0x200); - static_assert(offsetof(SecureMonitorParameters, bct_params) == 0x10); - static_assert(offsetof(SecureMonitorParameters, bootloader_state) == 0xF8); - static_assert(offsetof(SecureMonitorParameters, secmon_state) == 0xFC); + static_assert(AMS_OFFSETOF(SecureMonitorParameters, bct_params) == 0x10); + static_assert(AMS_OFFSETOF(SecureMonitorParameters, bootloader_state) == 0xF8); + static_assert(AMS_OFFSETOF(SecureMonitorParameters, secmon_state) == 0xFC); enum BootloaderAttribute { BootloaderAttribute_None = (0u << 0), diff --git a/libraries/libexosphere/include/exosphere/secmon/secmon_volatile_context.hpp b/libraries/libexosphere/include/exosphere/secmon/secmon_volatile_context.hpp index 6926e5070..b17293f04 100644 --- a/libraries/libexosphere/include/exosphere/secmon/secmon_volatile_context.hpp +++ b/libraries/libexosphere/include/exosphere/secmon/secmon_volatile_context.hpp @@ -128,10 +128,10 @@ namespace ams::secmon { } - constexpr inline const Address WarmbootStackAddress = MemoryRegionVirtualTzramVolatileData.GetAddress() + offsetof(VolatileData, warmboot_stack) + sizeof(VolatileData::warmboot_stack); - constexpr inline const Address Core012SmcStackAddress = MemoryRegionVirtualTzramVolatileData.GetAddress() + offsetof(VolatileData, core012_smc_stack) + sizeof(VolatileData::core012_smc_stack); + constexpr inline const Address WarmbootStackAddress = MemoryRegionVirtualTzramVolatileData.GetAddress() + AMS_OFFSETOF(VolatileData, warmboot_stack) + sizeof(VolatileData::warmboot_stack); + constexpr inline const Address Core012SmcStackAddress = MemoryRegionVirtualTzramVolatileData.GetAddress() + AMS_OFFSETOF(VolatileData, core012_smc_stack) + sizeof(VolatileData::core012_smc_stack); - constexpr inline const Address Core0ExceptionStackAddress = MemoryRegionVirtualTzramVolatileData.GetAddress() + offsetof(VolatileData, core_exception_stacks) + CoreExceptionStackSize; + constexpr inline const Address Core0ExceptionStackAddress = MemoryRegionVirtualTzramVolatileData.GetAddress() + AMS_OFFSETOF(VolatileData, core_exception_stacks) + CoreExceptionStackSize; constexpr inline const Address Core1ExceptionStackAddress = Core0ExceptionStackAddress + CoreExceptionStackSize; constexpr inline const Address Core2ExceptionStackAddress = Core1ExceptionStackAddress + CoreExceptionStackSize; diff --git a/libraries/libexosphere/source/gic/gic_api.cpp b/libraries/libexosphere/source/gic/gic_api.cpp index b7fefed88..223e77138 100644 --- a/libraries/libexosphere/source/gic/gic_api.cpp +++ b/libraries/libexosphere/source/gic/gic_api.cpp @@ -191,27 +191,27 @@ namespace ams::gic { } void SetPriority(int interrupt_id, int priority) { - ReadWrite(g_distributor_address + offsetof(GicDistributor, ipriorityr), BITSIZEOF(u8), interrupt_id, priority); + ReadWrite(g_distributor_address + AMS_OFFSETOF(GicDistributor, ipriorityr), BITSIZEOF(u8), interrupt_id, priority); } void SetInterruptGroup(int interrupt_id, int group) { - ReadWrite(g_distributor_address + offsetof(GicDistributor, igroupr), 1, interrupt_id, group); + ReadWrite(g_distributor_address + AMS_OFFSETOF(GicDistributor, igroupr), 1, interrupt_id, group); } void SetEnable(int interrupt_id, bool enable) { - Write(g_distributor_address + offsetof(GicDistributor, isenabler), 1, interrupt_id, enable); + Write(g_distributor_address + AMS_OFFSETOF(GicDistributor, isenabler), 1, interrupt_id, enable); } void SetSpiTargetCpu(int interrupt_id, u32 cpu_mask) { - ReadWrite(g_distributor_address + offsetof(GicDistributor, itargetsr), BITSIZEOF(u8), interrupt_id, cpu_mask); + ReadWrite(g_distributor_address + AMS_OFFSETOF(GicDistributor, itargetsr), BITSIZEOF(u8), interrupt_id, cpu_mask); } void SetSpiMode(int interrupt_id, InterruptMode mode) { - ReadWrite(g_distributor_address + offsetof(GicDistributor, icfgr), 2, interrupt_id, static_cast(mode) << 1); + ReadWrite(g_distributor_address + AMS_OFFSETOF(GicDistributor, icfgr), 2, interrupt_id, static_cast(mode) << 1); } void SetPending(int interrupt_id) { - Write(g_distributor_address + offsetof(GicDistributor, ispendr), 1, interrupt_id, 1); + Write(g_distributor_address + AMS_OFFSETOF(GicDistributor, ispendr), 1, interrupt_id, 1); } int GetInterruptRequestId() { diff --git a/libraries/libmesosphere/include/mesosphere/arch/arm64/init/kern_k_init_arguments.hpp b/libraries/libmesosphere/include/mesosphere/arch/arm64/init/kern_k_init_arguments.hpp index 9efca493c..494750515 100644 --- a/libraries/libmesosphere/include/mesosphere/arch/arm64/init/kern_k_init_arguments.hpp +++ b/libraries/libmesosphere/include/mesosphere/arch/arm64/init/kern_k_init_arguments.hpp @@ -35,17 +35,17 @@ namespace ams::kern::init { static_assert(alignof(KInitArguments) == util::CeilingPowerOfTwo(INIT_ARGUMENTS_SIZE)); static_assert(sizeof(KInitArguments) == std::max(INIT_ARGUMENTS_SIZE, util::CeilingPowerOfTwo(INIT_ARGUMENTS_SIZE))); - static_assert(__builtin_offsetof(KInitArguments, ttbr0) == INIT_ARGUMENTS_TTBR0); - static_assert(__builtin_offsetof(KInitArguments, ttbr1) == INIT_ARGUMENTS_TTBR1); - static_assert(__builtin_offsetof(KInitArguments, tcr) == INIT_ARGUMENTS_TCR); - static_assert(__builtin_offsetof(KInitArguments, mair) == INIT_ARGUMENTS_MAIR); - static_assert(__builtin_offsetof(KInitArguments, cpuactlr) == INIT_ARGUMENTS_CPUACTLR); - static_assert(__builtin_offsetof(KInitArguments, cpuectlr) == INIT_ARGUMENTS_CPUECTLR); - static_assert(__builtin_offsetof(KInitArguments, sctlr) == INIT_ARGUMENTS_SCTLR); - static_assert(__builtin_offsetof(KInitArguments, sp) == INIT_ARGUMENTS_SP); - static_assert(__builtin_offsetof(KInitArguments, entrypoint) == INIT_ARGUMENTS_ENTRYPOINT); - static_assert(__builtin_offsetof(KInitArguments, argument) == INIT_ARGUMENTS_ARGUMENT); - static_assert(__builtin_offsetof(KInitArguments, setup_function) == INIT_ARGUMENTS_SETUP_FUNCTION); - static_assert(__builtin_offsetof(KInitArguments, exception_stack) == INIT_ARGUMENTS_EXCEPTION_STACK); + static_assert(AMS_OFFSETOF(KInitArguments, ttbr0) == INIT_ARGUMENTS_TTBR0); + static_assert(AMS_OFFSETOF(KInitArguments, ttbr1) == INIT_ARGUMENTS_TTBR1); + static_assert(AMS_OFFSETOF(KInitArguments, tcr) == INIT_ARGUMENTS_TCR); + static_assert(AMS_OFFSETOF(KInitArguments, mair) == INIT_ARGUMENTS_MAIR); + static_assert(AMS_OFFSETOF(KInitArguments, cpuactlr) == INIT_ARGUMENTS_CPUACTLR); + static_assert(AMS_OFFSETOF(KInitArguments, cpuectlr) == INIT_ARGUMENTS_CPUECTLR); + static_assert(AMS_OFFSETOF(KInitArguments, sctlr) == INIT_ARGUMENTS_SCTLR); + static_assert(AMS_OFFSETOF(KInitArguments, sp) == INIT_ARGUMENTS_SP); + static_assert(AMS_OFFSETOF(KInitArguments, entrypoint) == INIT_ARGUMENTS_ENTRYPOINT); + static_assert(AMS_OFFSETOF(KInitArguments, argument) == INIT_ARGUMENTS_ARGUMENT); + static_assert(AMS_OFFSETOF(KInitArguments, setup_function) == INIT_ARGUMENTS_SETUP_FUNCTION); + static_assert(AMS_OFFSETOF(KInitArguments, exception_stack) == INIT_ARGUMENTS_EXCEPTION_STACK); } \ No newline at end of file diff --git a/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_exception_context.hpp b/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_exception_context.hpp index 8f9b4be0d..da3ce9cc8 100644 --- a/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_exception_context.hpp +++ b/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_exception_context.hpp @@ -45,40 +45,40 @@ namespace ams::kern::arch::arm64 { }; static_assert(sizeof(KExceptionContext) == EXCEPTION_CONTEXT_SIZE); - static_assert(__builtin_offsetof(KExceptionContext, x[ 0]) == EXCEPTION_CONTEXT_X0); - static_assert(__builtin_offsetof(KExceptionContext, x[ 1]) == EXCEPTION_CONTEXT_X1); - static_assert(__builtin_offsetof(KExceptionContext, x[ 2]) == EXCEPTION_CONTEXT_X2); - static_assert(__builtin_offsetof(KExceptionContext, x[ 3]) == EXCEPTION_CONTEXT_X3); - static_assert(__builtin_offsetof(KExceptionContext, x[ 4]) == EXCEPTION_CONTEXT_X4); - static_assert(__builtin_offsetof(KExceptionContext, x[ 5]) == EXCEPTION_CONTEXT_X5); - static_assert(__builtin_offsetof(KExceptionContext, x[ 6]) == EXCEPTION_CONTEXT_X6); - static_assert(__builtin_offsetof(KExceptionContext, x[ 7]) == EXCEPTION_CONTEXT_X7); - static_assert(__builtin_offsetof(KExceptionContext, x[ 8]) == EXCEPTION_CONTEXT_X8); - static_assert(__builtin_offsetof(KExceptionContext, x[ 9]) == EXCEPTION_CONTEXT_X9); - static_assert(__builtin_offsetof(KExceptionContext, x[10]) == EXCEPTION_CONTEXT_X10); - static_assert(__builtin_offsetof(KExceptionContext, x[11]) == EXCEPTION_CONTEXT_X11); - static_assert(__builtin_offsetof(KExceptionContext, x[12]) == EXCEPTION_CONTEXT_X12); - static_assert(__builtin_offsetof(KExceptionContext, x[13]) == EXCEPTION_CONTEXT_X13); - static_assert(__builtin_offsetof(KExceptionContext, x[14]) == EXCEPTION_CONTEXT_X14); - static_assert(__builtin_offsetof(KExceptionContext, x[15]) == EXCEPTION_CONTEXT_X15); - static_assert(__builtin_offsetof(KExceptionContext, x[16]) == EXCEPTION_CONTEXT_X16); - static_assert(__builtin_offsetof(KExceptionContext, x[17]) == EXCEPTION_CONTEXT_X17); - static_assert(__builtin_offsetof(KExceptionContext, x[18]) == EXCEPTION_CONTEXT_X18); - static_assert(__builtin_offsetof(KExceptionContext, x[19]) == EXCEPTION_CONTEXT_X19); - static_assert(__builtin_offsetof(KExceptionContext, x[20]) == EXCEPTION_CONTEXT_X20); - static_assert(__builtin_offsetof(KExceptionContext, x[21]) == EXCEPTION_CONTEXT_X21); - static_assert(__builtin_offsetof(KExceptionContext, x[22]) == EXCEPTION_CONTEXT_X22); - static_assert(__builtin_offsetof(KExceptionContext, x[23]) == EXCEPTION_CONTEXT_X23); - static_assert(__builtin_offsetof(KExceptionContext, x[24]) == EXCEPTION_CONTEXT_X24); - static_assert(__builtin_offsetof(KExceptionContext, x[25]) == EXCEPTION_CONTEXT_X25); - static_assert(__builtin_offsetof(KExceptionContext, x[26]) == EXCEPTION_CONTEXT_X26); - static_assert(__builtin_offsetof(KExceptionContext, x[27]) == EXCEPTION_CONTEXT_X27); - static_assert(__builtin_offsetof(KExceptionContext, x[28]) == EXCEPTION_CONTEXT_X28); - static_assert(__builtin_offsetof(KExceptionContext, x[29]) == EXCEPTION_CONTEXT_X29); - static_assert(__builtin_offsetof(KExceptionContext, x[30]) == EXCEPTION_CONTEXT_X30); - static_assert(__builtin_offsetof(KExceptionContext, sp) == EXCEPTION_CONTEXT_SP); - static_assert(__builtin_offsetof(KExceptionContext, pc) == EXCEPTION_CONTEXT_PC); - static_assert(__builtin_offsetof(KExceptionContext, psr) == EXCEPTION_CONTEXT_PSR); - static_assert(__builtin_offsetof(KExceptionContext, tpidr) == EXCEPTION_CONTEXT_TPIDR); + static_assert(AMS_OFFSETOF(KExceptionContext, x[ 0]) == EXCEPTION_CONTEXT_X0); + static_assert(AMS_OFFSETOF(KExceptionContext, x[ 1]) == EXCEPTION_CONTEXT_X1); + static_assert(AMS_OFFSETOF(KExceptionContext, x[ 2]) == EXCEPTION_CONTEXT_X2); + static_assert(AMS_OFFSETOF(KExceptionContext, x[ 3]) == EXCEPTION_CONTEXT_X3); + static_assert(AMS_OFFSETOF(KExceptionContext, x[ 4]) == EXCEPTION_CONTEXT_X4); + static_assert(AMS_OFFSETOF(KExceptionContext, x[ 5]) == EXCEPTION_CONTEXT_X5); + static_assert(AMS_OFFSETOF(KExceptionContext, x[ 6]) == EXCEPTION_CONTEXT_X6); + static_assert(AMS_OFFSETOF(KExceptionContext, x[ 7]) == EXCEPTION_CONTEXT_X7); + static_assert(AMS_OFFSETOF(KExceptionContext, x[ 8]) == EXCEPTION_CONTEXT_X8); + static_assert(AMS_OFFSETOF(KExceptionContext, x[ 9]) == EXCEPTION_CONTEXT_X9); + static_assert(AMS_OFFSETOF(KExceptionContext, x[10]) == EXCEPTION_CONTEXT_X10); + static_assert(AMS_OFFSETOF(KExceptionContext, x[11]) == EXCEPTION_CONTEXT_X11); + static_assert(AMS_OFFSETOF(KExceptionContext, x[12]) == EXCEPTION_CONTEXT_X12); + static_assert(AMS_OFFSETOF(KExceptionContext, x[13]) == EXCEPTION_CONTEXT_X13); + static_assert(AMS_OFFSETOF(KExceptionContext, x[14]) == EXCEPTION_CONTEXT_X14); + static_assert(AMS_OFFSETOF(KExceptionContext, x[15]) == EXCEPTION_CONTEXT_X15); + static_assert(AMS_OFFSETOF(KExceptionContext, x[16]) == EXCEPTION_CONTEXT_X16); + static_assert(AMS_OFFSETOF(KExceptionContext, x[17]) == EXCEPTION_CONTEXT_X17); + static_assert(AMS_OFFSETOF(KExceptionContext, x[18]) == EXCEPTION_CONTEXT_X18); + static_assert(AMS_OFFSETOF(KExceptionContext, x[19]) == EXCEPTION_CONTEXT_X19); + static_assert(AMS_OFFSETOF(KExceptionContext, x[20]) == EXCEPTION_CONTEXT_X20); + static_assert(AMS_OFFSETOF(KExceptionContext, x[21]) == EXCEPTION_CONTEXT_X21); + static_assert(AMS_OFFSETOF(KExceptionContext, x[22]) == EXCEPTION_CONTEXT_X22); + static_assert(AMS_OFFSETOF(KExceptionContext, x[23]) == EXCEPTION_CONTEXT_X23); + static_assert(AMS_OFFSETOF(KExceptionContext, x[24]) == EXCEPTION_CONTEXT_X24); + static_assert(AMS_OFFSETOF(KExceptionContext, x[25]) == EXCEPTION_CONTEXT_X25); + static_assert(AMS_OFFSETOF(KExceptionContext, x[26]) == EXCEPTION_CONTEXT_X26); + static_assert(AMS_OFFSETOF(KExceptionContext, x[27]) == EXCEPTION_CONTEXT_X27); + static_assert(AMS_OFFSETOF(KExceptionContext, x[28]) == EXCEPTION_CONTEXT_X28); + static_assert(AMS_OFFSETOF(KExceptionContext, x[29]) == EXCEPTION_CONTEXT_X29); + static_assert(AMS_OFFSETOF(KExceptionContext, x[30]) == EXCEPTION_CONTEXT_X30); + static_assert(AMS_OFFSETOF(KExceptionContext, sp) == EXCEPTION_CONTEXT_SP); + static_assert(AMS_OFFSETOF(KExceptionContext, pc) == EXCEPTION_CONTEXT_PC); + static_assert(AMS_OFFSETOF(KExceptionContext, psr) == EXCEPTION_CONTEXT_PSR); + static_assert(AMS_OFFSETOF(KExceptionContext, tpidr) == EXCEPTION_CONTEXT_TPIDR); } \ No newline at end of file diff --git a/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_thread_context.hpp b/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_thread_context.hpp index 897641c31..eb83269b5 100644 --- a/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_thread_context.hpp +++ b/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_thread_context.hpp @@ -86,25 +86,25 @@ namespace ams::kern::arch::arm64 { consteval bool KThreadContext::ValidateOffsets() { static_assert(sizeof(KThreadContext) == THREAD_CONTEXT_SIZE); - static_assert(__builtin_offsetof(KThreadContext, m_callee_saved.registers) == THREAD_CONTEXT_CPU_REGISTERS); - static_assert(__builtin_offsetof(KThreadContext, m_callee_saved.x19) == THREAD_CONTEXT_X19); - static_assert(__builtin_offsetof(KThreadContext, m_callee_saved.x20) == THREAD_CONTEXT_X20); - static_assert(__builtin_offsetof(KThreadContext, m_callee_saved.x21) == THREAD_CONTEXT_X21); - static_assert(__builtin_offsetof(KThreadContext, m_callee_saved.x22) == THREAD_CONTEXT_X22); - static_assert(__builtin_offsetof(KThreadContext, m_callee_saved.x23) == THREAD_CONTEXT_X23); - static_assert(__builtin_offsetof(KThreadContext, m_callee_saved.x24) == THREAD_CONTEXT_X24); - static_assert(__builtin_offsetof(KThreadContext, m_callee_saved.x25) == THREAD_CONTEXT_X25); - static_assert(__builtin_offsetof(KThreadContext, m_callee_saved.x26) == THREAD_CONTEXT_X26); - static_assert(__builtin_offsetof(KThreadContext, m_callee_saved.x27) == THREAD_CONTEXT_X27); - static_assert(__builtin_offsetof(KThreadContext, m_callee_saved.x28) == THREAD_CONTEXT_X28); - static_assert(__builtin_offsetof(KThreadContext, m_callee_saved.x29) == THREAD_CONTEXT_X29); - static_assert(__builtin_offsetof(KThreadContext, m_lr) == THREAD_CONTEXT_LR); - static_assert(__builtin_offsetof(KThreadContext, m_sp) == THREAD_CONTEXT_SP); - static_assert(__builtin_offsetof(KThreadContext, m_cpacr) == THREAD_CONTEXT_CPACR); - static_assert(__builtin_offsetof(KThreadContext, m_fpcr) == THREAD_CONTEXT_FPCR); - static_assert(__builtin_offsetof(KThreadContext, m_fpsr) == THREAD_CONTEXT_FPSR); - static_assert(__builtin_offsetof(KThreadContext, m_fpu_registers) == THREAD_CONTEXT_FPU_REGISTERS); - static_assert(__builtin_offsetof(KThreadContext, m_locked) == THREAD_CONTEXT_LOCKED); + static_assert(AMS_OFFSETOF(KThreadContext, m_callee_saved.registers) == THREAD_CONTEXT_CPU_REGISTERS); + static_assert(AMS_OFFSETOF(KThreadContext, m_callee_saved.x19) == THREAD_CONTEXT_X19); + static_assert(AMS_OFFSETOF(KThreadContext, m_callee_saved.x20) == THREAD_CONTEXT_X20); + static_assert(AMS_OFFSETOF(KThreadContext, m_callee_saved.x21) == THREAD_CONTEXT_X21); + static_assert(AMS_OFFSETOF(KThreadContext, m_callee_saved.x22) == THREAD_CONTEXT_X22); + static_assert(AMS_OFFSETOF(KThreadContext, m_callee_saved.x23) == THREAD_CONTEXT_X23); + static_assert(AMS_OFFSETOF(KThreadContext, m_callee_saved.x24) == THREAD_CONTEXT_X24); + static_assert(AMS_OFFSETOF(KThreadContext, m_callee_saved.x25) == THREAD_CONTEXT_X25); + static_assert(AMS_OFFSETOF(KThreadContext, m_callee_saved.x26) == THREAD_CONTEXT_X26); + static_assert(AMS_OFFSETOF(KThreadContext, m_callee_saved.x27) == THREAD_CONTEXT_X27); + static_assert(AMS_OFFSETOF(KThreadContext, m_callee_saved.x28) == THREAD_CONTEXT_X28); + static_assert(AMS_OFFSETOF(KThreadContext, m_callee_saved.x29) == THREAD_CONTEXT_X29); + static_assert(AMS_OFFSETOF(KThreadContext, m_lr) == THREAD_CONTEXT_LR); + static_assert(AMS_OFFSETOF(KThreadContext, m_sp) == THREAD_CONTEXT_SP); + static_assert(AMS_OFFSETOF(KThreadContext, m_cpacr) == THREAD_CONTEXT_CPACR); + static_assert(AMS_OFFSETOF(KThreadContext, m_fpcr) == THREAD_CONTEXT_FPCR); + static_assert(AMS_OFFSETOF(KThreadContext, m_fpsr) == THREAD_CONTEXT_FPSR); + static_assert(AMS_OFFSETOF(KThreadContext, m_fpu_registers) == THREAD_CONTEXT_FPU_REGISTERS); + static_assert(AMS_OFFSETOF(KThreadContext, m_locked) == THREAD_CONTEXT_LOCKED); return true; } diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_scheduler.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_scheduler.hpp index c68d26581..3d953c532 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_scheduler.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_scheduler.hpp @@ -211,12 +211,12 @@ namespace ams::kern { }; consteval bool KScheduler::ValidateAssemblyOffsets() { - static_assert(__builtin_offsetof(KScheduler, m_state.needs_scheduling) == KSCHEDULER_NEEDS_SCHEDULING); - static_assert(__builtin_offsetof(KScheduler, m_state.interrupt_task_runnable) == KSCHEDULER_INTERRUPT_TASK_RUNNABLE); - static_assert(__builtin_offsetof(KScheduler, m_state.highest_priority_thread) == KSCHEDULER_HIGHEST_PRIORITY_THREAD); - static_assert(__builtin_offsetof(KScheduler, m_state.idle_thread_stack) == KSCHEDULER_IDLE_THREAD_STACK); - static_assert(__builtin_offsetof(KScheduler, m_state.prev_thread) == KSCHEDULER_PREVIOUS_THREAD); - static_assert(__builtin_offsetof(KScheduler, m_state.interrupt_task_manager) == KSCHEDULER_INTERRUPT_TASK_MANAGER); + static_assert(AMS_OFFSETOF(KScheduler, m_state.needs_scheduling) == KSCHEDULER_NEEDS_SCHEDULING); + static_assert(AMS_OFFSETOF(KScheduler, m_state.interrupt_task_runnable) == KSCHEDULER_INTERRUPT_TASK_RUNNABLE); + static_assert(AMS_OFFSETOF(KScheduler, m_state.highest_priority_thread) == KSCHEDULER_HIGHEST_PRIORITY_THREAD); + static_assert(AMS_OFFSETOF(KScheduler, m_state.idle_thread_stack) == KSCHEDULER_IDLE_THREAD_STACK); + static_assert(AMS_OFFSETOF(KScheduler, m_state.prev_thread) == KSCHEDULER_PREVIOUS_THREAD); + static_assert(AMS_OFFSETOF(KScheduler, m_state.interrupt_task_manager) == KSCHEDULER_INTERRUPT_TASK_MANAGER); return true; } diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp index 0008938bc..99d1d1b4b 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp @@ -101,18 +101,18 @@ namespace ams::kern { static_assert(alignof(StackParameters) == 0x10); static_assert(sizeof(StackParameters) == THREAD_STACK_PARAMETERS_SIZE); - static_assert(__builtin_offsetof(StackParameters, svc_access_flags) == THREAD_STACK_PARAMETERS_SVC_PERMISSION); - static_assert(__builtin_offsetof(StackParameters, context) == THREAD_STACK_PARAMETERS_CONTEXT); - static_assert(__builtin_offsetof(StackParameters, cur_thread) == THREAD_STACK_PARAMETERS_CUR_THREAD); - static_assert(__builtin_offsetof(StackParameters, disable_count) == THREAD_STACK_PARAMETERS_DISABLE_COUNT); - static_assert(__builtin_offsetof(StackParameters, dpc_flags) == THREAD_STACK_PARAMETERS_DPC_FLAGS); - static_assert(__builtin_offsetof(StackParameters, current_svc_id) == THREAD_STACK_PARAMETERS_CURRENT_SVC_ID); - static_assert(__builtin_offsetof(StackParameters, is_calling_svc) == THREAD_STACK_PARAMETERS_IS_CALLING_SVC); - static_assert(__builtin_offsetof(StackParameters, is_in_exception_handler) == THREAD_STACK_PARAMETERS_IS_IN_EXCEPTION_HANDLER); - static_assert(__builtin_offsetof(StackParameters, is_pinned) == THREAD_STACK_PARAMETERS_IS_PINNED); + static_assert(AMS_OFFSETOF(StackParameters, svc_access_flags) == THREAD_STACK_PARAMETERS_SVC_PERMISSION); + static_assert(AMS_OFFSETOF(StackParameters, context) == THREAD_STACK_PARAMETERS_CONTEXT); + static_assert(AMS_OFFSETOF(StackParameters, cur_thread) == THREAD_STACK_PARAMETERS_CUR_THREAD); + static_assert(AMS_OFFSETOF(StackParameters, disable_count) == THREAD_STACK_PARAMETERS_DISABLE_COUNT); + static_assert(AMS_OFFSETOF(StackParameters, dpc_flags) == THREAD_STACK_PARAMETERS_DPC_FLAGS); + static_assert(AMS_OFFSETOF(StackParameters, current_svc_id) == THREAD_STACK_PARAMETERS_CURRENT_SVC_ID); + static_assert(AMS_OFFSETOF(StackParameters, is_calling_svc) == THREAD_STACK_PARAMETERS_IS_CALLING_SVC); + static_assert(AMS_OFFSETOF(StackParameters, is_in_exception_handler) == THREAD_STACK_PARAMETERS_IS_IN_EXCEPTION_HANDLER); + static_assert(AMS_OFFSETOF(StackParameters, is_pinned) == THREAD_STACK_PARAMETERS_IS_PINNED); #if defined(MESOSPHERE_ENABLE_HARDWARE_SINGLE_STEP) - static_assert(__builtin_offsetof(StackParameters, is_single_step) == THREAD_STACK_PARAMETERS_IS_SINGLE_STEP); + static_assert(AMS_OFFSETOF(StackParameters, is_single_step) == THREAD_STACK_PARAMETERS_IS_SINGLE_STEP); #endif struct QueueEntry { diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_thread_local_page.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_thread_local_page.hpp index 2d48661aa..64d508ca2 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_thread_local_page.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_thread_local_page.hpp @@ -107,8 +107,8 @@ namespace ams::kern { /* Miscellaneous sanity checking. */ static_assert(ams::svc::ThreadLocalRegionSize == THREAD_LOCAL_REGION_SIZE); - static_assert(__builtin_offsetof(ams::svc::ThreadLocalRegion, message_buffer) == THREAD_LOCAL_REGION_MESSAGE_BUFFER); - static_assert(__builtin_offsetof(ams::svc::ThreadLocalRegion, disable_count) == THREAD_LOCAL_REGION_DISABLE_COUNT); - static_assert(__builtin_offsetof(ams::svc::ThreadLocalRegion, interrupt_flag) == THREAD_LOCAL_REGION_INTERRUPT_FLAG); + static_assert(AMS_OFFSETOF(ams::svc::ThreadLocalRegion, message_buffer) == THREAD_LOCAL_REGION_MESSAGE_BUFFER); + static_assert(AMS_OFFSETOF(ams::svc::ThreadLocalRegion, disable_count) == THREAD_LOCAL_REGION_DISABLE_COUNT); + static_assert(AMS_OFFSETOF(ams::svc::ThreadLocalRegion, interrupt_flag) == THREAD_LOCAL_REGION_INTERRUPT_FLAG); } diff --git a/libraries/libmesosphere/source/arch/arm64/kern_exception_handlers.cpp b/libraries/libmesosphere/source/arch/arm64/kern_exception_handlers.cpp index a8f65123c..0cb325865 100644 --- a/libraries/libmesosphere/source/arch/arm64/kern_exception_handlers.cpp +++ b/libraries/libmesosphere/source/arch/arm64/kern_exception_handlers.cpp @@ -201,13 +201,13 @@ namespace ams::kern::arch::arm64 { context->pc = GetInteger(cur_process.GetEntryPoint()); context->x[0] = type; if (is_aarch64) { - context->x[1] = GetInteger(cur_process.GetProcessLocalRegionAddress() + __builtin_offsetof(ams::svc::aarch64::ProcessLocalRegion, exception_info)); + context->x[1] = GetInteger(cur_process.GetProcessLocalRegionAddress() + AMS_OFFSETOF(ams::svc::aarch64::ProcessLocalRegion, exception_info)); auto *plr = GetPointer(cur_process.GetProcessLocalRegionAddress()); context->sp = util::AlignDown(reinterpret_cast(plr->data) + sizeof(plr->data), 0x10); context->psr = 0; } else { - context->x[1] = GetInteger(cur_process.GetProcessLocalRegionAddress() + __builtin_offsetof(ams::svc::aarch32::ProcessLocalRegion, exception_info)); + context->x[1] = GetInteger(cur_process.GetProcessLocalRegionAddress() + AMS_OFFSETOF(ams::svc::aarch32::ProcessLocalRegion, exception_info)); auto *plr = GetPointer(cur_process.GetProcessLocalRegionAddress()); context->x[13] = util::AlignDown(reinterpret_cast(plr->data) + sizeof(plr->data), 0x10); diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_nca_header.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_nca_header.hpp index b0ba6b0f9..cdecb7851 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_nca_header.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_nca_header.hpp @@ -267,9 +267,9 @@ namespace ams::fssystem { }; static_assert(sizeof(NcaFsHeader) == NcaFsHeader::Size); static_assert(util::is_pod::value); - static_assert(offsetof(NcaFsHeader, patch_info) == NcaPatchInfo::Offset); + static_assert(AMS_OFFSETOF(NcaFsHeader, patch_info) == NcaPatchInfo::Offset); - inline constexpr const size_t NcaFsHeader::HashData::HierarchicalSha256Data::MasterHashOffset = offsetof(NcaFsHeader, hash_data.hierarchical_sha256_data.fs_data_master_hash); - inline constexpr const size_t NcaFsHeader::HashData::IntegrityMetaInfo::MasterHashOffset = offsetof(NcaFsHeader, hash_data.integrity_meta_info.master_hash); + inline constexpr const size_t NcaFsHeader::HashData::HierarchicalSha256Data::MasterHashOffset = AMS_OFFSETOF(NcaFsHeader, hash_data.hierarchical_sha256_data.fs_data_master_hash); + inline constexpr const size_t NcaFsHeader::HashData::IntegrityMetaInfo::MasterHashOffset = AMS_OFFSETOF(NcaFsHeader, hash_data.integrity_meta_info.master_hash); } diff --git a/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta.hpp index d447697bc..eb5cd327b 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta.hpp @@ -78,8 +78,8 @@ namespace ams::ncm { u8 reserved_1C[4]; }; static_assert(sizeof(PackagedContentMetaHeader) == 0x20); - static_assert(OFFSETOF(PackagedContentMetaHeader, reserved_0D) == 0x0D); - static_assert(OFFSETOF(PackagedContentMetaHeader, reserved_1C) == 0x1C); + static_assert(AMS_OFFSETOF(PackagedContentMetaHeader, reserved_0D) == 0x0D); + static_assert(AMS_OFFSETOF(PackagedContentMetaHeader, reserved_1C) == 0x1C); using InstallContentMetaHeader = PackagedContentMetaHeader; diff --git a/libraries/libstratosphere/include/stratosphere/ro/ro_types.hpp b/libraries/libstratosphere/include/stratosphere/ro/ro_types.hpp index fb716b028..d6da9e36f 100644 --- a/libraries/libstratosphere/include/stratosphere/ro/ro_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/ro/ro_types.hpp @@ -129,7 +129,7 @@ namespace ams::ro { static_assert(sizeof(NrrHeader) == 0x350, "NrrHeader definition!"); constexpr size_t NrrHeader::GetSignedAreaOffset() { - return OFFSETOF(NrrHeader, m_program_id); + return AMS_OFFSETOF(NrrHeader, m_program_id); } class NroHeader { diff --git a/libraries/libstratosphere/include/stratosphere/sf/sf_default_allocation_policy.hpp b/libraries/libstratosphere/include/stratosphere/sf/sf_default_allocation_policy.hpp index 8c243960f..64a491eb0 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/sf_default_allocation_policy.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/sf_default_allocation_policy.hpp @@ -35,13 +35,13 @@ namespace ams::sf { void *Allocate(size_t size) { AMS_ASSERT(size == sizeof(T)); AMS_UNUSED(size); - return DefaultAllocateImpl(sizeof(Holder), alignof(Holder), offsetof(Holder, storage)); + return DefaultAllocateImpl(sizeof(Holder), alignof(Holder), AMS_OFFSETOF(Holder, storage)); } void Deallocate(void *ptr, size_t size) { AMS_ASSERT(size == sizeof(T)); AMS_UNUSED(size); - return DefaultDeallocateImpl(ptr, sizeof(Holder), alignof(Holder), offsetof(Holder, storage)); + return DefaultDeallocateImpl(ptr, sizeof(Holder), alignof(Holder), AMS_OFFSETOF(Holder, storage)); } }; diff --git a/libraries/libstratosphere/include/stratosphere/tipc/tipc_deferral_manager.hpp b/libraries/libstratosphere/include/stratosphere/tipc/tipc_deferral_manager.hpp index 08c5faed6..c087c3941 100644 --- a/libraries/libstratosphere/include/stratosphere/tipc/tipc_deferral_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/tipc/tipc_deferral_manager.hpp @@ -164,12 +164,12 @@ namespace ams::tipc { }; consteval size_t DeferralManagerBase::GetObjectPointersOffsetBase() { - return OFFSETOF(DeferralManagerBase, m_objects_base); + return AMS_OFFSETOF(DeferralManagerBase, m_objects_base); } template consteval size_t DeferralManager::GetObjectPointersOffset() { - return OFFSETOF(DeferralManager, m_objects); + return AMS_OFFSETOF(DeferralManager, m_objects); } template diff --git a/libraries/libstratosphere/source/fssrv/fscreator/fssrv_storage_on_nca_creator.cpp b/libraries/libstratosphere/source/fssrv/fscreator/fssrv_storage_on_nca_creator.cpp index 14114df77..c50551681 100644 --- a/libraries/libstratosphere/source/fssrv/fscreator/fssrv_storage_on_nca_creator.cpp +++ b/libraries/libstratosphere/source/fssrv/fscreator/fssrv_storage_on_nca_creator.cpp @@ -26,19 +26,19 @@ namespace ams::fssrv::fscreator { size_t size; /* Read the Acid signature key generation. */ - constexpr s64 AcidSignatureKeyGenerationOffset = offsetof(ldr::Npdm, signature_key_generation); + constexpr s64 AcidSignatureKeyGenerationOffset = AMS_OFFSETOF(ldr::Npdm, signature_key_generation); u32 acid_signature_key_generation; R_TRY(file->Read(std::addressof(size), AcidSignatureKeyGenerationOffset, std::addressof(acid_signature_key_generation), sizeof(acid_signature_key_generation), fs::ReadOption())); R_UNLESS(size == sizeof(acid_signature_key_generation), fs::ResultInvalidAcidFileSize()); /* Read the Acid offset. */ - constexpr s64 AcidOffsetOffset = offsetof(ldr::Npdm, acid_offset); + constexpr s64 AcidOffsetOffset = AMS_OFFSETOF(ldr::Npdm, acid_offset); s32 acid_offset; R_TRY(file->Read(std::addressof(size), AcidOffsetOffset, std::addressof(acid_offset), sizeof(acid_offset), fs::ReadOption())); R_UNLESS(size == sizeof(acid_offset), fs::ResultInvalidAcidFileSize()); /* Read the Acid size. */ - constexpr s64 AcidSizeOffset = offsetof(ldr::Npdm, acid_size); + constexpr s64 AcidSizeOffset = AMS_OFFSETOF(ldr::Npdm, acid_size); s32 acid_size; R_TRY(file->Read(std::addressof(size), AcidSizeOffset, std::addressof(acid_size), sizeof(acid_size), fs::ReadOption())); R_UNLESS(size == sizeof(acid_size), fs::ResultInvalidAcidFileSize()); diff --git a/libraries/libstratosphere/source/os/impl/os_thread_manager_types.hpp b/libraries/libstratosphere/source/os/impl/os_thread_manager_types.hpp index e4de4b738..2e3a1e753 100644 --- a/libraries/libstratosphere/source/os/impl/os_thread_manager_types.hpp +++ b/libraries/libstratosphere/source/os/impl/os_thread_manager_types.hpp @@ -42,7 +42,7 @@ namespace ams::os::impl { return GetReference(parent.all_threads_node); } - static constexpr size_t Offset = OFFSETOF(ThreadType, all_threads_node); + static constexpr size_t Offset = AMS_OFFSETOF(ThreadType, all_threads_node); static ThreadType &GetParent(util::IntrusiveListNode &node) { return *reinterpret_cast(reinterpret_cast(std::addressof(node)) - Offset); diff --git a/libraries/libstratosphere/source/osdbg/impl/osdbg_thread_local_region.os.horizon.hpp b/libraries/libstratosphere/source/osdbg/impl/osdbg_thread_local_region.os.horizon.hpp index 3d3d7d0c2..c77f3222c 100644 --- a/libraries/libstratosphere/source/osdbg/impl/osdbg_thread_local_region.os.horizon.hpp +++ b/libraries/libstratosphere/source/osdbg/impl/osdbg_thread_local_region.os.horizon.hpp @@ -34,7 +34,7 @@ namespace ams::osdbg::impl { u64 p_thread_type; }; static_assert(sizeof(ThreadLocalRegionLp64) == sizeof(svc::ThreadLocalRegion)); - static_assert(__builtin_offsetof(ThreadLocalRegionLp64, tls) == 0x180); + static_assert(AMS_OFFSETOF(ThreadLocalRegionLp64, tls) == 0x180); struct ThreadLocalRegionIlp32 { @@ -51,7 +51,7 @@ namespace ams::osdbg::impl { u32 p_thread_type; }; static_assert(sizeof(ThreadLocalRegionIlp32) == sizeof(svc::ThreadLocalRegion)); - static_assert(__builtin_offsetof(ThreadLocalRegionIlp32, tls) == 0x1C0); + static_assert(AMS_OFFSETOF(ThreadLocalRegionIlp32, tls) == 0x1C0); struct LibnxThreadVars { static constexpr u32 Magic = util::FourCC<'!','T','V','$'>::Code; @@ -73,7 +73,7 @@ namespace ams::osdbg::impl { LibnxThreadVars thread_vars; }; static_assert(sizeof(ThreadLocalRegionLibnx) == sizeof(svc::ThreadLocalRegion)); - static_assert(__builtin_offsetof(ThreadLocalRegionLibnx, thread_vars) == 0x1E0); + static_assert(AMS_OFFSETOF(ThreadLocalRegionLibnx, thread_vars) == 0x1E0); struct LibnxThreadEntryArgs { u64 t; diff --git a/libraries/libstratosphere/source/spl/impl/spl_api_impl.cpp b/libraries/libstratosphere/source/spl/impl/spl_api_impl.cpp index 0504e2bc6..ed1fe8833 100644 --- a/libraries/libstratosphere/source/spl/impl/spl_api_impl.cpp +++ b/libraries/libstratosphere/source/spl/impl/spl_api_impl.cpp @@ -297,10 +297,10 @@ namespace ams::spl::impl { auto &layout = *reinterpret_cast(g_work_buffer); layout.crypt_ctx.in.num_entries = 0; - layout.crypt_ctx.in.address = g_work_buffer_mapped_address + offsetof(DecryptAesLayout, in_buffer); + layout.crypt_ctx.in.address = g_work_buffer_mapped_address + AMS_OFFSETOF(DecryptAesLayout, in_buffer); layout.crypt_ctx.in.size = sizeof(layout.in_buffer); layout.crypt_ctx.out.num_entries = 0; - layout.crypt_ctx.out.address = g_work_buffer_mapped_address + offsetof(DecryptAesLayout, out_buffer); + layout.crypt_ctx.out.address = g_work_buffer_mapped_address + AMS_OFFSETOF(DecryptAesLayout, out_buffer); layout.crypt_ctx.out.size = sizeof(layout.out_buffer); std::memcpy(layout.in_buffer, src, sizeof(layout.in_buffer)); @@ -312,8 +312,8 @@ namespace ams::spl::impl { smc::AsyncOperationKey op_key; const IvCtr iv_ctr = {}; const u32 mode = smc::GetComputeAesMode(smc::CipherMode::CbcDecrypt, GetPhysicalAesKeySlot(keyslot, true)); - const u32 dst_ll_addr = g_work_buffer_mapped_address + offsetof(DecryptAesLayout, crypt_ctx.out); - const u32 src_ll_addr = g_work_buffer_mapped_address + offsetof(DecryptAesLayout, crypt_ctx.in); + const u32 dst_ll_addr = g_work_buffer_mapped_address + AMS_OFFSETOF(DecryptAesLayout, crypt_ctx.out); + const u32 src_ll_addr = g_work_buffer_mapped_address + AMS_OFFSETOF(DecryptAesLayout, crypt_ctx.in); smc::Result res = smc::ComputeAes(std::addressof(op_key), dst_ll_addr, mode, iv_ctr, src_ll_addr, sizeof(layout.out_buffer)); if (res != smc::Result::Success) { @@ -666,8 +666,8 @@ namespace ams::spl::impl { std::scoped_lock lk(g_operation_lock); const u32 mode = smc::GetComputeAesMode(smc::CipherMode::Ctr, GetPhysicalAesKeySlot(keyslot, true)); - const u32 dst_ll_addr = g_work_buffer_mapped_address + offsetof(SeCryptContext, out); - const u32 src_ll_addr = g_work_buffer_mapped_address + offsetof(SeCryptContext, in); + const u32 dst_ll_addr = g_work_buffer_mapped_address + AMS_OFFSETOF(SeCryptContext, out); + const u32 src_ll_addr = g_work_buffer_mapped_address + AMS_OFFSETOF(SeCryptContext, in); smc::AsyncOperationKey op_key; smc::Result res = smc::ComputeAes(std::addressof(op_key), dst_ll_addr, mode, iv_ctr, src_ll_addr, src_size); diff --git a/libraries/libvapours/include/vapours/crypto/impl/crypto_hmac_impl.hpp b/libraries/libvapours/include/vapours/crypto/impl/crypto_hmac_impl.hpp index 3f2c1ecd1..d8f7a44fc 100644 --- a/libraries/libvapours/include/vapours/crypto/impl/crypto_hmac_impl.hpp +++ b/libraries/libvapours/include/vapours/crypto/impl/crypto_hmac_impl.hpp @@ -50,7 +50,7 @@ namespace ams::crypto::impl { public: HmacImpl() : m_state(State_None) { /* ... */ } ~HmacImpl() { - static_assert(offsetof(HmacImpl, m_hash_function) == 0); + static_assert(AMS_OFFSETOF(HmacImpl, m_hash_function) == 0); /* Clear everything except for the hash function. */ ClearMemory(reinterpret_cast(this) + sizeof(m_hash_function), sizeof(*this) - sizeof(m_hash_function)); diff --git a/libraries/libvapours/include/vapours/svc/svc_types_common.hpp b/libraries/libvapours/include/vapours/svc/svc_types_common.hpp index 6a776bbce..6b85c1452 100644 --- a/libraries/libvapours/include/vapours/svc/svc_types_common.hpp +++ b/libraries/libvapours/include/vapours/svc/svc_types_common.hpp @@ -563,7 +563,7 @@ namespace ams::svc { u64 padding[6]; }; static_assert(sizeof(ProcessLocalRegion) == 0x200); - static_assert(OFFSETOF(ProcessLocalRegion, dying_message_region_address) == 0x1C0); + static_assert(AMS_OFFSETOF(ProcessLocalRegion, dying_message_region_address) == 0x1C0); } @@ -607,7 +607,7 @@ namespace ams::svc { u64 padding[6]; }; static_assert(sizeof(ProcessLocalRegion) == 0x200); - static_assert(OFFSETOF(ProcessLocalRegion, dying_message_region_address) == 0x1C0); + static_assert(AMS_OFFSETOF(ProcessLocalRegion, dying_message_region_address) == 0x1C0); } diff --git a/libraries/libvapours/include/vapours/util/util_parent_of_member.hpp b/libraries/libvapours/include/vapours/util/util_parent_of_member.hpp index 74ddc40f7..fb4ea630d 100644 --- a/libraries/libvapours/include/vapours/util/util_parent_of_member.hpp +++ b/libraries/libvapours/include/vapours/util/util_parent_of_member.hpp @@ -170,11 +170,8 @@ namespace ams::util { /* Defines, for use by other code. */ - - #define OFFSETOF(parent, member) (::ams::util::impl::OffsetOf<&parent::member, parent>::value) - - #define GET_PARENT_PTR(parent, member, _arg) (::ams::util::GetParentPointer<&parent::member, parent>(_arg)) - - #define GET_PARENT_REF(parent, member, _arg) (::ams::util::GetParentReference<&parent::member, parent>(_arg)) + #define AMS_OFFSETOF(parent, member) (__builtin_offsetof(parent, member)) + #define AMS_GET_PARENT_PTR(parent, member, _arg) (::ams::util::GetParentPointer<&parent::member, parent>(_arg)) + #define AMS_GET_PARENT_REF(parent, member, _arg) (::ams::util::GetParentReference<&parent::member, parent>(_arg)) } diff --git a/libraries/libvapours/source/crypto/impl/crypto_gcm_mode_impl.arch.arm64.cpp b/libraries/libvapours/source/crypto/impl/crypto_gcm_mode_impl.arch.arm64.cpp index e7086b049..b63720e27 100644 --- a/libraries/libvapours/source/crypto/impl/crypto_gcm_mode_impl.arch.arm64.cpp +++ b/libraries/libvapours/source/crypto/impl/crypto_gcm_mode_impl.arch.arm64.cpp @@ -272,7 +272,7 @@ namespace ams::crypto::impl { Block last_block = Block{ .block_128 = { m_msg_size, m_aad_size } }; /* Multiply the last block by 8 to account for bit vs byte sizes. */ - static_assert(offsetof(Block128, hi) == 0); + static_assert(AMS_OFFSETOF(Block128, hi) == 0); GaloisShiftLeft(std::addressof(last_block.block_128.hi)); GaloisShiftLeft(std::addressof(last_block.block_128.hi)); GaloisShiftLeft(std::addressof(last_block.block_128.hi)); diff --git a/libraries/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.hpp b/libraries/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.hpp index f4f94cadb..3ac8f3969 100644 --- a/libraries/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.hpp +++ b/libraries/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.hpp @@ -123,7 +123,7 @@ namespace ams::sdmmc::impl { public: explicit SdmmcController(dd::PhysicalAddress registers_phys_addr) : SdHostStandardController(registers_phys_addr, SdmmcRegistersSize) { /* Set sdmmc registers. */ - static_assert(offsetof(SdmmcRegisters, sd_host_standard_registers) == 0); + static_assert(AMS_OFFSETOF(SdmmcRegisters, sd_host_standard_registers) == 0); m_sdmmc_registers = reinterpret_cast(m_registers); m_is_shutdown = true; diff --git a/stratosphere/ams_mitm/source/amsmitm_prodinfo_utils.cpp b/stratosphere/ams_mitm/source/amsmitm_prodinfo_utils.cpp index 69740191b..4236a845b 100644 --- a/stratosphere/ams_mitm/source/amsmitm_prodinfo_utils.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_prodinfo_utils.cpp @@ -119,7 +119,7 @@ namespace ams::mitm { } bool IsValid(const CalibrationInfoHeader &header) { - return header.magic == CalibrationMagic && GetCrc16(std::addressof(header), OFFSETOF(CalibrationInfoHeader, crc)) == header.crc; + return header.magic == CalibrationMagic && GetCrc16(std::addressof(header), AMS_OFFSETOF(CalibrationInfoHeader, crc)) == header.crc; } bool IsValid(const CalibrationInfoHeader &header, const void *body) { @@ -213,7 +213,7 @@ namespace ams::mitm { /* Set header. */ info.header.magic = CalibrationMagic; info.header.body_size = sizeof(info.body); - info.header.crc = GetCrc16(std::addressof(info.header), OFFSETOF(CalibrationInfoHeader, crc)); + info.header.crc = GetCrc16(std::addressof(info.header), AMS_OFFSETOF(CalibrationInfoHeader, crc)); /* Set blocks. */ Blank(info.GetBlock()); diff --git a/stratosphere/creport/source/creport_crash_report.cpp b/stratosphere/creport/source/creport_crash_report.cpp index e4d147dd8..bbb405adb 100644 --- a/stratosphere/creport/source/creport_crash_report.cpp +++ b/stratosphere/creport/source/creport_crash_report.cpp @@ -23,8 +23,8 @@ namespace ams::creport { /* Convenience definitions. */ constexpr size_t DyingMessageAddressOffset = 0x1C0; - static_assert(DyingMessageAddressOffset == OFFSETOF(ams::svc::aarch64::ProcessLocalRegion, dying_message_region_address)); - static_assert(DyingMessageAddressOffset == OFFSETOF(ams::svc::aarch32::ProcessLocalRegion, dying_message_region_address)); + static_assert(DyingMessageAddressOffset == AMS_OFFSETOF(ams::svc::aarch64::ProcessLocalRegion, dying_message_region_address)); + static_assert(DyingMessageAddressOffset == AMS_OFFSETOF(ams::svc::aarch32::ProcessLocalRegion, dying_message_region_address)); /* Helper functions. */ bool TryGetCurrentTimestamp(u64 *out) {