diff options
| author | Markus Pettersson <markus.pettersson@mullvad.net> | 2025-02-21 14:52:47 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2025-03-05 23:32:30 +0100 |
| commit | aefca5230e86aaf03fc3b1daa1c72f90f32fb693 (patch) | |
| tree | 6e312e51cd1f43df0cf4806f08d75c209c942585 /windows-installer/src | |
| parent | c3c0a0625b90783b96b769de916232bcdba3cf14 (diff) | |
| download | mullvadvpn-aefca5230e86aaf03fc3b1daa1c72f90f32fb693.tar.xz mullvadvpn-aefca5230e86aaf03fc3b1daa1c72f90f32fb693.zip | |
Remove explicit `unsafe` from `windows-installer`
Diffstat (limited to 'windows-installer/src')
| -rw-r--r-- | windows-installer/src/windows.rs | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/windows-installer/src/windows.rs b/windows-installer/src/windows.rs index 1b74b074b3..07e4587728 100644 --- a/windows-installer/src/windows.rs +++ b/windows-installer/src/windows.rs @@ -7,7 +7,7 @@ //! * `WIN_ARM64_INSTALLER` - a path to the ARM64 Windows installer use anyhow::{bail, Context}; use std::{ - ffi::{c_ushort, OsStr}, + ffi::OsStr, io::{self, Write}, num::NonZero, process::{Command, ExitStatus}, @@ -16,11 +16,7 @@ use std::{ use tempfile::TempPath; use windows_sys::{ w, - Win32::System::{ - LibraryLoader::{FindResourceW, LoadResource, LockResource, SizeofResource}, - SystemInformation::{IMAGE_FILE_MACHINE_AMD64, IMAGE_FILE_MACHINE_ARM64}, - Threading::IsWow64Process2, - }, + Win32::System::LibraryLoader::{FindResourceW, LoadResource, LockResource, SizeofResource}, }; /// Import resource constants from `resource.rs`. This is automatically generated by the build @@ -124,22 +120,14 @@ enum Architecture { /// Return native architecture (ignoring WOW64) fn get_native_arch() -> anyhow::Result<Architecture> { - let mut running_arch: c_ushort = 0; - let mut native_arch: c_ushort = 0; - - // SAFETY: Trivially safe, since we provide the required arguments. `hprocess == 0` is - // undocumented but refers to the current process. - let result = unsafe { IsWow64Process2(0, &mut running_arch, &mut native_arch) }; - if result == 0 { - bail!( - "Failed to get native architecture: {}", - io::Error::last_os_error() - ); - } + let Some(arch) = + talpid_platform_metadata::get_native_arch().context("Failed to get native architecture")? + else { + bail!("Unable to detect native architecture (most likely unsupported)"); + }; - match native_arch { - IMAGE_FILE_MACHINE_AMD64 => Ok(Architecture::X64), - IMAGE_FILE_MACHINE_ARM64 => Ok(Architecture::Arm64), - other => bail!("unsupported architecture: {other}"), + match arch { + talpid_platform_metadata::Architecture::X86 => Ok(Architecture::X64), + talpid_platform_metadata::Architecture::Arm64 => Ok(Architecture::Arm64), } } |
