mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 12:21:18 +00:00
ams: remove TYPED_STORAGE() macro in favor of template
This commit is contained in:
parent
8d9174b227
commit
aff0da9427
31 changed files with 55 additions and 57 deletions
|
@ -23,7 +23,7 @@ namespace ams::kern {
|
||||||
class KCodeMemory final : public KAutoObjectWithSlabHeapAndContainer<KCodeMemory, KAutoObjectWithList> {
|
class KCodeMemory final : public KAutoObjectWithSlabHeapAndContainer<KCodeMemory, KAutoObjectWithList> {
|
||||||
MESOSPHERE_AUTOOBJECT_TRAITS(KCodeMemory, KAutoObject);
|
MESOSPHERE_AUTOOBJECT_TRAITS(KCodeMemory, KAutoObject);
|
||||||
private:
|
private:
|
||||||
TYPED_STORAGE(KPageGroup) m_page_group;
|
util::TypedStorage<KPageGroup> m_page_group;
|
||||||
KProcess *m_owner;
|
KProcess *m_owner;
|
||||||
KProcessAddress m_address;
|
KProcessAddress m_address;
|
||||||
KLightLock m_lock;
|
KLightLock m_lock;
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace ams::kern {
|
||||||
class KTransferMemory final : public KAutoObjectWithSlabHeapAndContainer<KTransferMemory, KAutoObjectWithList> {
|
class KTransferMemory final : public KAutoObjectWithSlabHeapAndContainer<KTransferMemory, KAutoObjectWithList> {
|
||||||
MESOSPHERE_AUTOOBJECT_TRAITS(KTransferMemory, KAutoObject);
|
MESOSPHERE_AUTOOBJECT_TRAITS(KTransferMemory, KAutoObject);
|
||||||
private:
|
private:
|
||||||
TYPED_STORAGE(KPageGroup) m_page_group;
|
util::TypedStorage<KPageGroup> m_page_group;
|
||||||
KProcess *m_owner;
|
KProcess *m_owner;
|
||||||
KProcessAddress m_address;
|
KProcessAddress m_address;
|
||||||
KLightLock m_lock;
|
KLightLock m_lock;
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace ams::ddsf {
|
||||||
NON_MOVEABLE(DeviceCodeEntryHolder);
|
NON_MOVEABLE(DeviceCodeEntryHolder);
|
||||||
private:
|
private:
|
||||||
util::IntrusiveListNode list_node;
|
util::IntrusiveListNode list_node;
|
||||||
TYPED_STORAGE(DeviceCodeEntry) entry_storage;
|
util::TypedStorage<DeviceCodeEntry> entry_storage;
|
||||||
bool is_constructed;
|
bool is_constructed;
|
||||||
public:
|
public:
|
||||||
using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&DeviceCodeEntryHolder::list_node>;
|
using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&DeviceCodeEntryHolder::list_node>;
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace ams::ncm {
|
||||||
struct InstallProgress {
|
struct InstallProgress {
|
||||||
InstallProgressState state;
|
InstallProgressState state;
|
||||||
u8 pad[3];
|
u8 pad[3];
|
||||||
TYPED_STORAGE(Result) last_result;
|
util::TypedStorage<Result> last_result;
|
||||||
s64 installed_size;
|
s64 installed_size;
|
||||||
s64 total_size;
|
s64 total_size;
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,6 @@ namespace ams::os::impl {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using InternalConditionVariableStorage = TYPED_STORAGE(InternalConditionVariable);
|
using InternalConditionVariableStorage = util::TypedStorage<InternalConditionVariable>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,6 @@ namespace ams::os::impl {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using InternalCriticalSectionStorage = TYPED_STORAGE(InternalCriticalSection);
|
using InternalCriticalSectionStorage = util::TypedStorage<InternalCriticalSection>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace ams::os {
|
||||||
State_Terminated = 4,
|
State_Terminated = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
TYPED_STORAGE(util::IntrusiveListNode) all_threads_node;
|
util::TypedStorage<util::IntrusiveListNode> all_threads_node;
|
||||||
util::TypedStorage<impl::WaitableObjectList, sizeof(util::IntrusiveListNode), alignof(util::IntrusiveListNode)> waitlist;
|
util::TypedStorage<impl::WaitableObjectList, sizeof(util::IntrusiveListNode), alignof(util::IntrusiveListNode)> waitlist;
|
||||||
uintptr_t reserved[4];
|
uintptr_t reserved[4];
|
||||||
u8 state;
|
u8 state;
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace ams::os {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TimerEventType {
|
struct TimerEventType {
|
||||||
using TimeSpanStorage = TYPED_STORAGE(TimeSpan);
|
using TimeSpanStorage = util::TypedStorage<TimeSpan>;
|
||||||
|
|
||||||
enum State {
|
enum State {
|
||||||
State_NotInitialized = 0,
|
State_NotInitialized = 0,
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace ams::powctl {
|
||||||
|
|
||||||
struct Session {
|
struct Session {
|
||||||
bool has_session;
|
bool has_session;
|
||||||
TYPED_STORAGE(impl::SessionImpl) impl_storage;
|
util::TypedStorage<impl::SessionImpl> impl_storage;
|
||||||
|
|
||||||
Session() : has_session(false) { /* ... */ }
|
Session() : has_session(false) { /* ... */ }
|
||||||
};
|
};
|
||||||
|
|
|
@ -77,8 +77,8 @@ namespace ams::sf::cmif {
|
||||||
virtual ServiceObjectHolder GetObject(DomainObjectId id) override final;
|
virtual ServiceObjectHolder GetObject(DomainObjectId id) override final;
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
using DomainEntryStorage = TYPED_STORAGE(Entry);
|
using DomainEntryStorage = util::TypedStorage<Entry>;
|
||||||
using DomainStorage = TYPED_STORAGE(Domain);
|
using DomainStorage = util::TypedStorage<Domain>;
|
||||||
private:
|
private:
|
||||||
class EntryManager {
|
class EntryManager {
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -260,9 +260,9 @@ namespace ams::sf::hipc {
|
||||||
private:
|
private:
|
||||||
/* Resource storage. */
|
/* Resource storage. */
|
||||||
os::Mutex resource_mutex;
|
os::Mutex resource_mutex;
|
||||||
TYPED_STORAGE(Server) server_storages[MaxServers];
|
util::TypedStorage<Server> server_storages[MaxServers];
|
||||||
bool server_allocated[MaxServers];
|
bool server_allocated[MaxServers];
|
||||||
TYPED_STORAGE(ServerSession) session_storages[MaxSessions];
|
util::TypedStorage<ServerSession> session_storages[MaxSessions];
|
||||||
bool session_allocated[MaxSessions];
|
bool session_allocated[MaxSessions];
|
||||||
u8 pointer_buffer_storage[0x10 + (MaxSessions * ManagerOptions::PointerBufferSize)];
|
u8 pointer_buffer_storage[0x10 + (MaxSessions * ManagerOptions::PointerBufferSize)];
|
||||||
u8 saved_message_storage[0x10 + (MaxSessions * hipc::TlsMessageBufferSize)];
|
u8 saved_message_storage[0x10 + (MaxSessions * hipc::TlsMessageBufferSize)];
|
||||||
|
|
|
@ -684,7 +684,7 @@ namespace ams::sf::impl {
|
||||||
private:
|
private:
|
||||||
std::array<cmif::ServiceObjectHolder, NumInObjects> in_object_holders;
|
std::array<cmif::ServiceObjectHolder, NumInObjects> in_object_holders;
|
||||||
std::array<cmif::ServiceObjectHolder, NumOutObjects> out_object_holders;
|
std::array<cmif::ServiceObjectHolder, NumOutObjects> out_object_holders;
|
||||||
std::array<TYPED_STORAGE(SharedPointer<sf::IServiceObject>), NumOutObjects> out_shared_pointers;
|
std::array<util::TypedStorage<SharedPointer<sf::IServiceObject>>, NumOutObjects> out_shared_pointers;
|
||||||
std::array<cmif::DomainObjectId, NumOutObjects> out_object_ids;
|
std::array<cmif::DomainObjectId, NumOutObjects> out_object_ids;
|
||||||
public:
|
public:
|
||||||
constexpr InOutObjectHolder() : in_object_holders(), out_object_holders() {
|
constexpr InOutObjectHolder() : in_object_holders(), out_object_holders() {
|
||||||
|
|
|
@ -23,8 +23,8 @@ namespace ams::fs {
|
||||||
constinit os::SdkMutex g_mount_stratosphere_romfs_lock;
|
constinit os::SdkMutex g_mount_stratosphere_romfs_lock;
|
||||||
constinit bool g_mounted_stratosphere_romfs = false;
|
constinit bool g_mounted_stratosphere_romfs = false;
|
||||||
|
|
||||||
constinit TYPED_STORAGE(FileHandleStorage) g_stratosphere_romfs_storage = {};
|
constinit util::TypedStorage<FileHandleStorage> g_stratosphere_romfs_storage = {};
|
||||||
constinit TYPED_STORAGE(RomFsFileSystem) g_stratosphere_romfs_fs = {};
|
constinit util::TypedStorage<RomFsFileSystem> g_stratosphere_romfs_fs = {};
|
||||||
|
|
||||||
Result EnsureStratosphereRomfsMounted() {
|
Result EnsureStratosphereRomfsMounted() {
|
||||||
std::scoped_lock lk(g_mount_stratosphere_romfs_lock);
|
std::scoped_lock lk(g_mount_stratosphere_romfs_lock);
|
||||||
|
|
|
@ -68,19 +68,19 @@ namespace ams::fssystem {
|
||||||
alignas(os::MemoryPageSize) u8 g_device_buffer[DeviceBufferSize];
|
alignas(os::MemoryPageSize) u8 g_device_buffer[DeviceBufferSize];
|
||||||
|
|
||||||
alignas(os::MemoryPageSize) u8 g_buffer_pool[BufferPoolSize];
|
alignas(os::MemoryPageSize) u8 g_buffer_pool[BufferPoolSize];
|
||||||
TYPED_STORAGE(mem::StandardAllocator) g_buffer_allocator;
|
util::TypedStorage<mem::StandardAllocator> g_buffer_allocator;
|
||||||
TYPED_STORAGE(fssrv::MemoryResourceFromStandardAllocator) g_allocator;
|
util::TypedStorage<fssrv::MemoryResourceFromStandardAllocator> g_allocator;
|
||||||
|
|
||||||
/* TODO: Nintendo uses os::SetMemoryHeapSize (svc::SetHeapSize) and os::AllocateMemoryBlock for the BufferManager heap. */
|
/* TODO: Nintendo uses os::SetMemoryHeapSize (svc::SetHeapSize) and os::AllocateMemoryBlock for the BufferManager heap. */
|
||||||
/* It's unclear how we should handle this in ams.mitm (especially hoping to reuse some logic for fs reimpl). */
|
/* It's unclear how we should handle this in ams.mitm (especially hoping to reuse some logic for fs reimpl). */
|
||||||
/* Should we be doing the same(?) */
|
/* Should we be doing the same(?) */
|
||||||
TYPED_STORAGE(fssystem::FileSystemBufferManager) g_buffer_manager;
|
util::TypedStorage<fssystem::FileSystemBufferManager> g_buffer_manager;
|
||||||
alignas(os::MemoryPageSize) u8 g_buffer_manager_heap[BufferManagerHeapSize];
|
alignas(os::MemoryPageSize) u8 g_buffer_manager_heap[BufferManagerHeapSize];
|
||||||
|
|
||||||
/* FileSystem creators. */
|
/* FileSystem creators. */
|
||||||
TYPED_STORAGE(fssrv::fscreator::RomFileSystemCreator) g_rom_fs_creator;
|
util::TypedStorage<fssrv::fscreator::RomFileSystemCreator> g_rom_fs_creator;
|
||||||
TYPED_STORAGE(fssrv::fscreator::PartitionFileSystemCreator) g_partition_fs_creator;
|
util::TypedStorage<fssrv::fscreator::PartitionFileSystemCreator> g_partition_fs_creator;
|
||||||
TYPED_STORAGE(fssrv::fscreator::StorageOnNcaCreator) g_storage_on_nca_creator;
|
util::TypedStorage<fssrv::fscreator::StorageOnNcaCreator> g_storage_on_nca_creator;
|
||||||
|
|
||||||
fssrv::fscreator::FileSystemCreatorInterfaces g_fs_creator_interfaces = {};
|
fssrv::fscreator::FileSystemCreatorInterfaces g_fs_creator_interfaces = {};
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace ams::htc::server {
|
||||||
using ServerOptions = sf::hipc::DefaultServerManagerOptions;
|
using ServerOptions = sf::hipc::DefaultServerManagerOptions;
|
||||||
using ServerManager = sf::hipc::ServerManager<NumServers, ServerOptions, MaxSessions>;
|
using ServerManager = sf::hipc::ServerManager<NumServers, ServerOptions, MaxSessions>;
|
||||||
|
|
||||||
constinit TYPED_STORAGE(ServerManager) g_server_manager_storage;
|
constinit util::TypedStorage<ServerManager> g_server_manager_storage;
|
||||||
constinit ServerManager *g_server_manager = nullptr;
|
constinit ServerManager *g_server_manager = nullptr;
|
||||||
|
|
||||||
constinit HtcmiscImpl *g_misc_impl = nullptr;
|
constinit HtcmiscImpl *g_misc_impl = nullptr;
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace ams::htcfs {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constinit TYPED_STORAGE(Client) g_client_storage;
|
constinit util::TypedStorage<Client> g_client_storage;
|
||||||
constinit bool g_initialized;
|
constinit bool g_initialized;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace ams::htclow::mux {
|
||||||
os::Event *m_event;
|
os::Event *m_event;
|
||||||
u8 m_map_buffer[MapRequiredMemorySize];
|
u8 m_map_buffer[MapRequiredMemorySize];
|
||||||
MapType m_map;
|
MapType m_map;
|
||||||
TYPED_STORAGE(ChannelImpl) m_channel_storage[MaxChannelCount];
|
util::TypedStorage<ChannelImpl> m_channel_storage[MaxChannelCount];
|
||||||
bool m_storage_valid[MaxChannelCount];
|
bool m_storage_valid[MaxChannelCount];
|
||||||
public:
|
public:
|
||||||
ChannelImplMap(PacketFactory *pf, ctrl::HtcctrlStateMachine *sm, TaskManager *tm, os::Event *ev);
|
ChannelImplMap(PacketFactory *pf, ctrl::HtcctrlStateMachine *sm, TaskManager *tm, os::Event *ev);
|
||||||
|
|
|
@ -18,6 +18,6 @@
|
||||||
|
|
||||||
namespace ams::os::impl {
|
namespace ams::os::impl {
|
||||||
|
|
||||||
constinit TYPED_STORAGE(OsResourceManager) ResourceManagerHolder::s_resource_manager_storage = {};
|
constinit util::TypedStorage<OsResourceManager> ResourceManagerHolder::s_resource_manager_storage = {};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ namespace ams::os::impl {
|
||||||
|
|
||||||
class ResourceManagerHolder {
|
class ResourceManagerHolder {
|
||||||
private:
|
private:
|
||||||
static TYPED_STORAGE(OsResourceManager) s_resource_manager_storage;
|
static util::TypedStorage<OsResourceManager> s_resource_manager_storage;
|
||||||
private:
|
private:
|
||||||
constexpr ResourceManagerHolder() { /* ... */ }
|
constexpr ResourceManagerHolder() { /* ... */ }
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -27,15 +27,15 @@ namespace ams::os::impl {
|
||||||
|
|
||||||
struct WaitableHolderImpl {
|
struct WaitableHolderImpl {
|
||||||
union {
|
union {
|
||||||
TYPED_STORAGE(WaitableHolderOfHandle) holder_of_handle_storage;
|
util::TypedStorage<WaitableHolderOfHandle> holder_of_handle_storage;
|
||||||
TYPED_STORAGE(WaitableHolderOfEvent) holder_of_event_storage;
|
util::TypedStorage<WaitableHolderOfEvent> holder_of_event_storage;
|
||||||
TYPED_STORAGE(WaitableHolderOfInterProcessEvent) holder_of_inter_process_event_storage;
|
util::TypedStorage<WaitableHolderOfInterProcessEvent> holder_of_inter_process_event_storage;
|
||||||
TYPED_STORAGE(WaitableHolderOfInterruptEvent) holder_of_interrupt_event_storage;
|
util::TypedStorage<WaitableHolderOfInterruptEvent> holder_of_interrupt_event_storage;
|
||||||
TYPED_STORAGE(WaitableHolderOfTimerEvent) holder_of_timer_event_storage;
|
util::TypedStorage<WaitableHolderOfTimerEvent> holder_of_timer_event_storage;
|
||||||
TYPED_STORAGE(WaitableHolderOfThread) holder_of_thread_storage;
|
util::TypedStorage<WaitableHolderOfThread> holder_of_thread_storage;
|
||||||
TYPED_STORAGE(WaitableHolderOfSemaphore) holder_of_semaphore_storage;
|
util::TypedStorage<WaitableHolderOfSemaphore> holder_of_semaphore_storage;
|
||||||
TYPED_STORAGE(WaitableHolderOfMessageQueueForNotFull) holder_of_mq_for_not_full_storage;
|
util::TypedStorage<WaitableHolderOfMessageQueueForNotFull> holder_of_mq_for_not_full_storage;
|
||||||
TYPED_STORAGE(WaitableHolderOfMessageQueueForNotEmpty) holder_of_mq_for_not_empty_storage;
|
util::TypedStorage<WaitableHolderOfMessageQueueForNotEmpty> holder_of_mq_for_not_empty_storage;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -41,10 +41,10 @@ namespace ams::pgl::srv {
|
||||||
os::MessageQueue message_queue;
|
os::MessageQueue message_queue;
|
||||||
uintptr_t queue_buffer[QueueCapacity];
|
uintptr_t queue_buffer[QueueCapacity];
|
||||||
os::SystemEvent event;
|
os::SystemEvent event;
|
||||||
TYPED_STORAGE(lmem::HeapCommonHead) heap_head;
|
util::TypedStorage<lmem::HeapCommonHead> heap_head;
|
||||||
lmem::HeapHandle heap_handle;
|
lmem::HeapHandle heap_handle;
|
||||||
pm::ProcessEventInfo event_info_data[QueueCapacity];
|
pm::ProcessEventInfo event_info_data[QueueCapacity];
|
||||||
TYPED_STORAGE(ShellEventObserverHolder) holder;
|
util::TypedStorage<ShellEventObserverHolder> holder;
|
||||||
public:
|
public:
|
||||||
ShellEventObserver();
|
ShellEventObserver();
|
||||||
~ShellEventObserver();
|
~ShellEventObserver();
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace ams::sf::hipc::impl {
|
||||||
constinit os::ThreadType g_query_server_process_thread;
|
constinit os::ThreadType g_query_server_process_thread;
|
||||||
|
|
||||||
constexpr size_t MaxServers = 0;
|
constexpr size_t MaxServers = 0;
|
||||||
TYPED_STORAGE(sf::hipc::ServerManager<MaxServers>) g_query_server_storage;
|
util::TypedStorage<sf::hipc::ServerManager<MaxServers>> g_query_server_storage;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace ams::util {
|
||||||
class BoundedMap {
|
class BoundedMap {
|
||||||
private:
|
private:
|
||||||
std::array<std::optional<Key>, N> keys;
|
std::array<std::optional<Key>, N> keys;
|
||||||
std::array<TYPED_STORAGE(Value), N> values;
|
std::array<TypedStorage<Value>, N> values;
|
||||||
private:
|
private:
|
||||||
ALWAYS_INLINE void FreeEntry(size_t i) {
|
ALWAYS_INLINE void FreeEntry(size_t i) {
|
||||||
this->keys[i].reset();
|
this->keys[i].reset();
|
||||||
|
|
|
@ -569,7 +569,7 @@ namespace ams::util {
|
||||||
return util::GetParentReference<Member, Derived>(&node);
|
return util::GetParentReference<Member, Derived>(&node);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
static constexpr TYPED_STORAGE(Derived) DerivedStorage = {};
|
static constexpr TypedStorage<Derived> DerivedStorage = {};
|
||||||
static_assert(std::addressof(GetParent(GetNode(GetReference(DerivedStorage)))) == GetPointer(DerivedStorage));
|
static_assert(std::addressof(GetParent(GetNode(GetReference(DerivedStorage)))) == GetPointer(DerivedStorage));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -582,7 +582,7 @@ namespace ams::util {
|
||||||
using ListType = IntrusiveList<Derived, IntrusiveListMemberTraitsDeferredAssert>;
|
using ListType = IntrusiveList<Derived, IntrusiveListMemberTraitsDeferredAssert>;
|
||||||
|
|
||||||
static constexpr bool IsValid() {
|
static constexpr bool IsValid() {
|
||||||
TYPED_STORAGE(Derived) DerivedStorage = {};
|
TypedStorage<Derived> DerivedStorage = {};
|
||||||
return std::addressof(GetParent(GetNode(GetReference(DerivedStorage)))) == GetPointer(DerivedStorage);
|
return std::addressof(GetParent(GetNode(GetReference(DerivedStorage)))) == GetPointer(DerivedStorage);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -498,7 +498,7 @@ namespace ams::util {
|
||||||
return util::GetParentPointer<Member, Derived>(node);
|
return util::GetParentPointer<Member, Derived>(node);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
static constexpr TYPED_STORAGE(Derived) DerivedStorage = {};
|
static constexpr TypedStorage<Derived> DerivedStorage = {};
|
||||||
static_assert(GetParent(GetNode(GetPointer(DerivedStorage))) == GetPointer(DerivedStorage));
|
static_assert(GetParent(GetNode(GetPointer(DerivedStorage))) == GetPointer(DerivedStorage));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -513,7 +513,7 @@ namespace ams::util {
|
||||||
using TreeTypeImpl = impl::IntrusiveRedBlackTreeImpl;
|
using TreeTypeImpl = impl::IntrusiveRedBlackTreeImpl;
|
||||||
|
|
||||||
static constexpr bool IsValid() {
|
static constexpr bool IsValid() {
|
||||||
TYPED_STORAGE(Derived) DerivedStorage = {};
|
TypedStorage<Derived> DerivedStorage = {};
|
||||||
return GetParent(GetNode(GetPointer(DerivedStorage))) == GetPointer(DerivedStorage);
|
return GetParent(GetNode(GetPointer(DerivedStorage))) == GetPointer(DerivedStorage);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -63,7 +63,7 @@ namespace ams::util {
|
||||||
union Union {
|
union Union {
|
||||||
char c;
|
char c;
|
||||||
UnionHolder first_union;
|
UnionHolder first_union;
|
||||||
TYPED_STORAGE(ParentType) parent;
|
TypedStorage<ParentType> parent;
|
||||||
|
|
||||||
/* This coerces the active member to be c. */
|
/* This coerces the active member to be c. */
|
||||||
constexpr Union() : c() { /* ... */ }
|
constexpr Union() : c() { /* ... */ }
|
||||||
|
@ -110,7 +110,7 @@ namespace ams::util {
|
||||||
template<typename ParentType, typename MemberType>
|
template<typename ParentType, typename MemberType>
|
||||||
struct OffsetOfCalculator {
|
struct OffsetOfCalculator {
|
||||||
static constexpr std::ptrdiff_t OffsetOf(MemberType ParentType::*member) {
|
static constexpr std::ptrdiff_t OffsetOf(MemberType ParentType::*member) {
|
||||||
constexpr TYPED_STORAGE(ParentType) Holder = {};
|
constexpr TypedStorage<ParentType> Holder = {};
|
||||||
const auto *parent = GetPointer(Holder);
|
const auto *parent = GetPointer(Holder);
|
||||||
const auto *target = std::addressof(parent->*member);
|
const auto *target = std::addressof(parent->*member);
|
||||||
return static_cast<const uint8_t *>(static_cast<const void *>(target)) - static_cast<const uint8_t *>(static_cast<const void *>(parent));
|
return static_cast<const uint8_t *>(static_cast<const void *>(target)) - static_cast<const uint8_t *>(static_cast<const void *>(parent));
|
||||||
|
|
|
@ -20,30 +20,28 @@
|
||||||
|
|
||||||
namespace ams::util {
|
namespace ams::util {
|
||||||
|
|
||||||
template<typename T, size_t Size, size_t Align>
|
template<typename T, size_t Size = sizeof(T), size_t Align = alignof(T)>
|
||||||
struct TypedStorage {
|
struct TypedStorage {
|
||||||
typename std::aligned_storage<Size, Align>::type _storage;
|
typename std::aligned_storage<Size, Align>::type _storage;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define TYPED_STORAGE(...) ::ams::util::TypedStorage<__VA_ARGS__, sizeof(__VA_ARGS__), alignof(__VA_ARGS__)>
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static constexpr ALWAYS_INLINE T *GetPointer(TYPED_STORAGE(T) &ts) {
|
static constexpr ALWAYS_INLINE T *GetPointer(TypedStorage<T> &ts) {
|
||||||
return static_cast<T *>(static_cast<void *>(std::addressof(ts._storage)));
|
return static_cast<T *>(static_cast<void *>(std::addressof(ts._storage)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static constexpr ALWAYS_INLINE const T *GetPointer(const TYPED_STORAGE(T) &ts) {
|
static constexpr ALWAYS_INLINE const T *GetPointer(const TypedStorage<T> &ts) {
|
||||||
return static_cast<const T *>(static_cast<const void *>(std::addressof(ts._storage)));
|
return static_cast<const T *>(static_cast<const void *>(std::addressof(ts._storage)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static constexpr ALWAYS_INLINE T &GetReference(TYPED_STORAGE(T) &ts) {
|
static constexpr ALWAYS_INLINE T &GetReference(TypedStorage<T> &ts) {
|
||||||
return *GetPointer(ts);
|
return *GetPointer(ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static constexpr ALWAYS_INLINE const T &GetReference(const TYPED_STORAGE(T) &ts) {
|
static constexpr ALWAYS_INLINE const T &GetReference(const TypedStorage<T> &ts) {
|
||||||
return *GetPointer(ts);
|
return *GetPointer(ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -237,7 +237,7 @@ namespace ams::sdmmc::impl {
|
||||||
#if defined(AMS_SDMMC_USE_PCV_CLOCK_RESET_CONTROL)
|
#if defined(AMS_SDMMC_USE_PCV_CLOCK_RESET_CONTROL)
|
||||||
bool is_pcv_control;
|
bool is_pcv_control;
|
||||||
#endif
|
#endif
|
||||||
TYPED_STORAGE(PowerController) power_controller_storage;
|
util::TypedStorage<PowerController> power_controller_storage;
|
||||||
PowerController *power_controller;
|
PowerController *power_controller;
|
||||||
private:
|
private:
|
||||||
Result PowerOnForRegisterControl(BusPower bus_power);
|
Result PowerOnForRegisterControl(BusPower bus_power);
|
||||||
|
|
|
@ -1148,7 +1148,7 @@ namespace ams::dmnt::cheat::impl {
|
||||||
|
|
||||||
|
|
||||||
/* Manager global. */
|
/* Manager global. */
|
||||||
TYPED_STORAGE(CheatProcessManager) g_cheat_process_manager;
|
util::TypedStorage<CheatProcessManager> g_cheat_process_manager;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ namespace ams::dmnt::cheat::impl {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Manager global. */
|
/* Manager global. */
|
||||||
TYPED_STORAGE(DebugEventsManager) g_events_manager;
|
util::TypedStorage<DebugEventsManager> g_events_manager;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ namespace ams::pm::impl {
|
||||||
NON_MOVEABLE(ProcessInfoAllocator);
|
NON_MOVEABLE(ProcessInfoAllocator);
|
||||||
static_assert(MaxProcessInfos >= 0x40, "MaxProcessInfos is too small.");
|
static_assert(MaxProcessInfos >= 0x40, "MaxProcessInfos is too small.");
|
||||||
private:
|
private:
|
||||||
TYPED_STORAGE(ProcessInfo) process_info_storages[MaxProcessInfos];
|
util::TypedStorage<ProcessInfo> process_info_storages[MaxProcessInfos];
|
||||||
bool process_info_allocated[MaxProcessInfos];
|
bool process_info_allocated[MaxProcessInfos];
|
||||||
os::Mutex lock;
|
os::Mutex lock;
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue