diff options
| author | bunnei <bunneidev@gmail.com> | 2017-10-31 19:26:11 -0400 | 
|---|---|---|
| committer | bunnei <bunneidev@gmail.com> | 2017-10-31 19:26:11 -0400 | 
| commit | 34571f4d2e80a3194a3c4cb697dba674d11a35b4 (patch) | |
| tree | b2b4b70d7a5bdea95ef5d44733eedf7e6b3b7009 /src/core/hle | |
| parent | 3e802026043c0d06f147bc09429a1339b862f5b4 (diff) | |
hle: Use Switch formatted result codes.
Diffstat (limited to 'src/core/hle')
| -rw-r--r-- | src/core/hle/ipc.h | 1 | ||||
| -rw-r--r-- | src/core/hle/kernel/errors.h | 94 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 5 | ||||
| -rw-r--r-- | src/core/hle/result.h | 240 | ||||
| -rw-r--r-- | src/core/hle/service/sm/sm.h | 18 | 
5 files changed, 86 insertions, 272 deletions
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);  // These errors are commonly returned by invalid IPC translations, so alias them here for  // convenience.  // TODO(yuriks): These will probably go away once translation is implemented inside the kernel. -using Kernel::ERR_INVALID_BUFFER_DESCRIPTOR;  constexpr auto ERR_INVALID_HANDLE = Kernel::ERR_INVALID_HANDLE_OS; 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 {  // WARNING: The kernel is quite inconsistent in it's usage of errors code. Make sure to always  // double check that the code matches before re-using the constant. -constexpr ResultCode ERR_OUT_OF_HANDLES(ErrCodes::OutOfHandles, ErrorModule::Kernel, -                                        ErrorSummary::OutOfResource, -                                        ErrorLevel::Permanent); // 0xD8600413 -constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE(ErrCodes::SessionClosedByRemote, ErrorModule::OS, -                                                  ErrorSummary::Canceled, -                                                  ErrorLevel::Status); // 0xC920181A -constexpr ResultCode ERR_PORT_NAME_TOO_LONG(ErrCodes::PortNameTooLong, ErrorModule::OS, -                                            ErrorSummary::InvalidArgument, -                                            ErrorLevel::Usage); // 0xE0E0181E -constexpr ResultCode ERR_WRONG_PERMISSION(ErrCodes::WrongPermission, ErrorModule::OS, -                                          ErrorSummary::WrongArgument, ErrorLevel::Permanent); -constexpr ResultCode ERR_INVALID_BUFFER_DESCRIPTOR(ErrCodes::InvalidBufferDescriptor, -                                                   ErrorModule::OS, ErrorSummary::WrongArgument, -                                                   ErrorLevel::Permanent); -constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(ErrCodes::MaxConnectionsReached, ErrorModule::OS, -                                                 ErrorSummary::WouldBlock, -                                                 ErrorLevel::Temporary); // 0xD0401834 - -constexpr ResultCode ERR_NOT_AUTHORIZED(ErrorDescription::NotAuthorized, ErrorModule::OS, -                                        ErrorSummary::WrongArgument, -                                        ErrorLevel::Permanent); // 0xD9001BEA -constexpr ResultCode ERR_INVALID_ENUM_VALUE(ErrorDescription::InvalidEnumValue, ErrorModule::Kernel, -                                            ErrorSummary::InvalidArgument, -                                            ErrorLevel::Permanent); // 0xD8E007ED -constexpr ResultCode ERR_INVALID_ENUM_VALUE_FND(ErrorDescription::InvalidEnumValue, -                                                ErrorModule::FND, ErrorSummary::InvalidArgument, -                                                ErrorLevel::Permanent); // 0xD8E093ED -constexpr ResultCode ERR_INVALID_COMBINATION(ErrorDescription::InvalidCombination, ErrorModule::OS, -                                             ErrorSummary::InvalidArgument, -                                             ErrorLevel::Usage); // 0xE0E01BEE -constexpr ResultCode ERR_INVALID_COMBINATION_KERNEL(ErrorDescription::InvalidCombination, -                                                    ErrorModule::Kernel, -                                                    ErrorSummary::WrongArgument, -                                                    ErrorLevel::Permanent); // 0xD90007EE -constexpr ResultCode ERR_MISALIGNED_ADDRESS(ErrorDescription::MisalignedAddress, ErrorModule::OS, -                                            ErrorSummary::InvalidArgument, -                                            ErrorLevel::Usage); // 0xE0E01BF1 -constexpr ResultCode ERR_MISALIGNED_SIZE(ErrorDescription::MisalignedSize, ErrorModule::OS, -                                         ErrorSummary::InvalidArgument, -                                         ErrorLevel::Usage); // 0xE0E01BF2 -constexpr ResultCode ERR_OUT_OF_MEMORY(ErrorDescription::OutOfMemory, ErrorModule::Kernel, -                                       ErrorSummary::OutOfResource, -                                       ErrorLevel::Permanent); // 0xD86007F3 -constexpr ResultCode ERR_NOT_IMPLEMENTED(ErrorDescription::NotImplemented, ErrorModule::OS, -                                         ErrorSummary::InvalidArgument, -                                         ErrorLevel::Usage); // 0xE0E01BF4 -constexpr ResultCode ERR_INVALID_ADDRESS(ErrorDescription::InvalidAddress, ErrorModule::OS, -                                         ErrorSummary::InvalidArgument, -                                         ErrorLevel::Usage); // 0xE0E01BF5 -constexpr ResultCode ERR_INVALID_ADDRESS_STATE(ErrorDescription::InvalidAddress, ErrorModule::OS, -                                               ErrorSummary::InvalidState, -                                               ErrorLevel::Usage); // 0xE0A01BF5 -constexpr ResultCode ERR_INVALID_POINTER(ErrorDescription::InvalidPointer, ErrorModule::Kernel, -                                         ErrorSummary::InvalidArgument, -                                         ErrorLevel::Permanent); // 0xD8E007F6 -constexpr ResultCode ERR_INVALID_HANDLE(ErrorDescription::InvalidHandle, ErrorModule::Kernel, -                                        ErrorSummary::InvalidArgument, -                                        ErrorLevel::Permanent); // 0xD8E007F7 +// TODO(bunnei): Replace these with correct errors for Switch OS +constexpr ResultCode ERR_OUT_OF_HANDLES(-1); +constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE(-1); +constexpr ResultCode ERR_PORT_NAME_TOO_LONG(-1); +constexpr ResultCode ERR_WRONG_PERMISSION(-1); +constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(-1); +constexpr ResultCode ERR_INVALID_ENUM_VALUE(-1); +constexpr ResultCode ERR_INVALID_ENUM_VALUE_FND(-1); +constexpr ResultCode ERR_INVALID_COMBINATION(-1); +constexpr ResultCode ERR_INVALID_COMBINATION_KERNEL(-1); +constexpr ResultCode ERR_OUT_OF_MEMORY(-1); +constexpr ResultCode ERR_INVALID_ADDRESS(-1); +constexpr ResultCode ERR_INVALID_ADDRESS_STATE(-1); +constexpr ResultCode ERR_INVALID_HANDLE(-1);  /// Alternate code returned instead of ERR_INVALID_HANDLE in some code paths. -constexpr ResultCode ERR_INVALID_HANDLE_OS(ErrorDescription::InvalidHandle, ErrorModule::OS, -                                           ErrorSummary::WrongArgument, -                                           ErrorLevel::Permanent); // 0xD9001BF7 -constexpr ResultCode ERR_NOT_FOUND(ErrorDescription::NotFound, ErrorModule::Kernel, -                                   ErrorSummary::NotFound, ErrorLevel::Permanent); // 0xD88007FA -constexpr ResultCode ERR_OUT_OF_RANGE(ErrorDescription::OutOfRange, ErrorModule::OS, -                                      ErrorSummary::InvalidArgument, -                                      ErrorLevel::Usage); // 0xE0E01BFD -constexpr ResultCode ERR_OUT_OF_RANGE_KERNEL(ErrorDescription::OutOfRange, ErrorModule::Kernel, -                                             ErrorSummary::InvalidArgument, -                                             ErrorLevel::Permanent); // 0xD8E007FD -constexpr ResultCode RESULT_TIMEOUT(ErrorDescription::Timeout, ErrorModule::OS, -                                    ErrorSummary::StatusChanged, ErrorLevel::Info); +constexpr ResultCode ERR_INVALID_HANDLE_OS(-1); +constexpr ResultCode ERR_NOT_FOUND(-1); +constexpr ResultCode ERR_OUT_OF_RANGE(-1); +constexpr ResultCode ERR_OUT_OF_RANGE_KERNEL(-1); +constexpr ResultCode RESULT_TIMEOUT(-1);  /// Returned when Accept() is called on a port with no sessions to be accepted. -constexpr ResultCode ERR_NO_PENDING_SESSIONS(ErrCodes::NoPendingSessions, ErrorModule::OS, -                                             ErrorSummary::WouldBlock, -                                             ErrorLevel::Permanent); // 0xD8401823 +constexpr ResultCode ERR_NO_PENDING_SESSIONS(-1);  } // 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,      if (!Memory::IsValidVirtualAddress(*owner_process, entry_point)) {          LOG_ERROR(Kernel_SVC, "(name=%s): invalid entry %08x", name.c_str(), entry_point); -        // TODO: Verify error -        return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::Kernel, -                          ErrorSummary::InvalidArgument, ErrorLevel::Permanent); +        // TODO (bunnei): Find the correct error code to use here +        return ResultCode(-1);      }      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 @@  #include "common/common_funcs.h"  #include "common/common_types.h" -// All the constants in this file come from http://3dbrew.org/wiki/Error_codes +// All the constants in this file come from http://switchbrew.org/index.php?title=Error_codes  /** - * Detailed description of the error. Code 0 always means success. Codes 1000 and above are - * considered "well-known" and have common values between all modules. The meaning of other codes - * vary by module. + * Detailed description of the error. Code 0 always means success.   */  enum class ErrorDescription : u32 {      Success = 0, - -    // Codes 1000 and above are considered "well-known" and have common values between all modules. -    InvalidSection = 1000, -    TooLarge = 1001, -    NotAuthorized = 1002, -    AlreadyDone = 1003, -    InvalidSize = 1004, -    InvalidEnumValue = 1005, -    InvalidCombination = 1006, -    NoData = 1007, -    Busy = 1008, -    MisalignedAddress = 1009, -    MisalignedSize = 1010, -    OutOfMemory = 1011, -    NotImplemented = 1012, -    InvalidAddress = 1013, -    InvalidPointer = 1014, -    InvalidHandle = 1015, -    NotInitialized = 1016, -    AlreadyInitialized = 1017, -    NotFound = 1018, -    CancelRequested = 1019, -    AlreadyExists = 1020, -    OutOfRange = 1021, -    Timeout = 1022, -    InvalidResultValue = 1023, +    RemoteProcessDead = 301,  };  /** @@ -56,150 +29,64 @@ enum class ErrorDescription : u32 {  enum class ErrorModule : u32 {      Common = 0,      Kernel = 1, -    Util = 2, -    FileServer = 3, -    LoaderServer = 4, -    TCB = 5, -    OS = 6, -    DBG = 7, -    DMNT = 8, -    PDN = 9, -    GX = 10, -    I2C = 11, -    GPIO = 12, -    DD = 13, -    CODEC = 14, -    SPI = 15, -    PXI = 16, -    FS = 17, -    DI = 18, -    HID = 19, -    CAM = 20, -    PI = 21, -    PM = 22, -    PM_LOW = 23, -    FSI = 24, -    SRV = 25, -    NDM = 26, -    NWM = 27, -    SOC = 28, -    LDR = 29, -    ACC = 30, -    RomFS = 31, -    AM = 32, -    HIO = 33, -    Updater = 34, -    MIC = 35, -    FND = 36, -    MP = 37, -    MPWL = 38, -    AC = 39, -    HTTP = 40, -    DSP = 41, -    SND = 42, -    DLP = 43, -    HIO_LOW = 44, -    CSND = 45, -    SSL = 46, -    AM_LOW = 47, -    NEX = 48, -    Friends = 49, -    RDT = 50, -    Applet = 51, -    NIM = 52, -    PTM = 53, -    MIDI = 54, -    MC = 55, -    SWC = 56, -    FatFS = 57, -    NGC = 58, -    CARD = 59, -    CARDNOR = 60, -    SDMC = 61, -    BOSS = 62, -    DBM = 63, -    Config = 64, -    PS = 65, -    CEC = 66, -    IR = 67, -    UDS = 68, -    PL = 69, -    CUP = 70, -    Gyroscope = 71, -    MCU = 72, -    NS = 73, -    News = 74, -    RO = 75, -    GD = 76, -    CardSPI = 77, -    EC = 78, -    WebBrowser = 79, -    Test = 80, -    ENC = 81, -    PIA = 82, -    ACT = 83, -    VCTL = 84, -    OLV = 85, -    NEIA = 86, -    NPNS = 87, - -    AVD = 90, -    L2B = 91, -    MVD = 92, -    NFC = 93, -    UART = 94, -    SPM = 95, -    QTM = 96, -    NFP = 97, - -    Application = 254, -    InvalidResult = 255 -}; - -/// A less specific error cause. -enum class ErrorSummary : u32 { -    Success = 0, -    NothingHappened = 1, -    WouldBlock = 2, -    OutOfResource = 3, ///< There are no more kernel resources (memory, table slots) to -                       ///< execute the operation. -    NotFound = 4,      ///< A file or resource was not found. -    InvalidState = 5, -    NotSupported = 6,    ///< The operation is not supported or not implemented. -    InvalidArgument = 7, ///< Returned when a passed argument is invalid in the current runtime -                         ///< context. (Invalid handle, out-of-bounds pointer or size, etc.) -    WrongArgument = 8,   ///< Returned when a passed argument is in an incorrect format for use -                         ///< with the function. (E.g. Invalid enum value) -    Canceled = 9, -    StatusChanged = 10, -    Internal = 11, - -    InvalidResult = 63 -}; - -/// The severity of the error. -enum class ErrorLevel : u32 { -    Success = 0, -    Info = 1, - -    Status = 25, -    Temporary = 26, -    Permanent = 27, -    Usage = 28, -    Reinitialize = 29, -    Reset = 30, -    Fatal = 31 +    FS = 2, +    NvidiaTransferMemory = 3, +    NCM = 5, +    DD = 6, +    LR = 8, +    Loader = 9, +    CMIF = 10, +    HIPC = 11, +    PM = 15, +    NS = 16, +    HTC = 18, +    SM = 21, +    RO = 22, +    SDMMC = 24, +    SPL = 26, +    ETHC = 100, +    I2C = 101, +    Settings = 105, +    NIFM = 110, +    Display = 114, +    NTC = 116, +    FGM = 117, +    PCIE = 120, +    Friends = 121, +    SSL = 123, +    Account = 124, +    Mii = 126, +    AM = 128, +    PlayReport = 129, +    PCV = 133, +    OMM = 134, +    NIM = 137, +    PSC = 138, +    USB = 140, +    BTM = 143, +    ERPT = 147, +    APM = 148, +    NPNS = 154, +    ARP = 157, +    BOOT = 158, +    NFC = 161, +    UserlandAssert = 162, +    UserlandCrash = 168, +    HID = 203, +    Capture = 206, +    TC = 651, +    GeneralWebApplet = 800, +    WifiWebAuthApplet = 809, +    WhitelistedApplet = 810, +    ShopN = 811,  };  /// Encapsulates a CTR-OS error code, allowing it to be separated into its constituent fields.  union ResultCode {      u32 raw; -    BitField<0, 10, u32> description; -    BitField<10, 8, ErrorModule> module; - -    BitField<21, 6, ErrorSummary> summary; -    BitField<27, 5, ErrorLevel> level; +    BitField<0, 9, ErrorModule> module; +    BitField<9, 13, u32> description;      // The last bit of `level` is checked by apps and the kernel to determine if a result code is an      // error @@ -207,14 +94,11 @@ union ResultCode {      constexpr explicit ResultCode(u32 raw) : raw(raw) {} -    constexpr ResultCode(ErrorDescription description, ErrorModule module, ErrorSummary summary, -                         ErrorLevel level) -        : ResultCode(static_cast<u32>(description), module, summary, level) {} +    constexpr ResultCode(ErrorModule module, ErrorDescription description) +        : ResultCode(module, static_cast<u32>(description)) {} -    constexpr ResultCode(u32 description_, ErrorModule module_, ErrorSummary summary_, -                         ErrorLevel level_) -        : raw(description.FormatValue(description_) | module.FormatValue(module_) | -              summary.FormatValue(summary_) | level.FormatValue(level_)) {} +    constexpr ResultCode(ErrorModule module_, u32 description_) +        : raw(module.FormatValue(module_) | description.FormatValue(description_)) {}      constexpr ResultCode& operator=(const ResultCode& o) {          raw = o.raw; @@ -243,12 +127,6 @@ constexpr bool operator!=(const ResultCode& a, const ResultCode& b) {  /// The default success `ResultCode`.  constexpr ResultCode RESULT_SUCCESS(0); -/// Might be returned instead of a dummy success for unimplemented APIs. -constexpr ResultCode UnimplementedFunction(ErrorModule module) { -    return ResultCode(ErrorDescription::NotImplemented, module, ErrorSummary::NotSupported, -                      ErrorLevel::Permanent); -} -  /**   * This is an optional value type. It holds a `ResultCode` and, if that code is a success code,   * also holds a result of type `T`. If the code is an error code then trying to access the inner 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:  class Controller; -constexpr ResultCode ERR_SERVICE_NOT_REGISTERED(1, ErrorModule::SRV, ErrorSummary::WouldBlock, -                                                ErrorLevel::Temporary); // 0xD0406401 -constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(2, ErrorModule::SRV, ErrorSummary::WouldBlock, -                                                 ErrorLevel::Temporary); // 0xD0406402 -constexpr ResultCode ERR_INVALID_NAME_SIZE(5, ErrorModule::SRV, ErrorSummary::WrongArgument, -                                           ErrorLevel::Permanent); // 0xD9006405 -constexpr ResultCode ERR_ACCESS_DENIED(6, ErrorModule::SRV, ErrorSummary::InvalidArgument, -                                       ErrorLevel::Permanent); // 0xD8E06406 -constexpr ResultCode ERR_NAME_CONTAINS_NUL(7, ErrorModule::SRV, ErrorSummary::WrongArgument, -                                           ErrorLevel::Permanent); // 0xD9006407 -constexpr ResultCode ERR_ALREADY_REGISTERED(ErrorDescription::AlreadyExists, ErrorModule::OS, -                                            ErrorSummary::WrongArgument, -                                            ErrorLevel::Permanent); // 0xD9001BFC +constexpr ResultCode ERR_SERVICE_NOT_REGISTERED(-1); +constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(-1); +constexpr ResultCode ERR_INVALID_NAME_SIZE(-1); +constexpr ResultCode ERR_NAME_CONTAINS_NUL(-1); +constexpr ResultCode ERR_ALREADY_REGISTERED(-1);  class ServiceManager {  public:  | 
