diff --git a/libraries/libstratosphere/include/stratosphere/fs/common/fs_file_storage.hpp b/libraries/libstratosphere/include/stratosphere/fs/common/fs_file_storage.hpp index 3d8f44ec7..732c9299e 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/common/fs_file_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/common/fs_file_storage.hpp @@ -92,9 +92,9 @@ namespace ams::fs { FileHandle handle; bool close_file; s64 size; - os::Mutex mutex; + os::SdkMutex mutex; public: - constexpr explicit FileHandleStorage(FileHandle handle, bool close_file) : handle(handle), close_file(close_file), size(InvalidSize), mutex(false) { /* ... */ } + constexpr explicit FileHandleStorage(FileHandle handle, bool close_file) : handle(handle), close_file(close_file), size(InvalidSize), mutex() { /* ... */ } constexpr explicit FileHandleStorage(FileHandle handle) : FileHandleStorage(handle, false) { /* ... */ } virtual ~FileHandleStorage() override { diff --git a/libraries/libstratosphere/include/stratosphere/fssrv/fssrv_memory_resource_from_exp_heap.hpp b/libraries/libstratosphere/include/stratosphere/fssrv/fssrv_memory_resource_from_exp_heap.hpp index 08540f29e..99fdda7f7 100644 --- a/libraries/libstratosphere/include/stratosphere/fssrv/fssrv_memory_resource_from_exp_heap.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssrv/fssrv_memory_resource_from_exp_heap.hpp @@ -42,11 +42,11 @@ namespace ams::fssrv { class PeakCheckableMemoryResourceFromExpHeap : public ams::MemoryResource { private: lmem::HeapHandle heap_handle; - os::Mutex mutex; + os::SdkMutex mutex; size_t peak_free_size; size_t current_free_size; public: - constexpr explicit PeakCheckableMemoryResourceFromExpHeap(size_t heap_size) : heap_handle(nullptr), mutex(false), peak_free_size(heap_size), current_free_size(heap_size) { /* ... */ } + constexpr explicit PeakCheckableMemoryResourceFromExpHeap(size_t heap_size) : heap_handle(nullptr), mutex(), peak_free_size(heap_size), current_free_size(heap_size) { /* ... */ } void SetHeapHandle(lmem::HeapHandle handle) { this->heap_handle = handle; @@ -57,7 +57,7 @@ namespace ams::fssrv { void ClearPeak() { this->peak_free_size = this->current_free_size; } - std::scoped_lock GetScopedLock() { + std::scoped_lock GetScopedLock() { return std::scoped_lock(this->mutex); } diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/buffers/fssystem_file_system_buffer_manager.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/buffers/fssystem_file_system_buffer_manager.hpp index e6c37b66b..fcd84abe9 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/buffers/fssystem_file_system_buffer_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/buffers/fssystem_file_system_buffer_manager.hpp @@ -192,7 +192,7 @@ namespace ams::fssystem { size_t peak_free_size; size_t peak_total_allocatable_size; size_t retried_count; - mutable os::Mutex mutex; + mutable os::SdkRecursiveMutex mutex; public: static constexpr size_t QueryWorkBufferSize(s32 max_cache_count, s32 max_order) { const auto buddy_size = FileSystemBuddyHeap::QueryWorkBufferSize(max_order); @@ -200,7 +200,7 @@ namespace ams::fssystem { return buddy_size + table_size; } public: - FileSystemBufferManager() : total_size(), peak_free_size(), peak_total_allocatable_size(), retried_count(), mutex(true) { /* ... */ } + FileSystemBufferManager() : total_size(), peak_free_size(), peak_total_allocatable_size(), retried_count(), mutex() { /* ... */ } virtual ~FileSystemBufferManager() { /* ... */ } diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_aes_xts_storage.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_aes_xts_storage.hpp index f0780a2aa..9292339ec 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_aes_xts_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_aes_xts_storage.hpp @@ -33,7 +33,7 @@ namespace ams::fssystem { char key[2][KeySize]; char iv[IvSize]; const size_t block_size; - os::Mutex mutex; + os::SdkMutex mutex; public: AesXtsStorage(IStorage *base, const void *key1, const void *key2, size_t key_size, const void *iv, size_t iv_size, size_t block_size); diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_directory_redirection_filesystem.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_directory_redirection_filesystem.hpp index 281b4b99b..0bc6645df 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_directory_redirection_filesystem.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_directory_redirection_filesystem.hpp @@ -34,7 +34,7 @@ namespace ams::fssystem { virtual ~DirectoryRedirectionFileSystem(); protected: - inline util::optional> GetAccessorLock() const { + inline util::optional> GetAccessorLock() const { /* No accessor lock is needed. */ return util::nullopt; } diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_directory_savedata_filesystem.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_directory_savedata_filesystem.hpp index 026b2d936..54ccfba3c 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_directory_savedata_filesystem.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_directory_savedata_filesystem.hpp @@ -24,7 +24,7 @@ namespace ams::fssystem { using PathResolutionFileSystem = impl::IPathResolutionFileSystem; friend class impl::IPathResolutionFileSystem; private: - os::Mutex accessor_mutex; + os::SdkMutex accessor_mutex; s32 open_writable_files; public: DirectorySaveDataFileSystem(std::shared_ptr fs); @@ -33,9 +33,9 @@ namespace ams::fssystem { virtual ~DirectorySaveDataFileSystem(); protected: - inline util::optional> GetAccessorLock() { + inline util::optional> GetAccessorLock() { /* We have a real accessor lock that we want to use. */ - return util::make_optional>(this->accessor_mutex); + return util::make_optional>(this->accessor_mutex); } private: Result AllocateWorkBuffer(std::unique_ptr *out, size_t *out_size, size_t ideal_size); diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_integrity_romfs_storage.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_integrity_romfs_storage.hpp index fdc9d15b9..8c0414a25 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_integrity_romfs_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_integrity_romfs_storage.hpp @@ -30,11 +30,11 @@ namespace ams::fssystem { private: save::HierarchicalIntegrityVerificationStorage integrity_storage; save::FileSystemBufferManagerSet buffers; - os::Mutex mutex; + os::SdkRecursiveMutex mutex; Hash master_hash; std::unique_ptr master_hash_storage; public: - IntegrityRomFsStorage() : mutex(true) { /* ... */ } + IntegrityRomFsStorage() : mutex() { /* ... */ } virtual ~IntegrityRomFsStorage() override { this->Finalize(); } Result Initialize(save::HierarchicalIntegrityVerificationInformation level_hash_info, Hash master_hash, save::HierarchicalIntegrityVerificationStorage::HierarchicalStorageInformation storage_info, IBufferManager *bm); diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_subdirectory_filesystem.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_subdirectory_filesystem.hpp index e30e74db1..61ac5dd3c 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_subdirectory_filesystem.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_subdirectory_filesystem.hpp @@ -32,7 +32,7 @@ namespace ams::fssystem { virtual ~SubDirectoryFileSystem(); protected: - inline util::optional> GetAccessorLock() const { + inline util::optional> GetAccessorLock() const { /* No accessor lock is needed. */ return util::nullopt; } diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/save/fssystem_block_cache_buffered_storage.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/save/fssystem_block_cache_buffered_storage.hpp index b93ca0241..387280422 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/save/fssystem_block_cache_buffered_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/save/fssystem_block_cache_buffered_storage.hpp @@ -62,7 +62,7 @@ namespace ams::fssystem::save { }; private: IBufferManager *buffer_manager; - os::Mutex *mutex; + os::SdkRecursiveMutex *mutex; std::unique_ptr entries; IStorage *data_storage; Result last_result; @@ -78,7 +78,7 @@ namespace ams::fssystem::save { BlockCacheBufferedStorage(); virtual ~BlockCacheBufferedStorage() override; - Result Initialize(IBufferManager *bm, os::Mutex *mtx, IStorage *data, s64 data_size, size_t verif_block_size, s32 max_cache_entries, bool is_real_data, s8 buffer_level, bool is_keep_burst_mode, fs::StorageType storage_type); + Result Initialize(IBufferManager *bm, os::SdkRecursiveMutex *mtx, IStorage *data, s64 data_size, size_t verif_block_size, s32 max_cache_entries, bool is_real_data, s8 buffer_level, bool is_keep_burst_mode, fs::StorageType storage_type); void Finalize(); virtual Result Read(s64 offset, void *buffer, size_t size) override; diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/save/fssystem_buffered_storage.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/save/fssystem_buffered_storage.hpp index eb30a8a7e..8c5ca9db2 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/save/fssystem_buffered_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/save/fssystem_buffered_storage.hpp @@ -38,7 +38,7 @@ namespace ams::fssystem::save { s32 cache_count; Cache *next_acquire_cache; Cache *next_fetch_cache; - os::Mutex mutex; + os::SdkMutex mutex; bool bulk_read_enabled; public: BufferedStorage(); diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/save/fssystem_hierarchical_integrity_verification_storage.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/save/fssystem_hierarchical_integrity_verification_storage.hpp index 1283a2ac6..23b349016 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/save/fssystem_hierarchical_integrity_verification_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/save/fssystem_hierarchical_integrity_verification_storage.hpp @@ -147,7 +147,7 @@ namespace ams::fssystem::save { } private: FileSystemBufferManagerSet *buffers; - os::Mutex *mutex; + os::SdkRecursiveMutex *mutex; IntegrityVerificationStorage verify_storages[MaxLayers - 1]; BlockCacheBufferedStorage buffer_storages[MaxLayers - 1]; s64 data_size; @@ -157,7 +157,7 @@ namespace ams::fssystem::save { HierarchicalIntegrityVerificationStorage() : buffers(nullptr), mutex(nullptr), data_size(-1), is_written_for_rollback(false) { /* ... */ } virtual ~HierarchicalIntegrityVerificationStorage() override { this->Finalize(); } - Result Initialize(const HierarchicalIntegrityVerificationInformation &info, HierarchicalStorageInformation storage, FileSystemBufferManagerSet *bufs, os::Mutex *mtx, fs::StorageType storage_type); + Result Initialize(const HierarchicalIntegrityVerificationInformation &info, HierarchicalStorageInformation storage, FileSystemBufferManagerSet *bufs, os::SdkRecursiveMutex *mtx, fs::StorageType storage_type); void Finalize(); virtual Result Read(s64 offset, void *buffer, size_t size) override; diff --git a/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_store.hpp b/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_store.hpp index 707968e7e..537a1fc95 100644 --- a/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_store.hpp +++ b/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_file_key_value_store.hpp @@ -63,14 +63,14 @@ namespace ams::kvdb { bool Contains(const void *key, size_t key_size); }; private: - os::Mutex lock; + os::SdkMutex lock; Path dir_path; Cache cache; private: Path GetPath(const void *key, size_t key_size); Result GetKey(size_t *out_size, void *out_key, size_t max_out_size, const FileName &file_name); public: - FileKeyValueStore() : lock(false) { /* ... */ } + FileKeyValueStore() : lock() { /* ... */ } /* Basic accessors. */ Result Initialize(const char *dir); diff --git a/libraries/libstratosphere/include/stratosphere/lmem/impl/lmem_impl_common.hpp b/libraries/libstratosphere/include/stratosphere/lmem/impl/lmem_impl_common.hpp index 4cc2240a0..3009fa42f 100644 --- a/libraries/libstratosphere/include/stratosphere/lmem/impl/lmem_impl_common.hpp +++ b/libraries/libstratosphere/include/stratosphere/lmem/impl/lmem_impl_common.hpp @@ -85,7 +85,7 @@ namespace ams::lmem::impl { void *heap_start; void *heap_end; - os::MutexType mutex; + os::SdkMutexType mutex; u8 option; ImplementationHeapHead impl_head; }; diff --git a/libraries/libstratosphere/include/stratosphere/lr/lr_location_resolver_manager_impl.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_location_resolver_manager_impl.hpp index 0d9f57ac9..0405114f3 100644 --- a/libraries/libstratosphere/include/stratosphere/lr/lr_location_resolver_manager_impl.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_location_resolver_manager_impl.hpp @@ -28,7 +28,7 @@ namespace ams::lr { sf::SharedPointer registered_location_resolver = nullptr; sf::SharedPointer add_on_content_location_resolver = nullptr; - os::Mutex mutex{false}; + os::SdkMutex mutex{}; public: /* Actual commands. */ Result OpenLocationResolver(sf::Out> out, ncm::StorageId storage_id); diff --git a/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_manager_impl.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_manager_impl.hpp index a0e25cf9a..b52f9b86f 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_manager_impl.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_manager_impl.hpp @@ -102,7 +102,7 @@ namespace ams::ncm { ContentMetaDatabaseRoot() { /* ... */ } }; private: - os::Mutex mutex; + os::SdkRecursiveMutex mutex; bool initialized; ContentStorageRoot content_storage_roots[MaxContentStorageRoots]; ContentMetaDatabaseRoot content_meta_database_roots[MaxContentMetaDatabaseRoots]; @@ -111,8 +111,8 @@ namespace ams::ncm { RightsIdCache rights_id_cache; RegisteredHostContent registered_host_content; public: - ContentManagerImpl() : mutex(true), initialized(false), num_content_storage_entries(0), num_content_meta_entries(0), rights_id_cache(), registered_host_content() { - /* ... */ + ContentManagerImpl() : mutex(), initialized(false), num_content_storage_entries(0), num_content_meta_entries(0), rights_id_cache(), registered_host_content() { + /* ... */ }; ~ContentManagerImpl(); public: diff --git a/libraries/libstratosphere/include/stratosphere/ncm/ncm_install_task_base.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_install_task_base.hpp index 3e72ff483..936d28ace 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_install_task_base.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_install_task_base.hpp @@ -86,13 +86,13 @@ namespace ams::ncm { StorageId install_storage; InstallTaskDataBase *data; InstallProgress progress; - os::Mutex progress_mutex; + os::SdkMutex progress_mutex; u32 config; - os::Mutex cancel_mutex; + os::SdkMutex cancel_mutex; bool cancel_requested; InstallThroughput throughput; TimeSpan throughput_start_time; - os::Mutex throughput_mutex; + os::SdkMutex throughput_mutex; FirmwareVariationId firmware_variation_id; private: ALWAYS_INLINE Result SetLastResultOnFailure(Result result) { @@ -102,7 +102,7 @@ namespace ams::ncm { return result; } public: - InstallTaskBase() : data(), progress(), progress_mutex(false), cancel_mutex(false), cancel_requested(), throughput_mutex(false) { /* ... */ } + InstallTaskBase() : data(), progress(), progress_mutex(), cancel_mutex(), cancel_requested(), throughput_mutex() { /* ... */ } virtual ~InstallTaskBase() { /* ... */ }; public: virtual void Cancel(); diff --git a/libraries/libstratosphere/include/stratosphere/ncm/ncm_memory_report.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_memory_report.hpp index a825fb177..9a1f1a98a 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_memory_report.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_memory_report.hpp @@ -40,13 +40,13 @@ namespace ams::ncm { class HeapState { private: - os::Mutex mutex; + os::SdkMutex mutex; lmem::HeapHandle heap_handle; size_t total_alloc_size; size_t peak_total_alloc_size; size_t peak_alloc_size; public: - constexpr HeapState() : mutex(false), heap_handle(nullptr), total_alloc_size(0), peak_total_alloc_size(0), peak_alloc_size(0) { /* ... */ } + constexpr HeapState() : mutex(), heap_handle(nullptr), total_alloc_size(0), peak_total_alloc_size(0), peak_alloc_size(0) { /* ... */ } void Initialize(lmem::HeapHandle heap_handle); void Allocate(size_t size); diff --git a/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_manager.hpp b/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_manager.hpp index e59d54caf..e2b8e6248 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_manager.hpp @@ -84,7 +84,7 @@ namespace ams::sf::cmif { private: using EntryList = typename util::IntrusiveListMemberTraits<&Entry::free_list_node>::ListType; private: - os::Mutex lock; + os::SdkMutex lock; EntryList free_list; Entry *entries; size_t num_entries; @@ -114,13 +114,13 @@ namespace ams::sf::cmif { } }; private: - os::Mutex entry_owner_lock; + os::SdkMutex entry_owner_lock; EntryManager entry_manager; private: virtual void *AllocateDomain() = 0; virtual void FreeDomain(void *) = 0; protected: - ServerDomainManager(DomainEntryStorage *entry_storage, size_t entry_count) : entry_owner_lock(false), entry_manager(entry_storage, entry_count) { /* ... */ } + ServerDomainManager(DomainEntryStorage *entry_storage, size_t entry_count) : entry_owner_lock(), entry_manager(entry_storage, entry_count) { /* ... */ } inline DomainServiceObject *AllocateDomainServiceObject() { void *storage = this->AllocateDomain(); diff --git a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp index d611f5d1b..0f1b2e4aa 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_manager.hpp @@ -80,9 +80,9 @@ namespace ams::sf::hipc { os::Event notify_event; os::WaitableHolderType notify_event_holder; - os::Mutex waitable_selection_mutex; + os::SdkMutex waitable_selection_mutex; - os::Mutex waitlist_mutex; + os::SdkMutex waitlist_mutex; os::WaitableManagerType waitlist; private: virtual void RegisterSessionToWaitList(ServerSession *session) override final; @@ -192,7 +192,7 @@ namespace ams::sf::hipc { ServerManagerBase(DomainEntryStorage *entry_storage, size_t entry_count) : ServerDomainSessionManager(entry_storage, entry_count), request_stop_event(os::EventClearMode_ManualClear), notify_event(os::EventClearMode_ManualClear), - waitable_selection_mutex(false), waitlist_mutex(false) + waitable_selection_mutex(), waitlist_mutex() { /* Link waitables. */ os::InitializeWaitableManager(std::addressof(this->waitable_manager)); @@ -259,7 +259,7 @@ namespace ams::sf::hipc { using ServerManagerBase::DomainStorage; private: /* Resource storage. */ - os::Mutex resource_mutex; + os::SdkMutex resource_mutex; util::TypedStorage server_storages[MaxServers]; bool server_allocated[MaxServers]; util::TypedStorage session_storages[MaxSessions]; @@ -370,7 +370,7 @@ namespace ams::sf::hipc { return this->GetObjectBySessionIndex(session, this->saved_messages_start, hipc::TlsMessageBufferSize); } public: - ServerManager() : ServerManagerBase(this->domain_entry_storages, ManagerOptions::MaxDomainObjects), resource_mutex(false) { + ServerManager() : ServerManagerBase(this->domain_entry_storages, ManagerOptions::MaxDomainObjects), resource_mutex() { /* Clear storages. */ #define SF_SM_MEMCLEAR(obj) if constexpr (sizeof(obj) > 0) { std::memset(obj, 0, sizeof(obj)); } SF_SM_MEMCLEAR(this->server_storages); diff --git a/libraries/libstratosphere/include/stratosphere/tipc/tipc_server_manager.hpp b/libraries/libstratosphere/include/stratosphere/tipc/tipc_server_manager.hpp index 05c9b4183..33df54dc5 100644 --- a/libraries/libstratosphere/include/stratosphere/tipc/tipc_server_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/tipc/tipc_server_manager.hpp @@ -355,7 +355,7 @@ namespace ams::tipc { using PortAllocatorTuple = std::tuple; private: - os::Mutex m_mutex; + os::SdkRecursiveMutex m_mutex; os::TlsSlot m_tls_slot; PortManagerTuple m_port_managers; PortAllocatorTuple m_port_allocators; @@ -390,11 +390,11 @@ namespace ams::tipc { os::StartThread(m_port_threads + Ix); } public: - ServerManagerImpl() : m_mutex(true), m_tls_slot(), m_port_managers(), m_port_allocators() { /* ... */ } + ServerManagerImpl() : m_mutex(), m_tls_slot(), m_port_managers(), m_port_allocators() { /* ... */ } os::TlsSlot GetTlsSlot() const { return m_tls_slot; } - os::Mutex &GetMutex() { return m_mutex; } + os::SdkRecursiveMutex &GetMutex() { return m_mutex; } void Initialize() { /* Initialize our tls slot. */ diff --git a/libraries/libstratosphere/source/cfg/cfg_privileged_process.cpp b/libraries/libstratosphere/source/cfg/cfg_privileged_process.cpp index 0fe262a8b..a517b24f1 100644 --- a/libraries/libstratosphere/source/cfg/cfg_privileged_process.cpp +++ b/libraries/libstratosphere/source/cfg/cfg_privileged_process.cpp @@ -24,10 +24,10 @@ namespace ams::cfg { constexpr os::ProcessId InitialProcessIdMaxDeprecated = {0x50}; /* Privileged process globals. */ - os::Mutex g_lock(false); - bool g_got_privileged_process_status = false; - os::ProcessId g_min_initial_process_id = os::InvalidProcessId, g_max_initial_process_id = os::InvalidProcessId; - os::ProcessId g_cur_process_id = os::InvalidProcessId; + constinit os::SdkMutex g_lock; + constinit bool g_got_privileged_process_status = false; + constinit os::ProcessId g_min_initial_process_id = os::InvalidProcessId, g_max_initial_process_id = os::InvalidProcessId; + constinit os::ProcessId g_cur_process_id = os::InvalidProcessId; /* SD card helpers. */ void GetPrivilegedProcessIdRange(os::ProcessId *out_min, os::ProcessId *out_max) { diff --git a/libraries/libstratosphere/source/cfg/cfg_sd_card.cpp b/libraries/libstratosphere/source/cfg/cfg_sd_card.cpp index cbf60a724..84a96c778 100644 --- a/libraries/libstratosphere/source/cfg/cfg_sd_card.cpp +++ b/libraries/libstratosphere/source/cfg/cfg_sd_card.cpp @@ -29,9 +29,9 @@ namespace ams::cfg { constexpr size_t NumRequiredServicesForSdCardAccess = util::size(RequiredServicesForSdCardAccess); /* SD card globals. */ - os::Mutex g_sd_card_lock(false); - bool g_sd_card_initialized = false; - FsFileSystem g_sd_card_filesystem = {}; + constinit os::SdkMutex g_sd_card_lock; + constinit bool g_sd_card_initialized = false; + constinit FsFileSystem g_sd_card_filesystem = {}; /* SD card helpers. */ Result CheckSdCardServicesReady() { diff --git a/libraries/libstratosphere/source/diag/diag_assertion_impl.cpp b/libraries/libstratosphere/source/diag/diag_assertion_impl.cpp index 77e41c0b1..d075194ab 100644 --- a/libraries/libstratosphere/source/diag/diag_assertion_impl.cpp +++ b/libraries/libstratosphere/source/diag/diag_assertion_impl.cpp @@ -44,8 +44,8 @@ namespace ams::diag { inline void DebugLog(const char *format, ...) __attribute__((format(printf, 1, 2))); #ifdef AMS_ENABLE_DETAILED_ASSERTIONS - os::Mutex g_debug_log_lock(true); - char g_debug_buffer[0x400]; + constinit os::SdkRecursiveMutex g_debug_log_lock; + constinit char g_debug_buffer[0x400]; void DebugLogImpl(const char *format, ::std::va_list vl) { std::scoped_lock lk(g_debug_log_lock); diff --git a/libraries/libstratosphere/source/fs/fsa/fs_filesystem_accessor.cpp b/libraries/libstratosphere/source/fs/fsa/fs_filesystem_accessor.cpp index 10b2e3ec5..28fd3cea0 100644 --- a/libraries/libstratosphere/source/fs/fsa/fs_filesystem_accessor.cpp +++ b/libraries/libstratosphere/source/fs/fsa/fs_filesystem_accessor.cpp @@ -60,7 +60,7 @@ namespace ams::fs::impl { } FileSystemAccessor::FileSystemAccessor(const char *n, std::unique_ptr &&fs, std::unique_ptr &&generator) - : impl(std::move(fs)), open_list_lock(false), mount_name_generator(std::move(generator)), + : impl(std::move(fs)), open_list_lock(), mount_name_generator(std::move(generator)), access_log_enabled(false), data_cache_attachable(false), path_cache_attachable(false), path_cache_attached(false), multi_commit_supported(false) { R_ABORT_UNLESS(ValidateMountName(n)); diff --git a/libraries/libstratosphere/source/fs/fsa/fs_filesystem_accessor.hpp b/libraries/libstratosphere/source/fs/fsa/fs_filesystem_accessor.hpp index 856059c16..4e20419be 100644 --- a/libraries/libstratosphere/source/fs/fsa/fs_filesystem_accessor.hpp +++ b/libraries/libstratosphere/source/fs/fsa/fs_filesystem_accessor.hpp @@ -35,7 +35,7 @@ namespace ams::fs::impl { std::unique_ptr impl; FileList open_file_list; DirList open_dir_list; - os::Mutex open_list_lock; + os::SdkMutex open_list_lock; std::unique_ptr mount_name_generator; bool access_log_enabled; bool data_cache_attachable; diff --git a/libraries/libstratosphere/source/fs/fsa/fs_mount_table.hpp b/libraries/libstratosphere/source/fs/fsa/fs_mount_table.hpp index e0034588d..59fe63b2c 100644 --- a/libraries/libstratosphere/source/fs/fsa/fs_mount_table.hpp +++ b/libraries/libstratosphere/source/fs/fsa/fs_mount_table.hpp @@ -26,9 +26,9 @@ namespace ams::fs::impl { using FileSystemList = util::IntrusiveListBaseTraits::ListType; private: FileSystemList fs_list; - os::Mutex mutex; + os::SdkMutex mutex; public: - constexpr MountTable() : fs_list(), mutex(false) { /* ... */ } + constexpr MountTable() : fs_list(), mutex() { /* ... */ } private: bool CanAcceptMountName(const char *name); public: diff --git a/libraries/libstratosphere/source/fssystem/fssystem_aes_xts_storage.cpp b/libraries/libstratosphere/source/fssystem/fssystem_aes_xts_storage.cpp index 959725bdd..db19eceb9 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_aes_xts_storage.cpp +++ b/libraries/libstratosphere/source/fssystem/fssystem_aes_xts_storage.cpp @@ -17,7 +17,7 @@ namespace ams::fssystem { - AesXtsStorage::AesXtsStorage(IStorage *base, const void *key1, const void *key2, size_t key_size, const void *iv, size_t iv_size, size_t block_size) : base_storage(base), block_size(block_size), mutex(false) { + AesXtsStorage::AesXtsStorage(IStorage *base, const void *key1, const void *key2, size_t key_size, const void *iv, size_t iv_size, size_t block_size) : base_storage(base), block_size(block_size), mutex() { AMS_ASSERT(base != nullptr); AMS_ASSERT(key1 != nullptr); AMS_ASSERT(key2 != nullptr); diff --git a/libraries/libstratosphere/source/fssystem/fssystem_directory_savedata_filesystem.cpp b/libraries/libstratosphere/source/fssystem/fssystem_directory_savedata_filesystem.cpp index 8f60adee9..5f00412b7 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_directory_savedata_filesystem.cpp +++ b/libraries/libstratosphere/source/fssystem/fssystem_directory_savedata_filesystem.cpp @@ -74,13 +74,13 @@ namespace ams::fssystem { } DirectorySaveDataFileSystem::DirectorySaveDataFileSystem(std::shared_ptr fs) - : PathResolutionFileSystem(fs), accessor_mutex(false), open_writable_files(0) + : PathResolutionFileSystem(fs), accessor_mutex(), open_writable_files(0) { /* ... */ } DirectorySaveDataFileSystem::DirectorySaveDataFileSystem(std::unique_ptr fs) - : PathResolutionFileSystem(std::move(fs)), accessor_mutex(false), open_writable_files(0) + : PathResolutionFileSystem(std::move(fs)), accessor_mutex(), open_writable_files(0) { /* ... */ } diff --git a/libraries/libstratosphere/source/fssystem/fssystem_hierarchical_sha256_storage.hpp b/libraries/libstratosphere/source/fssystem/fssystem_hierarchical_sha256_storage.hpp index 5ef4a0082..16b461c6d 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_hierarchical_sha256_storage.hpp +++ b/libraries/libstratosphere/source/fssystem/fssystem_hierarchical_sha256_storage.hpp @@ -25,7 +25,7 @@ namespace ams::fssystem { static constexpr s32 LayerCount = 3; static constexpr size_t HashSize = crypto::Sha256Generator::HashSize; private: - os::Mutex mutex; + os::SdkMutex mutex; IStorage *base_storage; s64 base_storage_size; char *hash_buffer; @@ -33,7 +33,7 @@ namespace ams::fssystem { s32 hash_target_block_size; s32 log_size_ratio; public: - HierarchicalSha256Storage() : mutex(false) { /* ... */ } + HierarchicalSha256Storage() : mutex() { /* ... */ } Result Initialize(IStorage **base_storages, s32 layer_count, size_t htbs, void *hash_buf, size_t hash_buf_size); diff --git a/libraries/libstratosphere/source/fssystem/fssystem_key_slot_cache.hpp b/libraries/libstratosphere/source/fssystem/fssystem_key_slot_cache.hpp index 6b4f92345..0cf1f5e20 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_key_slot_cache.hpp +++ b/libraries/libstratosphere/source/fssystem/fssystem_key_slot_cache.hpp @@ -22,10 +22,10 @@ namespace ams::fssystem { NON_COPYABLE(KeySlotCacheAccessor); NON_MOVEABLE(KeySlotCacheAccessor); private: - util::unique_lock lk; + util::unique_lock lk; const s32 slot_index; public: - KeySlotCacheAccessor(s32 idx, util::unique_lock &&l) : lk(std::move(l)), slot_index(idx) { /* ... */ } + KeySlotCacheAccessor(s32 idx, util::unique_lock &&l) : lk(std::move(l)), slot_index(idx) { /* ... */ } s32 GetKeySlotIndex() const { return this->slot_index; } }; @@ -64,11 +64,11 @@ namespace ams::fssystem { private: using KeySlotCacheEntryList = util::IntrusiveListBaseTraits::ListType; private: - os::Mutex mutex; + os::SdkMutex mutex; KeySlotCacheEntryList high_priority_mru_list; KeySlotCacheEntryList low_priority_mru_list; public: - constexpr KeySlotCache() : mutex(false), high_priority_mru_list(), low_priority_mru_list() { /* ... */ } + constexpr KeySlotCache() : mutex(), high_priority_mru_list(), low_priority_mru_list() { /* ... */ } Result AllocateHighPriority(std::unique_ptr *out, const void *key, size_t key_size, s32 key2) { return this->AllocateFromLru(out, this->high_priority_mru_list, key, key_size, key2); diff --git a/libraries/libstratosphere/source/fssystem/fssystem_pooled_buffer.cpp b/libraries/libstratosphere/source/fssystem/fssystem_pooled_buffer.cpp index 7d36e9919..0ec3e1e43 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_pooled_buffer.cpp +++ b/libraries/libstratosphere/source/fssystem/fssystem_pooled_buffer.cpp @@ -21,13 +21,12 @@ namespace ams::fssystem { class AdditionalDeviceAddressEntry { private: - /* TODO: SdkMutex */ - os::Mutex mutex; + os::SdkMutex mutex; bool is_registered; uintptr_t address; size_t size; public: - constexpr AdditionalDeviceAddressEntry() : mutex(false), is_registered(), address(), size() { /* ... */ } + constexpr AdditionalDeviceAddressEntry() : mutex(), is_registered(), address(), size() { /* ... */ } void Register(uintptr_t addr, size_t sz) { std::scoped_lock lk(this->mutex); @@ -77,18 +76,17 @@ namespace ams::fssystem { constexpr size_t HeapAllocatableSizeMax = HeapBlockSize * (static_cast(1) << HeapOrderMax); constexpr size_t HeapAllocatableSizeMaxForLarge = HeapBlockSize * (static_cast(1) << HeapOrderMaxForLarge); - /* TODO: SdkMutex */ - os::Mutex g_heap_mutex(false); - FileSystemBuddyHeap g_heap; + constinit os::SdkMutex g_heap_mutex; + constinit FileSystemBuddyHeap g_heap; - std::atomic g_retry_count; - std::atomic g_reduce_allocation_count; + constinit std::atomic g_retry_count; + constinit std::atomic g_reduce_allocation_count; - void *g_heap_buffer; - size_t g_heap_size; - size_t g_heap_free_size_peak; + constinit void *g_heap_buffer; + constinit size_t g_heap_size; + constinit size_t g_heap_free_size_peak; - AdditionalDeviceAddressEntry g_additional_device_address_entry; + constinit AdditionalDeviceAddressEntry g_additional_device_address_entry; } diff --git a/libraries/libstratosphere/source/fssystem/fssystem_read_only_block_cache_storage.hpp b/libraries/libstratosphere/source/fssystem/fssystem_read_only_block_cache_storage.hpp index f46ee156d..61a73d88d 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_read_only_block_cache_storage.hpp +++ b/libraries/libstratosphere/source/fssystem/fssystem_read_only_block_cache_storage.hpp @@ -25,12 +25,12 @@ namespace ams::fssystem { private: using BlockCache = LruListCache; private: - os::Mutex mutex; + os::SdkMutex mutex; BlockCache block_cache; fs::IStorage * const base_storage; s32 block_size; public: - ReadOnlyBlockCacheStorage(IStorage *bs, s32 bsz, char *buf, size_t buf_size, s32 cache_block_count) : mutex(false), base_storage(bs), block_size(bsz) { + ReadOnlyBlockCacheStorage(IStorage *bs, s32 bsz, char *buf, size_t buf_size, s32 cache_block_count) : mutex(), base_storage(bs), block_size(bsz) { /* Validate preconditions. */ AMS_ASSERT(buf_size >= static_cast(this->block_size)); AMS_ASSERT(util::IsPowerOfTwo(this->block_size)); diff --git a/libraries/libstratosphere/source/fssystem/save/fssystem_block_cache_buffered_storage.cpp b/libraries/libstratosphere/source/fssystem/save/fssystem_block_cache_buffered_storage.cpp index 2379ab20b..773840aa0 100644 --- a/libraries/libstratosphere/source/fssystem/save/fssystem_block_cache_buffered_storage.cpp +++ b/libraries/libstratosphere/source/fssystem/save/fssystem_block_cache_buffered_storage.cpp @@ -27,7 +27,7 @@ namespace ams::fssystem::save { this->Finalize(); } - Result BlockCacheBufferedStorage::Initialize(IBufferManager *bm, os::Mutex *mtx, IStorage *data, s64 data_size, size_t verif_block_size, s32 max_cache_entries, bool is_real_data, s8 buffer_level, bool is_keep_burst_mode, fs::StorageType storage_type) { + Result BlockCacheBufferedStorage::Initialize(IBufferManager *bm, os::SdkRecursiveMutex *mtx, IStorage *data, s64 data_size, size_t verif_block_size, s32 max_cache_entries, bool is_real_data, s8 buffer_level, bool is_keep_burst_mode, fs::StorageType storage_type) { /* Validate preconditions. */ AMS_ASSERT(data != nullptr); AMS_ASSERT(bm != nullptr); diff --git a/libraries/libstratosphere/source/fssystem/save/fssystem_buffered_storage.cpp b/libraries/libstratosphere/source/fssystem/save/fssystem_buffered_storage.cpp index d8de70fcb..bdd064bd2 100644 --- a/libraries/libstratosphere/source/fssystem/save/fssystem_buffered_storage.cpp +++ b/libraries/libstratosphere/source/fssystem/save/fssystem_buffered_storage.cpp @@ -582,7 +582,7 @@ namespace ams::fssystem::save { } }; - BufferedStorage::BufferedStorage() : base_storage(), buffer_manager(), block_size(), base_storage_size(), caches(), cache_count(), next_acquire_cache(), next_fetch_cache(), mutex(false), bulk_read_enabled() { + BufferedStorage::BufferedStorage() : base_storage(), buffer_manager(), block_size(), base_storage_size(), caches(), cache_count(), next_acquire_cache(), next_fetch_cache(), mutex(), bulk_read_enabled() { /* ... */ } diff --git a/libraries/libstratosphere/source/fssystem/save/fssystem_hierarchical_integrity_verification_storage.cpp b/libraries/libstratosphere/source/fssystem/save/fssystem_hierarchical_integrity_verification_storage.cpp index 24967553e..67d9e47e3 100644 --- a/libraries/libstratosphere/source/fssystem/save/fssystem_hierarchical_integrity_verification_storage.cpp +++ b/libraries/libstratosphere/source/fssystem/save/fssystem_hierarchical_integrity_verification_storage.cpp @@ -150,7 +150,7 @@ namespace ams::fssystem::save { this->storage = fs::SubStorage(); } - Result HierarchicalIntegrityVerificationStorage::Initialize(const HierarchicalIntegrityVerificationInformation &info, HierarchicalStorageInformation storage, FileSystemBufferManagerSet *bufs, os::Mutex *mtx, fs::StorageType storage_type) { + Result HierarchicalIntegrityVerificationStorage::Initialize(const HierarchicalIntegrityVerificationInformation &info, HierarchicalStorageInformation storage, FileSystemBufferManagerSet *bufs, os::SdkRecursiveMutex *mtx, fs::StorageType storage_type) { /* Validate preconditions. */ AMS_ASSERT(bufs != nullptr); AMS_ASSERT(IntegrityMinLayerCount <= info.max_layers && info.max_layers <= IntegrityMaxLayerCount); diff --git a/libraries/libstratosphere/source/hid/hid_api.cpp b/libraries/libstratosphere/source/hid/hid_api.cpp index 7196618b4..2257d0918 100644 --- a/libraries/libstratosphere/source/hid/hid_api.cpp +++ b/libraries/libstratosphere/source/hid/hid_api.cpp @@ -20,8 +20,8 @@ namespace ams::hid { namespace { /* Global lock. */ - os::Mutex g_hid_lock(false); - bool g_initialized_hid = false; + constinit os::SdkMutex g_hid_lock; + constinit bool g_initialized_hid = false; /* Set of supported NpadIds (we want to read from any connected controllers). */ constexpr const HidNpadIdType NpadIdTypes[] = { diff --git a/libraries/libstratosphere/source/lmem/impl/lmem_impl_common_heap.hpp b/libraries/libstratosphere/source/lmem/impl/lmem_impl_common_heap.hpp index 6c2c5fa9e..e39d077d7 100644 --- a/libraries/libstratosphere/source/lmem/impl/lmem_impl_common_heap.hpp +++ b/libraries/libstratosphere/source/lmem/impl/lmem_impl_common_heap.hpp @@ -30,13 +30,13 @@ namespace ams::lmem::impl { public: explicit ScopedHeapLock(HeapHandle h) : handle(h) { if (this->handle->option & CreateOption_ThreadSafe) { - os::LockMutex(std::addressof(this->handle->mutex)); + os::LockSdkMutex(std::addressof(this->handle->mutex)); } } ~ScopedHeapLock() { if (this->handle->option & CreateOption_ThreadSafe) { - os::UnlockMutex(std::addressof(this->handle->mutex)); + os::UnlockSdkMutex(std::addressof(this->handle->mutex)); } } }; diff --git a/libraries/libstratosphere/source/lmem/impl/lmem_impl_exp_heap.cpp b/libraries/libstratosphere/source/lmem/impl/lmem_impl_exp_heap.cpp index 213fbd5fa..3119a3039 100644 --- a/libraries/libstratosphere/source/lmem/impl/lmem_impl_exp_heap.cpp +++ b/libraries/libstratosphere/source/lmem/impl/lmem_impl_exp_heap.cpp @@ -427,6 +427,7 @@ namespace ams::lmem::impl { const s32 abs_alignment = std::abs(alignment); AMS_ASSERT((abs_alignment & (abs_alignment - 1)) == 0); AMS_ASSERT(MinimumAlignment <= static_cast(abs_alignment)); + AMS_UNUSED(abs_alignment); /* Fix size to be correctly aligned. */ if (size == 0) { diff --git a/libraries/libstratosphere/source/lmem/lmem_exp_heap.cpp b/libraries/libstratosphere/source/lmem/lmem_exp_heap.cpp index 606040438..489ec9551 100644 --- a/libraries/libstratosphere/source/lmem/lmem_exp_heap.cpp +++ b/libraries/libstratosphere/source/lmem/lmem_exp_heap.cpp @@ -21,15 +21,12 @@ namespace ams::lmem { HeapHandle CreateExpHeap(void *address, size_t size, u32 option) { HeapHandle handle = impl::CreateExpHeap(address, size, option); if (option & CreateOption_ThreadSafe) { - os::InitializeMutex(std::addressof(handle->mutex), false, 0); + os::InitializeSdkMutex(std::addressof(handle->mutex)); } return handle; } void DestroyExpHeap(HeapHandle handle) { - if (handle->option & CreateOption_ThreadSafe) { - os::FinalizeMutex(std::addressof(handle->mutex)); - } impl::DestroyExpHeap(handle); } diff --git a/libraries/libstratosphere/source/lmem/lmem_unit_heap.cpp b/libraries/libstratosphere/source/lmem/lmem_unit_heap.cpp index edc7c8cd6..5a9b2a58f 100644 --- a/libraries/libstratosphere/source/lmem/lmem_unit_heap.cpp +++ b/libraries/libstratosphere/source/lmem/lmem_unit_heap.cpp @@ -21,7 +21,7 @@ namespace ams::lmem { HeapHandle CreateUnitHeap(void *address, size_t size, size_t unit_size, u32 option) { HeapHandle handle = impl::CreateUnitHeap(address, size, unit_size, DefaultAlignment, static_cast(option), InfoPlacement_Head, nullptr); if (option & CreateOption_ThreadSafe) { - os::InitializeMutex(std::addressof(handle->mutex), false, 0); + os::InitializeSdkMutex(std::addressof(handle->mutex)); } return handle; } @@ -29,7 +29,7 @@ namespace ams::lmem { HeapHandle CreateUnitHeap(void *address, size_t size, size_t unit_size, u32 option, s32 alignment, InfoPlacement info_placement) { HeapHandle handle = impl::CreateUnitHeap(address, size, unit_size, alignment, static_cast(option), info_placement, nullptr); if (option & CreateOption_ThreadSafe) { - os::InitializeMutex(std::addressof(handle->mutex), false, 0); + os::InitializeSdkMutex(std::addressof(handle->mutex)); } return handle; } @@ -37,15 +37,12 @@ namespace ams::lmem { HeapHandle CreateUnitHeap(void *address, size_t size, size_t unit_size, u32 option, s32 alignment, HeapCommonHead *heap_head) { HeapHandle handle = impl::CreateUnitHeap(address, size, unit_size, alignment, static_cast(option), InfoPlacement_Head, heap_head); if (option & CreateOption_ThreadSafe) { - os::InitializeMutex(std::addressof(handle->mutex), false, 0); + os::InitializeSdkMutex(std::addressof(handle->mutex)); } return handle; } void DestroyUnitHeap(HeapHandle handle) { - if (handle->option & CreateOption_ThreadSafe) { - os::FinalizeMutex(std::addressof(handle->mutex)); - } impl::DestroyUnitHeap(handle); } diff --git a/libraries/libstratosphere/source/mem/impl/heap/mem_impl_heap_tls_heap_central.hpp b/libraries/libstratosphere/source/mem/impl/heap/mem_impl_heap_tls_heap_central.hpp index 327e029b0..656b942d5 100644 --- a/libraries/libstratosphere/source/mem/impl/heap/mem_impl_heap_tls_heap_central.hpp +++ b/libraries/libstratosphere/source/mem/impl/heap/mem_impl_heap_tls_heap_central.hpp @@ -201,14 +201,14 @@ namespace ams::mem::impl::heap { s32 static_thread_quota; s32 dynamic_thread_quota; bool use_virtual_memory; - os::Mutex lock; + os::SdkRecursiveMutex lock; ListHeader spanpage_list; ListHeader full_spanpage_list; ListHeader freelists[FreeListCount]; FreeListAvailableWord freelists_bitmap[NumFreeListBitmaps]; ListHeader smallmem_lists[TlsHeapStatic::NumClassInfo]; public: - TlsHeapCentral() : lock(true) { + TlsHeapCentral() : lock() { this->span_table.total_pages = 0; } diff --git a/libraries/libstratosphere/source/ncm/ncm_install_task_base.cpp b/libraries/libstratosphere/source/ncm/ncm_install_task_base.cpp index f9a56b6a8..8f23ff1fc 100644 --- a/libraries/libstratosphere/source/ncm/ncm_install_task_base.cpp +++ b/libraries/libstratosphere/source/ncm/ncm_install_task_base.cpp @@ -635,7 +635,7 @@ namespace ams::ncm { for (s32 i = 0; i < count; i++) { R_UNLESS(!this->IsCancelRequested(), ncm::ResultCreatePlaceHolderCancelled()); - static os::Mutex s_placeholder_mutex(false); + static constinit os::SdkMutex s_placeholder_mutex; std::scoped_lock lk(s_placeholder_mutex); InstallContentMeta content_meta; diff --git a/libraries/libstratosphere/source/ncm/ncm_placeholder_accessor.hpp b/libraries/libstratosphere/source/ncm/ncm_placeholder_accessor.hpp index 1d8084451..72368649e 100644 --- a/libraries/libstratosphere/source/ncm/ncm_placeholder_accessor.hpp +++ b/libraries/libstratosphere/source/ncm/ncm_placeholder_accessor.hpp @@ -32,7 +32,7 @@ namespace ams::ncm { std::array caches; PathString *root_path; u64 cur_counter; - os::Mutex cache_mutex; + os::SdkMutex cache_mutex; MakePlaceHolderPathFunction make_placeholder_path_func; bool delay_flush; private: @@ -43,7 +43,7 @@ namespace ams::ncm { CacheEntry *FindInCache(PlaceHolderId placeholder_id); CacheEntry *GetFreeEntry();; public: - PlaceHolderAccessor() : cur_counter(0), cache_mutex(false), delay_flush(false) { + PlaceHolderAccessor() : cur_counter(0), cache_mutex(), delay_flush(false) { for (size_t i = 0; i < MaxCacheEntries; i++) { caches[i].id = InvalidPlaceHolderId; } diff --git a/libraries/libstratosphere/source/patcher/patcher_api.cpp b/libraries/libstratosphere/source/patcher/patcher_api.cpp index 177b80d94..bc8270862 100644 --- a/libraries/libstratosphere/source/patcher/patcher_api.cpp +++ b/libraries/libstratosphere/source/patcher/patcher_api.cpp @@ -31,8 +31,8 @@ namespace ams::patcher { constexpr size_t ModuleIpsPatchLength = 2 * sizeof(ro::ModuleId) + IpsFileExtensionLength; /* Global data. */ - os::Mutex apply_patch_lock(false); - u8 g_patch_read_buffer[os::MemoryPageSize]; + constinit os::SdkMutex g_apply_patch_lock; + constinit u8 g_patch_read_buffer[os::MemoryPageSize]; /* Helpers. */ inline u8 ConvertHexNybble(const char nybble) { @@ -213,7 +213,7 @@ namespace ams::patcher { void LocateAndApplyIpsPatchesToModule(const char *mount_name, const char *patch_dir_name, size_t protected_size, size_t offset, const ro::ModuleId *module_id, u8 *mapped_module, size_t mapped_size) { /* Ensure only one thread tries to apply patches at a time. */ - std::scoped_lock lk(apply_patch_lock); + std::scoped_lock lk(g_apply_patch_lock); /* Inspect all patches from /atmosphere//<*>/<*>.ips */ char path[fs::EntryNameLengthMax + 1]; diff --git a/libraries/libstratosphere/source/sf/cmif/sf_cmif_domain_manager.cpp b/libraries/libstratosphere/source/sf/cmif/sf_cmif_domain_manager.cpp index 7c16a9624..ec310babb 100644 --- a/libraries/libstratosphere/source/sf/cmif/sf_cmif_domain_manager.cpp +++ b/libraries/libstratosphere/source/sf/cmif/sf_cmif_domain_manager.cpp @@ -106,7 +106,7 @@ namespace ams::sf::cmif { return entry->object.Clone(); } - ServerDomainManager::EntryManager::EntryManager(DomainEntryStorage *entry_storage, size_t entry_count) : lock(false) { + ServerDomainManager::EntryManager::EntryManager(DomainEntryStorage *entry_storage, size_t entry_count) : lock() { this->entries = reinterpret_cast(entry_storage); this->num_entries = entry_count; for (size_t i = 0; i < this->num_entries; i++) { diff --git a/libraries/libstratosphere/source/sm/sm_utils.cpp b/libraries/libstratosphere/source/sm/sm_utils.cpp index f241e79e2..57dc2383d 100644 --- a/libraries/libstratosphere/source/sm/sm_utils.cpp +++ b/libraries/libstratosphere/source/sm/sm_utils.cpp @@ -21,17 +21,17 @@ namespace ams::sm::impl { namespace { /* Globals. */ - constinit os::Mutex g_mitm_ack_session_mutex(true); - constinit os::Mutex g_per_thread_session_mutex(true); + constinit os::SdkRecursiveMutex g_mitm_ack_session_mutex; + constinit os::SdkRecursiveMutex g_per_thread_session_mutex; } /* Utilities. */ - os::Mutex &GetMitmAcknowledgementSessionMutex() { + os::SdkRecursiveMutex &GetMitmAcknowledgementSessionMutex() { return g_mitm_ack_session_mutex; } - os::Mutex &GetPerThreadSessionMutex() { + os::SdkRecursiveMutex &GetPerThreadSessionMutex() { return g_per_thread_session_mutex; } diff --git a/libraries/libstratosphere/source/sm/sm_utils.hpp b/libraries/libstratosphere/source/sm/sm_utils.hpp index f8926c619..ed1cd1321 100644 --- a/libraries/libstratosphere/source/sm/sm_utils.hpp +++ b/libraries/libstratosphere/source/sm/sm_utils.hpp @@ -21,8 +21,8 @@ namespace ams::sm::impl { /* Utilities. */ - os::Mutex &GetMitmAcknowledgementSessionMutex(); - os::Mutex &GetPerThreadSessionMutex(); + os::SdkRecursiveMutex &GetMitmAcknowledgementSessionMutex(); + os::SdkRecursiveMutex &GetPerThreadSessionMutex(); template Result DoWithMitmAcknowledgementSession(F f) { diff --git a/libraries/libvapours/source/sdmmc/impl/sdmmc_base_device_accessor.hpp b/libraries/libvapours/source/sdmmc/impl/sdmmc_base_device_accessor.hpp index 8cb0490e8..5e8886745 100644 --- a/libraries/libvapours/source/sdmmc/impl/sdmmc_base_device_accessor.hpp +++ b/libraries/libvapours/source/sdmmc/impl/sdmmc_base_device_accessor.hpp @@ -214,9 +214,9 @@ namespace ams::sdmmc::impl { bool is_awake; public: #if defined(AMS_SDMMC_THREAD_SAFE) - mutable os::Mutex device_mutex; + mutable os::SdkRecursiveMutex device_mutex; public: - BaseDevice() : device_mutex(true) + BaseDevice() : device_mutex() #else BaseDevice() #endif diff --git a/stratosphere/ams_mitm/source/amsmitm_prodinfo_utils.cpp b/stratosphere/ams_mitm/source/amsmitm_prodinfo_utils.cpp index 9d7710664..04e1dce6d 100644 --- a/stratosphere/ams_mitm/source/amsmitm_prodinfo_utils.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_prodinfo_utils.cpp @@ -501,18 +501,18 @@ namespace ams::mitm { crypto::EncryptAes128Ctr(dst, dst_size, entropy.data, crypto::Aes128CtrEncryptor::KeySize, entropy.data + crypto::Aes128CtrEncryptor::KeySize, crypto::Aes128CtrEncryptor::IvSize, dst, dst_size); } - alignas(os::MemoryPageSize) CalibrationInfo g_calibration_info = {}; - alignas(os::MemoryPageSize) CalibrationInfo g_blank_calibration_info = {}; - alignas(os::MemoryPageSize) SecureCalibrationInfoBackup g_secure_calibration_info_backup = {}; + alignas(os::MemoryPageSize) constinit CalibrationInfo g_calibration_info = {}; + alignas(os::MemoryPageSize) constinit CalibrationInfo g_blank_calibration_info = {}; + alignas(os::MemoryPageSize) constinit SecureCalibrationInfoBackup g_secure_calibration_info_backup = {}; - util::optional g_prodinfo_backup_file; - util::optional g_blank_prodinfo_storage; - util::optional g_fake_secure_backup_storage; + constinit util::optional g_prodinfo_backup_file; + constinit util::optional g_blank_prodinfo_storage; + constinit util::optional g_fake_secure_backup_storage; - bool g_allow_writes = false; - bool g_has_secure_backup = false; + constinit bool g_allow_writes = false; + constinit bool g_has_secure_backup = false; - os::Mutex g_prodinfo_management_lock(false); + constinit os::SdkMutex g_prodinfo_management_lock; } diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_calibration_binary_storage.cpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_calibration_binary_storage.cpp index 0f1bee112..0905c3046 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_calibration_binary_storage.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_calibration_binary_storage.cpp @@ -22,7 +22,7 @@ namespace ams::mitm::fs { namespace { - os::Mutex g_cal0_access_mutex(false); + constinit os::SdkMutex g_cal0_access_mutex; } Result CalibrationBinaryStorage::Read(s64 offset, void *_buffer, size_t size) { diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_layered_romfs_storage.cpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_layered_romfs_storage.cpp index c959e2f96..669e06923 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_layered_romfs_storage.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_layered_romfs_storage.cpp @@ -22,9 +22,9 @@ namespace ams::mitm::fs { namespace { - os::Mutex g_mq_lock(false); - bool g_started_req_thread; - uintptr_t g_mq_storage[2]; + constinit os::SdkMutex g_mq_lock; + constinit bool g_started_req_thread; + constinit uintptr_t g_mq_storage[2]; os::MessageQueue g_req_mq(g_mq_storage + 0, 1); os::MessageQueue g_ack_mq(g_mq_storage + 1, 1); diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.cpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.cpp index 9c2c2be8b..204430d98 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_romfs.cpp @@ -258,8 +258,8 @@ namespace ams::mitm::fs { } } - os::Mutex g_fs_romfs_path_lock(false); - char g_fs_romfs_path_buffer[fs::EntryNameLengthMax + 1]; + constinit os::SdkMutex g_fs_romfs_path_lock; + constinit char g_fs_romfs_path_buffer[fs::EntryNameLengthMax + 1]; NOINLINE void OpenFileSystemRomfsDirectory(FsDir *out, ncm::ProgramId program_id, BuildDirectoryContext *parent, fs::OpenDirectoryMode mode, FsFileSystem *fs) { std::scoped_lock lk(g_fs_romfs_path_lock); diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp index 1f10c4449..dffb43b1b 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp @@ -23,15 +23,19 @@ namespace ams::mitm::settings { namespace { - os::Mutex g_firmware_version_lock(false); - bool g_cached_firmware_version; - settings::FirmwareVersion g_firmware_version; - settings::FirmwareVersion g_ams_firmware_version; + constinit os::SdkMutex g_firmware_version_lock; + constinit bool g_cached_firmware_version; + constinit settings::FirmwareVersion g_firmware_version; + constinit settings::FirmwareVersion g_ams_firmware_version; void CacheFirmwareVersion() { + if (AMS_LIKELY(g_cached_firmware_version)) { + return; + } + std::scoped_lock lk(g_firmware_version_lock); - if (AMS_LIKELY(g_cached_firmware_version)) { + if (AMS_UNLIKELY(g_cached_firmware_version)) { return; } diff --git a/stratosphere/ams_mitm/source/sysupdater/sysupdater_apply_manager.hpp b/stratosphere/ams_mitm/source/sysupdater/sysupdater_apply_manager.hpp index d05bad8c4..4c7a4d8a7 100644 --- a/stratosphere/ams_mitm/source/sysupdater/sysupdater_apply_manager.hpp +++ b/stratosphere/ams_mitm/source/sysupdater/sysupdater_apply_manager.hpp @@ -20,9 +20,9 @@ namespace ams::mitm::sysupdater { class SystemUpdateApplyManager { private: - os::Mutex apply_mutex; + os::SdkMutex apply_mutex; public: - constexpr SystemUpdateApplyManager() : apply_mutex(false) { /* ... */ } + constexpr SystemUpdateApplyManager() : apply_mutex() { /* ... */ } Result ApplyPackageTask(ncm::PackageSystemDowngradeTask *task); }; diff --git a/stratosphere/creport/source/creport_scoped_file.cpp b/stratosphere/creport/source/creport_scoped_file.cpp index 1ab3fb26a..93b45804e 100644 --- a/stratosphere/creport/source/creport_scoped_file.cpp +++ b/stratosphere/creport/source/creport_scoped_file.cpp @@ -23,8 +23,8 @@ namespace ams::creport { /* Convenience definitions. */ constexpr size_t MaximumLineLength = 0x20; - os::Mutex g_format_lock(false); - char g_format_buffer[2 * os::MemoryPageSize]; + constinit os::SdkMutex g_format_lock; + constinit char g_format_buffer[2 * os::MemoryPageSize]; } diff --git a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp index 832ebc0ac..702901ca5 100644 --- a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp +++ b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp @@ -83,7 +83,7 @@ namespace ams::dmnt::cheat::impl { private: static constexpr size_t ThreadStackSize = 0x4000; private: - os::Mutex cheat_lock; + os::SdkMutex cheat_lock; os::Event unsafe_break_event; os::Event debug_events_event; /* Autoclear. */ os::ThreadType detect_thread, debug_events_thread; @@ -250,7 +250,7 @@ namespace ams::dmnt::cheat::impl { } public: - CheatProcessManager() : cheat_lock(false), unsafe_break_event(os::EventClearMode_ManualClear), debug_events_event(os::EventClearMode_AutoClear), cheat_process_event(os::EventClearMode_AutoClear, true) { + CheatProcessManager() : cheat_lock(), unsafe_break_event(os::EventClearMode_ManualClear), debug_events_event(os::EventClearMode_AutoClear), cheat_process_event(os::EventClearMode_AutoClear, true) { /* Learn whether we should enable cheats by default. */ { u8 en = 0; diff --git a/stratosphere/dmnt/source/dmnt_main.cpp b/stratosphere/dmnt/source/dmnt_main.cpp index 881b5cf2b..48b1c98aa 100644 --- a/stratosphere/dmnt/source/dmnt_main.cpp +++ b/stratosphere/dmnt/source/dmnt_main.cpp @@ -14,7 +14,6 @@ * along with this program. If not, see . */ #include -#include "dmnt_service.hpp" #include "cheat/dmnt_cheat_service.hpp" #include "cheat/impl/dmnt_cheat_api.hpp" @@ -189,8 +188,6 @@ int main(int argc, char **argv) ams::dmnt::cheat::impl::InitializeCheatManager(); /* Create services. */ - /* TODO: Implement rest of dmnt:- in ams.tma development branch. */ - /* TODO: register debug service */ R_ABORT_UNLESS(g_server_manager.RegisterObjectForServer(g_cheat_service.GetShared(), CheatServiceName, CheatMaxSessions)); /* Loop forever, servicing our services. */ diff --git a/stratosphere/dmnt/source/dmnt_service.hpp b/stratosphere/dmnt/source/dmnt_service.hpp deleted file mode 100644 index 8372f6241..000000000 --- a/stratosphere/dmnt/source/dmnt_service.hpp +++ /dev/null @@ -1,137 +0,0 @@ -/* - * 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 - -namespace ams::dmnt { - - /* TODO: Move into libstratosphere, eventually. */ - struct TargetIOFileHandle : sf::LargeData, sf::PrefersMapAliasTransferMode { - u64 value; - - constexpr u64 GetValue() const { - return this->value; - } - - constexpr explicit operator u64() const { - return this->value; - } - - inline constexpr bool operator==(const TargetIOFileHandle &rhs) const { - return this->value == rhs.value; - } - - inline constexpr bool operator!=(const TargetIOFileHandle &rhs) const { - return this->value != rhs.value; - } - - inline constexpr bool operator<(const TargetIOFileHandle &rhs) const { - return this->value < rhs.value; - } - - inline constexpr bool operator<=(const TargetIOFileHandle &rhs) const { - return this->value <= rhs.value; - } - - inline constexpr bool operator>(const TargetIOFileHandle &rhs) const { - return this->value > rhs.value; - } - - inline constexpr bool operator>=(const TargetIOFileHandle &rhs) const { - return this->value >= rhs.value; - } - }; - - static_assert(util::is_pod::value && sizeof(TargetIOFileHandle) == sizeof(u64), "TargetIOFileHandle"); - - /* TODO: Convert to new sf format in the future. */ - class DebugMonitorService final { - private: - enum class CommandId { - BreakDebugProcess = 0, - TerminateDebugProcess = 1, - CloseHandle = 2, - LoadImage = 3, - GetProcessId = 4, - GetProcessHandle = 5, - WaitSynchronization = 6, - GetDebugEvent = 7, - GetProcessModuleInfo = 8, - GetProcessList = 9, - GetThreadList = 10, - GetDebugThreadContext = 11, - ContinueDebugEvent = 12, - ReadDebugProcessMemory = 13, - WriteDebugProcessMemory = 14, - SetDebugThreadContext = 15, - GetDebugThreadParam = 16, - InitializeThreadInfo = 17, - SetHardwareBreakPoint = 18, - QueryDebugProcessMemory = 19, - GetProcessMemoryDetails = 20, - AttachByProgramId = 21, - AttachOnLaunch = 22, - GetDebugMonitorProcessId = 23, - GetJitDebugProcessList = 25, - CreateCoreDump = 26, - GetAllDebugThreadInfo = 27, - TargetIO_FileOpen = 29, - TargetIO_FileClose = 30, - TargetIO_FileRead = 31, - TargetIO_FileWrite = 32, - TargetIO_FileSetAttributes = 33, - TargetIO_FileGetInformation = 34, - TargetIO_FileSetTime = 35, - TargetIO_FileSetSize = 36, - TargetIO_FileDelete = 37, - TargetIO_FileMove = 38, - TargetIO_DirectoryCreate = 39, - TargetIO_DirectoryDelete = 40, - TargetIO_DirectoryRename = 41, - TargetIO_DirectoryGetCount = 42, - TargetIO_DirectoryOpen = 43, - TargetIO_DirectoryGetNext = 44, - TargetIO_DirectoryClose = 45, - TargetIO_GetFreeSpace = 46, - TargetIO_GetVolumeInformation = 47, - InitiateCoreDump = 48, - ContinueCoreDump = 49, - AddTTYToCoreDump = 50, - AddImageToCoreDump = 51, - CloseCoreDump = 52, - CancelAttach = 53, - }; - private: - Result BreakDebugProcess(Handle debug_hnd); - Result TerminateDebugProcess(Handle debug_hnd); - Result CloseHandle(Handle debug_hnd); - Result GetProcessId(sf::Out out_pid, Handle hnd); - Result GetProcessHandle(sf::Out out_hnd, os::ProcessId pid); - Result WaitSynchronization(Handle hnd, u64 ns); - - Result TargetIO_FileOpen(sf::Out out_hnd, const sf::InBuffer &path, int open_mode, u32 create_mode); - Result TargetIO_FileClose(TargetIOFileHandle hnd); - Result TargetIO_FileRead(TargetIOFileHandle hnd, const sf::OutNonSecureBuffer &out_data, sf::Out out_read, s64 offset); - Result TargetIO_FileWrite(TargetIOFileHandle hnd, const sf::InNonSecureBuffer &data, sf::Out out_written, s64 offset); - Result TargetIO_FileSetAttributes(const sf::InBuffer &path, const sf::InBuffer &attributes); - Result TargetIO_FileGetInformation(const sf::InBuffer &path, const sf::OutArray &out_info, sf::Out is_directory); - Result TargetIO_FileSetTime(const sf::InBuffer &path, u64 create, u64 access, u64 modify); - Result TargetIO_FileSetSize(const sf::InBuffer &input, s64 size); - Result TargetIO_FileDelete(const sf::InBuffer &path); - Result TargetIO_FileMove(const sf::InBuffer &src_path, const sf::InBuffer &dst_path); - }; - -} diff --git a/stratosphere/dmnt/source/dmnt_service_debug.cpp b/stratosphere/dmnt/source/dmnt_service_debug.cpp deleted file mode 100644 index 06a5e7351..000000000 --- a/stratosphere/dmnt/source/dmnt_service_debug.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 . - */ -#include -#include "dmnt_service.hpp" - -namespace ams::dmnt { - - Result DebugMonitorService::BreakDebugProcess(Handle debug_hnd) { - /* Nintendo discards the output of this command, but we will return it. */ - return svcBreakDebugProcess(debug_hnd); - } - - Result DebugMonitorService::TerminateDebugProcess(Handle debug_hnd) { - /* Nintendo discards the output of this command, but we will return it. */ - return svcTerminateDebugProcess(debug_hnd); - } - - Result DebugMonitorService::CloseHandle(Handle debug_hnd) { - /* Nintendo discards the output of this command, but we will return it. */ - /* This command is, entertainingly, also pretty unsafe in general... */ - return svcCloseHandle(debug_hnd); - } - - Result DebugMonitorService::GetProcessId(sf::Out out_pid, Handle hnd) { - /* Nintendo discards the output of this command, but we will return it. */ - return os::TryGetProcessId(out_pid.GetPointer(), hnd); - } - - Result DebugMonitorService::GetProcessHandle(sf::Out out_hnd, os::ProcessId pid) { - R_TRY_CATCH(svcDebugActiveProcess(out_hnd.GetPointer(), static_cast(pid))) { - R_CONVERT(svc::ResultBusy, dbg::ResultAlreadyAttached()); - } R_END_TRY_CATCH; - - return ResultSuccess(); - } - - Result DebugMonitorService::WaitSynchronization(Handle hnd, u64 ns) { - /* Nintendo discards the output of this command, but we will return it. */ - return svcWaitSynchronizationSingle(hnd, ns); - } - -} diff --git a/stratosphere/dmnt/source/dmnt_service_target_io.cpp b/stratosphere/dmnt/source/dmnt_service_target_io.cpp deleted file mode 100644 index b4ecb1d62..000000000 --- a/stratosphere/dmnt/source/dmnt_service_target_io.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/* - * 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 . - */ -#include -#include "dmnt_service.hpp" - -namespace std { - - template<> - struct hash { - u64 operator()(ams::dmnt::TargetIOFileHandle const &handle) const noexcept { - return handle.GetValue(); - } - }; - -} - -namespace ams::dmnt { - - namespace { - - enum TIOCreateOption : u32 { - TIOCreateOption_CreateNew = 1, - TIOCreateOption_CreateAlways = 2, - TIOCreateOption_OpenExisting = 3, - TIOCreateOption_OpenAlways = 4, - TIOCreateOption_ResetSize = 5, - }; - - /* Nintendo uses actual pointers as file handles. We'll add a layer of indirection... */ - bool g_sd_initialized = false; - os::Mutex g_sd_lock(false); - FsFileSystem g_sd_fs; - - os::Mutex g_file_handle_lock(false); - u64 g_cur_fd; - std::unordered_map g_file_handles; - - Result EnsureSdInitialized() { - std::scoped_lock lk(g_sd_lock); - R_SUCCEED_IF(g_sd_initialized); - - R_TRY(fsOpenSdCardFileSystem(&g_sd_fs)); - g_sd_initialized = true; - return ResultSuccess(); - } - - TargetIOFileHandle GetNewFileHandle(FsFile f) { - std::scoped_lock lk(g_file_handle_lock); - - TargetIOFileHandle fd = { .value = g_cur_fd++ }; - g_file_handles[fd] = f; - return fd; - } - - Result GetFileByHandle(FsFile *out, TargetIOFileHandle handle) { - std::scoped_lock lk(g_file_handle_lock); - - if (g_file_handles.find(handle) != g_file_handles.end()) { - *out = g_file_handles[handle]; - return ResultSuccess(); - } - - return fs::ResultInvalidArgument(); - } - - Result CloseFileByHandle(TargetIOFileHandle handle) { - std::scoped_lock lk(g_file_handle_lock); - - if (g_file_handles.find(handle) != g_file_handles.end()) { - fsFileClose(&g_file_handles[handle]); - g_file_handles.erase(handle); - return ResultSuccess(); - } - - return fs::ResultInvalidArgument(); - } - - void FixPath(char *dst, size_t dst_size, const sf::InBuffer &path) { - dst[dst_size - 1] = 0; - strncpy(dst, "/", dst_size - 1); - - const char *src = reinterpret_cast(path.GetPointer()); - size_t src_idx = 0; - size_t dst_idx = 1; - while (src_idx < path.GetSize() && (src[src_idx] == '/' || src[src_idx] == '\\')) { - src_idx++; - } - - while (src_idx < path.GetSize() && dst_idx < dst_size - 1 && src[src_idx] != 0) { - if (src[src_idx] == '\\') { - dst[dst_idx] = '/'; - } else { - dst[dst_idx] = src[src_idx]; - } - - src_idx++; - dst_idx++; - } - - if (dst_idx < dst_size) { - dst[dst_idx] = 0; - } - } - - } - - Result DebugMonitorService::TargetIO_FileOpen(sf::Out out_hnd, const sf::InBuffer &path, int open_mode, u32 create_mode) { - R_TRY(EnsureSdInitialized()); - - char fs_path[FS_MAX_PATH]; - FixPath(fs_path, sizeof(fs_path), path); - - /* Create file as required by mode. */ - if (create_mode == TIOCreateOption_CreateAlways) { - fsFsDeleteFile(&g_sd_fs, fs_path); - R_TRY(fsFsCreateFile(&g_sd_fs, fs_path, 0, 0)); - } else if (create_mode == TIOCreateOption_CreateNew) { - R_TRY(fsFsCreateFile(&g_sd_fs, fs_path, 0, 0)); - } else if (create_mode == TIOCreateOption_OpenAlways) { - fsFsCreateFile(&g_sd_fs, fs_path, 0, 0); - } - - /* Open the file, guard to prevent failure to close. */ - FsFile f; - R_TRY(fsFsOpenFile(&g_sd_fs, fs_path, open_mode, &f)); - auto file_guard = SCOPE_GUARD { fsFileClose(&f); }; - - /* Set size if needed. */ - if (create_mode == TIOCreateOption_ResetSize) { - R_TRY(fsFileSetSize(&f, 0)); - } - - /* Cancel guard, output file handle. */ - file_guard.Cancel(); - out_hnd.SetValue(GetNewFileHandle(f)); - - return ResultSuccess(); - } - - Result DebugMonitorService::TargetIO_FileClose(TargetIOFileHandle hnd) { - return CloseFileByHandle(hnd); - } - - Result DebugMonitorService::TargetIO_FileRead(TargetIOFileHandle hnd, const sf::OutNonSecureBuffer &out_data, sf::Out out_read, s64 offset) { - FsFile f; - size_t read = 0; - - R_TRY(GetFileByHandle(&f, hnd)); - R_TRY(fsFileRead(&f, offset, out_data.GetPointer(), out_data.GetSize(), FsReadOption_None, &read)); - - out_read.SetValue(static_cast(read)); - return ResultSuccess(); - } - - Result DebugMonitorService::TargetIO_FileWrite(TargetIOFileHandle hnd, const sf::InNonSecureBuffer &data, sf::Out out_written, s64 offset) { - FsFile f; - - R_TRY(GetFileByHandle(&f, hnd)); - R_TRY(fsFileWrite(&f, offset, data.GetPointer(), data.GetSize(), FsWriteOption_None)); - - out_written.SetValue(data.GetSize()); - return ResultSuccess(); - } - - Result DebugMonitorService::TargetIO_FileSetAttributes(const sf::InBuffer &path, const sf::InBuffer &attributes) { - /* I don't really know why this command exists, Horizon doesn't allow you to set any attributes. */ - /* N just returns ResultSuccess unconditionally here. */ - return ResultSuccess(); - } - - Result DebugMonitorService::TargetIO_FileGetInformation(const sf::InBuffer &path, const sf::OutArray &out_info, sf::Out is_directory) { - R_TRY(EnsureSdInitialized()); - - char fs_path[FS_MAX_PATH]; - FixPath(fs_path, sizeof(fs_path), path); - - for (size_t i = 0; i < out_info.GetSize(); i++) { - out_info[i] = 0; - } - is_directory.SetValue(0); - - FsFile f; - if (R_SUCCEEDED(fsFsOpenFile(&g_sd_fs, fs_path, FsOpenMode_Read, &f))) { - ON_SCOPE_EXIT { fsFileClose(&f); }; - - /* N doesn't check this return code. */ - if (out_info.GetSize() > 0) { - fsFileGetSize(&f, reinterpret_cast(&out_info[0])); - } - - /* TODO: N does not call fsFsGetFileTimestampRaw here, but we possibly could. */ - } else { - FsDir dir; - R_TRY(fsFsOpenDirectory(&g_sd_fs, fs_path, FsDirOpenMode_ReadFiles | FsDirOpenMode_ReadDirs, &dir)); - fsDirClose(&dir); - is_directory.SetValue(1); - } - - return ResultSuccess(); - } - - Result DebugMonitorService::TargetIO_FileSetTime(const sf::InBuffer &path, u64 create, u64 access, u64 modify) { - /* This is another function that doesn't really need to exist, because Horizon doesn't let you set anything. */ - return ResultSuccess(); - } - - Result DebugMonitorService::TargetIO_FileSetSize(const sf::InBuffer &input, s64 size) { - /* Why does this function take in a path and not a file handle? */ - R_TRY(EnsureSdInitialized()); - - /* We will try to be better than N, here. N only treats input as a path. */ - FsFile f; - if (input.GetSize() == sizeof(TargetIOFileHandle)) { - R_UNLESS(R_FAILED(GetFileByHandle(&f, *reinterpret_cast(input.GetPointer()))), fsFileSetSize(&f, size)); - } - - char fs_path[FS_MAX_PATH]; - FixPath(fs_path, sizeof(fs_path), input); - - R_TRY(fsFsOpenFile(&g_sd_fs, fs_path, FsOpenMode_Write, &f)); - ON_SCOPE_EXIT { fsFileClose(&f); }; - - return fsFileSetSize(&f, size); - } - - Result DebugMonitorService::TargetIO_FileDelete(const sf::InBuffer &path) { - R_TRY(EnsureSdInitialized()); - - char fs_path[FS_MAX_PATH]; - FixPath(fs_path, sizeof(fs_path), path); - - return fsFsDeleteFile(&g_sd_fs, fs_path); - } - - Result DebugMonitorService::TargetIO_FileMove(const sf::InBuffer &src_path, const sf::InBuffer &dst_path) { - R_TRY(EnsureSdInitialized()); - - char fs_src_path[FS_MAX_PATH]; - char fs_dst_path[FS_MAX_PATH]; - FixPath(fs_src_path, sizeof(fs_src_path), src_path); - FixPath(fs_dst_path, sizeof(fs_dst_path), dst_path); - - return fsFsRenameFile(&g_sd_fs, fs_src_path, fs_dst_path); - } - -} diff --git a/stratosphere/fatal/source/fatal_event_manager.cpp b/stratosphere/fatal/source/fatal_event_manager.cpp index 8a8cbb2f3..f3b069218 100644 --- a/stratosphere/fatal/source/fatal_event_manager.cpp +++ b/stratosphere/fatal/source/fatal_event_manager.cpp @@ -18,7 +18,7 @@ namespace ams::fatal::srv { - FatalEventManager::FatalEventManager() : lock(false) { + FatalEventManager::FatalEventManager() : lock() { /* Just create all the events. */ for (size_t i = 0; i < FatalEventManager::NumFatalEvents; i++) { R_ABORT_UNLESS(os::CreateSystemEvent(std::addressof(this->events[i]), os::EventClearMode_AutoClear, true)); diff --git a/stratosphere/fatal/source/fatal_event_manager.hpp b/stratosphere/fatal/source/fatal_event_manager.hpp index 9225aa599..9265cb30a 100644 --- a/stratosphere/fatal/source/fatal_event_manager.hpp +++ b/stratosphere/fatal/source/fatal_event_manager.hpp @@ -24,7 +24,7 @@ namespace ams::fatal::srv { public: static constexpr size_t NumFatalEvents = 3; private: - os::Mutex lock; + os::SdkMutex lock; size_t num_events_gotten = 0; os::SystemEventType events[NumFatalEvents]; public: diff --git a/stratosphere/fatal/source/fatal_scoped_file.cpp b/stratosphere/fatal/source/fatal_scoped_file.cpp index 50b82e263..7c1c5975a 100644 --- a/stratosphere/fatal/source/fatal_scoped_file.cpp +++ b/stratosphere/fatal/source/fatal_scoped_file.cpp @@ -23,8 +23,8 @@ namespace ams::fatal::srv { /* Convenience definitions. */ constexpr size_t MaximumLineLength = 0x20; - os::Mutex g_format_lock(false); - char g_format_buffer[2 * os::MemoryPageSize]; + constinit os::SdkMutex g_format_lock; + constinit char g_format_buffer[2 * os::MemoryPageSize]; } diff --git a/stratosphere/loader/source/ldr_content_management.cpp b/stratosphere/loader/source/ldr_content_management.cpp index ae3df8d5e..ec780e194 100644 --- a/stratosphere/loader/source/ldr_content_management.cpp +++ b/stratosphere/loader/source/ldr_content_management.cpp @@ -20,7 +20,7 @@ namespace ams::ldr { namespace { - os::Mutex g_scoped_code_mount_lock(false); + constinit os::SdkMutex g_scoped_code_mount_lock; } diff --git a/stratosphere/loader/source/ldr_content_management.hpp b/stratosphere/loader/source/ldr_content_management.hpp index c06ce220c..b39b7d0e6 100644 --- a/stratosphere/loader/source/ldr_content_management.hpp +++ b/stratosphere/loader/source/ldr_content_management.hpp @@ -23,7 +23,7 @@ namespace ams::ldr { NON_COPYABLE(ScopedCodeMount); NON_MOVEABLE(ScopedCodeMount); private: - std::scoped_lock lk; + std::scoped_lock lk; cfg::OverrideStatus override_status; fs::CodeVerificationData ams_code_verification_data; fs::CodeVerificationData sd_or_base_code_verification_data; diff --git a/stratosphere/pm/source/impl/pm_process_info.hpp b/stratosphere/pm/source/impl/pm_process_info.hpp index 8d4ae637a..5c3d53618 100644 --- a/stratosphere/pm/source/impl/pm_process_info.hpp +++ b/stratosphere/pm/source/impl/pm_process_info.hpp @@ -167,9 +167,9 @@ namespace ams::pm::impl { class ProcessList final : public util::IntrusiveListMemberTraits<&ProcessInfo::list_node>::ListType { private: - os::Mutex lock; + os::SdkMutex lock; public: - constexpr ProcessList() : lock(false) { /* ... */ } + constexpr ProcessList() : lock() { /* ... */ } void Lock() { this->lock.Lock(); diff --git a/stratosphere/pm/source/impl/pm_process_manager.cpp b/stratosphere/pm/source/impl/pm_process_manager.cpp index 9e9c7650a..5b0a05a16 100644 --- a/stratosphere/pm/source/impl/pm_process_manager.cpp +++ b/stratosphere/pm/source/impl/pm_process_manager.cpp @@ -78,18 +78,15 @@ namespace ams::pm::impl { NON_MOVEABLE(ProcessInfoAllocator); static_assert(MaxProcessInfos >= 0x40, "MaxProcessInfos is too small."); private: - util::TypedStorage process_info_storages[MaxProcessInfos]; - bool process_info_allocated[MaxProcessInfos]; - os::Mutex lock; + util::TypedStorage process_info_storages[MaxProcessInfos]{}; + bool process_info_allocated[MaxProcessInfos]{}; + os::SdkMutex lock{}; private: constexpr inline size_t GetProcessInfoIndex(ProcessInfo *process_info) const { return process_info - GetPointer(this->process_info_storages[0]); } public: - constexpr ProcessInfoAllocator() : lock(false) { - std::memset(this->process_info_storages, 0, sizeof(this->process_info_storages)); - std::memset(this->process_info_allocated, 0, sizeof(this->process_info_allocated)); - } + constexpr ProcessInfoAllocator() = default; template ProcessInfo *AllocateProcessInfo(Args &&... args) { @@ -123,34 +120,34 @@ namespace ams::pm::impl { /* Process Tracking globals. */ void ProcessTrackingMain(void *arg); - os::ThreadType g_process_track_thread; - alignas(os::ThreadStackAlignment) u8 g_process_track_thread_stack[16_KB]; + constinit os::ThreadType g_process_track_thread; + alignas(os::ThreadStackAlignment) constinit u8 g_process_track_thread_stack[16_KB]; /* Process lists. */ - ProcessList g_process_list; - ProcessList g_dead_process_list; + constinit ProcessList g_process_list; + constinit ProcessList g_dead_process_list; /* Process Info Allocation. */ /* Note: The kernel slabheap is size 0x50 -- we allow slightly larger to account for the dead process list. */ constexpr size_t MaxProcessCount = 0x60; - ProcessInfoAllocator g_process_info_allocator; + constinit ProcessInfoAllocator g_process_info_allocator; /* Global events. */ - os::SystemEventType g_process_event; - os::SystemEventType g_hook_to_create_process_event; - os::SystemEventType g_hook_to_create_application_process_event; - os::SystemEventType g_boot_finished_event; + constinit os::SystemEventType g_process_event; + constinit os::SystemEventType g_hook_to_create_process_event; + constinit os::SystemEventType g_hook_to_create_application_process_event; + constinit os::SystemEventType g_boot_finished_event; /* Process Launch synchronization globals. */ - os::Mutex g_launch_program_lock(false); + constinit os::SdkMutex g_launch_program_lock; os::Event g_process_launch_start_event(os::EventClearMode_AutoClear); os::Event g_process_launch_finish_event(os::EventClearMode_AutoClear); - Result g_process_launch_result = ResultSuccess(); - LaunchProcessArgs g_process_launch_args = {}; + constinit Result g_process_launch_result = ResultSuccess(); + constinit LaunchProcessArgs g_process_launch_args = {}; /* Hook globals. */ - std::atomic g_program_id_hook; - std::atomic g_application_hook; + constinit std::atomic g_program_id_hook; + constinit std::atomic g_application_hook; /* Forward declarations. */ Result LaunchProcess(os::WaitableManagerType &waitable_manager, const LaunchProcessArgs &args); diff --git a/stratosphere/pm/source/impl/pm_resource_manager.cpp b/stratosphere/pm/source/impl/pm_resource_manager.cpp index 7eca4f16d..5a2c62142 100644 --- a/stratosphere/pm/source/impl/pm_resource_manager.cpp +++ b/stratosphere/pm/source/impl/pm_resource_manager.cpp @@ -44,13 +44,13 @@ namespace ams::pm::resource { constexpr size_t ExtraSystemMemorySizeAtmosphere500 = 33_MB; /* Applet pool is 0x20100000 */ /* Globals. */ - os::Mutex g_resource_limit_lock(false); - Handle g_resource_limit_handles[ResourceLimitGroup_Count]; - spl::MemoryArrangement g_memory_arrangement = spl::MemoryArrangement_Standard; - u64 g_system_memory_boost_size = 0; - u64 g_extra_application_threads_available = 0; + constinit os::SdkMutex g_resource_limit_lock; + constinit Handle g_resource_limit_handles[ResourceLimitGroup_Count]; + constinit spl::MemoryArrangement g_memory_arrangement = spl::MemoryArrangement_Standard; + constinit u64 g_system_memory_boost_size = 0; + constinit u64 g_extra_application_threads_available = 0; - u64 g_resource_limits[ResourceLimitGroup_Count][svc::LimitableResource_Count] = { + constinit u64 g_resource_limits[ResourceLimitGroup_Count][svc::LimitableResource_Count] = { [ResourceLimitGroup_System] = { [svc::LimitableResource_PhysicalMemoryMax] = 0, /* Initialized by more complicated logic later. */ [svc::LimitableResource_ThreadCountMax] = 508, @@ -74,7 +74,7 @@ namespace ams::pm::resource { }, }; - u64 g_memory_resource_limits[spl::MemoryArrangement_Count][ResourceLimitGroup_Count] = { + constinit u64 g_memory_resource_limits[spl::MemoryArrangement_Count][ResourceLimitGroup_Count] = { [spl::MemoryArrangement_Standard] = { [ResourceLimitGroup_System] = 269_MB, [ResourceLimitGroup_Application] = 3285_MB, diff --git a/stratosphere/sm/source/impl/sm_service_manager.cpp b/stratosphere/sm/source/impl/sm_service_manager.cpp index 4b5c7dcf7..70dd2502a 100644 --- a/stratosphere/sm/source/impl/sm_service_manager.cpp +++ b/stratosphere/sm/source/impl/sm_service_manager.cpp @@ -145,7 +145,7 @@ namespace ams::sm::impl { /* any kind of mutual exclusivity when accessing (and modifying) global state. Previously, this was */ /* not a problem, because sm was strictly single-threaded, and so two threads could not race eachother. */ /* We will add a mutex (and perform locking) in order to prevent simultaneous access to global state. */ - constinit os::Mutex g_mutex{true}; + constinit os::SdkRecursiveMutex g_mutex; constinit std::array g_process_list = [] { std::array list = {}; diff --git a/stratosphere/spl/source/spl_api_impl.cpp b/stratosphere/spl/source/spl_api_impl.cpp index 0d3426ba5..dbc8343dd 100644 --- a/stratosphere/spl/source/spl_api_impl.cpp +++ b/stratosphere/spl/source/spl_api_impl.cpp @@ -41,8 +41,8 @@ namespace ams::spl::impl { constexpr s32 MaxVirtualAesKeySlots = 9; /* KeySlot management. */ - KeySlotCache g_keyslot_cache; - util::optional g_keyslot_cache_entry[MaxPhysicalAesKeySlots]; + constinit KeySlotCache g_keyslot_cache; + constinit util::optional g_keyslot_cache_entry[MaxPhysicalAesKeySlots]; inline s32 GetMaxPhysicalKeySlots() { return (hos::GetVersion() >= hos::Version_6_0_0) ? MaxPhysicalAesKeySlots : MaxPhysicalAesKeySlotsDeprecated; @@ -96,9 +96,9 @@ namespace ams::spl::impl { }; }; - const void *g_keyslot_owners[MaxVirtualAesKeySlots]; - KeySlotContents g_keyslot_contents[MaxVirtualAesKeySlots]; - KeySlotContents g_physical_keyslot_contents_for_backwards_compatibility[MaxPhysicalAesKeySlots]; + constinit const void *g_keyslot_owners[MaxVirtualAesKeySlots]; + constinit KeySlotContents g_keyslot_contents[MaxVirtualAesKeySlots]; + constinit KeySlotContents g_physical_keyslot_contents_for_backwards_compatibility[MaxPhysicalAesKeySlots]; void ClearPhysicalKeySlot(s32 keyslot) { AMS_ASSERT(IsPhysicalKeySlot(keyslot)); @@ -237,18 +237,18 @@ namespace ams::spl::impl { }; /* Global variables. */ - CtrDrbg g_drbg; - os::InterruptEventType g_se_event; - os::SystemEventType g_se_keyslot_available_event; + constinit CtrDrbg g_drbg; + constinit os::InterruptEventType g_se_event; + constinit os::SystemEventType g_se_keyslot_available_event; - Handle g_se_das_hnd; - u32 g_se_mapped_work_buffer_addr; - alignas(os::MemoryPageSize) u8 g_work_buffer[2 * WorkBufferSizeMax]; + constinit Handle g_se_das_hnd; + constinit u32 g_se_mapped_work_buffer_addr; + alignas(os::MemoryPageSize) constinit u8 g_work_buffer[2 * WorkBufferSizeMax]; - os::Mutex g_async_op_lock(false); + constinit os::SdkMutex g_async_op_lock; - BootReasonValue g_boot_reason; - bool g_boot_reason_set; + constinit BootReasonValue g_boot_reason; + constinit bool g_boot_reason_set; /* Boot Reason accessors. */ BootReasonValue GetBootReason() { @@ -505,10 +505,13 @@ namespace ams::spl::impl { void Initialize() { /* Initialize the Drbg. */ InitializeCtrDrbg(); + /* Initialize SE interrupt + keyslot events. */ InitializeSeEvents(); + /* Initialize DAS for the SE. */ InitializeDeviceAddressSpace(); + /* Initialize the keyslot cache. */ InitializeKeySlotCache(); }