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 = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"mullvad-version",
|
"mullvad-version",
|
||||||
|
"talpid-platform-metadata",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
"winres",
|
"winres",
|
||||||
|
@ -11,9 +11,10 @@ rust-version.workspace = true
|
|||||||
workspace = true
|
workspace = true
|
||||||
|
|
||||||
[target.'cfg(all(target_os = "windows", target_arch = "x86_64"))'.dependencies]
|
[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
|
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]
|
[build-dependencies]
|
||||||
winres = "0.1"
|
winres = "0.1"
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
//! * `WIN_ARM64_INSTALLER` - a path to the ARM64 Windows installer
|
//! * `WIN_ARM64_INSTALLER` - a path to the ARM64 Windows installer
|
||||||
use anyhow::{bail, Context};
|
use anyhow::{bail, Context};
|
||||||
use std::{
|
use std::{
|
||||||
ffi::{c_ushort, OsStr},
|
ffi::OsStr,
|
||||||
io::{self, Write},
|
io::{self, Write},
|
||||||
num::NonZero,
|
num::NonZero,
|
||||||
process::{Command, ExitStatus},
|
process::{Command, ExitStatus},
|
||||||
@ -16,11 +16,7 @@ use std::{
|
|||||||
use tempfile::TempPath;
|
use tempfile::TempPath;
|
||||||
use windows_sys::{
|
use windows_sys::{
|
||||||
w,
|
w,
|
||||||
Win32::System::{
|
Win32::System::LibraryLoader::{FindResourceW, LoadResource, LockResource, SizeofResource},
|
||||||
LibraryLoader::{FindResourceW, LoadResource, LockResource, SizeofResource},
|
|
||||||
SystemInformation::{IMAGE_FILE_MACHINE_AMD64, IMAGE_FILE_MACHINE_ARM64},
|
|
||||||
Threading::IsWow64Process2,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Import resource constants from `resource.rs`. This is automatically generated by the build
|
/// Import resource constants from `resource.rs`. This is automatically generated by the build
|
||||||
@ -124,22 +120,14 @@ enum Architecture {
|
|||||||
|
|
||||||
/// Return native architecture (ignoring WOW64)
|
/// Return native architecture (ignoring WOW64)
|
||||||
fn get_native_arch() -> anyhow::Result<Architecture> {
|
fn get_native_arch() -> anyhow::Result<Architecture> {
|
||||||
let mut running_arch: c_ushort = 0;
|
let Some(arch) =
|
||||||
let mut native_arch: c_ushort = 0;
|
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
|
match arch {
|
||||||
// undocumented but refers to the current process.
|
talpid_platform_metadata::Architecture::X86 => Ok(Architecture::X64),
|
||||||
let result = unsafe { IsWow64Process2(0, &mut running_arch, &mut native_arch) };
|
talpid_platform_metadata::Architecture::Arm64 => Ok(Architecture::Arm64),
|
||||||
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}"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user