core: backport some ResultCode updates (#6645)

Co-authored-by: Lioncash <mathew1800@gmail.com>
Co-authored-by: Morph <39850852+Morph1984@users.noreply.github.com>
This commit is contained in:
GPUCode 2023-07-03 03:23:53 +03:00 committed by GitHub
parent 0b37c1da57
commit 2126c240cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 1204 additions and 277 deletions

View file

@ -92,7 +92,7 @@ CIAFile::~CIAFile() {
ResultVal<std::size_t> CIAFile::Read(u64 offset, std::size_t length, u8* buffer) const {
UNIMPLEMENTED();
return MakeResult<std::size_t>(length);
return length;
}
ResultCode CIAFile::WriteTicket() {
@ -203,7 +203,7 @@ ResultVal<std::size_t> CIAFile::WriteContentData(u64 offset, std::size_t length,
}
}
return MakeResult(length);
return length;
}
ResultVal<std::size_t> CIAFile::Write(u64 offset, std::size_t length, bool flush,
@ -235,7 +235,7 @@ ResultVal<std::size_t> CIAFile::Write(u64 offset, std::size_t length, bool flush
// If we don't have a header yet, we can't pull offsets of other sections
if (install_state == CIAInstallState::InstallStarted)
return MakeResult<std::size_t>(length);
return length;
// If we have been given data before (or including) .app content, pull it into
// our buffer, but only pull *up to* the content offset, no further.
@ -267,14 +267,14 @@ ResultVal<std::size_t> CIAFile::Write(u64 offset, std::size_t length, bool flush
// Content data sizes can only be retrieved from TMD data
if (install_state != CIAInstallState::TMDLoaded)
return MakeResult<std::size_t>(length);
return length;
// From this point forward, data will no longer be buffered in data
auto result = WriteContentData(offset, length, buffer);
if (result.Failed())
return result;
return MakeResult<std::size_t>(length);
return length;
}
u64 CIAFile::GetSize() const {
@ -1316,7 +1316,7 @@ ResultVal<std::unique_ptr<AMFileWrapper>> GetFileFromSession(
// File::OpenSubFile
std::size_t offset = file->GetSessionFileOffset(server);
std::size_t size = file->GetSessionFileSize(server);
return MakeResult(std::make_unique<AMFileWrapper>(file, offset, size));
return std::make_unique<AMFileWrapper>(file, offset, size);
}
LOG_ERROR(Service_AM, "Failed to cast handle to FSFile!");

View file

@ -291,7 +291,7 @@ ResultVal<MessageParameter> AppletManager::GlanceParameter(AppletId app_id) {
next_parameter = {};
}
return MakeResult<MessageParameter>(std::move(parameter));
return parameter;
}
ResultVal<MessageParameter> AppletManager::ReceiveParameter(AppletId app_id) {
@ -333,7 +333,7 @@ ResultVal<AppletManager::GetLockHandleResult> AppletManager::GetLockHandle(
corrected_attributes.raw);
}
return MakeResult<AppletManager::GetLockHandleResult>({corrected_attributes, 0, lock});
return GetLockHandleResult{corrected_attributes, 0, lock};
}
ResultVal<AppletManager::InitializeResult> AppletManager::Initialize(AppletId app_id,
@ -372,8 +372,7 @@ ResultVal<AppletManager::InitializeResult> AppletManager::Initialize(AppletId ap
});
}
return MakeResult<InitializeResult>(
{slot_data->notification_event, slot_data->parameter_event});
return InitializeResult{slot_data->notification_event, slot_data->parameter_event};
}
ResultCode AppletManager::Enable(AppletAttributes attributes) {
@ -420,7 +419,7 @@ ResultVal<Notification> AppletManager::InquireNotification(AppletId app_id) {
if (slot_data->registered) {
auto notification = slot_data->notification;
slot_data->notification = Notification::None;
return MakeResult<Notification>(notification);
return notification;
}
}
@ -943,12 +942,12 @@ ResultVal<AppletManager::AppletManInfo> AppletManager::GetAppletManInfo(
}
}
return MakeResult<AppletManInfo>({
return AppletManInfo{
.active_applet_pos = active_applet_pos,
.requested_applet_id = requested_applet_id,
.home_menu_applet_id = AppletId::HomeMenu,
.active_applet_id = active_applet_id,
});
};
}
ResultVal<AppletManager::AppletInfo> AppletManager::GetAppletInfo(AppletId app_id) {
@ -968,8 +967,13 @@ ResultVal<AppletManager::AppletInfo> AppletManager::GetAppletInfo(AppletId app_i
auto media_type = ((slot_data->title_id >> 32) & 0xFFFFFFFF) == 0x00040000
? Service::FS::MediaType::SDMC
: Service::FS::MediaType::NAND;
return MakeResult<AppletInfo>({slot_data->title_id, media_type, slot_data->registered,
slot_data->loaded, slot_data->attributes.raw});
return AppletInfo{
.title_id = slot_data->title_id,
.media_type = media_type,
.registered = slot_data->registered,
.loaded = slot_data->loaded,
.attributes = slot_data->attributes.raw,
};
}
ResultCode AppletManager::PrepareToDoApplicationJump(u64 title_id, FS::MediaType media_type,

View file

@ -1239,7 +1239,7 @@ void Module::CheckAndUpdateFile(const CecDataPathType path_type, const u32 ncch_
const u32 message_size = static_cast<u32>(message->GetSize());
std::vector<u8> buffer(message_size);
message->Read(0, message_size, buffer.data()).Unwrap();
void(message->Read(0, message_size, buffer.data()).Unwrap());
message->Close();
std::memcpy(&message_headers[outbox_info_header.message_num++], buffer.data(),
@ -1329,7 +1329,7 @@ void Module::CheckAndUpdateFile(const CecDataPathType path_type, const u32 ncch_
const u32 message_size = static_cast<u32>(message->GetSize());
std::vector<u8> buffer(message_size);
message->Read(0, message_size, buffer.data()).Unwrap();
void(message->Read(0, message_size, buffer.data()).Unwrap());
message->Close();
// Message id is at offset 0x20, and is 8 bytes

View file

@ -432,7 +432,7 @@ ResultVal<void*> Module::GetConfigInfoBlockPointer(u32 block_id, u32 size, u32 f
else
pointer = &cfg_config_file_buffer[itr->offset_or_data];
return MakeResult<void*>(pointer);
return pointer;
}
ResultCode Module::GetConfigInfoBlock(u32 block_id, u32 size, u32 flag, void* output) {

View file

@ -63,7 +63,7 @@ ResultVal<ArchiveHandle> ArchiveManager::OpenArchive(ArchiveIdCode id_code,
++next_handle;
}
handle_map.emplace(next_handle, std::move(res));
return MakeResult(next_handle++);
return next_handle++;
}
ResultCode ArchiveManager::CloseArchive(ArchiveHandle handle) {
@ -103,7 +103,7 @@ ArchiveManager::OpenFileFromArchive(ArchiveHandle archive_handle, const FileSys:
}
auto file = std::make_shared<File>(system.Kernel(), std::move(backend).Unwrap(), path);
return std::make_pair(MakeResult(std::move(file)), open_timeout_ns);
return std::make_pair(std::move(file), open_timeout_ns);
}
ResultCode ArchiveManager::DeleteFileFromArchive(ArchiveHandle archive_handle,
@ -197,8 +197,7 @@ ResultVal<std::shared_ptr<Directory>> ArchiveManager::OpenDirectoryFromArchive(
return backend.Code();
}
auto directory = std::make_shared<Directory>(std::move(backend).Unwrap(), path);
return MakeResult(std::move(directory));
return std::make_shared<Directory>(std::move(backend).Unwrap(), path);
}
ResultVal<u64> ArchiveManager::GetFreeBytesInArchive(ArchiveHandle archive_handle) {
@ -206,7 +205,7 @@ ResultVal<u64> ArchiveManager::GetFreeBytesInArchive(ArchiveHandle archive_handl
if (archive == nullptr) {
return FileSys::ERR_INVALID_ARCHIVE_HANDLE;
}
return MakeResult(archive->GetFreeBytes());
return archive->GetFreeBytes();
}
ResultCode ArchiveManager::FormatArchive(ArchiveIdCode id_code,
@ -314,7 +313,7 @@ ResultVal<ArchiveResource> ArchiveManager::GetArchiveResource(MediaType media_ty
resource.cluster_size_in_bytes = 16384;
resource.partition_capacity_in_clusters = 0x80000; // 8GiB capacity
resource.free_space_in_clusters = 0x80000; // 8GiB free
return MakeResult(resource);
return resource;
}
void ArchiveManager::RegisterArchiveTypes() {

View file

@ -845,11 +845,11 @@ ResultVal<u16> FS_USER::GetSpecialContentIndexFromGameCard(u64 title_id, Special
switch (type) {
case SpecialContentType::Update:
return MakeResult(static_cast<u16>(NCSDContentIndex::Update));
return static_cast<u16>(NCSDContentIndex::Update);
case SpecialContentType::Manual:
return MakeResult(static_cast<u16>(NCSDContentIndex::Manual));
return static_cast<u16>(NCSDContentIndex::Manual);
case SpecialContentType::DLPChild:
return MakeResult(static_cast<u16>(NCSDContentIndex::DLP));
return static_cast<u16>(NCSDContentIndex::DLP);
default:
UNREACHABLE();
}
@ -874,9 +874,9 @@ ResultVal<u16> FS_USER::GetSpecialContentIndexFromTMD(MediaType media_type, u64
switch (type) {
case SpecialContentType::Manual:
return MakeResult(static_cast<u16>(FileSys::TMDContentIndex::Manual));
return static_cast<u16>(FileSys::TMDContentIndex::Manual);
case SpecialContentType::DLPChild:
return MakeResult(static_cast<u16>(FileSys::TMDContentIndex::DLP));
return static_cast<u16>(FileSys::TMDContentIndex::DLP);
default:
ASSERT(false);
}

View file

@ -301,7 +301,7 @@ ResultVal<VAddr> CROHelper::RebaseSegmentTable(u32 cro_size, VAddr data_segment_
}
SetEntry(system.Memory(), i, segment);
}
return MakeResult<u32>(prev_data_segment + module_address);
return prev_data_segment + module_address;
}
ResultCode CROHelper::RebaseExportNamedSymbolTable() {
@ -776,10 +776,10 @@ ResultCode CROHelper::ApplyImportNamedSymbol(VAddr crs_address) {
return result;
}
return MakeResult<bool>(false);
return false;
}
return MakeResult<bool>(true);
return true;
});
if (result.IsError()) {
return result;
@ -897,9 +897,9 @@ ResultCode CROHelper::ApplyModuleImport(VAddr crs_address) {
return result;
}
}
return MakeResult<bool>(false);
return false;
}
return MakeResult<bool>(true);
return true;
});
if (result.IsError()) {
return result;
@ -1090,10 +1090,10 @@ ResultCode CROHelper::ApplyExitRelocations(VAddr crs_address) {
return result;
}
return MakeResult<bool>(false);
return false;
}
return MakeResult<bool>(true);
return true;
});
if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying exit relocation {:08X}", result.raw);
@ -1317,7 +1317,7 @@ ResultCode CROHelper::Link(VAddr crs_address, bool link_on_load_bug_fix) {
if (result.IsError())
return result;
return MakeResult<bool>(true);
return true;
});
if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error applying export {:08X}", result.raw);
@ -1362,7 +1362,7 @@ ResultCode CROHelper::Unlink(VAddr crs_address) {
if (result.IsError())
return result;
return MakeResult<bool>(true);
return true;
});
if (result.IsError()) {
LOG_ERROR(Service_LDR, "Error resetting export {:08X}", result.raw);

View file

@ -673,7 +673,7 @@ ResultVal<std::shared_ptr<Kernel::Event>> NWM_UDS::Initialize(
channel_data.clear();
}
return MakeResult(connection_status_event);
return connection_status_event;
}
void NWM_UDS::InitializeWithVersion(Kernel::HLERequestContext& ctx) {

View file

@ -131,7 +131,7 @@ void PLG_LDR::OnProcessExit(Kernel::Process& process, Kernel::KernelSystem& kern
ResultVal<Kernel::Handle> PLG_LDR::GetMemoryChangedHandle(Kernel::KernelSystem& kernel) {
if (plgldr_context.memory_changed_handle)
return MakeResult(plgldr_context.memory_changed_handle);
return plgldr_context.memory_changed_handle;
std::shared_ptr<Kernel::Event> evt = kernel.CreateEvent(
Kernel::ResetType::OneShot,
@ -139,7 +139,7 @@ ResultVal<Kernel::Handle> PLG_LDR::GetMemoryChangedHandle(Kernel::KernelSystem&
CASCADE_RESULT(plgldr_context.memory_changed_handle,
kernel.GetCurrentProcess()->handle_table.Create(std::move(evt)));
return MakeResult(plgldr_context.memory_changed_handle);
return plgldr_context.memory_changed_handle;
}
void PLG_LDR::OnMemoryChanged(Kernel::Process& process, Kernel::KernelSystem& kernel) {

View file

@ -44,7 +44,7 @@ ResultVal<std::shared_ptr<Kernel::ServerPort>> ServiceManager::RegisterService(
registered_services_inverse.emplace(client_port->GetObjectId(), name);
registered_services.emplace(std::move(name), std::move(client_port));
return MakeResult(std::move(server_port));
return server_port;
}
ResultVal<std::shared_ptr<Kernel::ClientPort>> ServiceManager::GetServicePort(
@ -56,7 +56,7 @@ ResultVal<std::shared_ptr<Kernel::ClientPort>> ServiceManager::GetServicePort(
return ERR_SERVICE_NOT_REGISTERED;
}
return MakeResult(it->second);
return it->second;
}
ResultVal<std::shared_ptr<Kernel::ClientSession>> ServiceManager::ConnectToService(