summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/file_sys/errors.h66
-rw-r--r--src/core/file_sys/ivfc_archive.cpp10
-rw-r--r--src/core/file_sys/savedata_archive.cpp22
-rw-r--r--src/core/hle/ipc.h1
-rw-r--r--src/core/hle/kernel/errors.h94
-rw-r--r--src/core/hle/kernel/thread.cpp5
-rw-r--r--src/core/hle/result.h240
-rw-r--r--src/core/hle/service/sm/sm.h18
8 files changed, 110 insertions, 346 deletions
diff --git a/src/core/file_sys/errors.h b/src/core/file_sys/errors.h
index a974bc775..be3224ef8 100644
--- a/src/core/file_sys/errors.h
+++ b/src/core/file_sys/errors.h
@@ -34,61 +34,15 @@ enum {
34}; 34};
35} 35}
36 36
37constexpr ResultCode ERROR_INVALID_PATH(ErrCodes::InvalidPath, ErrorModule::FS, 37// TODO(bunnei): Replace these with correct errors for Switch OS
38 ErrorSummary::InvalidArgument, ErrorLevel::Usage); 38constexpr ResultCode ERROR_INVALID_PATH(ResultCode(-1));
39constexpr ResultCode ERROR_UNSUPPORTED_OPEN_FLAGS(ErrCodes::UnsupportedOpenFlags, ErrorModule::FS, 39constexpr ResultCode ERROR_UNSUPPORTED_OPEN_FLAGS(ResultCode(-1));
40 ErrorSummary::NotSupported, ErrorLevel::Usage); 40constexpr ResultCode ERROR_INVALID_OPEN_FLAGS(ResultCode(-1));
41constexpr ResultCode ERROR_INVALID_OPEN_FLAGS(ErrCodes::InvalidOpenFlags, ErrorModule::FS, 41constexpr ResultCode ERROR_FILE_NOT_FOUND(ResultCode(-1));
42 ErrorSummary::Canceled, ErrorLevel::Status); 42constexpr ResultCode ERROR_PATH_NOT_FOUND(ResultCode(-1));
43constexpr ResultCode ERROR_INVALID_READ_FLAG(ErrCodes::InvalidReadFlag, ErrorModule::FS, 43constexpr ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY(ResultCode(-1));
44 ErrorSummary::InvalidArgument, ErrorLevel::Usage); 44constexpr ResultCode ERROR_DIRECTORY_ALREADY_EXISTS(ResultCode(-1));
45constexpr ResultCode ERROR_FILE_NOT_FOUND(ErrCodes::FileNotFound, ErrorModule::FS, 45constexpr ResultCode ERROR_FILE_ALREADY_EXISTS(ResultCode(-1));
46 ErrorSummary::NotFound, ErrorLevel::Status); 46constexpr ResultCode ERROR_DIRECTORY_NOT_EMPTY(ResultCode(-1));
47constexpr ResultCode ERROR_PATH_NOT_FOUND(ErrCodes::PathNotFound, ErrorModule::FS,
48 ErrorSummary::NotFound, ErrorLevel::Status);
49constexpr ResultCode ERROR_NOT_FOUND(ErrCodes::NotFound, ErrorModule::FS, ErrorSummary::NotFound,
50 ErrorLevel::Status);
51constexpr ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY(ErrCodes::UnexpectedFileOrDirectory,
52 ErrorModule::FS, ErrorSummary::NotSupported,
53 ErrorLevel::Usage);
54constexpr ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC(ErrCodes::NotAFile, ErrorModule::FS,
55 ErrorSummary::Canceled,
56 ErrorLevel::Status);
57constexpr ResultCode ERROR_DIRECTORY_ALREADY_EXISTS(ErrCodes::DirectoryAlreadyExists,
58 ErrorModule::FS, ErrorSummary::NothingHappened,
59 ErrorLevel::Status);
60constexpr ResultCode ERROR_FILE_ALREADY_EXISTS(ErrCodes::FileAlreadyExists, ErrorModule::FS,
61 ErrorSummary::NothingHappened, ErrorLevel::Status);
62constexpr ResultCode ERROR_ALREADY_EXISTS(ErrCodes::AlreadyExists, ErrorModule::FS,
63 ErrorSummary::NothingHappened, ErrorLevel::Status);
64constexpr ResultCode ERROR_DIRECTORY_NOT_EMPTY(ErrCodes::DirectoryNotEmpty, ErrorModule::FS,
65 ErrorSummary::Canceled, ErrorLevel::Status);
66constexpr ResultCode ERROR_GAMECARD_NOT_INSERTED(ErrCodes::GameCardNotInserted, ErrorModule::FS,
67 ErrorSummary::NotFound, ErrorLevel::Status);
68constexpr ResultCode ERROR_INCORRECT_EXEFS_READ_SIZE(ErrCodes::IncorrectExeFSReadSize,
69 ErrorModule::FS, ErrorSummary::NotSupported,
70 ErrorLevel::Usage);
71constexpr ResultCode ERROR_ROMFS_NOT_FOUND(ErrCodes::RomFSNotFound, ErrorModule::FS,
72 ErrorSummary::NotFound, ErrorLevel::Status);
73constexpr ResultCode ERROR_COMMAND_NOT_ALLOWED(ErrCodes::CommandNotAllowed, ErrorModule::FS,
74 ErrorSummary::WrongArgument, ErrorLevel::Permanent);
75constexpr 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.
79constexpr ResultCode ERR_INVALID_ARCHIVE_HANDLE(ErrCodes::ArchiveNotMounted, ErrorModule::FS,
80 ErrorSummary::NotFound,
81 ErrorLevel::Status); // 0xC8804465
82constexpr 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 */
89constexpr ResultCode ERR_NOT_FOUND_INVALID_STATE(ErrCodes::NotFound, ErrorModule::FS,
90 ErrorSummary::InvalidState, ErrorLevel::Status);
91constexpr ResultCode ERR_NOT_FORMATTED(ErrCodes::NotFormatted, ErrorModule::FS,
92 ErrorSummary::InvalidState, ErrorLevel::Status);
93 47
94} // namespace FileSys 48} // namespace FileSys
diff --git a/src/core/file_sys/ivfc_archive.cpp b/src/core/file_sys/ivfc_archive.cpp
index 2735d2e3c..b3c3f2c6f 100644
--- a/src/core/file_sys/ivfc_archive.cpp
+++ b/src/core/file_sys/ivfc_archive.cpp
@@ -26,9 +26,8 @@ ResultVal<std::unique_ptr<FileBackend>> IVFCArchive::OpenFile(const Path& path,
26ResultCode IVFCArchive::DeleteFile(const Path& path) const { 26ResultCode IVFCArchive::DeleteFile(const Path& path) const {
27 LOG_CRITICAL(Service_FS, "Attempted to delete a file from an IVFC archive (%s).", 27 LOG_CRITICAL(Service_FS, "Attempted to delete a file from an IVFC archive (%s).",
28 GetName().c_str()); 28 GetName().c_str());
29 // TODO(Subv): Verify error code 29 // TODO(bunnei): Use correct error code
30 return ResultCode(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled, 30 return ResultCode(-1);
31 ErrorLevel::Status);
32} 31}
33 32
34ResultCode IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const { 33ResultCode IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
@@ -55,9 +54,8 @@ ResultCode IVFCArchive::DeleteDirectoryRecursively(const Path& path) const {
55ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const { 54ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const {
56 LOG_CRITICAL(Service_FS, "Attempted to create a file in an IVFC archive (%s).", 55 LOG_CRITICAL(Service_FS, "Attempted to create a file in an IVFC archive (%s).",
57 GetName().c_str()); 56 GetName().c_str());
58 // TODO: Verify error code 57 // TODO(bunnei): Use correct error code
59 return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, 58 return ResultCode(-1);
60 ErrorLevel::Permanent);
61} 59}
62 60
63ResultCode IVFCArchive::CreateDirectory(const Path& path) const { 61ResultCode IVFCArchive::CreateDirectory(const Path& path) const {
diff --git a/src/core/file_sys/savedata_archive.cpp b/src/core/file_sys/savedata_archive.cpp
index f8f811ba0..d7b012f6e 100644
--- a/src/core/file_sys/savedata_archive.cpp
+++ b/src/core/file_sys/savedata_archive.cpp
@@ -128,10 +128,8 @@ ResultCode SaveDataArchive::RenameFile(const Path& src_path, const Path& dest_pa
128 return RESULT_SUCCESS; 128 return RESULT_SUCCESS;
129 } 129 }
130 130
131 // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't 131 // TODO(bunnei): Use correct error code
132 // exist or similar. Verify. 132 return ResultCode(-1);
133 return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
134 ErrorSummary::NothingHappened, ErrorLevel::Status);
135} 133}
136 134
137template <typename T> 135template <typename T>
@@ -223,8 +221,9 @@ ResultCode SaveDataArchive::CreateFile(const FileSys::Path& path, u64 size) cons
223 } 221 }
224 222
225 LOG_ERROR(Service_FS, "Too large file"); 223 LOG_ERROR(Service_FS, "Too large file");
226 return ResultCode(ErrorDescription::TooLarge, ErrorModule::FS, ErrorSummary::OutOfResource, 224
227 ErrorLevel::Info); 225 // TODO(bunnei): Use correct error code
226 return ResultCode(-1);
228} 227}
229 228
230ResultCode SaveDataArchive::CreateDirectory(const Path& path) const { 229ResultCode SaveDataArchive::CreateDirectory(const Path& path) const {
@@ -260,8 +259,9 @@ ResultCode SaveDataArchive::CreateDirectory(const Path& path) const {
260 } 259 }
261 260
262 LOG_CRITICAL(Service_FS, "(unreachable) Unknown error creating %s", mount_point.c_str()); 261 LOG_CRITICAL(Service_FS, "(unreachable) Unknown error creating %s", mount_point.c_str());
263 return ResultCode(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled, 262
264 ErrorLevel::Status); 263 // TODO(bunnei): Use correct error code
264 return ResultCode(-1);
265} 265}
266 266
267ResultCode SaveDataArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { 267ResultCode SaveDataArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
@@ -287,10 +287,8 @@ ResultCode SaveDataArchive::RenameDirectory(const Path& src_path, const Path& de
287 return RESULT_SUCCESS; 287 return RESULT_SUCCESS;
288 } 288 }
289 289
290 // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't 290 // TODO(bunnei): Use correct error code
291 // exist or similar. Verify. 291 return ResultCode(-1);
292 return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
293 ErrorSummary::NothingHappened, ErrorLevel::Status);
294} 292}
295 293
296ResultVal<std::unique_ptr<DirectoryBackend>> SaveDataArchive::OpenDirectory( 294ResultVal<std::unique_ptr<DirectoryBackend>> SaveDataArchive::OpenDirectory(
diff --git a/src/core/hle/ipc.h b/src/core/hle/ipc.h
index 16f51a635..4dc8937c3 100644
--- a/src/core/hle/ipc.h
+++ b/src/core/hle/ipc.h
@@ -17,7 +17,6 @@ constexpr size_t COMMAND_BUFFER_LENGTH = 0x100 / sizeof(u32);
17// These errors are commonly returned by invalid IPC translations, so alias them here for 17// These errors are commonly returned by invalid IPC translations, so alias them here for
18// convenience. 18// convenience.
19// TODO(yuriks): These will probably go away once translation is implemented inside the kernel. 19// TODO(yuriks): These will probably go away once translation is implemented inside the kernel.
20using Kernel::ERR_INVALID_BUFFER_DESCRIPTOR;
21constexpr auto ERR_INVALID_HANDLE = Kernel::ERR_INVALID_HANDLE_OS; 20constexpr auto ERR_INVALID_HANDLE = Kernel::ERR_INVALID_HANDLE_OS;
22 21
23 22
diff --git a/src/core/hle/kernel/errors.h b/src/core/hle/kernel/errors.h
index 64aa61460..f8890f0e3 100644
--- a/src/core/hle/kernel/errors.h
+++ b/src/core/hle/kernel/errors.h
@@ -23,81 +23,27 @@ enum {
23// WARNING: The kernel is quite inconsistent in it's usage of errors code. Make sure to always 23// WARNING: The kernel is quite inconsistent in it's usage of errors code. Make sure to always
24// double check that the code matches before re-using the constant. 24// double check that the code matches before re-using the constant.
25 25
26constexpr ResultCode ERR_OUT_OF_HANDLES(ErrCodes::OutOfHandles, ErrorModule::Kernel, 26// TODO(bunnei): Replace these with correct errors for Switch OS
27 ErrorSummary::OutOfResource, 27constexpr ResultCode ERR_OUT_OF_HANDLES(-1);
28 ErrorLevel::Permanent); // 0xD8600413 28constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE(-1);
29constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE(ErrCodes::SessionClosedByRemote, ErrorModule::OS, 29constexpr ResultCode ERR_PORT_NAME_TOO_LONG(-1);
30 ErrorSummary::Canceled, 30constexpr ResultCode ERR_WRONG_PERMISSION(-1);
31 ErrorLevel::Status); // 0xC920181A 31constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(-1);
32constexpr ResultCode ERR_PORT_NAME_TOO_LONG(ErrCodes::PortNameTooLong, ErrorModule::OS, 32constexpr ResultCode ERR_INVALID_ENUM_VALUE(-1);
33 ErrorSummary::InvalidArgument, 33constexpr ResultCode ERR_INVALID_ENUM_VALUE_FND(-1);
34 ErrorLevel::Usage); // 0xE0E0181E 34constexpr ResultCode ERR_INVALID_COMBINATION(-1);
35constexpr ResultCode ERR_WRONG_PERMISSION(ErrCodes::WrongPermission, ErrorModule::OS, 35constexpr ResultCode ERR_INVALID_COMBINATION_KERNEL(-1);
36 ErrorSummary::WrongArgument, ErrorLevel::Permanent); 36constexpr ResultCode ERR_OUT_OF_MEMORY(-1);
37constexpr ResultCode ERR_INVALID_BUFFER_DESCRIPTOR(ErrCodes::InvalidBufferDescriptor, 37constexpr ResultCode ERR_INVALID_ADDRESS(-1);
38 ErrorModule::OS, ErrorSummary::WrongArgument, 38constexpr ResultCode ERR_INVALID_ADDRESS_STATE(-1);
39 ErrorLevel::Permanent); 39constexpr ResultCode ERR_INVALID_HANDLE(-1);
40constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(ErrCodes::MaxConnectionsReached, ErrorModule::OS,
41 ErrorSummary::WouldBlock,
42 ErrorLevel::Temporary); // 0xD0401834
43
44constexpr ResultCode ERR_NOT_AUTHORIZED(ErrorDescription::NotAuthorized, ErrorModule::OS,
45 ErrorSummary::WrongArgument,
46 ErrorLevel::Permanent); // 0xD9001BEA
47constexpr ResultCode ERR_INVALID_ENUM_VALUE(ErrorDescription::InvalidEnumValue, ErrorModule::Kernel,
48 ErrorSummary::InvalidArgument,
49 ErrorLevel::Permanent); // 0xD8E007ED
50constexpr ResultCode ERR_INVALID_ENUM_VALUE_FND(ErrorDescription::InvalidEnumValue,
51 ErrorModule::FND, ErrorSummary::InvalidArgument,
52 ErrorLevel::Permanent); // 0xD8E093ED
53constexpr ResultCode ERR_INVALID_COMBINATION(ErrorDescription::InvalidCombination, ErrorModule::OS,
54 ErrorSummary::InvalidArgument,
55 ErrorLevel::Usage); // 0xE0E01BEE
56constexpr ResultCode ERR_INVALID_COMBINATION_KERNEL(ErrorDescription::InvalidCombination,
57 ErrorModule::Kernel,
58 ErrorSummary::WrongArgument,
59 ErrorLevel::Permanent); // 0xD90007EE
60constexpr ResultCode ERR_MISALIGNED_ADDRESS(ErrorDescription::MisalignedAddress, ErrorModule::OS,
61 ErrorSummary::InvalidArgument,
62 ErrorLevel::Usage); // 0xE0E01BF1
63constexpr ResultCode ERR_MISALIGNED_SIZE(ErrorDescription::MisalignedSize, ErrorModule::OS,
64 ErrorSummary::InvalidArgument,
65 ErrorLevel::Usage); // 0xE0E01BF2
66constexpr ResultCode ERR_OUT_OF_MEMORY(ErrorDescription::OutOfMemory, ErrorModule::Kernel,
67 ErrorSummary::OutOfResource,
68 ErrorLevel::Permanent); // 0xD86007F3
69constexpr ResultCode ERR_NOT_IMPLEMENTED(ErrorDescription::NotImplemented, ErrorModule::OS,
70 ErrorSummary::InvalidArgument,
71 ErrorLevel::Usage); // 0xE0E01BF4
72constexpr ResultCode ERR_INVALID_ADDRESS(ErrorDescription::InvalidAddress, ErrorModule::OS,
73 ErrorSummary::InvalidArgument,
74 ErrorLevel::Usage); // 0xE0E01BF5
75constexpr ResultCode ERR_INVALID_ADDRESS_STATE(ErrorDescription::InvalidAddress, ErrorModule::OS,
76 ErrorSummary::InvalidState,
77 ErrorLevel::Usage); // 0xE0A01BF5
78constexpr ResultCode ERR_INVALID_POINTER(ErrorDescription::InvalidPointer, ErrorModule::Kernel,
79 ErrorSummary::InvalidArgument,
80 ErrorLevel::Permanent); // 0xD8E007F6
81constexpr ResultCode ERR_INVALID_HANDLE(ErrorDescription::InvalidHandle, ErrorModule::Kernel,
82 ErrorSummary::InvalidArgument,
83 ErrorLevel::Permanent); // 0xD8E007F7
84/// Alternate code returned instead of ERR_INVALID_HANDLE in some code paths. 40/// Alternate code returned instead of ERR_INVALID_HANDLE in some code paths.
85constexpr ResultCode ERR_INVALID_HANDLE_OS(ErrorDescription::InvalidHandle, ErrorModule::OS, 41constexpr ResultCode ERR_INVALID_HANDLE_OS(-1);
86 ErrorSummary::WrongArgument, 42constexpr ResultCode ERR_NOT_FOUND(-1);
87 ErrorLevel::Permanent); // 0xD9001BF7 43constexpr ResultCode ERR_OUT_OF_RANGE(-1);
88constexpr ResultCode ERR_NOT_FOUND(ErrorDescription::NotFound, ErrorModule::Kernel, 44constexpr ResultCode ERR_OUT_OF_RANGE_KERNEL(-1);
89 ErrorSummary::NotFound, ErrorLevel::Permanent); // 0xD88007FA 45constexpr ResultCode RESULT_TIMEOUT(-1);
90constexpr ResultCode ERR_OUT_OF_RANGE(ErrorDescription::OutOfRange, ErrorModule::OS,
91 ErrorSummary::InvalidArgument,
92 ErrorLevel::Usage); // 0xE0E01BFD
93constexpr ResultCode ERR_OUT_OF_RANGE_KERNEL(ErrorDescription::OutOfRange, ErrorModule::Kernel,
94 ErrorSummary::InvalidArgument,
95 ErrorLevel::Permanent); // 0xD8E007FD
96constexpr ResultCode RESULT_TIMEOUT(ErrorDescription::Timeout, ErrorModule::OS,
97 ErrorSummary::StatusChanged, ErrorLevel::Info);
98/// Returned when Accept() is called on a port with no sessions to be accepted. 46/// Returned when Accept() is called on a port with no sessions to be accepted.
99constexpr ResultCode ERR_NO_PENDING_SESSIONS(ErrCodes::NoPendingSessions, ErrorModule::OS, 47constexpr ResultCode ERR_NO_PENDING_SESSIONS(-1);
100 ErrorSummary::WouldBlock,
101 ErrorLevel::Permanent); // 0xD8401823
102 48
103} // namespace Kernel 49} // namespace Kernel
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 8b72084bf..372cafdd9 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -386,9 +386,8 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
386 386
387 if (!Memory::IsValidVirtualAddress(*owner_process, entry_point)) { 387 if (!Memory::IsValidVirtualAddress(*owner_process, entry_point)) {
388 LOG_ERROR(Kernel_SVC, "(name=%s): invalid entry %08x", name.c_str(), entry_point); 388 LOG_ERROR(Kernel_SVC, "(name=%s): invalid entry %08x", name.c_str(), entry_point);
389 // TODO: Verify error 389 // TODO (bunnei): Find the correct error code to use here
390 return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel, 390 return ResultCode(-1);
391 ErrorSummary::InvalidArgument, ErrorLevel::Permanent);
392 } 391 }
393 392
394 SharedPtr<Thread> thread(new Thread); 393 SharedPtr<Thread> thread(new Thread);
diff --git a/src/core/hle/result.h b/src/core/hle/result.h
index 47b6e2b23..10ddc4feb 100644
--- a/src/core/hle/result.h
+++ b/src/core/hle/result.h
@@ -11,41 +11,14 @@
11#include "common/common_funcs.h" 11#include "common/common_funcs.h"
12#include "common/common_types.h" 12#include "common/common_types.h"
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://switchbrew.org/index.php?title=Error_codes
15 15
16/** 16/**
17 * Detailed description of the error. Code 0 always means success. Codes 1000 and above are 17 * Detailed description of the error. Code 0 always means success.
18 * considered "well-known" and have common values between all modules. The meaning of other codes
19 * vary by module.
20 */ 18 */
21enum class ErrorDescription : u32 { 19enum class ErrorDescription : u32 {
22 Success = 0, 20 Success = 0,
23 21 RemoteProcessDead = 301,
24 // Codes 1000 and above are considered "well-known" and have common values between all modules.
25 InvalidSection = 1000,
26 TooLarge = 1001,
27 NotAuthorized = 1002,
28 AlreadyDone = 1003,
29 InvalidSize = 1004,
30 InvalidEnumValue = 1005,
31 InvalidCombination = 1006,
32 NoData = 1007,
33 Busy = 1008,
34 MisalignedAddress = 1009,
35 MisalignedSize = 1010,
36 OutOfMemory = 1011,
37 NotImplemented = 1012,
38 InvalidAddress = 1013,
39 InvalidPointer = 1014,
40 InvalidHandle = 1015,
41 NotInitialized = 1016,
42 AlreadyInitialized = 1017,
43 NotFound = 1018,
44 CancelRequested = 1019,
45 AlreadyExists = 1020,
46 OutOfRange = 1021,
47 Timeout = 1022,
48 InvalidResultValue = 1023,
49}; 22};
50 23
51/** 24/**
@@ -56,150 +29,64 @@ enum class ErrorDescription : u32 {
56enum class ErrorModule : u32 { 29enum class ErrorModule : u32 {
57 Common = 0, 30 Common = 0,
58 Kernel = 1, 31 Kernel = 1,
59 Util = 2, 32 FS = 2,
60 FileServer = 3, 33 NvidiaTransferMemory = 3,
61 LoaderServer = 4, 34 NCM = 5,
62 TCB = 5, 35 DD = 6,
63 OS = 6, 36 LR = 8,
64 DBG = 7, 37 Loader = 9,
65 DMNT = 8, 38 CMIF = 10,
66 PDN = 9, 39 HIPC = 11,
67 GX = 10, 40 PM = 15,
68 I2C = 11, 41 NS = 16,
69 GPIO = 12, 42 HTC = 18,
70 DD = 13, 43 SM = 21,
71 CODEC = 14, 44 RO = 22,
72 SPI = 15, 45 SDMMC = 24,
73 PXI = 16, 46 SPL = 26,
74 FS = 17, 47 ETHC = 100,
75 DI = 18, 48 I2C = 101,
76 HID = 19, 49 Settings = 105,
77 CAM = 20, 50 NIFM = 110,
78 PI = 21, 51 Display = 114,
79 PM = 22, 52 NTC = 116,
80 PM_LOW = 23, 53 FGM = 117,
81 FSI = 24, 54 PCIE = 120,
82 SRV = 25, 55 Friends = 121,
83 NDM = 26, 56 SSL = 123,
84 NWM = 27, 57 Account = 124,
85 SOC = 28, 58 Mii = 126,
86 LDR = 29, 59 AM = 128,
87 ACC = 30, 60 PlayReport = 129,
88 RomFS = 31, 61 PCV = 133,
89 AM = 32, 62 OMM = 134,
90 HIO = 33, 63 NIM = 137,
91 Updater = 34, 64 PSC = 138,
92 MIC = 35, 65 USB = 140,
93 FND = 36, 66 BTM = 143,
94 MP = 37, 67 ERPT = 147,
95 MPWL = 38, 68 APM = 148,
96 AC = 39, 69 NPNS = 154,
97 HTTP = 40, 70 ARP = 157,
98 DSP = 41, 71 BOOT = 158,
99 SND = 42, 72 NFC = 161,
100 DLP = 43, 73 UserlandAssert = 162,
101 HIO_LOW = 44, 74 UserlandCrash = 168,
102 CSND = 45, 75 HID = 203,
103 SSL = 46, 76 Capture = 206,
104 AM_LOW = 47, 77 TC = 651,
105 NEX = 48, 78 GeneralWebApplet = 800,
106 Friends = 49, 79 WifiWebAuthApplet = 809,
107 RDT = 50, 80 WhitelistedApplet = 810,
108 Applet = 51, 81 ShopN = 811,
109 NIM = 52,
110 PTM = 53,
111 MIDI = 54,
112 MC = 55,
113 SWC = 56,
114 FatFS = 57,
115 NGC = 58,
116 CARD = 59,
117 CARDNOR = 60,
118 SDMC = 61,
119 BOSS = 62,
120 DBM = 63,
121 Config = 64,
122 PS = 65,
123 CEC = 66,
124 IR = 67,
125 UDS = 68,
126 PL = 69,
127 CUP = 70,
128 Gyroscope = 71,
129 MCU = 72,
130 NS = 73,
131 News = 74,
132 RO = 75,
133 GD = 76,
134 CardSPI = 77,
135 EC = 78,
136 WebBrowser = 79,
137 Test = 80,
138 ENC = 81,
139 PIA = 82,
140 ACT = 83,
141 VCTL = 84,
142 OLV = 85,
143 NEIA = 86,
144 NPNS = 87,
145
146 AVD = 90,
147 L2B = 91,
148 MVD = 92,
149 NFC = 93,
150 UART = 94,
151 SPM = 95,
152 QTM = 96,
153 NFP = 97,
154
155 Application = 254,
156 InvalidResult = 255
157};
158
159/// A less specific error cause.
160enum class ErrorSummary : u32 {
161 Success = 0,
162 NothingHappened = 1,
163 WouldBlock = 2,
164 OutOfResource = 3, ///< There are no more kernel resources (memory, table slots) to
165 ///< execute the operation.
166 NotFound = 4, ///< A file or resource was not found.
167 InvalidState = 5,
168 NotSupported = 6, ///< The operation is not supported or not implemented.
169 InvalidArgument = 7, ///< Returned when a passed argument is invalid in the current runtime
170 ///< context. (Invalid handle, out-of-bounds pointer or size, etc.)
171 WrongArgument = 8, ///< Returned when a passed argument is in an incorrect format for use
172 ///< with the function. (E.g. Invalid enum value)
173 Canceled = 9,
174 StatusChanged = 10,
175 Internal = 11,
176
177 InvalidResult = 63
178};
179
180/// The severity of the error.
181enum class ErrorLevel : u32 {
182 Success = 0,
183 Info = 1,
184
185 Status = 25,
186 Temporary = 26,
187 Permanent = 27,
188 Usage = 28,
189 Reinitialize = 29,
190 Reset = 30,
191 Fatal = 31
192}; 82};
193 83
194/// Encapsulates a CTR-OS error code, allowing it to be separated into its constituent fields. 84/// Encapsulates a CTR-OS error code, allowing it to be separated into its constituent fields.
195union ResultCode { 85union ResultCode {
196 u32 raw; 86 u32 raw;
197 87
198 BitField<0, 10, u32> description; 88 BitField<0, 9, ErrorModule> module;
199 BitField<10, 8, ErrorModule> module; 89 BitField<9, 13, u32> description;
200
201 BitField<21, 6, ErrorSummary> summary;
202 BitField<27, 5, ErrorLevel> level;
203 90
204 // The last bit of `level` is checked by apps and the kernel to determine if a result code is an 91 // The last bit of `level` is checked by apps and the kernel to determine if a result code is an
205 // error 92 // error
@@ -207,14 +94,11 @@ union ResultCode {
207 94
208 constexpr explicit ResultCode(u32 raw) : raw(raw) {} 95 constexpr explicit ResultCode(u32 raw) : raw(raw) {}
209 96
210 constexpr ResultCode(ErrorDescription description, ErrorModule module, ErrorSummary summary, 97 constexpr ResultCode(ErrorModule module, ErrorDescription description)
211 ErrorLevel level) 98 : ResultCode(module, static_cast<u32>(description)) {}
212 : ResultCode(static_cast<u32>(description), module, summary, level) {}
213 99
214 constexpr ResultCode(u32 description_, ErrorModule module_, ErrorSummary summary_, 100 constexpr ResultCode(ErrorModule module_, u32 description_)
215 ErrorLevel level_) 101 : raw(module.FormatValue(module_) | description.FormatValue(description_)) {}
216 : raw(description.FormatValue(description_) | module.FormatValue(module_) |
217 summary.FormatValue(summary_) | level.FormatValue(level_)) {}
218 102
219 constexpr ResultCode& operator=(const ResultCode& o) { 103 constexpr ResultCode& operator=(const ResultCode& o) {
220 raw = o.raw; 104 raw = o.raw;
@@ -243,12 +127,6 @@ constexpr bool operator!=(const ResultCode& a, const ResultCode& b) {
243/// The default success `ResultCode`. 127/// The default success `ResultCode`.
244constexpr ResultCode RESULT_SUCCESS(0); 128constexpr ResultCode RESULT_SUCCESS(0);
245 129
246/// Might be returned instead of a dummy success for unimplemented APIs.
247constexpr ResultCode UnimplementedFunction(ErrorModule module) {
248 return ResultCode(ErrorDescription::NotImplemented, module, ErrorSummary::NotSupported,
249 ErrorLevel::Permanent);
250}
251
252/** 130/**
253 * This is an optional value type. It holds a `ResultCode` and, if that code is a success code, 131 * This is an optional value type. It holds a `ResultCode` and, if that code is a success code,
254 * also holds a result of type `T`. If the code is an error code then trying to access the inner 132 * also holds a result of type `T`. If the code is an error code then trying to access the inner
diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h
index eaae68ca1..eb463a656 100644
--- a/src/core/hle/service/sm/sm.h
+++ b/src/core/hle/service/sm/sm.h
@@ -35,19 +35,11 @@ private:
35 35
36class Controller; 36class Controller;
37 37
38constexpr ResultCode ERR_SERVICE_NOT_REGISTERED(1, ErrorModule::SRV, ErrorSummary::WouldBlock, 38constexpr ResultCode ERR_SERVICE_NOT_REGISTERED(-1);
39 ErrorLevel::Temporary); // 0xD0406401 39constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(-1);
40constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(2, ErrorModule::SRV, ErrorSummary::WouldBlock, 40constexpr ResultCode ERR_INVALID_NAME_SIZE(-1);
41 ErrorLevel::Temporary); // 0xD0406402 41constexpr ResultCode ERR_NAME_CONTAINS_NUL(-1);
42constexpr ResultCode ERR_INVALID_NAME_SIZE(5, ErrorModule::SRV, ErrorSummary::WrongArgument, 42constexpr ResultCode ERR_ALREADY_REGISTERED(-1);
43 ErrorLevel::Permanent); // 0xD9006405
44constexpr ResultCode ERR_ACCESS_DENIED(6, ErrorModule::SRV, ErrorSummary::InvalidArgument,
45 ErrorLevel::Permanent); // 0xD8E06406
46constexpr ResultCode ERR_NAME_CONTAINS_NUL(7, ErrorModule::SRV, ErrorSummary::WrongArgument,
47 ErrorLevel::Permanent); // 0xD9006407
48constexpr ResultCode ERR_ALREADY_REGISTERED(ErrorDescription::AlreadyExists, ErrorModule::OS,
49 ErrorSummary::WrongArgument,
50 ErrorLevel::Permanent); // 0xD9001BFC
51 43
52class ServiceManager { 44class ServiceManager {
53public: 45public: