ams: remove TYPED_STORAGE() macro in favor of template

This commit is contained in:
Michael Scire 2021-03-21 18:47:30 -07:00
parent 8d9174b227
commit aff0da9427
31 changed files with 55 additions and 57 deletions

View file

@ -23,7 +23,7 @@ namespace ams::kern {
class KCodeMemory final : public KAutoObjectWithSlabHeapAndContainer<KCodeMemory, KAutoObjectWithList> {
MESOSPHERE_AUTOOBJECT_TRAITS(KCodeMemory, KAutoObject);
private:
TYPED_STORAGE(KPageGroup) m_page_group;
util::TypedStorage<KPageGroup> m_page_group;
KProcess *m_owner;
KProcessAddress m_address;
KLightLock m_lock;

View file

@ -23,7 +23,7 @@ namespace ams::kern {
class KTransferMemory final : public KAutoObjectWithSlabHeapAndContainer<KTransferMemory, KAutoObjectWithList> {
MESOSPHERE_AUTOOBJECT_TRAITS(KTransferMemory, KAutoObject);
private:
TYPED_STORAGE(KPageGroup) m_page_group;
util::TypedStorage<KPageGroup> m_page_group;
KProcess *m_owner;
KProcessAddress m_address;
KLightLock m_lock;

View file

@ -49,7 +49,7 @@ namespace ams::ddsf {
NON_MOVEABLE(DeviceCodeEntryHolder);
private:
util::IntrusiveListNode list_node;
TYPED_STORAGE(DeviceCodeEntry) entry_storage;
util::TypedStorage<DeviceCodeEntry> entry_storage;
bool is_constructed;
public:
using ListTraits = util::IntrusiveListMemberTraitsDeferredAssert<&DeviceCodeEntryHolder::list_node>;

View file

@ -29,7 +29,7 @@ namespace ams::ncm {
struct InstallProgress {
InstallProgressState state;
u8 pad[3];
TYPED_STORAGE(Result) last_result;
util::TypedStorage<Result> last_result;
s64 installed_size;
s64 total_size;

View file

@ -53,6 +53,6 @@ namespace ams::os::impl {
}
};
using InternalConditionVariableStorage = TYPED_STORAGE(InternalConditionVariable);
using InternalConditionVariableStorage = util::TypedStorage<InternalConditionVariable>;
}

View file

@ -57,6 +57,6 @@ namespace ams::os::impl {
}
};
using InternalCriticalSectionStorage = TYPED_STORAGE(InternalCriticalSection);
using InternalCriticalSectionStorage = util::TypedStorage<InternalCriticalSection>;
}

View file

@ -44,7 +44,7 @@ namespace ams::os {
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;
uintptr_t reserved[4];
u8 state;

View file

@ -29,7 +29,7 @@ namespace ams::os {
}
struct TimerEventType {
using TimeSpanStorage = TYPED_STORAGE(TimeSpan);
using TimeSpanStorage = util::TypedStorage<TimeSpan>;
enum State {
State_NotInitialized = 0,

View file

@ -35,7 +35,7 @@ namespace ams::powctl {
struct Session {
bool has_session;
TYPED_STORAGE(impl::SessionImpl) impl_storage;
util::TypedStorage<impl::SessionImpl> impl_storage;
Session() : has_session(false) { /* ... */ }
};

View file

@ -77,8 +77,8 @@ namespace ams::sf::cmif {
virtual ServiceObjectHolder GetObject(DomainObjectId id) override final;
};
public:
using DomainEntryStorage = TYPED_STORAGE(Entry);
using DomainStorage = TYPED_STORAGE(Domain);
using DomainEntryStorage = util::TypedStorage<Entry>;
using DomainStorage = util::TypedStorage<Domain>;
private:
class EntryManager {
private:

View file

@ -260,9 +260,9 @@ namespace ams::sf::hipc {
private:
/* Resource storage. */
os::Mutex resource_mutex;
TYPED_STORAGE(Server) server_storages[MaxServers];
util::TypedStorage<Server> server_storages[MaxServers];
bool server_allocated[MaxServers];
TYPED_STORAGE(ServerSession) session_storages[MaxSessions];
util::TypedStorage<ServerSession> session_storages[MaxSessions];
bool session_allocated[MaxSessions];
u8 pointer_buffer_storage[0x10 + (MaxSessions * ManagerOptions::PointerBufferSize)];
u8 saved_message_storage[0x10 + (MaxSessions * hipc::TlsMessageBufferSize)];

View file

@ -684,7 +684,7 @@ namespace ams::sf::impl {
private:
std::array<cmif::ServiceObjectHolder, NumInObjects> in_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;
public:
constexpr InOutObjectHolder() : in_object_holders(), out_object_holders() {

View file

@ -23,8 +23,8 @@ namespace ams::fs {
constinit os::SdkMutex g_mount_stratosphere_romfs_lock;
constinit bool g_mounted_stratosphere_romfs = false;
constinit TYPED_STORAGE(FileHandleStorage) g_stratosphere_romfs_storage = {};
constinit TYPED_STORAGE(RomFsFileSystem) g_stratosphere_romfs_fs = {};
constinit util::TypedStorage<FileHandleStorage> g_stratosphere_romfs_storage = {};
constinit util::TypedStorage<RomFsFileSystem> g_stratosphere_romfs_fs = {};
Result EnsureStratosphereRomfsMounted() {
std::scoped_lock lk(g_mount_stratosphere_romfs_lock);

View file

@ -68,19 +68,19 @@ namespace ams::fssystem {
alignas(os::MemoryPageSize) u8 g_device_buffer[DeviceBufferSize];
alignas(os::MemoryPageSize) u8 g_buffer_pool[BufferPoolSize];
TYPED_STORAGE(mem::StandardAllocator) g_buffer_allocator;
TYPED_STORAGE(fssrv::MemoryResourceFromStandardAllocator) g_allocator;
util::TypedStorage<mem::StandardAllocator> g_buffer_allocator;
util::TypedStorage<fssrv::MemoryResourceFromStandardAllocator> g_allocator;
/* 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). */
/* 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];
/* FileSystem creators. */
TYPED_STORAGE(fssrv::fscreator::RomFileSystemCreator) g_rom_fs_creator;
TYPED_STORAGE(fssrv::fscreator::PartitionFileSystemCreator) g_partition_fs_creator;
TYPED_STORAGE(fssrv::fscreator::StorageOnNcaCreator) g_storage_on_nca_creator;
util::TypedStorage<fssrv::fscreator::RomFileSystemCreator> g_rom_fs_creator;
util::TypedStorage<fssrv::fscreator::PartitionFileSystemCreator> g_partition_fs_creator;
util::TypedStorage<fssrv::fscreator::StorageOnNcaCreator> g_storage_on_nca_creator;
fssrv::fscreator::FileSystemCreatorInterfaces g_fs_creator_interfaces = {};

View file

@ -28,7 +28,7 @@ namespace ams::htc::server {
using ServerOptions = sf::hipc::DefaultServerManagerOptions;
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 HtcmiscImpl *g_misc_impl = nullptr;

View file

@ -20,7 +20,7 @@ namespace ams::htcfs {
namespace {
constinit TYPED_STORAGE(Client) g_client_storage;
constinit util::TypedStorage<Client> g_client_storage;
constinit bool g_initialized;
}

View file

@ -35,7 +35,7 @@ namespace ams::htclow::mux {
os::Event *m_event;
u8 m_map_buffer[MapRequiredMemorySize];
MapType m_map;
TYPED_STORAGE(ChannelImpl) m_channel_storage[MaxChannelCount];
util::TypedStorage<ChannelImpl> m_channel_storage[MaxChannelCount];
bool m_storage_valid[MaxChannelCount];
public:
ChannelImplMap(PacketFactory *pf, ctrl::HtcctrlStateMachine *sm, TaskManager *tm, os::Event *ev);

View file

@ -18,6 +18,6 @@
namespace ams::os::impl {
constinit TYPED_STORAGE(OsResourceManager) ResourceManagerHolder::s_resource_manager_storage = {};
constinit util::TypedStorage<OsResourceManager> ResourceManagerHolder::s_resource_manager_storage = {};
}

View file

@ -42,7 +42,7 @@ namespace ams::os::impl {
class ResourceManagerHolder {
private:
static TYPED_STORAGE(OsResourceManager) s_resource_manager_storage;
static util::TypedStorage<OsResourceManager> s_resource_manager_storage;
private:
constexpr ResourceManagerHolder() { /* ... */ }
public:

View file

@ -27,15 +27,15 @@ namespace ams::os::impl {
struct WaitableHolderImpl {
union {
TYPED_STORAGE(WaitableHolderOfHandle) holder_of_handle_storage;
TYPED_STORAGE(WaitableHolderOfEvent) holder_of_event_storage;
TYPED_STORAGE(WaitableHolderOfInterProcessEvent) holder_of_inter_process_event_storage;
TYPED_STORAGE(WaitableHolderOfInterruptEvent) holder_of_interrupt_event_storage;
TYPED_STORAGE(WaitableHolderOfTimerEvent) holder_of_timer_event_storage;
TYPED_STORAGE(WaitableHolderOfThread) holder_of_thread_storage;
TYPED_STORAGE(WaitableHolderOfSemaphore) holder_of_semaphore_storage;
TYPED_STORAGE(WaitableHolderOfMessageQueueForNotFull) holder_of_mq_for_not_full_storage;
TYPED_STORAGE(WaitableHolderOfMessageQueueForNotEmpty) holder_of_mq_for_not_empty_storage;
util::TypedStorage<WaitableHolderOfHandle> holder_of_handle_storage;
util::TypedStorage<WaitableHolderOfEvent> holder_of_event_storage;
util::TypedStorage<WaitableHolderOfInterProcessEvent> holder_of_inter_process_event_storage;
util::TypedStorage<WaitableHolderOfInterruptEvent> holder_of_interrupt_event_storage;
util::TypedStorage<WaitableHolderOfTimerEvent> holder_of_timer_event_storage;
util::TypedStorage<WaitableHolderOfThread> holder_of_thread_storage;
util::TypedStorage<WaitableHolderOfSemaphore> holder_of_semaphore_storage;
util::TypedStorage<WaitableHolderOfMessageQueueForNotFull> holder_of_mq_for_not_full_storage;
util::TypedStorage<WaitableHolderOfMessageQueueForNotEmpty> holder_of_mq_for_not_empty_storage;
};
};

View file

@ -41,10 +41,10 @@ namespace ams::pgl::srv {
os::MessageQueue message_queue;
uintptr_t queue_buffer[QueueCapacity];
os::SystemEvent event;
TYPED_STORAGE(lmem::HeapCommonHead) heap_head;
util::TypedStorage<lmem::HeapCommonHead> heap_head;
lmem::HeapHandle heap_handle;
pm::ProcessEventInfo event_info_data[QueueCapacity];
TYPED_STORAGE(ShellEventObserverHolder) holder;
util::TypedStorage<ShellEventObserverHolder> holder;
public:
ShellEventObserver();
~ShellEventObserver();

View file

@ -50,7 +50,7 @@ namespace ams::sf::hipc::impl {
constinit os::ThreadType g_query_server_process_thread;
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;
}

View file

@ -25,7 +25,7 @@ namespace ams::util {
class BoundedMap {
private:
std::array<std::optional<Key>, N> keys;
std::array<TYPED_STORAGE(Value), N> values;
std::array<TypedStorage<Value>, N> values;
private:
ALWAYS_INLINE void FreeEntry(size_t i) {
this->keys[i].reset();

View file

@ -569,7 +569,7 @@ namespace ams::util {
return util::GetParentReference<Member, Derived>(&node);
}
private:
static constexpr TYPED_STORAGE(Derived) DerivedStorage = {};
static constexpr TypedStorage<Derived> DerivedStorage = {};
static_assert(std::addressof(GetParent(GetNode(GetReference(DerivedStorage)))) == GetPointer(DerivedStorage));
};
@ -582,7 +582,7 @@ namespace ams::util {
using ListType = IntrusiveList<Derived, IntrusiveListMemberTraitsDeferredAssert>;
static constexpr bool IsValid() {
TYPED_STORAGE(Derived) DerivedStorage = {};
TypedStorage<Derived> DerivedStorage = {};
return std::addressof(GetParent(GetNode(GetReference(DerivedStorage)))) == GetPointer(DerivedStorage);
}
private:

View file

@ -498,7 +498,7 @@ namespace ams::util {
return util::GetParentPointer<Member, Derived>(node);
}
private:
static constexpr TYPED_STORAGE(Derived) DerivedStorage = {};
static constexpr TypedStorage<Derived> DerivedStorage = {};
static_assert(GetParent(GetNode(GetPointer(DerivedStorage))) == GetPointer(DerivedStorage));
};
@ -513,7 +513,7 @@ namespace ams::util {
using TreeTypeImpl = impl::IntrusiveRedBlackTreeImpl;
static constexpr bool IsValid() {
TYPED_STORAGE(Derived) DerivedStorage = {};
TypedStorage<Derived> DerivedStorage = {};
return GetParent(GetNode(GetPointer(DerivedStorage))) == GetPointer(DerivedStorage);
}
private:

View file

@ -63,7 +63,7 @@ namespace ams::util {
union Union {
char c;
UnionHolder first_union;
TYPED_STORAGE(ParentType) parent;
TypedStorage<ParentType> parent;
/* This coerces the active member to be c. */
constexpr Union() : c() { /* ... */ }
@ -110,7 +110,7 @@ namespace ams::util {
template<typename ParentType, typename MemberType>
struct OffsetOfCalculator {
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 *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));

View file

@ -20,30 +20,28 @@
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 {
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>
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)));
}
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)));
}
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);
}
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);
}

View file

@ -237,7 +237,7 @@ namespace ams::sdmmc::impl {
#if defined(AMS_SDMMC_USE_PCV_CLOCK_RESET_CONTROL)
bool is_pcv_control;
#endif
TYPED_STORAGE(PowerController) power_controller_storage;
util::TypedStorage<PowerController> power_controller_storage;
PowerController *power_controller;
private:
Result PowerOnForRegisterControl(BusPower bus_power);

View file

@ -1148,7 +1148,7 @@ namespace ams::dmnt::cheat::impl {
/* Manager global. */
TYPED_STORAGE(CheatProcessManager) g_cheat_process_manager;
util::TypedStorage<CheatProcessManager> g_cheat_process_manager;
}

View file

@ -143,7 +143,7 @@ namespace ams::dmnt::cheat::impl {
};
/* Manager global. */
TYPED_STORAGE(DebugEventsManager) g_events_manager;
util::TypedStorage<DebugEventsManager> g_events_manager;
}

View file

@ -78,7 +78,7 @@ namespace ams::pm::impl {
NON_MOVEABLE(ProcessInfoAllocator);
static_assert(MaxProcessInfos >= 0x40, "MaxProcessInfos is too small.");
private:
TYPED_STORAGE(ProcessInfo) process_info_storages[MaxProcessInfos];
util::TypedStorage<ProcessInfo> process_info_storages[MaxProcessInfos];
bool process_info_allocated[MaxProcessInfos];
os::Mutex lock;
private: