Merge pull request #2716 from yuriks/decentralized-result
Decentralize ResultCode
This commit is contained in:
commit
61decd84cc
33 changed files with 385 additions and 300 deletions
|
|
@ -108,7 +108,7 @@
|
|||
* symptoms.
|
||||
*/
|
||||
#pragma pack(1)
|
||||
template <std::size_t position, std::size_t bits, typename T>
|
||||
template <std::size_t Position, std::size_t Bits, typename T>
|
||||
struct BitField {
|
||||
private:
|
||||
// We hide the copy assigment operator here, because the default copy
|
||||
|
|
@ -117,7 +117,45 @@ private:
|
|||
// We don't delete it because we want BitField to be trivially copyable.
|
||||
BitField& operator=(const BitField&) = default;
|
||||
|
||||
// StorageType is T for non-enum types and the underlying type of T if
|
||||
// T is an enumeration. Note that T is wrapped within an enable_if in the
|
||||
// former case to workaround compile errors which arise when using
|
||||
// std::underlying_type<T>::type directly.
|
||||
using StorageType = typename std::conditional_t<std::is_enum<T>::value, std::underlying_type<T>,
|
||||
std::enable_if<true, T>>::type;
|
||||
|
||||
// Unsigned version of StorageType
|
||||
using StorageTypeU = std::make_unsigned_t<StorageType>;
|
||||
|
||||
public:
|
||||
/// Constants to allow limited introspection of fields if needed
|
||||
static constexpr size_t position = Position;
|
||||
static constexpr size_t bits = Bits;
|
||||
static constexpr StorageType mask = (((StorageTypeU)~0) >> (8 * sizeof(T) - bits)) << position;
|
||||
|
||||
/**
|
||||
* Formats a value by masking and shifting it according to the field parameters. A value
|
||||
* containing several bitfields can be assembled by formatting each of their values and ORing
|
||||
* the results together.
|
||||
*/
|
||||
static constexpr FORCE_INLINE StorageType FormatValue(const T& value) {
|
||||
return ((StorageType)value << position) & mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts a value from the passed storage. In most situations prefer use the member functions
|
||||
* (such as Value() or operator T), but this can be used to extract a value from a bitfield
|
||||
* union in a constexpr context.
|
||||
*/
|
||||
static constexpr FORCE_INLINE T ExtractValue(const StorageType& storage) {
|
||||
if (std::numeric_limits<T>::is_signed) {
|
||||
std::size_t shift = 8 * sizeof(T) - bits;
|
||||
return (T)((storage << (shift - position)) >> shift);
|
||||
} else {
|
||||
return (T)((storage & mask) >> position);
|
||||
}
|
||||
}
|
||||
|
||||
// This constructor and assignment operator might be considered ambiguous:
|
||||
// Would they initialize the storage or just the bitfield?
|
||||
// Hence, delete them. Use the Assign method to set bitfield values!
|
||||
|
|
@ -126,23 +164,18 @@ public:
|
|||
|
||||
// Force default constructor to be created
|
||||
// so that we can use this within unions
|
||||
BitField() = default;
|
||||
constexpr BitField() = default;
|
||||
|
||||
FORCE_INLINE operator T() const {
|
||||
return Value();
|
||||
}
|
||||
|
||||
FORCE_INLINE void Assign(const T& value) {
|
||||
storage = (storage & ~GetMask()) | (((StorageType)value << position) & GetMask());
|
||||
storage = (storage & ~mask) | FormatValue(value);
|
||||
}
|
||||
|
||||
FORCE_INLINE T Value() const {
|
||||
if (std::numeric_limits<T>::is_signed) {
|
||||
std::size_t shift = 8 * sizeof(T) - bits;
|
||||
return (T)((storage << (shift - position)) >> shift);
|
||||
} else {
|
||||
return (T)((storage & GetMask()) >> position);
|
||||
}
|
||||
return ExtractValue(storage);
|
||||
}
|
||||
|
||||
// TODO: we may want to change this to explicit operator bool() if it's bug-free in VS2015
|
||||
|
|
@ -151,20 +184,6 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
// StorageType is T for non-enum types and the underlying type of T if
|
||||
// T is an enumeration. Note that T is wrapped within an enable_if in the
|
||||
// former case to workaround compile errors which arise when using
|
||||
// std::underlying_type<T>::type directly.
|
||||
typedef typename std::conditional<std::is_enum<T>::value, std::underlying_type<T>,
|
||||
std::enable_if<true, T>>::type::type StorageType;
|
||||
|
||||
// Unsigned version of StorageType
|
||||
typedef typename std::make_unsigned<StorageType>::type StorageTypeU;
|
||||
|
||||
FORCE_INLINE StorageType GetMask() const {
|
||||
return (((StorageTypeU)~0) >> (8 * sizeof(T) - bits)) << position;
|
||||
}
|
||||
|
||||
StorageType storage;
|
||||
|
||||
static_assert(bits + position <= 8 * sizeof(T), "Bitfield out of range");
|
||||
|
|
|
|||
|
|
@ -231,6 +231,7 @@ set(HEADERS
|
|||
hle/kernel/address_arbiter.h
|
||||
hle/kernel/client_port.h
|
||||
hle/kernel/client_session.h
|
||||
hle/kernel/errors.h
|
||||
hle/kernel/event.h
|
||||
hle/kernel/kernel.h
|
||||
hle/kernel/memory.h
|
||||
|
|
|
|||
|
|
@ -38,8 +38,7 @@ public:
|
|||
ResultVal<size_t> Write(u64 offset, size_t length, bool flush,
|
||||
const u8* buffer) const override {
|
||||
if (offset > size) {
|
||||
return ResultCode(ErrorDescription::FS_WriteBeyondEnd, ErrorModule::FS,
|
||||
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
|
||||
return ERR_WRITE_BEYOND_END;
|
||||
} else if (offset == size) {
|
||||
return MakeResult<size_t>(0);
|
||||
}
|
||||
|
|
@ -191,11 +190,9 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_ExtSaveData::Open(cons
|
|||
// TODO(Subv): Verify the archive behavior of SharedExtSaveData compared to ExtSaveData.
|
||||
// ExtSaveData seems to return FS_NotFound (120) when the archive doesn't exist.
|
||||
if (!shared) {
|
||||
return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS,
|
||||
ErrorSummary::InvalidState, ErrorLevel::Status);
|
||||
return ERR_NOT_FOUND_INVALID_STATE;
|
||||
} else {
|
||||
return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
|
||||
ErrorSummary::InvalidState, ErrorLevel::Status);
|
||||
return ERR_NOT_FORMATTED;
|
||||
}
|
||||
}
|
||||
auto archive = std::make_unique<ExtSaveDataArchive>(fullpath);
|
||||
|
|
@ -230,8 +227,7 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Pat
|
|||
if (!file.IsOpen()) {
|
||||
LOG_ERROR(Service_FS, "Could not open metadata information for archive");
|
||||
// TODO(Subv): Verify error code
|
||||
return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
|
||||
ErrorSummary::InvalidState, ErrorLevel::Status);
|
||||
return ERR_NOT_FORMATTED;
|
||||
}
|
||||
|
||||
ArchiveFormatInfo info = {};
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "common/logging/log.h"
|
||||
#include "common/string_util.h"
|
||||
#include "core/file_sys/archive_source_sd_savedata.h"
|
||||
#include "core/file_sys/errors.h"
|
||||
#include "core/file_sys/savedata_archive.h"
|
||||
#include "core/hle/service/fs/archive.h"
|
||||
|
||||
|
|
@ -49,8 +50,7 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveSource_SDSaveData::Open(u64 pr
|
|||
// save file/directory structure expected by the game has not yet been initialized.
|
||||
// Returning the NotFormatted error code will signal the game to provision the SaveData
|
||||
// archive with the files and folders that it expects.
|
||||
return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
|
||||
ErrorSummary::InvalidState, ErrorLevel::Status);
|
||||
return ERR_NOT_FORMATTED;
|
||||
}
|
||||
|
||||
auto archive = std::make_unique<SaveDataArchive>(std::move(concrete_mount_point));
|
||||
|
|
@ -81,8 +81,7 @@ ResultVal<ArchiveFormatInfo> ArchiveSource_SDSaveData::GetFormatInfo(u64 program
|
|||
if (!file.IsOpen()) {
|
||||
LOG_ERROR(Service_FS, "Could not open metadata information for archive");
|
||||
// TODO(Subv): Verify error code
|
||||
return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
|
||||
ErrorSummary::InvalidState, ErrorLevel::Status);
|
||||
return ERR_NOT_FORMATTED;
|
||||
}
|
||||
|
||||
ArchiveFormatInfo info = {};
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include "common/file_util.h"
|
||||
#include "common/string_util.h"
|
||||
#include "core/file_sys/archive_systemsavedata.h"
|
||||
#include "core/file_sys/errors.h"
|
||||
#include "core/file_sys/savedata_archive.h"
|
||||
#include "core/hle/service/fs/archive.h"
|
||||
|
||||
|
|
@ -53,8 +54,7 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(c
|
|||
std::string fullpath = GetSystemSaveDataPath(base_path, path);
|
||||
if (!FileUtil::Exists(fullpath)) {
|
||||
// TODO(Subv): Check error code, this one is probably wrong
|
||||
return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
|
||||
ErrorSummary::InvalidState, ErrorLevel::Status);
|
||||
return ERR_NOT_FORMATTED;
|
||||
}
|
||||
auto archive = std::make_unique<SaveDataArchive>(fullpath);
|
||||
return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include "common/file_util.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/file_sys/disk_archive.h"
|
||||
#include "core/file_sys/errors.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// FileSys namespace
|
||||
|
|
@ -17,8 +18,7 @@ namespace FileSys {
|
|||
|
||||
ResultVal<size_t> DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const {
|
||||
if (!mode.read_flag)
|
||||
return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS,
|
||||
ErrorSummary::Canceled, ErrorLevel::Status);
|
||||
return ERROR_INVALID_OPEN_FLAGS;
|
||||
|
||||
file->Seek(offset, SEEK_SET);
|
||||
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
|
|||
ResultVal<size_t> DiskFile::Write(const u64 offset, const size_t length, const bool flush,
|
||||
const u8* buffer) const {
|
||||
if (!mode.write_flag)
|
||||
return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS,
|
||||
ErrorSummary::Canceled, ErrorLevel::Status);
|
||||
return ERROR_INVALID_OPEN_FLAGS;
|
||||
|
||||
file->Seek(offset, SEEK_SET);
|
||||
size_t written = file->WriteBytes(buffer, length);
|
||||
|
|
|
|||
|
|
@ -2,52 +2,93 @@
|
|||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
const ResultCode ERROR_INVALID_PATH(ErrorDescription::FS_InvalidPath, ErrorModule::FS,
|
||||
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
|
||||
const ResultCode ERROR_UNSUPPORTED_OPEN_FLAGS(ErrorDescription::FS_UnsupportedOpenFlags,
|
||||
ErrorModule::FS, ErrorSummary::NotSupported,
|
||||
ErrorLevel::Usage);
|
||||
const ResultCode ERROR_INVALID_OPEN_FLAGS(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS,
|
||||
ErrorSummary::Canceled, ErrorLevel::Status);
|
||||
const ResultCode ERROR_INVALID_READ_FLAG(ErrorDescription::FS_InvalidReadFlag, ErrorModule::FS,
|
||||
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
|
||||
const ResultCode ERROR_FILE_NOT_FOUND(ErrorDescription::FS_FileNotFound, ErrorModule::FS,
|
||||
ErrorSummary::NotFound, ErrorLevel::Status);
|
||||
const ResultCode ERROR_PATH_NOT_FOUND(ErrorDescription::FS_PathNotFound, ErrorModule::FS,
|
||||
ErrorSummary::NotFound, ErrorLevel::Status);
|
||||
const ResultCode ERROR_NOT_FOUND(ErrorDescription::FS_NotFound, ErrorModule::FS,
|
||||
ErrorSummary::NotFound, ErrorLevel::Status);
|
||||
const ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY(ErrorDescription::FS_UnexpectedFileOrDirectory,
|
||||
ErrorModule::FS, ErrorSummary::NotSupported,
|
||||
ErrorLevel::Usage);
|
||||
const ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC(ErrorDescription::FS_NotAFile,
|
||||
ErrorModule::FS, ErrorSummary::Canceled,
|
||||
ErrorLevel::Status);
|
||||
const ResultCode ERROR_DIRECTORY_ALREADY_EXISTS(ErrorDescription::FS_DirectoryAlreadyExists,
|
||||
ErrorModule::FS, ErrorSummary::NothingHappened,
|
||||
ErrorLevel::Status);
|
||||
const ResultCode ERROR_FILE_ALREADY_EXISTS(ErrorDescription::FS_FileAlreadyExists, ErrorModule::FS,
|
||||
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
||||
const ResultCode ERROR_ALREADY_EXISTS(ErrorDescription::FS_AlreadyExists, ErrorModule::FS,
|
||||
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
||||
const ResultCode ERROR_DIRECTORY_NOT_EMPTY(ErrorDescription::FS_DirectoryNotEmpty, ErrorModule::FS,
|
||||
ErrorSummary::Canceled, ErrorLevel::Status);
|
||||
const ResultCode ERROR_GAMECARD_NOT_INSERTED(ErrorDescription::FS_GameCardNotInserted,
|
||||
ErrorModule::FS, ErrorSummary::NotFound,
|
||||
ErrorLevel::Status);
|
||||
const ResultCode ERROR_INCORRECT_EXEFS_READ_SIZE(ErrorDescription::FS_IncorrectExeFSReadSize,
|
||||
ErrorModule::FS, ErrorSummary::NotSupported,
|
||||
ErrorLevel::Usage);
|
||||
const ResultCode ERROR_ROMFS_NOT_FOUND(ErrorDescription::FS_RomFSNotFound, ErrorModule::FS,
|
||||
ErrorSummary::NotFound, ErrorLevel::Status);
|
||||
const ResultCode ERROR_COMMAND_NOT_ALLOWED(ErrorDescription::FS_CommandNotAllowed, ErrorModule::FS,
|
||||
ErrorSummary::WrongArgument, ErrorLevel::Permanent);
|
||||
const ResultCode ERROR_EXEFS_SECTION_NOT_FOUND(ErrorDescription::FS_ExeFSSectionNotFound,
|
||||
ErrorModule::FS, ErrorSummary::NotFound,
|
||||
ErrorLevel::Status);
|
||||
namespace ErrCodes {
|
||||
enum {
|
||||
RomFSNotFound = 100,
|
||||
ArchiveNotMounted = 101,
|
||||
FileNotFound = 112,
|
||||
PathNotFound = 113,
|
||||
GameCardNotInserted = 141,
|
||||
NotFound = 120,
|
||||
FileAlreadyExists = 180,
|
||||
DirectoryAlreadyExists = 185,
|
||||
AlreadyExists = 190,
|
||||
InvalidOpenFlags = 230,
|
||||
DirectoryNotEmpty = 240,
|
||||
NotAFile = 250,
|
||||
NotFormatted = 340, ///< This is used by the FS service when creating a SaveData archive
|
||||
ExeFSSectionNotFound = 567,
|
||||
CommandNotAllowed = 630,
|
||||
InvalidReadFlag = 700,
|
||||
InvalidPath = 702,
|
||||
WriteBeyondEnd = 705,
|
||||
UnsupportedOpenFlags = 760,
|
||||
IncorrectExeFSReadSize = 761,
|
||||
UnexpectedFileOrDirectory = 770,
|
||||
};
|
||||
}
|
||||
|
||||
constexpr ResultCode ERROR_INVALID_PATH(ErrCodes::InvalidPath, ErrorModule::FS,
|
||||
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
|
||||
constexpr ResultCode ERROR_UNSUPPORTED_OPEN_FLAGS(ErrCodes::UnsupportedOpenFlags, ErrorModule::FS,
|
||||
ErrorSummary::NotSupported, ErrorLevel::Usage);
|
||||
constexpr ResultCode ERROR_INVALID_OPEN_FLAGS(ErrCodes::InvalidOpenFlags, ErrorModule::FS,
|
||||
ErrorSummary::Canceled, ErrorLevel::Status);
|
||||
constexpr ResultCode ERROR_INVALID_READ_FLAG(ErrCodes::InvalidReadFlag, ErrorModule::FS,
|
||||
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
|
||||
constexpr ResultCode ERROR_FILE_NOT_FOUND(ErrCodes::FileNotFound, ErrorModule::FS,
|
||||
ErrorSummary::NotFound, ErrorLevel::Status);
|
||||
constexpr ResultCode ERROR_PATH_NOT_FOUND(ErrCodes::PathNotFound, ErrorModule::FS,
|
||||
ErrorSummary::NotFound, ErrorLevel::Status);
|
||||
constexpr ResultCode ERROR_NOT_FOUND(ErrCodes::NotFound, ErrorModule::FS, ErrorSummary::NotFound,
|
||||
ErrorLevel::Status);
|
||||
constexpr ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY(ErrCodes::UnexpectedFileOrDirectory,
|
||||
ErrorModule::FS, ErrorSummary::NotSupported,
|
||||
ErrorLevel::Usage);
|
||||
constexpr ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC(ErrCodes::NotAFile, ErrorModule::FS,
|
||||
ErrorSummary::Canceled,
|
||||
ErrorLevel::Status);
|
||||
constexpr ResultCode ERROR_DIRECTORY_ALREADY_EXISTS(ErrCodes::DirectoryAlreadyExists,
|
||||
ErrorModule::FS, ErrorSummary::NothingHappened,
|
||||
ErrorLevel::Status);
|
||||
constexpr ResultCode ERROR_FILE_ALREADY_EXISTS(ErrCodes::FileAlreadyExists, ErrorModule::FS,
|
||||
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
||||
constexpr ResultCode ERROR_ALREADY_EXISTS(ErrCodes::AlreadyExists, ErrorModule::FS,
|
||||
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
||||
constexpr ResultCode ERROR_DIRECTORY_NOT_EMPTY(ErrCodes::DirectoryNotEmpty, ErrorModule::FS,
|
||||
ErrorSummary::Canceled, ErrorLevel::Status);
|
||||
constexpr ResultCode ERROR_GAMECARD_NOT_INSERTED(ErrCodes::GameCardNotInserted, ErrorModule::FS,
|
||||
ErrorSummary::NotFound, ErrorLevel::Status);
|
||||
constexpr ResultCode ERROR_INCORRECT_EXEFS_READ_SIZE(ErrCodes::IncorrectExeFSReadSize,
|
||||
ErrorModule::FS, ErrorSummary::NotSupported,
|
||||
ErrorLevel::Usage);
|
||||
constexpr ResultCode ERROR_ROMFS_NOT_FOUND(ErrCodes::RomFSNotFound, ErrorModule::FS,
|
||||
ErrorSummary::NotFound, ErrorLevel::Status);
|
||||
constexpr ResultCode ERROR_COMMAND_NOT_ALLOWED(ErrCodes::CommandNotAllowed, ErrorModule::FS,
|
||||
ErrorSummary::WrongArgument, ErrorLevel::Permanent);
|
||||
constexpr ResultCode ERROR_EXEFS_SECTION_NOT_FOUND(ErrCodes::ExeFSSectionNotFound, ErrorModule::FS,
|
||||
ErrorSummary::NotFound, ErrorLevel::Status);
|
||||
|
||||
/// Returned when a function is passed an invalid archive handle.
|
||||
constexpr ResultCode ERR_INVALID_ARCHIVE_HANDLE(ErrCodes::ArchiveNotMounted, ErrorModule::FS,
|
||||
ErrorSummary::NotFound,
|
||||
ErrorLevel::Status); // 0xC8804465
|
||||
constexpr ResultCode ERR_WRITE_BEYOND_END(ErrCodes::WriteBeyondEnd, ErrorModule::FS,
|
||||
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
|
||||
|
||||
/**
|
||||
* Variant of ERROR_NOT_FOUND returned in some places in the code. Unknown if these usages are
|
||||
* correct or a bug.
|
||||
*/
|
||||
constexpr ResultCode ERR_NOT_FOUND_INVALID_STATE(ErrCodes::NotFound, ErrorModule::FS,
|
||||
ErrorSummary::InvalidState, ErrorLevel::Status);
|
||||
constexpr ResultCode ERR_NOT_FORMATTED(ErrCodes::NotFormatted, ErrorModule::FS,
|
||||
ErrorSummary::InvalidState, ErrorLevel::Status);
|
||||
|
||||
} // namespace FileSys
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ void Wrap() {
|
|||
FuncReturn(retval);
|
||||
}
|
||||
|
||||
template <ResultCode func(u32*, s32, u32, u32, u32, s32)>
|
||||
template <ResultCode func(u32*, u32, u32, u32, u32, s32)>
|
||||
void Wrap() {
|
||||
u32 param_1 = 0;
|
||||
u32 retval = func(¶m_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)).raw;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/kernel/errors.h"
|
||||
#include "core/hle/kernel/thread.h"
|
||||
#include "core/memory.h"
|
||||
|
||||
|
|
@ -43,6 +44,12 @@ inline u32* GetStaticBuffers(const int offset = 0) {
|
|||
|
||||
namespace IPC {
|
||||
|
||||
// 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;
|
||||
|
||||
enum DescriptorType : u32 {
|
||||
// Buffer related desciptors types (mask : 0x0F)
|
||||
StaticBuffer = 0x02,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "common/common_types.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/hle/kernel/address_arbiter.h"
|
||||
#include "core/hle/kernel/errors.h"
|
||||
#include "core/hle/kernel/thread.h"
|
||||
#include "core/memory.h"
|
||||
|
||||
|
|
@ -74,8 +75,7 @@ ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address,
|
|||
|
||||
default:
|
||||
LOG_ERROR(Kernel, "unknown type=%d", type);
|
||||
return ResultCode(ErrorDescription::InvalidEnumValue, ErrorModule::Kernel,
|
||||
ErrorSummary::WrongArgument, ErrorLevel::Usage);
|
||||
return ERR_INVALID_ENUM_VALUE_FND;
|
||||
}
|
||||
|
||||
// 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,
|
|||
if (type == ArbitrationType::WaitIfLessThanWithTimeout ||
|
||||
type == ArbitrationType::DecrementAndWaitIfLessThanWithTimeout) {
|
||||
|
||||
return ResultCode(ErrorDescription::Timeout, ErrorModule::OS, ErrorSummary::StatusChanged,
|
||||
ErrorLevel::Info);
|
||||
return RESULT_TIMEOUT;
|
||||
}
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "common/assert.h"
|
||||
#include "core/hle/kernel/client_port.h"
|
||||
#include "core/hle/kernel/client_session.h"
|
||||
#include "core/hle/kernel/errors.h"
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
#include "core/hle/kernel/server_port.h"
|
||||
#include "core/hle/kernel/server_session.h"
|
||||
|
|
@ -19,8 +20,7 @@ ResultVal<SharedPtr<ClientSession>> ClientPort::Connect() {
|
|||
// AcceptSession before returning from this call.
|
||||
|
||||
if (active_sessions >= max_sessions) {
|
||||
return ResultCode(ErrorDescription::MaxConnectionsReached, ErrorModule::OS,
|
||||
ErrorSummary::WouldBlock, ErrorLevel::Temporary);
|
||||
return ERR_MAX_CONNECTIONS_REACHED;
|
||||
}
|
||||
active_sessions++;
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,7 @@ ResultCode ClientSession::SendSyncRequest() {
|
|||
if (parent->server)
|
||||
return parent->server->HandleSyncRequest();
|
||||
|
||||
return ResultCode(ErrorDescription::SessionClosedByRemote, ErrorModule::OS,
|
||||
ErrorSummary::Canceled, ErrorLevel::Status);
|
||||
return ERR_SESSION_CLOSED_BY_REMOTE;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
|||
98
src/core/hle/kernel/errors.h
Normal file
98
src/core/hle/kernel/errors.h
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
// Copyright 2017 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
namespace ErrCodes {
|
||||
enum {
|
||||
OutOfHandles = 19,
|
||||
SessionClosedByRemote = 26,
|
||||
PortNameTooLong = 30,
|
||||
WrongPermission = 46,
|
||||
InvalidBufferDescriptor = 48,
|
||||
MaxConnectionsReached = 52,
|
||||
};
|
||||
}
|
||||
|
||||
// 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
|
||||
/// 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);
|
||||
|
||||
} // namespace Kernel
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/hle/config_mem.h"
|
||||
#include "core/hle/kernel/errors.h"
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
#include "core/hle/kernel/memory.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
|
|
|
|||
|
|
@ -19,13 +19,6 @@ using Handle = u32;
|
|||
|
||||
class Thread;
|
||||
|
||||
// TODO: Verify code
|
||||
const ResultCode ERR_OUT_OF_HANDLES(ErrorDescription::OutOfMemory, ErrorModule::Kernel,
|
||||
ErrorSummary::OutOfResource, ErrorLevel::Temporary);
|
||||
// TOOD: Verify code
|
||||
const ResultCode ERR_INVALID_HANDLE(ErrorDescription::InvalidHandle, ErrorModule::Kernel,
|
||||
ErrorSummary::InvalidArgument, ErrorLevel::Permanent);
|
||||
|
||||
enum KernelHandle : Handle {
|
||||
CurrentThread = 0xFFFF8000,
|
||||
CurrentProcess = 0xFFFF8001,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "common/assert.h"
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/hle/kernel/errors.h"
|
||||
#include "core/hle/kernel/memory.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
#include "core/hle/kernel/resource_limit.h"
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
// Refer to the license.txt file included.
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "core/hle/kernel/errors.h"
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
#include "core/hle/kernel/semaphore.h"
|
||||
#include "core/hle/kernel/thread.h"
|
||||
|
|
@ -16,8 +17,7 @@ ResultVal<SharedPtr<Semaphore>> Semaphore::Create(s32 initial_count, s32 max_cou
|
|||
std::string name) {
|
||||
|
||||
if (initial_count > max_count)
|
||||
return ResultCode(ErrorDescription::InvalidCombination, ErrorModule::Kernel,
|
||||
ErrorSummary::WrongArgument, ErrorLevel::Permanent);
|
||||
return ERR_INVALID_COMBINATION_KERNEL;
|
||||
|
||||
SharedPtr<Semaphore> semaphore(new Semaphore);
|
||||
|
||||
|
|
@ -42,8 +42,7 @@ void Semaphore::Acquire(Thread* thread) {
|
|||
|
||||
ResultVal<s32> Semaphore::Release(s32 release_count) {
|
||||
if (max_count - available_count < release_count)
|
||||
return ResultCode(ErrorDescription::OutOfRange, ErrorModule::Kernel,
|
||||
ErrorSummary::InvalidArgument, ErrorLevel::Permanent);
|
||||
return ERR_OUT_OF_RANGE_KERNEL;
|
||||
|
||||
s32 previous_count = available_count;
|
||||
available_count += release_count;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <cstring>
|
||||
#include "common/logging/log.h"
|
||||
#include "core/hle/kernel/errors.h"
|
||||
#include "core/hle/kernel/memory.h"
|
||||
#include "core/hle/kernel/shared_memory.h"
|
||||
#include "core/memory.h"
|
||||
|
|
@ -102,24 +103,21 @@ ResultCode SharedMemory::Map(Process* target_process, VAddr address, MemoryPermi
|
|||
|
||||
// Automatically allocated memory blocks can only be mapped with other_permissions = DontCare
|
||||
if (base_address == 0 && other_permissions != MemoryPermission::DontCare) {
|
||||
return ResultCode(ErrorDescription::InvalidCombination, ErrorModule::OS,
|
||||
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
|
||||
return ERR_INVALID_COMBINATION;
|
||||
}
|
||||
|
||||
// Error out if the requested permissions don't match what the creator process allows.
|
||||
if (static_cast<u32>(permissions) & ~static_cast<u32>(own_other_permissions)) {
|
||||
LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s, permissions don't match",
|
||||
GetObjectId(), address, name.c_str());
|
||||
return ResultCode(ErrorDescription::InvalidCombination, ErrorModule::OS,
|
||||
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
|
||||
return ERR_INVALID_COMBINATION;
|
||||
}
|
||||
|
||||
// Heap-backed memory blocks can not be mapped with other_permissions = DontCare
|
||||
if (base_address != 0 && other_permissions == MemoryPermission::DontCare) {
|
||||
LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s, permissions don't match",
|
||||
GetObjectId(), address, name.c_str());
|
||||
return ResultCode(ErrorDescription::InvalidCombination, ErrorModule::OS,
|
||||
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
|
||||
return ERR_INVALID_COMBINATION;
|
||||
}
|
||||
|
||||
// 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
|
|||
static_cast<u32>(this->permissions) & ~static_cast<u32>(other_permissions)) {
|
||||
LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s, permissions don't match",
|
||||
GetObjectId(), address, name.c_str());
|
||||
return ResultCode(ErrorDescription::WrongPermission, ErrorModule::OS,
|
||||
ErrorSummary::WrongArgument, ErrorLevel::Permanent);
|
||||
return ERR_WRONG_PERMISSION;
|
||||
}
|
||||
|
||||
// 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
|
|||
if (address < Memory::HEAP_VADDR || address + size >= Memory::SHARED_MEMORY_VADDR_END) {
|
||||
LOG_ERROR(Kernel, "cannot map id=%u, address=0x%08X name=%s, invalid address",
|
||||
GetObjectId(), address, name.c_str());
|
||||
return ResultCode(ErrorDescription::InvalidAddress, ErrorModule::OS,
|
||||
ErrorSummary::InvalidArgument, ErrorLevel::Usage);
|
||||
return ERR_INVALID_ADDRESS;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include "core/arm/skyeye_common/armstate.h"
|
||||
#include "core/core.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hle/kernel/errors.h"
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
#include "core/hle/kernel/memory.h"
|
||||
#include "core/hle/kernel/mutex.h"
|
||||
|
|
@ -241,9 +242,7 @@ static void ThreadWakeupCallback(u64 thread_handle, int cycles_late) {
|
|||
for (auto& object : thread->wait_objects)
|
||||
object->RemoveWaitingThread(thread.get());
|
||||
thread->wait_objects.clear();
|
||||
thread->SetWaitSynchronizationResult(ResultCode(ErrorDescription::Timeout, ErrorModule::OS,
|
||||
ErrorSummary::StatusChanged,
|
||||
ErrorLevel::Info));
|
||||
thread->SetWaitSynchronizationResult(RESULT_TIMEOUT);
|
||||
}
|
||||
|
||||
thread->ResumeFromWait();
|
||||
|
|
@ -351,10 +350,20 @@ static void ResetThreadContext(ARM_Interface::ThreadContext& context, u32 stack_
|
|||
context.cpsr = USER32MODE | ((entry_point & 1) << 5); // Usermode and THUMB mode
|
||||
}
|
||||
|
||||
ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, s32 priority,
|
||||
ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, u32 priority,
|
||||
u32 arg, s32 processor_id, VAddr stack_top) {
|
||||
ASSERT_MSG(priority >= THREADPRIO_HIGHEST && priority <= THREADPRIO_LOWEST,
|
||||
"Invalid thread priority");
|
||||
// Check if priority is in ranged. Lowest priority -> highest priority id.
|
||||
if (priority > THREADPRIO_LOWEST) {
|
||||
LOG_ERROR(Kernel_SVC, "Invalid thread priority: %d", priority);
|
||||
return ERR_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
if (processor_id > THREADPROCESSORID_MAX) {
|
||||
LOG_ERROR(Kernel_SVC, "Invalid processor id: %d", processor_id);
|
||||
return ERR_OUT_OF_RANGE_KERNEL;
|
||||
}
|
||||
|
||||
// TODO(yuriks): Other checks, returning 0xD9001BEA
|
||||
|
||||
if (!Memory::IsValidVirtualAddress(entry_point)) {
|
||||
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,
|
|||
if (linheap_memory->size() + Memory::PAGE_SIZE > memory_region->size) {
|
||||
LOG_ERROR(Kernel_SVC,
|
||||
"Not enough space in region to allocate a new TLS page for thread");
|
||||
return ResultCode(ErrorDescription::OutOfMemory, ErrorModule::Kernel,
|
||||
ErrorSummary::OutOfResource, ErrorLevel::Permanent);
|
||||
return ERR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
u32 offset = linheap_memory->size();
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public:
|
|||
* @param stack_top The address of the thread's stack top
|
||||
* @return A shared pointer to the newly created thread
|
||||
*/
|
||||
static ResultVal<SharedPtr<Thread>> Create(std::string name, VAddr entry_point, s32 priority,
|
||||
static ResultVal<SharedPtr<Thread>> Create(std::string name, VAddr entry_point, u32 priority,
|
||||
u32 arg, s32 processor_id, VAddr stack_top);
|
||||
|
||||
std::string GetName() const override {
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue