mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-30 14:35:17 -04:00
ams: globally prefer R_RETURN to return for ams::Result
This commit is contained in:
parent
dd78ede99f
commit
bbf22b4c60
325 changed files with 1955 additions and 1993 deletions
|
@ -21,7 +21,7 @@ namespace ams::settings::impl {
|
|||
Result GetConfigurationId1(settings::factory::ConfigurationId1 *out) {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
static_assert(sizeof(*out) == sizeof(::SetCalConfigurationId1));
|
||||
return ::setcalGetConfigurationId1(reinterpret_cast<::SetCalConfigurationId1 *>(out));
|
||||
R_RETURN(::setcalGetConfigurationId1(reinterpret_cast<::SetCalConfigurationId1 *>(out)));
|
||||
#else
|
||||
AMS_UNUSED(out);
|
||||
AMS_ABORT("TODO");
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace ams::settings::impl {
|
|||
Result GetErrorReportSharePermission(s32 *out) {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
static_assert(sizeof(*out) == sizeof(::SetSysErrorReportSharePermission));
|
||||
return ::setsysGetErrorReportSharePermission(reinterpret_cast<::SetSysErrorReportSharePermission *>(out));
|
||||
R_RETURN(::setsysGetErrorReportSharePermission(reinterpret_cast<::SetSysErrorReportSharePermission *>(out)));
|
||||
#else
|
||||
AMS_UNUSED(out);
|
||||
AMS_ABORT("TODO");
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace ams::settings::impl {
|
|||
Result GetFirmwareVersion(settings::system::FirmwareVersion *out) {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
static_assert(sizeof(*out) == sizeof(::SetSysFirmwareVersion));
|
||||
return ::setsysGetFirmwareVersion(reinterpret_cast<::SetSysFirmwareVersion *>(out));
|
||||
R_RETURN(::setsysGetFirmwareVersion(reinterpret_cast<::SetSysFirmwareVersion *>(out)));
|
||||
#else
|
||||
AMS_UNUSED(out);
|
||||
AMS_ABORT("TODO");
|
||||
|
|
|
@ -300,7 +300,7 @@ namespace ams::settings::impl {
|
|||
AMS_ASSERT(out != nullptr);
|
||||
|
||||
/* Get the map. */
|
||||
return GetKeyValueStoreMap(out, false);
|
||||
R_RETURN(GetKeyValueStoreMap(out, false));
|
||||
}
|
||||
|
||||
Result GetKeyValueStoreMap(Map **out, bool force_load) {
|
||||
|
@ -338,7 +338,7 @@ namespace ams::settings::impl {
|
|||
AMS_ASSERT(out != nullptr);
|
||||
|
||||
/* Get the map. */
|
||||
return GetKeyValueStoreMap(out, true);
|
||||
R_RETURN(GetKeyValueStoreMap(out, true));
|
||||
}
|
||||
|
||||
Result GetMapValueOfKeyValueStoreItemForDebug(MapValue *out, const KeyValueStoreItemForDebug &item) {
|
||||
|
@ -536,7 +536,7 @@ namespace ams::settings::impl {
|
|||
AMS_ASSERT(data != nullptr);
|
||||
|
||||
/* Load the key value store map. */
|
||||
return LoadKeyValueStoreMapDefault(out, *data);
|
||||
R_RETURN(LoadKeyValueStoreMapDefault(out, *data));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -708,7 +708,7 @@ namespace ams::settings::impl {
|
|||
}
|
||||
|
||||
/* Load the value. */
|
||||
return load(*out, key, type, value_buffer, value_size);
|
||||
R_RETURN(load(*out, key, type, value_buffer, value_size));
|
||||
}
|
||||
|
||||
Result LoadKeyValueStoreMapForDebug(Map *out, SystemSaveData *system_save_data, SystemSaveData *fwdbg_system_save_data, SystemSaveData *pfcfg_system_save_data) {
|
||||
|
@ -885,7 +885,7 @@ namespace ams::settings::impl {
|
|||
AMS_ASSERT(system_save_data != nullptr);
|
||||
|
||||
/* Save the current values of the key value store map. */
|
||||
return SaveKeyValueStoreMapCurrent(*system_save_data, map);
|
||||
R_RETURN(SaveKeyValueStoreMapCurrent(*system_save_data, map));
|
||||
}
|
||||
|
||||
template<typename T, typename F>
|
||||
|
@ -933,13 +933,13 @@ namespace ams::settings::impl {
|
|||
}
|
||||
|
||||
/* Commit the save data. */
|
||||
return data.Commit(false);
|
||||
R_RETURN(data.Commit(false));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Result SaveKeyValueStoreMapCurrent(T &data, const Map &map) {
|
||||
/* Save the current values in the map to the data. */
|
||||
return SaveKeyValueStoreMap(data, map, [](u8 *out_type, const void **out_value_buffer, u32 *out_value_size, const MapValue &map_value) -> bool {
|
||||
R_RETURN(SaveKeyValueStoreMap(data, map, [](u8 *out_type, const void **out_value_buffer, u32 *out_value_size, const MapValue &map_value) -> bool {
|
||||
/* Check preconditions. */
|
||||
AMS_ASSERT(out_type != nullptr);
|
||||
AMS_ASSERT(out_value_buffer != nullptr);
|
||||
|
@ -955,13 +955,13 @@ namespace ams::settings::impl {
|
|||
*out_value_buffer = map_value.current_value;
|
||||
*out_value_size = map_value.current_value_size;
|
||||
return true;
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Result SaveKeyValueStoreMapDefault(T &data, const Map &map) {
|
||||
/* Save the default values in the map to the data. */
|
||||
return SaveKeyValueStoreMap(data, map, [](u8 *out_type, const void **out_value_buffer, u32 *out_value_size, const MapValue &map_value) -> bool {
|
||||
R_RETURN(SaveKeyValueStoreMap(data, map, [](u8 *out_type, const void **out_value_buffer, u32 *out_value_size, const MapValue &map_value) -> bool {
|
||||
/* Check preconditions. */
|
||||
AMS_ASSERT(out_type != nullptr);
|
||||
AMS_ASSERT(out_value_buffer != nullptr);
|
||||
|
@ -972,11 +972,11 @@ namespace ams::settings::impl {
|
|||
*out_value_buffer = map_value.default_value;
|
||||
*out_value_size = map_value.default_value_size;
|
||||
return true;
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
Result SaveKeyValueStoreMapDefaultForDebug(SystemSaveData &data, const Map &map) {
|
||||
return SaveKeyValueStoreMapDefault(data, map);
|
||||
R_RETURN(SaveKeyValueStoreMapDefault(data, map));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -1161,16 +1161,17 @@ namespace ams::settings::impl {
|
|||
map_value.current_value_size = map_value.default_value_size;
|
||||
map_value.current_value = map_value.default_value;
|
||||
|
||||
/* Attempt to save the key value store map. */
|
||||
if (const auto result = SaveKeyValueStoreMap(*map); R_FAILED(result)) {
|
||||
/* If we fail, revert the map. */
|
||||
ON_RESULT_FAILURE {
|
||||
/* Revert to the previous value. */
|
||||
map_value.current_value_size = prev_value_size;
|
||||
map_value.current_value = prev_value;
|
||||
|
||||
/* Attempt to save the map again. Nintendo does not check the result of this. */
|
||||
SaveKeyValueStoreMap(*map);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
/* Attempt to save the key value store map. */
|
||||
R_TRY(SaveKeyValueStoreMap(*map));
|
||||
|
||||
/* If present, free the previous value. */
|
||||
if (prev_value != nullptr && prev_value != map_value.default_value) {
|
||||
|
@ -1222,31 +1223,27 @@ namespace ams::settings::impl {
|
|||
std::memcpy(value_buffer, buffer, value_size);
|
||||
}
|
||||
|
||||
/* When we're done, free the unused value buffer. */
|
||||
ON_SCOPE_EXIT {
|
||||
if (value_buffer != nullptr && value_buffer != map_value.default_value) {
|
||||
FreeToHeap(value_buffer, value_size);
|
||||
}
|
||||
};
|
||||
|
||||
/* Swap the current value with the new value. */
|
||||
std::swap(map_value.current_value_size, value_size);
|
||||
std::swap(map_value.current_value, value_buffer);
|
||||
|
||||
/* Attempt to save the key value store map. */
|
||||
const auto result = SaveKeyValueStoreMap(*map);
|
||||
|
||||
/* If we failed, revert to the previous value. */
|
||||
if (R_FAILED(result)) {
|
||||
/* If we fail, revert. */
|
||||
ON_RESULT_FAILURE {
|
||||
std::swap(map_value.current_value_size, value_size);
|
||||
std::swap(map_value.current_value, value_buffer);
|
||||
}
|
||||
|
||||
/* Free the now unused value. */
|
||||
if (value_buffer != nullptr && value_buffer != map_value.default_value) {
|
||||
FreeToHeap(value_buffer, value_size);
|
||||
}
|
||||
|
||||
/* If we failed, attempt to save the map again. Note that Nintendo does not check the result of this. */
|
||||
if (R_FAILED(result)) {
|
||||
SaveKeyValueStoreMap(*map);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
R_SUCCEED();
|
||||
/* Attempt to save the key value store map. */
|
||||
R_RETURN(SaveKeyValueStoreMap(*map));
|
||||
}
|
||||
|
||||
Result AddKeyValueStoreItemForDebug(const KeyValueStoreItemForDebug * const items, size_t items_count) {
|
||||
|
@ -1476,7 +1473,7 @@ namespace ams::settings::impl {
|
|||
std::scoped_lock lk(g_key_value_store_mutex);
|
||||
|
||||
/* Read the firmware debug system data. */
|
||||
return ReadSystemDataFirmwareDebug(out_count, out_buffer, out_buffer_size);
|
||||
R_RETURN(ReadSystemDataFirmwareDebug(out_count, out_buffer, out_buffer_size));
|
||||
}
|
||||
|
||||
Result ReadKeyValueStorePlatformConfiguration(u64 *out_count, char * const out_buffer, size_t out_buffer_size) {
|
||||
|
@ -1488,7 +1485,7 @@ namespace ams::settings::impl {
|
|||
std::scoped_lock lk(g_key_value_store_mutex);
|
||||
|
||||
/* Read the platform configuration system data. */
|
||||
return ReadSystemDataPlatformConfiguration(out_count, out_buffer, out_buffer_size);
|
||||
R_RETURN(ReadSystemDataPlatformConfiguration(out_count, out_buffer, out_buffer_size));
|
||||
}
|
||||
|
||||
Result ReadKeyValueStoreSaveData(u64 *out_count, char * const out_buffer, size_t out_buffer_size) {
|
||||
|
@ -1500,7 +1497,7 @@ namespace ams::settings::impl {
|
|||
std::scoped_lock lk(g_key_value_store_mutex);
|
||||
|
||||
/* Read the system save data. */
|
||||
return ReadSystemSaveData(out_count, out_buffer, out_buffer_size);
|
||||
R_RETURN(ReadSystemSaveData(out_count, out_buffer, out_buffer_size));
|
||||
}
|
||||
|
||||
Result ReloadKeyValueStoreForDebug(SystemSaveData *system_save_data, SystemSaveData *fwdbg_system_data, SystemSaveData *pfcfg_system_data) {
|
||||
|
@ -1518,7 +1515,7 @@ namespace ams::settings::impl {
|
|||
AMS_ASSERT(map != nullptr);
|
||||
|
||||
/* Load the key value store map. */
|
||||
return LoadKeyValueStoreMapForDebug(map, system_save_data, fwdbg_system_data, pfcfg_system_data);
|
||||
R_RETURN(LoadKeyValueStoreMapForDebug(map, system_save_data, fwdbg_system_data, pfcfg_system_data));
|
||||
}
|
||||
|
||||
Result ReloadKeyValueStoreForDebug() {
|
||||
|
@ -1531,7 +1528,7 @@ namespace ams::settings::impl {
|
|||
AMS_ASSERT(map != nullptr);
|
||||
|
||||
/* Load the key value store map. */
|
||||
return LoadKeyValueStoreMap(map);
|
||||
R_RETURN(LoadKeyValueStoreMap(map));
|
||||
}
|
||||
|
||||
Result ResetKeyValueStoreSaveData() {
|
||||
|
@ -1566,7 +1563,7 @@ namespace ams::settings::impl {
|
|||
}
|
||||
|
||||
/* Save the key value store map. */
|
||||
return SaveKeyValueStoreMap(*map);
|
||||
R_RETURN(SaveKeyValueStoreMap(*map));
|
||||
}
|
||||
|
||||
Result SaveKeyValueStoreAllForDebug(SystemSaveData *data) {
|
||||
|
@ -1585,7 +1582,7 @@ namespace ams::settings::impl {
|
|||
R_TRY(SaveKeyValueStoreMapDefaultForDebug(*data, *map));
|
||||
|
||||
/* Save the key value store map. */
|
||||
return SaveKeyValueStoreMap(*map);
|
||||
R_RETURN(SaveKeyValueStoreMap(*map));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace ams::settings::impl {
|
|||
Result GetPlatformRegion(s32 *out) {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
static_assert(sizeof(*out) == sizeof(::SetSysPlatformRegion));
|
||||
return ::setsysGetPlatformRegion(reinterpret_cast<::SetSysPlatformRegion *>(out));
|
||||
R_RETURN(::setsysGetPlatformRegion(reinterpret_cast<::SetSysPlatformRegion *>(out)));
|
||||
#else
|
||||
AMS_UNUSED(out);
|
||||
AMS_ABORT("TODO");
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace ams::settings::impl {
|
|||
Result GetProductModel(s32 *out) {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
static_assert(sizeof(*out) == sizeof(::SetSysProductModel));
|
||||
return ::setsysGetProductModel(reinterpret_cast<::SetSysProductModel *>(out));
|
||||
R_RETURN(::setsysGetProductModel(reinterpret_cast<::SetSysProductModel *>(out)));
|
||||
#else
|
||||
AMS_UNUSED(out);
|
||||
AMS_ABORT("TODO");
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace ams::settings::impl {
|
|||
Result GetRegionCode(s32 *out) {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
static_assert(sizeof(*out) == sizeof(::SetRegion));
|
||||
return ::setGetRegionCode(reinterpret_cast<::SetRegion *>(out));
|
||||
R_RETURN(::setGetRegionCode(reinterpret_cast<::SetRegion *>(out)));
|
||||
#else
|
||||
AMS_UNUSED(out);
|
||||
AMS_ABORT("TODO");
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace ams::settings::impl {
|
|||
Result GetSerialNumber(settings::factory::SerialNumber *out) {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
static_assert(sizeof(*out) == sizeof(::SetCalSerialNumber));
|
||||
return ::setcalGetSerialNumber(reinterpret_cast<::SetCalSerialNumber *>(out));
|
||||
R_RETURN(::setcalGetSerialNumber(reinterpret_cast<::SetCalSerialNumber *>(out)));
|
||||
#else
|
||||
AMS_UNUSED(out);
|
||||
AMS_ABORT("TODO");
|
||||
|
@ -31,7 +31,7 @@ namespace ams::settings::impl {
|
|||
Result GetSerialNumber(settings::system::SerialNumber *out) {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
static_assert(sizeof(*out) == sizeof(::SetSysSerialNumber));
|
||||
return ::setsysGetSerialNumber(reinterpret_cast<::SetSysSerialNumber *>(out));
|
||||
R_RETURN(::setsysGetSerialNumber(reinterpret_cast<::SetSysSerialNumber *>(out)));
|
||||
#else
|
||||
AMS_UNUSED(out);
|
||||
AMS_ABORT("TODO");
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace ams::settings::impl {
|
|||
|
||||
Result LazyFileAccessor::Open(const char *path, int mode) {
|
||||
/* Open our file. */
|
||||
return fs::OpenFile(std::addressof(m_file), path, mode);
|
||||
R_RETURN(fs::OpenFile(std::addressof(m_file), path, mode));
|
||||
}
|
||||
|
||||
void LazyFileAccessor::Close() {
|
||||
|
@ -98,7 +98,7 @@ namespace ams::settings::impl {
|
|||
|
||||
/* If the read is too big for the cache, read the data directly. */
|
||||
if (size > sizeof(m_buffer)) {
|
||||
return fs::ReadFile(m_file, offset, dst, size);
|
||||
R_RETURN(fs::ReadFile(m_file, offset, dst, size));
|
||||
}
|
||||
|
||||
/* Get the file size. */
|
||||
|
@ -107,7 +107,7 @@ namespace ams::settings::impl {
|
|||
|
||||
/* If the file is too small, read the data directly. */
|
||||
if (file_size < offset + static_cast<s64>(size)) {
|
||||
return fs::ReadFile(m_file, offset, dst, size);
|
||||
R_RETURN(fs::ReadFile(m_file, offset, dst, size));
|
||||
}
|
||||
|
||||
/* Determine the read size. */
|
||||
|
@ -152,11 +152,11 @@ namespace ams::settings::impl {
|
|||
}
|
||||
|
||||
Result SystemData::Mount() {
|
||||
return fs::MountSystemData(m_mount_name, m_system_data_id);
|
||||
R_RETURN(fs::MountSystemData(m_mount_name, m_system_data_id));
|
||||
}
|
||||
|
||||
Result SystemData::OpenToRead() {
|
||||
return GetLazyFileAccessor().Open(m_file_path, fs::OpenMode_Read);
|
||||
R_RETURN(GetLazyFileAccessor().Open(m_file_path, fs::OpenMode_Read));
|
||||
}
|
||||
|
||||
void SystemData::Close() {
|
||||
|
@ -164,7 +164,7 @@ namespace ams::settings::impl {
|
|||
}
|
||||
|
||||
Result SystemData::Read(s64 offset, void *dst, size_t size) {
|
||||
return GetLazyFileAccessor().Read(offset, dst, size);
|
||||
R_RETURN(GetLazyFileAccessor().Read(offset, dst, size));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -454,23 +454,23 @@ namespace ams::settings::impl {
|
|||
}
|
||||
|
||||
/* Mount the save data. */
|
||||
return fs::MountSystemSaveData(m_mount_name, m_save_data_space_id, m_system_save_data_id);
|
||||
R_RETURN(fs::MountSystemSaveData(m_mount_name, m_save_data_space_id, m_system_save_data_id));
|
||||
}
|
||||
|
||||
Result SystemSaveData::Commit(bool synchronous) {
|
||||
return GetLazyFileAccessor().Commit(m_mount_name, synchronous);
|
||||
R_RETURN(GetLazyFileAccessor().Commit(m_mount_name, synchronous));
|
||||
}
|
||||
|
||||
Result SystemSaveData::Create(s64 size) {
|
||||
return GetLazyFileAccessor().Create(m_mount_name, size);
|
||||
R_RETURN(GetLazyFileAccessor().Create(m_mount_name, size));
|
||||
}
|
||||
|
||||
Result SystemSaveData::OpenToRead() {
|
||||
return GetLazyFileAccessor().Open(m_mount_name, fs::OpenMode_Read);
|
||||
R_RETURN(GetLazyFileAccessor().Open(m_mount_name, fs::OpenMode_Read));
|
||||
}
|
||||
|
||||
Result SystemSaveData::OpenToWrite() {
|
||||
return GetLazyFileAccessor().Open(m_mount_name, fs::OpenMode_Write);
|
||||
R_RETURN(GetLazyFileAccessor().Open(m_mount_name, fs::OpenMode_Write));
|
||||
}
|
||||
|
||||
void SystemSaveData::Close() {
|
||||
|
@ -481,14 +481,14 @@ namespace ams::settings::impl {
|
|||
AMS_ASSERT(offset >= 0);
|
||||
AMS_ASSERT(buf != nullptr);
|
||||
|
||||
return GetLazyFileAccessor().Read(offset, buf, size);
|
||||
R_RETURN(GetLazyFileAccessor().Read(offset, buf, size));
|
||||
}
|
||||
|
||||
Result SystemSaveData::Write(s64 offset, const void *buf, size_t size) {
|
||||
AMS_ASSERT(offset >= 0);
|
||||
AMS_ASSERT(buf != nullptr);
|
||||
|
||||
return GetLazyFileAccessor().Write(offset, buf, size);
|
||||
R_RETURN(GetLazyFileAccessor().Write(offset, buf, size));
|
||||
}
|
||||
|
||||
Result SystemSaveData::Flush() {
|
||||
|
@ -497,7 +497,7 @@ namespace ams::settings::impl {
|
|||
}
|
||||
|
||||
Result SystemSaveData::SetFileSize(s64 size) {
|
||||
return GetLazyFileAccessor().SetFileSize(size);
|
||||
R_RETURN(GetLazyFileAccessor().SetFileSize(size));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue