os: remove ManagedHandle, refactor to use NativeHandle typename

This commit is contained in:
Michael Scire
2021-10-04 12:33:09 -07:00
parent a774833790
commit 6f76066d24
71 changed files with 473 additions and 397 deletions

View File

@@ -469,7 +469,10 @@ namespace ams::mitm::sysupdater {
return ResultSuccess();
}
Result SystemUpdateService::SetupUpdateImpl(os::ManagedHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id) {
Result SystemUpdateService::SetupUpdateImpl(os::NativeHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id) {
/* Ensure the transfer memory handle is closed, if we exit before creating the management object. */
auto handle_guard = SCOPE_GUARD { os::CloseNativeHandle(transfer_memory); };
/* Ensure we don't already have an update set up. */
R_UNLESS(!this->setup_update, ns::ResultCardUpdateAlreadySetup());
@@ -481,6 +484,7 @@ namespace ams::mitm::sysupdater {
}
/* Initialize the update task. */
handle_guard.Cancel();
R_TRY(InitializeUpdateTask(transfer_memory, transfer_memory_size, path, exfat, firmware_variation_id));
/* The update is now set up. */
@@ -488,10 +492,10 @@ namespace ams::mitm::sysupdater {
return ResultSuccess();
}
Result SystemUpdateService::InitializeUpdateTask(os::ManagedHandle &transfer_memory_handle, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id) {
Result SystemUpdateService::InitializeUpdateTask(os::NativeHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id) {
/* Map the transfer memory. */
const size_t tmem_buffer_size = static_cast<size_t>(transfer_memory_size);
this->update_transfer_memory.emplace(tmem_buffer_size, transfer_memory_handle.Get(), true);
this->update_transfer_memory.emplace(tmem_buffer_size, transfer_memory, true);
void *tmem_buffer;
R_TRY(this->update_transfer_memory->Map(std::addressof(tmem_buffer), os::MemoryPermission_None));
@@ -500,9 +504,6 @@ namespace ams::mitm::sysupdater {
this->update_transfer_memory = util::nullopt;
};
/* Now that the memory is mapped, the input handle is managed and can be released. */
transfer_memory_handle.Detach();
/* Adjust the package root. */
ncm::Path package_root;
R_TRY(FormatUserPackagePath(std::addressof(package_root), path));

View File

@@ -64,8 +64,8 @@ namespace ams::mitm::sysupdater {
public:
constexpr SystemUpdateService() : apply_manager(), update_task(), update_transfer_memory(), setup_update(false), requested_update(false) { /* ... */ }
private:
Result SetupUpdateImpl(os::ManagedHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id);
Result InitializeUpdateTask(os::ManagedHandle &transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id);
Result SetupUpdateImpl(os::NativeHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id);
Result InitializeUpdateTask(os::NativeHandle transfer_memory, u64 transfer_memory_size, const ncm::Path &path, bool exfat, ncm::FirmwareVariationId firmware_variation_id);
public:
Result GetUpdateInformation(sf::Out<UpdateInformation> out, const ncm::Path &path);
Result ValidateUpdate(sf::Out<Result> out_validate_result, sf::Out<Result> out_validate_exfat_result, sf::Out<UpdateValidationInfo> out_validate_info, const ncm::Path &path);