Remove explicit unsafe
from windows-installer
This commit is contained in:
parent
c3c0a0625b
commit
aefca5230e
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -5886,6 +5886,7 @@ version = "0.0.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"mullvad-version",
|
||||
"talpid-platform-metadata",
|
||||
"tempfile",
|
||||
"windows-sys 0.52.0",
|
||||
"winres",
|
||||
|
@ -11,9 +11,10 @@ rust-version.workspace = true
|
||||
workspace = true
|
||||
|
||||
[target.'cfg(all(target_os = "windows", target_arch = "x86_64"))'.dependencies]
|
||||
windows-sys = { version = "0.52.0", features = ["Win32_System", "Win32_System_LibraryLoader", "Win32_System_SystemInformation", "Win32_System_Threading"] }
|
||||
tempfile = "3.10"
|
||||
anyhow.workspace = true
|
||||
talpid-platform-metadata = { path = "../talpid-platform-metadata" }
|
||||
tempfile = "3.10"
|
||||
windows-sys = { version = "0.52.0", features = ["Win32_System", "Win32_System_LibraryLoader", "Win32_System_SystemInformation", "Win32_System_Threading"] }
|
||||
|
||||
[build-dependencies]
|
||||
winres = "0.1"
|
||||
|
@ -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;
|
||||
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)");
|
||||
};
|
||||
|
||||
// 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()
|
||||
);
|
||||
}
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user