diff options
| author | 2017-05-26 11:59:57 -0400 | |
|---|---|---|
| committer | 2017-05-26 11:59:57 -0400 | |
| commit | 61decd84cc5308bded75eae62c3247a66b3698d8 (patch) | |
| tree | bbe05121af1a971bc295cb81baeea63f8c54f407 | |
| parent | Merge pull request #2697 from wwylele/proctex (diff) | |
| parent | FS: Remove unused result definition (diff) | |
| download | yuzu-61decd84cc5308bded75eae62c3247a66b3698d8.tar.gz yuzu-61decd84cc5308bded75eae62c3247a66b3698d8.tar.xz yuzu-61decd84cc5308bded75eae62c3247a66b3698d8.zip | |
Merge pull request #2716 from yuriks/decentralized-result
Decentralize ResultCode
33 files changed, 385 insertions, 300 deletions
diff --git a/src/common/bit_field.h b/src/common/bit_field.h index 030f7caeb..0cc0a1be0 100644 --- a/src/common/bit_field.h +++ b/src/common/bit_field.h | |||
| @@ -108,7 +108,7 @@ | |||
| 108 | * symptoms. | 108 | * symptoms. |
| 109 | */ | 109 | */ |
| 110 | #pragma pack(1) | 110 | #pragma pack(1) |
| 111 | template <std::size_t position, std::size_t bits, typename T> | 111 | template <std::size_t Position, std::size_t Bits, typename T> |
| 112 | struct BitField { | 112 | struct BitField { |
| 113 | private: | 113 | private: |
| 114 | // We hide the copy assigment operator here, because the default copy | 114 | // We hide the copy assigment operator here, because the default copy |
| @@ -117,7 +117,45 @@ private: | |||
| 117 | // We don't delete it because we want BitField to be trivially copyable. | 117 | // We don't delete it because we want BitField to be trivially copyable. |
| 118 | BitField& operator=(const BitField&) = default; | 118 | BitField& operator=(const BitField&) = default; |
| 119 | 119 | ||
| 120 | // StorageType is T for non-enum types and the underlying type of T if | ||
| 121 | // T is an enumeration. Note that T is wrapped within an enable_if in the | ||
| 122 | // former case to workaround compile errors which arise when using | ||
| 123 | // std::underlying_type<T>::type directly. | ||
| 124 | using StorageType = typename std::conditional_t<std::is_enum<T>::value, std::underlying_type<T>, | ||
| 125 | std::enable_if<true, T>>::type; | ||
| 126 | |||
| 127 | // Unsigned version of StorageType | ||
| 128 | using StorageTypeU = std::make_unsigned_t<StorageType>; | ||
| 129 | |||
| 120 | public: | 130 | public: |
| 131 | /// Constants to allow limited introspection of fields if needed | ||
| 132 | static constexpr size_t position = Position; | ||
| 133 | static constexpr size_t bits = Bits; | ||
| 134 | static constexpr StorageType mask = (((StorageTypeU)~0) >> (8 * sizeof(T) - bits)) << position; | ||
| 135 | |||
| 136 | /** | ||
| 137 | * Formats a value by masking and shifting it according to the field parameters. A value | ||
| 138 | * containing several bitfields can be assembled by formatting each of their values and ORing | ||
| 139 | * the results together. | ||
| 140 | */ | ||
| 141 | static constexpr FORCE_INLINE StorageType FormatValue(const T& value) { | ||
| 142 | return ((StorageType)value << position) & mask; | ||
| 143 | } | ||
| 144 | |||
| 145 | /** | ||
| 146 | * Extracts a value from the passed storage. In most situations prefer use the member functions | ||
| 147 | * (such as Value() or operator T), but this can be used to extract a value from a bitfield | ||
| 148 | * union in a constexpr context. | ||
| 149 | */ | ||
| 150 | static constexpr FORCE_INLINE T ExtractValue(const StorageType& storage) { | ||
| 151 | if (std::numeric_limits<T>::is_signed) { | ||
| 152 | std::size_t shift = 8 * sizeof(T) - bits; | ||
| 153 | return (T)((storage << (shift - position)) >> shift); | ||
| 154 | } else { | ||
| 155 | return (T)((storage & mask) >> position); | ||
| 156 | } | ||
| 157 | } | ||
| 158 | |||
| 121 | // This constructor and assignment operator might be considered ambiguous: | 159 | // This constructor and assignment operator might be considered ambiguous: |
| 122 | // Would they initialize the storage or just the bitfield? | 160 | // Would they initialize the storage or just the bitfield? |
| 123 | // Hence, delete them. Use the Assign method to set bitfield values! | 161 | // Hence, delete them. Use the Assign method to set bitfield values! |
| @@ -126,23 +164,18 @@ public: | |||
| 126 | 164 | ||
| 127 | // Force default constructor to be created | 165 | // Force default constructor to be created |
| 128 | // so that we can use this within unions | 166 | // so that we can use this within unions |
| 129 | BitField() = default; | 167 | constexpr BitField() = default; |
| 130 | 168 | ||
| 131 | FORCE_INLINE operator T() const { | 169 | FORCE_INLINE operator T() const { |
| 132 | return Value(); | 170 | return Value(); |
| 133 | } | 171 | } |
| 134 | 172 | ||
| 135 | FORCE_INLINE void Assign(const T& value) { | 173 | FORCE_INLINE void Assign(const T& value) { |
| 136 | storage = (storage & ~GetMask()) | (((StorageType)value << position) & GetMask()); | 174 | storage = (storage & ~mask) | FormatValue(value); |
| 137 | } | 175 | } |
| 138 | 176 | ||
| 139 | FORCE_INLINE T Value() const { | 177 | FORCE_INLINE T Value() const { |
| 140 | if (std::numeric_limits<T>::is_signed) { | 178 | return ExtractValue(storage); |
| 141 | std::size_t shift = 8 * sizeof(T) - bits; | ||
| 142 | return (T)((storage << (shift - position)) >> shift); | ||
| 143 | } else { | ||
| 144 | return (T)((storage & GetMask()) >> position); | ||
| 145 | } | ||
| 146 | } | 179 | } |
| 147 | 180 | ||
| 148 | // TODO: we may want to change this to explicit operator bool() if it's bug-free in VS2015 | 181 | // TODO: we may want to change this to explicit operator bool() if it's bug-free in VS2015 |
| @@ -151,20 +184,6 @@ public: | |||
| 151 | } | 184 | } |
| 152 | 185 | ||
| 153 | private: | 186 | private: |
| 154 | // StorageType is T for non-enum types and the underlying type of T if | ||
| 155 | // T is an enumeration. Note that T is wrapped within an enable_if in the | ||
| 156 | // former case to workaround compile errors which arise when using | ||
| 157 | // std::underlying_type<T>::type directly. | ||
| 158 | typedef typename std::conditional<std::is_enum<T>::value, std::underlying_type<T>, | ||
| 159 | std::enable_if<true, T>>::type::type StorageType; | ||
| 160 | |||
| 161 | // Unsigned version of StorageType | ||
| 162 | typedef typename std::make_unsigned<StorageType>::type StorageTypeU; | ||
| 163 | |||
| 164 | FORCE_INLINE StorageType GetMask() const { | ||
| 165 | return (((StorageTypeU)~0) >> (8 * sizeof(T) - bits)) << position; | ||
| 166 | } | ||
| 167 | |||
| 168 | StorageType storage; | 187 | StorageType storage; |
| 169 | 188 | ||
| 170 | static_assert(bits + position <= 8 * sizeof(T), "Bitfield out of range"); | 189 | static_assert(bits + position <= 8 * sizeof(T), "Bitfield out of range"); |
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 57504529f..b19335fe1 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -231,6 +231,7 @@ set(HEADERS | |||
| 231 | hle/kernel/address_arbiter.h | 231 | hle/kernel/address_arbiter.h |
| 232 | hle/kernel/client_port.h | 232 | hle/kernel/client_port.h |
| 233 | hle/kernel/client_session.h | 233 | hle/kernel/client_session.h |
| 234 | hle/kernel/errors.h | ||
| 234 | hle/kernel/event.h | 235 | hle/kernel/event.h |
| 235 | hle/kernel/kernel.h | 236 | hle/kernel/kernel.h |
| 236 | hle/kernel/memory.h | 237 | hle/kernel/memory.h |
diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp index f454e7840..4867c9d17 100644 --- a/src/core/file_sys/archive_extsavedata.cpp +++ b/src/core/file_sys/archive_extsavedata.cpp | |||
| @@ -38,8 +38,7 @@ public: | |||
| 38 | ResultVal<size_t> Write(u64 offset, size_t length, bool flush, | 38 | ResultVal<size_t> Write(u64 offset, size_t length, bool flush, |
| 39 | const u8* buffer) const override { | 39 | const u8* buffer) const override { |
| 40 | if (offset > size) { | 40 | if (offset > size) { |
| 41 | return ResultCode(ErrorDescription::FS_WriteBeyondEnd, ErrorModule::FS, | 41 | return ERR_WRITE_BEYOND_END; |
| 42 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 43 | } else if (offset == size) { | 42 | } else if (offset == size) { |
| 44 | return MakeResult<size_t>(0); | 43 | return MakeResult<size_t>(0); |
| 45 | } | 44 | } |
| @@ -191,11 +190,9 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_ExtSaveData::Open(cons | |||
| 191 | // TODO(Subv): Verify the archive behavior of SharedExtSaveData compared to ExtSaveData. | 190 | // TODO(Subv): Verify the archive behavior of SharedExtSaveData compared to ExtSaveData. |
| 192 | // ExtSaveData seems to return FS_NotFound (120) when the archive doesn't exist. | 191 | // ExtSaveData seems to return FS_NotFound (120) when the archive doesn't exist. |
| 193 | if (!shared) { | 192 | if (!shared) { |
| 194 | return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, | 193 | return ERR_NOT_FOUND_INVALID_STATE; |
| 195 | ErrorSummary::InvalidState, ErrorLevel::Status); | ||
| 196 | } else { | 194 | } else { |
| 197 | return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, | 195 | return ERR_NOT_FORMATTED; |
| 198 | ErrorSummary::InvalidState, ErrorLevel::Status); | ||
| 199 | } | 196 | } |
| 200 | } | 197 | } |
| 201 | auto archive = std::make_unique<ExtSaveDataArchive>(fullpath); | 198 | auto archive = std::make_unique<ExtSaveDataArchive>(fullpath); |
| @@ -230,8 +227,7 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Pat | |||
| 230 | if (!file.IsOpen()) { | 227 | if (!file.IsOpen()) { |
| 231 | LOG_ERROR(Service_FS, "Could not open metadata information for archive"); | 228 | LOG_ERROR(Service_FS, "Could not open metadata information for archive"); |
| 232 | // TODO(Subv): Verify error code | 229 | // TODO(Subv): Verify error code |
| 233 | return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, | 230 | return ERR_NOT_FORMATTED; |
| 234 | ErrorSummary::InvalidState, ErrorLevel::Status); | ||
| 235 | } | 231 | } |
| 236 | 232 | ||
| 237 | ArchiveFormatInfo info = {}; | 233 | ArchiveFormatInfo info = {}; |
diff --git a/src/core/file_sys/archive_source_sd_savedata.cpp b/src/core/file_sys/archive_source_sd_savedata.cpp index f31a68038..a7e331724 100644 --- a/src/core/file_sys/archive_source_sd_savedata.cpp +++ b/src/core/file_sys/archive_source_sd_savedata.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include "common/logging/log.h" | 6 | #include "common/logging/log.h" |
| 7 | #include "common/string_util.h" | 7 | #include "common/string_util.h" |
| 8 | #include "core/file_sys/archive_source_sd_savedata.h" | 8 | #include "core/file_sys/archive_source_sd_savedata.h" |
| 9 | #include "core/file_sys/errors.h" | ||
| 9 | #include "core/file_sys/savedata_archive.h" | 10 | #include "core/file_sys/savedata_archive.h" |
| 10 | #include "core/hle/service/fs/archive.h" | 11 | #include "core/hle/service/fs/archive.h" |
| 11 | 12 | ||
| @@ -49,8 +50,7 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveSource_SDSaveData::Open(u64 pr | |||
| 49 | // save file/directory structure expected by the game has not yet been initialized. | 50 | // save file/directory structure expected by the game has not yet been initialized. |
| 50 | // Returning the NotFormatted error code will signal the game to provision the SaveData | 51 | // Returning the NotFormatted error code will signal the game to provision the SaveData |
| 51 | // archive with the files and folders that it expects. | 52 | // archive with the files and folders that it expects. |
| 52 | return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, | 53 | return ERR_NOT_FORMATTED; |
| 53 | ErrorSummary::InvalidState, ErrorLevel::Status); | ||
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | auto archive = std::make_unique<SaveDataArchive>(std::move(concrete_mount_point)); | 56 | auto archive = std::make_unique<SaveDataArchive>(std::move(concrete_mount_point)); |
| @@ -81,8 +81,7 @@ ResultVal<ArchiveFormatInfo> ArchiveSource_SDSaveData::GetFormatInfo(u64 program | |||
| 81 | if (!file.IsOpen()) { | 81 | if (!file.IsOpen()) { |
| 82 | LOG_ERROR(Service_FS, "Could not open metadata information for archive"); | 82 | LOG_ERROR(Service_FS, "Could not open metadata information for archive"); |
| 83 | // TODO(Subv): Verify error code | 83 | // TODO(Subv): Verify error code |
| 84 | return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, | 84 | return ERR_NOT_FORMATTED; |
| 85 | ErrorSummary::InvalidState, ErrorLevel::Status); | ||
| 86 | } | 85 | } |
| 87 | 86 | ||
| 88 | ArchiveFormatInfo info = {}; | 87 | ArchiveFormatInfo info = {}; |
diff --git a/src/core/file_sys/archive_systemsavedata.cpp b/src/core/file_sys/archive_systemsavedata.cpp index 8986b5c0e..81423bffd 100644 --- a/src/core/file_sys/archive_systemsavedata.cpp +++ b/src/core/file_sys/archive_systemsavedata.cpp | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include "common/file_util.h" | 9 | #include "common/file_util.h" |
| 10 | #include "common/string_util.h" | 10 | #include "common/string_util.h" |
| 11 | #include "core/file_sys/archive_systemsavedata.h" | 11 | #include "core/file_sys/archive_systemsavedata.h" |
| 12 | #include "core/file_sys/errors.h" | ||
| 12 | #include "core/file_sys/savedata_archive.h" | 13 | #include "core/file_sys/savedata_archive.h" |
| 13 | #include "core/hle/service/fs/archive.h" | 14 | #include "core/hle/service/fs/archive.h" |
| 14 | 15 | ||
| @@ -53,8 +54,7 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(c | |||
| 53 | std::string fullpath = GetSystemSaveDataPath(base_path, path); | 54 | std::string fullpath = GetSystemSaveDataPath(base_path, path); |
| 54 | if (!FileUtil::Exists(fullpath)) { | 55 | if (!FileUtil::Exists(fullpath)) { |
| 55 | // TODO(Subv): Check error code, this one is probably wrong | 56 | // TODO(Subv): Check error code, this one is probably wrong |
| 56 | return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, | 57 | return ERR_NOT_FORMATTED; |
| 57 | ErrorSummary::InvalidState, ErrorLevel::Status); | ||
| 58 | } | 58 | } |
| 59 | auto archive = std::make_unique<SaveDataArchive>(fullpath); | 59 | auto archive = std::make_unique<SaveDataArchive>(fullpath); |
| 60 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); | 60 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); |
diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp index a243d9a13..98d80aabc 100644 --- a/src/core/file_sys/disk_archive.cpp +++ b/src/core/file_sys/disk_archive.cpp | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include "common/file_util.h" | 9 | #include "common/file_util.h" |
| 10 | #include "common/logging/log.h" | 10 | #include "common/logging/log.h" |
| 11 | #include "core/file_sys/disk_archive.h" | 11 | #include "core/file_sys/disk_archive.h" |
| 12 | #include "core/file_sys/errors.h" | ||
| 12 | 13 | ||
| 13 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 14 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 14 | // FileSys namespace | 15 | // FileSys namespace |
| @@ -17,8 +18,7 @@ namespace FileSys { | |||
| 17 | 18 | ||
| 18 | ResultVal<size_t> DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const { | 19 | ResultVal<size_t> DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const { |
| 19 | if (!mode.read_flag) | 20 | if (!mode.read_flag) |
| 20 | return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, | 21 | return ERROR_INVALID_OPEN_FLAGS; |
| 21 | ErrorSummary::Canceled, ErrorLevel::Status); | ||
| 22 | 22 | ||
| 23 | file->Seek(offset, SEEK_SET); | 23 | file->Seek(offset, SEEK_SET); |
| 24 | return MakeResult<size_t>(file->ReadBytes(buffer, length)); | 24 | return MakeResult<size_t>(file->ReadBytes(buffer, length)); |
| @@ -27,8 +27,7 @@ ResultVal<size_t> DiskFile::Read(const u64 offset, const size_t length, u8* buff | |||
| 27 | ResultVal<size_t> DiskFile::Write(const u64 offset, const size_t length, const bool flush, | 27 | ResultVal<size_t> DiskFile::Write(const u64 offset, const size_t length, const bool flush, |
| 28 | const u8* buffer) const { | 28 | const u8* buffer) const { |
| 29 | if (!mode.write_flag) | 29 | if (!mode.write_flag) |
| 30 | return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, | 30 | return ERROR_INVALID_OPEN_FLAGS; |
| 31 | ErrorSummary::Canceled, ErrorLevel::Status); | ||
| 32 | 31 | ||
| 33 | file->Seek(offset, SEEK_SET); | 32 | file->Seek(offset, SEEK_SET); |
| 34 | size_t written = file->WriteBytes(buffer, length); | 33 | size_t written = file->WriteBytes(buffer, length); |
diff --git a/src/core/file_sys/errors.h b/src/core/file_sys/errors.h index 9fc8d753b..a974bc775 100644 --- a/src/core/file_sys/errors.h +++ b/src/core/file_sys/errors.h | |||
| @@ -2,52 +2,93 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | ||
| 6 | |||
| 5 | #include "core/hle/result.h" | 7 | #include "core/hle/result.h" |
| 6 | 8 | ||
| 7 | namespace FileSys { | 9 | namespace FileSys { |
| 8 | 10 | ||
| 9 | const ResultCode ERROR_INVALID_PATH(ErrorDescription::FS_InvalidPath, ErrorModule::FS, | 11 | namespace ErrCodes { |
| 10 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | 12 | enum { |
| 11 | const ResultCode ERROR_UNSUPPORTED_OPEN_FLAGS(ErrorDescription::FS_UnsupportedOpenFlags, | 13 | RomFSNotFound = 100, |
| 12 | ErrorModule::FS, ErrorSummary::NotSupported, | 14 | ArchiveNotMounted = 101, |
| 13 | ErrorLevel::Usage); | 15 | FileNotFound = 112, |
| 14 | const ResultCode ERROR_INVALID_OPEN_FLAGS(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, | 16 | PathNotFound = 113, |
| 15 | ErrorSummary::Canceled, ErrorLevel::Status); | 17 | GameCardNotInserted = 141, |
| 16 | const ResultCode ERROR_INVALID_READ_FLAG(ErrorDescription::FS_InvalidReadFlag, ErrorModule::FS, | 18 | NotFound = 120, |
| 17 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | 19 | FileAlreadyExists = 180, |
| 18 | const ResultCode ERROR_FILE_NOT_FOUND(ErrorDescription::FS_FileNotFound, ErrorModule::FS, | 20 | DirectoryAlreadyExists = 185, |
| 19 | ErrorSummary::NotFound, ErrorLevel::Status); | 21 | AlreadyExists = 190, |
| 20 | const ResultCode ERROR_PATH_NOT_FOUND(ErrorDescription::FS_PathNotFound, ErrorModule::FS, | 22 | InvalidOpenFlags = 230, |
| 21 | ErrorSummary::NotFound, ErrorLevel::Status); | 23 | DirectoryNotEmpty = 240, |
| 22 | const ResultCode ERROR_NOT_FOUND(ErrorDescription::FS_NotFound, ErrorModule::FS, | 24 | NotAFile = 250, |
| 23 | ErrorSummary::NotFound, ErrorLevel::Status); | 25 | NotFormatted = 340, ///< This is used by the FS service when creating a SaveData archive |
| 24 | const ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY(ErrorDescription::FS_UnexpectedFileOrDirectory, | 26 | ExeFSSectionNotFound = 567, |
| 25 | ErrorModule::FS, ErrorSummary::NotSupported, | 27 | CommandNotAllowed = 630, |
| 26 | ErrorLevel::Usage); | 28 | InvalidReadFlag = 700, |
| 27 | const ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC(ErrorDescription::FS_NotAFile, | 29 | InvalidPath = 702, |
| 28 | ErrorModule::FS, ErrorSummary::Canceled, | 30 | WriteBeyondEnd = 705, |
| 29 | ErrorLevel::Status); | 31 | UnsupportedOpenFlags = 760, |
| 30 | const ResultCode ERROR_DIRECTORY_ALREADY_EXISTS(ErrorDescription::FS_DirectoryAlreadyExists, | 32 | IncorrectExeFSReadSize = 761, |
| 31 | ErrorModule::FS, ErrorSummary::NothingHappened, | 33 | UnexpectedFileOrDirectory = 770, |
| 32 | ErrorLevel::Status); | 34 | }; |
| 33 | const ResultCode ERROR_FILE_ALREADY_EXISTS(ErrorDescription::FS_FileAlreadyExists, ErrorModule::FS, | 35 | } |
| 34 | ErrorSummary::NothingHappened, ErrorLevel::Status); | 36 | |
| 35 | const ResultCode ERROR_ALREADY_EXISTS(ErrorDescription::FS_AlreadyExists, ErrorModule::FS, | 37 | constexpr ResultCode ERROR_INVALID_PATH(ErrCodes::InvalidPath, ErrorModule::FS, |
| 36 | ErrorSummary::NothingHappened, ErrorLevel::Status); | 38 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); |
| 37 | const ResultCode ERROR_DIRECTORY_NOT_EMPTY(ErrorDescription::FS_DirectoryNotEmpty, ErrorModule::FS, | 39 | constexpr ResultCode ERROR_UNSUPPORTED_OPEN_FLAGS(ErrCodes::UnsupportedOpenFlags, ErrorModule::FS, |
| 38 | ErrorSummary::Canceled, ErrorLevel::Status); | 40 | ErrorSummary::NotSupported, ErrorLevel::Usage); |
| 39 | const ResultCode ERROR_GAMECARD_NOT_INSERTED(ErrorDescription::FS_GameCardNotInserted, | 41 | constexpr ResultCode ERROR_INVALID_OPEN_FLAGS(ErrCodes::InvalidOpenFlags, ErrorModule::FS, |
| 40 | ErrorModule::FS, ErrorSummary::NotFound, | 42 | ErrorSummary::Canceled, ErrorLevel::Status); |
| 41 | ErrorLevel::Status); | 43 | constexpr ResultCode ERROR_INVALID_READ_FLAG(ErrCodes::InvalidReadFlag, ErrorModule::FS, |
| 42 | const ResultCode ERROR_INCORRECT_EXEFS_READ_SIZE(ErrorDescription::FS_IncorrectExeFSReadSize, | 44 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); |
| 43 | ErrorModule::FS, ErrorSummary::NotSupported, | 45 | constexpr ResultCode ERROR_FILE_NOT_FOUND(ErrCodes::FileNotFound, ErrorModule::FS, |
| 44 | ErrorLevel::Usage); | 46 | ErrorSummary::NotFound, ErrorLevel::Status); |
| 45 | const ResultCode ERROR_ROMFS_NOT_FOUND(ErrorDescription::FS_RomFSNotFound, ErrorModule::FS, | 47 | constexpr ResultCode ERROR_PATH_NOT_FOUND(ErrCodes::PathNotFound, ErrorModule::FS, |
| 46 | ErrorSummary::NotFound, ErrorLevel::Status); | 48 | ErrorSummary::NotFound, ErrorLevel::Status); |
| 47 | const ResultCode ERROR_COMMAND_NOT_ALLOWED(ErrorDescription::FS_CommandNotAllowed, ErrorModule::FS, | 49 | constexpr ResultCode ERROR_NOT_FOUND(ErrCodes::NotFound, ErrorModule::FS, ErrorSummary::NotFound, |
| 48 | ErrorSummary::WrongArgument, ErrorLevel::Permanent); | 50 | ErrorLevel::Status); |
| 49 | const ResultCode ERROR_EXEFS_SECTION_NOT_FOUND(ErrorDescription::FS_ExeFSSectionNotFound, | 51 | constexpr ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY(ErrCodes::UnexpectedFileOrDirectory, |
| 50 | ErrorModule::FS, ErrorSummary::NotFound, | 52 | ErrorModule::FS, ErrorSummary::NotSupported, |
| 51 | ErrorLevel::Status); | 53 | ErrorLevel::Usage); |
| 54 | constexpr ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC(ErrCodes::NotAFile, ErrorModule::FS, | ||
| 55 | ErrorSummary::Canceled, | ||
| 56 | ErrorLevel::Status); | ||
| 57 | constexpr ResultCode ERROR_DIRECTORY_ALREADY_EXISTS(ErrCodes::DirectoryAlreadyExists, | ||
| 58 | ErrorModule::FS, ErrorSummary::NothingHappened, | ||
| 59 | ErrorLevel::Status); | ||
| 60 | constexpr ResultCode ERROR_FILE_ALREADY_EXISTS(ErrCodes::FileAlreadyExists, ErrorModule::FS, | ||
| 61 | ErrorSummary::NothingHappened, ErrorLevel::Status); | ||
| 62 | constexpr ResultCode ERROR_ALREADY_EXISTS(ErrCodes::AlreadyExists, ErrorModule::FS, | ||
| 63 | ErrorSummary::NothingHappened, ErrorLevel::Status); | ||
| 64 | constexpr ResultCode ERROR_DIRECTORY_NOT_EMPTY(ErrCodes::DirectoryNotEmpty, ErrorModule::FS, | ||
| 65 | ErrorSummary::Canceled, ErrorLevel::Status); | ||
| 66 | constexpr ResultCode ERROR_GAMECARD_NOT_INSERTED(ErrCodes::GameCardNotInserted, ErrorModule::FS, | ||
| 67 | ErrorSummary::NotFound, ErrorLevel::Status); | ||
| 68 | constexpr ResultCode ERROR_INCORRECT_EXEFS_READ_SIZE(ErrCodes::IncorrectExeFSReadSize, | ||
| 69 | ErrorModule::FS, ErrorSummary::NotSupported, | ||
| 70 | ErrorLevel::Usage); | ||
| 71 | constexpr ResultCode ERROR_ROMFS_NOT_FOUND(ErrCodes::RomFSNotFound, ErrorModule::FS, | ||
| 72 | ErrorSummary::NotFound, ErrorLevel::Status); | ||
| 73 | constexpr ResultCode ERROR_COMMAND_NOT_ALLOWED(ErrCodes::CommandNotAllowed, ErrorModule::FS, | ||
| 74 | ErrorSummary::WrongArgument, ErrorLevel::Permanent); | ||
| 75 | constexpr ResultCode ERROR_EXEFS_SECTION_NOT_FOUND(ErrCodes::ExeFSSectionNotFound, ErrorModule::FS, | ||
| 76 | ErrorSummary::NotFound, ErrorLevel::Status); | ||
| 77 | |||
| 78 | /// Returned when a function is passed an invalid archive handle. | ||
| 79 | constexpr ResultCode ERR_INVALID_ARCHIVE_HANDLE(ErrCodes::ArchiveNotMounted, ErrorModule::FS, | ||
| 80 | ErrorSummary::NotFound, | ||
| 81 | ErrorLevel::Status); // 0xC8804465 | ||
| 82 | constexpr ResultCode ERR_WRITE_BEYOND_END(ErrCodes::WriteBeyondEnd, ErrorModule::FS, | ||
| 83 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 84 | |||
| 85 | /** | ||
| 86 | * Variant of ERROR_NOT_FOUND returned in some places in the code. Unknown if these usages are | ||
| 87 | * correct or a bug. | ||
| 88 | */ | ||
| 89 | constexpr ResultCode ERR_NOT_FOUND_INVALID_STATE(ErrCodes::NotFound, ErrorModule::FS, | ||
| 90 | ErrorSummary::InvalidState, ErrorLevel::Status); | ||
| 91 | constexpr ResultCode ERR_NOT_FORMATTED(ErrCodes::NotFormatted, ErrorModule::FS, | ||
| 92 | ErrorSummary::InvalidState, ErrorLevel::Status); | ||
| 52 | 93 | ||
| 53 | } // namespace FileSys | 94 | } // namespace FileSys |
diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index f6eb900f0..18b6e7017 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h | |||
| @@ -53,7 +53,7 @@ void Wrap() { | |||
| 53 | FuncReturn(retval); | 53 | FuncReturn(retval); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | template <ResultCode func(u32*, s32, u32, u32, u32, s32)> | 56 | template <ResultCode func(u32*, u32, u32, u32, u32, s32)> |
| 57 | void Wrap() { | 57 | void Wrap() { |
| 58 | u32 param_1 = 0; | 58 | u32 param_1 = 0; |
| 59 | u32 retval = func(¶m_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)).raw; | 59 | u32 retval = func(¶m_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)).raw; |
diff --git a/src/core/hle/ipc.h b/src/core/hle/ipc.h index 3a5d481a5..303ca090d 100644 --- a/src/core/hle/ipc.h +++ b/src/core/hle/ipc.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "core/hle/kernel/errors.h" | ||
| 8 | #include "core/hle/kernel/thread.h" | 9 | #include "core/hle/kernel/thread.h" |
| 9 | #include "core/memory.h" | 10 | #include "core/memory.h" |
| 10 | 11 | ||
| @@ -43,6 +44,12 @@ inline u32* GetStaticBuffers(const int offset = 0) { | |||
| 43 | 44 | ||
| 44 | namespace IPC { | 45 | namespace IPC { |
| 45 | 46 | ||
| 47 | // These errors are commonly returned by invalid IPC translations, so alias them here for | ||
| 48 | // convenience. | ||
| 49 | // TODO(yuriks): These will probably go away once translation is implemented inside the kernel. | ||
| 50 | using Kernel::ERR_INVALID_BUFFER_DESCRIPTOR; | ||
| 51 | constexpr auto ERR_INVALID_HANDLE = Kernel::ERR_INVALID_HANDLE_OS; | ||
| 52 | |||
| 46 | enum DescriptorType : u32 { | 53 | enum DescriptorType : u32 { |
| 47 | // Buffer related desciptors types (mask : 0x0F) | 54 | // Buffer related desciptors types (mask : 0x0F) |
| 48 | StaticBuffer = 0x02, | 55 | StaticBuffer = 0x02, |
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp index 01fab123e..776d342f0 100644 --- a/src/core/hle/kernel/address_arbiter.cpp +++ b/src/core/hle/kernel/address_arbiter.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include "common/common_types.h" | 5 | #include "common/common_types.h" |
| 6 | #include "common/logging/log.h" | 6 | #include "common/logging/log.h" |
| 7 | #include "core/hle/kernel/address_arbiter.h" | 7 | #include "core/hle/kernel/address_arbiter.h" |
| 8 | #include "core/hle/kernel/errors.h" | ||
| 8 | #include "core/hle/kernel/thread.h" | 9 | #include "core/hle/kernel/thread.h" |
| 9 | #include "core/memory.h" | 10 | #include "core/memory.h" |
| 10 | 11 | ||
| @@ -74,8 +75,7 @@ ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address, | |||
| 74 | 75 | ||
| 75 | default: | 76 | default: |
| 76 | LOG_ERROR(Kernel, "unknown type=%d", type); | 77 | LOG_ERROR(Kernel, "unknown type=%d", type); |
| 77 | return ResultCode(ErrorDescription::InvalidEnumValue, ErrorModule::Kernel, | 78 | return ERR_INVALID_ENUM_VALUE_FND; |
| 78 | ErrorSummary::WrongArgument, ErrorLevel::Usage); | ||
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | // The calls that use a timeout seem to always return a Timeout error even if they did not put | 81 | // The calls that use a timeout seem to always return a Timeout error even if they did not put |
| @@ -83,8 +83,7 @@ ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address, | |||
| 83 | if (type == ArbitrationType::WaitIfLessThanWithTimeout || | 83 | if (type == ArbitrationType::WaitIfLessThanWithTimeout || |
| 84 | type == ArbitrationType::DecrementAndWaitIfLessThanWithTimeout) { | 84 | type == ArbitrationType::DecrementAndWaitIfLessThanWithTimeout) { |
| 85 | 85 | ||
| 86 | return ResultCode(ErrorDescription::Timeout, ErrorModule::OS, ErrorSummary::StatusChanged, | 86 | return RESULT_TIMEOUT; |
| 87 | ErrorLevel::Info); | ||
| 88 | } | 87 | } |
| 89 | return RESULT_SUCCESS; | 88 | return RESULT_SUCCESS; |
| 90 | } | 89 | } |
diff --git a/src/core/hle/kernel/client_port.cpp b/src/core/hle/kernel/client_port.cpp index ddcf4c916..03ffdece1 100644 --- a/src/core/hle/kernel/client_port.cpp +++ b/src/core/hle/kernel/client_port.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include "common/assert.h" | 5 | #include "common/assert.h" |
| 6 | #include "core/hle/kernel/client_port.h" | 6 | #include "core/hle/kernel/client_port.h" |
| 7 | #include "core/hle/kernel/client_session.h" | 7 | #include "core/hle/kernel/client_session.h" |
| 8 | #include "core/hle/kernel/errors.h" | ||
| 8 | #include "core/hle/kernel/kernel.h" | 9 | #include "core/hle/kernel/kernel.h" |
| 9 | #include "core/hle/kernel/server_port.h" | 10 | #include "core/hle/kernel/server_port.h" |
| 10 | #include "core/hle/kernel/server_session.h" | 11 | #include "core/hle/kernel/server_session.h" |
| @@ -19,8 +20,7 @@ ResultVal<SharedPtr<ClientSession>> ClientPort::Connect() { | |||
| 19 | // AcceptSession before returning from this call. | 20 | // AcceptSession before returning from this call. |
| 20 | 21 | ||
| 21 | if (active_sessions >= max_sessions) { | 22 | if (active_sessions >= max_sessions) { |
| 22 | return ResultCode(ErrorDescription::MaxConnectionsReached, ErrorModule::OS, | 23 | return ERR_MAX_CONNECTIONS_REACHED; |
| 23 | ErrorSummary::WouldBlock, ErrorLevel::Temporary); | ||
| 24 | } | 24 | } |
| 25 | active_sessions++; | 25 | active_sessions++; |
| 26 | 26 | ||
diff --git a/src/core/hle/kernel/client_session.cpp b/src/core/hle/kernel/client_session.cpp index e297b7464..783b1c061 100644 --- a/src/core/hle/kernel/client_session.cpp +++ b/src/core/hle/kernel/client_session.cpp | |||
| @@ -30,8 +30,7 @@ ResultCode ClientSession::SendSyncRequest() { | |||
| 30 | if (parent->server) | 30 | if (parent->server) |
| 31 | return parent->server->HandleSyncRequest(); | 31 | return parent->server->HandleSyncRequest(); |
| 32 | 32 | ||
| 33 | return ResultCode(ErrorDescription::SessionClosedByRemote, ErrorModule::OS, | 33 | return ERR_SESSION_CLOSED_BY_REMOTE; |
| 34 | ErrorSummary::Canceled, ErrorLevel::Status); | ||
| 35 | } | 34 | } |
| 36 | 35 | ||
| 37 | } // namespace | 36 | } // namespace |
diff --git a/src/core/hle/kernel/errors.h b/src/core/hle/kernel/errors.h new file mode 100644 index 000000000..b3b60e7df --- /dev/null +++ b/src/core/hle/kernel/errors.h | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "core/hle/result.h" | ||
| 8 | |||
| 9 | namespace Kernel { | ||
| 10 | |||
| 11 | namespace ErrCodes { | ||
| 12 | enum { | ||
| 13 | OutOfHandles = 19, | ||
| 14 | SessionClosedByRemote = 26, | ||
| 15 | PortNameTooLong = 30, | ||
| 16 | WrongPermission = 46, | ||
| 17 | InvalidBufferDescriptor = 48, | ||
| 18 | MaxConnectionsReached = 52, | ||
| 19 | }; | ||
| 20 | } | ||
| 21 | |||
| 22 | // WARNING: The kernel is quite inconsistent in it's usage of errors code. Make sure to always | ||
| 23 | // double check that the code matches before re-using the constant. | ||
| 24 | |||
| 25 | constexpr ResultCode ERR_OUT_OF_HANDLES(ErrCodes::OutOfHandles, ErrorModule::Kernel, | ||
| 26 | ErrorSummary::OutOfResource, | ||
| 27 | ErrorLevel::Permanent); // 0xD8600413 | ||
| 28 | constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE(ErrCodes::SessionClosedByRemote, ErrorModule::OS, | ||
| 29 | ErrorSummary::Canceled, | ||
| 30 | ErrorLevel::Status); // 0xC920181A | ||
| 31 | constexpr ResultCode ERR_PORT_NAME_TOO_LONG(ErrCodes::PortNameTooLong, ErrorModule::OS, | ||
| 32 | ErrorSummary::InvalidArgument, | ||
| 33 | ErrorLevel::Usage); // 0xE0E0181E | ||
| 34 | constexpr ResultCode ERR_WRONG_PERMISSION(ErrCodes::WrongPermission, ErrorModule::OS, | ||
| 35 | ErrorSummary::WrongArgument, ErrorLevel::Permanent); | ||
| 36 | constexpr ResultCode ERR_INVALID_BUFFER_DESCRIPTOR(ErrCodes::InvalidBufferDescriptor, | ||
| 37 | ErrorModule::OS, ErrorSummary::WrongArgument, | ||
| 38 | ErrorLevel::Permanent); | ||
| 39 | constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(ErrCodes::MaxConnectionsReached, ErrorModule::OS, | ||
| 40 | ErrorSummary::WouldBlock, | ||
| 41 | ErrorLevel::Temporary); // 0xD0401834 | ||
| 42 | |||
| 43 | constexpr ResultCode ERR_NOT_AUTHORIZED(ErrorDescription::NotAuthorized, ErrorModule::OS, | ||
| 44 | ErrorSummary::WrongArgument, | ||
| 45 | ErrorLevel::Permanent); // 0xD9001BEA | ||
| 46 | constexpr ResultCode ERR_INVALID_ENUM_VALUE(ErrorDescription::InvalidEnumValue, ErrorModule::Kernel, | ||
| 47 | ErrorSummary::InvalidArgument, | ||
| 48 | ErrorLevel::Permanent); // 0xD8E007ED | ||
| 49 | constexpr ResultCode ERR_INVALID_ENUM_VALUE_FND(ErrorDescription::InvalidEnumValue, | ||
| 50 | ErrorModule::FND, ErrorSummary::InvalidArgument, | ||
| 51 | ErrorLevel::Permanent); // 0xD8E093ED | ||
| 52 | constexpr ResultCode ERR_INVALID_COMBINATION(ErrorDescription::InvalidCombination, ErrorModule::OS, | ||
| 53 | ErrorSummary::InvalidArgument, | ||
| 54 | ErrorLevel::Usage); // 0xE0E01BEE | ||
| 55 | constexpr ResultCode ERR_INVALID_COMBINATION_KERNEL(ErrorDescription::InvalidCombination, | ||
| 56 | ErrorModule::Kernel, | ||
| 57 | ErrorSummary::WrongArgument, | ||
| 58 | ErrorLevel::Permanent); // 0xD90007EE | ||
| 59 | constexpr ResultCode ERR_MISALIGNED_ADDRESS(ErrorDescription::MisalignedAddress, ErrorModule::OS, | ||
| 60 | ErrorSummary::InvalidArgument, | ||
| 61 | ErrorLevel::Usage); // 0xE0E01BF1 | ||
| 62 | constexpr ResultCode ERR_MISALIGNED_SIZE(ErrorDescription::MisalignedSize, ErrorModule::OS, | ||
| 63 | ErrorSummary::InvalidArgument, | ||
| 64 | ErrorLevel::Usage); // 0xE0E01BF2 | ||
| 65 | constexpr ResultCode ERR_OUT_OF_MEMORY(ErrorDescription::OutOfMemory, ErrorModule::Kernel, | ||
| 66 | ErrorSummary::OutOfResource, | ||
| 67 | ErrorLevel::Permanent); // 0xD86007F3 | ||
| 68 | constexpr ResultCode ERR_NOT_IMPLEMENTED(ErrorDescription::NotImplemented, ErrorModule::OS, | ||
| 69 | ErrorSummary::InvalidArgument, | ||
| 70 | ErrorLevel::Usage); // 0xE0E01BF4 | ||
| 71 | constexpr ResultCode ERR_INVALID_ADDRESS(ErrorDescription::InvalidAddress, ErrorModule::OS, | ||
| 72 | ErrorSummary::InvalidArgument, | ||
| 73 | ErrorLevel::Usage); // 0xE0E01BF5 | ||
| 74 | constexpr ResultCode ERR_INVALID_ADDRESS_STATE(ErrorDescription::InvalidAddress, ErrorModule::OS, | ||
| 75 | ErrorSummary::InvalidState, | ||
| 76 | ErrorLevel::Usage); // 0xE0A01BF5 | ||
| 77 | constexpr ResultCode ERR_INVALID_POINTER(ErrorDescription::InvalidPointer, ErrorModule::Kernel, | ||
| 78 | ErrorSummary::InvalidArgument, | ||
| 79 | ErrorLevel::Permanent); // 0xD8E007F6 | ||
| 80 | constexpr ResultCode ERR_INVALID_HANDLE(ErrorDescription::InvalidHandle, ErrorModule::Kernel, | ||
| 81 | ErrorSummary::InvalidArgument, | ||
| 82 | ErrorLevel::Permanent); // 0xD8E007F7 | ||
| 83 | /// Alternate code returned instead of ERR_INVALID_HANDLE in some code paths. | ||
| 84 | constexpr ResultCode ERR_INVALID_HANDLE_OS(ErrorDescription::InvalidHandle, ErrorModule::OS, | ||
| 85 | ErrorSummary::WrongArgument, | ||
| 86 | ErrorLevel::Permanent); // 0xD9001BF7 | ||
| 87 | constexpr ResultCode ERR_NOT_FOUND(ErrorDescription::NotFound, ErrorModule::Kernel, | ||
| 88 | ErrorSummary::NotFound, ErrorLevel::Permanent); // 0xD88007FA | ||
| 89 | constexpr ResultCode ERR_OUT_OF_RANGE(ErrorDescription::OutOfRange, ErrorModule::OS, | ||
| 90 | ErrorSummary::InvalidArgument, | ||
| 91 | ErrorLevel::Usage); // 0xE0E01BFD | ||
| 92 | constexpr ResultCode ERR_OUT_OF_RANGE_KERNEL(ErrorDescription::OutOfRange, ErrorModule::Kernel, | ||
| 93 | ErrorSummary::InvalidArgument, | ||
| 94 | ErrorLevel::Permanent); // 0xD8E007FD | ||
| 95 | constexpr ResultCode RESULT_TIMEOUT(ErrorDescription::Timeout, ErrorModule::OS, | ||
| 96 | ErrorSummary::StatusChanged, ErrorLevel::Info); | ||
| 97 | |||
| 98 | } // namespace Kernel | ||
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index f599916f0..7f84e01aa 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include "common/assert.h" | 6 | #include "common/assert.h" |
| 7 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "core/hle/config_mem.h" | 8 | #include "core/hle/config_mem.h" |
| 9 | #include "core/hle/kernel/errors.h" | ||
| 9 | #include "core/hle/kernel/kernel.h" | 10 | #include "core/hle/kernel/kernel.h" |
| 10 | #include "core/hle/kernel/memory.h" | 11 | #include "core/hle/kernel/memory.h" |
| 11 | #include "core/hle/kernel/process.h" | 12 | #include "core/hle/kernel/process.h" |
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index bb8b99bb5..94f2025a0 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h | |||
| @@ -19,13 +19,6 @@ using Handle = u32; | |||
| 19 | 19 | ||
| 20 | class Thread; | 20 | class Thread; |
| 21 | 21 | ||
| 22 | // TODO: Verify code | ||
| 23 | const ResultCode ERR_OUT_OF_HANDLES(ErrorDescription::OutOfMemory, ErrorModule::Kernel, | ||
| 24 | ErrorSummary::OutOfResource, ErrorLevel::Temporary); | ||
| 25 | // TOOD: Verify code | ||
| 26 | const ResultCode ERR_INVALID_HANDLE(ErrorDescription::InvalidHandle, ErrorModule::Kernel, | ||
| 27 | ErrorSummary::InvalidArgument, ErrorLevel::Permanent); | ||
| 28 | |||
| 29 | enum KernelHandle : Handle { | 22 | enum KernelHandle : Handle { |
| 30 | CurrentThread = 0xFFFF8000, | 23 | CurrentThread = 0xFFFF8000, |
| 31 | CurrentProcess = 0xFFFF8001, | 24 | CurrentProcess = 0xFFFF8001, |
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 32cb25fb7..1c31ec950 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include "common/assert.h" | 6 | #include "common/assert.h" |
| 7 | #include "common/common_funcs.h" | 7 | #include "common/common_funcs.h" |
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "core/hle/kernel/errors.h" | ||
| 9 | #include "core/hle/kernel/memory.h" | 10 | #include "core/hle/kernel/memory.h" |
| 10 | #include "core/hle/kernel/process.h" | 11 | #include "core/hle/kernel/process.h" |
| 11 | #include "core/hle/kernel/resource_limit.h" | 12 | #include "core/hle/kernel/resource_limit.h" |
diff --git a/src/core/hle/kernel/semaphore.cpp b/src/core/hle/kernel/semaphore.cpp index 8bda2f75d..fcf586728 100644 --- a/src/core/hle/kernel/semaphore.cpp +++ b/src/core/hle/kernel/semaphore.cpp | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/assert.h" | 5 | #include "common/assert.h" |
| 6 | #include "core/hle/kernel/errors.h" | ||
| 6 | #include "core/hle/kernel/kernel.h" | 7 | #include "core/hle/kernel/kernel.h" |
| 7 | #include "core/hle/kernel/semaphore.h" | 8 | #include "core/hle/kernel/semaphore.h" |
| 8 | #include "core/hle/kernel/thread.h" | 9 | #include "core/hle/kernel/thread.h" |
| @@ -16,8 +17,7 @@ ResultVal<SharedPtr<Semaphore>> Semaphore::Create(s32 initial_count, s32 max_cou | |||
| 16 | std::string name) { | 17 | std::string name) { |
| 17 | 18 | ||
| 18 | if (initial_count > max_count) | 19 | if (initial_count > max_count) |
| 19 | return ResultCode(ErrorDescription::InvalidCombination, ErrorModule::Kernel, | 20 | return ERR_INVALID_COMBINATION_KERNEL; |
| 20 | ErrorSummary::WrongArgument, ErrorLevel::Permanent); | ||
| 21 | 21 | ||
| 22 | SharedPtr<Semaphore> semaphore(new Semaphore); | 22 | SharedPtr<Semaphore> semaphore(new Semaphore); |
| 23 | 23 | ||
| @@ -42,8 +42,7 @@ void Semaphore::Acquire(Thread* thread) { | |||
| 42 | 42 | ||
| 43 | ResultVal<s32> Semaphore::Release(s32 release_count) { | 43 | ResultVal<s32> Semaphore::Release(s32 release_count) { |
| 44 | if (max_count - available_count < release_count) | 44 | if (max_count - available_count < release_count) |
| 45 | return ResultCode(ErrorDescription::OutOfRange, ErrorModule::Kernel, | 45 | return ERR_OUT_OF_RANGE_KERNEL; |
| 46 | ErrorSummary::InvalidArgument, ErrorLevel::Permanent); | ||
| 47 | 46 | ||
| 48 | s32 previous_count = available_count; | 47 | s32 previous_count = available_count; |
| 49 | available_count += release_count; | 48 | available_count += release_count; |
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index bc1560d12..922e5ab58 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include <cstring> | 5 | #include <cstring> |
| 6 | #include "common/logging/log.h" | 6 | #include "common/logging/log.h" |
| 7 | #include "core/hle/kernel/errors.h" | ||
| 7 | #include "core/hle/kernel/memory.h" | 8 | #include "core/hle/kernel/memory.h" |
| 8 | #include "core/hle/kernel/shared_memory.h" | 9 | #include "core/hle/kernel/shared_memory.h" |
| 9 | #include "core/memory.h" | 10 | #include "core/memory.h" |
| @@ -102,24 +103,21 @@ ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermi | |||
| 102 | 103 | ||
| 103 | // Automatically allocated memory blocks can only be mapped with other_permissions = DontCare | 104 | // Automatically allocated memory blocks can only be mapped with other_permissions = DontCare |
| 104 | if (base_address == 0 && other_permissions != MemoryPermission::DontCare) { | 105 | if (base_address == 0 && other_permissions != MemoryPermission::DontCare) { |
| 105 | return ResultCode(ErrorDescription::InvalidCombination, ErrorModule::OS, | 106 | return ERR_INVALID_COMBINATION; |
| 106 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | // Error out if the requested permissions don't match what the creator process allows. | 109 | // Error out if the requested permissions don't match what the creator process allows. |
| 110 | if (static_cast<u32>(permissions) & ~static_cast<u32>(own_other_permissions)) { | 110 | if (static_cast<u32>(permissions) & ~static_cast<u32>(own_other_permissions)) { |
| 111 | LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s, permissions don't match", | 111 | LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s, permissions don't match", |
| 112 | GetObjectId(), address, name.c_str()); | 112 | GetObjectId(), address, name.c_str()); |
| 113 | return ResultCode(ErrorDescription::InvalidCombination, ErrorModule::OS, | 113 | return ERR_INVALID_COMBINATION; |
| 114 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 115 | } | 114 | } |
| 116 | 115 | ||
| 117 | // Heap-backed memory blocks can not be mapped with other_permissions = DontCare | 116 | // Heap-backed memory blocks can not be mapped with other_permissions = DontCare |
| 118 | if (base_address != 0 && other_permissions == MemoryPermission::DontCare) { | 117 | if (base_address != 0 && other_permissions == MemoryPermission::DontCare) { |
| 119 | LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s, permissions don't match", | 118 | LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s, permissions don't match", |
| 120 | GetObjectId(), address, name.c_str()); | 119 | GetObjectId(), address, name.c_str()); |
| 121 | return ResultCode(ErrorDescription::InvalidCombination, ErrorModule::OS, | 120 | return ERR_INVALID_COMBINATION; |
| 122 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 123 | } | 121 | } |
| 124 | 122 | ||
| 125 | // Error out if the provided permissions are not compatible with what the creator process needs. | 123 | // Error out if the provided permissions are not compatible with what the creator process needs. |
| @@ -127,8 +125,7 @@ ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermi | |||
| 127 | static_cast<u32>(this->permissions) & ~static_cast<u32>(other_permissions)) { | 125 | static_cast<u32>(this->permissions) & ~static_cast<u32>(other_permissions)) { |
| 128 | LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s, permissions don't match", | 126 | LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s, permissions don't match", |
| 129 | GetObjectId(), address, name.c_str()); | 127 | GetObjectId(), address, name.c_str()); |
| 130 | return ResultCode(ErrorDescription::WrongPermission, ErrorModule::OS, | 128 | return ERR_WRONG_PERMISSION; |
| 131 | ErrorSummary::WrongArgument, ErrorLevel::Permanent); | ||
| 132 | } | 129 | } |
| 133 | 130 | ||
| 134 | // TODO(Subv): Check for the Shared Device Mem flag in the creator process. | 131 | // TODO(Subv): Check for the Shared Device Mem flag in the creator process. |
| @@ -144,8 +141,7 @@ ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermi | |||
| 144 | if (address < Memory::HEAP_VADDR || address + size >= Memory::SHARED_MEMORY_VADDR_END) { | 141 | if (address < Memory::HEAP_VADDR || address + size >= Memory::SHARED_MEMORY_VADDR_END) { |
| 145 | LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s, invalid address", | 142 | LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s, invalid address", |
| 146 | GetObjectId(), address, name.c_str()); | 143 | GetObjectId(), address, name.c_str()); |
| 147 | return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::OS, | 144 | return ERR_INVALID_ADDRESS; |
| 148 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 149 | } | 145 | } |
| 150 | } | 146 | } |
| 151 | 147 | ||
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 3b7555d87..519ff51a8 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | #include "core/arm/skyeye_common/armstate.h" | 14 | #include "core/arm/skyeye_common/armstate.h" |
| 15 | #include "core/core.h" | 15 | #include "core/core.h" |
| 16 | #include "core/core_timing.h" | 16 | #include "core/core_timing.h" |
| 17 | #include "core/hle/kernel/errors.h" | ||
| 17 | #include "core/hle/kernel/kernel.h" | 18 | #include "core/hle/kernel/kernel.h" |
| 18 | #include "core/hle/kernel/memory.h" | 19 | #include "core/hle/kernel/memory.h" |
| 19 | #include "core/hle/kernel/mutex.h" | 20 | #include "core/hle/kernel/mutex.h" |
| @@ -241,9 +242,7 @@ static void ThreadWakeupCallback(u64 thread_handle, int cycles_late) { | |||
| 241 | for (auto& object : thread->wait_objects) | 242 | for (auto& object : thread->wait_objects) |
| 242 | object->RemoveWaitingThread(thread.get()); | 243 | object->RemoveWaitingThread(thread.get()); |
| 243 | thread->wait_objects.clear(); | 244 | thread->wait_objects.clear(); |
| 244 | thread->SetWaitSynchronizationResult(ResultCode(ErrorDescription::Timeout, ErrorModule::OS, | 245 | thread->SetWaitSynchronizationResult(RESULT_TIMEOUT); |
| 245 | ErrorSummary::StatusChanged, | ||
| 246 | ErrorLevel::Info)); | ||
| 247 | } | 246 | } |
| 248 | 247 | ||
| 249 | thread->ResumeFromWait(); | 248 | thread->ResumeFromWait(); |
| @@ -351,10 +350,20 @@ static void ResetThreadContext(ARM_Interface::ThreadContext& context, u32 stack_ | |||
| 351 | context.cpsr = USER32MODE | ((entry_point & 1) << 5); // Usermode and THUMB mode | 350 | context.cpsr = USER32MODE | ((entry_point & 1) << 5); // Usermode and THUMB mode |
| 352 | } | 351 | } |
| 353 | 352 | ||
| 354 | ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, s32 priority, | 353 | ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, u32 priority, |
| 355 | u32 arg, s32 processor_id, VAddr stack_top) { | 354 | u32 arg, s32 processor_id, VAddr stack_top) { |
| 356 | ASSERT_MSG(priority >= THREADPRIO_HIGHEST && priority <= THREADPRIO_LOWEST, | 355 | // Check if priority is in ranged. Lowest priority -> highest priority id. |
| 357 | "Invalid thread priority"); | 356 | if (priority > THREADPRIO_LOWEST) { |
| 357 | LOG_ERROR(Kernel_SVC, "Invalid thread priority: %d", priority); | ||
| 358 | return ERR_OUT_OF_RANGE; | ||
| 359 | } | ||
| 360 | |||
| 361 | if (processor_id > THREADPROCESSORID_MAX) { | ||
| 362 | LOG_ERROR(Kernel_SVC, "Invalid processor id: %d", processor_id); | ||
| 363 | return ERR_OUT_OF_RANGE_KERNEL; | ||
| 364 | } | ||
| 365 | |||
| 366 | // TODO(yuriks): Other checks, returning 0xD9001BEA | ||
| 358 | 367 | ||
| 359 | if (!Memory::IsValidVirtualAddress(entry_point)) { | 368 | if (!Memory::IsValidVirtualAddress(entry_point)) { |
| 360 | LOG_ERROR(Kernel_SVC, "(name=%s): invalid entry %08x", name.c_str(), entry_point); | 369 | LOG_ERROR(Kernel_SVC, "(name=%s): invalid entry %08x", name.c_str(), entry_point); |
| @@ -399,8 +408,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, | |||
| 399 | if (linheap_memory->size() + Memory::PAGE_SIZE > memory_region->size) { | 408 | if (linheap_memory->size() + Memory::PAGE_SIZE > memory_region->size) { |
| 400 | LOG_ERROR(Kernel_SVC, | 409 | LOG_ERROR(Kernel_SVC, |
| 401 | "Not enough space in region to allocate a new TLS page for thread"); | 410 | "Not enough space in region to allocate a new TLS page for thread"); |
| 402 | return ResultCode(ErrorDescription::OutOfMemory, ErrorModule::Kernel, | 411 | return ERR_OUT_OF_MEMORY; |
| 403 | ErrorSummary::OutOfResource, ErrorLevel::Permanent); | ||
| 404 | } | 412 | } |
| 405 | 413 | ||
| 406 | u32 offset = linheap_memory->size(); | 414 | u32 offset = linheap_memory->size(); |
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 6ab31c70b..7b5169cfc 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -57,7 +57,7 @@ public: | |||
| 57 | * @param stack_top The address of the thread's stack top | 57 | * @param stack_top The address of the thread's stack top |
| 58 | * @return A shared pointer to the newly created thread | 58 | * @return A shared pointer to the newly created thread |
| 59 | */ | 59 | */ |
| 60 | static ResultVal<SharedPtr<Thread>> Create(std::string name, VAddr entry_point, s32 priority, | 60 | static ResultVal<SharedPtr<Thread>> Create(std::string name, VAddr entry_point, u32 priority, |
| 61 | u32 arg, s32 processor_id, VAddr stack_top); | 61 | u32 arg, s32 processor_id, VAddr stack_top); |
| 62 | 62 | ||
| 63 | std::string GetName() const override { | 63 | std::string GetName() const override { |
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp index 6dd24f846..cef1f7fa8 100644 --- a/src/core/hle/kernel/vm_manager.cpp +++ b/src/core/hle/kernel/vm_manager.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include <iterator> | 5 | #include <iterator> |
| 6 | #include "common/assert.h" | 6 | #include "common/assert.h" |
| 7 | #include "core/hle/kernel/errors.h" | ||
| 7 | #include "core/hle/kernel/vm_manager.h" | 8 | #include "core/hle/kernel/vm_manager.h" |
| 8 | #include "core/memory.h" | 9 | #include "core/memory.h" |
| 9 | #include "core/memory_setup.h" | 10 | #include "core/memory_setup.h" |
diff --git a/src/core/hle/kernel/vm_manager.h b/src/core/hle/kernel/vm_manager.h index 9055664b2..38e0d74d0 100644 --- a/src/core/hle/kernel/vm_manager.h +++ b/src/core/hle/kernel/vm_manager.h | |||
| @@ -13,14 +13,6 @@ | |||
| 13 | 13 | ||
| 14 | namespace Kernel { | 14 | namespace Kernel { |
| 15 | 15 | ||
| 16 | const ResultCode ERR_INVALID_ADDRESS{// 0xE0E01BF5 | ||
| 17 | ErrorDescription::InvalidAddress, ErrorModule::OS, | ||
| 18 | ErrorSummary::InvalidArgument, ErrorLevel::Usage}; | ||
| 19 | |||
| 20 | const ResultCode ERR_INVALID_ADDRESS_STATE{// 0xE0A01BF5 | ||
| 21 | ErrorDescription::InvalidAddress, ErrorModule::OS, | ||
| 22 | ErrorSummary::InvalidState, ErrorLevel::Usage}; | ||
| 23 | |||
| 24 | enum class VMAType : u8 { | 16 | enum class VMAType : u8 { |
| 25 | /// VMA represents an unmapped region of the address space. | 17 | /// VMA represents an unmapped region of the address space. |
| 26 | Free, | 18 | Free, |
diff --git a/src/core/hle/result.h b/src/core/hle/result.h index 13b948871..c49650f7d 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h | |||
| @@ -13,38 +13,15 @@ | |||
| 13 | 13 | ||
| 14 | // All the constants in this file come from http://3dbrew.org/wiki/Error_codes | 14 | // All the constants in this file come from http://3dbrew.org/wiki/Error_codes |
| 15 | 15 | ||
| 16 | /// Detailed description of the error. This listing is likely incomplete. | 16 | /** |
| 17 | * Detailed description of the error. Code 0 always means success. Codes 1000 and above are | ||
| 18 | * considered "well-known" and have common values between all modules. The meaning of other codes | ||
| 19 | * vary by module. | ||
| 20 | */ | ||
| 17 | enum class ErrorDescription : u32 { | 21 | enum class ErrorDescription : u32 { |
| 18 | Success = 0, | 22 | Success = 0, |
| 19 | SessionClosedByRemote = 26, | 23 | |
| 20 | WrongPermission = 46, | 24 | // Codes 1000 and above are considered "well-known" and have common values between all modules. |
| 21 | OS_InvalidBufferDescriptor = 48, | ||
| 22 | MaxConnectionsReached = 52, | ||
| 23 | WrongAddress = 53, | ||
| 24 | FS_RomFSNotFound = 100, | ||
| 25 | FS_ArchiveNotMounted = 101, | ||
| 26 | FS_FileNotFound = 112, | ||
| 27 | FS_PathNotFound = 113, | ||
| 28 | FS_GameCardNotInserted = 141, | ||
| 29 | FS_NotFound = 120, | ||
| 30 | FS_FileAlreadyExists = 180, | ||
| 31 | FS_DirectoryAlreadyExists = 185, | ||
| 32 | FS_AlreadyExists = 190, | ||
| 33 | FS_InvalidOpenFlags = 230, | ||
| 34 | FS_DirectoryNotEmpty = 240, | ||
| 35 | FS_NotAFile = 250, | ||
| 36 | FS_NotFormatted = 340, ///< This is used by the FS service when creating a SaveData archive | ||
| 37 | OutofRangeOrMisalignedAddress = | ||
| 38 | 513, // TODO(purpasmart): Check if this name fits its actual usage | ||
| 39 | GPU_FirstInitialization = 519, | ||
| 40 | FS_ExeFSSectionNotFound = 567, | ||
| 41 | FS_CommandNotAllowed = 630, | ||
| 42 | FS_InvalidReadFlag = 700, | ||
| 43 | FS_InvalidPath = 702, | ||
| 44 | FS_WriteBeyondEnd = 705, | ||
| 45 | FS_UnsupportedOpenFlags = 760, | ||
| 46 | FS_IncorrectExeFSReadSize = 761, | ||
| 47 | FS_UnexpectedFileOrDirectory = 770, | ||
| 48 | InvalidSection = 1000, | 25 | InvalidSection = 1000, |
| 49 | TooLarge = 1001, | 26 | TooLarge = 1001, |
| 50 | NotAuthorized = 1002, | 27 | NotAuthorized = 1002, |
| @@ -218,7 +195,7 @@ enum class ErrorLevel : u32 { | |||
| 218 | union ResultCode { | 195 | union ResultCode { |
| 219 | u32 raw; | 196 | u32 raw; |
| 220 | 197 | ||
| 221 | BitField<0, 10, ErrorDescription> description; | 198 | BitField<0, 10, u32> description; |
| 222 | BitField<10, 8, ErrorModule> module; | 199 | BitField<10, 8, ErrorModule> module; |
| 223 | 200 | ||
| 224 | BitField<21, 6, ErrorSummary> summary; | 201 | BitField<21, 6, ErrorSummary> summary; |
| @@ -228,45 +205,46 @@ union ResultCode { | |||
| 228 | // error | 205 | // error |
| 229 | BitField<31, 1, u32> is_error; | 206 | BitField<31, 1, u32> is_error; |
| 230 | 207 | ||
| 231 | explicit ResultCode(u32 raw) : raw(raw) {} | 208 | constexpr explicit ResultCode(u32 raw) : raw(raw) {} |
| 232 | ResultCode(ErrorDescription description_, ErrorModule module_, ErrorSummary summary_, | 209 | |
| 233 | ErrorLevel level_) | 210 | constexpr ResultCode(ErrorDescription description, ErrorModule module, ErrorSummary summary, |
| 234 | : raw(0) { | 211 | ErrorLevel level) |
| 235 | description.Assign(description_); | 212 | : ResultCode(static_cast<u32>(description), module, summary, level) {} |
| 236 | module.Assign(module_); | 213 | |
| 237 | summary.Assign(summary_); | 214 | constexpr ResultCode(u32 description_, ErrorModule module_, ErrorSummary summary_, |
| 238 | level.Assign(level_); | 215 | ErrorLevel level_) |
| 239 | } | 216 | : raw(description.FormatValue(description_) | module.FormatValue(module_) | |
| 217 | summary.FormatValue(summary_) | level.FormatValue(level_)) {} | ||
| 240 | 218 | ||
| 241 | ResultCode& operator=(const ResultCode& o) { | 219 | constexpr ResultCode& operator=(const ResultCode& o) { |
| 242 | raw = o.raw; | 220 | raw = o.raw; |
| 243 | return *this; | 221 | return *this; |
| 244 | } | 222 | } |
| 245 | 223 | ||
| 246 | bool IsSuccess() const { | 224 | constexpr bool IsSuccess() const { |
| 247 | return is_error == 0; | 225 | return is_error.ExtractValue(raw) == 0; |
| 248 | } | 226 | } |
| 249 | 227 | ||
| 250 | bool IsError() const { | 228 | constexpr bool IsError() const { |
| 251 | return is_error == 1; | 229 | return is_error.ExtractValue(raw) == 1; |
| 252 | } | 230 | } |
| 253 | }; | 231 | }; |
| 254 | 232 | ||
| 255 | inline bool operator==(const ResultCode& a, const ResultCode& b) { | 233 | constexpr bool operator==(const ResultCode& a, const ResultCode& b) { |
| 256 | return a.raw == b.raw; | 234 | return a.raw == b.raw; |
| 257 | } | 235 | } |
| 258 | 236 | ||
| 259 | inline bool operator!=(const ResultCode& a, const ResultCode& b) { | 237 | constexpr bool operator!=(const ResultCode& a, const ResultCode& b) { |
| 260 | return a.raw != b.raw; | 238 | return a.raw != b.raw; |
| 261 | } | 239 | } |
| 262 | 240 | ||
| 263 | // Convenience functions for creating some common kinds of errors: | 241 | // Convenience functions for creating some common kinds of errors: |
| 264 | 242 | ||
| 265 | /// The default success `ResultCode`. | 243 | /// The default success `ResultCode`. |
| 266 | const ResultCode RESULT_SUCCESS(0); | 244 | constexpr ResultCode RESULT_SUCCESS(0); |
| 267 | 245 | ||
| 268 | /// Might be returned instead of a dummy success for unimplemented APIs. | 246 | /// Might be returned instead of a dummy success for unimplemented APIs. |
| 269 | inline ResultCode UnimplementedFunction(ErrorModule module) { | 247 | constexpr ResultCode UnimplementedFunction(ErrorModule module) { |
| 270 | return ResultCode(ErrorDescription::NotImplemented, module, ErrorSummary::NotSupported, | 248 | return ResultCode(ErrorDescription::NotImplemented, module, ErrorSummary::NotSupported, |
| 271 | ErrorLevel::Permanent); | 249 | ErrorLevel::Permanent); |
| 272 | } | 250 | } |
diff --git a/src/core/hle/service/boss/boss.cpp b/src/core/hle/service/boss/boss.cpp index e0de037f8..91056189a 100644 --- a/src/core/hle/service/boss/boss.cpp +++ b/src/core/hle/service/boss/boss.cpp | |||
| @@ -24,9 +24,7 @@ void InitializeSession(Service::Interface* self) { | |||
| 24 | 24 | ||
| 25 | if (translation != IPC::CallingPidDesc()) { | 25 | if (translation != IPC::CallingPidDesc()) { |
| 26 | cmd_buff[0] = IPC::MakeHeader(0, 0x1, 0); // 0x40 | 26 | cmd_buff[0] = IPC::MakeHeader(0, 0x1, 0); // 0x40 |
| 27 | cmd_buff[1] = ResultCode(ErrorDescription::OS_InvalidBufferDescriptor, ErrorModule::OS, | 27 | cmd_buff[1] = IPC::ERR_INVALID_BUFFER_DESCRIPTOR.raw; |
| 28 | ErrorSummary::WrongArgument, ErrorLevel::Permanent) | ||
| 29 | .raw; | ||
| 30 | LOG_ERROR(Service_BOSS, "The translation was invalid, translation=0x%08X", translation); | 28 | LOG_ERROR(Service_BOSS, "The translation was invalid, translation=0x%08X", translation); |
| 31 | return; | 29 | return; |
| 32 | } | 30 | } |
diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index 8c8c1ec77..caa41ded7 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include "common/string_util.h" | 11 | #include "common/string_util.h" |
| 12 | #include "common/swap.h" | 12 | #include "common/swap.h" |
| 13 | #include "core/file_sys/archive_systemsavedata.h" | 13 | #include "core/file_sys/archive_systemsavedata.h" |
| 14 | #include "core/file_sys/errors.h" | ||
| 14 | #include "core/file_sys/file_backend.h" | 15 | #include "core/file_sys/file_backend.h" |
| 15 | #include "core/hle/result.h" | 16 | #include "core/hle/result.h" |
| 16 | #include "core/hle/service/cfg/cfg.h" | 17 | #include "core/hle/service/cfg/cfg.h" |
| @@ -411,7 +412,7 @@ ResultCode UpdateConfigNANDSavegame() { | |||
| 411 | ResultCode FormatConfig() { | 412 | ResultCode FormatConfig() { |
| 412 | ResultCode res = DeleteConfigNANDSaveFile(); | 413 | ResultCode res = DeleteConfigNANDSaveFile(); |
| 413 | // The delete command fails if the file doesn't exist, so we have to check that too | 414 | // The delete command fails if the file doesn't exist, so we have to check that too |
| 414 | if (!res.IsSuccess() && res.description != ErrorDescription::FS_FileNotFound) { | 415 | if (!res.IsSuccess() && res != FileSys::ERROR_FILE_NOT_FOUND) { |
| 415 | return res; | 416 | return res; |
| 416 | } | 417 | } |
| 417 | // Delete the old data | 418 | // Delete the old data |
| @@ -534,7 +535,7 @@ ResultCode LoadConfigNANDSaveFile() { | |||
| 534 | Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path); | 535 | Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path); |
| 535 | 536 | ||
| 536 | // If the archive didn't exist, create the files inside | 537 | // If the archive didn't exist, create the files inside |
| 537 | if (archive_result.Code().description == ErrorDescription::FS_NotFormatted) { | 538 | if (archive_result.Code() == FileSys::ERR_NOT_FORMATTED) { |
| 538 | // Format the archive to create the directories | 539 | // Format the archive to create the directories |
| 539 | Service::FS::FormatArchive(Service::FS::ArchiveIdCode::SystemSaveData, | 540 | Service::FS::FormatArchive(Service::FS::ArchiveIdCode::SystemSaveData, |
| 540 | FileSys::ArchiveFormatInfo(), archive_path); | 541 | FileSys::ArchiveFormatInfo(), archive_path); |
diff --git a/src/core/hle/service/dsp_dsp.cpp b/src/core/hle/service/dsp_dsp.cpp index 39711ea97..79171a0bc 100644 --- a/src/core/hle/service/dsp_dsp.cpp +++ b/src/core/hle/service/dsp_dsp.cpp | |||
| @@ -289,9 +289,7 @@ static void WriteProcessPipe(Service::Interface* self) { | |||
| 289 | "size=0x%X, buffer=0x%08X", | 289 | "size=0x%X, buffer=0x%08X", |
| 290 | cmd_buff[3], pipe_index, size, buffer); | 290 | cmd_buff[3], pipe_index, size, buffer); |
| 291 | cmd_buff[0] = IPC::MakeHeader(0, 1, 0); | 291 | cmd_buff[0] = IPC::MakeHeader(0, 1, 0); |
| 292 | cmd_buff[1] = ResultCode(ErrorDescription::OS_InvalidBufferDescriptor, ErrorModule::OS, | 292 | cmd_buff[1] = IPC::ERR_INVALID_BUFFER_DESCRIPTOR.raw; |
| 293 | ErrorSummary::WrongArgument, ErrorLevel::Permanent) | ||
| 294 | .raw; | ||
| 295 | return; | 293 | return; |
| 296 | } | 294 | } |
| 297 | 295 | ||
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 6cddc1fdb..632712f2c 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp | |||
| @@ -22,6 +22,7 @@ | |||
| 22 | #include "core/file_sys/archive_sdmcwriteonly.h" | 22 | #include "core/file_sys/archive_sdmcwriteonly.h" |
| 23 | #include "core/file_sys/archive_systemsavedata.h" | 23 | #include "core/file_sys/archive_systemsavedata.h" |
| 24 | #include "core/file_sys/directory_backend.h" | 24 | #include "core/file_sys/directory_backend.h" |
| 25 | #include "core/file_sys/errors.h" | ||
| 25 | #include "core/file_sys/file_backend.h" | 26 | #include "core/file_sys/file_backend.h" |
| 26 | #include "core/hle/kernel/client_session.h" | 27 | #include "core/hle/kernel/client_session.h" |
| 27 | #include "core/hle/result.h" | 28 | #include "core/hle/result.h" |
| @@ -50,16 +51,6 @@ static constexpr Kernel::Handle INVALID_HANDLE{}; | |||
| 50 | namespace Service { | 51 | namespace Service { |
| 51 | namespace FS { | 52 | namespace FS { |
| 52 | 53 | ||
| 53 | // TODO: Verify code | ||
| 54 | /// Returned when a function is passed an invalid handle. | ||
| 55 | const ResultCode ERR_INVALID_HANDLE(ErrorDescription::InvalidHandle, ErrorModule::FS, | ||
| 56 | ErrorSummary::InvalidArgument, ErrorLevel::Permanent); | ||
| 57 | |||
| 58 | /// Returned when a function is passed an invalid archive handle. | ||
| 59 | const ResultCode ERR_INVALID_ARCHIVE_HANDLE(ErrorDescription::FS_ArchiveNotMounted, ErrorModule::FS, | ||
| 60 | ErrorSummary::NotFound, | ||
| 61 | ErrorLevel::Status); // 0xC8804465 | ||
| 62 | |||
| 63 | // Command to access archive file | 54 | // Command to access archive file |
| 64 | enum class FileCommand : u32 { | 55 | enum class FileCommand : u32 { |
| 65 | Dummy1 = 0x000100C6, | 56 | Dummy1 = 0x000100C6, |
| @@ -284,7 +275,7 @@ ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code, FileSys::Path& archi | |||
| 284 | 275 | ||
| 285 | ResultCode CloseArchive(ArchiveHandle handle) { | 276 | ResultCode CloseArchive(ArchiveHandle handle) { |
| 286 | if (handle_map.erase(handle) == 0) | 277 | if (handle_map.erase(handle) == 0) |
| 287 | return ERR_INVALID_ARCHIVE_HANDLE; | 278 | return FileSys::ERR_INVALID_ARCHIVE_HANDLE; |
| 288 | else | 279 | else |
| 289 | return RESULT_SUCCESS; | 280 | return RESULT_SUCCESS; |
| 290 | } | 281 | } |
| @@ -309,7 +300,7 @@ ResultVal<std::shared_ptr<File>> OpenFileFromArchive(ArchiveHandle archive_handl | |||
| 309 | const FileSys::Mode mode) { | 300 | const FileSys::Mode mode) { |
| 310 | ArchiveBackend* archive = GetArchive(archive_handle); | 301 | ArchiveBackend* archive = GetArchive(archive_handle); |
| 311 | if (archive == nullptr) | 302 | if (archive == nullptr) |
| 312 | return ERR_INVALID_ARCHIVE_HANDLE; | 303 | return FileSys::ERR_INVALID_ARCHIVE_HANDLE; |
| 313 | 304 | ||
| 314 | auto backend = archive->OpenFile(path, mode); | 305 | auto backend = archive->OpenFile(path, mode); |
| 315 | if (backend.Failed()) | 306 | if (backend.Failed()) |
| @@ -322,7 +313,7 @@ ResultVal<std::shared_ptr<File>> OpenFileFromArchive(ArchiveHandle archive_handl | |||
| 322 | ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { | 313 | ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { |
| 323 | ArchiveBackend* archive = GetArchive(archive_handle); | 314 | ArchiveBackend* archive = GetArchive(archive_handle); |
| 324 | if (archive == nullptr) | 315 | if (archive == nullptr) |
| 325 | return ERR_INVALID_ARCHIVE_HANDLE; | 316 | return FileSys::ERR_INVALID_ARCHIVE_HANDLE; |
| 326 | 317 | ||
| 327 | return archive->DeleteFile(path); | 318 | return archive->DeleteFile(path); |
| 328 | } | 319 | } |
| @@ -334,7 +325,7 @@ ResultCode RenameFileBetweenArchives(ArchiveHandle src_archive_handle, | |||
| 334 | ArchiveBackend* src_archive = GetArchive(src_archive_handle); | 325 | ArchiveBackend* src_archive = GetArchive(src_archive_handle); |
| 335 | ArchiveBackend* dest_archive = GetArchive(dest_archive_handle); | 326 | ArchiveBackend* dest_archive = GetArchive(dest_archive_handle); |
| 336 | if (src_archive == nullptr || dest_archive == nullptr) | 327 | if (src_archive == nullptr || dest_archive == nullptr) |
| 337 | return ERR_INVALID_ARCHIVE_HANDLE; | 328 | return FileSys::ERR_INVALID_ARCHIVE_HANDLE; |
| 338 | 329 | ||
| 339 | if (src_archive == dest_archive) { | 330 | if (src_archive == dest_archive) { |
| 340 | return src_archive->RenameFile(src_path, dest_path); | 331 | return src_archive->RenameFile(src_path, dest_path); |
| @@ -347,7 +338,7 @@ ResultCode RenameFileBetweenArchives(ArchiveHandle src_archive_handle, | |||
| 347 | ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { | 338 | ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { |
| 348 | ArchiveBackend* archive = GetArchive(archive_handle); | 339 | ArchiveBackend* archive = GetArchive(archive_handle); |
| 349 | if (archive == nullptr) | 340 | if (archive == nullptr) |
| 350 | return ERR_INVALID_ARCHIVE_HANDLE; | 341 | return FileSys::ERR_INVALID_ARCHIVE_HANDLE; |
| 351 | 342 | ||
| 352 | return archive->DeleteDirectory(path); | 343 | return archive->DeleteDirectory(path); |
| 353 | } | 344 | } |
| @@ -356,7 +347,7 @@ ResultCode DeleteDirectoryRecursivelyFromArchive(ArchiveHandle archive_handle, | |||
| 356 | const FileSys::Path& path) { | 347 | const FileSys::Path& path) { |
| 357 | ArchiveBackend* archive = GetArchive(archive_handle); | 348 | ArchiveBackend* archive = GetArchive(archive_handle); |
| 358 | if (archive == nullptr) | 349 | if (archive == nullptr) |
| 359 | return ERR_INVALID_ARCHIVE_HANDLE; | 350 | return FileSys::ERR_INVALID_ARCHIVE_HANDLE; |
| 360 | 351 | ||
| 361 | return archive->DeleteDirectoryRecursively(path); | 352 | return archive->DeleteDirectoryRecursively(path); |
| 362 | } | 353 | } |
| @@ -365,7 +356,7 @@ ResultCode CreateFileInArchive(ArchiveHandle archive_handle, const FileSys::Path | |||
| 365 | u64 file_size) { | 356 | u64 file_size) { |
| 366 | ArchiveBackend* archive = GetArchive(archive_handle); | 357 | ArchiveBackend* archive = GetArchive(archive_handle); |
| 367 | if (archive == nullptr) | 358 | if (archive == nullptr) |
| 368 | return ERR_INVALID_ARCHIVE_HANDLE; | 359 | return FileSys::ERR_INVALID_ARCHIVE_HANDLE; |
| 369 | 360 | ||
| 370 | return archive->CreateFile(path, file_size); | 361 | return archive->CreateFile(path, file_size); |
| 371 | } | 362 | } |
| @@ -373,7 +364,7 @@ ResultCode CreateFileInArchive(ArchiveHandle archive_handle, const FileSys::Path | |||
| 373 | ResultCode CreateDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { | 364 | ResultCode CreateDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { |
| 374 | ArchiveBackend* archive = GetArchive(archive_handle); | 365 | ArchiveBackend* archive = GetArchive(archive_handle); |
| 375 | if (archive == nullptr) | 366 | if (archive == nullptr) |
| 376 | return ERR_INVALID_ARCHIVE_HANDLE; | 367 | return FileSys::ERR_INVALID_ARCHIVE_HANDLE; |
| 377 | 368 | ||
| 378 | return archive->CreateDirectory(path); | 369 | return archive->CreateDirectory(path); |
| 379 | } | 370 | } |
| @@ -385,7 +376,7 @@ ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle, | |||
| 385 | ArchiveBackend* src_archive = GetArchive(src_archive_handle); | 376 | ArchiveBackend* src_archive = GetArchive(src_archive_handle); |
| 386 | ArchiveBackend* dest_archive = GetArchive(dest_archive_handle); | 377 | ArchiveBackend* dest_archive = GetArchive(dest_archive_handle); |
| 387 | if (src_archive == nullptr || dest_archive == nullptr) | 378 | if (src_archive == nullptr || dest_archive == nullptr) |
| 388 | return ERR_INVALID_ARCHIVE_HANDLE; | 379 | return FileSys::ERR_INVALID_ARCHIVE_HANDLE; |
| 389 | 380 | ||
| 390 | if (src_archive == dest_archive) { | 381 | if (src_archive == dest_archive) { |
| 391 | return src_archive->RenameDirectory(src_path, dest_path); | 382 | return src_archive->RenameDirectory(src_path, dest_path); |
| @@ -399,7 +390,7 @@ ResultVal<std::shared_ptr<Directory>> OpenDirectoryFromArchive(ArchiveHandle arc | |||
| 399 | const FileSys::Path& path) { | 390 | const FileSys::Path& path) { |
| 400 | ArchiveBackend* archive = GetArchive(archive_handle); | 391 | ArchiveBackend* archive = GetArchive(archive_handle); |
| 401 | if (archive == nullptr) | 392 | if (archive == nullptr) |
| 402 | return ERR_INVALID_ARCHIVE_HANDLE; | 393 | return FileSys::ERR_INVALID_ARCHIVE_HANDLE; |
| 403 | 394 | ||
| 404 | auto backend = archive->OpenDirectory(path); | 395 | auto backend = archive->OpenDirectory(path); |
| 405 | if (backend.Failed()) | 396 | if (backend.Failed()) |
| @@ -412,7 +403,7 @@ ResultVal<std::shared_ptr<Directory>> OpenDirectoryFromArchive(ArchiveHandle arc | |||
| 412 | ResultVal<u64> GetFreeBytesInArchive(ArchiveHandle archive_handle) { | 403 | ResultVal<u64> GetFreeBytesInArchive(ArchiveHandle archive_handle) { |
| 413 | ArchiveBackend* archive = GetArchive(archive_handle); | 404 | ArchiveBackend* archive = GetArchive(archive_handle); |
| 414 | if (archive == nullptr) | 405 | if (archive == nullptr) |
| 415 | return ERR_INVALID_ARCHIVE_HANDLE; | 406 | return FileSys::ERR_INVALID_ARCHIVE_HANDLE; |
| 416 | return MakeResult<u64>(archive->GetFreeBytes()); | 407 | return MakeResult<u64>(archive->GetFreeBytes()); |
| 417 | } | 408 | } |
| 418 | 409 | ||
diff --git a/src/core/hle/service/fs/fs_user.cpp b/src/core/hle/service/fs/fs_user.cpp index 33b290699..e53a970d3 100644 --- a/src/core/hle/service/fs/fs_user.cpp +++ b/src/core/hle/service/fs/fs_user.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "common/scope_exit.h" | 9 | #include "common/scope_exit.h" |
| 10 | #include "common/string_util.h" | 10 | #include "common/string_util.h" |
| 11 | #include "core/file_sys/errors.h" | ||
| 11 | #include "core/hle/kernel/client_session.h" | 12 | #include "core/hle/kernel/client_session.h" |
| 12 | #include "core/hle/result.h" | 13 | #include "core/hle/result.h" |
| 13 | #include "core/hle/service/fs/archive.h" | 14 | #include "core/hle/service/fs/archive.h" |
| @@ -539,9 +540,7 @@ static void FormatSaveData(Service::Interface* self) { | |||
| 539 | if (archive_id != FS::ArchiveIdCode::SaveData) { | 540 | if (archive_id != FS::ArchiveIdCode::SaveData) { |
| 540 | LOG_ERROR(Service_FS, "tried to format an archive different than SaveData, %u", | 541 | LOG_ERROR(Service_FS, "tried to format an archive different than SaveData, %u", |
| 541 | static_cast<u32>(archive_id)); | 542 | static_cast<u32>(archive_id)); |
| 542 | cmd_buff[1] = ResultCode(ErrorDescription::FS_InvalidPath, ErrorModule::FS, | 543 | cmd_buff[1] = FileSys::ERROR_INVALID_PATH.raw; |
| 543 | ErrorSummary::InvalidArgument, ErrorLevel::Usage) | ||
| 544 | .raw; | ||
| 545 | return; | 544 | return; |
| 546 | } | 545 | } |
| 547 | 546 | ||
| @@ -802,9 +801,7 @@ static void InitializeWithSdkVersion(Service::Interface* self) { | |||
| 802 | cmd_buff[1] = RESULT_SUCCESS.raw; | 801 | cmd_buff[1] = RESULT_SUCCESS.raw; |
| 803 | } else { | 802 | } else { |
| 804 | LOG_ERROR(Service_FS, "ProcessId Header must be 0x20"); | 803 | LOG_ERROR(Service_FS, "ProcessId Header must be 0x20"); |
| 805 | cmd_buff[1] = ResultCode(ErrorDescription::OS_InvalidBufferDescriptor, ErrorModule::OS, | 804 | cmd_buff[1] = IPC::ERR_INVALID_BUFFER_DESCRIPTOR.raw; |
| 806 | ErrorSummary::WrongArgument, ErrorLevel::Permanent) | ||
| 807 | .raw; | ||
| 808 | } | 805 | } |
| 809 | } | 806 | } |
| 810 | 807 | ||
diff --git a/src/core/hle/service/gsp_gpu.cpp b/src/core/hle/service/gsp_gpu.cpp index a960778a7..46c4ed01a 100644 --- a/src/core/hle/service/gsp_gpu.cpp +++ b/src/core/hle/service/gsp_gpu.cpp | |||
| @@ -25,13 +25,24 @@ namespace GSP { | |||
| 25 | // Beginning address of HW regs | 25 | // Beginning address of HW regs |
| 26 | const u32 REGS_BEGIN = 0x1EB00000; | 26 | const u32 REGS_BEGIN = 0x1EB00000; |
| 27 | 27 | ||
| 28 | const ResultCode ERR_GSP_REGS_OUTOFRANGE_OR_MISALIGNED( | 28 | namespace ErrCodes { |
| 29 | ErrorDescription::OutofRangeOrMisalignedAddress, ErrorModule::GX, ErrorSummary::InvalidArgument, | 29 | enum { |
| 30 | ErrorLevel::Usage); // 0xE0E02A01 | 30 | // TODO(purpasmart): Check if this name fits its actual usage |
| 31 | const ResultCode ERR_GSP_REGS_MISALIGNED(ErrorDescription::MisalignedSize, ErrorModule::GX, | 31 | OutofRangeOrMisalignedAddress = 513, |
| 32 | FirstInitialization = 519, | ||
| 33 | }; | ||
| 34 | } | ||
| 35 | |||
| 36 | constexpr ResultCode RESULT_FIRST_INITIALIZATION(ErrCodes::FirstInitialization, ErrorModule::GX, | ||
| 37 | ErrorSummary::Success, ErrorLevel::Success); | ||
| 38 | constexpr ResultCode ERR_REGS_OUTOFRANGE_OR_MISALIGNED(ErrCodes::OutofRangeOrMisalignedAddress, | ||
| 39 | ErrorModule::GX, | ||
| 40 | ErrorSummary::InvalidArgument, | ||
| 41 | ErrorLevel::Usage); // 0xE0E02A01 | ||
| 42 | constexpr ResultCode ERR_REGS_MISALIGNED(ErrorDescription::MisalignedSize, ErrorModule::GX, | ||
| 32 | ErrorSummary::InvalidArgument, | 43 | ErrorSummary::InvalidArgument, |
| 33 | ErrorLevel::Usage); // 0xE0E02BF2 | 44 | ErrorLevel::Usage); // 0xE0E02BF2 |
| 34 | const ResultCode ERR_GSP_REGS_INVALID_SIZE(ErrorDescription::InvalidSize, ErrorModule::GX, | 45 | constexpr ResultCode ERR_REGS_INVALID_SIZE(ErrorDescription::InvalidSize, ErrorModule::GX, |
| 35 | ErrorSummary::InvalidArgument, | 46 | ErrorSummary::InvalidArgument, |
| 36 | ErrorLevel::Usage); // 0xE0E02BEC | 47 | ErrorLevel::Usage); // 0xE0E02BEC |
| 37 | 48 | ||
| @@ -93,11 +104,11 @@ static ResultCode WriteHWRegs(u32 base_address, u32 size_in_bytes, VAddr data_va | |||
| 93 | LOG_ERROR(Service_GSP, | 104 | LOG_ERROR(Service_GSP, |
| 94 | "Write address was out of range or misaligned! (address=0x%08x, size=0x%08x)", | 105 | "Write address was out of range or misaligned! (address=0x%08x, size=0x%08x)", |
| 95 | base_address, size_in_bytes); | 106 | base_address, size_in_bytes); |
| 96 | return ERR_GSP_REGS_OUTOFRANGE_OR_MISALIGNED; | 107 | return ERR_REGS_OUTOFRANGE_OR_MISALIGNED; |
| 97 | } else if (size_in_bytes <= max_size_in_bytes) { | 108 | } else if (size_in_bytes <= max_size_in_bytes) { |
| 98 | if (size_in_bytes & 3) { | 109 | if (size_in_bytes & 3) { |
| 99 | LOG_ERROR(Service_GSP, "Misaligned size 0x%08x", size_in_bytes); | 110 | LOG_ERROR(Service_GSP, "Misaligned size 0x%08x", size_in_bytes); |
| 100 | return ERR_GSP_REGS_MISALIGNED; | 111 | return ERR_REGS_MISALIGNED; |
| 101 | } else { | 112 | } else { |
| 102 | while (size_in_bytes > 0) { | 113 | while (size_in_bytes > 0) { |
| 103 | WriteSingleHWReg(base_address, Memory::Read32(data_vaddr)); | 114 | WriteSingleHWReg(base_address, Memory::Read32(data_vaddr)); |
| @@ -111,7 +122,7 @@ static ResultCode WriteHWRegs(u32 base_address, u32 size_in_bytes, VAddr data_va | |||
| 111 | 122 | ||
| 112 | } else { | 123 | } else { |
| 113 | LOG_ERROR(Service_GSP, "Out of range size 0x%08x", size_in_bytes); | 124 | LOG_ERROR(Service_GSP, "Out of range size 0x%08x", size_in_bytes); |
| 114 | return ERR_GSP_REGS_INVALID_SIZE; | 125 | return ERR_REGS_INVALID_SIZE; |
| 115 | } | 126 | } |
| 116 | } | 127 | } |
| 117 | 128 | ||
| @@ -134,11 +145,11 @@ static ResultCode WriteHWRegsWithMask(u32 base_address, u32 size_in_bytes, VAddr | |||
| 134 | LOG_ERROR(Service_GSP, | 145 | LOG_ERROR(Service_GSP, |
| 135 | "Write address was out of range or misaligned! (address=0x%08x, size=0x%08x)", | 146 | "Write address was out of range or misaligned! (address=0x%08x, size=0x%08x)", |
| 136 | base_address, size_in_bytes); | 147 | base_address, size_in_bytes); |
| 137 | return ERR_GSP_REGS_OUTOFRANGE_OR_MISALIGNED; | 148 | return ERR_REGS_OUTOFRANGE_OR_MISALIGNED; |
| 138 | } else if (size_in_bytes <= max_size_in_bytes) { | 149 | } else if (size_in_bytes <= max_size_in_bytes) { |
| 139 | if (size_in_bytes & 3) { | 150 | if (size_in_bytes & 3) { |
| 140 | LOG_ERROR(Service_GSP, "Misaligned size 0x%08x", size_in_bytes); | 151 | LOG_ERROR(Service_GSP, "Misaligned size 0x%08x", size_in_bytes); |
| 141 | return ERR_GSP_REGS_MISALIGNED; | 152 | return ERR_REGS_MISALIGNED; |
| 142 | } else { | 153 | } else { |
| 143 | while (size_in_bytes > 0) { | 154 | while (size_in_bytes > 0) { |
| 144 | const u32 reg_address = base_address + REGS_BEGIN; | 155 | const u32 reg_address = base_address + REGS_BEGIN; |
| @@ -164,7 +175,7 @@ static ResultCode WriteHWRegsWithMask(u32 base_address, u32 size_in_bytes, VAddr | |||
| 164 | 175 | ||
| 165 | } else { | 176 | } else { |
| 166 | LOG_ERROR(Service_GSP, "Out of range size 0x%08x", size_in_bytes); | 177 | LOG_ERROR(Service_GSP, "Out of range size 0x%08x", size_in_bytes); |
| 167 | return ERR_GSP_REGS_INVALID_SIZE; | 178 | return ERR_REGS_INVALID_SIZE; |
| 168 | } | 179 | } |
| 169 | } | 180 | } |
| 170 | 181 | ||
| @@ -372,9 +383,7 @@ static void RegisterInterruptRelayQueue(Interface* self) { | |||
| 372 | if (first_initialization) { | 383 | if (first_initialization) { |
| 373 | // This specific code is required for a successful initialization, rather than 0 | 384 | // This specific code is required for a successful initialization, rather than 0 |
| 374 | first_initialization = false; | 385 | first_initialization = false; |
| 375 | cmd_buff[1] = ResultCode(ErrorDescription::GPU_FirstInitialization, ErrorModule::GX, | 386 | cmd_buff[1] = RESULT_FIRST_INITIALIZATION.raw; |
| 376 | ErrorSummary::Success, ErrorLevel::Success) | ||
| 377 | .raw; | ||
| 378 | } else { | 387 | } else { |
| 379 | cmd_buff[1] = RESULT_SUCCESS.raw; | 388 | cmd_buff[1] = RESULT_SUCCESS.raw; |
| 380 | } | 389 | } |
diff --git a/src/core/hle/service/ir/ir_user.cpp b/src/core/hle/service/ir/ir_user.cpp index 226af0083..369115f09 100644 --- a/src/core/hle/service/ir/ir_user.cpp +++ b/src/core/hle/service/ir/ir_user.cpp | |||
| @@ -267,8 +267,7 @@ static void InitializeIrNopShared(Interface* self) { | |||
| 267 | shared_memory = Kernel::g_handle_table.Get<Kernel::SharedMemory>(handle); | 267 | shared_memory = Kernel::g_handle_table.Get<Kernel::SharedMemory>(handle); |
| 268 | if (!shared_memory) { | 268 | if (!shared_memory) { |
| 269 | LOG_CRITICAL(Service_IR, "invalid shared memory handle 0x%08X", handle); | 269 | LOG_CRITICAL(Service_IR, "invalid shared memory handle 0x%08X", handle); |
| 270 | rb.Push(ResultCode(ErrorDescription::InvalidHandle, ErrorModule::OS, | 270 | rb.Push(IPC::ERR_INVALID_HANDLE); |
| 271 | ErrorSummary::WrongArgument, ErrorLevel::Permanent)); | ||
| 272 | return; | 271 | return; |
| 273 | } | 272 | } |
| 274 | shared_memory->name = "IR_USER: shared memory"; | 273 | shared_memory->name = "IR_USER: shared memory"; |
diff --git a/src/core/hle/service/ptm/ptm.cpp b/src/core/hle/service/ptm/ptm.cpp index 319e8c946..39382ef09 100644 --- a/src/core/hle/service/ptm/ptm.cpp +++ b/src/core/hle/service/ptm/ptm.cpp | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/logging/log.h" | 5 | #include "common/logging/log.h" |
| 6 | #include "core/file_sys/errors.h" | ||
| 6 | #include "core/file_sys/file_backend.h" | 7 | #include "core/file_sys/file_backend.h" |
| 7 | #include "core/hle/service/fs/archive.h" | 8 | #include "core/hle/service/fs/archive.h" |
| 8 | #include "core/hle/service/ptm/ptm.h" | 9 | #include "core/hle/service/ptm/ptm.h" |
| @@ -134,7 +135,7 @@ void Init() { | |||
| 134 | auto archive_result = | 135 | auto archive_result = |
| 135 | Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path); | 136 | Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path); |
| 136 | // If the archive didn't exist, create the files inside | 137 | // If the archive didn't exist, create the files inside |
| 137 | if (archive_result.Code().description == ErrorDescription::FS_NotFormatted) { | 138 | if (archive_result.Code() == FileSys::ERR_NOT_FORMATTED) { |
| 138 | // Format the archive to create the directories | 139 | // Format the archive to create the directories |
| 139 | Service::FS::FormatArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, | 140 | Service::FS::FormatArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, |
| 140 | FileSys::ArchiveFormatInfo(), archive_path); | 141 | FileSys::ArchiveFormatInfo(), archive_path); |
diff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cpp index 3bd787147..130c9d25e 100644 --- a/src/core/hle/service/srv.cpp +++ b/src/core/hle/service/srv.cpp | |||
| @@ -30,9 +30,7 @@ static void RegisterClient(Interface* self) { | |||
| 30 | 30 | ||
| 31 | if (cmd_buff[1] != IPC::CallingPidDesc()) { | 31 | if (cmd_buff[1] != IPC::CallingPidDesc()) { |
| 32 | cmd_buff[0] = IPC::MakeHeader(0x0, 0x1, 0); // 0x40 | 32 | cmd_buff[0] = IPC::MakeHeader(0x0, 0x1, 0); // 0x40 |
| 33 | cmd_buff[1] = ResultCode(ErrorDescription::OS_InvalidBufferDescriptor, ErrorModule::OS, | 33 | cmd_buff[1] = IPC::ERR_INVALID_BUFFER_DESCRIPTOR.raw; |
| 34 | ErrorSummary::WrongArgument, ErrorLevel::Permanent) | ||
| 35 | .raw; | ||
| 36 | return; | 34 | return; |
| 37 | } | 35 | } |
| 38 | cmd_buff[0] = IPC::MakeHeader(0x1, 0x1, 0); // 0x10040 | 36 | cmd_buff[0] = IPC::MakeHeader(0x1, 0x1, 0); // 0x10040 |
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 8538cfc9d..30230d65a 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | #include "core/hle/kernel/address_arbiter.h" | 14 | #include "core/hle/kernel/address_arbiter.h" |
| 15 | #include "core/hle/kernel/client_port.h" | 15 | #include "core/hle/kernel/client_port.h" |
| 16 | #include "core/hle/kernel/client_session.h" | 16 | #include "core/hle/kernel/client_session.h" |
| 17 | #include "core/hle/kernel/errors.h" | ||
| 17 | #include "core/hle/kernel/event.h" | 18 | #include "core/hle/kernel/event.h" |
| 18 | #include "core/hle/kernel/memory.h" | 19 | #include "core/hle/kernel/memory.h" |
| 19 | #include "core/hle/kernel/mutex.h" | 20 | #include "core/hle/kernel/mutex.h" |
| @@ -37,25 +38,6 @@ using Kernel::ERR_INVALID_HANDLE; | |||
| 37 | 38 | ||
| 38 | namespace SVC { | 39 | namespace SVC { |
| 39 | 40 | ||
| 40 | const ResultCode ERR_NOT_FOUND(ErrorDescription::NotFound, ErrorModule::Kernel, | ||
| 41 | ErrorSummary::NotFound, ErrorLevel::Permanent); // 0xD88007FA | ||
| 42 | const ResultCode ERR_PORT_NAME_TOO_LONG(ErrorDescription(30), ErrorModule::OS, | ||
| 43 | ErrorSummary::InvalidArgument, | ||
| 44 | ErrorLevel::Usage); // 0xE0E0181E | ||
| 45 | |||
| 46 | const ResultCode ERR_SYNC_TIMEOUT(ErrorDescription::Timeout, ErrorModule::OS, | ||
| 47 | ErrorSummary::StatusChanged, ErrorLevel::Info); | ||
| 48 | |||
| 49 | const ResultCode ERR_MISALIGNED_ADDRESS{// 0xE0E01BF1 | ||
| 50 | ErrorDescription::MisalignedAddress, ErrorModule::OS, | ||
| 51 | ErrorSummary::InvalidArgument, ErrorLevel::Usage}; | ||
| 52 | const ResultCode ERR_MISALIGNED_SIZE{// 0xE0E01BF2 | ||
| 53 | ErrorDescription::MisalignedSize, ErrorModule::OS, | ||
| 54 | ErrorSummary::InvalidArgument, ErrorLevel::Usage}; | ||
| 55 | const ResultCode ERR_INVALID_COMBINATION{// 0xE0E01BEE | ||
| 56 | ErrorDescription::InvalidCombination, ErrorModule::OS, | ||
| 57 | ErrorSummary::InvalidArgument, ErrorLevel::Usage}; | ||
| 58 | |||
| 59 | enum ControlMemoryOperation { | 41 | enum ControlMemoryOperation { |
| 60 | MEMOP_FREE = 1, | 42 | MEMOP_FREE = 1, |
| 61 | MEMOP_RESERVE = 2, // This operation seems to be unsupported in the kernel | 43 | MEMOP_RESERVE = 2, // This operation seems to be unsupported in the kernel |
| @@ -195,8 +177,7 @@ static ResultCode MapMemoryBlock(Kernel::Handle handle, u32 addr, u32 permission | |||
| 195 | LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); | 177 | LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); |
| 196 | } | 178 | } |
| 197 | 179 | ||
| 198 | return ResultCode(ErrorDescription::InvalidCombination, ErrorModule::OS, | 180 | return Kernel::ERR_INVALID_COMBINATION; |
| 199 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 200 | } | 181 | } |
| 201 | 182 | ||
| 202 | static ResultCode UnmapMemoryBlock(Kernel::Handle handle, u32 addr) { | 183 | static ResultCode UnmapMemoryBlock(Kernel::Handle handle, u32 addr) { |
| @@ -216,16 +197,16 @@ static ResultCode UnmapMemoryBlock(Kernel::Handle handle, u32 addr) { | |||
| 216 | /// Connect to an OS service given the port name, returns the handle to the port to out | 197 | /// Connect to an OS service given the port name, returns the handle to the port to out |
| 217 | static ResultCode ConnectToPort(Kernel::Handle* out_handle, const char* port_name) { | 198 | static ResultCode ConnectToPort(Kernel::Handle* out_handle, const char* port_name) { |
| 218 | if (port_name == nullptr) | 199 | if (port_name == nullptr) |
| 219 | return ERR_NOT_FOUND; | 200 | return Kernel::ERR_NOT_FOUND; |
| 220 | if (std::strlen(port_name) > 11) | 201 | if (std::strlen(port_name) > 11) |
| 221 | return ERR_PORT_NAME_TOO_LONG; | 202 | return Kernel::ERR_PORT_NAME_TOO_LONG; |
| 222 | 203 | ||
| 223 | LOG_TRACE(Kernel_SVC, "called port_name=%s", port_name); | 204 | LOG_TRACE(Kernel_SVC, "called port_name=%s", port_name); |
| 224 | 205 | ||
| 225 | auto it = Service::g_kernel_named_ports.find(port_name); | 206 | auto it = Service::g_kernel_named_ports.find(port_name); |
| 226 | if (it == Service::g_kernel_named_ports.end()) { | 207 | if (it == Service::g_kernel_named_ports.end()) { |
| 227 | LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: %s", port_name); | 208 | LOG_WARNING(Kernel_SVC, "tried to connect to unknown port: %s", port_name); |
| 228 | return ERR_NOT_FOUND; | 209 | return Kernel::ERR_NOT_FOUND; |
| 229 | } | 210 | } |
| 230 | 211 | ||
| 231 | auto client_port = it->second; | 212 | auto client_port = it->second; |
| @@ -275,7 +256,7 @@ static ResultCode WaitSynchronization1(Kernel::Handle handle, s64 nano_seconds) | |||
| 275 | if (object->ShouldWait(thread)) { | 256 | if (object->ShouldWait(thread)) { |
| 276 | 257 | ||
| 277 | if (nano_seconds == 0) | 258 | if (nano_seconds == 0) |
| 278 | return ERR_SYNC_TIMEOUT; | 259 | return Kernel::RESULT_TIMEOUT; |
| 279 | 260 | ||
| 280 | thread->wait_objects = {object}; | 261 | thread->wait_objects = {object}; |
| 281 | object->AddWaitingThread(thread); | 262 | object->AddWaitingThread(thread); |
| @@ -289,7 +270,7 @@ static ResultCode WaitSynchronization1(Kernel::Handle handle, s64 nano_seconds) | |||
| 289 | // Note: The output of this SVC will be set to RESULT_SUCCESS if the thread | 270 | // Note: The output of this SVC will be set to RESULT_SUCCESS if the thread |
| 290 | // resumes due to a signal in its wait objects. | 271 | // resumes due to a signal in its wait objects. |
| 291 | // Otherwise we retain the default value of timeout. | 272 | // Otherwise we retain the default value of timeout. |
| 292 | return ERR_SYNC_TIMEOUT; | 273 | return Kernel::RESULT_TIMEOUT; |
| 293 | } | 274 | } |
| 294 | 275 | ||
| 295 | object->Acquire(thread); | 276 | object->Acquire(thread); |
| @@ -304,8 +285,7 @@ static ResultCode WaitSynchronizationN(s32* out, Kernel::Handle* handles, s32 ha | |||
| 304 | 285 | ||
| 305 | // Check if 'handles' is invalid | 286 | // Check if 'handles' is invalid |
| 306 | if (handles == nullptr) | 287 | if (handles == nullptr) |
| 307 | return ResultCode(ErrorDescription::InvalidPointer, ErrorModule::Kernel, | 288 | return Kernel::ERR_INVALID_POINTER; |
| 308 | ErrorSummary::InvalidArgument, ErrorLevel::Permanent); | ||
| 309 | 289 | ||
| 310 | // NOTE: on real hardware, there is no nullptr check for 'out' (tested with firmware 4.4). If | 290 | // NOTE: on real hardware, there is no nullptr check for 'out' (tested with firmware 4.4). If |
| 311 | // this happens, the running application will crash. | 291 | // this happens, the running application will crash. |
| @@ -313,8 +293,7 @@ static ResultCode WaitSynchronizationN(s32* out, Kernel::Handle* handles, s32 ha | |||
| 313 | 293 | ||
| 314 | // Check if 'handle_count' is invalid | 294 | // Check if 'handle_count' is invalid |
| 315 | if (handle_count < 0) | 295 | if (handle_count < 0) |
| 316 | return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS, | 296 | return Kernel::ERR_OUT_OF_RANGE; |
| 317 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 318 | 297 | ||
| 319 | using ObjectPtr = Kernel::SharedPtr<Kernel::WaitObject>; | 298 | using ObjectPtr = Kernel::SharedPtr<Kernel::WaitObject>; |
| 320 | std::vector<ObjectPtr> objects(handle_count); | 299 | std::vector<ObjectPtr> objects(handle_count); |
| @@ -344,7 +323,7 @@ static ResultCode WaitSynchronizationN(s32* out, Kernel::Handle* handles, s32 ha | |||
| 344 | // If a timeout value of 0 was provided, just return the Timeout error code instead of | 323 | // If a timeout value of 0 was provided, just return the Timeout error code instead of |
| 345 | // suspending the thread. | 324 | // suspending the thread. |
| 346 | if (nano_seconds == 0) | 325 | if (nano_seconds == 0) |
| 347 | return ERR_SYNC_TIMEOUT; | 326 | return Kernel::RESULT_TIMEOUT; |
| 348 | 327 | ||
| 349 | // Put the thread to sleep | 328 | // Put the thread to sleep |
| 350 | thread->status = THREADSTATUS_WAIT_SYNCH_ALL; | 329 | thread->status = THREADSTATUS_WAIT_SYNCH_ALL; |
| @@ -365,7 +344,7 @@ static ResultCode WaitSynchronizationN(s32* out, Kernel::Handle* handles, s32 ha | |||
| 365 | *out = -1; | 344 | *out = -1; |
| 366 | // Note: The output of this SVC will be set to RESULT_SUCCESS if the thread resumes due to | 345 | // Note: The output of this SVC will be set to RESULT_SUCCESS if the thread resumes due to |
| 367 | // a signal in one of its wait objects. | 346 | // a signal in one of its wait objects. |
| 368 | return ERR_SYNC_TIMEOUT; | 347 | return Kernel::RESULT_TIMEOUT; |
| 369 | } else { | 348 | } else { |
| 370 | // Find the first object that is acquirable in the provided list of objects | 349 | // Find the first object that is acquirable in the provided list of objects |
| 371 | auto itr = std::find_if(objects.begin(), objects.end(), [thread](const ObjectPtr& object) { | 350 | auto itr = std::find_if(objects.begin(), objects.end(), [thread](const ObjectPtr& object) { |
| @@ -385,7 +364,7 @@ static ResultCode WaitSynchronizationN(s32* out, Kernel::Handle* handles, s32 ha | |||
| 385 | // If a timeout value of 0 was provided, just return the Timeout error code instead of | 364 | // If a timeout value of 0 was provided, just return the Timeout error code instead of |
| 386 | // suspending the thread. | 365 | // suspending the thread. |
| 387 | if (nano_seconds == 0) | 366 | if (nano_seconds == 0) |
| 388 | return ERR_SYNC_TIMEOUT; | 367 | return Kernel::RESULT_TIMEOUT; |
| 389 | 368 | ||
| 390 | // Put the thread to sleep | 369 | // Put the thread to sleep |
| 391 | thread->status = THREADSTATUS_WAIT_SYNCH_ANY; | 370 | thread->status = THREADSTATUS_WAIT_SYNCH_ANY; |
| @@ -411,7 +390,7 @@ static ResultCode WaitSynchronizationN(s32* out, Kernel::Handle* handles, s32 ha | |||
| 411 | // Otherwise we retain the default value of timeout, and -1 in the out parameter | 390 | // Otherwise we retain the default value of timeout, and -1 in the out parameter |
| 412 | thread->wait_set_output = true; | 391 | thread->wait_set_output = true; |
| 413 | *out = -1; | 392 | *out = -1; |
| 414 | return ERR_SYNC_TIMEOUT; | 393 | return Kernel::RESULT_TIMEOUT; |
| 415 | } | 394 | } |
| 416 | } | 395 | } |
| 417 | 396 | ||
| @@ -520,22 +499,20 @@ static ResultCode GetResourceLimitLimitValues(s64* values, Kernel::Handle resour | |||
| 520 | } | 499 | } |
| 521 | 500 | ||
| 522 | /// Creates a new thread | 501 | /// Creates a new thread |
| 523 | static ResultCode CreateThread(Kernel::Handle* out_handle, s32 priority, u32 entry_point, u32 arg, | 502 | static ResultCode CreateThread(Kernel::Handle* out_handle, u32 priority, u32 entry_point, u32 arg, |
| 524 | u32 stack_top, s32 processor_id) { | 503 | u32 stack_top, s32 processor_id) { |
| 525 | using Kernel::Thread; | 504 | using Kernel::Thread; |
| 526 | 505 | ||
| 527 | std::string name = Common::StringFromFormat("unknown-%08" PRIX32, entry_point); | 506 | std::string name = Common::StringFromFormat("unknown-%08" PRIX32, entry_point); |
| 528 | 507 | ||
| 529 | if (priority > THREADPRIO_LOWEST) { | 508 | if (priority > THREADPRIO_LOWEST) { |
| 530 | return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS, | 509 | return Kernel::ERR_OUT_OF_RANGE; |
| 531 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 532 | } | 510 | } |
| 533 | 511 | ||
| 534 | using Kernel::ResourceLimit; | 512 | using Kernel::ResourceLimit; |
| 535 | Kernel::SharedPtr<ResourceLimit>& resource_limit = Kernel::g_current_process->resource_limit; | 513 | Kernel::SharedPtr<ResourceLimit>& resource_limit = Kernel::g_current_process->resource_limit; |
| 536 | if (resource_limit->GetMaxResourceValue(Kernel::ResourceTypes::PRIORITY) > priority) { | 514 | if (resource_limit->GetMaxResourceValue(Kernel::ResourceTypes::PRIORITY) > priority) { |
| 537 | return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::OS, | 515 | return Kernel::ERR_NOT_AUTHORIZED; |
| 538 | ErrorSummary::WrongArgument, ErrorLevel::Permanent); | ||
| 539 | } | 516 | } |
| 540 | 517 | ||
| 541 | switch (processor_id) { | 518 | switch (processor_id) { |
| @@ -605,8 +582,7 @@ static ResultCode GetThreadPriority(s32* priority, Kernel::Handle handle) { | |||
| 605 | /// Sets the priority for the specified thread | 582 | /// Sets the priority for the specified thread |
| 606 | static ResultCode SetThreadPriority(Kernel::Handle handle, s32 priority) { | 583 | static ResultCode SetThreadPriority(Kernel::Handle handle, s32 priority) { |
| 607 | if (priority > THREADPRIO_LOWEST) { | 584 | if (priority > THREADPRIO_LOWEST) { |
| 608 | return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS, | 585 | return Kernel::ERR_OUT_OF_RANGE; |
| 609 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 610 | } | 586 | } |
| 611 | 587 | ||
| 612 | SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); | 588 | SharedPtr<Kernel::Thread> thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); |
| @@ -618,8 +594,7 @@ static ResultCode SetThreadPriority(Kernel::Handle handle, s32 priority) { | |||
| 618 | // the one from the thread owner's resource limit. | 594 | // the one from the thread owner's resource limit. |
| 619 | Kernel::SharedPtr<ResourceLimit>& resource_limit = Kernel::g_current_process->resource_limit; | 595 | Kernel::SharedPtr<ResourceLimit>& resource_limit = Kernel::g_current_process->resource_limit; |
| 620 | if (resource_limit->GetMaxResourceValue(Kernel::ResourceTypes::PRIORITY) > priority) { | 596 | if (resource_limit->GetMaxResourceValue(Kernel::ResourceTypes::PRIORITY) > priority) { |
| 621 | return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::OS, | 597 | return Kernel::ERR_NOT_AUTHORIZED; |
| 622 | ErrorSummary::WrongArgument, ErrorLevel::Permanent); | ||
| 623 | } | 598 | } |
| 624 | 599 | ||
| 625 | thread->SetPriority(priority); | 600 | thread->SetPriority(priority); |
| @@ -743,8 +718,7 @@ static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* page_inf | |||
| 743 | auto vma = process->vm_manager.FindVMA(addr); | 718 | auto vma = process->vm_manager.FindVMA(addr); |
| 744 | 719 | ||
| 745 | if (vma == Kernel::g_current_process->vm_manager.vma_map.end()) | 720 | if (vma == Kernel::g_current_process->vm_manager.vma_map.end()) |
| 746 | return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::OS, | 721 | return Kernel::ERR_INVALID_ADDRESS; |
| 747 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 748 | 722 | ||
| 749 | memory_info->base_address = vma->second.base; | 723 | memory_info->base_address = vma->second.base; |
| 750 | memory_info->permission = static_cast<u32>(vma->second.permissions); | 724 | memory_info->permission = static_cast<u32>(vma->second.permissions); |
| @@ -842,8 +816,7 @@ static ResultCode SetTimer(Kernel::Handle handle, s64 initial, s64 interval) { | |||
| 842 | LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); | 816 | LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); |
| 843 | 817 | ||
| 844 | if (initial < 0 || interval < 0) { | 818 | if (initial < 0 || interval < 0) { |
| 845 | return ResultCode(ErrorDescription::OutOfRange, ErrorModule::Kernel, | 819 | return Kernel::ERR_OUT_OF_RANGE_KERNEL; |
| 846 | ErrorSummary::InvalidArgument, ErrorLevel::Permanent); | ||
| 847 | } | 820 | } |
| 848 | 821 | ||
| 849 | SharedPtr<Timer> timer = Kernel::g_handle_table.Get<Timer>(handle); | 822 | SharedPtr<Timer> timer = Kernel::g_handle_table.Get<Timer>(handle); |
| @@ -902,8 +875,7 @@ static ResultCode CreateMemoryBlock(Kernel::Handle* out_handle, u32 addr, u32 si | |||
| 902 | using Kernel::SharedMemory; | 875 | using Kernel::SharedMemory; |
| 903 | 876 | ||
| 904 | if (size % Memory::PAGE_SIZE != 0) | 877 | if (size % Memory::PAGE_SIZE != 0) |
| 905 | return ResultCode(ErrorDescription::MisalignedSize, ErrorModule::OS, | 878 | return Kernel::ERR_MISALIGNED_SIZE; |
| 906 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 907 | 879 | ||
| 908 | SharedPtr<SharedMemory> shared_memory = nullptr; | 880 | SharedPtr<SharedMemory> shared_memory = nullptr; |
| 909 | 881 | ||
| @@ -924,16 +896,14 @@ static ResultCode CreateMemoryBlock(Kernel::Handle* out_handle, u32 addr, u32 si | |||
| 924 | 896 | ||
| 925 | if (!VerifyPermissions(static_cast<MemoryPermission>(my_permission)) || | 897 | if (!VerifyPermissions(static_cast<MemoryPermission>(my_permission)) || |
| 926 | !VerifyPermissions(static_cast<MemoryPermission>(other_permission))) | 898 | !VerifyPermissions(static_cast<MemoryPermission>(other_permission))) |
| 927 | return ResultCode(ErrorDescription::InvalidCombination, ErrorModule::OS, | 899 | return Kernel::ERR_INVALID_COMBINATION; |
| 928 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 929 | 900 | ||
| 930 | // TODO(Subv): Processes with memory type APPLICATION are not allowed | 901 | // TODO(Subv): Processes with memory type APPLICATION are not allowed |
| 931 | // to create memory blocks with addr = 0, any attempts to do so | 902 | // to create memory blocks with addr = 0, any attempts to do so |
| 932 | // should return error 0xD92007EA. | 903 | // should return error 0xD92007EA. |
| 933 | if ((addr < Memory::PROCESS_IMAGE_VADDR || addr + size > Memory::SHARED_MEMORY_VADDR_END) && | 904 | if ((addr < Memory::PROCESS_IMAGE_VADDR || addr + size > Memory::SHARED_MEMORY_VADDR_END) && |
| 934 | addr != 0) { | 905 | addr != 0) { |
| 935 | return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::OS, | 906 | return Kernel::ERR_INVALID_ADDRESS; |
| 936 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 937 | } | 907 | } |
| 938 | 908 | ||
| 939 | // When trying to create a memory block with address = 0, | 909 | // When trying to create a memory block with address = 0, |
| @@ -1035,7 +1005,7 @@ static ResultCode GetProcessInfo(s64* out, Kernel::Handle process_handle, u32 ty | |||
| 1035 | *out = process->heap_used + process->linear_heap_used + process->misc_memory_used; | 1005 | *out = process->heap_used + process->linear_heap_used + process->misc_memory_used; |
| 1036 | if (*out % Memory::PAGE_SIZE != 0) { | 1006 | if (*out % Memory::PAGE_SIZE != 0) { |
| 1037 | LOG_ERROR(Kernel_SVC, "called, memory size not page-aligned"); | 1007 | LOG_ERROR(Kernel_SVC, "called, memory size not page-aligned"); |
| 1038 | return ERR_MISALIGNED_SIZE; | 1008 | return Kernel::ERR_MISALIGNED_SIZE; |
| 1039 | } | 1009 | } |
| 1040 | break; | 1010 | break; |
| 1041 | case 1: | 1011 | case 1: |
| @@ -1051,19 +1021,15 @@ static ResultCode GetProcessInfo(s64* out, Kernel::Handle process_handle, u32 ty | |||
| 1051 | case 20: | 1021 | case 20: |
| 1052 | *out = Memory::FCRAM_PADDR - process->GetLinearHeapBase(); | 1022 | *out = Memory::FCRAM_PADDR - process->GetLinearHeapBase(); |
| 1053 | break; | 1023 | break; |
| 1024 | case 21: | ||
| 1025 | case 22: | ||
| 1026 | case 23: | ||
| 1027 | // These return a different error value than higher invalid values | ||
| 1028 | LOG_ERROR(Kernel_SVC, "unknown GetProcessInfo type=%u", type); | ||
| 1029 | return Kernel::ERR_NOT_IMPLEMENTED; | ||
| 1054 | default: | 1030 | default: |
| 1055 | LOG_ERROR(Kernel_SVC, "unknown GetProcessInfo type=%u", type); | 1031 | LOG_ERROR(Kernel_SVC, "unknown GetProcessInfo type=%u", type); |
| 1056 | 1032 | return Kernel::ERR_INVALID_ENUM_VALUE; | |
| 1057 | if (type >= 21 && type <= 23) { | ||
| 1058 | return ResultCode( // 0xE0E01BF4 | ||
| 1059 | ErrorDescription::NotImplemented, ErrorModule::OS, ErrorSummary::InvalidArgument, | ||
| 1060 | ErrorLevel::Usage); | ||
| 1061 | } else { | ||
| 1062 | return ResultCode( // 0xD8E007ED | ||
| 1063 | ErrorDescription::InvalidEnumValue, ErrorModule::Kernel, | ||
| 1064 | ErrorSummary::InvalidArgument, ErrorLevel::Permanent); | ||
| 1065 | } | ||
| 1066 | break; | ||
| 1067 | } | 1033 | } |
| 1068 | 1034 | ||
| 1069 | return RESULT_SUCCESS; | 1035 | return RESULT_SUCCESS; |