diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/core.cpp | 16 | ||||
-rw-r--r-- | src/core/file_sys/romfs_factory.cpp | 10 | ||||
-rw-r--r-- | src/core/file_sys/savedata_factory.cpp | 4 | ||||
-rw-r--r-- | src/core/file_sys/sdmc_factory.cpp | 2 | ||||
-rw-r--r-- | src/core/hle/kernel/k_handle_table.cpp | 1 | ||||
-rw-r--r-- | src/core/hle/kernel/k_page_table.cpp | 4 | ||||
-rw-r--r-- | src/core/hle/kernel/k_process.cpp | 11 | ||||
-rw-r--r-- | src/core/hle/kernel/kernel.cpp | 36 | ||||
-rw-r--r-- | src/core/hle/kernel/kernel.h | 8 | ||||
-rw-r--r-- | src/core/hle/kernel/svc.cpp | 6 | ||||
-rw-r--r-- | src/core/hle/result.h | 210 | ||||
-rw-r--r-- | src/core/hle/service/filesystem/filesystem.cpp | 21 | ||||
-rw-r--r-- | src/core/hle/service/glue/glue_manager.cpp | 4 | ||||
-rw-r--r-- | src/core/hle/service/ldr/ldr.cpp | 4 | ||||
-rw-r--r-- | src/core/hle/service/mii/mii_manager.cpp | 4 | ||||
-rw-r--r-- | src/core/hle/service/ns/ns.cpp | 4 | ||||
-rw-r--r-- | src/core/hle/service/sm/sm.cpp | 4 | ||||
-rw-r--r-- | src/core/hle/service/spl/spl_module.cpp | 26 | ||||
-rw-r--r-- | src/core/hle/service/vi/vi.cpp | 10 |
19 files changed, 169 insertions, 216 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp index 3c75f42ae..c3a0f9dae 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -83,12 +83,6 @@ FileSys::StorageId GetStorageIdForFrontendSlot( } } -void KProcessDeleter(Kernel::KProcess* process) { - process->Destroy(); -} - -using KProcessPtr = std::unique_ptr<Kernel::KProcess, decltype(&KProcessDeleter)>; - } // Anonymous namespace FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, @@ -261,11 +255,10 @@ struct System::Impl { } telemetry_session->AddInitialInfo(*app_loader, fs_controller, *content_provider); - main_process = KProcessPtr{Kernel::KProcess::Create(system.Kernel()), KProcessDeleter}; - ASSERT(Kernel::KProcess::Initialize(main_process.get(), system, "main", + auto main_process = Kernel::KProcess::Create(system.Kernel()); + ASSERT(Kernel::KProcess::Initialize(main_process, system, "main", Kernel::KProcess::ProcessType::Userland) .IsSuccess()); - main_process->Open(); const auto [load_result, load_parameters] = app_loader->Load(*main_process, system); if (load_result != Loader::ResultStatus::Success) { LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", load_result); @@ -275,7 +268,7 @@ struct System::Impl { static_cast<u32>(SystemResultStatus::ErrorLoader) + static_cast<u32>(load_result)); } AddGlueRegistrationForProcess(*app_loader, *main_process); - kernel.MakeCurrentProcess(main_process.get()); + kernel.MakeCurrentProcess(main_process); kernel.InitializeCores(); // Initialize cheat engine @@ -340,8 +333,6 @@ struct System::Impl { kernel.Shutdown(); memory.Reset(); applet_manager.ClearAll(); - // TODO: The main process should be freed based on KAutoObject ref counting. - main_process.reset(); LOG_DEBUG(Core, "Shutdown OK"); } @@ -403,7 +394,6 @@ struct System::Impl { std::unique_ptr<Tegra::GPU> gpu_core; std::unique_ptr<Hardware::InterruptManager> interrupt_manager; std::unique_ptr<Core::DeviceMemory> device_memory; - KProcessPtr main_process{nullptr, KProcessDeleter}; Core::Memory::Memory memory; CpuManager cpu_manager; std::atomic_bool is_powered_on{}; diff --git a/src/core/file_sys/romfs_factory.cpp b/src/core/file_sys/romfs_factory.cpp index 638c6cea8..3d9ce863b 100644 --- a/src/core/file_sys/romfs_factory.cpp +++ b/src/core/file_sys/romfs_factory.cpp @@ -39,13 +39,12 @@ void RomFSFactory::SetPackedUpdate(VirtualFile update_raw_file) { ResultVal<VirtualFile> RomFSFactory::OpenCurrentProcess(u64 current_process_title_id) const { if (!updatable) { - return MakeResult<VirtualFile>(file); + return file; } const PatchManager patch_manager{current_process_title_id, filesystem_controller, content_provider}; - return MakeResult<VirtualFile>( - patch_manager.PatchRomFS(file, ivfc_offset, ContentRecordType::Program, update_raw)); + return patch_manager.PatchRomFS(file, ivfc_offset, ContentRecordType::Program, update_raw); } ResultVal<VirtualFile> RomFSFactory::OpenPatchedRomFS(u64 title_id, ContentRecordType type) const { @@ -58,8 +57,7 @@ ResultVal<VirtualFile> RomFSFactory::OpenPatchedRomFS(u64 title_id, ContentRecor const PatchManager patch_manager{title_id, filesystem_controller, content_provider}; - return MakeResult<VirtualFile>( - patch_manager.PatchRomFS(nca->GetRomFS(), nca->GetBaseIVFCOffset(), type)); + return patch_manager.PatchRomFS(nca->GetRomFS(), nca->GetBaseIVFCOffset(), type); } ResultVal<VirtualFile> RomFSFactory::OpenPatchedRomFSWithProgramIndex( @@ -83,7 +81,7 @@ ResultVal<VirtualFile> RomFSFactory::Open(u64 title_id, StorageId storage, return ResultUnknown; } - return MakeResult<VirtualFile>(romfs); + return romfs; } std::shared_ptr<NCA> RomFSFactory::GetEntry(u64 title_id, StorageId storage, diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp index b5254dd75..0c8ec4ba2 100644 --- a/src/core/file_sys/savedata_factory.cpp +++ b/src/core/file_sys/savedata_factory.cpp @@ -94,7 +94,7 @@ ResultVal<VirtualDir> SaveDataFactory::Create(SaveDataSpaceId space, return ResultUnknown; } - return MakeResult<VirtualDir>(std::move(out)); + return out; } ResultVal<VirtualDir> SaveDataFactory::Open(SaveDataSpaceId space, @@ -115,7 +115,7 @@ ResultVal<VirtualDir> SaveDataFactory::Open(SaveDataSpaceId space, return ResultUnknown; } - return MakeResult<VirtualDir>(std::move(out)); + return out; } VirtualDir SaveDataFactory::GetSaveDataSpaceDirectory(SaveDataSpaceId space) const { diff --git a/src/core/file_sys/sdmc_factory.cpp b/src/core/file_sys/sdmc_factory.cpp index e5c72cd4d..c0e13e56f 100644 --- a/src/core/file_sys/sdmc_factory.cpp +++ b/src/core/file_sys/sdmc_factory.cpp @@ -25,7 +25,7 @@ SDMCFactory::SDMCFactory(VirtualDir sd_dir_, VirtualDir sd_mod_dir_) SDMCFactory::~SDMCFactory() = default; ResultVal<VirtualDir> SDMCFactory::Open() const { - return MakeResult<VirtualDir>(sd_dir); + return sd_dir; } VirtualDir SDMCFactory::GetSDMCModificationLoadRoot(u64 title_id) const { diff --git a/src/core/hle/kernel/k_handle_table.cpp b/src/core/hle/kernel/k_handle_table.cpp index 44d13169f..e90fc0628 100644 --- a/src/core/hle/kernel/k_handle_table.cpp +++ b/src/core/hle/kernel/k_handle_table.cpp @@ -56,6 +56,7 @@ bool KHandleTable::Remove(Handle handle) { } // Close the object. + kernel.UnregisterInUseObject(obj); obj->Close(); return true; } diff --git a/src/core/hle/kernel/k_page_table.cpp b/src/core/hle/kernel/k_page_table.cpp index 5e0b620c2..526b87241 100644 --- a/src/core/hle/kernel/k_page_table.cpp +++ b/src/core/hle/kernel/k_page_table.cpp @@ -859,7 +859,7 @@ ResultVal<VAddr> KPageTable::SetHeapSize(std::size_t size) { current_heap_addr = heap_region_start + size; } - return MakeResult<VAddr>(heap_region_start); + return heap_region_start; } ResultVal<VAddr> KPageTable::AllocateAndMapMemory(std::size_t needed_num_pages, std::size_t align, @@ -893,7 +893,7 @@ ResultVal<VAddr> KPageTable::AllocateAndMapMemory(std::size_t needed_num_pages, block_manager->Update(addr, needed_num_pages, state, perm); - return MakeResult<VAddr>(addr); + return addr; } ResultCode KPageTable::LockForDeviceAddressSpace(VAddr addr, std::size_t size) { diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp index 211157ccc..76fd8c285 100644 --- a/src/core/hle/kernel/k_process.cpp +++ b/src/core/hle/kernel/k_process.cpp @@ -434,11 +434,6 @@ void KProcess::PrepareForTermination() { } void KProcess::Finalize() { - // Release memory to the resource limit. - if (resource_limit != nullptr) { - resource_limit->Close(); - } - // Finalize the handle table and close any open handles. handle_table.Finalize(); @@ -460,6 +455,12 @@ void KProcess::Finalize() { } } + // Release memory to the resource limit. + if (resource_limit != nullptr) { + resource_limit->Close(); + resource_limit = nullptr; + } + // Perform inherited finalization. KAutoObjectWithSlabHeapAndContainer<KProcess, KSynchronizationObject>::Finalize(); } diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index bea945301..4a139c5e7 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -91,12 +91,6 @@ struct KernelCore::Impl { } void Shutdown() { - // Shutdown all processes. - if (current_process) { - current_process->Finalize(); - current_process->Close(); - current_process = nullptr; - } process_list.clear(); // Close all open server ports. @@ -170,6 +164,24 @@ struct KernelCore::Impl { // Next host thead ID to use, 0-3 IDs represent core threads, >3 represent others next_host_thread_id = Core::Hardware::NUM_CPU_CORES; + // Close kernel objects that were not freed on shutdown + { + std::lock_guard lk(registered_in_use_objects_lock); + if (registered_in_use_objects.size()) { + for (auto& object : registered_in_use_objects) { + object->Close(); + } + registered_in_use_objects.clear(); + } + } + + // Shutdown all processes. + if (current_process) { + current_process->Finalize(); + current_process->Close(); + current_process = nullptr; + } + // Track kernel objects that were not freed on shutdown { std::lock_guard lk(registered_objects_lock); @@ -714,9 +726,11 @@ struct KernelCore::Impl { std::unordered_set<KServerPort*> server_ports; std::unordered_set<KServerSession*> server_sessions; std::unordered_set<KAutoObject*> registered_objects; + std::unordered_set<KAutoObject*> registered_in_use_objects; std::mutex server_ports_lock; std::mutex server_sessions_lock; std::mutex registered_objects_lock; + std::mutex registered_in_use_objects_lock; std::unique_ptr<Core::ExclusiveMonitor> exclusive_monitor; std::vector<Kernel::PhysicalCore> cores; @@ -928,6 +942,16 @@ void KernelCore::UnregisterKernelObject(KAutoObject* object) { impl->registered_objects.erase(object); } +void KernelCore::RegisterInUseObject(KAutoObject* object) { + std::lock_guard lk(impl->registered_in_use_objects_lock); + impl->registered_in_use_objects.insert(object); +} + +void KernelCore::UnregisterInUseObject(KAutoObject* object) { + std::lock_guard lk(impl->registered_in_use_objects_lock); + impl->registered_in_use_objects.erase(object); +} + bool KernelCore::IsValidNamedPort(NamedPortTable::const_iterator port) const { return port != impl->named_ports.cend(); } diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index b6658b437..d2ceae950 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -204,6 +204,14 @@ public: /// destroyed during the current emulation session. void UnregisterKernelObject(KAutoObject* object); + /// Registers kernel objects with guest in use state, this is purely for close + /// after emulation has been shutdown. + void RegisterInUseObject(KAutoObject* object); + + /// Unregisters a kernel object previously registered with RegisterInUseObject when it was + /// destroyed during the current emulation session. + void UnregisterInUseObject(KAutoObject* object); + /// Determines whether or not the given port is a valid named port. bool IsValidNamedPort(NamedPortTable::const_iterator port) const; diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 7f38ade1c..c43135856 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -427,11 +427,15 @@ static ResultCode WaitSynchronization(Core::System& system, s32* index, VAddr ha R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>(objs.data(), handles, num_handles), ResultInvalidHandle); + for (const auto& obj : objs) { + kernel.RegisterInUseObject(obj); + } } // Ensure handles are closed when we're done. SCOPE_EXIT({ for (u64 i = 0; i < num_handles; ++i) { + kernel.UnregisterInUseObject(objs[i]); objs[i]->Close(); } }); @@ -1561,6 +1565,7 @@ static ResultCode StartThread(Core::System& system, Handle thread_handle) { // If we succeeded, persist a reference to the thread. thread->Open(); + system.Kernel().RegisterInUseObject(thread.GetPointerUnsafe()); return ResultSuccess; } @@ -1576,6 +1581,7 @@ static void ExitThread(Core::System& system) { auto* const current_thread = system.Kernel().CurrentScheduler()->GetCurrentThread(); system.GlobalSchedulerContext().RemoveThread(current_thread); current_thread->Exit(); + system.Kernel().UnregisterInUseObject(current_thread); } static void ExitThread32(Core::System& system) { diff --git a/src/core/hle/result.h b/src/core/hle/result.h index 2c6b24848..3807b9aa8 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h @@ -4,11 +4,10 @@ #pragma once -#include <new> -#include <utility> #include "common/assert.h" #include "common/bit_field.h" #include "common/common_types.h" +#include "common/expected.h" // All the constants in this file come from http://switchbrew.org/index.php?title=Error_codes @@ -155,203 +154,130 @@ constexpr ResultCode ResultSuccess(0); constexpr ResultCode ResultUnknown(UINT32_MAX); /** - * This is an optional value type. It holds a `ResultCode` and, if that code is a success code, - * also holds a result of type `T`. If the code is an error code then trying to access the inner - * value fails, thus ensuring that the ResultCode of functions is always checked properly before - * their return value is used. It is similar in concept to the `std::optional` type - * (http://en.cppreference.com/w/cpp/experimental/optional) originally proposed for inclusion in - * C++14, or the `Result` type in Rust (http://doc.rust-lang.org/std/result/index.html). + * This is an optional value type. It holds a `ResultCode` and, if that code is ResultSuccess, it + * also holds a result of type `T`. If the code is an error code (not ResultSuccess), then trying + * to access the inner value with operator* is undefined behavior and will assert with Unwrap(). + * Users of this class must be cognizant to check the status of the ResultVal with operator bool(), + * Code(), Succeeded() or Failed() prior to accessing the inner value. * * An example of how it could be used: * \code * ResultVal<int> Frobnicate(float strength) { * if (strength < 0.f || strength > 1.0f) { * // Can't frobnicate too weakly or too strongly - * return ResultCode(ErrorDescription::OutOfRange, ErrorModule::Common, - * ErrorSummary::InvalidArgument, ErrorLevel::Permanent); + * return ResultCode{ErrorModule::Common, 1}; * } else { * // Frobnicated! Give caller a cookie - * return MakeResult<int>(42); + * return 42; * } * } * \endcode * * \code - * ResultVal<int> frob_result = Frobnicate(0.75f); + * auto frob_result = Frobnicate(0.75f); * if (frob_result) { * // Frobbed ok * printf("My cookie is %d\n", *frob_result); * } else { - * printf("Guess I overdid it. :( Error code: %ux\n", frob_result.code().hex); + * printf("Guess I overdid it. :( Error code: %ux\n", frob_result.Code().raw); * } * \endcode */ template <typename T> class ResultVal { public: - /// Constructs an empty `ResultVal` with the given error code. The code must not be a success - /// code. - ResultVal(ResultCode error_code = ResultUnknown) : result_code(error_code) { - ASSERT(error_code.IsError()); - } + constexpr ResultVal() : expected{} {} + + constexpr ResultVal(ResultCode code) : expected{Common::Unexpected(code)} {} + + template <typename U> + constexpr ResultVal(U&& val) : expected{std::forward<U>(val)} {} - /** - * Similar to the non-member function `MakeResult`, with the exception that you can manually - * specify the success code. `success_code` must not be an error code. - */ template <typename... Args> - [[nodiscard]] static ResultVal WithCode(ResultCode success_code, Args&&... args) { - ResultVal<T> result; - result.emplace(success_code, std::forward<Args>(args)...); - return result; - } + constexpr ResultVal(Args&&... args) : expected{std::in_place, std::forward<Args>(args)...} {} - ResultVal(const ResultVal& o) noexcept : result_code(o.result_code) { - if (!o.empty()) { - new (&object) T(o.object); - } - } + ~ResultVal() = default; - ResultVal(ResultVal&& o) noexcept : result_code(o.result_code) { - if (!o.empty()) { - new (&object) T(std::move(o.object)); - } - } + constexpr ResultVal(const ResultVal&) = default; + constexpr ResultVal(ResultVal&&) = default; - ~ResultVal() { - if (!empty()) { - object.~T(); - } - } + ResultVal& operator=(const ResultVal&) = default; + ResultVal& operator=(ResultVal&&) = default; - ResultVal& operator=(const ResultVal& o) noexcept { - if (this == &o) { - return *this; - } - if (!empty()) { - if (!o.empty()) { - object = o.object; - } else { - object.~T(); - } - } else { - if (!o.empty()) { - new (&object) T(o.object); - } - } - result_code = o.result_code; - - return *this; + [[nodiscard]] constexpr explicit operator bool() const noexcept { + return expected.has_value(); } - ResultVal& operator=(ResultVal&& o) noexcept { - if (this == &o) { - return *this; - } - if (!empty()) { - if (!o.empty()) { - object = std::move(o.object); - } else { - object.~T(); - } - } else { - if (!o.empty()) { - new (&object) T(std::move(o.object)); - } - } - result_code = o.result_code; - - return *this; + [[nodiscard]] constexpr ResultCode Code() const { + return expected.has_value() ? ResultSuccess : expected.error(); } - /** - * Replaces the current result with a new constructed result value in-place. The code must not - * be an error code. - */ - template <typename... Args> - void emplace(ResultCode success_code, Args&&... args) { - ASSERT(success_code.IsSuccess()); - if (!empty()) { - object.~T(); - } - new (&object) T(std::forward<Args>(args)...); - result_code = success_code; + [[nodiscard]] constexpr bool Succeeded() const { + return expected.has_value(); } - /// Returns true if the `ResultVal` contains an error code and no value. - [[nodiscard]] bool empty() const { - return result_code.IsError(); + [[nodiscard]] constexpr bool Failed() const { + return !expected.has_value(); } - /// Returns true if the `ResultVal` contains a return value. - [[nodiscard]] bool Succeeded() const { - return result_code.IsSuccess(); + [[nodiscard]] constexpr T* operator->() { + return std::addressof(expected.value()); } - /// Returns true if the `ResultVal` contains an error code and no value. - [[nodiscard]] bool Failed() const { - return empty(); + + [[nodiscard]] constexpr const T* operator->() const { + return std::addressof(expected.value()); } - [[nodiscard]] ResultCode Code() const { - return result_code; + [[nodiscard]] constexpr T& operator*() & { + return *expected; } - [[nodiscard]] const T& operator*() const { - return object; + [[nodiscard]] constexpr const T& operator*() const& { + return *expected; } - [[nodiscard]] T& operator*() { - return object; + + [[nodiscard]] constexpr T&& operator*() && { + return *expected; } - [[nodiscard]] const T* operator->() const { - return &object; + + [[nodiscard]] constexpr const T&& operator*() const&& { + return *expected; } - [[nodiscard]] T* operator->() { - return &object; + + [[nodiscard]] constexpr T& Unwrap() & { + ASSERT_MSG(Succeeded(), "Tried to Unwrap empty ResultVal"); + return expected.value(); } - /// Returns the value contained in this `ResultVal`, or the supplied default if it is missing. - template <typename U> - [[nodiscard]] T ValueOr(U&& value) const { - return !empty() ? object : std::move(value); + [[nodiscard]] constexpr const T& Unwrap() const& { + ASSERT_MSG(Succeeded(), "Tried to Unwrap empty ResultVal"); + return expected.value(); } - /// Asserts that the result succeeded and returns a reference to it. - [[nodiscard]] T& Unwrap() & { + [[nodiscard]] constexpr T&& Unwrap() && { ASSERT_MSG(Succeeded(), "Tried to Unwrap empty ResultVal"); - return **this; + return std::move(expected.value()); } - [[nodiscard]] T&& Unwrap() && { + [[nodiscard]] constexpr const T&& Unwrap() const&& { ASSERT_MSG(Succeeded(), "Tried to Unwrap empty ResultVal"); - return std::move(**this); + return std::move(expected.value()); } -private: - // A union is used to allocate the storage for the value, while allowing us to construct and - // destruct it at will. - union { - T object; - }; - ResultCode result_code; -}; + template <typename U> + [[nodiscard]] constexpr T ValueOr(U&& v) const& { + return expected.value_or(v); + } -/** - * This function is a helper used to construct `ResultVal`s. It receives the arguments to construct - * `T` with and creates a success `ResultVal` contained the constructed value. - */ -template <typename T, typename... Args> -[[nodiscard]] ResultVal<T> MakeResult(Args&&... args) { - return ResultVal<T>::WithCode(ResultSuccess, std::forward<Args>(args)...); -} + template <typename U> + [[nodiscard]] constexpr T ValueOr(U&& v) && { + return expected.value_or(v); + } -/** - * Deducible overload of MakeResult, allowing the template parameter to be ommited if you're just - * copy or move constructing. - */ -template <typename Arg> -[[nodiscard]] ResultVal<std::remove_cvref_t<Arg>> MakeResult(Arg&& arg) { - return ResultVal<std::remove_cvref_t<Arg>>::WithCode(ResultSuccess, std::forward<Arg>(arg)); -} +private: + // TODO: Replace this with std::expected once it is standardized in the STL. + Common::Expected<T, ResultCode> expected; +}; /** * Check for the success of `source` (which must evaluate to a ResultVal). If it succeeds, unwraps diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index f8f9e32f7..42e468ce2 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -226,11 +226,10 @@ ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std:: } if (mode == FileSys::Mode::Append) { - return MakeResult<FileSys::VirtualFile>( - std::make_shared<FileSys::OffsetVfsFile>(file, 0, file->GetSize())); + return std::make_shared<FileSys::OffsetVfsFile>(file, 0, file->GetSize()); } - return MakeResult<FileSys::VirtualFile>(file); + return file; } ResultVal<FileSys::VirtualDir> VfsDirectoryServiceWrapper::OpenDirectory(const std::string& path_) { @@ -240,7 +239,7 @@ ResultVal<FileSys::VirtualDir> VfsDirectoryServiceWrapper::OpenDirectory(const s // TODO(DarkLordZach): Find a better error code for this return FileSys::ERROR_PATH_NOT_FOUND; } - return MakeResult(dir); + return dir; } ResultVal<FileSys::EntryType> VfsDirectoryServiceWrapper::GetEntryType( @@ -252,12 +251,12 @@ ResultVal<FileSys::EntryType> VfsDirectoryServiceWrapper::GetEntryType( auto filename = Common::FS::GetFilename(path); // TODO(Subv): Some games use the '/' path, find out what this means. if (filename.empty()) - return MakeResult(FileSys::EntryType::Directory); + return FileSys::EntryType::Directory; if (dir->GetFile(filename) != nullptr) - return MakeResult(FileSys::EntryType::File); + return FileSys::EntryType::File; if (dir->GetSubdirectory(filename) != nullptr) - return MakeResult(FileSys::EntryType::Directory); + return FileSys::EntryType::Directory; return FileSys::ERROR_PATH_NOT_FOUND; } @@ -270,7 +269,7 @@ ResultVal<FileSys::FileTimeStampRaw> VfsDirectoryServiceWrapper::GetFileTimeStam if (GetEntryType(path).Failed()) { return FileSys::ERROR_PATH_NOT_FOUND; } - return MakeResult(dir->GetFileTimeStamp(Common::FS::GetFilename(path))); + return dir->GetFileTimeStamp(Common::FS::GetFilename(path)); } FileSystemController::FileSystemController(Core::System& system_) : system{system_} {} @@ -395,7 +394,7 @@ ResultVal<FileSys::VirtualDir> FileSystemController::OpenSaveDataSpace( return FileSys::ERROR_ENTITY_NOT_FOUND; } - return MakeResult(save_data_factory->GetSaveDataSpaceDirectory(space)); + return save_data_factory->GetSaveDataSpaceDirectory(space); } ResultVal<FileSys::VirtualDir> FileSystemController::OpenSDMC() const { @@ -421,7 +420,7 @@ ResultVal<FileSys::VirtualDir> FileSystemController::OpenBISPartition( return FileSys::ERROR_INVALID_ARGUMENT; } - return MakeResult<FileSys::VirtualDir>(std::move(part)); + return part; } ResultVal<FileSys::VirtualFile> FileSystemController::OpenBISPartitionStorage( @@ -437,7 +436,7 @@ ResultVal<FileSys::VirtualFile> FileSystemController::OpenBISPartitionStorage( return FileSys::ERROR_INVALID_ARGUMENT; } - return MakeResult<FileSys::VirtualFile>(std::move(part)); + return part; } u64 FileSystemController::GetFreeSpaceSize(FileSys::StorageId id) const { diff --git a/src/core/hle/service/glue/glue_manager.cpp b/src/core/hle/service/glue/glue_manager.cpp index aa9d48c0c..48e133b48 100644 --- a/src/core/hle/service/glue/glue_manager.cpp +++ b/src/core/hle/service/glue/glue_manager.cpp @@ -26,7 +26,7 @@ ResultVal<ApplicationLaunchProperty> ARPManager::GetLaunchProperty(u64 title_id) return ERR_NOT_REGISTERED; } - return MakeResult<ApplicationLaunchProperty>(iter->second.launch); + return iter->second.launch; } ResultVal<std::vector<u8>> ARPManager::GetControlProperty(u64 title_id) const { @@ -39,7 +39,7 @@ ResultVal<std::vector<u8>> ARPManager::GetControlProperty(u64 title_id) const { return ERR_NOT_REGISTERED; } - return MakeResult<std::vector<u8>>(iter->second.control); + return iter->second.control; } ResultCode ARPManager::Register(u64 title_id, ApplicationLaunchProperty launch, diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp index 24b7e4435..e4b97c1f6 100644 --- a/src/core/hle/service/ldr/ldr.cpp +++ b/src/core/hle/service/ldr/ldr.cpp @@ -335,7 +335,7 @@ public: CASCADE_CODE(result); if (ValidateRegionForMap(page_table, addr, size)) { - return MakeResult<VAddr>(addr); + return addr; } } @@ -371,7 +371,7 @@ public: } if (ValidateRegionForMap(page_table, addr, size)) { - return MakeResult<VAddr>(addr); + return addr; } } diff --git a/src/core/hle/service/mii/mii_manager.cpp b/src/core/hle/service/mii/mii_manager.cpp index 4fef2aea4..ca4ed35bb 100644 --- a/src/core/hle/service/mii/mii_manager.cpp +++ b/src/core/hle/service/mii/mii_manager.cpp @@ -443,14 +443,14 @@ ResultVal<std::vector<MiiInfoElement>> MiiManager::GetDefault(SourceFlag source_ std::vector<MiiInfoElement> result; if ((source_flag & SourceFlag::Default) == SourceFlag::None) { - return MakeResult(std::move(result)); + return result; } for (std::size_t index = BaseMiiCount; index < DefaultMiiCount; index++) { result.emplace_back(BuildDefault(index), Source::Default); } - return MakeResult(std::move(result)); + return result; } ResultCode MiiManager::GetIndex([[maybe_unused]] const MiiInfo& info, u32& index) { diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp index 931b48f72..64ffc8572 100644 --- a/src/core/hle/service/ns/ns.cpp +++ b/src/core/hle/service/ns/ns.cpp @@ -414,7 +414,7 @@ ResultVal<u8> IApplicationManagerInterface::GetApplicationDesiredLanguage( for (const auto lang : *priority_list) { const auto supported_flag = GetSupportedLanguageFlag(lang); if (supported_languages == 0 || (supported_languages & supported_flag) == supported_flag) { - return MakeResult(static_cast<u8>(lang)); + return static_cast<u8>(lang); } } @@ -448,7 +448,7 @@ ResultVal<u64> IApplicationManagerInterface::ConvertApplicationLanguageToLanguag return ERR_APPLICATION_LANGUAGE_NOT_FOUND; } - return MakeResult(static_cast<u64>(*language_code)); + return static_cast<u64>(*language_code); } IApplicationVersionInterface::IApplicationVersionInterface(Core::System& system_) diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp index ae4dc4a75..41abb146c 100644 --- a/src/core/hle/service/sm/sm.cpp +++ b/src/core/hle/service/sm/sm.cpp @@ -87,7 +87,7 @@ ResultVal<Kernel::KPort*> ServiceManager::GetServicePort(const std::string& name auto handler = it->second; port->GetServerPort().SetSessionHandler(std::move(handler)); - return MakeResult(port); + return port; } /** @@ -165,7 +165,7 @@ ResultVal<Kernel::KClientSession*> SM::GetServiceImpl(Kernel::HLERequestContext& LOG_DEBUG(Service_SM, "called service={} -> session={}", name, session->GetId()); - return MakeResult(session); + return session; } void SM::RegisterService(Kernel::HLERequestContext& ctx) { diff --git a/src/core/hle/service/spl/spl_module.cpp b/src/core/hle/service/spl/spl_module.cpp index ed4c06260..10f7d1461 100644 --- a/src/core/hle/service/spl/spl_module.cpp +++ b/src/core/hle/service/spl/spl_module.cpp @@ -120,40 +120,40 @@ ResultVal<u64> Module::Interface::GetConfigImpl(ConfigItem config_item) const { return ResultSecureMonitorNotImplemented; case ConfigItem::ExosphereApiVersion: // Get information about the current exosphere version. - return MakeResult((u64{HLE::ApiVersion::ATMOSPHERE_RELEASE_VERSION_MAJOR} << 56) | - (u64{HLE::ApiVersion::ATMOSPHERE_RELEASE_VERSION_MINOR} << 48) | - (u64{HLE::ApiVersion::ATMOSPHERE_RELEASE_VERSION_MICRO} << 40) | - (static_cast<u64>(HLE::ApiVersion::GetTargetFirmware()))); + return (u64{HLE::ApiVersion::ATMOSPHERE_RELEASE_VERSION_MAJOR} << 56) | + (u64{HLE::ApiVersion::ATMOSPHERE_RELEASE_VERSION_MINOR} << 48) | + (u64{HLE::ApiVersion::ATMOSPHERE_RELEASE_VERSION_MICRO} << 40) | + (static_cast<u64>(HLE::ApiVersion::GetTargetFirmware())); case ConfigItem::ExosphereNeedsReboot: // We are executing, so we aren't in the process of rebooting. - return MakeResult(u64{0}); + return u64{0}; case ConfigItem::ExosphereNeedsShutdown: // We are executing, so we aren't in the process of shutting down. - return MakeResult(u64{0}); + return u64{0}; case ConfigItem::ExosphereGitCommitHash: // Get information about the current exosphere git commit hash. - return MakeResult(u64{0}); + return u64{0}; case ConfigItem::ExosphereHasRcmBugPatch: // Get information about whether this unit has the RCM bug patched. - return MakeResult(u64{0}); + return u64{0}; case ConfigItem::ExosphereBlankProdInfo: // Get whether this unit should simulate a "blanked" PRODINFO. - return MakeResult(u64{0}); + return u64{0}; case ConfigItem::ExosphereAllowCalWrites: // Get whether this unit should allow writing to the calibration partition. - return MakeResult(u64{0}); + return u64{0}; case ConfigItem::ExosphereEmummcType: // Get what kind of emummc this unit has active. - return MakeResult(u64{0}); + return u64{0}; case ConfigItem::ExospherePayloadAddress: // Gets the physical address of the reboot payload buffer, if one exists. return ResultSecureMonitorNotInitialized; case ConfigItem::ExosphereLogConfiguration: // Get the log configuration. - return MakeResult(u64{0}); + return u64{0}; case ConfigItem::ExosphereForceEnableUsb30: // Get whether usb 3.0 should be force-enabled. - return MakeResult(u64{0}); + return u64{0}; default: return ResultSecureMonitorInvalidArgument; } diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 439e7e472..760b528b9 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp @@ -1284,15 +1284,15 @@ private: static ResultVal<ConvertedScaleMode> ConvertScalingModeImpl(NintendoScaleMode mode) { switch (mode) { case NintendoScaleMode::None: - return MakeResult(ConvertedScaleMode::None); + return ConvertedScaleMode::None; case NintendoScaleMode::Freeze: - return MakeResult(ConvertedScaleMode::Freeze); + return ConvertedScaleMode::Freeze; case NintendoScaleMode::ScaleToWindow: - return MakeResult(ConvertedScaleMode::ScaleToWindow); + return ConvertedScaleMode::ScaleToWindow; case NintendoScaleMode::ScaleAndCrop: - return MakeResult(ConvertedScaleMode::ScaleAndCrop); + return ConvertedScaleMode::ScaleAndCrop; case NintendoScaleMode::PreserveAspectRatio: - return MakeResult(ConvertedScaleMode::PreserveAspectRatio); + return ConvertedScaleMode::PreserveAspectRatio; default: LOG_ERROR(Service_VI, "Invalid scaling mode specified, mode={}", mode); return ERR_OPERATION_FAILED; |