diff --git a/CMakeLists.txt b/CMakeLists.txt index da8a44ef..34542f84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ add_compile_definitions(BOOST_NO_CXX98_FUNCTION_BASE) # Forbid Boost from using add_library(boost INTERFACE) target_include_directories(boost SYSTEM INTERFACE ${Boost_INCLUDE_DIR}) -set(CRYPTOPP_BUILD_TESTING OFF) +set(CRYPTOPP_BUILD_TESTING OFF) add_subdirectory(third_party/cryptopp) # Check for x64 @@ -114,7 +114,9 @@ set(HEADER_FILES include/emulator.hpp include/helpers.hpp include/opengl.hpp inc include/fs/archive_ext_save_data.hpp include/services/shared_font.hpp include/fs/archive_ncch.hpp include/renderer_gl/textures.hpp include/colour.hpp include/services/y2r.hpp include/services/cam.hpp include/services/ldr_ro.hpp include/ipc.hpp include/services/act.hpp include/services/nfc.hpp - include/system_models.hpp include/services/dlp_srvr.hpp + include/system_models.hpp include/services/dlp_srvr.hpp include/result/result.hpp + include/result/result_common.hpp include/result/result_fs.hpp include/result/result_fnd.hpp + include/result/result_gsp.hpp include/result/result_kernel.hpp include/result/result_os.hpp ) set(THIRD_PARTY_SOURCE_FILES third_party/imgui/imgui.cpp diff --git a/include/fs/archive_base.hpp b/include/fs/archive_base.hpp index 5cd0b3bd..e1b4caa0 100644 --- a/include/fs/archive_base.hpp +++ b/include/fs/archive_base.hpp @@ -10,6 +10,9 @@ #include "helpers.hpp" #include "memory.hpp" #include "result.hpp" +#include "result/result.hpp" + +using Result::HorizonResult; namespace PathType { enum : u32 { @@ -97,7 +100,7 @@ struct FileSession { u32 priority = 0; // TODO: What does this even do bool isOpen; - FileSession(ArchiveBase* archive, const FSPath& filePath, const FSPath& archivePath, FILE* fd, bool isOpen = true) : + FileSession(ArchiveBase* archive, const FSPath& filePath, const FSPath& archivePath, FILE* fd, bool isOpen = true) : archive(archive), path(filePath), archivePath(archivePath), fd(fd), isOpen(isOpen), priority(0) {} // For cloning a file session @@ -128,16 +131,6 @@ struct DirectorySession { // Otherwise the fd of the opened file is returned (or nullptr if the opened file doesn't require one) using FileDescriptor = std::optional; -enum class FSResult : u32 { - Success = 0, - AlreadyExists = 0x82044BE, - FileTooLarge = 0x86044D2, - FileNotFound = 0xC8804470, - NotFoundInvalid = 0xC8A04478, // Also a not found error code used here and there in the FS module. - NotFormatted = 0xC8A04554, // Trying to access an archive that needs formatting and has not been formatted - UnexpectedFileOrDir = 0xE0C04702 -}; - class ArchiveBase { public: struct FormatInfo { @@ -149,7 +142,7 @@ public: protected: using Handle = u32; - + static constexpr FileDescriptor NoFile = nullptr; static constexpr FileDescriptor FileError = std::nullopt; Memory& mem; @@ -176,12 +169,12 @@ protected: // If the path string doesn't begin with / then that means it's accessing outside the FS root, which is invalid & unsafe if (pathString[0] != Char('/')) return false; - // Counts how many folders sans the root our file is nested under. + // Counts how many folders sans the root our file is nested under. // If it's < 0 at any point of parsing, then the path is unsafe and tries to crawl outside our file sandbox. // If it's 0 then this is the FS root. // If it's > 0 then we're in a subdirectory of the root. int level = 0; - + // Split the string on / characters and see how many of the substrings are ".." size_t pos = 0; while ((pos = pathString.find(Char('/'))) != String::npos) { @@ -202,27 +195,27 @@ protected: public: virtual std::string name() = 0; virtual u64 getFreeBytes() = 0; - virtual FSResult createFile(const FSPath& path, u64 size) = 0; - virtual FSResult deleteFile(const FSPath& path) = 0; + virtual HorizonResult createFile(const FSPath& path, u64 size) = 0; + virtual HorizonResult deleteFile(const FSPath& path) = 0; - virtual Rust::Result getFormatInfo(const FSPath& path) { + virtual Rust::Result getFormatInfo(const FSPath& path) { Helpers::panic("Unimplemented GetFormatInfo for %s archive", name().c_str()); // Return a dummy struct just to avoid the UB of not returning anything, even if we panic return Ok(FormatInfo{ .size = 0, .numOfDirectories = 0, .numOfFiles = 0, .duplicateData = false }); } - virtual FSResult createDirectory(const FSPath& path) { + virtual HorizonResult createDirectory(const FSPath& path) { Helpers::panic("Unimplemented CreateDirectory for %s archive", name().c_str()); - return FSResult::AlreadyExists; + return Result::FS::AlreadyExists; } // Returns nullopt if opening the file failed, otherwise returns a file descriptor to it (nullptr if none is needed) virtual FileDescriptor openFile(const FSPath& path, const FilePerms& perms) = 0; - virtual Rust::Result openArchive(const FSPath& path) = 0; + virtual Rust::Result openArchive(const FSPath& path) = 0; - virtual Rust::Result openDirectory(const FSPath& path) { + virtual Rust::Result openDirectory(const FSPath& path) { Helpers::panic("Unimplemented OpenDirectory for %s archive", name().c_str()); - return Err(FSResult::FileNotFound); + return Err(Result::FS::FileNotFoundAlt); } virtual void format(const FSPath& path, const FormatInfo& info) { @@ -232,6 +225,6 @@ public: // Read size bytes from a file starting at offset "offset" into a certain buffer in memory // Returns the number of bytes read, or nullopt if the read failed virtual std::optional readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) = 0; - + ArchiveBase(Memory& mem) : mem(mem) {} }; \ No newline at end of file diff --git a/include/fs/archive_ext_save_data.hpp b/include/fs/archive_ext_save_data.hpp index 95c822e9..6e7fe65b 100644 --- a/include/fs/archive_ext_save_data.hpp +++ b/include/fs/archive_ext_save_data.hpp @@ -9,11 +9,11 @@ public: u64 getFreeBytes() override { Helpers::panic("ExtSaveData::GetFreeBytes unimplemented"); return 0; } std::string name() override { return "ExtSaveData::" + backingFolder; } - FSResult createFile(const FSPath& path, u64 size) override; - FSResult deleteFile(const FSPath& path) override; + HorizonResult createFile(const FSPath& path, u64 size) override; + HorizonResult deleteFile(const FSPath& path) override; - Rust::Result openArchive(const FSPath& path) override; - Rust::Result openDirectory(const FSPath& path) override; + Rust::Result openArchive(const FSPath& path) override; + Rust::Result openDirectory(const FSPath& path) override; FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override; std::optional readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override; diff --git a/include/fs/archive_ncch.hpp b/include/fs/archive_ncch.hpp index 9bc84a09..275bcd20 100644 --- a/include/fs/archive_ncch.hpp +++ b/include/fs/archive_ncch.hpp @@ -8,10 +8,10 @@ public: u64 getFreeBytes() override { Helpers::panic("NCCH::GetFreeBytes unimplemented"); return 0; } std::string name() override { return "NCCH"; } - FSResult createFile(const FSPath& path, u64 size) override; - FSResult deleteFile(const FSPath& path) override; + HorizonResult createFile(const FSPath& path, u64 size) override; + HorizonResult deleteFile(const FSPath& path) override; - Rust::Result openArchive(const FSPath& path) override; + Rust::Result openArchive(const FSPath& path) override; FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override; std::optional readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override; diff --git a/include/fs/archive_save_data.hpp b/include/fs/archive_save_data.hpp index 4831f8df..9b25f008 100644 --- a/include/fs/archive_save_data.hpp +++ b/include/fs/archive_save_data.hpp @@ -8,17 +8,17 @@ public: u64 getFreeBytes() override { Helpers::panic("SaveData::GetFreeBytes unimplemented"); return 0; } std::string name() override { return "SaveData"; } - FSResult createDirectory(const FSPath& path) override; - FSResult createFile(const FSPath& path, u64 size) override; - FSResult deleteFile(const FSPath& path) override; + HorizonResult createDirectory(const FSPath& path) override; + HorizonResult createFile(const FSPath& path, u64 size) override; + HorizonResult deleteFile(const FSPath& path) override; - Rust::Result openArchive(const FSPath& path) override; - Rust::Result openDirectory(const FSPath& path) override; + Rust::Result openArchive(const FSPath& path) override; + Rust::Result openDirectory(const FSPath& path) override; FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override; std::optional readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override; void format(const FSPath& path, const FormatInfo& info) override; - Rust::Result getFormatInfo(const FSPath& path) override; + Rust::Result getFormatInfo(const FSPath& path) override; std::filesystem::path getFormatInfoPath() { return IOFile::getAppData() / "FormatInfo" / "SaveData.format"; diff --git a/include/fs/archive_sdmc.hpp b/include/fs/archive_sdmc.hpp index 1e03aa46..a8d9e259 100644 --- a/include/fs/archive_sdmc.hpp +++ b/include/fs/archive_sdmc.hpp @@ -1,5 +1,8 @@ #pragma once #include "archive_base.hpp" +#include "result/result.hpp" + +using Result::HorizonResult; class SDMCArchive : public ArchiveBase { public: @@ -8,10 +11,10 @@ public: u64 getFreeBytes() override { Helpers::panic("SDMC::GetFreeBytes unimplemented"); return 0; } std::string name() override { return "SDMC"; } - FSResult createFile(const FSPath& path, u64 size) override; - FSResult deleteFile(const FSPath& path) override; + HorizonResult createFile(const FSPath& path, u64 size) override; + HorizonResult deleteFile(const FSPath& path) override; - Rust::Result openArchive(const FSPath& path) override; + Rust::Result openArchive(const FSPath& path) override; FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override; std::optional readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override; }; \ No newline at end of file diff --git a/include/fs/archive_self_ncch.hpp b/include/fs/archive_self_ncch.hpp index 357db93e..e8877a47 100644 --- a/include/fs/archive_self_ncch.hpp +++ b/include/fs/archive_self_ncch.hpp @@ -8,10 +8,10 @@ public: u64 getFreeBytes() override { return 0; } std::string name() override { return "SelfNCCH"; } - FSResult createFile(const FSPath& path, u64 size) override; - FSResult deleteFile(const FSPath& path) override; + HorizonResult createFile(const FSPath& path, u64 size) override; + HorizonResult deleteFile(const FSPath& path) override; - Rust::Result openArchive(const FSPath& path) override; + Rust::Result openArchive(const FSPath& path) override; FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override; std::optional readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override; diff --git a/include/kernel/kernel_types.hpp b/include/kernel/kernel_types.hpp index e0611c65..56bed359 100644 --- a/include/kernel/kernel_types.hpp +++ b/include/kernel/kernel_types.hpp @@ -4,33 +4,7 @@ #include "fs/archive_base.hpp" #include "handles.hpp" #include "helpers.hpp" - -namespace SVCResult { - enum : u32 { - Success = 0, - Failure = 0xFFFFFFFF, - ObjectNotFound = 0xD88007FA, - - // Different calls return a different value for these ones - InvalidEnumValue = 0xD8E007ED, - InvalidEnumValueAlt = 0xD8E093ED, - BadHandle = 0xD8E007F7, - BadHandleAlt = 0xD9001BF7, - - InvalidCombination = 0xE0E01BEE, // Used for invalid memory permission combinations - UnalignedAddr = 0xE0E01BF1, - UnalignedSize = 0xE0E01BF2, - - BadThreadPriority = 0xE0E01BFD, - PortNameTooLong = 0xE0E0181E, - - // Returned when a thread stops waiting due to timing out - Timeout = 0x9401BFE, - - // Returned when a thread releases a mutex it does not own - InvalidMutexRelease = 0xD8E0041F - }; -} +#include "result/result.hpp" enum class KernelObjectType : u8 { AddressArbiter, Archive, Directory, File, MemoryBlock, Process, ResourceLimit, Session, Dummy, @@ -125,7 +99,7 @@ struct Thread { ThreadStatus status; Handle handle; // OS handle for this thread int index; // Index of the thread. 0 for the first thread, 1 for the second, and so on - + // The waiting address for threads that are waiting on an AddressArbiter u32 waitingAddress; diff --git a/include/result/result.hpp b/include/result/result.hpp new file mode 100644 index 00000000..00a2436e --- /dev/null +++ b/include/result/result.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include "result_common.hpp" +#include "result_kernel.hpp" +#include "result_os.hpp" +#include "result_fnd.hpp" +#include "result_fs.hpp" +#include "result_gsp.hpp" \ No newline at end of file diff --git a/include/result/result_common.hpp b/include/result/result_common.hpp new file mode 100644 index 00000000..6a7d9bdb --- /dev/null +++ b/include/result/result_common.hpp @@ -0,0 +1,206 @@ +#pragma once + +#include +#include +#include + +namespace Result { + enum class HorizonResultLevel : uint32_t { + Success = 0, + Info = 1, + Status = 25, + Temporary = 26, + Permanent = 27, + Usage = 28, + Reinitialize = 29, + Reset = 30, + Fatal = 31, + }; + + enum class HorizonResultSummary : uint32_t { + Success = 0, + NothingHappened = 1, + WouldBlock = 2, + OutOfResource = 3, + NotFound = 4, + InvalidState = 5, + NotSupported = 6, + InvalidArgument = 7, + WrongArgument = 8, + Canceled = 9, + StatusChanged = 10, + Internal = 11, + }; + + enum class HorizonResultModule : uint32_t { + Common = 0, + Kernel = 1, + Util = 2, + FileServer = 3, + LoaderServer = 4, + TCB = 5, + OS = 6, + DBG = 7, + DMNT = 8, + PDN = 9 , + GSP = 10, + I2C = 11, + GPIO = 12, + DD = 13, + CODEC = 14, + SPI = 15, + PXI = 16, + FS = 17, + DI = 18, + HID = 19, + CAM = 20, + PI = 21, + PM = 22, + PM_LOW = 23, + FSI = 24, + SRV = 25, + NDM = 26, + NWM = 27, + SOC = 28, + LDR = 29, + ACC = 30, + RomFS = 31, + AM = 32, + HIO = 33, + Updater = 34, + MIC = 35, + FND = 36, + MP = 37, + MPWL = 38, + AC = 39, + HTTP = 40, + DSP = 41, + SND = 42, + DLP = 43, + HIO_LOW = 44, + CSND = 45, + SSL = 46, + AM_LOW = 47, + NEX = 48, + Friends = 49, + RDT = 50, + Applet = 51, + NIM = 52, + PTM = 53, + MIDI = 54, + MC = 55, + SWC = 56, + FatFS = 57, + NGC = 58, + CARD = 59, + CARDNOR = 60, + SDMC = 61, + BOSS = 62, + DBM = 63, + Config = 64, + PS = 65, + CEC = 66, + IR = 67, + UDS = 68, + PL = 69, + CUP = 70, + Gyroscope = 71, + MCU = 72, + NS = 73, + News = 74, + RO = 75, + GD = 76, + CardSPI = 77, + EC = 78, + WebBrowser = 79, + Test = 80, + ENC = 81, + PIA = 82, + ACT = 83, + VCTL = 84, + OLV = 85, + NEIA = 86, + NPNS = 87, + AVD = 90, + L2B = 91, + MVD = 92, + NFC = 93, + UART = 94, + SPM = 95, + QTM = 96, + NFP = 97, + }; + + class HorizonResult { + private: + static const uint32_t DescriptionBits = 10; + static const uint32_t ModuleBits = 8; + static const uint32_t ReservedBits = 3; + static const uint32_t SummaryBits = 6; + static const uint32_t LevelBits = 5; + + static const uint32_t DescriptionOffset = 0; + static const uint32_t ModuleOffset = DescriptionOffset + DescriptionBits; + static const uint32_t SummaryOffset = ModuleOffset + ModuleBits + ReservedBits; + static const uint32_t LevelOffset = SummaryOffset + SummaryBits; + + static_assert(DescriptionBits + ModuleBits + SummaryBits + LevelBits + ReservedBits == sizeof(uint32_t) * CHAR_BIT, "Invalid Result size"); + + uint32_t m_value; + + constexpr inline uint32_t getBitsValue(int offset, int amount) { + return (m_value >> offset) & ~(~0 << amount); + } + + static constexpr inline uint32_t makeValue(uint32_t description, uint32_t module, uint32_t summary, uint32_t level) { + return (description << DescriptionOffset) | (module << ModuleOffset) | (summary << SummaryOffset) | (level << LevelOffset); + } + + public: + constexpr HorizonResult() {} + constexpr HorizonResult(uint32_t value) : m_value(value) {} + constexpr HorizonResult(uint32_t description, HorizonResultModule module, HorizonResultSummary summary, HorizonResultLevel level) : m_value(makeValue(description, static_cast(module), static_cast(summary), static_cast(level))) {} + constexpr operator uint32_t() const { return m_value; } + + constexpr inline uint32_t getDescription() { + return getBitsValue(DescriptionOffset, DescriptionBits); + } + + constexpr inline HorizonResultModule getModule() { + return static_cast(getBitsValue(ModuleOffset, ModuleBits)); + } + + constexpr inline HorizonResultSummary getSummary() { + return static_cast(getBitsValue(SummaryOffset, SummaryBits)); + } + + constexpr inline HorizonResultLevel getLevel() { + return static_cast(getBitsValue(LevelOffset, LevelBits)); + } + + constexpr inline uint32_t getRawValue() { + return m_value; + } + + constexpr inline bool isSuccess() { + return m_value == 0; + } + + constexpr inline bool isFailure() { + return m_value != 0; + } + }; + + static_assert(std::is_trivially_destructible::value, "std::is_trivially_destructible::value"); + + #define DEFINE_HORIZON_RESULT_MODULE(ns, value) \ + namespace ns::Detail {\ + static constexpr HorizonResultModule ModuleId = HorizonResultModule::value; \ + } + + #define DEFINE_HORIZON_RESULT(name, description, summary, level) \ + static constexpr HorizonResult name(description, Detail::ModuleId, HorizonResultSummary::summary, HorizonResultLevel::level); + + static constexpr HorizonResult Success(0); + static constexpr HorizonResult FailurePlaceholder(UINT32_MAX); +}; diff --git a/include/result/result_fnd.hpp b/include/result/result_fnd.hpp new file mode 100644 index 00000000..9d8cfba7 --- /dev/null +++ b/include/result/result_fnd.hpp @@ -0,0 +1,8 @@ +#pragma once +#include "result_common.hpp" + +DEFINE_HORIZON_RESULT_MODULE(Result::FND, FND); + +namespace Result::FND { + DEFINE_HORIZON_RESULT(InvalidEnumValue, 1005, InvalidArgument, Permanent); +}; diff --git a/include/result/result_fs.hpp b/include/result/result_fs.hpp new file mode 100644 index 00000000..96df0995 --- /dev/null +++ b/include/result/result_fs.hpp @@ -0,0 +1,18 @@ +#pragma once +#include "result_common.hpp" + +DEFINE_HORIZON_RESULT_MODULE(Result::FS, FS); + +namespace Result::FS { + // TODO: Verify this + DEFINE_HORIZON_RESULT(FileNotFound, 100, NotFound, Status); + // TODO: Verify this + DEFINE_HORIZON_RESULT(FileNotFoundAlt, 112, NotFound, Status); + // Also a not found error code used here and there in the FS module. + DEFINE_HORIZON_RESULT(NotFoundInvalid, 120, InvalidState, Status); + DEFINE_HORIZON_RESULT(AlreadyExists, 190, NothingHappened, Info); + DEFINE_HORIZON_RESULT(FileTooLarge, 210, OutOfResource, Info); + // Trying to access an archive that needs formatting and has not been formatted + DEFINE_HORIZON_RESULT(NotFormatted, 340, InvalidState, Status); + DEFINE_HORIZON_RESULT(UnexpectedFileOrDir, 770, NotSupported, Usage); +}; diff --git a/include/result/result_gsp.hpp b/include/result/result_gsp.hpp new file mode 100644 index 00000000..03c51f30 --- /dev/null +++ b/include/result/result_gsp.hpp @@ -0,0 +1,8 @@ +#pragma once +#include "result_common.hpp" + +DEFINE_HORIZON_RESULT_MODULE(Result::GSP, GSP); + +namespace Result::GSP { + DEFINE_HORIZON_RESULT(SuccessRegisterIRQ, 519, Success, Success); +}; diff --git a/include/result/result_kernel.hpp b/include/result/result_kernel.hpp new file mode 100644 index 00000000..308745ec --- /dev/null +++ b/include/result/result_kernel.hpp @@ -0,0 +1,15 @@ +#pragma once +#include "result_common.hpp" + +DEFINE_HORIZON_RESULT_MODULE(Result::Kernel, Kernel); + +namespace Result::Kernel { + // Returned when a thread releases a mutex it does not own + DEFINE_HORIZON_RESULT(InvalidMutexRelease, 31, InvalidArgument, Permanent); + DEFINE_HORIZON_RESULT(NotFound, 1018, NotFound, Permanent); + DEFINE_HORIZON_RESULT(InvalidEnumValue, 1005, InvalidArgument, Permanent); + DEFINE_HORIZON_RESULT(InvalidHandle, 1015, InvalidArgument, Permanent); + + + static_assert(InvalidHandle == 0xD8E007F7, "conversion broken"); +}; diff --git a/include/result/result_os.hpp b/include/result/result_os.hpp new file mode 100644 index 00000000..f9b6d4dc --- /dev/null +++ b/include/result/result_os.hpp @@ -0,0 +1,14 @@ +#pragma once +#include "result_common.hpp" + +DEFINE_HORIZON_RESULT_MODULE(Result::OS, OS); + +namespace Result::OS { + DEFINE_HORIZON_RESULT(PortNameTooLong, 30, InvalidArgument, Usage); + DEFINE_HORIZON_RESULT(InvalidHandle, 1015, WrongArgument, Permanent); + DEFINE_HORIZON_RESULT(InvalidCombination, 1006, InvalidArgument, Usage); + DEFINE_HORIZON_RESULT(MisalignedAddress, 1009, InvalidArgument, Usage); + DEFINE_HORIZON_RESULT(MisalignedSize, 1010, InvalidArgument, Usage); + DEFINE_HORIZON_RESULT(OutOfRange, 1021, InvalidArgument, Usage); + DEFINE_HORIZON_RESULT(Timeout, 1022, StatusChanged, Info); +}; diff --git a/include/services/ac.hpp b/include/services/ac.hpp index 2053ea21..e9aa8920 100644 --- a/include/services/ac.hpp +++ b/include/services/ac.hpp @@ -3,6 +3,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" class ACService { Handle handle = KernelHandles::AC; diff --git a/include/services/act.hpp b/include/services/act.hpp index 5502447a..b7f25e31 100644 --- a/include/services/act.hpp +++ b/include/services/act.hpp @@ -3,6 +3,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" class ACTService { Handle handle = KernelHandles::ACT; diff --git a/include/services/am.hpp b/include/services/am.hpp index 89362371..d961734f 100644 --- a/include/services/am.hpp +++ b/include/services/am.hpp @@ -3,6 +3,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" class AMService { Handle handle = KernelHandles::AM; diff --git a/include/services/apt.hpp b/include/services/apt.hpp index 33fa8297..56bf3083 100644 --- a/include/services/apt.hpp +++ b/include/services/apt.hpp @@ -4,6 +4,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" // Yay, more circular dependencies class Kernel; diff --git a/include/services/boss.hpp b/include/services/boss.hpp index ce0b9e0c..daf2ab13 100644 --- a/include/services/boss.hpp +++ b/include/services/boss.hpp @@ -3,6 +3,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" class BOSSService { Handle handle = KernelHandles::BOSS; diff --git a/include/services/cam.hpp b/include/services/cam.hpp index 7f4065ab..3ff80a32 100644 --- a/include/services/cam.hpp +++ b/include/services/cam.hpp @@ -3,6 +3,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" class CAMService { Handle handle = KernelHandles::CAM; diff --git a/include/services/cecd.hpp b/include/services/cecd.hpp index 392cbc67..48afd5dd 100644 --- a/include/services/cecd.hpp +++ b/include/services/cecd.hpp @@ -4,6 +4,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" class Kernel; diff --git a/include/services/cfg.hpp b/include/services/cfg.hpp index b15bc707..1250a0c7 100644 --- a/include/services/cfg.hpp +++ b/include/services/cfg.hpp @@ -4,6 +4,7 @@ #include "logger.hpp" #include "memory.hpp" #include "region_codes.hpp" +#include "result/result.hpp" class CFGService { Handle handle = KernelHandles::CFG; diff --git a/include/services/dlp_srvr.hpp b/include/services/dlp_srvr.hpp index c4be004f..1e714283 100644 --- a/include/services/dlp_srvr.hpp +++ b/include/services/dlp_srvr.hpp @@ -3,6 +3,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" // Please forgive me for how everything in this file is named // "dlp:SRVR" is not a nice name to work with diff --git a/include/services/dsp.hpp b/include/services/dsp.hpp index d6f98bd4..ab9fb106 100644 --- a/include/services/dsp.hpp +++ b/include/services/dsp.hpp @@ -4,6 +4,7 @@ #include "helpers.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" namespace DSPPipeType { enum : u32 { diff --git a/include/services/frd.hpp b/include/services/frd.hpp index 9f893729..9a6ff066 100644 --- a/include/services/frd.hpp +++ b/include/services/frd.hpp @@ -4,6 +4,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" // It's important to keep this struct to 16 bytes as we use its sizeof in the service functions in frd.cpp struct FriendKey { diff --git a/include/services/fs.hpp b/include/services/fs.hpp index 93e28d18..9220a869 100644 --- a/include/services/fs.hpp +++ b/include/services/fs.hpp @@ -8,6 +8,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" // Yay, more circular dependencies class Kernel; @@ -29,8 +30,8 @@ class FSService { ExtSaveDataArchive sharedExtSaveData_nand; ArchiveBase* getArchiveFromID(u32 id, const FSPath& archivePath); - Rust::Result openArchiveHandle(u32 archiveID, const FSPath& path); - Rust::Result openDirectoryHandle(ArchiveBase* archive, const FSPath& path); + Rust::Result openArchiveHandle(u32 archiveID, const FSPath& path); + Rust::Result openDirectoryHandle(ArchiveBase* archive, const FSPath& path); std::optional openFileHandle(ArchiveBase* archive, const FSPath& path, const FSPath& archivePath, const FilePerms& perms); FSPath readPath(u32 type, u32 pointer, u32 size); @@ -62,7 +63,7 @@ public: sharedExtSaveData_nand(mem, "../SharedFiles/NAND", true), extSaveData_sdmc(mem, "SDMC"), sdmc(mem), selfNcch(mem), ncch(mem), kernel(kernel) {} - + void reset(); void handleSyncRequest(u32 messagePointer); // Creates directories for NAND, ExtSaveData, etc if they don't already exist. Should be executed after loading a new ROM. diff --git a/include/services/gsp_gpu.hpp b/include/services/gsp_gpu.hpp index cab6fbff..f687532e 100644 --- a/include/services/gsp_gpu.hpp +++ b/include/services/gsp_gpu.hpp @@ -6,6 +6,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" enum class GPUInterrupt : u8 { PSC0 = 0, // Memory fill completed diff --git a/include/services/gsp_lcd.hpp b/include/services/gsp_lcd.hpp index c6fcf7ec..e7672d4f 100644 --- a/include/services/gsp_lcd.hpp +++ b/include/services/gsp_lcd.hpp @@ -3,6 +3,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" class LCDService { Handle handle = KernelHandles::LCD; diff --git a/include/services/hid.hpp b/include/services/hid.hpp index 3a7bd570..ea36bb0d 100644 --- a/include/services/hid.hpp +++ b/include/services/hid.hpp @@ -5,6 +5,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" namespace HID::Keys { enum : u32 { diff --git a/include/services/ldr_ro.hpp b/include/services/ldr_ro.hpp index 11b8e911..7acfce69 100644 --- a/include/services/ldr_ro.hpp +++ b/include/services/ldr_ro.hpp @@ -3,6 +3,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" class LDRService { Handle handle = KernelHandles::LDR_RO; diff --git a/include/services/mic.hpp b/include/services/mic.hpp index 943734e1..b8b4d5c9 100644 --- a/include/services/mic.hpp +++ b/include/services/mic.hpp @@ -3,6 +3,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" class MICService { Handle handle = KernelHandles::MIC; diff --git a/include/services/ndm.hpp b/include/services/ndm.hpp index 8879f2c2..05538884 100644 --- a/include/services/ndm.hpp +++ b/include/services/ndm.hpp @@ -3,6 +3,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" class NDMService { Handle handle = KernelHandles::NDM; diff --git a/include/services/nfc.hpp b/include/services/nfc.hpp index 9f626037..59e8f362 100644 --- a/include/services/nfc.hpp +++ b/include/services/nfc.hpp @@ -3,6 +3,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" // You know the drill class Kernel; diff --git a/include/services/nim.hpp b/include/services/nim.hpp index 6d45b837..dfe13694 100644 --- a/include/services/nim.hpp +++ b/include/services/nim.hpp @@ -3,6 +3,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" class NIMService { Handle handle = KernelHandles::NIM; diff --git a/include/services/ptm.hpp b/include/services/ptm.hpp index 5751fe28..ea07f08d 100644 --- a/include/services/ptm.hpp +++ b/include/services/ptm.hpp @@ -3,6 +3,7 @@ #include "kernel_types.hpp" #include "logger.hpp" #include "memory.hpp" +#include "result/result.hpp" class PTMService { Handle handle = KernelHandles::PTM; diff --git a/src/core/fs/archive_ext_save_data.cpp b/src/core/fs/archive_ext_save_data.cpp index bb7ce1a7..ca03b326 100644 --- a/src/core/fs/archive_ext_save_data.cpp +++ b/src/core/fs/archive_ext_save_data.cpp @@ -3,7 +3,7 @@ namespace fs = std::filesystem; -FSResult ExtSaveDataArchive::createFile(const FSPath& path, u64 size) { +HorizonResult ExtSaveDataArchive::createFile(const FSPath& path, u64 size) { if (size == 0) Helpers::panic("ExtSaveData file does not support size == 0"); @@ -15,22 +15,22 @@ FSResult ExtSaveDataArchive::createFile(const FSPath& path, u64 size) { p += fs::path(path.utf16_string).make_preferred(); if (fs::exists(p)) - return FSResult::AlreadyExists; - + return Result::FS::AlreadyExists; + // Create a file of size "size" by creating an empty one, seeking to size - 1 and just writing a 0 there IOFile file(p.string().c_str(), "wb"); if (file.seek(size - 1, SEEK_SET) && file.writeBytes("", 1).second == 1) { - return FSResult::Success; + return Result::Success; } - return FSResult::FileTooLarge; + return Result::FS::FileTooLarge; } Helpers::panic("ExtSaveDataArchive::OpenFile: Failed"); - return FSResult::Success; + return Result::Success; } -FSResult ExtSaveDataArchive::deleteFile(const FSPath& path) { +HorizonResult ExtSaveDataArchive::deleteFile(const FSPath& path) { if (path.type == PathType::UTF16) { if (!isPathSafe(path)) Helpers::panic("Unsafe path in ExtSaveData::DeleteFile"); @@ -43,7 +43,7 @@ FSResult ExtSaveDataArchive::deleteFile(const FSPath& path) { } if (!fs::is_regular_file(p)) { - return FSResult::FileNotFound; + return Result::FS::FileNotFoundAlt; } std::error_code ec; @@ -55,11 +55,11 @@ FSResult ExtSaveDataArchive::deleteFile(const FSPath& path) { Helpers::warn("ExtSaveData::DeleteFile: fs::remove failed\n"); } - return FSResult::Success; + return Result::Success; } Helpers::panic("ExtSaveDataArchive::DeleteFile: Unknown path type"); - return FSResult::Success; + return Result::Success; } FileDescriptor ExtSaveDataArchive::openFile(const FSPath& path, const FilePerms& perms) { @@ -95,7 +95,7 @@ std::string ExtSaveDataArchive::getExtSaveDataPathFromBinary(const FSPath& path) return backingFolder + std::to_string(saveLow) + std::to_string(saveHigh); } -Rust::Result ExtSaveDataArchive::openArchive(const FSPath& path) { +Rust::Result ExtSaveDataArchive::openArchive(const FSPath& path) { if (path.type != PathType::Binary || path.binary.size() != 12) { Helpers::panic("ExtSaveData accessed with an invalid path in OpenArchive"); } @@ -105,13 +105,13 @@ Rust::Result ExtSaveDataArchive::openArchive(const FSPat // fs::path formatInfopath = IOFile::getAppData() / "FormatInfo" / (getExtSaveDataPathFromBinary(path) + ".format"); // Format info not found so the archive is not formatted // if (!fs::is_regular_file(formatInfopath)) { - // return isShared ? Err(FSResult::NotFormatted) : Err(FSResult::NotFoundInvalid); + // return isShared ? Err(Result::FS::NotFormatted) : Err(Result::FS::NotFoundInvalid); //} return Ok((ArchiveBase*)this); } -Rust::Result ExtSaveDataArchive::openDirectory(const FSPath& path) { +Rust::Result ExtSaveDataArchive::openDirectory(const FSPath& path) { if (path.type == PathType::UTF16) { if (!isPathSafe(path)) Helpers::panic("Unsafe path in ExtSaveData::OpenDirectory"); @@ -121,18 +121,18 @@ Rust::Result ExtSaveDataArchive::openDirectory(const if (fs::is_regular_file(p)) { printf("ExtSaveData: OpenArchive used with a file path"); - return Err(FSResult::UnexpectedFileOrDir); + return Err(Result::FS::UnexpectedFileOrDir); } if (fs::is_directory(p)) { return Ok(DirectorySession(this, p)); } else { - return Err(FSResult::FileNotFound); + return Err(Result::FS::FileNotFoundAlt); } } Helpers::panic("ExtSaveDataArchive::OpenDirectory: Unimplemented path type"); - return Err(FSResult::Success); + return Err(Result::Success); } std::optional ExtSaveDataArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) { diff --git a/src/core/fs/archive_ncch.cpp b/src/core/fs/archive_ncch.cpp index 6deaa0f4..0c635c21 100644 --- a/src/core/fs/archive_ncch.cpp +++ b/src/core/fs/archive_ncch.cpp @@ -21,14 +21,14 @@ namespace MediaType { }; }; -FSResult NCCHArchive::createFile(const FSPath& path, u64 size) { +HorizonResult NCCHArchive::createFile(const FSPath& path, u64 size) { Helpers::panic("[NCCH] CreateFile not yet supported"); - return FSResult::Success; + return Result::Success; } -FSResult NCCHArchive::deleteFile(const FSPath& path) { +HorizonResult NCCHArchive::deleteFile(const FSPath& path) { Helpers::panic("[NCCH] Unimplemented DeleteFile"); - return FSResult::Success; + return Result::Success; } FileDescriptor NCCHArchive::openFile(const FSPath& path, const FilePerms& perms) { @@ -48,7 +48,7 @@ FileDescriptor NCCHArchive::openFile(const FSPath& path, const FilePerms& perms) return NoFile; } -Rust::Result NCCHArchive::openArchive(const FSPath& path) { +Rust::Result NCCHArchive::openArchive(const FSPath& path) { if (path.type != PathType::Binary || path.binary.size() != 16) { Helpers::panic("NCCHArchive::OpenArchive: Invalid path"); } diff --git a/src/core/fs/archive_save_data.cpp b/src/core/fs/archive_save_data.cpp index 572d22e0..2b17f51c 100644 --- a/src/core/fs/archive_save_data.cpp +++ b/src/core/fs/archive_save_data.cpp @@ -4,7 +4,7 @@ namespace fs = std::filesystem; -FSResult SaveDataArchive::createFile(const FSPath& path, u64 size) { +HorizonResult SaveDataArchive::createFile(const FSPath& path, u64 size) { if (path.type == PathType::UTF16) { if (!isPathSafe(path)) Helpers::panic("Unsafe path in SaveData::CreateFile"); @@ -13,28 +13,28 @@ FSResult SaveDataArchive::createFile(const FSPath& path, u64 size) { p += fs::path(path.utf16_string).make_preferred(); if (fs::exists(p)) - return FSResult::AlreadyExists; - + return Result::FS::AlreadyExists; + IOFile file(p.string().c_str(), "wb"); - + // If the size is 0, leave the file empty and return success if (size == 0) { - return FSResult::Success; + return Result::Success; } // If it is not empty, seek to size - 1 and write a 0 to create a file of size "size" else if (file.seek(size - 1, SEEK_SET) && file.writeBytes("", 1).second == 1) { - return FSResult::Success; + return Result::Success; } - return FSResult::FileTooLarge; + return Result::FS::FileTooLarge; } Helpers::panic("SaveDataArchive::OpenFile: Failed"); - return FSResult::Success; + return Result::Success; } -FSResult SaveDataArchive::createDirectory(const FSPath& path) { +HorizonResult SaveDataArchive::createDirectory(const FSPath& path) { if (path.type == PathType::UTF16) { if (!isPathSafe(path)) Helpers::panic("Unsafe path in SaveData::OpenFile"); @@ -43,19 +43,19 @@ FSResult SaveDataArchive::createDirectory(const FSPath& path) { p += fs::path(path.utf16_string).make_preferred(); if (fs::is_directory(p)) - return FSResult::AlreadyExists; + return Result::FS::AlreadyExists; if (fs::is_regular_file(p)) { Helpers::panic("File path passed to SaveData::CreateDirectory"); } bool success = fs::create_directory(p); - return success ? FSResult::Success : FSResult::UnexpectedFileOrDir; + return success ? Result::Success : Result::FS::UnexpectedFileOrDir; } else { Helpers::panic("Unimplemented SaveData::CreateDirectory"); } } -FSResult SaveDataArchive::deleteFile(const FSPath& path) { +HorizonResult SaveDataArchive::deleteFile(const FSPath& path) { if (path.type == PathType::UTF16) { if (!isPathSafe(path)) Helpers::panic("Unsafe path in SaveData::DeleteFile"); @@ -68,7 +68,7 @@ FSResult SaveDataArchive::deleteFile(const FSPath& path) { } if (!fs::is_regular_file(p)) { - return FSResult::FileNotFound; + return Result::FS::FileNotFoundAlt; } std::error_code ec; @@ -80,11 +80,11 @@ FSResult SaveDataArchive::deleteFile(const FSPath& path) { Helpers::warn("SaveData::DeleteFile: fs::remove failed\n"); } - return FSResult::Success; + return Result::Success; } Helpers::panic("SaveDataArchive::DeleteFile: Unknown path type"); - return FSResult::Success; + return Result::Success; } FileDescriptor SaveDataArchive::openFile(const FSPath& path, const FilePerms& perms) { @@ -121,7 +121,7 @@ FileDescriptor SaveDataArchive::openFile(const FSPath& path, const FilePerms& pe return FileError; } -Rust::Result SaveDataArchive::openDirectory(const FSPath& path) { +Rust::Result SaveDataArchive::openDirectory(const FSPath& path) { if (path.type == PathType::UTF16) { if (!isPathSafe(path)) Helpers::panic("Unsafe path in SaveData::OpenDirectory"); @@ -131,34 +131,34 @@ Rust::Result SaveDataArchive::openDirectory(const FS if (fs::is_regular_file(p)) { printf("SaveData: OpenDirectory used with a file path"); - return Err(FSResult::UnexpectedFileOrDir); + return Err(Result::FS::UnexpectedFileOrDir); } if (fs::is_directory(p)) { return Ok(DirectorySession(this, p)); } else { - return Err(FSResult::FileNotFound); + return Err(Result::FS::FileNotFoundAlt); } } Helpers::panic("SaveDataArchive::OpenDirectory: Unimplemented path type"); - return Err(FSResult::Success); + return Err(Result::Success); } -Rust::Result SaveDataArchive::getFormatInfo(const FSPath& path) { +Rust::Result SaveDataArchive::getFormatInfo(const FSPath& path) { const fs::path formatInfoPath = getFormatInfoPath(); IOFile file(formatInfoPath, "rb"); // If the file failed to open somehow, we return that the archive is not formatted if (!file.isOpen()) { - return Err(FSResult::NotFormatted); + return Err(Result::FS::NotFormatted); } FormatInfo ret; auto [success, bytesRead] = file.readBytes(&ret, sizeof(FormatInfo)); if (!success || bytesRead != sizeof(FormatInfo)) { Helpers::warn("SaveData::GetFormatInfo: Format file exists but was not properly read into the FormatInfo struct"); - return Err(FSResult::NotFormatted); + return Err(Result::FS::NotFormatted); } return Ok(ret); @@ -168,7 +168,7 @@ void SaveDataArchive::format(const FSPath& path, const ArchiveBase::FormatInfo& const fs::path saveDataPath = IOFile::getAppData() / "SaveData"; const fs::path formatInfoPath = getFormatInfoPath(); - // Delete all contents by deleting the directory then recreating it + // Delete all contents by deleting the directory then recreating it fs::remove_all(saveDataPath); fs::create_directories(saveDataPath); @@ -177,16 +177,16 @@ void SaveDataArchive::format(const FSPath& path, const ArchiveBase::FormatInfo& file.writeBytes(&info, sizeof(info)); } -Rust::Result SaveDataArchive::openArchive(const FSPath& path) { +Rust::Result SaveDataArchive::openArchive(const FSPath& path) { if (path.type != PathType::Empty) { Helpers::panic("Unimplemented path type for SaveData archive: %d\n", path.type); - return Err(FSResult::NotFoundInvalid); + return Err(Result::FS::NotFoundInvalid); } const fs::path formatInfoPath = getFormatInfoPath(); // Format info not found so the archive is not formatted if (!fs::is_regular_file(formatInfoPath)) { - return Err(FSResult::NotFormatted); + return Err(Result::FS::NotFormatted); } return Ok((ArchiveBase*)this); diff --git a/src/core/fs/archive_sdmc.cpp b/src/core/fs/archive_sdmc.cpp index 0759fcee..5049df14 100644 --- a/src/core/fs/archive_sdmc.cpp +++ b/src/core/fs/archive_sdmc.cpp @@ -1,14 +1,14 @@ #include "fs/archive_sdmc.hpp" #include -FSResult SDMCArchive::createFile(const FSPath& path, u64 size) { +HorizonResult SDMCArchive::createFile(const FSPath& path, u64 size) { Helpers::panic("[SDMC] CreateFile not yet supported"); - return FSResult::Success; + return Result::Success; } -FSResult SDMCArchive::deleteFile(const FSPath& path) { +HorizonResult SDMCArchive::deleteFile(const FSPath& path) { Helpers::panic("[SDMC] Unimplemented DeleteFile"); - return FSResult::Success; + return Result::Success; } FileDescriptor SDMCArchive::openFile(const FSPath& path, const FilePerms& perms) { @@ -16,9 +16,9 @@ FileDescriptor SDMCArchive::openFile(const FSPath& path, const FilePerms& perms) return FileError; } -Rust::Result SDMCArchive::openArchive(const FSPath& path) { +Rust::Result SDMCArchive::openArchive(const FSPath& path) { printf("SDMCArchive::OpenArchive: Failed\n"); - return Err(FSResult::NotFormatted); + return Err(Result::FS::NotFormatted); } std::optional SDMCArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) { diff --git a/src/core/fs/archive_self_ncch.cpp b/src/core/fs/archive_self_ncch.cpp index 0447ce8c..2146c578 100644 --- a/src/core/fs/archive_self_ncch.cpp +++ b/src/core/fs/archive_self_ncch.cpp @@ -9,14 +9,14 @@ namespace PathType { }; }; -FSResult SelfNCCHArchive::createFile(const FSPath& path, u64 size) { +HorizonResult SelfNCCHArchive::createFile(const FSPath& path, u64 size) { Helpers::panic("[SelfNCCH] CreateFile not yet supported"); - return FSResult::Success; + return Result::Success; } -FSResult SelfNCCHArchive::deleteFile(const FSPath& path) { +HorizonResult SelfNCCHArchive::deleteFile(const FSPath& path) { Helpers::panic("[SelfNCCH] Unimplemented DeleteFile"); - return FSResult::Success; + return Result::Success; } FileDescriptor SelfNCCHArchive::openFile(const FSPath& path, const FilePerms& perms) { @@ -40,10 +40,10 @@ FileDescriptor SelfNCCHArchive::openFile(const FSPath& path, const FilePerms& pe return NoFile; // No file descriptor needed for RomFS } -Rust::Result SelfNCCHArchive::openArchive(const FSPath& path) { +Rust::Result SelfNCCHArchive::openArchive(const FSPath& path) { if (path.type != PathType::Empty) { Helpers::panic("Invalid path type for SelfNCCH archive: %d\n", path.type); - return Err(FSResult::NotFoundInvalid); + return Err(Result::FS::NotFoundInvalid); } return Ok((ArchiveBase*)this); diff --git a/src/core/kernel/address_arbiter.cpp b/src/core/kernel/address_arbiter.cpp index 24e73cfe..9fb9f7be 100644 --- a/src/core/kernel/address_arbiter.cpp +++ b/src/core/kernel/address_arbiter.cpp @@ -26,7 +26,7 @@ Handle Kernel::makeArbiter() { // Result CreateAddressArbiter(Handle* arbiter) void Kernel::createAddressArbiter() { logSVC("CreateAddressArbiter\n"); - regs[0] = SVCResult::Success; + regs[0] = Result::Success; regs[1] = makeArbiter(); } @@ -43,7 +43,7 @@ void Kernel::arbitrateAddress() { const auto arbiter = getObject(handle, KernelObjectType::AddressArbiter); if (arbiter == nullptr) [[unlikely]] { - regs[0] = SVCResult::BadHandle; + regs[0] = Result::Kernel::InvalidHandle; return; } @@ -52,16 +52,16 @@ void Kernel::arbitrateAddress() { } if (type > 4) [[unlikely]] { - regs[0] = SVCResult::InvalidEnumValueAlt; + regs[0] = Result::FND::InvalidEnumValue; return; } // This needs to put the error code in r0 before we change threads - regs[0] = SVCResult::Success; + regs[0] = Result::Success; switch (static_cast(type)) { // Puts this thread to sleep if word < value until another thread arbitrates the address using SIGNAL case ArbitrationType::WaitIfLess: { - s32 word = static_cast(mem.read32(address)); // Yes this is meant to be signed + s32 word = static_cast(mem.read32(address)); // Yes this is meant to be signed if (word < value) { sleepThreadOnArbiter(address); } @@ -71,7 +71,7 @@ void Kernel::arbitrateAddress() { // Puts this thread to sleep if word < value until another thread arbitrates the address using SIGNAL // If the thread is put to sleep, the arbiter address is decremented case ArbitrationType::DecrementAndWaitIfLess: { - s32 word = static_cast(mem.read32(address)); // Yes this is meant to be signed + s32 word = static_cast(mem.read32(address)); // Yes this is meant to be signed if (word < value) { mem.write32(address, word - 1); sleepThreadOnArbiter(address); diff --git a/src/core/kernel/directory_operations.cpp b/src/core/kernel/directory_operations.cpp index 44d79111..567d9cb8 100644 --- a/src/core/kernel/directory_operations.cpp +++ b/src/core/kernel/directory_operations.cpp @@ -7,12 +7,6 @@ namespace DirectoryOps { }; } -namespace Result { - enum : u32 { - Success = 0 - }; -} - void Kernel::handleDirectoryOperation(u32 messagePointer, Handle directory) { const u32 cmd = mem.read32(messagePointer); switch (cmd) { diff --git a/src/core/kernel/events.cpp b/src/core/kernel/events.cpp index e395ab22..e117dd62 100644 --- a/src/core/kernel/events.cpp +++ b/src/core/kernel/events.cpp @@ -38,7 +38,7 @@ bool Kernel::signalEvent(Handle handle) { // One-shot events get cleared once they are acquired by some thread and only wake up 1 thread at a time if (event->resetType == ResetType::OneShot) { int index = wakeupOneThread(event->waitlist, handle); // Wake up one thread with the highest priority - event->waitlist ^= (1ull << index); // Remove thread from waitlist + event->waitlist ^= (1ull << index); // Remove thread from waitlist event->fired = false; } else { wakeupAllThreads(event->waitlist, handle); @@ -64,11 +64,11 @@ void Kernel::svcCreateEvent() { logSVC("CreateEvent(handle pointer = %08X, resetType = %s)\n", outPointer, resetTypeToString(resetType)); - regs[0] = SVCResult::Success; + regs[0] = Result::Success; regs[1] = makeEvent(static_cast(resetType)); } -// Result ClearEvent(Handle event) +// Result ClearEvent(Handle event) void Kernel::svcClearEvent() { const Handle handle = regs[0]; const auto event = getObject(handle, KernelObjectType::Event); @@ -76,15 +76,15 @@ void Kernel::svcClearEvent() { if (event == nullptr) [[unlikely]] { Helpers::panic("Tried to clear non-existent event (handle = %X)", handle); - regs[0] = SVCResult::BadHandle; + regs[0] = Result::Kernel::InvalidHandle; return; } event->getData()->fired = false; - regs[0] = SVCResult::Success; + regs[0] = Result::Success; } -// Result SignalEvent(Handle event) +// Result SignalEvent(Handle event) void Kernel::svcSignalEvent() { const Handle handle = regs[0]; logSVC("SignalEvent(event handle = %X)\n", handle); @@ -92,15 +92,15 @@ void Kernel::svcSignalEvent() { if (object == nullptr) { Helpers::panic("Signalled non-existent event: %X\n", handle); - regs[0] = SVCResult::BadHandle; + regs[0] = Result::Kernel::InvalidHandle; } else { // We must signalEvent after setting r0, otherwise the r0 of the new thread will ne corrupted - regs[0] = SVCResult::Success; + regs[0] = Result::Success; signalEvent(handle); } } -// Result WaitSynchronization1(Handle handle, s64 timeout_nanoseconds) +// Result WaitSynchronization1(Handle handle, s64 timeout_nanoseconds) void Kernel::waitSynchronization1() { const Handle handle = regs[0]; const s64 ns = s64(u64(regs[1]) | (u64(regs[2]) << 32)); @@ -110,7 +110,7 @@ void Kernel::waitSynchronization1() { if (object == nullptr) [[unlikely]] { Helpers::panic("WaitSynchronization1: Bad event handle %X\n", handle); - regs[0] = SVCResult::BadHandle; + regs[0] = Result::Kernel::InvalidHandle; return; } @@ -120,16 +120,16 @@ void Kernel::waitSynchronization1() { if (!shouldWaitOnObject(object)) { acquireSyncObject(object, threads[currentThreadIndex]); // Acquire the object since it's ready - regs[0] = SVCResult::Success; + regs[0] = Result::Success; rescheduleThreads(); } else { // Timeout is 0, don't bother waiting, instantly timeout if (ns == 0) { - regs[0] = SVCResult::Timeout; + regs[0] = Result::OS::Timeout; return; } - regs[0] = SVCResult::Timeout; // This will be overwritten with success if we don't timeout + regs[0] = Result::OS::Timeout; // This will be overwritten with success if we don't timeout auto& t = threads[currentThreadIndex]; t.waitList.resize(1); @@ -180,7 +180,7 @@ void Kernel::waitSynchronizationN() { // Panic if one of the objects is not even an object if (object == nullptr) [[unlikely]] { Helpers::panic("WaitSynchronizationN: Bad object handle %X\n", handle); - regs[0] = SVCResult::BadHandle; + regs[0] = Result::Kernel::InvalidHandle; return; } @@ -206,16 +206,16 @@ void Kernel::waitSynchronizationN() { // We only need to wait on one object. Easy...?! if (!waitAll) { - // If there's ready objects, acquire the first one and return + // If there's ready objects, acquire the first one and return if (oneObjectReady) { - regs[0] = SVCResult::Success; + regs[0] = Result::Success; regs[1] = firstReadyObjectIndex; // Return index of the acquired object acquireSyncObject(waitObjects[firstReadyObjectIndex].second, t); // Acquire object rescheduleThreads(); return; } - regs[0] = SVCResult::Timeout; // This will be overwritten with success if we don't timeout + regs[0] = Result::OS::Timeout; // This will be overwritten with success if we don't timeout // If the thread wakes up without timeout, this will be adjusted to the index of the handle that woke us up regs[1] = 0xFFFFFFFF; t.waitList.resize(handleCount); @@ -223,7 +223,7 @@ void Kernel::waitSynchronizationN() { t.outPointer = outPointer; t.waitingNanoseconds = ns; t.sleepTick = cpu.getTicks(); - + for (s32 i = 0; i < handleCount; i++) { t.waitList[i] = waitObjects[i].first; // Add object to this thread's waitlist waitObjects[i].second->getWaitlist() |= (1ull << currentThreadIndex); // And add the thread to the object's waitlist diff --git a/src/core/kernel/file_operations.cpp b/src/core/kernel/file_operations.cpp index d3d01bb7..455e9fc2 100644 --- a/src/core/kernel/file_operations.cpp +++ b/src/core/kernel/file_operations.cpp @@ -14,12 +14,6 @@ namespace FileOps { }; } -namespace Result { - enum : u32 { - Success = 0 - }; -} - void Kernel::handleFileOperation(u32 messagePointer, Handle file) { const u32 cmd = mem.read32(messagePointer); @@ -90,7 +84,7 @@ void Kernel::readFile(u32 messagePointer, Handle fileHandle) { if (!file->isOpen) { Helpers::panic("Tried to read closed file"); } - + // Handle files with their own file descriptors by just fread'ing the data if (file->fd) { std::unique_ptr data(new u8[size]); diff --git a/src/core/kernel/kernel.cpp b/src/core/kernel/kernel.cpp index f93dd386..1402b468 100644 --- a/src/core/kernel/kernel.cpp +++ b/src/core/kernel/kernel.cpp @@ -149,7 +149,7 @@ u32 Kernel::getTLSPointer() { // Result CloseHandle(Handle handle) void Kernel::svcCloseHandle() { logSVC("CloseHandle(handle = %d) (Unimplemented)\n", regs[0]); - regs[0] = SVCResult::Success; + regs[0] = Result::Success; } // u64 GetSystemTick() @@ -169,7 +169,7 @@ void Kernel::outputDebugString() { std::string message = mem.readString(pointer, size); logDebugString("[OutputDebugString] %s\n", message.c_str()); - regs[0] = SVCResult::Success; + regs[0] = Result::Success; } void Kernel::getProcessID() { @@ -178,11 +178,11 @@ void Kernel::getProcessID() { logSVC("GetProcessID(process: %s)\n", getProcessName(pid).c_str()); if (process == nullptr) [[unlikely]] { - regs[0] = SVCResult::BadHandle; + regs[0] = Result::Kernel::InvalidHandle; return; } - regs[0] = SVCResult::Success; + regs[0] = Result::Success; regs[1] = process->getData()->id; } @@ -194,7 +194,7 @@ void Kernel::getProcessInfo() { logSVC("GetProcessInfo(process: %s, type = %d)\n", getProcessName(pid).c_str(), type); if (process == nullptr) [[unlikely]] { - regs[0] = SVCResult::BadHandle; + regs[0] = Result::Kernel::InvalidHandle; return; } @@ -215,7 +215,7 @@ void Kernel::getProcessInfo() { Helpers::panic("GetProcessInfo: unimplemented type %d", type); } - regs[0] = SVCResult::Success; + regs[0] = Result::Success; } // Result DuplicateHandle(Handle* out, Handle original) @@ -224,7 +224,7 @@ void Kernel::duplicateHandle() { logSVC("DuplicateHandle(handle = %X)\n", original); if (original == KernelHandles::CurrentThread) { - regs[0] = SVCResult::Success; + regs[0] = Result::Success; Handle ret = makeObject(KernelObjectType::Thread); objects[ret].data = &threads[currentThreadIndex]; diff --git a/src/core/kernel/memory_management.cpp b/src/core/kernel/memory_management.cpp index 18aa93a6..99d72bd6 100644 --- a/src/core/kernel/memory_management.cpp +++ b/src/core/kernel/memory_management.cpp @@ -36,7 +36,7 @@ static constexpr bool isAligned(u32 value) { return (value & 0xFFF) == 0; } -// Result ControlMemory(u32* outaddr, u32 addr0, u32 addr1, u32 size, +// Result ControlMemory(u32* outaddr, u32 addr0, u32 addr1, u32 size, // MemoryOperation operation, MemoryPermission permissions) // This has a weird ABI documented here https://www.3dbrew.org/wiki/Kernel_ABI // TODO: Does this need to write to outaddr? @@ -64,7 +64,7 @@ void Kernel::controlMemory() { if (!isAligned(addr0) || !isAligned(addr1) || !isAligned(size)) { Helpers::panic("ControlMemory: Unaligned parameters\nAddr0: %08X\nAddr1: %08X\nSize: %08X", addr0, addr1, size); } - + logSVC("ControlMemory(addr0 = %08X, addr1 = %08X, size = %08X, operation = %X (%c%c%c)%s\n", addr0, addr1, size, operation, r ? 'r' : '-', w ? 'w' : '-', x ? 'x' : '-', linear ? ", linear" : "" ); @@ -90,7 +90,7 @@ void Kernel::controlMemory() { default: Helpers::panic("ControlMemory: unknown operation %X\n", operation); } - regs[0] = SVCResult::Success; + regs[0] = Result::Success; } // Result QueryMemory(MemoryInfo* memInfo, PageInfo* pageInfo, u32 addr) @@ -102,7 +102,7 @@ void Kernel::queryMemory() { logSVC("QueryMemory(mem info pointer = %08X, page info pointer = %08X, addr = %08X)\n", memInfo, pageInfo, addr); const auto info = mem.queryMemory(addr); - regs[0] = SVCResult::Success; + regs[0] = Result::Success; regs[1] = info.baseAddr; regs[2] = info.size; regs[3] = info.perms; @@ -110,7 +110,7 @@ void Kernel::queryMemory() { regs[5] = 0; // page flags } -// Result MapMemoryBlock(Handle memblock, u32 addr, MemoryPermission myPermissions, MemoryPermission otherPermission) +// Result MapMemoryBlock(Handle memblock, u32 addr, MemoryPermission myPermissions, MemoryPermission otherPermission) void Kernel::mapMemoryBlock() { const Handle block = regs[0]; u32 addr = regs[1]; @@ -146,7 +146,7 @@ void Kernel::mapMemoryBlock() { Helpers::panic("MapMemoryBlock where the handle does not refer to a known piece of kernel shared mem"); } - regs[0] = SVCResult::Success; + regs[0] = Result::Success; } Handle Kernel::makeMemoryBlock(u32 addr, u32 size, u32 myPermission, u32 otherPermission) { @@ -180,13 +180,13 @@ void Kernel::createMemoryBlock() { // Throw error if the size of the shared memory block is not aligned to page boundary if (!isAligned(size)) { - regs[0] = SVCResult::UnalignedSize; + regs[0] = Result::OS::MisalignedSize; return; } // Throw error if one of the permissions is not valid if (!isPermValid(myPermission) || !isPermValid(otherPermission)) { - regs[0] = SVCResult::InvalidCombination; + regs[0] = Result::OS::InvalidCombination; return; } @@ -199,6 +199,6 @@ void Kernel::createMemoryBlock() { if (myPermission == MemoryPermissions::DontCare) myPermission = MemoryPermissions::ReadWrite; if (otherPermission == MemoryPermissions::DontCare) otherPermission = MemoryPermissions::ReadWrite; - regs[0] = SVCResult::Success; + regs[0] = Result::Success; regs[1] = makeMemoryBlock(addr, size, myPermission, otherPermission); } \ No newline at end of file diff --git a/src/core/kernel/ports.cpp b/src/core/kernel/ports.cpp index 71446454..a7351fd0 100644 --- a/src/core/kernel/ports.cpp +++ b/src/core/kernel/ports.cpp @@ -43,7 +43,7 @@ void Kernel::connectToPort() { if (port.size() > Port::maxNameLen) { Helpers::panic("ConnectToPort: Port name too long\n"); - regs[0] = SVCResult::PortNameTooLong; + regs[0] = Result::OS::PortNameTooLong; return; } @@ -51,7 +51,7 @@ void Kernel::connectToPort() { std::optional optionalHandle = getPortHandle(port.c_str()); if (!optionalHandle.has_value()) [[unlikely]] { Helpers::panic("ConnectToPort: Port doesn't exist\n"); - regs[0] = SVCResult::ObjectNotFound; + regs[0] = Result::Kernel::NotFound; return; } @@ -65,7 +65,7 @@ void Kernel::connectToPort() { // TODO: Actually create session Handle sessionHandle = makeSession(portHandle); - regs[0] = SVCResult::Success; + regs[0] = Result::Success; regs[1] = sessionHandle; } @@ -80,7 +80,7 @@ void Kernel::sendSyncRequest() { if (KernelHandles::isServiceHandle(handle)) { // The service call might cause a reschedule and change threads. Hence, set r0 before executing the service call // Because if the service call goes first, we might corrupt the new thread's r0!! - regs[0] = SVCResult::Success; + regs[0] = Result::Success; serviceManager.sendCommandToService(messagePointer, handle); return; } @@ -88,7 +88,7 @@ void Kernel::sendSyncRequest() { // Check if our sync request is targetting a file instead of a service bool isFileOperation = getObject(handle, KernelObjectType::File) != nullptr; if (isFileOperation) { - regs[0] = SVCResult::Success; // r0 goes first here too + regs[0] = Result::Success; // r0 goes first here too handleFileOperation(messagePointer, handle); return; } @@ -96,7 +96,7 @@ void Kernel::sendSyncRequest() { // Check if our sync request is targetting a directory instead of a service bool isDirectoryOperation = getObject(handle, KernelObjectType::Directory) != nullptr; if (isDirectoryOperation) { - regs[0] = SVCResult::Success; // r0 goes first here too + regs[0] = Result::Success; // r0 goes first here too handleDirectoryOperation(messagePointer, handle); return; } @@ -105,7 +105,7 @@ void Kernel::sendSyncRequest() { const auto session = getObject(handle, KernelObjectType::Session); if (session == nullptr) [[unlikely]] { Helpers::panic("SendSyncRequest: Invalid handle"); - regs[0] = SVCResult::BadHandle; + regs[0] = Result::Kernel::InvalidHandle; return; } @@ -113,10 +113,10 @@ void Kernel::sendSyncRequest() { const Handle portHandle = sessionData->portHandle; if (portHandle == srvHandle) { // Special-case SendSyncRequest targetting the "srv: port" - regs[0] = SVCResult::Success; + regs[0] = Result::Success; serviceManager.handleSyncRequest(messagePointer); } else if (portHandle == errorPortHandle) { // Special-case "err:f" for juicy logs too - regs[0] = SVCResult::Success; + regs[0] = Result::Success; handleErrorSyncRequest(messagePointer); } else { const auto portData = objects[portHandle].getData(); diff --git a/src/core/kernel/resource_limits.cpp b/src/core/kernel/resource_limits.cpp index 11497a0b..8c6d8565 100644 --- a/src/core/kernel/resource_limits.cpp +++ b/src/core/kernel/resource_limits.cpp @@ -10,13 +10,13 @@ void Kernel::getResourceLimit() { logSVC("GetResourceLimit (handle pointer = %08X, process: %s)\n", handlePointer, getProcessName(pid).c_str()); if (process == nullptr) [[unlikely]] { - regs[0] = SVCResult::BadHandle; + regs[0] = Result::Kernel::InvalidHandle; return; } const auto processData = static_cast(process->data); - regs[0] = SVCResult::Success; + regs[0] = Result::Success; regs[1] = processData->limits.handle; } @@ -29,7 +29,7 @@ void Kernel::getResourceLimitLimitValues() { const KernelObject* limit = getObject(resourceLimit, KernelObjectType::ResourceLimit); if (limit == nullptr) [[unlikely]] { - regs[0] = SVCResult::BadHandle; + regs[0] = Result::Kernel::InvalidHandle; return; } @@ -46,7 +46,7 @@ void Kernel::getResourceLimitLimitValues() { count--; } - regs[0] = SVCResult::Success; + regs[0] = Result::Success; } // Result GetResourceLimitCurrentValues(s64* values, Handle resourceLimit, LimitableResource* names, s32 nameCount) @@ -59,7 +59,7 @@ void Kernel::getResourceLimitCurrentValues() { const KernelObject* limit = getObject(resourceLimit, KernelObjectType::ResourceLimit); if (limit == nullptr) [[unlikely]] { - regs[0] = SVCResult::BadHandle; + regs[0] = Result::Kernel::InvalidHandle; return; } @@ -75,7 +75,7 @@ void Kernel::getResourceLimitCurrentValues() { count--; } - regs[0] = SVCResult::Success; + regs[0] = Result::Success; } s32 Kernel::getCurrentResourceValue(const KernelObject* limit, u32 resourceName) { diff --git a/src/core/kernel/threads.cpp b/src/core/kernel/threads.cpp index f41de34b..cf6b2cac 100644 --- a/src/core/kernel/threads.cpp +++ b/src/core/kernel/threads.cpp @@ -49,7 +49,7 @@ void Kernel::sortThreads() { bool Kernel::canThreadRun(const Thread& t) { if (t.status == ThreadStatus::Ready) { return true; - } else if (t.status == ThreadStatus::WaitSleep || t.status == ThreadStatus::WaitSync1 + } else if (t.status == ThreadStatus::WaitSleep || t.status == ThreadStatus::WaitSync1 || t.status == ThreadStatus::WaitSyncAny || t.status == ThreadStatus::WaitSyncAll) { const u64 elapsedTicks = cpu.getTicks() - t.sleepTick; @@ -83,7 +83,7 @@ std::optional Kernel::getNextThread() { void Kernel::switchToNextThread() { std::optional newThreadIndex = getNextThread(); - + if (!newThreadIndex.has_value()) { log("Kernel tried to switch to the next thread but none found. Switching to random thread\n"); assert(aliveThreadCount != 0); @@ -103,7 +103,7 @@ void Kernel::switchToNextThread() { // See if there;s a higher priority, ready thread and switch to that void Kernel::rescheduleThreads() { std::optional newThreadIndex = getNextThread(); - + if (newThreadIndex.has_value() && newThreadIndex.value() != currentThreadIndex) { threads[currentThreadIndex].status = ThreadStatus::Ready; switchThread(newThreadIndex.value()); @@ -275,12 +275,12 @@ int Kernel::wakeupOneThread(u64 waitlist, Handle handle) { switch (t.status) { case ThreadStatus::WaitSync1: t.status = ThreadStatus::Ready; - t.gprs[0] = SVCResult::Success; // The thread did not timeout, so write success to r0 + t.gprs[0] = Result::Success; // The thread did not timeout, so write success to r0 break; case ThreadStatus::WaitSyncAny: t.status = ThreadStatus::Ready; - t.gprs[0] = SVCResult::Success; // The thread did not timeout, so write success to r0 + t.gprs[0] = Result::Success; // The thread did not timeout, so write success to r0 // Get the index of the event in the object's waitlist, write it to r1 for (size_t i = 0; i < t.waitList.size(); i++) { @@ -310,12 +310,12 @@ void Kernel::wakeupAllThreads(u64 waitlist, Handle handle) { switch (t.status) { case ThreadStatus::WaitSync1: t.status = ThreadStatus::Ready; - t.gprs[0] = SVCResult::Success; // The thread did not timeout, so write success to r0 + t.gprs[0] = Result::Success; // The thread did not timeout, so write success to r0 break; case ThreadStatus::WaitSyncAny: t.status = ThreadStatus::Ready; - t.gprs[0] = SVCResult::Success; // The thread did not timeout, so write success to r0 + t.gprs[0] = Result::Success; // The thread did not timeout, so write success to r0 // Get the index of the event in the object's waitlist, write it to r1 for (size_t i = 0; i < t.waitList.size(); i++) { @@ -354,7 +354,7 @@ void Kernel::sleepThread(s64 ns) { } } -// Result CreateThread(s32 priority, ThreadFunc entrypoint, u32 arg, u32 stacktop, s32 threadPriority, s32 processorID) +// Result CreateThread(s32 priority, ThreadFunc entrypoint, u32 arg, u32 stacktop, s32 threadPriority, s32 processorID) void Kernel::createThread() { u32 priority = regs[0]; u32 entrypoint = regs[1]; @@ -367,11 +367,11 @@ void Kernel::createThread() { if (priority > 0x3F) [[unlikely]] { Helpers::panic("Created thread with bad priority value %X", priority); - regs[0] = SVCResult::BadThreadPriority; + regs[0] = Result::OS::OutOfRange; return; } - regs[0] = SVCResult::Success; + regs[0] = Result::Success; regs[1] = makeThread(entrypoint, initialSP, priority, id, arg, ThreadStatus::Ready); rescheduleThreads(); } @@ -381,7 +381,7 @@ void Kernel::svcSleepThread() { const s64 ns = s64(u64(regs[0]) | (u64(regs[1]) << 32)); //logSVC("SleepThread(ns = %lld)\n", ns); - regs[0] = SVCResult::Success; + regs[0] = Result::Success; sleepThread(ns); } @@ -390,18 +390,18 @@ void Kernel::getThreadID() { logSVC("GetThreadID(handle = %X)\n", handle); if (handle == KernelHandles::CurrentThread) { - regs[0] = SVCResult::Success; + regs[0] = Result::Success; regs[1] = currentThreadIndex; return; } const auto thread = getObject(handle, KernelObjectType::Thread); if (thread == nullptr) [[unlikely]] { - regs[0] = SVCResult::BadHandle; + regs[0] = Result::Kernel::InvalidHandle; return; } - regs[0] = SVCResult::Success; + regs[0] = Result::Success; regs[1] = thread->getData()->index; } @@ -410,14 +410,14 @@ void Kernel::getThreadPriority() { logSVC("GetThreadPriority (handle = %X)\n", handle); if (handle == KernelHandles::CurrentThread) { - regs[0] = SVCResult::Success; + regs[0] = Result::Success; regs[1] = threads[currentThreadIndex].priority; } else { auto object = getObject(handle, KernelObjectType::Thread); if (object == nullptr) [[unlikely]] { - regs[0] = SVCResult::BadHandle; + regs[0] = Result::Kernel::InvalidHandle; } else { - regs[0] = SVCResult::Success; + regs[0] = Result::Success; regs[1] = object->getData()->priority; } } @@ -429,20 +429,20 @@ void Kernel::setThreadPriority() { logSVC("SetThreadPriority (handle = %X, priority = %X)\n", handle, priority); if (priority > 0x3F) { - regs[0] = SVCResult::BadThreadPriority; + regs[0] = Result::OS::OutOfRange; return; } if (handle == KernelHandles::CurrentThread) { - regs[0] = SVCResult::Success; + regs[0] = Result::Success; threads[currentThreadIndex].priority = priority; } else { auto object = getObject(handle, KernelObjectType::Thread); if (object == nullptr) [[unlikely]] { - regs[0] = SVCResult::BadHandle; + regs[0] = Result::Kernel::InvalidHandle; return; } else { - regs[0] = SVCResult::Success; + regs[0] = Result::Success; object->getData()->priority = priority; } } @@ -478,7 +478,7 @@ void Kernel::svcCreateMutex() { bool locked = regs[1] != 0; logSVC("CreateMutex (locked = %s)\n", locked ? "yes" : "no"); - regs[0] = SVCResult::Success; + regs[0] = Result::Success; regs[1] = makeMutex(locked); } @@ -489,18 +489,18 @@ void Kernel::svcReleaseMutex() { const auto object = getObject(handle, KernelObjectType::Mutex); if (object == nullptr) [[unlikely]] { Helpers::panic("Tried to release non-existent mutex"); - regs[0] = SVCResult::BadHandle; + regs[0] = Result::Kernel::InvalidHandle; return; } Mutex* moo = object->getData(); // A thread can't release a mutex it does not own if (!moo->locked || moo->ownerThread != currentThreadIndex) { - regs[0] = SVCResult::InvalidMutexRelease; + regs[0] = Result::Kernel::InvalidMutexRelease; return; } - regs[0] = SVCResult::Success; + regs[0] = Result::Success; releaseMutex(moo); } @@ -515,7 +515,7 @@ void Kernel::svcCreateSemaphore() { if (initialCount < 0 || maxCount < 0) Helpers::panic("CreateSemaphore: Negative count value"); - regs[0] = SVCResult::Success; + regs[0] = Result::Success; regs[1] = makeSemaphore(initialCount, maxCount); } @@ -527,7 +527,7 @@ void Kernel::svcReleaseSemaphore() { const auto object = getObject(handle, KernelObjectType::Semaphore); if (object == nullptr) [[unlikely]] { Helpers::panic("Tried to release non-existent semaphore"); - regs[0] = SVCResult::BadHandle; + regs[0] = Result::Kernel::InvalidHandle; return; } @@ -539,7 +539,7 @@ void Kernel::svcReleaseSemaphore() { Helpers::panic("ReleaseSemaphore: Release count too high"); // Write success and old available count to r0 and r1 respectively - regs[0] = SVCResult::Success; + regs[0] = Result::Success; regs[1] = s->availableCount; // Bump available count s->availableCount += releaseCount; diff --git a/src/core/services/ac.cpp b/src/core/services/ac.cpp index 66452534..4c533e05 100644 --- a/src/core/services/ac.cpp +++ b/src/core/services/ac.cpp @@ -7,12 +7,6 @@ namespace ACCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void ACService::reset() {} void ACService::handleSyncRequest(u32 messagePointer) { diff --git a/src/core/services/act.cpp b/src/core/services/act.cpp index 7f2f34f7..d8a5a802 100644 --- a/src/core/services/act.cpp +++ b/src/core/services/act.cpp @@ -7,12 +7,6 @@ namespace ACTCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void ACTService::reset() {} void ACTService::handleSyncRequest(u32 messagePointer) { diff --git a/src/core/services/am.cpp b/src/core/services/am.cpp index 9db92df5..5e2956d8 100644 --- a/src/core/services/am.cpp +++ b/src/core/services/am.cpp @@ -8,12 +8,6 @@ namespace AMCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void AMService::reset() {} void AMService::handleSyncRequest(u32 messagePointer) { diff --git a/src/core/services/apt.cpp b/src/core/services/apt.cpp index 637a922f..f2c7612d 100644 --- a/src/core/services/apt.cpp +++ b/src/core/services/apt.cpp @@ -25,12 +25,6 @@ namespace APTCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - // https://www.3dbrew.org/wiki/NS_and_APT_Services#Command namespace APTTransitions { enum : u32 { @@ -154,7 +148,7 @@ void APTService::inquireNotification(u32 messagePointer) { mem.write32(messagePointer, IPC::responseHeader(0xB, 2, 0)); mem.write32(messagePointer + 4, Result::Success); - mem.write32(messagePointer + 8, static_cast(NotificationType::None)); + mem.write32(messagePointer + 8, static_cast(NotificationType::None)); } void APTService::getLockHandle(u32 messagePointer) { diff --git a/src/core/services/boss.cpp b/src/core/services/boss.cpp index f43aa5f3..ee3ad8a6 100644 --- a/src/core/services/boss.cpp +++ b/src/core/services/boss.cpp @@ -14,12 +14,6 @@ namespace BOSSCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void BOSSService::reset() { optoutFlag = 0; } diff --git a/src/core/services/cam.cpp b/src/core/services/cam.cpp index db62aec3..ea21cf9d 100644 --- a/src/core/services/cam.cpp +++ b/src/core/services/cam.cpp @@ -8,12 +8,6 @@ namespace CAMCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void CAMService::reset() {} void CAMService::handleSyncRequest(u32 messagePointer) { diff --git a/src/core/services/cecd.cpp b/src/core/services/cecd.cpp index 56936acf..f641e40d 100644 --- a/src/core/services/cecd.cpp +++ b/src/core/services/cecd.cpp @@ -8,12 +8,6 @@ namespace CECDCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void CECDService::reset() { infoEvent = std::nullopt; } diff --git a/src/core/services/cfg.cpp b/src/core/services/cfg.cpp index 0dfd7233..ab969183 100644 --- a/src/core/services/cfg.cpp +++ b/src/core/services/cfg.cpp @@ -16,12 +16,6 @@ namespace CFGCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void CFGService::reset() {} void CFGService::handleSyncRequest(u32 messagePointer) { @@ -89,7 +83,7 @@ void CFGService::getConfigInfoBlk2(u32 messagePointer) { } else if (size == 4 && blockID == 0xD0000) { // Agreed EULA version (first 2 bytes) and latest EULA version (next 2 bytes) log("Read EULA info\n"); mem.write16(output, 0x0202); // Agreed EULA version = 2.2 (Random number. TODO: Check) - mem.write16(output + 2, 0x0202); // Latest EULA version = 2.2 + mem.write16(output + 2, 0x0202); // Latest EULA version = 2.2 } else if (size == 0x800 && blockID == 0xB0001) { // UTF-16 name for our country in every language at 0x80 byte intervals constexpr size_t languageCount = 16; constexpr size_t nameSize = 0x80; // Max size of each name in bytes @@ -105,7 +99,7 @@ void CFGService::getConfigInfoBlk2(u32 messagePointer) { std::u16string name = u"Pandington"; // Note: This + the null terminator needs to fit in 0x80 bytes for (int i = 0; i < languageCount; i++) { - u32 pointer = output + i * nameSize; + u32 pointer = output + i * nameSize; writeStringU16(pointer, name); } } else if (size == 4 && blockID == 0xB0003) { // Coordinates (latidude and longtitude) as s16 diff --git a/src/core/services/dlp_srvr.cpp b/src/core/services/dlp_srvr.cpp index 3e465e21..e3ef25e9 100644 --- a/src/core/services/dlp_srvr.cpp +++ b/src/core/services/dlp_srvr.cpp @@ -7,12 +7,6 @@ namespace DlpSrvrCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void DlpSrvrService::reset() {} void DlpSrvrService::handleSyncRequest(u32 messagePointer) { diff --git a/src/core/services/dsp.cpp b/src/core/services/dsp.cpp index 17793c55..376a08a0 100644 --- a/src/core/services/dsp.cpp +++ b/src/core/services/dsp.cpp @@ -25,7 +25,6 @@ namespace DSPCommands { namespace Result { enum : u32 { - Success = 0, HeadphonesNotInserted = 0, HeadphonesInserted = 1 }; @@ -215,7 +214,7 @@ void DSPService::registerInterruptEvents(u32 messagePointer) { const u32 channel = mem.read32(messagePointer + 8); const u32 eventHandle = mem.read32(messagePointer + 16); log("DSP::RegisterInterruptEvents (interrupt = %d, channel = %d, event = %d)\n", interrupt, channel, eventHandle); - + // The event handle being 0 means we're removing an event if (eventHandle == 0) { DSPEvent& e = getEventRef(interrupt, channel); // Get event diff --git a/src/core/services/frd.cpp b/src/core/services/frd.cpp index 8af0f012..ad0c07dc 100644 --- a/src/core/services/frd.cpp +++ b/src/core/services/frd.cpp @@ -17,12 +17,6 @@ namespace FRDCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void FRDService::reset() {} void FRDService::handleSyncRequest(u32 messagePointer) { @@ -91,7 +85,7 @@ void FRDService::getMyProfile(u32 messagePointer) { mem.write32(messagePointer + 4, Result::Success); // TODO: Should maybe make these user-configurable. Not super important though - mem.write8(messagePointer + 8, static_cast(Regions::USA)); // Region + mem.write8(messagePointer + 8, static_cast(Regions::USA)); // Region mem.write8(messagePointer + 9, static_cast(CountryCodes::US)); // Country mem.write8(messagePointer + 10, 2); // Area (this should be Washington) mem.write8(messagePointer + 11, static_cast(LanguageCodes::English)); // Language diff --git a/src/core/services/fs.cpp b/src/core/services/fs.cpp index fe8bce8d..06c970f0 100644 --- a/src/core/services/fs.cpp +++ b/src/core/services/fs.cpp @@ -32,14 +32,6 @@ namespace FSCommands { }; } -namespace ResultCode { - enum : u32 { - Success = 0, - FileNotFound = 0xC8804464, // TODO: Verify this - Failure = 0xFFFFFFFF, - }; -} - void FSService::reset() { priority = 0; } @@ -96,15 +88,15 @@ std::optional FSService::openFileHandle(ArchiveBase* archive, const FSPa auto& file = kernel.getObjects()[handle]; file.data = new FileSession(archive, path, archivePath, opened.value()); - + return handle; } else { return std::nullopt; } } -Rust::Result FSService::openDirectoryHandle(ArchiveBase* archive, const FSPath& path) { - Rust::Result opened = archive->openDirectory(path); +Rust::Result FSService::openDirectoryHandle(ArchiveBase* archive, const FSPath& path) { + Rust::Result opened = archive->openDirectory(path); if (opened.isOk()) { // If opened doesn't have a value, we failed to open the directory auto handle = kernel.makeObject(KernelObjectType::Directory); auto& object = kernel.getObjects()[handle]; @@ -116,15 +108,15 @@ Rust::Result FSService::openDirectoryHandle(ArchiveBase* archi } } -Rust::Result FSService::openArchiveHandle(u32 archiveID, const FSPath& path) { +Rust::Result FSService::openArchiveHandle(u32 archiveID, const FSPath& path) { ArchiveBase* archive = getArchiveFromID(archiveID, path); if (archive == nullptr) [[unlikely]] { Helpers::panic("OpenArchive: Tried to open unknown archive %d.", archiveID); - return Err(FSResult::NotFormatted); + return Err(Result::FS::NotFormatted); } - Rust::Result res = archive->openArchive(path); + Rust::Result res = archive->openArchive(path); if (res.isOk()) { auto handle = kernel.makeObject(KernelObjectType::Archive); auto& archiveObject = kernel.getObjects()[handle]; @@ -175,7 +167,7 @@ void FSService::handleSyncRequest(u32 messagePointer) { void FSService::initialize(u32 messagePointer) { log("FS::Initialize\n"); mem.write32(messagePointer, IPC::responseHeader(0x801, 1, 0)); - mem.write32(messagePointer + 4, ResultCode::Success); + mem.write32(messagePointer + 4, Result::Success); } // TODO: Figure out how this is different from Initialize @@ -184,7 +176,7 @@ void FSService::initializeWithSdkVersion(u32 messagePointer) { log("FS::InitializeWithSDKVersion(version = %d)\n", version); mem.write32(messagePointer, IPC::responseHeader(0x861, 1, 0)); - mem.write32(messagePointer + 4, ResultCode::Success); + mem.write32(messagePointer + 4, Result::Success); } void FSService::closeArchive(u32 messagePointer) { @@ -196,10 +188,10 @@ void FSService::closeArchive(u32 messagePointer) { if (object == nullptr) { log("FSService::CloseArchive: Tried to close invalid archive %X\n", handle); - mem.write32(messagePointer + 4, ResultCode::Failure); + mem.write32(messagePointer + 4, Result::FailurePlaceholder); } else { object->getData()->isOpen = false; - mem.write32(messagePointer + 4, ResultCode::Success); + mem.write32(messagePointer + 4, Result::Success); } } @@ -211,15 +203,15 @@ void FSService::openArchive(u32 messagePointer) { auto archivePath = readPath(archivePathType, archivePathPointer, archivePathSize); log("FS::OpenArchive(archive ID = %d, archive path type = %d)\n", archiveID, archivePathType); - - Rust::Result res = openArchiveHandle(archiveID, archivePath); + + Rust::Result res = openArchiveHandle(archiveID, archivePath); mem.write32(messagePointer, IPC::responseHeader(0x80C, 3, 0)); if (res.isOk()) { - mem.write32(messagePointer + 4, ResultCode::Success); + mem.write32(messagePointer + 4, Result::Success); mem.write64(messagePointer + 8, res.unwrap()); } else { log("FS::OpenArchive: Failed to open archive with id = %d. Error %08X\n", archiveID, (u32)res.unwrapErr()); - mem.write32(messagePointer + 4, static_cast(res.unwrapErr())); + mem.write32(messagePointer + 4, res.unwrapErr()); mem.write64(messagePointer + 8, 0); } } @@ -237,7 +229,7 @@ void FSService::openFile(u32 messagePointer) { auto archiveObject = kernel.getObject(archiveHandle, KernelObjectType::Archive); if (archiveObject == nullptr) [[unlikely]] { log("FS::OpenFile: Invalid archive handle %d\n", archiveHandle); - mem.write32(messagePointer + 4, ResultCode::Failure); + mem.write32(messagePointer + 4, Result::FailurePlaceholder); return; } @@ -251,9 +243,9 @@ void FSService::openFile(u32 messagePointer) { mem.write32(messagePointer, IPC::responseHeader(0x802, 1, 2)); if (!handle.has_value()) { printf("OpenFile failed\n"); - mem.write32(messagePointer + 4, ResultCode::FileNotFound); + mem.write32(messagePointer + 4, Result::FS::FileNotFound); } else { - mem.write32(messagePointer + 4, ResultCode::Success); + mem.write32(messagePointer + 4, Result::Success); mem.write32(messagePointer + 8, 0x10); // "Move handle descriptor" mem.write32(messagePointer + 12, handle.value()); } @@ -270,13 +262,13 @@ void FSService::createDirectory(u32 messagePointer) { KernelObject* archiveObject = kernel.getObject(archiveHandle, KernelObjectType::Archive); if (archiveObject == nullptr) [[unlikely]] { log("FS::CreateDirectory: Invalid archive handle %d\n", archiveHandle); - mem.write32(messagePointer + 4, ResultCode::Failure); + mem.write32(messagePointer + 4, Result::FailurePlaceholder); return; } ArchiveBase* archive = archiveObject->getData()->archive; const auto dirPath = readPath(pathType, pathPointer, pathSize); - const FSResult res = archive->createDirectory(dirPath); + const Result::HorizonResult res = archive->createDirectory(dirPath); mem.write32(messagePointer, IPC::responseHeader(0x809, 1, 0)); mem.write32(messagePointer + 4, static_cast(res)); @@ -292,7 +284,7 @@ void FSService::openDirectory(u32 messagePointer) { KernelObject* archiveObject = kernel.getObject(archiveHandle, KernelObjectType::Archive); if (archiveObject == nullptr) [[unlikely]] { log("FS::OpenDirectory: Invalid archive handle %d\n", archiveHandle); - mem.write32(messagePointer + 4, ResultCode::Failure); + mem.write32(messagePointer + 4, Result::FailurePlaceholder); return; } @@ -302,7 +294,7 @@ void FSService::openDirectory(u32 messagePointer) { mem.write32(messagePointer, IPC::responseHeader(0x80B, 1, 2)); if (dir.isOk()) { - mem.write32(messagePointer + 4, ResultCode::Success); + mem.write32(messagePointer + 4, Result::Success); mem.write32(messagePointer + 12, dir.unwrap()); } else { printf("FS::OpenDirectory failed\n"); @@ -324,14 +316,14 @@ void FSService::openFileDirectly(u32 messagePointer) { auto archivePath = readPath(archivePathType, archivePathPointer, archivePathSize); ArchiveBase* archive = getArchiveFromID(archiveID, archivePath); - + if (archive == nullptr) [[unlikely]] { Helpers::panic("OpenFileDirectly: Tried to open unknown archive %d.", archiveID); } auto filePath = readPath(filePathType, filePathPointer, filePathSize); const FilePerms perms(openFlags); - Rust::Result res = archive->openArchive(archivePath); + Rust::Result res = archive->openArchive(archivePath); if (res.isErr()) [[unlikely]] { Helpers::panic("OpenFileDirectly: Failed to open archive with given path"); } @@ -342,7 +334,7 @@ void FSService::openFileDirectly(u32 messagePointer) { if (!handle.has_value()) { Helpers::panic("OpenFileDirectly: Failed to open file with given path"); } else { - mem.write32(messagePointer + 4, ResultCode::Success); + mem.write32(messagePointer + 4, Result::Success); mem.write32(messagePointer + 12, handle.value()); } } @@ -360,16 +352,16 @@ void FSService::createFile(u32 messagePointer) { auto archiveObject = kernel.getObject(archiveHandle, KernelObjectType::Archive); if (archiveObject == nullptr) [[unlikely]] { log("FS::OpenFile: Invalid archive handle %d\n", archiveHandle); - mem.write32(messagePointer + 4, ResultCode::Failure); + mem.write32(messagePointer + 4, Result::FailurePlaceholder); return; } ArchiveBase* archive = archiveObject->getData()->archive; auto filePath = readPath(filePathType, filePathPointer, filePathSize); - FSResult res = archive->createFile(filePath, size); + Result::HorizonResult res = archive->createFile(filePath, size); mem.write32(messagePointer, IPC::responseHeader(0x808, 1, 0)); - mem.write32(messagePointer + 4, static_cast(res)); + mem.write32(messagePointer + 4, res); } void FSService::deleteFile(u32 messagePointer) { @@ -382,14 +374,14 @@ void FSService::deleteFile(u32 messagePointer) { auto archiveObject = kernel.getObject(archiveHandle, KernelObjectType::Archive); if (archiveObject == nullptr) [[unlikely]] { log("FS::DeleteFile: Invalid archive handle %d\n", archiveHandle); - mem.write32(messagePointer + 4, ResultCode::Failure); + mem.write32(messagePointer + 4, Result::FailurePlaceholder); return; } ArchiveBase* archive = archiveObject->getData()->archive; auto filePath = readPath(filePathType, filePathPointer, filePathSize); - FSResult res = archive->deleteFile(filePath); + Result::HorizonResult res = archive->deleteFile(filePath); mem.write32(messagePointer, IPC::responseHeader(0x804, 1, 0)); mem.write32(messagePointer + 4, static_cast(res)); } @@ -409,12 +401,12 @@ void FSService::getFormatInfo(u32 messagePointer) { } mem.write32(messagePointer, IPC::responseHeader(0x845, 5, 0)); - Rust::Result res = archive->getFormatInfo(path); + Rust::Result res = archive->getFormatInfo(path); // If the FormatInfo was returned, write them to the output buffer. Otherwise, write an error code. if (res.isOk()) { ArchiveBase::FormatInfo info = res.unwrap(); - mem.write32(messagePointer + 4, ResultCode::Success); + mem.write32(messagePointer + 4, Result::Success); mem.write32(messagePointer + 8, info.size); mem.write32(messagePointer + 12, info.numOfDirectories); mem.write32(messagePointer + 16, info.numOfFiles); @@ -458,7 +450,7 @@ void FSService::formatSaveData(u32 messagePointer) { saveData.format(path, info); mem.write32(messagePointer, IPC::responseHeader(0x84C, 1, 0)); - mem.write32(messagePointer + 4, ResultCode::Success); + mem.write32(messagePointer + 4, Result::Success); } void FSService::formatThisUserSaveData(u32 messagePointer) { @@ -478,7 +470,7 @@ void FSService::formatThisUserSaveData(u32 messagePointer) { .duplicateData = duplicateData }; FSPath emptyPath; - + mem.write32(messagePointer, IPC::responseHeader(0x080F, 1, 0)); saveData.format(emptyPath, info); } @@ -497,13 +489,13 @@ void FSService::controlArchive(u32 messagePointer) { mem.write32(messagePointer, IPC::responseHeader(0x80D, 1, 0)); if (archiveObject == nullptr) [[unlikely]] { log("FS::ControlArchive: Invalid archive handle %d\n", archiveHandle); - mem.write32(messagePointer + 4, ResultCode::Failure); + mem.write32(messagePointer + 4, Result::FailurePlaceholder); return; } switch (action) { case 0: // Commit save data changes. Shouldn't need us to do anything - mem.write32(messagePointer + 4, ResultCode::Success); + mem.write32(messagePointer + 4, Result::Success); break; default: Helpers::panic("Unimplemented action for ControlArchive (action = %X)\n", action); @@ -519,7 +511,7 @@ void FSService::getFreeBytes(u32 messagePointer) { mem.write32(messagePointer, IPC::responseHeader(0x812, 3, 0)); if (session == nullptr) [[unlikely]] { log("FS::GetFreeBytes: Invalid archive handle %d\n", archiveHandle); - mem.write32(messagePointer + 4, ResultCode::Failure); + mem.write32(messagePointer + 4, Result::FailurePlaceholder); return; } @@ -531,7 +523,7 @@ void FSService::getPriority(u32 messagePointer) { log("FS::GetPriority\n"); mem.write32(messagePointer, IPC::responseHeader(0x863, 2, 0)); - mem.write32(messagePointer + 4, ResultCode::Success); + mem.write32(messagePointer + 4, Result::Success); mem.write32(messagePointer + 8, priority); } @@ -540,13 +532,13 @@ void FSService::setPriority(u32 messagePointer) { log("FS::SetPriority (priority = %d)\n", value); mem.write32(messagePointer, IPC::responseHeader(0x862, 1, 0)); - mem.write32(messagePointer + 4, ResultCode::Success); + mem.write32(messagePointer + 4, Result::Success); priority = value; } void FSService::isSdmcDetected(u32 messagePointer) { log("FS::IsSdmcDetected\n"); mem.write32(messagePointer, IPC::responseHeader(0x817, 2, 0)); - mem.write32(messagePointer + 4, ResultCode::Success); + mem.write32(messagePointer + 4, Result::Success); mem.write32(messagePointer + 8, 0); // Whether SD is detected. For now we emulate a 3DS without an SD. } \ No newline at end of file diff --git a/src/core/services/gsp_gpu.cpp b/src/core/services/gsp_gpu.cpp index 76d2f4a5..f3374263 100644 --- a/src/core/services/gsp_gpu.cpp +++ b/src/core/services/gsp_gpu.cpp @@ -30,13 +30,6 @@ namespace GXCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - SuccessRegisterIRQ = 0x2A07 // TODO: Is this a reference to the Ricoh 2A07 used in PAL NES systems? - }; -} - void GPUService::reset() { privilegedProcess = 0xFFFFFFFF; // Set the privileged process to an invalid handle interruptEvent = std::nullopt; @@ -100,7 +93,7 @@ void GPUService::registerInterruptRelayQueue(u32 messagePointer) { } mem.write32(messagePointer, IPC::responseHeader(0x13, 2, 2)); - mem.write32(messagePointer + 4, Result::SuccessRegisterIRQ); // First init returns a unique result + mem.write32(messagePointer + 4, Result::GSP::SuccessRegisterIRQ); // First init returns a unique result mem.write32(messagePointer + 8, 0); // TODO: GSP module thread index mem.write32(messagePointer + 12, 0); // Translation descriptor mem.write32(messagePointer + 16, KernelHandles::GSPSharedMemHandle); @@ -120,7 +113,7 @@ void GPUService::requestInterrupt(GPUInterrupt type) { u8& interruptCount = sharedMem[1]; u8 flagIndex = (index + interruptCount) % 0x34; interruptCount++; - + sharedMem[2] = 0; // Set error code to 0 sharedMem[0xC + flagIndex] = static_cast(type); // Write interrupt type to queue @@ -187,7 +180,7 @@ void GPUService::writeHwRegsWithMask(u32 messagePointer) { u32 dataPointer = mem.read32(messagePointer + 16); // Data pointer u32 maskPointer = mem.read32(messagePointer + 24); // Mask pointer - log("GSP::GPU::writeHwRegsWithMask (GPU address = %08X, size = %X, data address = %08X, mask address = %08X)\n", + log("GSP::GPU::writeHwRegsWithMask (GPU address = %08X, size = %X, data address = %08X, mask address = %08X)\n", ioAddr, size, dataPointer, maskPointer); // Check for alignment @@ -202,7 +195,7 @@ void GPUService::writeHwRegsWithMask(u32 messagePointer) { if (ioAddr >= 0x420000) { Helpers::panic("GSP::GPU::writeHwRegs offset too big"); } - + ioAddr += 0x1EB00000; for (u32 i = 0; i < size; i += 4) { const u32 current = gpu.readReg(ioAddr); @@ -301,13 +294,13 @@ void GPUService::processCommandBuffer() { commandsLeft--; } - } + } } // Fill 2 GPU framebuffers, buf0 and buf1, using a specific word value void GPUService::memoryFill(u32* cmd) { u32 control = cmd[7]; - + // buf0 parameters u32 start0 = cmd[1]; // Start address for the fill. If 0, don't fill anything u32 value0 = cmd[2]; // Value to fill the framebuffer with diff --git a/src/core/services/gsp_lcd.cpp b/src/core/services/gsp_lcd.cpp index ff438b56..d018166b 100644 --- a/src/core/services/gsp_lcd.cpp +++ b/src/core/services/gsp_lcd.cpp @@ -6,12 +6,6 @@ namespace LCDCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void LCDService::reset() {} void LCDService::handleSyncRequest(u32 messagePointer) { diff --git a/src/core/services/hid.cpp b/src/core/services/hid.cpp index fa4536d0..ed7f2afd 100644 --- a/src/core/services/hid.cpp +++ b/src/core/services/hid.cpp @@ -13,13 +13,6 @@ namespace HIDCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - Failure = 0xFFFFFFFF - }; -} - void HIDService::reset() { sharedMem = nullptr; accelerometerEnabled = false; @@ -155,7 +148,7 @@ void HIDService::updateInputs(u64 currentTick) { writeSharedMem(touchEntryOffset, touchScreenX); writeSharedMem(touchEntryOffset + 2, touchScreenY); writeSharedMem(touchEntryOffset + 4, touchScreenPressed ? 1 : 0); - + // Next, update accelerometer state if (nextAccelerometerIndex == 0) { writeSharedMem(0x110, readSharedMem(0x108)); // Copy previous tick count diff --git a/src/core/services/ldr_ro.cpp b/src/core/services/ldr_ro.cpp index 91ae041d..4ea73b4e 100644 --- a/src/core/services/ldr_ro.cpp +++ b/src/core/services/ldr_ro.cpp @@ -8,12 +8,6 @@ namespace LDRCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void LDRService::reset() {} void LDRService::handleSyncRequest(u32 messagePointer) { diff --git a/src/core/services/mic.cpp b/src/core/services/mic.cpp index 83349a67..7f283ce8 100644 --- a/src/core/services/mic.cpp +++ b/src/core/services/mic.cpp @@ -13,12 +13,6 @@ namespace MICCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void MICService::reset() { micEnabled = false; shouldClamp = false; diff --git a/src/core/services/ndm.cpp b/src/core/services/ndm.cpp index a9ea9140..6dbc440c 100644 --- a/src/core/services/ndm.cpp +++ b/src/core/services/ndm.cpp @@ -11,12 +11,6 @@ namespace NDMCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void NDMService::reset() {} void NDMService::handleSyncRequest(u32 messagePointer) { diff --git a/src/core/services/nfc.cpp b/src/core/services/nfc.cpp index 833922eb..c6ed363d 100644 --- a/src/core/services/nfc.cpp +++ b/src/core/services/nfc.cpp @@ -10,12 +10,6 @@ namespace NFCCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void NFCService::reset() { tagInRangeEvent = std::nullopt; tagOutOfRangeEvent = std::nullopt; diff --git a/src/core/services/nim.cpp b/src/core/services/nim.cpp index df9737f6..e4e14c1c 100644 --- a/src/core/services/nim.cpp +++ b/src/core/services/nim.cpp @@ -7,12 +7,6 @@ namespace NIMCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void NIMService::reset() {} void NIMService::handleSyncRequest(u32 messagePointer) { diff --git a/src/core/services/ptm.cpp b/src/core/services/ptm.cpp index fc2d9e93..1c530987 100644 --- a/src/core/services/ptm.cpp +++ b/src/core/services/ptm.cpp @@ -3,18 +3,12 @@ namespace PTMCommands { enum : u32 { - GetStepHistory = 0x000B00C2, + GetStepHistory = 0x000B00C2, GetTotalStepCount = 0x000C0000, ConfigureNew3DSCPU = 0x08180040 }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void PTMService::reset() {} void PTMService::handleSyncRequest(u32 messagePointer) { diff --git a/src/core/services/service_manager.cpp b/src/core/services/service_manager.cpp index 2b9c5167..5f2918de 100644 --- a/src/core/services/service_manager.cpp +++ b/src/core/services/service_manager.cpp @@ -60,12 +60,6 @@ namespace Commands { }; } -namespace Result { - enum : u32 { - Success = 0 - }; -} - // Handle an IPC message issued using the SendSyncRequest SVC // The parameters are stored in thread-local storage in this format: https://www.3dbrew.org/wiki/IPC#Message_Structure // messagePointer: The base pointer for the IPC message diff --git a/src/core/services/y2r.cpp b/src/core/services/y2r.cpp index 64a5a4d7..44b7c6ea 100644 --- a/src/core/services/y2r.cpp +++ b/src/core/services/y2r.cpp @@ -29,12 +29,6 @@ namespace Y2RCommands { }; } -namespace Result { - enum : u32 { - Success = 0, - }; -} - void Y2RService::reset() { transferEndInterruptEnabled = false; transferEndEvent = std::nullopt;