From 7d041e853d3868fd6d3ba06fb94dbf6ffd817d10 Mon Sep 17 00:00:00 2001 From: SciresM Date: Mon, 11 May 2020 15:02:10 -0700 Subject: [PATCH] Switch atmosphere's build target to C++20. (#952) * ams: update to build with gcc10/c++20 * remove mno-outline-atomics * ams: take care of most TODO C++20s * fusee/sept: update for gcc10 * whoosh, your code now uses pre-compiled headers * make: dependency fixes --- config/common.mk | 2 +- libmesosphere/Makefile | 5 +- .../arm64/kern_k_interrupt_controller.hpp | 8 +- .../mesosphere/init/kern_init_layout.hpp | 2 +- .../include/mesosphere/kern_k_auto_object.hpp | 5 +- .../mesosphere/kern_k_capabilities.hpp | 4 +- .../mesosphere/kern_k_current_context.hpp | 4 +- .../mesosphere/kern_k_page_table_base.hpp | 2 +- .../mesosphere/kern_k_priority_queue.hpp | 51 ++--- .../include/mesosphere/kern_k_scheduler.hpp | 11 +- .../mesosphere/kern_k_scheduler_lock.hpp | 19 +- .../include/mesosphere/kern_k_scoped_lock.hpp | 17 +- .../svc/kern_svc_k_user_pointer.hpp | 85 ++++---- .../source/kern_k_address_space_info.cpp | 26 +-- libmesosphere/source/kern_k_object_name.cpp | 5 +- libstratosphere/Makefile | 7 +- .../include/stratosphere/ams/ams_types.hpp | 2 +- .../capsrv_screen_shot_decode_option.hpp | 2 +- .../include/stratosphere/cfg/cfg_types.hpp | 2 +- .../stratosphere/dmnt/dmnt_cheat_types.hpp | 6 +- .../include/stratosphere/erpt/erpt_types.hpp | 4 +- .../stratosphere/fatal/fatal_types.hpp | 124 +++++------ .../include/stratosphere/fs/fs_common.hpp | 2 +- .../fs/fs_dbm_hierarchical_rom_file_table.hpp | 10 +- .../fs/fs_dbm_rom_key_value_storage.hpp | 4 +- .../stratosphere/fs/fs_dbm_rom_path_tool.hpp | 2 +- .../stratosphere/fs/fs_dbm_rom_types.hpp | 6 +- .../include/stratosphere/fs/fs_file.hpp | 4 +- .../stratosphere/fs/fs_memory_management.hpp | 2 +- .../stratosphere/fs/fs_query_range.hpp | 2 +- .../include/stratosphere/fs/fs_rights_id.hpp | 2 +- .../stratosphere/fs/fs_save_data_types.hpp | 6 +- .../stratosphere/fssrv/fssrv_sf_path.hpp | 2 +- .../fssystem_file_system_buddy_heap.hpp | 2 +- ...system_dbm_hierarchical_rom_file_table.hpp | 10 +- .../fssystem_dbm_rom_key_value_storage.hpp | 4 +- .../fssystem/fssystem_dbm_rom_path_tool.hpp | 2 +- .../fssystem/fssystem_dbm_rom_types.hpp | 6 +- .../fssystem_partition_file_system_meta.hpp | 4 +- .../kvdb/kvdb_file_key_value_cache.hpp | 2 +- .../kvdb/kvdb_file_key_value_store.hpp | 10 +- .../kvdb/kvdb_memory_key_value_store.hpp | 10 +- .../include/stratosphere/ldr/ldr_types.hpp | 12 +- .../include/stratosphere/lr/lr_types.hpp | 2 +- .../stratosphere/mem/impl/mem_impl_common.hpp | 2 +- .../stratosphere/ncm/ncm_content_info.hpp | 2 +- .../ncm/ncm_content_manager_impl.hpp | 2 +- .../stratosphere/ncm/ncm_program_location.hpp | 2 +- .../stratosphere/ncm/ncm_rights_id.hpp | 2 +- .../stratosphere/os/os_rw_lock_types.hpp | 2 +- .../include/stratosphere/pgl/pgl_types.hpp | 2 +- .../include/stratosphere/pm/pm_types.hpp | 2 +- libstratosphere/include/stratosphere/reg.hpp | 6 +- .../factory/settings_device_certificate.hpp | 6 +- .../factory/settings_serial_number.hpp | 2 +- .../settings/settings_fwdbg_types.hpp | 4 +- .../stratosphere/settings/settings_types.hpp | 4 +- .../cmif/sf_cmif_server_message_processor.hpp | 2 +- .../sf/cmif/sf_cmif_service_dispatch.hpp | 2 +- .../sf/impl/sf_impl_command_serialization.hpp | 10 +- .../include/stratosphere/sf/sf_out.hpp | 4 +- libstratosphere/source/ams/ams_emummc_api.cpp | 1 - .../source/ams/ams_environment.cpp | 4 +- .../source/ams/ams_exosphere_api.cpp | 1 - .../decodersrv_decoder_work_memory.hpp | 2 +- libstratosphere/source/cfg/cfg_flags.cpp | 1 - libstratosphere/source/cfg/cfg_override.cpp | 1 - .../source/cfg/cfg_privileged_process.cpp | 1 - libstratosphere/source/cfg/cfg_sd_card.cpp | 1 - .../source/fs/fs_file_path_hash.hpp | 2 +- .../source/fs/fsa/fs_mount_name.hpp | 2 +- .../fssystem_partition_file_system_meta.cpp | 2 +- .../fssystem/fssystem_romfs_filesystem.cpp | 10 +- libstratosphere/source/kvdb/kvdb_archive.cpp | 5 +- .../source/kvdb/kvdb_file_key_value_store.cpp | 1 - libstratosphere/source/map/map_api.cpp | 1 - .../heap/mem_impl_heap_tls_heap_static.hpp | 8 +- .../ncm/ncm_content_meta_database_impl.cpp | 2 +- .../source/os/impl/os_resource_manager.cpp | 3 +- .../os/impl/os_waitable_manager_impl.cpp | 1 + libstratosphere/source/os/os_event.cpp | 1 + .../source/os/os_interrupt_event.cpp | 1 + .../source/os/os_message_queue.cpp | 1 + libstratosphere/source/os/os_semaphore.cpp | 1 + .../source/pgl/srv/pgl_srv_shell.cpp | 2 +- libstratosphere/source/sm/sm_api.cpp | 1 + libstratosphere/source/sm/sm_manager_api.cpp | 1 + libstratosphere/source/sm/sm_mitm_api.cpp | 1 + libstratosphere/source/sm/sm_utils.cpp | 1 + .../source/updater/updater_api.cpp | 2 - .../source/updater/updater_bis_management.cpp | 1 + .../source/updater/updater_bis_save.cpp | 1 + .../source/updater/updater_files.cpp | 1 + .../source/updater/updater_paths.cpp | 1 + libstratosphere/source/util/ini.c | 3 + .../crypto/crypto_rsa_oaep_decryptor.hpp | 2 +- .../crypto/crypto_rsa_oaep_encryptor.hpp | 2 +- .../crypto/crypto_rsa_pss_verifier.hpp | 2 +- .../crypto/impl/crypto_hash_function.hpp | 18 +- .../crypto/impl/crypto_rsa_oaep_impl.hpp | 2 +- .../crypto/impl/crypto_rsa_pss_impl.hpp | 2 +- .../crypto/impl/crypto_sha256_impl.hpp | 2 +- libvapours/include/vapours/defines.hpp | 3 - libvapours/include/vapours/includes.hpp | 3 + libvapours/include/vapours/span.hpp | 202 +----------------- .../impl/svc_codegen_impl_code_generator.hpp | 7 +- .../codegen/impl/svc_codegen_impl_common.hpp | 2 +- .../svc_codegen_impl_kernel_svc_wrapper.hpp | 93 ++++---- .../codegen/impl/svc_codegen_impl_layout.hpp | 12 +- .../svc_codegen_impl_layout_conversion.hpp | 22 +- .../impl/svc_codegen_impl_meta_code.hpp | 19 +- .../impl/svc_codegen_impl_parameter.hpp | 6 +- .../vapours/svc/ipc/svc_message_buffer.hpp | 26 +-- libvapours/include/vapours/util.hpp | 1 + .../include/vapours/util/util_bitpack.hpp | 10 +- .../include/vapours/util/util_bitutil.hpp | 42 ++-- .../include/vapours/util/util_endian.hpp | 30 +-- .../include/vapours/util/util_fourcc.hpp | 15 +- .../include/vapours/util/util_type_traits.hpp | 26 +++ 119 files changed, 474 insertions(+), 698 deletions(-) create mode 100644 libvapours/include/vapours/util/util_type_traits.hpp diff --git a/config/common.mk b/config/common.mk index 964a7d0a..4d68b232 100644 --- a/config/common.mk +++ b/config/common.mk @@ -18,7 +18,7 @@ export ATMOSPHERE_DEFINES := -DATMOSPHERE export ATMOSPHERE_SETTINGS := -fPIE -g export ATMOSPHERE_CFLAGS := -Wall -ffunction-sections -fdata-sections -fno-strict-aliasing -fwrapv \ -fno-asynchronous-unwind-tables -fno-unwind-tables -fno-stack-protector -export ATMOSPHERE_CXXFLAGS := -fno-rtti -fno-exceptions -std=gnu++17 +export ATMOSPHERE_CXXFLAGS := -fno-rtti -fno-exceptions -std=gnu++20 export ATMOSPHERE_ASFLAGS := diff --git a/libmesosphere/Makefile b/libmesosphere/Makefile index c9c190e9..747fd285 100644 --- a/libmesosphere/Makefile +++ b/libmesosphere/Makefile @@ -6,8 +6,7 @@ include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/../config/common.mk #--------------------------------------------------------------------------------- # options for code generation #--------------------------------------------------------------------------------- -#PRECOMPILED_HEADERS := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/include/mesosphere.hpp -PRECOMPILED_HEADERS := +PRECOMPILED_HEADERS := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/include/mesosphere.hpp DEFINES := $(ATMOSPHERE_DEFINES) -DATMOSPHERE_IS_MESOSPHERE SETTINGS := $(ATMOSPHERE_SETTINGS) -O2 -mgeneral-regs-only -ffixed-x18 -Werror -fno-non-call-exceptions @@ -122,6 +121,8 @@ $(filter-out kern_svc_tables.o, $(OFILES)) : $(GCH_FILES) $(OFILES_SRC) : $(HFILES_BIN) +kern_libc_generic.o: CFLAGS += -fno-builtin + #--------------------------------------------------------------------------------- %_bin.h %.bin.o : %.bin #--------------------------------------------------------------------------------- diff --git a/libmesosphere/include/mesosphere/arch/arm64/kern_k_interrupt_controller.hpp b/libmesosphere/include/mesosphere/arch/arm64/kern_k_interrupt_controller.hpp index a6d7a180..ce276c1a 100644 --- a/libmesosphere/include/mesosphere/arch/arm64/kern_k_interrupt_controller.hpp +++ b/libmesosphere/include/mesosphere/arch/arm64/kern_k_interrupt_controller.hpp @@ -72,7 +72,7 @@ namespace ams::kern::arch::arm64 { SgirTargetListFilter_Reserved = (3 << 24), }; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(sizeof(GicDistributor) == 0x1000); struct GicCpuInterface { @@ -98,7 +98,7 @@ namespace ams::kern::arch::arm64 { u32 dir; u32 _0x1004[1023]; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(sizeof(GicCpuInterface) == 0x2000); struct KInterruptController { @@ -164,11 +164,11 @@ namespace ams::kern::arch::arm64 { } void SetTarget(s32 irq, s32 core_id) const { - this->gicd->itargetsr.bytes[irq] |= GetGicMask(core_id); + this->gicd->itargetsr.bytes[irq] = this->gicd->itargetsr.bytes[irq] | GetGicMask(core_id); } void ClearTarget(s32 irq, s32 core_id) const { - this->gicd->itargetsr.bytes[irq] &= ~GetGicMask(core_id); + this->gicd->itargetsr.bytes[irq] = this->gicd->itargetsr.bytes[irq] & ~GetGicMask(core_id); } void SetPriorityLevel(s32 irq, s32 level) const { diff --git a/libmesosphere/include/mesosphere/init/kern_init_layout.hpp b/libmesosphere/include/mesosphere/init/kern_init_layout.hpp index 620ef85f..3d379ca0 100644 --- a/libmesosphere/include/mesosphere/init/kern_init_layout.hpp +++ b/libmesosphere/include/mesosphere/init/kern_init_layout.hpp @@ -32,7 +32,7 @@ namespace ams::kern::init { u32 init_array_offset; u32 init_array_end_offset; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(sizeof(KernelLayout) == 0x30); } \ No newline at end of file diff --git a/libmesosphere/include/mesosphere/kern_k_auto_object.hpp b/libmesosphere/include/mesosphere/kern_k_auto_object.hpp index 2ffc2869..01648d3e 100644 --- a/libmesosphere/include/mesosphere/kern_k_auto_object.hpp +++ b/libmesosphere/include/mesosphere/kern_k_auto_object.hpp @@ -185,10 +185,7 @@ namespace ams::kern { T *obj; private: constexpr ALWAYS_INLINE void Swap(KScopedAutoObject &rhs) { - /* TODO: C++20 constexpr std::swap */ - T *tmp = rhs.obj; - rhs.obj = this->obj; - this->obj = tmp; + std::swap(this->obj, rhs.obj); } public: constexpr ALWAYS_INLINE KScopedAutoObject() : obj(nullptr) { /* ... */ } diff --git a/libmesosphere/include/mesosphere/kern_k_capabilities.hpp b/libmesosphere/include/mesosphere/kern_k_capabilities.hpp index bac44a21..72d48666 100644 --- a/libmesosphere/include/mesosphere/kern_k_capabilities.hpp +++ b/libmesosphere/include/mesosphere/kern_k_capabilities.hpp @@ -64,7 +64,7 @@ namespace ams::kern { static constexpr u32 GetCapabilityId(CapabilityType type) { const u32 flag = GetCapabilityFlag(type); - if (true /* C++20: std::is_constant_evaluated() */) { + if (std::is_constant_evaluated()) { return CountTrailingZero(flag); } else { return static_cast(__builtin_ctz(flag)); @@ -84,7 +84,7 @@ namespace ams::kern { template static constexpr inline u32 CapabilityId = []() -> u32 { const u32 flag = static_cast(Type) + 1; - if (true /* C++20: std::is_constant_evaluated() */) { + if (std::is_constant_evaluated()) { for (u32 i = 0; i < BITSIZEOF(u32); i++) { if (flag & (1u << i)) { return i; diff --git a/libmesosphere/include/mesosphere/kern_k_current_context.hpp b/libmesosphere/include/mesosphere/kern_k_current_context.hpp index ae8a7947..442f04fe 100644 --- a/libmesosphere/include/mesosphere/kern_k_current_context.hpp +++ b/libmesosphere/include/mesosphere/kern_k_current_context.hpp @@ -31,8 +31,10 @@ namespace ams::kern { s32 core_id; void *exception_stack_top; }; - static_assert(std::is_pod::value); + static_assert(std::is_standard_layout::value && std::is_trivially_destructible::value); static_assert(sizeof(KCurrentContext) <= cpu::DataCacheLineSize); + static_assert(sizeof(std::atomic) == sizeof(KThread *)); + static_assert(sizeof(std::atomic) == sizeof(KProcess *)); namespace impl { diff --git a/libmesosphere/include/mesosphere/kern_k_page_table_base.hpp b/libmesosphere/include/mesosphere/kern_k_page_table_base.hpp index 0ebfb206..2298dd9d 100644 --- a/libmesosphere/include/mesosphere/kern_k_page_table_base.hpp +++ b/libmesosphere/include/mesosphere/kern_k_page_table_base.hpp @@ -65,7 +65,7 @@ namespace ams::kern { Node *next; u8 buffer[PageSize - sizeof(Node *)]; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); private: Node *root; public: diff --git a/libmesosphere/include/mesosphere/kern_k_priority_queue.hpp b/libmesosphere/include/mesosphere/kern_k_priority_queue.hpp index 3b471b4d..033c5937 100644 --- a/libmesosphere/include/mesosphere/kern_k_priority_queue.hpp +++ b/libmesosphere/include/mesosphere/kern_k_priority_queue.hpp @@ -18,39 +18,34 @@ namespace ams::kern { - /* - TODO: C++20 + template + concept KPriorityQueueAffinityMask = !std::is_reference::value && requires (T &t) { + { t.GetAffinityMask() } -> std::convertible_to; + { t.SetAffinityMask(std::declval()) }; - template - concept KPriorityQueueAffinityMask = !std::is_reference::value && requires (T &t) { - { t.GetAffinityMask() } -> std::convertible_to; - { t.SetAffinityMask(std::declval()) }; + { t.GetAffinity(std::declval()) } -> std::same_as; + { t.SetAffinity(std::declval(), std::declval()) }; + { t.SetAll() }; + }; - { t.GetAffinity(std::declval()) } -> std::same_as; - { t.SetAffinity(std::declval(), std::declval()) }; - { t.SetAll() }; - }; + template + concept KPriorityQueueMember = !std::is_reference::value && requires (T &t) { + { typename T::QueueEntry() }; + { (typename T::QueueEntry()).Initialize() }; + { (typename T::QueueEntry()).SetPrev(std::addressof(t)) }; + { (typename T::QueueEntry()).SetNext(std::addressof(t)) }; + { (typename T::QueueEntry()).GetNext() } -> std::same_as; + { (typename T::QueueEntry()).GetPrev() } -> std::same_as; + { t.GetPriorityQueueEntry(std::declval()) } -> std::same_as; - template - concept KPriorityQueueMember = !std::is_reference::value && requires (T &t) { - { typename T::QueueEntry() }; - { (typename T::QueueEntry()).Initialize() }; - { (typename T::QueueEntry()).SetPrev(std::addressof(t)) }; - { (typename T::QueueEntry()).SetNext(std::addressof(t)) }; - { (typename T::QueueEntry()).GetNext() } -> std::same_as; - { (typename T::QueueEntry()).GetPrev() } -> std::same_as; - { t.GetPriorityQueueEntry(std::declval()) } -> std::same_as; + { t.GetAffinityMask() }; + { typename std::remove_cvref::type() } -> KPriorityQueueAffinityMask; - { t.GetAffinityMask() }; - { typename std::remove_cvref::type() } -> KPriorityQueueAffinityMask; + { t.GetActiveCore() } -> std::convertible_to; + { t.GetPriority() } -> std::convertible_to; + }; - { t.GetActiveCore() } -> std::convertible_to; - { t.GetPriority() } -> std::convertible_to; - }; - */ - - - template /* TODO C++20: requires KPriorityQueueMember */ + template requires KPriorityQueueMember class KPriorityQueue { public: using AffinityMaskType = typename std::remove_cv().GetAffinityMask())>::type>::type; diff --git a/libmesosphere/include/mesosphere/kern_k_scheduler.hpp b/libmesosphere/include/mesosphere/kern_k_scheduler.hpp index 5fb57ad2..2e8247f5 100644 --- a/libmesosphere/include/mesosphere/kern_k_scheduler.hpp +++ b/libmesosphere/include/mesosphere/kern_k_scheduler.hpp @@ -33,8 +33,6 @@ namespace ams::kern { NON_COPYABLE(KScheduler); NON_MOVEABLE(KScheduler); public: - using LockType = KAbstractSchedulerLock; - static constexpr s32 HighestCoreMigrationAllowedPriority = 2; static_assert(ams::svc::LowestThreadPriority >= HighestCoreMigrationAllowedPriority); static_assert(ams::svc::HighestThreadPriority <= HighestCoreMigrationAllowedPriority); @@ -50,9 +48,6 @@ namespace ams::kern { private: friend class KScopedSchedulerLock; friend class KScopedSchedulerLockAndSleep; - static bool s_scheduler_update_needed; - static LockType s_scheduler_lock; - static KSchedulerPriorityQueue s_priority_queue; private: SchedulingState state; bool is_active; @@ -160,6 +155,12 @@ namespace ams::kern { } NOINLINE u64 UpdateHighestPriorityThread(KThread *thread); + public: + using LockType = KAbstractSchedulerLock; + private: + static bool s_scheduler_update_needed; + static KSchedulerPriorityQueue s_priority_queue; + static LockType s_scheduler_lock; }; class KScopedSchedulerLock : KScopedLock { diff --git a/libmesosphere/include/mesosphere/kern_k_scheduler_lock.hpp b/libmesosphere/include/mesosphere/kern_k_scheduler_lock.hpp index 3be30f90..355719f1 100644 --- a/libmesosphere/include/mesosphere/kern_k_scheduler_lock.hpp +++ b/libmesosphere/include/mesosphere/kern_k_scheduler_lock.hpp @@ -23,19 +23,14 @@ namespace ams::kern { class KThread; - /* - TODO: C++20 + template + concept KSchedulerLockable = !std::is_reference::value && requires(T) { + { T::DisableScheduling() } -> std::same_as; + { T::EnableScheduling(std::declval()) } -> std::same_as; + { T::UpdateHighestPriorityThreads() } -> std::convertible_to; + }; - template - concept KSchedulerLockable = !std::is_reference::value && requires { - { T::DisableScheduling() } -> std::same_as; - { T::EnableScheduling(std::declval()) } -> std::same_as; - { T::UpdateHighestPriorityThreads() } -> std::convertible_to; - }; - - */ - - template /* TODO C++20: requires KSchedulerLockable */ + template requires KSchedulerLockable class KAbstractSchedulerLock { private: KAlignedSpinLock spin_lock; diff --git a/libmesosphere/include/mesosphere/kern_k_scoped_lock.hpp b/libmesosphere/include/mesosphere/kern_k_scoped_lock.hpp index fd6756b2..8ae0fecb 100644 --- a/libmesosphere/include/mesosphere/kern_k_scoped_lock.hpp +++ b/libmesosphere/include/mesosphere/kern_k_scoped_lock.hpp @@ -18,18 +18,13 @@ namespace ams::kern { - /* - TODO: C++20 + template + concept KLockable = !std::is_reference::value && requires (T &t) { + { t.Lock() } -> std::same_as; + { t.Unlock() } -> std::same_as; + }; - template - concept KLockable = !std::is_reference::value && requires (T &t) { - { t.Lock() } -> std::same_as; - { t.Unlock() } -> std::same_as; - }; - - */ - - template /* TODO C++20: requires KLockable */ + template requires KLockable class KScopedLock { NON_COPYABLE(KScopedLock); NON_MOVEABLE(KScopedLock); diff --git a/libmesosphere/include/mesosphere/svc/kern_svc_k_user_pointer.hpp b/libmesosphere/include/mesosphere/svc/kern_svc_k_user_pointer.hpp index fce28f59..5d707d52 100644 --- a/libmesosphere/include/mesosphere/svc/kern_svc_k_user_pointer.hpp +++ b/libmesosphere/include/mesosphere/svc/kern_svc_k_user_pointer.hpp @@ -22,47 +22,35 @@ namespace ams::kern::svc { namespace impl { - /* TODO: C++20 - template - concept Pointer = std::is_pointer::value; - - template - concept NonConstPointer = Pointer && !std::is_const::type>::value; - - template - concept ConstPointer = Pointer && std::is_const::type>::value; - - template - concept AlignedNPointer = Pointer && alignof(typename std::remove_pointer::type) >= N && util::IsAligned(sizeof(typename std::remove_pointer::type), N); - - template - concept Aligned8Pointer = AlignedNPointer; - - template - concept Aligned16Pointer = AlignedNPointer && Aligned8; - - template - concept Aligned32Pointer = AlignedNPointer && Aligned16; - - template - concept Aligned64Pointer = AlignedNPointer && Aligned32; - */ + template + concept Pointer = std::is_pointer::value; template - constexpr inline bool IsPointer = std::is_pointer::value; + concept NonConstPointer = Pointer && !std::is_const::type>::value; template - constexpr inline bool IsConstPointer = IsPointer && std::is_const::type>::value; - - template - constexpr inline bool IsNonConstPointer = IsPointer && !std::is_const::type>::value; + concept ConstPointer = Pointer && std::is_const::type>::value; template - constexpr inline bool IsAlignedNPointer = IsPointer && alignof(typename std::remove_pointer::type) >= N && util::IsAligned(sizeof(typename std::remove_pointer::type), N); + concept AlignedNPointer = Pointer && alignof(typename std::remove_pointer::type) >= N && util::IsAligned(sizeof(typename std::remove_pointer::type), N); - template /* requires Aligned8Pointer<_T> */ - class KUserPointerImplTraits { - static_assert(IsAlignedNPointer<_T, sizeof(u8)>); + template + concept Aligned8Pointer = AlignedNPointer; + + template + concept Aligned16Pointer = AlignedNPointer && Aligned8Pointer; + + template + concept Aligned32Pointer = AlignedNPointer && Aligned16Pointer; + + template + concept Aligned64Pointer = AlignedNPointer && Aligned32Pointer; + + template + class KUserPointerImplTraits; + + template requires Aligned8Pointer<_T> + class KUserPointerImplTraits<_T> { public: using T = typename std::remove_const::type>::type; public: @@ -77,9 +65,8 @@ namespace ams::kern::svc { } }; - template /* requires Aligned32Pointer<_T> */ - class KUserPointerImplTraits<_T, typename std::enable_if && !IsAlignedNPointer<_T, sizeof(u64)>>::type> { - static_assert(IsAlignedNPointer<_T, sizeof(u32)>); + template requires Aligned32Pointer<_T> + class KUserPointerImplTraits<_T> { public: using T = typename std::remove_const::type>::type; public: @@ -94,9 +81,8 @@ namespace ams::kern::svc { } }; - template /* requires Aligned64Pointer<_T> */ - class KUserPointerImplTraits<_T, typename std::enable_if>::type> { - static_assert(IsAlignedNPointer<_T, sizeof(u64)>); + template requires Aligned64Pointer<_T> + class KUserPointerImplTraits<_T> { public: using T = typename std::remove_const::type>::type; public: @@ -111,8 +97,11 @@ namespace ams::kern::svc { } }; - template /* requires Aligned8Pointer<_T> */ - class KUserPointerImpl : impl::KUserPointerTag { + template + class KUserPointerImpl; + + template requires Aligned8Pointer<_T> + class KUserPointerImpl<_T> : impl::KUserPointerTag { private: using Traits = KUserPointerImplTraits<_T>; protected: @@ -170,11 +159,11 @@ namespace ams::kern::svc { } - template - class KUserPointer; + template + struct KUserPointer; - template /* requires impl::ConstPointer */ - struct KUserPointer>::type> : public impl::KUserPointerImpl { + template requires impl::ConstPointer + struct KUserPointer : public impl::KUserPointerImpl { public: static constexpr bool IsInput = true; public: @@ -186,8 +175,8 @@ namespace ams::kern::svc { using impl::KUserPointerImpl::GetUnsafePointer; }; - template /* requires impl::NonConstPointer */ - struct KUserPointer>::type> : public impl::KUserPointerImpl { + template requires impl::NonConstPointer + struct KUserPointer : public impl::KUserPointerImpl { public: static constexpr bool IsInput = false; public: diff --git a/libmesosphere/source/kern_k_address_space_info.cpp b/libmesosphere/source/kern_k_address_space_info.cpp index e8c04ec9..1d81e14d 100644 --- a/libmesosphere/source/kern_k_address_space_info.cpp +++ b/libmesosphere/source/kern_k_address_space_info.cpp @@ -22,19 +22,19 @@ namespace ams::kern { constexpr uintptr_t Invalid = std::numeric_limits::max(); constexpr KAddressSpaceInfo AddressSpaceInfos[] = { - { .bit_width = 32, .address = 2_MB, .size = 1_GB - 2_MB, KAddressSpaceInfo::Type_32Bit, }, - { .bit_width = 32, .address = 1_GB, .size = 4_GB - 1_GB, KAddressSpaceInfo::Type_Small64Bit, }, - { .bit_width = 32, .address = Invalid, .size = 1_GB, KAddressSpaceInfo::Type_Heap, }, - { .bit_width = 32, .address = Invalid, .size = 1_GB, KAddressSpaceInfo::Type_Alias, }, - { .bit_width = 36, .address = 128_MB, .size = 2_GB - 128_MB, KAddressSpaceInfo::Type_32Bit, }, - { .bit_width = 36, .address = 2_GB, .size = 64_GB - 2_GB, KAddressSpaceInfo::Type_Small64Bit, }, - { .bit_width = 36, .address = Invalid, .size = 6_GB, KAddressSpaceInfo::Type_Heap, }, - { .bit_width = 36, .address = Invalid, .size = 6_GB, KAddressSpaceInfo::Type_Alias, }, - { .bit_width = 39, .address = 128_MB, .size = 512_GB - 128_MB, KAddressSpaceInfo::Type_Large64Bit, }, - { .bit_width = 39, .address = Invalid, .size = 64_GB, KAddressSpaceInfo::Type_32Bit, }, - { .bit_width = 39, .address = Invalid, .size = 6_GB, KAddressSpaceInfo::Type_Heap, }, - { .bit_width = 39, .address = Invalid, .size = 64_GB, KAddressSpaceInfo::Type_Alias, }, - { .bit_width = 39, .address = Invalid, .size = 2_GB, KAddressSpaceInfo::Type_Stack, }, + { .bit_width = 32, .address = 2_MB, .size = 1_GB - 2_MB, .type = KAddressSpaceInfo::Type_32Bit, }, + { .bit_width = 32, .address = 1_GB, .size = 4_GB - 1_GB, .type = KAddressSpaceInfo::Type_Small64Bit, }, + { .bit_width = 32, .address = Invalid, .size = 1_GB, .type = KAddressSpaceInfo::Type_Heap, }, + { .bit_width = 32, .address = Invalid, .size = 1_GB, .type = KAddressSpaceInfo::Type_Alias, }, + { .bit_width = 36, .address = 128_MB, .size = 2_GB - 128_MB, .type = KAddressSpaceInfo::Type_32Bit, }, + { .bit_width = 36, .address = 2_GB, .size = 64_GB - 2_GB, .type = KAddressSpaceInfo::Type_Small64Bit, }, + { .bit_width = 36, .address = Invalid, .size = 6_GB, .type = KAddressSpaceInfo::Type_Heap, }, + { .bit_width = 36, .address = Invalid, .size = 6_GB, .type = KAddressSpaceInfo::Type_Alias, }, + { .bit_width = 39, .address = 128_MB, .size = 512_GB - 128_MB, .type = KAddressSpaceInfo::Type_Large64Bit, }, + { .bit_width = 39, .address = Invalid, .size = 64_GB, .type = KAddressSpaceInfo::Type_32Bit, }, + { .bit_width = 39, .address = Invalid, .size = 6_GB, .type = KAddressSpaceInfo::Type_Heap, }, + { .bit_width = 39, .address = Invalid, .size = 64_GB, .type = KAddressSpaceInfo::Type_Alias, }, + { .bit_width = 39, .address = Invalid, .size = 2_GB, .type = KAddressSpaceInfo::Type_Stack, }, }; constexpr bool IsAllowedIndexForAddress(size_t index) { diff --git a/libmesosphere/source/kern_k_object_name.cpp b/libmesosphere/source/kern_k_object_name.cpp index 76312245..b5fd505a 100644 --- a/libmesosphere/source/kern_k_object_name.cpp +++ b/libmesosphere/source/kern_k_object_name.cpp @@ -19,9 +19,8 @@ namespace ams::kern { namespace { - /* TODO: C++20 constinit */ - KLightLock g_object_list_lock; - KObjectName::List g_object_list; + constinit KLightLock g_object_list_lock; + constinit KObjectName::List g_object_list; } diff --git a/libstratosphere/Makefile b/libstratosphere/Makefile index 15aad5a6..a87f062f 100644 --- a/libstratosphere/Makefile +++ b/libstratosphere/Makefile @@ -15,6 +15,8 @@ include $(DEVKITPRO)/libnx/switch_rules #--------------------------------------------------------------------------------- # options for code generation #--------------------------------------------------------------------------------- +PRECOMPILED_HEADERS := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/include/stratosphere.hpp + DEFINES := $(ATMOSPHERE_DEFINES) -DATMOSPHERE_IS_STRATOSPHERE -D_GNU_SOURCE SETTINGS := $(ATMOSPHERE_SETTINGS) -O2 CFLAGS := $(ATMOSPHERE_CFLAGS) $(SETTINGS) $(DEFINES) $(INCLUDE) @@ -40,7 +42,7 @@ LIBDIRS := $(PORTLIBS) $(LIBNX) $(ATMOSPHERE_LIBRARIES_DIR)/libvapours ifneq ($(BUILD),$(notdir $(CURDIR))) #--------------------------------------------------------------------------------- -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) $(CURDIR)/include \ $(foreach dir,$(DATA),$(CURDIR)/$(dir)) CFILES := $(foreach dir,$(SOURCES),$(filter-out $(notdir $(wildcard $(dir)/*.arch.*.c)) $(notdir $(wildcard $(dir)/*.board.*.c)) $(notdir $(wildcard $(dir)/*.os.*.c)), \ @@ -77,6 +79,7 @@ endif export OFILES_BIN := $(addsuffix .o,$(BINFILES)) export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) +export GCH_FILES := $(foreach hdr,$(PRECOMPILED_HEADERS:.hpp=.gch),$(notdir $(hdr))) export OFILES := $(OFILES_BIN) $(OFILES_SRC) export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) @@ -125,6 +128,8 @@ DEPENDS := $(OFILES:.o=.d) #--------------------------------------------------------------------------------- $(OUTPUT) : $(OFILES) +$(OFILES) : $(GCH_FILES) + $(OFILES_SRC) : $(HFILES_BIN) #--------------------------------------------------------------------------------- diff --git a/libstratosphere/include/stratosphere/ams/ams_types.hpp b/libstratosphere/include/stratosphere/ams/ams_types.hpp index 73b69fba..b16de724 100644 --- a/libstratosphere/include/stratosphere/ams/ams_types.hpp +++ b/libstratosphere/include/stratosphere/ams/ams_types.hpp @@ -104,7 +104,7 @@ namespace ams { }; static_assert(sizeof(FatalErrorContext) == 0x450, "sizeof(FatalErrorContext)"); - static_assert(std::is_pod::value, "FatalErrorContext"); + static_assert(util::is_pod::value, "FatalErrorContext"); #ifdef ATMOSPHERE_GIT_BRANCH NX_CONSTEXPR const char *GetGitBranch() { diff --git a/libstratosphere/include/stratosphere/capsrv/capsrv_screen_shot_decode_option.hpp b/libstratosphere/include/stratosphere/capsrv/capsrv_screen_shot_decode_option.hpp index 5b0ba29e..6606470b 100644 --- a/libstratosphere/include/stratosphere/capsrv/capsrv_screen_shot_decode_option.hpp +++ b/libstratosphere/include/stratosphere/capsrv/capsrv_screen_shot_decode_option.hpp @@ -41,6 +41,6 @@ namespace ams::capsrv { }; static_assert(sizeof(ScreenShotDecodeOption) == 0x20); static_assert(sizeof(ScreenShotDecodeOption) == sizeof(::CapsScreenShotDecodeOption)); - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); } diff --git a/libstratosphere/include/stratosphere/cfg/cfg_types.hpp b/libstratosphere/include/stratosphere/cfg/cfg_types.hpp index 6f2bffc4..b7d5847f 100644 --- a/libstratosphere/include/stratosphere/cfg/cfg_types.hpp +++ b/libstratosphere/include/stratosphere/cfg/cfg_types.hpp @@ -49,7 +49,7 @@ namespace ams::cfg { }; static_assert(sizeof(OverrideStatus) == 0x10, "sizeof(OverrideStatus)"); - static_assert(std::is_pod::value, "std::is_pod::value"); + static_assert(util::is_pod::value, "util::is_pod::value"); constexpr inline bool operator==(const OverrideStatus &lhs, const OverrideStatus &rhs) { return std::memcmp(&lhs, &rhs, sizeof(lhs)) == 0; diff --git a/libstratosphere/include/stratosphere/dmnt/dmnt_cheat_types.hpp b/libstratosphere/include/stratosphere/dmnt/dmnt_cheat_types.hpp index 017e7340..53ab40bf 100644 --- a/libstratosphere/include/stratosphere/dmnt/dmnt_cheat_types.hpp +++ b/libstratosphere/include/stratosphere/dmnt/dmnt_cheat_types.hpp @@ -36,7 +36,7 @@ namespace ams::dmnt::cheat { u8 main_nso_build_id[0x20]; }; - static_assert(std::is_pod::value && sizeof(CheatProcessMetadata) == 0x70, "CheatProcessMetadata definition!"); + static_assert(util::is_pod::value && sizeof(CheatProcessMetadata) == 0x70, "CheatProcessMetadata definition!"); struct CheatDefinition : sf::LargeData, sf::PrefersMapAliasTransferMode { char readable_name[0x40]; @@ -50,8 +50,8 @@ namespace ams::dmnt::cheat { CheatDefinition definition; }; - static_assert(std::is_pod::value, "CheatDefinition"); - static_assert(std::is_pod::value, "CheatEntry"); + static_assert(util::is_pod::value, "CheatDefinition"); + static_assert(util::is_pod::value, "CheatEntry"); struct FrozenAddressValue { u64 value; diff --git a/libstratosphere/include/stratosphere/erpt/erpt_types.hpp b/libstratosphere/include/stratosphere/erpt/erpt_types.hpp index bc29605e..d26cf6e1 100644 --- a/libstratosphere/include/stratosphere/erpt/erpt_types.hpp +++ b/libstratosphere/include/stratosphere/erpt/erpt_types.hpp @@ -108,7 +108,7 @@ namespace ams::erpt { }; using ReportFlagSet = util::BitFlagSet; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(sizeof(ReportFlagSet) == sizeof(u32)); struct ReportInfo { @@ -149,7 +149,7 @@ namespace ams::erpt { }; using AttachmentFlagSet = util::BitFlagSet; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(sizeof(AttachmentFlagSet) == sizeof(u32)); constexpr inline u32 AttachmentNameSizeMax = 0x20; diff --git a/libstratosphere/include/stratosphere/fatal/fatal_types.hpp b/libstratosphere/include/stratosphere/fatal/fatal_types.hpp index f2a9dc91..1228e7af 100644 --- a/libstratosphere/include/stratosphere/fatal/fatal_types.hpp +++ b/libstratosphere/include/stratosphere/fatal/fatal_types.hpp @@ -75,44 +75,44 @@ namespace ams::fatal { static constexpr size_t MaxStackTraceDepth = 0x20; static constexpr const char *RegisterNameStrings[RegisterName_Count] = { - u8"X0", - u8"X1", - u8"X2", - u8"X3", - u8"X4", - u8"X5", - u8"X6", - u8"X7", - u8"X8", - u8"X9", - u8"X10", - u8"X11", - u8"X12", - u8"X13", - u8"X14", - u8"X15", - u8"X16", - u8"X17", - u8"X18", - u8"X19", - u8"X20", - u8"X21", - u8"X22", - u8"X23", - u8"X24", - u8"X25", - u8"X26", - u8"X27", - u8"X28", - u8"FP", - u8"LR", - u8"SP", - u8"PC", - u8"PState", - u8"Afsr0", - u8"Afsr1", - u8"Esr", - u8"Far", + "X0", + "X1", + "X2", + "X3", + "X4", + "X5", + "X6", + "X7", + "X8", + "X9", + "X10", + "X11", + "X12", + "X13", + "X14", + "X15", + "X16", + "X17", + "X18", + "X19", + "X20", + "X21", + "X22", + "X23", + "X24", + "X25", + "X26", + "X27", + "X28", + "FP", + "LR", + "SP", + "PC", + "PState", + "Afsr0", + "Afsr1", + "Esr", + "Far", }; /* Registers, exception context. N left names for these fields in fatal .rodata. */ @@ -209,27 +209,27 @@ namespace ams::fatal { static constexpr size_t MaxStackTraceDepth = 0x20; static constexpr const char *RegisterNameStrings[RegisterName_Count] = { - u8"R0", - u8"R1", - u8"R2", - u8"R3", - u8"R4", - u8"R5", - u8"R6", - u8"R7", - u8"R8", - u8"R9", - u8"R10", - u8"FP", - u8"IP", - u8"LR", - u8"SP", - u8"PC", - u8"PState", - u8"Afsr0", - u8"Afsr1", - u8"Esr", - u8"Far", + "R0", + "R1", + "R2", + "R3", + "R4", + "R5", + "R6", + "R7", + "R8", + "R9", + "R10", + "FP", + "IP", + "LR", + "SP", + "PC", + "PState", + "Afsr0", + "Afsr1", + "Esr", + "Far", }; /* Registers, exception context. N left names for these fields in fatal .rodata. */ @@ -311,9 +311,9 @@ namespace ams::fatal { } }; - static_assert(std::is_pod::value && sizeof(aarch64::CpuContext) == 0x248, "aarch64::CpuContext definition!"); - static_assert(std::is_pod::value && sizeof(aarch32::CpuContext) == 0xE0, "aarch32::CpuContext definition!"); - static_assert(std::is_pod::value && sizeof(CpuContext) == 0x250, "CpuContext definition!"); + static_assert(util::is_pod::value && sizeof(aarch64::CpuContext) == 0x248, "aarch64::CpuContext definition!"); + static_assert(util::is_pod::value && sizeof(aarch32::CpuContext) == 0xE0, "aarch32::CpuContext definition!"); + static_assert(util::is_pod::value && sizeof(CpuContext) == 0x250, "CpuContext definition!"); namespace srv { diff --git a/libstratosphere/include/stratosphere/fs/fs_common.hpp b/libstratosphere/include/stratosphere/fs/fs_common.hpp index 4f6a6436..e91ae983 100644 --- a/libstratosphere/include/stratosphere/fs/fs_common.hpp +++ b/libstratosphere/include/stratosphere/fs/fs_common.hpp @@ -43,6 +43,6 @@ namespace ams::fs { return this->Get(); } }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); } \ No newline at end of file diff --git a/libstratosphere/include/stratosphere/fs/fs_dbm_hierarchical_rom_file_table.hpp b/libstratosphere/include/stratosphere/fs/fs_dbm_hierarchical_rom_file_table.hpp index d2306154..25651f7e 100644 --- a/libstratosphere/include/stratosphere/fs/fs_dbm_hierarchical_rom_file_table.hpp +++ b/libstratosphere/include/stratosphere/fs/fs_dbm_hierarchical_rom_file_table.hpp @@ -28,7 +28,7 @@ namespace ams::fs { Position next_dir; Position next_file; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); using DirectoryInfo = RomDirectoryInfo; using FileInfo = RomFileInfo; @@ -56,13 +56,13 @@ namespace ams::fs { Position dir; Position file; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); struct RomFileEntry { Position next; FileInfo info; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static constexpr inline u32 MaxKeyLength = RomPathTool::MaxPathLength; @@ -109,7 +109,7 @@ namespace ams::fs { return RomPathTool::IsEqualPath(reinterpret_cast(aux_lhs), reinterpret_cast(aux_rhs), aux_lhs_size / sizeof(RomPathChar)); } }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); struct EntryKey { RomEntryKey key; @@ -126,7 +126,7 @@ namespace ams::fs { return hash; } }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); using DirectoryEntryMapTable = EntryMapTable; using FileEntryMapTable = EntryMapTable; diff --git a/libstratosphere/include/stratosphere/fs/fs_dbm_rom_key_value_storage.hpp b/libstratosphere/include/stratosphere/fs/fs_dbm_rom_key_value_storage.hpp index 044e17b7..455f1cdf 100644 --- a/libstratosphere/include/stratosphere/fs/fs_dbm_rom_key_value_storage.hpp +++ b/libstratosphere/include/stratosphere/fs/fs_dbm_rom_key_value_storage.hpp @@ -31,7 +31,7 @@ namespace ams::fs { BucketIndex ind; Position pos; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); private: static constexpr inline Position InvalidPosition = ~Position(); @@ -41,7 +41,7 @@ namespace ams::fs { Position next; u32 size; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); private: s64 bucket_count; SubStorage bucket_storage; diff --git a/libstratosphere/include/stratosphere/fs/fs_dbm_rom_path_tool.hpp b/libstratosphere/include/stratosphere/fs/fs_dbm_rom_path_tool.hpp index c57b1fe9..7fc957c9 100644 --- a/libstratosphere/include/stratosphere/fs/fs_dbm_rom_path_tool.hpp +++ b/libstratosphere/include/stratosphere/fs/fs_dbm_rom_path_tool.hpp @@ -26,7 +26,7 @@ namespace ams::fs { size_t length; const RomPathChar *path; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); constexpr void InitializeRomEntryName(RomEntryName *entry) { AMS_ABORT_UNLESS(entry != nullptr); diff --git a/libstratosphere/include/stratosphere/fs/fs_dbm_rom_types.hpp b/libstratosphere/include/stratosphere/fs/fs_dbm_rom_types.hpp index 86a646e4..f746af65 100644 --- a/libstratosphere/include/stratosphere/fs/fs_dbm_rom_types.hpp +++ b/libstratosphere/include/stratosphere/fs/fs_dbm_rom_types.hpp @@ -34,19 +34,19 @@ namespace ams::fs { s64 file_entry_size; s64 body_offset; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(sizeof(RomFileSystemInformation) == 0x50); struct RomDirectoryInfo { /* ... */ }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); struct RomFileInfo { Int64 offset; Int64 size; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); namespace RomStringTraits { diff --git a/libstratosphere/include/stratosphere/fs/fs_file.hpp b/libstratosphere/include/stratosphere/fs/fs_file.hpp index 51fab707..36e7d790 100644 --- a/libstratosphere/include/stratosphere/fs/fs_file.hpp +++ b/libstratosphere/include/stratosphere/fs/fs_file.hpp @@ -34,7 +34,7 @@ namespace ams::fs { return !(lhs == rhs); } - static_assert(std::is_pod::value && sizeof(ReadOption) == sizeof(u32)); + static_assert(util::is_pod::value && sizeof(ReadOption) == sizeof(u32)); struct WriteOption { u32 value; @@ -58,7 +58,7 @@ namespace ams::fs { return !(lhs == rhs); } - static_assert(std::is_pod::value && sizeof(WriteOption) == sizeof(u32)); + static_assert(util::is_pod::value && sizeof(WriteOption) == sizeof(u32)); struct FileHandle { void *handle; diff --git a/libstratosphere/include/stratosphere/fs/fs_memory_management.hpp b/libstratosphere/include/stratosphere/fs/fs_memory_management.hpp index cc9a31a2..03e34474 100644 --- a/libstratosphere/include/stratosphere/fs/fs_memory_management.hpp +++ b/libstratosphere/include/stratosphere/fs/fs_memory_management.hpp @@ -42,7 +42,7 @@ namespace ams::fs { template std::unique_ptr MakeUnique() { - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); return std::unique_ptr(static_cast(::ams::fs::impl::Allocate(sizeof(T))), Deleter(sizeof(T))); } diff --git a/libstratosphere/include/stratosphere/fs/fs_query_range.hpp b/libstratosphere/include/stratosphere/fs/fs_query_range.hpp index 5cdc45c2..1c0fbdeb 100644 --- a/libstratosphere/include/stratosphere/fs/fs_query_range.hpp +++ b/libstratosphere/include/stratosphere/fs/fs_query_range.hpp @@ -36,7 +36,7 @@ namespace ams::fs { } }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(sizeof(QueryRangeInfo) == 0x40); static_assert(sizeof(QueryRangeInfo) == sizeof(::FsRangeInfo)); diff --git a/libstratosphere/include/stratosphere/fs/fs_rights_id.hpp b/libstratosphere/include/stratosphere/fs/fs_rights_id.hpp index e13bca7b..9dae55eb 100644 --- a/libstratosphere/include/stratosphere/fs/fs_rights_id.hpp +++ b/libstratosphere/include/stratosphere/fs/fs_rights_id.hpp @@ -23,7 +23,7 @@ namespace ams::fs { u64 data64[2]; }; static_assert(sizeof(RightsId) == 0x10); - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); inline bool operator==(const RightsId &lhs, const RightsId &rhs) { return std::memcmp(std::addressof(lhs), std::addressof(rhs), sizeof(RightsId)) == 0; diff --git a/libstratosphere/include/stratosphere/fs/fs_save_data_types.hpp b/libstratosphere/include/stratosphere/fs/fs_save_data_types.hpp index 8d49efe3..e663d67d 100644 --- a/libstratosphere/include/stratosphere/fs/fs_save_data_types.hpp +++ b/libstratosphere/include/stratosphere/fs/fs_save_data_types.hpp @@ -51,7 +51,7 @@ namespace ams::fs { struct UserId { u64 data[2]; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); constexpr inline bool operator<(const UserId &lhs, const UserId &rhs) { if (lhs.data[0] < rhs.data[0]) { @@ -92,7 +92,7 @@ namespace ams::fs { bool pseudo; u8 reserved[0x1A]; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(sizeof(SaveDataCreationInfo) == 0x40); struct SaveDataAttribute { @@ -154,6 +154,6 @@ namespace ams::fs { u8 unused[0x190]; }; static_assert(sizeof(SaveDataExtraData) == 0x200); - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); } diff --git a/libstratosphere/include/stratosphere/fssrv/fssrv_sf_path.hpp b/libstratosphere/include/stratosphere/fssrv/fssrv_sf_path.hpp index a847a258..16d7976d 100644 --- a/libstratosphere/include/stratosphere/fssrv/fssrv_sf_path.hpp +++ b/libstratosphere/include/stratosphere/fssrv/fssrv_sf_path.hpp @@ -43,7 +43,7 @@ namespace ams::fssrv::sf { } }; - static_assert(std::is_pod::value && sizeof(Path) == FS_MAX_PATH); + static_assert(util::is_pod::value && sizeof(Path) == FS_MAX_PATH); using FspPath = Path; diff --git a/libstratosphere/include/stratosphere/fssystem/buffers/fssystem_file_system_buddy_heap.hpp b/libstratosphere/include/stratosphere/fssystem/buffers/fssystem_file_system_buddy_heap.hpp index 0da25569..dad54e2a 100644 --- a/libstratosphere/include/stratosphere/fssystem/buffers/fssystem_file_system_buddy_heap.hpp +++ b/libstratosphere/include/stratosphere/fssystem/buffers/fssystem_file_system_buddy_heap.hpp @@ -30,7 +30,7 @@ namespace ams::fssystem { class PageList; struct PageEntry { PageEntry *next; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(sizeof(PageEntry) <= BlockSizeMin); class PageList : public ::ams::fs::impl::Newable { diff --git a/libstratosphere/include/stratosphere/fssystem/fssystem_dbm_hierarchical_rom_file_table.hpp b/libstratosphere/include/stratosphere/fssystem/fssystem_dbm_hierarchical_rom_file_table.hpp index 98d27b05..8ee5f4da 100644 --- a/libstratosphere/include/stratosphere/fssystem/fssystem_dbm_hierarchical_rom_file_table.hpp +++ b/libstratosphere/include/stratosphere/fssystem/fssystem_dbm_hierarchical_rom_file_table.hpp @@ -35,7 +35,7 @@ namespace ams::fssystem { Position next_dir; Position next_file; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); using DirectoryInfo = RomDirectoryInfo; using FileInfo = RomFileInfo; @@ -63,13 +63,13 @@ namespace ams::fssystem { Position dir; Position file; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); struct RomFileEntry { Position next; FileInfo info; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static constexpr inline u32 MaxKeyLength = RomPathTool::MaxPathLength; @@ -115,7 +115,7 @@ namespace ams::fssystem { return RomPathTool::IsEqualPath(reinterpret_cast(aux_lhs), reinterpret_cast(aux_rhs), aux_lhs_size / sizeof(RomPathChar)); } }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); struct EntryKey { RomEntryKey key; @@ -132,7 +132,7 @@ namespace ams::fssystem { return hash; } }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); using DirectoryEntryMapTable = EntryMapTable; using FileEntryMapTable = EntryMapTable; diff --git a/libstratosphere/include/stratosphere/fssystem/fssystem_dbm_rom_key_value_storage.hpp b/libstratosphere/include/stratosphere/fssystem/fssystem_dbm_rom_key_value_storage.hpp index f47569f6..1bbea7a5 100644 --- a/libstratosphere/include/stratosphere/fssystem/fssystem_dbm_rom_key_value_storage.hpp +++ b/libstratosphere/include/stratosphere/fssystem/fssystem_dbm_rom_key_value_storage.hpp @@ -37,7 +37,7 @@ namespace ams::fssystem { BucketIndex ind; Position pos; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); private: static constexpr inline Position InvalidPosition = ~Position(); @@ -47,7 +47,7 @@ namespace ams::fssystem { Position next; u32 size; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); private: s64 bucket_offset; u32 bucket_count; diff --git a/libstratosphere/include/stratosphere/fssystem/fssystem_dbm_rom_path_tool.hpp b/libstratosphere/include/stratosphere/fssystem/fssystem_dbm_rom_path_tool.hpp index d6cd961a..6c40eac5 100644 --- a/libstratosphere/include/stratosphere/fssystem/fssystem_dbm_rom_path_tool.hpp +++ b/libstratosphere/include/stratosphere/fssystem/fssystem_dbm_rom_path_tool.hpp @@ -26,7 +26,7 @@ namespace ams::fssystem { size_t length; const RomPathChar *path; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); constexpr void InitializeRomEntryName(RomEntryName *entry) { entry->length = 0; diff --git a/libstratosphere/include/stratosphere/fssystem/fssystem_dbm_rom_types.hpp b/libstratosphere/include/stratosphere/fssystem/fssystem_dbm_rom_types.hpp index 304cf9dd..1baf32eb 100644 --- a/libstratosphere/include/stratosphere/fssystem/fssystem_dbm_rom_types.hpp +++ b/libstratosphere/include/stratosphere/fssystem/fssystem_dbm_rom_types.hpp @@ -34,19 +34,19 @@ namespace ams::fssystem { s64 file_entry_size; s64 body_offset; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(sizeof(RomFileSystemInformation) == 0x50); struct RomDirectoryInfo { /* ... */ }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); struct RomFileInfo { fs::Int64 offset; fs::Int64 size; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); namespace RomStringTraits { diff --git a/libstratosphere/include/stratosphere/fssystem/fssystem_partition_file_system_meta.hpp b/libstratosphere/include/stratosphere/fssystem/fssystem_partition_file_system_meta.hpp index 5e34906d..a45ad3d0 100644 --- a/libstratosphere/include/stratosphere/fssystem/fssystem_partition_file_system_meta.hpp +++ b/libstratosphere/include/stratosphere/fssystem/fssystem_partition_file_system_meta.hpp @@ -29,7 +29,7 @@ namespace ams::fssystem { u32 name_offset; u32 reserved; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); #pragma pack(pop) static constexpr const char VersionSignature[] = { 'P', 'F', 'S', '0' }; @@ -52,7 +52,7 @@ namespace ams::fssystem { u64 hash_target_offset; char hash[HashSize]; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); #pragma pack(pop) static constexpr const char VersionSignature[] = { 'H', 'F', 'S', '0' }; diff --git a/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_cache.hpp b/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_cache.hpp index 52f8b270..07c7008a 100644 --- a/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_cache.hpp +++ b/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_cache.hpp @@ -186,7 +186,7 @@ namespace ams::kvdb { template class FileKeyValueCache { - static_assert(std::is_pod::value, "FileKeyValueCache Key must be pod!"); + static_assert(util::is_pod::value, "FileKeyValueCache Key must be pod!"); static_assert(sizeof(Key) <= FileKeyValueStore::MaxKeySize, "FileKeyValueCache Key is too big!"); public: using LeastRecentlyUsedList = impl::LruList; diff --git a/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_store.hpp b/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_store.hpp index ce204dfb..047562ff 100644 --- a/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_store.hpp +++ b/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_store.hpp @@ -38,7 +38,7 @@ namespace ams::kvdb { size_t key_size; size_t value_size; }; - static_assert(std::is_pod::value, "FileKeyValueStore::Entry definition!"); + static_assert(util::is_pod::value, "FileKeyValueStore::Entry definition!"); class Cache { private: @@ -83,13 +83,13 @@ namespace ams::kvdb { /* Niceties. */ template Result Get(size_t *out_size, void *out_value, size_t max_out_size, const Key &key) { - static_assert(std::is_pod::value && sizeof(Key) <= MaxKeySize, "Invalid FileKeyValueStore Key!"); + static_assert(util::is_pod::value && sizeof(Key) <= MaxKeySize, "Invalid FileKeyValueStore Key!"); return this->Get(out_size, out_value, max_out_size, &key, sizeof(Key)); } template Result Get(Value *out_value, const Key &key) { - static_assert(std::is_pod::value && !std::is_pointer::value, "Invalid FileKeyValueStore Value!"); + static_assert(util::is_pod::value && !std::is_pointer::value, "Invalid FileKeyValueStore Value!"); size_t size = 0; R_TRY(this->Get(&size, out_value, sizeof(Value), key)); AMS_ABORT_UNLESS(size >= sizeof(Value)); @@ -103,13 +103,13 @@ namespace ams::kvdb { template Result Set(const Key &key, const void *value, size_t value_size) { - static_assert(std::is_pod::value && sizeof(Key) <= MaxKeySize, "Invalid FileKeyValueStore Key!"); + static_assert(util::is_pod::value && sizeof(Key) <= MaxKeySize, "Invalid FileKeyValueStore Key!"); return this->Set(&key, sizeof(Key), value, value_size); } template Result Set(const Key &key, const Value &value) { - static_assert(std::is_pod::value && !std::is_pointer::value, "Invalid FileKeyValueStore Value!"); + static_assert(util::is_pod::value && !std::is_pointer::value, "Invalid FileKeyValueStore Value!"); return this->Set(key, &value, sizeof(Value)); } diff --git a/libstratosphere/include/stratosphere/kvdb/kvdb_memory_key_value_store.hpp b/libstratosphere/include/stratosphere/kvdb/kvdb_memory_key_value_store.hpp index 1ec2b2fc..f64ee96f 100644 --- a/libstratosphere/include/stratosphere/kvdb/kvdb_memory_key_value_store.hpp +++ b/libstratosphere/include/stratosphere/kvdb/kvdb_memory_key_value_store.hpp @@ -26,7 +26,7 @@ namespace ams::kvdb { template class MemoryKeyValueStore { - static_assert(std::is_pod::value, "KeyValueStore Keys must be pod!"); + static_assert(util::is_pod::value, "KeyValueStore Keys must be pod!"); NON_COPYABLE(MemoryKeyValueStore); NON_MOVEABLE(MemoryKeyValueStore); public: @@ -49,7 +49,7 @@ namespace ams::kvdb { if constexpr (!std::is_same::value) { AMS_ABORT_UNLESS(sizeof(Value) <= this->value_size); /* Ensure we only get pod. */ - static_assert(std::is_pod::value, "KeyValueStore Values must be pod"); + static_assert(util::is_pod::value, "KeyValueStore Values must be pod"); } return reinterpret_cast(this->value); } @@ -60,7 +60,7 @@ namespace ams::kvdb { if constexpr (!std::is_same::value) { AMS_ABORT_UNLESS(sizeof(Value) <= this->value_size); /* Ensure we only get pod. */ - static_assert(std::is_pod::value, "KeyValueStore Values must be pod"); + static_assert(util::is_pod::value, "KeyValueStore Values must be pod"); } return reinterpret_cast(this->value); } @@ -366,14 +366,14 @@ namespace ams::kvdb { template Result Set(const Key &key, const Value &value) { /* Only allow setting pod. */ - static_assert(std::is_pod::value, "KeyValueStore Values must be pod"); + static_assert(util::is_pod::value, "KeyValueStore Values must be pod"); return this->Set(key, &value, sizeof(Value)); } template Result Set(const Key &key, const Value *value) { /* Only allow setting pod. */ - static_assert(std::is_pod::value, "KeyValueStore Values must be pod"); + static_assert(util::is_pod::value, "KeyValueStore Values must be pod"); return this->Set(key, value, sizeof(Value)); } diff --git a/libstratosphere/include/stratosphere/ldr/ldr_types.hpp b/libstratosphere/include/stratosphere/ldr/ldr_types.hpp index 933fc1d9..4c83687c 100644 --- a/libstratosphere/include/stratosphere/ldr/ldr_types.hpp +++ b/libstratosphere/include/stratosphere/ldr/ldr_types.hpp @@ -35,7 +35,7 @@ namespace ams::ldr { u32 aci_fah_size; u8 ac_buffer[0x3E0]; }; - static_assert(std::is_pod::value && sizeof(ProgramInfo) == 0x400, "ProgramInfo definition!"); + static_assert(util::is_pod::value && sizeof(ProgramInfo) == 0x400, "ProgramInfo definition!"); enum ProgramInfoFlag { ProgramInfoFlag_SystemModule = (0 << 0), @@ -71,7 +71,7 @@ namespace ams::ldr { inline bool operator!=(const PinId &lhs, const PinId &rhs) { return lhs.value != rhs.value; } - static_assert(sizeof(PinId) == sizeof(u64) && std::is_pod::value, "PinId definition!"); + static_assert(sizeof(PinId) == sizeof(u64) && util::is_pod::value, "PinId definition!"); /* Import ModuleInfo from libnx. */ using ModuleInfo = ::LoaderModuleInfo; @@ -142,7 +142,7 @@ namespace ams::ldr { }; }; }; - static_assert(sizeof(NsoHeader) == 0x100 && std::is_pod::value, "NsoHeader definition!"); + static_assert(sizeof(NsoHeader) == 0x100 && util::is_pod::value, "NsoHeader definition!"); /* NPDM types. */ struct Aci { @@ -160,7 +160,7 @@ namespace ams::ldr { u32 kac_size; u8 reserved_38[0x8]; }; - static_assert(sizeof(Aci) == 0x40 && std::is_pod::value, "Aci definition!"); + static_assert(sizeof(Aci) == 0x40 && util::is_pod::value, "Aci definition!"); struct Acid { static constexpr u32 Magic = util::FourCC<'A','C','I','D'>::Code; @@ -199,7 +199,7 @@ namespace ams::ldr { u32 kac_size; u8 reserved_238[0x8]; }; - static_assert(sizeof(Acid) == 0x240 && std::is_pod::value, "Acid definition!"); + static_assert(sizeof(Acid) == 0x240 && util::is_pod::value, "Acid definition!"); struct Npdm { static constexpr u32 Magic = util::FourCC<'M','E','T','A'>::Code; @@ -239,6 +239,6 @@ namespace ams::ldr { u32 acid_offset; u32 acid_size; }; - static_assert(sizeof(Npdm) == 0x80 && std::is_pod::value, "Npdm definition!"); + static_assert(sizeof(Npdm) == 0x80 && util::is_pod::value, "Npdm definition!"); } diff --git a/libstratosphere/include/stratosphere/lr/lr_types.hpp b/libstratosphere/include/stratosphere/lr/lr_types.hpp index 5b15c513..4a684470 100644 --- a/libstratosphere/include/stratosphere/lr/lr_types.hpp +++ b/libstratosphere/include/stratosphere/lr/lr_types.hpp @@ -56,6 +56,6 @@ namespace ams::lr { } }; - static_assert(std::is_pod::value && sizeof(Path) == fs::EntryNameLengthMax); + static_assert(util::is_pod::value && sizeof(Path) == fs::EntryNameLengthMax); } diff --git a/libstratosphere/include/stratosphere/mem/impl/mem_impl_common.hpp b/libstratosphere/include/stratosphere/mem/impl/mem_impl_common.hpp index ff0bbaf5..314a3d3b 100644 --- a/libstratosphere/include/stratosphere/mem/impl/mem_impl_common.hpp +++ b/libstratosphere/include/stratosphere/mem/impl/mem_impl_common.hpp @@ -65,6 +65,6 @@ namespace ams::mem::impl { size_t alloc_size; size_t hash; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); } diff --git a/libstratosphere/include/stratosphere/ncm/ncm_content_info.hpp b/libstratosphere/include/stratosphere/ncm/ncm_content_info.hpp index c0fcd21f..16f78428 100644 --- a/libstratosphere/include/stratosphere/ncm/ncm_content_info.hpp +++ b/libstratosphere/include/stratosphere/ncm/ncm_content_info.hpp @@ -55,7 +55,7 @@ namespace ams::ncm { } }; - static_assert(sizeof(std::is_pod::value)); + static_assert(sizeof(util::is_pod::value)); static_assert(sizeof(ContentInfo) == 0x18); } diff --git a/libstratosphere/include/stratosphere/ncm/ncm_content_manager_impl.hpp b/libstratosphere/include/stratosphere/ncm/ncm_content_manager_impl.hpp index 9f4fd8ae..244aa3ff 100644 --- a/libstratosphere/include/stratosphere/ncm/ncm_content_manager_impl.hpp +++ b/libstratosphere/include/stratosphere/ncm/ncm_content_manager_impl.hpp @@ -65,7 +65,7 @@ namespace ams::ncm { u32 flags; fs::SaveDataSpaceId space_id; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); class ContentManagerImpl final : public IContentManager { private: diff --git a/libstratosphere/include/stratosphere/ncm/ncm_program_location.hpp b/libstratosphere/include/stratosphere/ncm/ncm_program_location.hpp index 3e2e5356..097f83eb 100644 --- a/libstratosphere/include/stratosphere/ncm/ncm_program_location.hpp +++ b/libstratosphere/include/stratosphere/ncm/ncm_program_location.hpp @@ -27,7 +27,7 @@ namespace ams::ncm { return { .program_id = program_id, .storage_id = static_cast(storage_id), }; } }; - static_assert(sizeof(ProgramLocation) == 0x10 && std::is_pod::value); + static_assert(sizeof(ProgramLocation) == 0x10 && util::is_pod::value); static_assert(sizeof(ProgramLocation) == sizeof(::NcmProgramLocation) && alignof(ProgramLocation) == alignof(::NcmProgramLocation), "ProgramLocation Libnx Compatibility"); diff --git a/libstratosphere/include/stratosphere/ncm/ncm_rights_id.hpp b/libstratosphere/include/stratosphere/ncm/ncm_rights_id.hpp index 6806fa7f..f025407c 100644 --- a/libstratosphere/include/stratosphere/ncm/ncm_rights_id.hpp +++ b/libstratosphere/include/stratosphere/ncm/ncm_rights_id.hpp @@ -25,7 +25,7 @@ namespace ams::ncm { u8 reserved[7]; }; static_assert(sizeof(RightsId) == 0x18); - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); inline bool operator==(const RightsId &lhs, const RightsId &rhs) { return std::tie(lhs.id, lhs.key_generation) == std::tie(rhs.id, rhs.key_generation); diff --git a/libstratosphere/include/stratosphere/os/os_rw_lock_types.hpp b/libstratosphere/include/stratosphere/os/os_rw_lock_types.hpp index 4d6acf17..166d9de8 100644 --- a/libstratosphere/include/stratosphere/os/os_rw_lock_types.hpp +++ b/libstratosphere/include/stratosphere/os/os_rw_lock_types.hpp @@ -36,7 +36,7 @@ namespace ams::os { }; util::BitPack32 counter; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(std::is_trivial::value); union { diff --git a/libstratosphere/include/stratosphere/pgl/pgl_types.hpp b/libstratosphere/include/stratosphere/pgl/pgl_types.hpp index 08aceb8f..3cbd21b2 100644 --- a/libstratosphere/include/stratosphere/pgl/pgl_types.hpp +++ b/libstratosphere/include/stratosphere/pgl/pgl_types.hpp @@ -52,6 +52,6 @@ namespace ams::pgl { }; } }; - static_assert(sizeof(ContentMetaInfo) == 0x10 && std::is_pod::value); + static_assert(sizeof(ContentMetaInfo) == 0x10 && util::is_pod::value); } diff --git a/libstratosphere/include/stratosphere/pm/pm_types.hpp b/libstratosphere/include/stratosphere/pm/pm_types.hpp index f433bddb..a26fe88a 100644 --- a/libstratosphere/include/stratosphere/pm/pm_types.hpp +++ b/libstratosphere/include/stratosphere/pm/pm_types.hpp @@ -97,6 +97,6 @@ namespace ams::pm { u32 event; os::ProcessId process_id; }; - static_assert(sizeof(ProcessEventInfo) == 0x10 && std::is_pod::value, "ProcessEventInfo definition!"); + static_assert(sizeof(ProcessEventInfo) == 0x10 && util::is_pod::value, "ProcessEventInfo definition!"); } diff --git a/libstratosphere/include/stratosphere/reg.hpp b/libstratosphere/include/stratosphere/reg.hpp index 6321d53b..6b5076f9 100644 --- a/libstratosphere/include/stratosphere/reg.hpp +++ b/libstratosphere/include/stratosphere/reg.hpp @@ -36,7 +36,7 @@ namespace ams::reg { } inline void SetBits(volatile u32 *reg, u32 mask) { - *reg |= mask; + *reg = *reg | mask; } inline void SetBits(uintptr_t reg, u32 mask) { @@ -44,7 +44,7 @@ namespace ams::reg { } inline void ClearBits(volatile u32 *reg, u32 mask) { - *reg &= ~mask; + *reg = *reg & ~mask; } inline void ClearBits(uintptr_t reg, u32 mask) { @@ -52,7 +52,7 @@ namespace ams::reg { } inline void MaskBits(volatile u32 *reg, u32 mask) { - *reg &= mask; + *reg = *reg & mask; } inline void MaskBits(uintptr_t reg, u32 mask) { diff --git a/libstratosphere/include/stratosphere/settings/factory/settings_device_certificate.hpp b/libstratosphere/include/stratosphere/settings/factory/settings_device_certificate.hpp index b9be0525..4c445a95 100644 --- a/libstratosphere/include/stratosphere/settings/factory/settings_device_certificate.hpp +++ b/libstratosphere/include/stratosphere/settings/factory/settings_device_certificate.hpp @@ -22,18 +22,18 @@ namespace ams::settings::factory { u8 data[0x180]; }; static_assert(sizeof(EccP256DeviceCertificate) == 0x180); - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); struct EccB233DeviceCertificate { u8 data[0x180]; }; static_assert(sizeof(EccB233DeviceCertificate) == 0x180); - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); struct Rsa2048DeviceCertificate { u8 data[0x240]; }; static_assert(sizeof(Rsa2048DeviceCertificate) == 0x240); - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); } diff --git a/libstratosphere/include/stratosphere/settings/factory/settings_serial_number.hpp b/libstratosphere/include/stratosphere/settings/factory/settings_serial_number.hpp index 068d7d65..301139cc 100644 --- a/libstratosphere/include/stratosphere/settings/factory/settings_serial_number.hpp +++ b/libstratosphere/include/stratosphere/settings/factory/settings_serial_number.hpp @@ -22,6 +22,6 @@ namespace ams::settings::factory { char str[0x18]; }; static_assert(sizeof(SerialNumber) == 0x18); - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); } diff --git a/libstratosphere/include/stratosphere/settings/settings_fwdbg_types.hpp b/libstratosphere/include/stratosphere/settings/settings_fwdbg_types.hpp index 461e36b0..7fee0800 100644 --- a/libstratosphere/include/stratosphere/settings/settings_fwdbg_types.hpp +++ b/libstratosphere/include/stratosphere/settings/settings_fwdbg_types.hpp @@ -27,12 +27,12 @@ namespace ams::settings::fwdbg { char value[util::AlignUp(SettingsNameLengthMax + 1, alignof(u64))]; }; - static_assert(std::is_pod::value && sizeof(SettingsName) > SettingsNameLengthMax); + static_assert(util::is_pod::value && sizeof(SettingsName) > SettingsNameLengthMax); struct SettingsItemKey : sf::LargeData { char value[util::AlignUp(SettingsItemKeyLengthMax + 1, alignof(u64))]; }; - static_assert(std::is_pod::value && sizeof(SettingsItemKey) > SettingsItemKeyLengthMax); + static_assert(util::is_pod::value && sizeof(SettingsItemKey) > SettingsItemKeyLengthMax); } diff --git a/libstratosphere/include/stratosphere/settings/settings_types.hpp b/libstratosphere/include/stratosphere/settings/settings_types.hpp index 0b960062..2930d1ff 100644 --- a/libstratosphere/include/stratosphere/settings/settings_types.hpp +++ b/libstratosphere/include/stratosphere/settings/settings_types.hpp @@ -152,7 +152,7 @@ namespace ams::settings { return impl::IsValidLanguageCode(lc, std::make_index_sequence{}); } - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(sizeof(LanguageCode) == sizeof(u64)); /* Not an official type, but convenient. */ @@ -193,7 +193,7 @@ namespace ams::settings { } }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(sizeof(FirmwareVersion) == sizeof(::SetSysFirmwareVersion)); constexpr inline bool operator==(const FirmwareVersion &lhs, const FirmwareVersion &rhs) { diff --git a/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_server_message_processor.hpp b/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_server_message_processor.hpp index 65dd2701..f96c6fd4 100644 --- a/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_server_message_processor.hpp +++ b/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_server_message_processor.hpp @@ -63,7 +63,7 @@ namespace ams::sf::cmif { } }; - static_assert(std::is_pod::value, "std::is_pod::value"); + static_assert(util::is_pod::value, "util::is_pod::value"); static_assert(sizeof(ServerMessageRuntimeMetadata) == sizeof(u64), "sizeof(ServerMessageRuntimeMetadata)"); class ServerMessageProcessor { diff --git a/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_service_dispatch.hpp b/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_service_dispatch.hpp index 44e35b4f..cca03664 100644 --- a/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_service_dispatch.hpp +++ b/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_service_dispatch.hpp @@ -61,7 +61,7 @@ namespace ams::sf::cmif { return this->handler; } }; - static_assert(std::is_pod::value && sizeof(ServiceCommandMeta) == 0x18, "sizeof(ServiceCommandMeta)"); + static_assert(util::is_pod::value && sizeof(ServiceCommandMeta) == 0x18, "sizeof(ServiceCommandMeta)"); namespace impl { diff --git a/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp b/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp index 3ceb664d..2247d6de 100644 --- a/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp +++ b/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp @@ -77,7 +77,7 @@ namespace ams::sf { class Out> : public impl::OutObjectTag { static_assert(std::is_base_of::value, "Out> requires ServiceObject base."); - template + template friend class Out; public: @@ -308,11 +308,7 @@ namespace ams::sf::impl { /* Use insertion sort, which is stable and optimal for small numbers of parameters. */ for (size_t i = 1; i < sizeof...(Ts); i++) { for (size_t j = i; j > 0 && values[map[j-1]] > values[map[j]]; j--) { - /* std::swap is not constexpr until c++20 :( */ - /* TODO: std::swap(map[j], map[j-1]); */ - const size_t tmp = map[j]; - map[j] = map[j-1]; - map[j-1] = tmp; + std::swap(map[j], map[j-1]); } } } @@ -1042,7 +1038,7 @@ namespace ams::sf::impl { }; constexpr Result GetCmifOutHeaderPointer(CmifOutHeader **out_header_ptr, cmif::PointerAndSize &out_raw_data) { - CmifOutHeader *header = reinterpret_cast(out_raw_data.GetPointer()); + CmifOutHeader *header = static_cast(out_raw_data.GetPointer()); R_UNLESS(out_raw_data.GetSize() >= sizeof(*header), sf::cmif::ResultInvalidHeaderSize()); out_raw_data = cmif::PointerAndSize(out_raw_data.GetAddress() + sizeof(*header), out_raw_data.GetSize() - sizeof(*header)); *out_header_ptr = header; diff --git a/libstratosphere/include/stratosphere/sf/sf_out.hpp b/libstratosphere/include/stratosphere/sf/sf_out.hpp index b5fb1e6f..414c916d 100644 --- a/libstratosphere/include/stratosphere/sf/sf_out.hpp +++ b/libstratosphere/include/stratosphere/sf/sf_out.hpp @@ -33,9 +33,9 @@ namespace ams::sf { struct IsOutForceEnabled<::ams::Result> : public std::true_type{}; template - using IsOutEnabled = typename std::enable_if::value || IsOutForceEnabled::value>::type; + concept OutEnabled = (std::is_trivial::value || IsOutForceEnabled::value) && !std::is_pointer::value; - template> + template requires OutEnabled class Out : public impl::OutBaseTag { public: static constexpr size_t TypeSize = sizeof(T); diff --git a/libstratosphere/source/ams/ams_emummc_api.cpp b/libstratosphere/source/ams/ams_emummc_api.cpp index f00f8653..f1c1c888 100644 --- a/libstratosphere/source/ams/ams_emummc_api.cpp +++ b/libstratosphere/source/ams/ams_emummc_api.cpp @@ -13,7 +13,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include namespace ams::emummc { diff --git a/libstratosphere/source/ams/ams_environment.cpp b/libstratosphere/source/ams/ams_environment.cpp index 47babfb9..7679570a 100644 --- a/libstratosphere/source/ams/ams_environment.cpp +++ b/libstratosphere/source/ams/ams_environment.cpp @@ -13,7 +13,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include #include "ams_bpc.h" @@ -182,6 +181,9 @@ extern "C" { /* Custom abort handler, so that std::abort will trigger these. */ void abort() { + static ams::os::Mutex abort_lock(true); + std::scoped_lock lk(abort_lock); + ams::AbortImpl(); __builtin_unreachable(); } diff --git a/libstratosphere/source/ams/ams_exosphere_api.cpp b/libstratosphere/source/ams/ams_exosphere_api.cpp index 63243d66..e964d393 100644 --- a/libstratosphere/source/ams/ams_exosphere_api.cpp +++ b/libstratosphere/source/ams/ams_exosphere_api.cpp @@ -13,7 +13,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include #include #include diff --git a/libstratosphere/source/capsrv/server/decodersrv/decodersrv_decoder_work_memory.hpp b/libstratosphere/source/capsrv/server/decodersrv/decodersrv_decoder_work_memory.hpp index cf590c57..11b38088 100644 --- a/libstratosphere/source/capsrv/server/decodersrv/decodersrv_decoder_work_memory.hpp +++ b/libstratosphere/source/capsrv/server/decodersrv/decodersrv_decoder_work_memory.hpp @@ -23,6 +23,6 @@ namespace ams::capsrv::server { }; static_assert(sizeof(DecoderWorkMemory) == SoftwareJpegDecoderWorkMemorySize); static_assert(alignof(DecoderWorkMemory) == os::MemoryPageSize); - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); } diff --git a/libstratosphere/source/cfg/cfg_flags.cpp b/libstratosphere/source/cfg/cfg_flags.cpp index c607cbab..abf078a0 100644 --- a/libstratosphere/source/cfg/cfg_flags.cpp +++ b/libstratosphere/source/cfg/cfg_flags.cpp @@ -13,7 +13,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include namespace ams::cfg { diff --git a/libstratosphere/source/cfg/cfg_override.cpp b/libstratosphere/source/cfg/cfg_override.cpp index c31cb16b..9bd7fedb 100644 --- a/libstratosphere/source/cfg/cfg_override.cpp +++ b/libstratosphere/source/cfg/cfg_override.cpp @@ -13,7 +13,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include namespace ams::cfg { diff --git a/libstratosphere/source/cfg/cfg_privileged_process.cpp b/libstratosphere/source/cfg/cfg_privileged_process.cpp index 1df518d0..0fe262a8 100644 --- a/libstratosphere/source/cfg/cfg_privileged_process.cpp +++ b/libstratosphere/source/cfg/cfg_privileged_process.cpp @@ -13,7 +13,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include namespace ams::cfg { diff --git a/libstratosphere/source/cfg/cfg_sd_card.cpp b/libstratosphere/source/cfg/cfg_sd_card.cpp index a79a23fa..cbf60a72 100644 --- a/libstratosphere/source/cfg/cfg_sd_card.cpp +++ b/libstratosphere/source/cfg/cfg_sd_card.cpp @@ -13,7 +13,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include namespace ams::cfg { diff --git a/libstratosphere/source/fs/fs_file_path_hash.hpp b/libstratosphere/source/fs/fs_file_path_hash.hpp index bbc58083..3fa00fbc 100644 --- a/libstratosphere/source/fs/fs_file_path_hash.hpp +++ b/libstratosphere/source/fs/fs_file_path_hash.hpp @@ -23,7 +23,7 @@ namespace ams::fs::impl { struct FilePathHash : public Newable { u8 data[FilePathHashSize]; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); inline bool operator==(const FilePathHash &lhs, const FilePathHash &rhs) { return std::memcmp(lhs.data, rhs.data, FilePathHashSize) == 0; diff --git a/libstratosphere/source/fs/fsa/fs_mount_name.hpp b/libstratosphere/source/fs/fsa/fs_mount_name.hpp index 8f77d3fe..de999277 100644 --- a/libstratosphere/source/fs/fsa/fs_mount_name.hpp +++ b/libstratosphere/source/fs/fsa/fs_mount_name.hpp @@ -21,6 +21,6 @@ namespace ams::fs { struct MountName { char str[MountNameLengthMax + 1]; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); } diff --git a/libstratosphere/source/fssystem/fssystem_partition_file_system_meta.cpp b/libstratosphere/source/fssystem/fssystem_partition_file_system_meta.cpp index dc598e49..591c35a9 100644 --- a/libstratosphere/source/fssystem/fssystem_partition_file_system_meta.cpp +++ b/libstratosphere/source/fssystem/fssystem_partition_file_system_meta.cpp @@ -24,7 +24,7 @@ namespace ams::fssystem { u32 name_table_size; u32 reserved; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(sizeof(PartitionFileSystemMeta::PartitionFileSystemHeader) == 0x10); template diff --git a/libstratosphere/source/fssystem/fssystem_romfs_filesystem.cpp b/libstratosphere/source/fssystem/fssystem_romfs_filesystem.cpp index 93659d16..009c51d0 100644 --- a/libstratosphere/source/fssystem/fssystem_romfs_filesystem.cpp +++ b/libstratosphere/source/fssystem/fssystem_romfs_filesystem.cpp @@ -37,7 +37,7 @@ namespace ams::fssystem { virtual ~RomFsFile() { /* ... */ } public: virtual Result ReadImpl(size_t *out, s64 offset, void *buffer, size_t size, const fs::ReadOption &option) override { - R_TRY(buffers::DoContinuouslyUntilBufferIsAllocated([=]() -> Result { + R_TRY(buffers::DoContinuouslyUntilBufferIsAllocated([=, this]() -> Result { size_t read_size = 0; R_TRY(this->DryRead(std::addressof(read_size), offset, size, option, fs::OpenMode_Read)); @@ -84,7 +84,7 @@ namespace ams::fssystem { operate_size = this->GetSize() - offset; } - R_TRY(buffers::DoContinuouslyUntilBufferIsAllocated([=]() -> Result { + R_TRY(buffers::DoContinuouslyUntilBufferIsAllocated([=, this]() -> Result { R_TRY(this->parent->GetBaseStorage()->OperateRange(dst, dst_size, op_id, this->start + offset, operate_size, src, src_size)); return ResultSuccess(); }, AMS_CURRENT_FUNCTION_NAME)); @@ -113,7 +113,7 @@ namespace ams::fssystem { virtual ~RomFsDirectory() override { /* ... */ } public: virtual Result ReadImpl(s64 *out_count, fs::DirectoryEntry *out_entries, s64 max_entries) { - R_TRY(buffers::DoContinuouslyUntilBufferIsAllocated([=]() -> Result { + R_TRY(buffers::DoContinuouslyUntilBufferIsAllocated([=, this]() -> Result { return this->ReadImpl(out_count, std::addressof(this->current_find), out_entries, max_entries); }, AMS_CURRENT_FUNCTION_NAME)); return ResultSuccess(); @@ -278,7 +278,7 @@ namespace ams::fssystem { } Result RomFsFileSystem::GetFileInfo(RomFileTable::FileInfo *out, const char *path) { - R_TRY(buffers::DoContinuouslyUntilBufferIsAllocated([=]() -> Result { + R_TRY(buffers::DoContinuouslyUntilBufferIsAllocated([=, this]() -> Result { R_TRY_CATCH(this->rom_file_table.OpenFile(out, path)) { R_CONVERT(fs::ResultDbmNotFound, fs::ResultPathNotFound()); } R_END_TRY_CATCH; @@ -325,7 +325,7 @@ namespace ams::fssystem { } Result RomFsFileSystem::GetEntryTypeImpl(fs::DirectoryEntryType *out, const char *path) { - R_TRY(buffers::DoContinuouslyUntilBufferIsAllocated([=]() -> Result { + R_TRY(buffers::DoContinuouslyUntilBufferIsAllocated([=, this]() -> Result { RomDirectoryInfo dir_info; R_TRY_CATCH(this->rom_file_table.GetDirectoryInformation(std::addressof(dir_info), path)) { diff --git a/libstratosphere/source/kvdb/kvdb_archive.cpp b/libstratosphere/source/kvdb/kvdb_archive.cpp index f3f36575..35070451 100644 --- a/libstratosphere/source/kvdb/kvdb_archive.cpp +++ b/libstratosphere/source/kvdb/kvdb_archive.cpp @@ -13,7 +13,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include namespace ams::kvdb { @@ -42,7 +41,7 @@ namespace ams::kvdb { return header; } }; - static_assert(sizeof(ArchiveHeader) == 0xC && std::is_pod::value, "ArchiveHeader definition!"); + static_assert(sizeof(ArchiveHeader) == 0xC && util::is_pod::value, "ArchiveHeader definition!"); struct ArchiveEntryHeader { u8 magic[sizeof(ArchiveEntryMagic)]; @@ -62,7 +61,7 @@ namespace ams::kvdb { return header; } }; - static_assert(sizeof(ArchiveEntryHeader) == 0xC && std::is_pod::value, "ArchiveEntryHeader definition!"); + static_assert(sizeof(ArchiveEntryHeader) == 0xC && util::is_pod::value, "ArchiveEntryHeader definition!"); } diff --git a/libstratosphere/source/kvdb/kvdb_file_key_value_store.cpp b/libstratosphere/source/kvdb/kvdb_file_key_value_store.cpp index eb699b60..fbcea57a 100644 --- a/libstratosphere/source/kvdb/kvdb_file_key_value_store.cpp +++ b/libstratosphere/source/kvdb/kvdb_file_key_value_store.cpp @@ -13,7 +13,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include namespace ams::kvdb { diff --git a/libstratosphere/source/map/map_api.cpp b/libstratosphere/source/map/map_api.cpp index 5c3bdf0f..1c7a50b9 100644 --- a/libstratosphere/source/map/map_api.cpp +++ b/libstratosphere/source/map/map_api.cpp @@ -13,7 +13,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include namespace ams::map { diff --git a/libstratosphere/source/mem/impl/heap/mem_impl_heap_tls_heap_static.hpp b/libstratosphere/source/mem/impl/heap/mem_impl_heap_tls_heap_static.hpp index eace7593..523aac2e 100644 --- a/libstratosphere/source/mem/impl/heap/mem_impl_heap_tls_heap_static.hpp +++ b/libstratosphere/source/mem/impl/heap/mem_impl_heap_tls_heap_static.hpp @@ -160,7 +160,7 @@ namespace ams::mem::impl::heap { template static ALWAYS_INLINE T *AlignUpPage(T *ptr) { - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(util::IsAligned(PageSize, alignof(T))); return reinterpret_cast(AlignUpPage(reinterpret_cast(ptr))); } @@ -171,7 +171,7 @@ namespace ams::mem::impl::heap { template static ALWAYS_INLINE T *AlignDownPage(T *ptr) { - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(util::IsAligned(PageSize, alignof(T))); return reinterpret_cast(AlignDownPage(reinterpret_cast(ptr))); } @@ -182,7 +182,7 @@ namespace ams::mem::impl::heap { template static ALWAYS_INLINE T *AlignUpPhysicalPage(T *ptr) { - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(util::IsAligned(PhysicalPageSize, alignof(T))); return reinterpret_cast(AlignUpPhysicalPage(reinterpret_cast(ptr))); } @@ -193,7 +193,7 @@ namespace ams::mem::impl::heap { template static ALWAYS_INLINE T *AlignDownPhysicalPage(T *ptr) { - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(util::IsAligned(PhysicalPageSize, alignof(T))); return reinterpret_cast(AlignDownPhysicalPage(reinterpret_cast(ptr))); } diff --git a/libstratosphere/source/ncm/ncm_content_meta_database_impl.cpp b/libstratosphere/source/ncm/ncm_content_meta_database_impl.cpp index a9cad853..30d5ac10 100644 --- a/libstratosphere/source/ncm/ncm_content_meta_database_impl.cpp +++ b/libstratosphere/source/ncm/ncm_content_meta_database_impl.cpp @@ -451,7 +451,7 @@ namespace ams::ncm { /* Ensure this type of key has an owner. */ R_UNLESS(key.type == ContentMetaType::Application || key.type == ContentMetaType::Patch || key.type == ContentMetaType::AddOnContent, ncm::ResultInvalidContentMetaKey()); - + /* Applications are their own owner. */ if (key.type == ContentMetaType::Application) { out_id.SetValue({key.id}); diff --git a/libstratosphere/source/os/impl/os_resource_manager.cpp b/libstratosphere/source/os/impl/os_resource_manager.cpp index 6585ea6c..6ff528a3 100644 --- a/libstratosphere/source/os/impl/os_resource_manager.cpp +++ b/libstratosphere/source/os/impl/os_resource_manager.cpp @@ -18,7 +18,6 @@ namespace ams::os::impl { - /* TODO: C++20 constinit */ - TYPED_STORAGE(OsResourceManager) ResourceManagerHolder::s_resource_manager_storage = {}; + constinit TYPED_STORAGE(OsResourceManager) ResourceManagerHolder::s_resource_manager_storage = {}; } diff --git a/libstratosphere/source/os/impl/os_waitable_manager_impl.cpp b/libstratosphere/source/os/impl/os_waitable_manager_impl.cpp index 4da762eb..e5a2a48d 100644 --- a/libstratosphere/source/os/impl/os_waitable_manager_impl.cpp +++ b/libstratosphere/source/os/impl/os_waitable_manager_impl.cpp @@ -13,6 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include "os_waitable_manager_impl.hpp" #include "os_waitable_object_list.hpp" #include "os_tick_manager.hpp" diff --git a/libstratosphere/source/os/os_event.cpp b/libstratosphere/source/os/os_event.cpp index 372e6fd6..2350b8ae 100644 --- a/libstratosphere/source/os/os_event.cpp +++ b/libstratosphere/source/os/os_event.cpp @@ -13,6 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include "impl/os_timeout_helper.hpp" #include "impl/os_waitable_object_list.hpp" #include "impl/os_waitable_holder_impl.hpp" diff --git a/libstratosphere/source/os/os_interrupt_event.cpp b/libstratosphere/source/os/os_interrupt_event.cpp index e9823193..e2bd5811 100644 --- a/libstratosphere/source/os/os_interrupt_event.cpp +++ b/libstratosphere/source/os/os_interrupt_event.cpp @@ -13,6 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include "impl/os_interrupt_event_impl.hpp" #include "impl/os_waitable_object_list.hpp" diff --git a/libstratosphere/source/os/os_message_queue.cpp b/libstratosphere/source/os/os_message_queue.cpp index 795ecf4a..b9bdb025 100644 --- a/libstratosphere/source/os/os_message_queue.cpp +++ b/libstratosphere/source/os/os_message_queue.cpp @@ -13,6 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include "impl/os_waitable_object_list.hpp" #include "impl/os_timeout_helper.hpp" diff --git a/libstratosphere/source/os/os_semaphore.cpp b/libstratosphere/source/os/os_semaphore.cpp index e5569109..62fe78d2 100644 --- a/libstratosphere/source/os/os_semaphore.cpp +++ b/libstratosphere/source/os/os_semaphore.cpp @@ -13,6 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include "impl/os_waitable_object_list.hpp" #include "impl/os_timeout_helper.hpp" diff --git a/libstratosphere/source/pgl/srv/pgl_srv_shell.cpp b/libstratosphere/source/pgl/srv/pgl_srv_shell.cpp index 9ffbb85a..633e28ae 100644 --- a/libstratosphere/source/pgl/srv/pgl_srv_shell.cpp +++ b/libstratosphere/source/pgl/srv/pgl_srv_shell.cpp @@ -27,7 +27,7 @@ namespace ams::pgl::srv { os::ProcessId process_id; u32 flags; }; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); enum ProcessDataFlag : u32 { ProcessDataFlag_None = 0, diff --git a/libstratosphere/source/sm/sm_api.cpp b/libstratosphere/source/sm/sm_api.cpp index 4a7b80cc..ef7be4e5 100644 --- a/libstratosphere/source/sm/sm_api.cpp +++ b/libstratosphere/source/sm/sm_api.cpp @@ -13,6 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include "sm_utils.hpp" namespace ams::sm { diff --git a/libstratosphere/source/sm/sm_manager_api.cpp b/libstratosphere/source/sm/sm_manager_api.cpp index 383e0295..5072f3c5 100644 --- a/libstratosphere/source/sm/sm_manager_api.cpp +++ b/libstratosphere/source/sm/sm_manager_api.cpp @@ -13,6 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include "sm_utils.hpp" #include "smm_ams.h" diff --git a/libstratosphere/source/sm/sm_mitm_api.cpp b/libstratosphere/source/sm/sm_mitm_api.cpp index 38bffd8f..431c3b96 100644 --- a/libstratosphere/source/sm/sm_mitm_api.cpp +++ b/libstratosphere/source/sm/sm_mitm_api.cpp @@ -13,6 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include "sm_utils.hpp" namespace ams::sm::mitm { diff --git a/libstratosphere/source/sm/sm_utils.cpp b/libstratosphere/source/sm/sm_utils.cpp index 62d79f3c..2cfefc23 100644 --- a/libstratosphere/source/sm/sm_utils.cpp +++ b/libstratosphere/source/sm/sm_utils.cpp @@ -13,6 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include "sm_utils.hpp" namespace ams::sm::impl { diff --git a/libstratosphere/source/updater/updater_api.cpp b/libstratosphere/source/updater/updater_api.cpp index 00894124..014ea117 100644 --- a/libstratosphere/source/updater/updater_api.cpp +++ b/libstratosphere/source/updater/updater_api.cpp @@ -13,8 +13,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - -#include #include #include diff --git a/libstratosphere/source/updater/updater_bis_management.cpp b/libstratosphere/source/updater/updater_bis_management.cpp index 9e587991..b643634b 100644 --- a/libstratosphere/source/updater/updater_bis_management.cpp +++ b/libstratosphere/source/updater/updater_bis_management.cpp @@ -13,6 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include "updater_bis_management.hpp" namespace ams::updater { diff --git a/libstratosphere/source/updater/updater_bis_save.cpp b/libstratosphere/source/updater/updater_bis_save.cpp index 20618f49..1ab76e0c 100644 --- a/libstratosphere/source/updater/updater_bis_save.cpp +++ b/libstratosphere/source/updater/updater_bis_save.cpp @@ -13,6 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include "updater_bis_save.hpp" namespace ams::updater { diff --git a/libstratosphere/source/updater/updater_files.cpp b/libstratosphere/source/updater/updater_files.cpp index 3266862f..3d668181 100644 --- a/libstratosphere/source/updater/updater_files.cpp +++ b/libstratosphere/source/updater/updater_files.cpp @@ -13,6 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include "updater_files.hpp" namespace ams::updater { diff --git a/libstratosphere/source/updater/updater_paths.cpp b/libstratosphere/source/updater/updater_paths.cpp index 6ede7d00..4fefa5df 100644 --- a/libstratosphere/source/updater/updater_paths.cpp +++ b/libstratosphere/source/updater/updater_paths.cpp @@ -13,6 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include "updater_paths.hpp" namespace ams::updater { diff --git a/libstratosphere/source/util/ini.c b/libstratosphere/source/util/ini.c index 426430c9..501e9224 100644 --- a/libstratosphere/source/util/ini.c +++ b/libstratosphere/source/util/ini.c @@ -70,7 +70,10 @@ static char* find_chars_or_comment(const char* s, const char* chars) /* Version of strncpy that ensures dest (size bytes) is null-terminated. */ static char* strncpy0(char* dest, const char* src, size_t size) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-truncation" strncpy(dest, src, size - 1); +#pragma GCC diagnostic pop dest[size - 1] = '\0'; return dest; } diff --git a/libvapours/include/vapours/crypto/crypto_rsa_oaep_decryptor.hpp b/libvapours/include/vapours/crypto/crypto_rsa_oaep_decryptor.hpp index 73bbeacf..86b3750b 100644 --- a/libvapours/include/vapours/crypto/crypto_rsa_oaep_decryptor.hpp +++ b/libvapours/include/vapours/crypto/crypto_rsa_oaep_decryptor.hpp @@ -23,7 +23,7 @@ namespace ams::crypto { - template /* requires HashFunction */ + template requires impl::HashFunction class RsaOaepDecryptor { NON_COPYABLE(RsaOaepDecryptor); NON_MOVEABLE(RsaOaepDecryptor); diff --git a/libvapours/include/vapours/crypto/crypto_rsa_oaep_encryptor.hpp b/libvapours/include/vapours/crypto/crypto_rsa_oaep_encryptor.hpp index bd29e4e2..bcda3471 100644 --- a/libvapours/include/vapours/crypto/crypto_rsa_oaep_encryptor.hpp +++ b/libvapours/include/vapours/crypto/crypto_rsa_oaep_encryptor.hpp @@ -23,7 +23,7 @@ namespace ams::crypto { - template /* requires HashFunction */ + template requires impl::HashFunction class RsaOaepEncryptor { NON_COPYABLE(RsaOaepEncryptor); NON_MOVEABLE(RsaOaepEncryptor); diff --git a/libvapours/include/vapours/crypto/crypto_rsa_pss_verifier.hpp b/libvapours/include/vapours/crypto/crypto_rsa_pss_verifier.hpp index bd7ddcea..27385448 100644 --- a/libvapours/include/vapours/crypto/crypto_rsa_pss_verifier.hpp +++ b/libvapours/include/vapours/crypto/crypto_rsa_pss_verifier.hpp @@ -23,7 +23,7 @@ namespace ams::crypto { - template /* requires HashFunction */ + template requires impl::HashFunction class RsaPssVerifier { NON_COPYABLE(RsaPssVerifier); NON_MOVEABLE(RsaPssVerifier); diff --git a/libvapours/include/vapours/crypto/impl/crypto_hash_function.hpp b/libvapours/include/vapours/crypto/impl/crypto_hash_function.hpp index b598b46f..68ca106a 100644 --- a/libvapours/include/vapours/crypto/impl/crypto_hash_function.hpp +++ b/libvapours/include/vapours/crypto/impl/crypto_hash_function.hpp @@ -23,15 +23,13 @@ namespace ams::crypto::impl { - /* TODO: C++20 - template - concept HashFunction = requires(T &t, const void *cv, void *v, size_t sz) { - { T::HashSize } -> std::same_as; - { T::BlockSize } -> std::same_as; - { t.Initialize() } -> std::same_as; - { t.Update(cv, sz) } -> std::same_as; - { t.GetHash(v, sz) } -> std::same_as; - }; - */ + template + concept HashFunction = requires(T &t, const void *cv, void *v, size_t sz) { + { T::HashSize } -> std::convertible_to; + { T::BlockSize } -> std::convertible_to; + { t.Initialize() } -> std::same_as; + { t.Update(cv, sz) } -> std::same_as; + { t.GetHash(v, sz) } -> std::same_as; + }; } diff --git a/libvapours/include/vapours/crypto/impl/crypto_rsa_oaep_impl.hpp b/libvapours/include/vapours/crypto/impl/crypto_rsa_oaep_impl.hpp index d925f16a..cc0e5956 100644 --- a/libvapours/include/vapours/crypto/impl/crypto_rsa_oaep_impl.hpp +++ b/libvapours/include/vapours/crypto/impl/crypto_rsa_oaep_impl.hpp @@ -22,7 +22,7 @@ namespace ams::crypto::impl { - template /* requires HashFunction */ + template requires HashFunction class RsaOaepImpl { NON_COPYABLE(RsaOaepImpl); NON_MOVEABLE(RsaOaepImpl); diff --git a/libvapours/include/vapours/crypto/impl/crypto_rsa_pss_impl.hpp b/libvapours/include/vapours/crypto/impl/crypto_rsa_pss_impl.hpp index 1ce73e72..3febb5ab 100644 --- a/libvapours/include/vapours/crypto/impl/crypto_rsa_pss_impl.hpp +++ b/libvapours/include/vapours/crypto/impl/crypto_rsa_pss_impl.hpp @@ -22,7 +22,7 @@ namespace ams::crypto::impl { - template /* requires HashFunction */ + template requires HashFunction class RsaPssImpl { NON_COPYABLE(RsaPssImpl); NON_MOVEABLE(RsaPssImpl); diff --git a/libvapours/include/vapours/crypto/impl/crypto_sha256_impl.hpp b/libvapours/include/vapours/crypto/impl/crypto_sha256_impl.hpp index bbd145ef..ab9b6971 100644 --- a/libvapours/include/vapours/crypto/impl/crypto_sha256_impl.hpp +++ b/libvapours/include/vapours/crypto/impl/crypto_sha256_impl.hpp @@ -66,6 +66,6 @@ namespace ams::crypto::impl { } }; - /* static_assert(HashFunction); */ + static_assert(HashFunction); } diff --git a/libvapours/include/vapours/defines.hpp b/libvapours/include/vapours/defines.hpp index 5f78e90f..39164080 100644 --- a/libvapours/include/vapours/defines.hpp +++ b/libvapours/include/vapours/defines.hpp @@ -35,9 +35,6 @@ #define CONST_FOLD(x) (__builtin_constant_p(x) ? (x) : (x)) -#define WRAP_TEMPLATE_CONSTANT(...) ([] { using U = union { static constexpr auto GetValue() { return __VA_ARGS__; } }; return U{}; }()) -#define UNWRAP_TEMPLATE_CONSTANT(tpnm) (tpnm::GetValue()) - #define CONCATENATE_IMPL(s1, s2) s1##s2 #define CONCATENATE(s1, s2) CONCATENATE_IMPL(s1, s2) diff --git a/libvapours/include/vapours/includes.hpp b/libvapours/include/vapours/includes.hpp index 713d7d4c..577e2c45 100644 --- a/libvapours/include/vapours/includes.hpp +++ b/libvapours/include/vapours/includes.hpp @@ -28,6 +28,7 @@ /* C++ headers. */ #include +#include #include #include #include @@ -38,6 +39,8 @@ #include #include #include +#include +#include /* Stratosphere wants additional libstdc++ headers, others do not. */ #ifdef ATMOSPHERE_IS_STRATOSPHERE diff --git a/libvapours/include/vapours/span.hpp b/libvapours/include/vapours/span.hpp index ee0a07a2..dc94f5f3 100644 --- a/libvapours/include/vapours/span.hpp +++ b/libvapours/include/vapours/span.hpp @@ -19,207 +19,7 @@ namespace ams { - /* TODO C++20 switch to template using Span = std::span */ - - namespace impl { - - template - class SpanConstIterator; - - template - class SpanIteratorImpl { - public: - friend class SpanConstIterator; - - using index_type = typename Span::index_type; - using difference_type = typename Span::difference_type; - using value_type = typename std::remove_cv::type; - using pointer = typename std::add_pointer::type; - using reference = Reference; - using iterator_category = std::random_access_iterator_tag; - private: - const Span *span = nullptr; - index_type index = 0; - public: - constexpr ALWAYS_INLINE SpanIteratorImpl() = default; - constexpr ALWAYS_INLINE SpanIteratorImpl(const Span *s, index_type idx) : span(s), index(idx) { /* ... */ } - - constexpr ALWAYS_INLINE pointer operator->() const { - return this->span->data() + this->index; - } - - constexpr ALWAYS_INLINE reference operator*() const { - return *this->operator->(); - } - - constexpr ALWAYS_INLINE Derived operator++(int) { - auto prev = static_cast(*this); - ++(*this); - return prev; - } - - constexpr ALWAYS_INLINE Derived operator--(int) { - auto prev = static_cast(*this); - --(*this); - return prev; - } - - constexpr ALWAYS_INLINE Derived &operator++() { ++this->index; return static_cast(*this); } - constexpr ALWAYS_INLINE Derived &operator--() { --this->index; return static_cast(*this); } - - constexpr ALWAYS_INLINE Derived &operator+=(difference_type n) { this->index += n; return static_cast(*this); } - constexpr ALWAYS_INLINE Derived &operator-=(difference_type n) { this->index -= n; return static_cast(*this); } - - constexpr ALWAYS_INLINE Derived operator+(difference_type n) const { auto r = static_cast(*this); return r += n; } - constexpr ALWAYS_INLINE Derived operator-(difference_type n) const { auto r = static_cast(*this); return r -= n; } - - constexpr ALWAYS_INLINE friend Derived operator+(difference_type n, Derived it) { return it + n; } - constexpr ALWAYS_INLINE difference_type operator-(Derived rhs) const { AMS_ASSERT(this->span == rhs.span); return this->index - rhs.index; } - - constexpr ALWAYS_INLINE reference operator[](difference_type n) const { return *(*this + n); } - - constexpr ALWAYS_INLINE friend bool operator==(Derived lhs, Derived rhs) { - return lhs.span == rhs.span && lhs.index == rhs.index; - } - - constexpr ALWAYS_INLINE friend bool operator<(Derived lhs, Derived rhs) { - AMS_ASSERT(lhs.span == rhs.span); - return lhs.index < rhs.index; - } - - constexpr ALWAYS_INLINE friend bool operator!=(Derived lhs, Derived rhs) { return !(lhs == rhs); } - - constexpr ALWAYS_INLINE friend bool operator>(Derived lhs, Derived rhs) { return rhs < lhs; } - - constexpr ALWAYS_INLINE friend bool operator<=(Derived lhs, Derived rhs) { return !(lhs > rhs); } - constexpr ALWAYS_INLINE friend bool operator>=(Derived lhs, Derived rhs) { return !(lhs < rhs); } - }; - - template - class SpanIterator : public SpanIteratorImpl, typename Span::element_type&> { - public: - using SpanIteratorImpl, typename Span::element_type&>::SpanIteratorImpl; - }; - - template - class SpanConstIterator : public SpanIteratorImpl, const typename Span::element_type&> { - public: - using SpanIteratorImpl, const typename Span::element_type&>::SpanIteratorImpl; - - constexpr ALWAYS_INLINE SpanConstIterator() = default; - constexpr ALWAYS_INLINE SpanConstIterator(const SpanIterator &rhs) : SpanConstIterator(rhs.span, rhs.index) { /* ... */ } - }; - - } - template - class Span { - public: - using element_type = T; - using value_type = typename std::remove_cv::type; - using index_type = std::ptrdiff_t; - using difference_type = std::ptrdiff_t; - using pointer = element_type *; - using reference = element_type &; - using iterator = ::ams::impl::SpanIterator; - using const_iterator = ::ams::impl::SpanConstIterator; - using reverse_iterator = std::reverse_iterator; - using const_reverse_iterator = std::reverse_iterator; - private: - T *ptr; - index_type num_elements; - public: - constexpr ALWAYS_INLINE Span() : ptr(), num_elements() { /* ... */ } - - constexpr ALWAYS_INLINE Span(T *p, index_type size) : ptr(p), num_elements(size) { - AMS_ASSERT(this->num_elements > 0 || this->ptr == nullptr); - } - - constexpr ALWAYS_INLINE Span(T *start, T *end) : Span(start, end - start) { /* ... */ } - - template - constexpr ALWAYS_INLINE Span(T (&arr)[Size]) : Span(static_cast(arr), static_cast(Size)) { /* ... */ } - - template - constexpr ALWAYS_INLINE Span(std::array &arr) : Span(arr.data(), static_cast(Size)) { /* ... */ } - - template - constexpr ALWAYS_INLINE Span(const std::array &arr) : Span(arr.data(), static_cast(Size)) { /* ... */ } - - template::value>::type> - constexpr ALWAYS_INLINE Span(const Span &rhs) : Span(rhs.data(), rhs.size()) { /* ... */ } - public: - constexpr ALWAYS_INLINE iterator begin() const { return { this, 0 }; } - constexpr ALWAYS_INLINE iterator end() const { return { this, this->num_elements }; } - - constexpr ALWAYS_INLINE const_iterator cbegin() const { return { this, 0 }; } - constexpr ALWAYS_INLINE const_iterator cend() const { return { this, this->num_elements }; } - - constexpr ALWAYS_INLINE reverse_iterator rbegin() const { return reverse_iterator(this->end()); } - constexpr ALWAYS_INLINE reverse_iterator rend() const { return reverse_iterator(this->begin()); } - - constexpr ALWAYS_INLINE const_reverse_iterator crbegin() const { return reverse_iterator(this->cend()); } - constexpr ALWAYS_INLINE const_reverse_iterator crend() const { return reverse_iterator(this->cbegin()); } - - constexpr ALWAYS_INLINE pointer data() const { return this->ptr; } - - constexpr ALWAYS_INLINE index_type size() const { return this->num_elements; } - constexpr ALWAYS_INLINE index_type size_bytes() const { return this->size() * sizeof(T); } - - constexpr ALWAYS_INLINE bool empty() const { return this->size() == 0; } - - constexpr ALWAYS_INLINE T &operator[](index_type idx) const { - AMS_ASSERT(idx < this->size()); - return this->ptr[idx]; - } - - constexpr ALWAYS_INLINE T &operator()(index_type idx) const { return (*this)[idx]; } - - constexpr ALWAYS_INLINE Span first(index_type size) const { - AMS_ASSERT(size <= this->size()); - return { this->ptr, size }; - } - - constexpr ALWAYS_INLINE Span last(index_type size) const { - AMS_ASSERT(size <= this->size()); - return { this->ptr + (this->size() - size), size }; - } - - constexpr ALWAYS_INLINE Span subspan(index_type idx, index_type size) const { - AMS_ASSERT(size <= this->size()); - AMS_ASSERT(this->size() - size >= idx); - return { this->ptr + idx, size }; - } - - constexpr ALWAYS_INLINE Span subspan(index_type idx) const { - AMS_ASSERT(idx <= this->size()); - return { this->ptr + idx, this->size() - idx }; - } - }; - - template - constexpr ALWAYS_INLINE Span MakeSpan(T *start, T *end) { - return { start, end }; - } - - template - constexpr ALWAYS_INLINE Span MakeSpan(T *p, typename Span::index_type size) { - return { p, size }; - } - - template - constexpr ALWAYS_INLINE Span MakeSpan(T (&arr)[Size]) { - return Span(arr); - } - - template - constexpr ALWAYS_INLINE Span MakeSpan(std::array &arr) { - return Span(arr); - } - - template - constexpr ALWAYS_INLINE Span MakeSpan(const std::array &arr) { - return Span(arr); - } + using Span = std::span; } diff --git a/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_code_generator.hpp b/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_code_generator.hpp index 3cf0b73d..88866a05 100644 --- a/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_code_generator.hpp +++ b/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_code_generator.hpp @@ -261,12 +261,11 @@ namespace ams::svc::codegen::impl { /* TODO */ }; - template - static ALWAYS_INLINE void GenerateCodeForMetaCode(MetaCodeHolder) { - constexpr auto MetaCode = UNWRAP_TEMPLATE_CONSTANT(MetaCodeHolder); + template + static ALWAYS_INLINE void GenerateCodeForMetaCode() { constexpr size_t NumOperations = MetaCode.GetNumOperations(); static_assert(NumOperations <= 64); - #define SVC_CODEGEN_HANDLER(n) do { if constexpr (n < NumOperations) { constexpr auto Operation = MetaCode.GetOperation(n); GenerateCodeForOperation(WRAP_TEMPLATE_CONSTANT(Operation)); } } while (0) + #define SVC_CODEGEN_HANDLER(n) do { if constexpr (n < NumOperations) { constexpr auto Operation = MetaCode.GetOperation(n); GenerateCodeForOperation(); } } while (0) SVC_CODEGEN_FOR_I_FROM_0_TO_64(SVC_CODEGEN_HANDLER) #undef SVC_CODEGEN_HANDLER } diff --git a/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_common.hpp b/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_common.hpp index 97f6f5d2..f1a7b2b6 100644 --- a/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_common.hpp +++ b/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_common.hpp @@ -143,7 +143,7 @@ namespace ams::svc::codegen::impl { template class RegisterAllocator { - private: + public: std::array map; public: constexpr explicit RegisterAllocator() : map() { /* ... */ } diff --git a/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_kernel_svc_wrapper.hpp b/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_kernel_svc_wrapper.hpp index 44f11b44..6872199b 100644 --- a/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_kernel_svc_wrapper.hpp +++ b/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_kernel_svc_wrapper.hpp @@ -319,38 +319,43 @@ namespace ams::svc::codegen::impl { template struct TypeIndexFilter { - template - static constexpr auto GetFilteredTupleImpl(UseArrayHolder, std::tuple, std::index_sequence) { - constexpr auto UseArray = UNWRAP_TEMPLATE_CONSTANT(UseArrayHolder); - static_assert(sizeof...(TailType) == sizeof...(TailIndex)); - static_assert(HeadIndex <= UseArray.size()); - if constexpr (sizeof...(TailType) == 0) { - if constexpr (!UseArray[HeadIndex]) { - return std::tuple{}; - } else { - return std::tuple<>{}; - } - } else { - auto tail_tuple = GetFilteredTupleImpl(UseArrayHolder{}, std::tuple{}, std::index_sequence{}); - if constexpr (!UseArray[HeadIndex]) { - return std::tuple_cat(std::tuple{}, tail_tuple); - } else { - return std::tuple_cat(std::tuple<>{}, tail_tuple); - } - } - } + template + struct Helper; - template - static constexpr auto GetFilteredTuple(UseArrayHolder) { - return GetFilteredTupleImpl(UseArrayHolder{}, std::tuple{}, std::make_index_sequence()); - } + template + struct Helper, std::index_sequence> { + using Type = std::tuple<>; + }; + + template + struct Helper, std::index_sequence> { + + using LastHeadType = std::tuple; + using LastNullType = std::tuple<>; + + using LastType = typename std::conditional::type; + + using NextTailType = std::tuple; + using NextTailSequence = std::index_sequence; + + using NextType = typename std::conditional(), std::declval::Type>())), + decltype(std::tuple_cat(std::declval(), std::declval::Type>())) + >::type; + + using Type = typename std::conditional::type; + + }; + + template + using FilteredTupleType = typename Helper, decltype(std::make_index_sequence())>::Type; }; - template - static constexpr auto GetModifiedOperations(AllocatorHolder, std::tuple ops) { + template + static constexpr auto GetModifiedOperations(std::tuple ops) { constexpr size_t ModifyRegister = [] { - auto allocator = UNWRAP_TEMPLATE_CONSTANT(AllocatorHolder); + auto allocator = Allocator; return allocator.AllocateFirstFree(); }(); @@ -359,13 +364,13 @@ namespace ams::svc::codegen::impl { return std::tuple{}; } - template - static constexpr auto GenerateBeforeOperations(MetaCodeGenerator &mcg, AllocatorHolder, std::tuple ops) -> RegisterAllocator { + template + static constexpr auto GenerateBeforeOperations(MetaCodeGenerator &mcg, std::tuple ops) -> RegisterAllocator { constexpr size_t NumOperations = 1 + sizeof...(OtherOperations); using OperationsTuple = decltype(ops); using FilterHelper = TypeIndexFilter; - constexpr auto ProcessOperation = [](MetaCodeGenerator &pr_mcg, auto &allocator, Operation) { + constexpr auto ProcessOperation = [](MetaCodeGenerator &pr_mcg, auto &allocator) { if (Conversion::template CanGenerateCode(allocator)) { Conversion::template GenerateCode(pr_mcg, allocator); return true; @@ -373,12 +378,12 @@ namespace ams::svc::codegen::impl { return false; }; - constexpr auto ProcessResults = [ProcessOperation](std::tuple) { - auto allocator = UNWRAP_TEMPLATE_CONSTANT(AllocatorHolder); + constexpr auto ProcessResults = [](std::tuple) { + auto allocator = AllocatorVal; MetaCodeGenerator pr_mcg; - auto use_array = std::array{ ProcessOperation(pr_mcg, allocator, Operations{})... }; + auto use_array = std::array{ ProcessOp.template operator()(pr_mcg, allocator)... }; return std::make_tuple(use_array, allocator, pr_mcg); - }(OperationsTuple{}); + }.template operator()(OperationsTuple{}); constexpr auto CanGenerate = std::get<0>(ProcessResults); constexpr auto AfterAllocator = std::get<1>(ProcessResults); @@ -388,15 +393,15 @@ namespace ams::svc::codegen::impl { mcg.AddOperationDirectly(GeneratedCode.GetOperation(i)); } - constexpr auto FilteredOperations = FilterHelper::template GetFilteredTuple(WRAP_TEMPLATE_CONSTANT(CanGenerate)); - static_assert(std::tuple_size::value <= NumOperations); - if constexpr (std::tuple_size::value > 0) { - if constexpr (std::tuple_size::value != NumOperations) { - return GenerateBeforeOperations(mcg, WRAP_TEMPLATE_CONSTANT(AfterAllocator), FilteredOperations); + using FilteredOperations = typename FilterHelper::FilteredTupleType; + static_assert(std::tuple_size::value <= NumOperations); + if constexpr (std::tuple_size::value > 0) { + if constexpr (std::tuple_size::value != NumOperations) { + return GenerateBeforeOperations(mcg, FilteredOperations{}); } else { /* No progress was made, so we need to make a change. */ - constexpr auto ModifiedOperations = GetModifiedOperations(WRAP_TEMPLATE_CONSTANT(AfterAllocator), FilteredOperations); - return GenerateBeforeOperations(mcg, WRAP_TEMPLATE_CONSTANT(AfterAllocator), ModifiedOperations); + constexpr auto ModifiedOperations = GetModifiedOperations(FilteredOperations{}); + return GenerateBeforeOperations(mcg, ModifiedOperations); } } else { return AfterAllocator; @@ -433,7 +438,7 @@ namespace ams::svc::codegen::impl { /* Generate code for before operations. */ if constexpr (Conversion::NumBeforeOperations > 0) { - allocator = GenerateBeforeOperations(mcg, WRAP_TEMPLATE_CONSTANT(InitialAllocator), typename Conversion::BeforeOperations{}); + allocator = GenerateBeforeOperations(mcg, typename Conversion::BeforeOperations{}); } else { allocator = InitialAllocator; } @@ -527,8 +532,8 @@ namespace ams::svc::codegen::impl { static ALWAYS_INLINE void WrapSvcFunction() { /* Generate appropriate assembly. */ - GenerateCodeForMetaCode(WRAP_TEMPLATE_CONSTANT(BeforeMetaCode)); - ON_SCOPE_EXIT { GenerateCodeForMetaCode(WRAP_TEMPLATE_CONSTANT(AfterMetaCode)); }; + GenerateCodeForMetaCode(); + ON_SCOPE_EXIT { GenerateCodeForMetaCode(); }; return reinterpret_cast(Function)(); } diff --git a/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_layout.hpp b/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_layout.hpp index 1f4eb0f0..4a6adadd 100644 --- a/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_layout.hpp +++ b/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_layout.hpp @@ -24,7 +24,7 @@ namespace ams::svc::codegen::impl { static constexpr size_t MaxParameters = 8; private: static constexpr size_t InvalidIndex = std::numeric_limits::max(); - private: + public: /* ABI parameters. */ Abi abi; @@ -102,7 +102,7 @@ namespace ams::svc::codegen::impl { }; class ProcedureLayout { - private: + public: Abi abi; ParameterLayout input; ParameterLayout output; @@ -205,7 +205,7 @@ namespace ams::svc::codegen::impl { }; class SvcInvocationLayout { - private: + public: Abi abi; ParameterLayout input; ParameterLayout output; @@ -220,11 +220,7 @@ namespace ams::svc::codegen::impl { } for (size_t i = 1; i < num_parameters; i++) { for (size_t j = i; j > 0 && param_layout.GetParameter(map[j-1]).GetLocation(0) > param_layout.GetParameter(map[j]).GetLocation(0); j--) { - /* std::swap is not constexpr until c++20 :( */ - /* TODO: std::swap(map[j], map[j-1]); */ - const size_t tmp = map[j]; - map[j] = map[j-1]; - map[j-1] = tmp; + std::swap(map[j], map[j-1]); } } diff --git a/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_layout_conversion.hpp b/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_layout_conversion.hpp index bd0190c5..1b018992 100644 --- a/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_layout_conversion.hpp +++ b/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_layout_conversion.hpp @@ -304,9 +304,8 @@ namespace ams::svc::codegen::impl { static constexpr auto DetermineConversionOperations() { [[maybe_unused]] constexpr auto Procedure = LayoutForKernel; [[maybe_unused]] constexpr ParameterLayout Svc = Input ? LayoutForSvc.GetInputLayout() : LayoutForSvc.GetOutputLayout(); - [[maybe_unused]] constexpr std::array ParameterMap = [](SvcHolder){ + [[maybe_unused]] constexpr std::array ParameterMap = [](){ /* We want to iterate over the parameters in sorted order. */ - constexpr ParameterLayout CapturedSvc = UNWRAP_TEMPLATE_CONSTANT(SvcHolder); std::array map{}; const size_t num_parameters = CapturedSvc.GetNumParameters(); for (size_t i = 0; i < num_parameters; i++) { @@ -314,15 +313,11 @@ namespace ams::svc::codegen::impl { } for (size_t i = 1; i < num_parameters; i++) { for (size_t j = i; j > 0 && CapturedSvc.GetParameter(map[j-1]).GetLocation(0) > CapturedSvc.GetParameter(map[j]).GetLocation(0); j--) { - /* std::swap is not constexpr until c++20 :( */ - /* TODO: std::swap(map[j], map[j-1]); */ - const size_t tmp = map[j]; - map[j] = map[j-1]; - map[j-1] = tmp; + std::swap(map[j], map[j-1]); } } return map; - }(WRAP_TEMPLATE_CONSTANT(Svc)); + }.template operator()(); if constexpr (ParameterIndex >= Svc.GetNumParameters()) { /* Base case: we're done. */ @@ -377,16 +372,13 @@ namespace ams::svc::codegen::impl { constexpr size_t RegisterSize = SvcAbiType::RegisterSize; constexpr size_t PassedSize = ProcedureParam.GetTypeSize(); - /* TODO: C++20 templated lambdas. For now, use GCC extension syntax. */ - constexpr auto SvcIndexSequence = [](SvcParamWrapper, std::index_sequence) { - constexpr Parameter CapturedSvcParam = UNWRAP_TEMPLATE_CONSTANT(SvcParamWrapper); + constexpr auto SvcIndexSequence = [](std::index_sequence) { return std::index_sequence{}; - }(WRAP_TEMPLATE_CONSTANT(SvcParam), std::make_index_sequence()); + }.template operator()(std::make_index_sequence()); - constexpr auto OperationValue = [](ProcedureLocWrapper, std::index_sequence) { - constexpr Location CapturedProcedureLoc = UNWRAP_TEMPLATE_CONSTANT(ProcedureLocWrapper); + constexpr auto OperationValue = [](std::index_sequence) { return LayoutConversionBase::OperationScatter{}; - }(WRAP_TEMPLATE_CONSTANT(ProcedureLoc), SvcIndexSequence); + }.template operator()(SvcIndexSequence); constexpr auto cur_op = std::make_tuple(OperationValue); diff --git a/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_meta_code.hpp b/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_meta_code.hpp index 4b1b5d27..8d84a618 100644 --- a/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_meta_code.hpp +++ b/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_meta_code.hpp @@ -79,7 +79,7 @@ namespace ams::svc::codegen::impl { return op; } - private: + public: size_t num_operations; std::array operations; public: @@ -98,15 +98,13 @@ namespace ams::svc::codegen::impl { } }; - template + template static constexpr auto GetOperationParameterSequence() { - constexpr auto _Operation = UNWRAP_TEMPLATE_CONSTANT(_OperationHolder); - constexpr size_t NumParameters = _Operation.num_parameters; + constexpr size_t NumParameters = Operation.num_parameters; - return [](OperationHolder, std::index_sequence) { - constexpr auto Operation = UNWRAP_TEMPLATE_CONSTANT(OperationHolder); + return [](std::index_sequence) { return std::index_sequence{}; - }(_OperationHolder{}, std::make_index_sequence()); + }(std::make_index_sequence()); } template @@ -130,10 +128,9 @@ namespace ams::svc::codegen::impl { #undef META_CODE_OPERATION_KIND_GENERATE_CODE } - template - static ALWAYS_INLINE void GenerateCodeForOperation(OperationHolder) { - constexpr auto Operation = UNWRAP_TEMPLATE_CONSTANT(OperationHolder); - GenerateCodeForOperationImpl(GetOperationParameterSequence()); + template + static ALWAYS_INLINE void GenerateCodeForOperation() { + GenerateCodeForOperationImpl(GetOperationParameterSequence()); } class MetaCodeGenerator { diff --git a/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_parameter.hpp b/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_parameter.hpp index 76825f3e..f077e30b 100644 --- a/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_parameter.hpp +++ b/libvapours/include/vapours/svc/codegen/impl/svc_codegen_impl_parameter.hpp @@ -27,7 +27,7 @@ namespace ams::svc::codegen::impl { class Location { private: static constexpr size_t InvalidIndex = std::numeric_limits::max(); - private: + public: Storage storage; size_t index; public: @@ -75,7 +75,7 @@ namespace ams::svc::codegen::impl { static constexpr size_t MaxLocations = 8; static constexpr size_t IdentifierLengthMax = 0x40; class Identifier { - private: + public: char name[IdentifierLengthMax]; size_t index; public: @@ -99,7 +99,7 @@ namespace ams::svc::codegen::impl { return !(*this == rhs); } }; - private: + public: Identifier identifier; ArgumentType type; size_t type_size; diff --git a/libvapours/include/vapours/svc/ipc/svc_message_buffer.hpp b/libvapours/include/vapours/svc/ipc/svc_message_buffer.hpp index 9a979e87..1c379ca7 100644 --- a/libvapours/include/vapours/svc/ipc/svc_message_buffer.hpp +++ b/libvapours/include/vapours/svc/ipc/svc_message_buffer.hpp @@ -58,11 +58,11 @@ namespace ams::svc::ipc { private: util::BitPack32 header[2]; public: - constexpr ALWAYS_INLINE MessageHeader() : header({util::BitPack32{0}, util::BitPack32{0}}) { + constexpr ALWAYS_INLINE MessageHeader() : header{util::BitPack32{0}, util::BitPack32{0}} { this->header[0].Set(NullTag); } - constexpr ALWAYS_INLINE MessageHeader(u16 tag, bool special, s32 ptr, s32 send, s32 recv, s32 exch, s32 raw, s32 recv_list) : header({util::BitPack32{0}, util::BitPack32{0}}) { + constexpr ALWAYS_INLINE MessageHeader(u16 tag, bool special, s32 ptr, s32 send, s32 recv, s32 exch, s32 raw, s32 recv_list) : header{util::BitPack32{0}, util::BitPack32{0}} { this->header[0].Set(tag); this->header[0].Set(ptr); this->header[0].Set(send); @@ -74,11 +74,11 @@ namespace ams::svc::ipc { this->header[1].Set(special); } - ALWAYS_INLINE explicit MessageHeader(const MessageBuffer &buf) : header({util::BitPack32{0}, util::BitPack32{0}}) { + ALWAYS_INLINE explicit MessageHeader(const MessageBuffer &buf) : header{util::BitPack32{0}, util::BitPack32{0}} { buf.Get(0, this->header, util::size(this->header)); } - ALWAYS_INLINE explicit MessageHeader(const u32 *msg) : header({util::BitPack32{msg[0]}, util::BitPack32{msg[1]}}) { /* ... */ } + ALWAYS_INLINE explicit MessageHeader(const u32 *msg) : header{util::BitPack32{msg[0]}, util::BitPack32{msg[1]}} { /* ... */ } constexpr ALWAYS_INLINE u16 GetTag() const { return this->header[0].Get(); @@ -219,9 +219,9 @@ namespace ams::svc::ipc { private: util::BitPack32 data[3]; public: - constexpr ALWAYS_INLINE MapAliasDescriptor() : data({util::BitPack32{0}, util::BitPack32{0}, util::BitPack32{0}}) { /* ... */ } + constexpr ALWAYS_INLINE MapAliasDescriptor() : data{util::BitPack32{0}, util::BitPack32{0}, util::BitPack32{0}} { /* ... */ } - ALWAYS_INLINE MapAliasDescriptor(const void *buffer, size_t _size, Attribute attr = Attribute_Ipc) : data({util::BitPack32{0}, util::BitPack32{0}, util::BitPack32{0}}) { + ALWAYS_INLINE MapAliasDescriptor(const void *buffer, size_t _size, Attribute attr = Attribute_Ipc) : data{util::BitPack32{0}, util::BitPack32{0}, util::BitPack32{0}} { const u64 address = reinterpret_cast(buffer); const u64 size = static_cast(_size); this->data[0] = { static_cast(size) }; @@ -233,7 +233,7 @@ namespace ams::svc::ipc { this->data[2].Set(GetAddressHigh(address)); } - ALWAYS_INLINE MapAliasDescriptor(const MessageBuffer &buf, s32 index) : data({util::BitPack32{0}, util::BitPack32{0}, util::BitPack32{0}}) { + ALWAYS_INLINE MapAliasDescriptor(const MessageBuffer &buf, s32 index) : data{util::BitPack32{0}, util::BitPack32{0}, util::BitPack32{0}} { buf.Get(index, this->data, util::size(this->data)); } @@ -283,9 +283,9 @@ namespace ams::svc::ipc { private: util::BitPack32 data[2]; public: - constexpr ALWAYS_INLINE PointerDescriptor() : data({util::BitPack32{0}, util::BitPack32{0}}) { /* ... */ } + constexpr ALWAYS_INLINE PointerDescriptor() : data{util::BitPack32{0}, util::BitPack32{0}} { /* ... */ } - ALWAYS_INLINE PointerDescriptor(const void *buffer, size_t size, s32 index) : data({util::BitPack32{0}, util::BitPack32{0}}) { + ALWAYS_INLINE PointerDescriptor(const void *buffer, size_t size, s32 index) : data{util::BitPack32{0}, util::BitPack32{0}} { const u64 address = reinterpret_cast(buffer); this->data[0].Set(index); @@ -296,7 +296,7 @@ namespace ams::svc::ipc { this->data[1] = { static_cast(address) }; } - ALWAYS_INLINE PointerDescriptor(const MessageBuffer &buf, s32 index) : data({util::BitPack32{0}, util::BitPack32{0}}) { + ALWAYS_INLINE PointerDescriptor(const MessageBuffer &buf, s32 index) : data{util::BitPack32{0}, util::BitPack32{0}} { buf.Get(index, this->data, util::size(this->data)); } @@ -338,9 +338,9 @@ namespace ams::svc::ipc { private: util::BitPack32 data[2]; public: - constexpr ALWAYS_INLINE ReceiveListEntry() : data({util::BitPack32{0}, util::BitPack32{0}}) { /* ... */ } + constexpr ALWAYS_INLINE ReceiveListEntry() : data{util::BitPack32{0}, util::BitPack32{0}} { /* ... */ } - ALWAYS_INLINE ReceiveListEntry(const void *buffer, size_t size) : data({util::BitPack32{0}, util::BitPack32{0}}) { + ALWAYS_INLINE ReceiveListEntry(const void *buffer, size_t size) : data{util::BitPack32{0}, util::BitPack32{0}} { const u64 address = reinterpret_cast(buffer); this->data[0] = { static_cast(address) }; @@ -349,7 +349,7 @@ namespace ams::svc::ipc { this->data[1].Set(size); } - ALWAYS_INLINE ReceiveListEntry(u32 a, u32 b) : data({util::BitPack32{a}, util::BitPack32{b}}) { /* ... */ } + ALWAYS_INLINE ReceiveListEntry(u32 a, u32 b) : data{util::BitPack32{a}, util::BitPack32{b}} { /* ... */ } constexpr ALWAYS_INLINE uintptr_t GetAddress() { const u64 address = (static_cast(this->data[1].Get()) << AddressLow::Count) | this->data[0].Get(); diff --git a/libvapours/include/vapours/util.hpp b/libvapours/include/vapours/util.hpp index 3048f515..867668f8 100644 --- a/libvapours/include/vapours/util.hpp +++ b/libvapours/include/vapours/util.hpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include diff --git a/libvapours/include/vapours/util/util_bitpack.hpp b/libvapours/include/vapours/util/util_bitpack.hpp index fac3c681..c89058d6 100644 --- a/libvapours/include/vapours/util/util_bitpack.hpp +++ b/libvapours/include/vapours/util/util_bitpack.hpp @@ -50,7 +50,7 @@ namespace ams::util { static constexpr size_t Next = Index + Count; using BitPackType = BitPack; - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); static_assert(Mask != 0); static_assert(std::is_integral::value || std::is_enum::value); @@ -84,10 +84,10 @@ namespace ams::util { using BitPack32 = impl::BitPack; using BitPack64 = impl::BitPack; - static_assert(std::is_pod::value); - static_assert(std::is_pod::value); - static_assert(std::is_pod::value); - static_assert(std::is_pod::value); + static_assert(util::is_pod::value); + static_assert(util::is_pod::value); + static_assert(util::is_pod::value); + static_assert(util::is_pod::value); static_assert(std::is_trivially_destructible::value); static_assert(std::is_trivially_destructible::value); static_assert(std::is_trivially_destructible::value); diff --git a/libvapours/include/vapours/util/util_bitutil.hpp b/libvapours/include/vapours/util/util_bitutil.hpp index de8e7898..cf974f62 100644 --- a/libvapours/include/vapours/util/util_bitutil.hpp +++ b/libvapours/include/vapours/util/util_bitutil.hpp @@ -30,11 +30,9 @@ namespace ams::util { } - template + template requires std::integral class BitsOf { private: - static_assert(std::is_integral::value); - static constexpr ALWAYS_INLINE int GetLsbPos(T v) { return __builtin_ctzll(static_cast(v)); } @@ -78,69 +76,68 @@ namespace ams::util { } }; - template + template requires std::integral constexpr ALWAYS_INLINE T CombineBits(Args... args) { return (... | (T(1u) << args)); } - template + template requires std::integral constexpr ALWAYS_INLINE T ResetLeastSignificantOneBit(T x) { return x & (x - 1); } - template + template requires std::integral constexpr ALWAYS_INLINE T SetLeastSignificantZeroBit(T x) { return x | (x + 1); } - template + template requires std::integral constexpr ALWAYS_INLINE T LeastSignificantOneBit(T x) { return x & ~(x - 1); } - template + template requires std::integral constexpr ALWAYS_INLINE T LeastSignificantZeroBit(T x) { return ~x & (x + 1); } - template + template requires std::integral constexpr ALWAYS_INLINE T ResetTrailingOnes(T x) { return x & (x + 1); } - template + template requires std::integral constexpr ALWAYS_INLINE T SetTrailingZeros(T x) { return x | (x - 1); } - template + template requires std::integral constexpr ALWAYS_INLINE T MaskTrailingZeros(T x) { return (~x) & (x - 1); } - template + template requires std::integral constexpr ALWAYS_INLINE T MaskTrailingOnes(T x) { return ~((~x) | (x + 1)); } - template + template requires std::integral constexpr ALWAYS_INLINE T MaskTrailingZerosAndLeastSignificantOneBit(T x) { return x ^ (x - 1); } - template + template requires std::integral constexpr ALWAYS_INLINE T MaskTrailingOnesAndLeastSignificantZeroBit(T x) { return x ^ (x + 1); } - template + template requires std::integral constexpr ALWAYS_INLINE int PopCount(T x) { /* TODO: C++20 std::bit_cast */ using U = typename std::make_unsigned::type; U u = static_cast(x); - /* TODO: C++20 std::is_constant_evaluated */ - if (false) { + if (std::is_constant_evaluated()) { /* https://en.wikipedia.org/wiki/Hamming_weight */ constexpr U m1 = U(-1) / 0x03; constexpr U m2 = U(-1) / 0x05; @@ -168,10 +165,9 @@ namespace ams::util { } } - template + template requires std::integral constexpr ALWAYS_INLINE int CountLeadingZeros(T x) { - /* TODO: C++20 std::is_constant_evaluated */ - if (false) { + if (std::is_constant_evaluated()) { for (size_t i = 0; i < impl::Log2; ++i) { const size_t shift = (0x1 << i); x |= x >> shift; @@ -195,18 +191,18 @@ namespace ams::util { } } - template + template requires std::integral constexpr ALWAYS_INLINE bool IsPowerOfTwo(T x) { return x > 0 && ResetLeastSignificantOneBit(x) == 0; } - template + template requires std::integral constexpr ALWAYS_INLINE T CeilingPowerOfTwo(T x) { AMS_ASSERT(x > 0); return T(1) << (BITSIZEOF(T) - CountLeadingZeros(T(x - 1))); } - template + template requires std::integral constexpr ALWAYS_INLINE T FloorPowerOfTwo(T x) { AMS_ASSERT(x > 0); return T(1) << (BITSIZEOF(T) - CountLeadingZeros(x) - 1); diff --git a/libvapours/include/vapours/util/util_endian.hpp b/libvapours/include/vapours/util/util_endian.hpp index fcf294ba..19844f20 100644 --- a/libvapours/include/vapours/util/util_endian.hpp +++ b/libvapours/include/vapours/util/util_endian.hpp @@ -20,27 +20,17 @@ namespace ams::util { - /* TODO: C++20 std::endian */ - constexpr bool IsLittleEndian() { - #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - return true; - #else - return false; - #endif + return std::endian::native == std::endian::little; } constexpr bool IsBigEndian() { - #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - return true; - #else - return false; - #endif + return std::endian::native == std::endian::big; } static_assert(IsLittleEndian() ^ IsBigEndian()); - template /* requires unsigned_integral */ + template requires std::unsigned_integral constexpr ALWAYS_INLINE U SwapBytes(const U u) { static_assert(BITSIZEOF(u8) == 8); constexpr U ByteMask = 0xFFu; @@ -85,14 +75,14 @@ namespace ams::util { ((u & (ByteMask << 0)) << 40); } - template /* requires integral */ + template requires std::integral constexpr ALWAYS_INLINE void SwapBytes(T *ptr) { using U = typename std::make_unsigned::type; *ptr = static_cast(SwapBytes(static_cast(*ptr))); } - template /* requires integral */ + template requires std::integral constexpr ALWAYS_INLINE T ConvertToBigEndian(const T val) { using U = typename std::make_unsigned::type; @@ -104,7 +94,7 @@ namespace ams::util { } } - template /* requires integral */ + template requires std::integral constexpr ALWAYS_INLINE T ConvertToLittleEndian(const T val) { using U = typename std::make_unsigned::type; @@ -116,7 +106,7 @@ namespace ams::util { } } - template /* requires integral */ + template requires std::integral constexpr ALWAYS_INLINE T ConvertToBigEndian48(const T val) { using U = typename std::make_unsigned::type; static_assert(sizeof(T) == sizeof(u64)); @@ -130,7 +120,7 @@ namespace ams::util { } } - template /* requires integral */ + template requires std::integral constexpr ALWAYS_INLINE T ConvertToLittleEndian48(const T val) { using U = typename std::make_unsigned::type; static_assert(sizeof(T) == sizeof(u64)); @@ -144,12 +134,12 @@ namespace ams::util { } } - template /* requires integral */ + template requires std::integral constexpr ALWAYS_INLINE T LoadBigEndian(T *ptr) { return ConvertToBigEndian(*ptr); } - template /* requires integral */ + template requires std::integral constexpr ALWAYS_INLINE T LoadLittleEndian(T *ptr) { return ConvertToLittleEndian(*ptr); } diff --git a/libvapours/include/vapours/util/util_fourcc.hpp b/libvapours/include/vapours/util/util_fourcc.hpp index 5b805e03..08e8b3c0 100644 --- a/libvapours/include/vapours/util/util_fourcc.hpp +++ b/libvapours/include/vapours/util/util_fourcc.hpp @@ -17,16 +17,14 @@ #pragma once #include #include +#include namespace ams::util { template struct FourCC { - /* TODO: C++20 std::endian */ - static constexpr u32 Code = (static_cast(A) << 0x00) | - (static_cast(B) << 0x08) | - (static_cast(C) << 0x10) | - (static_cast(D) << 0x18); + static constexpr u32 Code = IsLittleEndian() ? ((static_cast(A) << 0x00) | (static_cast(B) << 0x08) | (static_cast(C) << 0x10) | (static_cast(D) << 0x18)) + : ((static_cast(A) << 0x18) | (static_cast(B) << 0x10) | (static_cast(C) << 0x08) | (static_cast(D) << 0x00)); static constexpr const char String[] = {A, B, C, D}; @@ -36,11 +34,8 @@ namespace ams::util { template struct ReverseFourCC { - /* TODO: C++20 std::endian */ - static constexpr u32 Code = (static_cast(A) << 0x18) | - (static_cast(B) << 0x10) | - (static_cast(C) << 0x08) | - (static_cast(D) << 0x00); + static constexpr u32 Code = IsLittleEndian() ? ((static_cast(A) << 0x18) | (static_cast(B) << 0x10) | (static_cast(C) << 0x08) | (static_cast(D) << 0x00)) + : ((static_cast(A) << 0x00) | (static_cast(B) << 0x08) | (static_cast(C) << 0x10) | (static_cast(D) << 0x18)); static constexpr const char String[] = {D, C, B, A}; diff --git a/libvapours/include/vapours/util/util_type_traits.hpp b/libvapours/include/vapours/util/util_type_traits.hpp new file mode 100644 index 00000000..146b41a4 --- /dev/null +++ b/libvapours/include/vapours/util/util_type_traits.hpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include +#include + +namespace ams::util { + + template + using is_pod = std::bool_constant::value && std::is_trivial::value>; + +}