From b5936479f1c31f4cafd3725e77a38ac39435ee37 Mon Sep 17 00:00:00 2001 From: Mahmut Bulut Date: Fri, 13 Dec 2019 20:51:13 +0100 Subject: [PATCH] Fix pointer width, goddamit --- bastion-executor/Cargo.toml | 1 + bastion-executor/src/placement.rs | 33 ++++++++++++++++++------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/bastion-executor/Cargo.toml b/bastion-executor/Cargo.toml index 37e3ace6..ff00822a 100644 --- a/bastion-executor/Cargo.toml +++ b/bastion-executor/Cargo.toml @@ -42,6 +42,7 @@ jemallocator = { version = "^0.3", optional = true, default-features = false } [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "^0.3.8", features = ["basetsd"] } +#winapi = "^0.2.8" kernel32-sys = "^0.2.2" [dev-dependencies] diff --git a/bastion-executor/src/placement.rs b/bastion-executor/src/placement.rs index 8aec14ce..a2105c35 100644 --- a/bastion-executor/src/placement.rs +++ b/bastion-executor/src/placement.rs @@ -214,26 +214,31 @@ mod windows { // Set core affinity for current thread. unsafe { - SetThreadAffinityMask(GetCurrentThread(), mask as DWORD_PTR); + #[cfg(target_pointer_width = "32")] + SetThreadAffinityMask(GetCurrentThread(), mask as DWORD_PTR as u32); + #[cfg(target_pointer_width = "64")] + SetThreadAffinityMask(GetCurrentThread(), mask as DWORD_PTR as u64); } } fn get_affinity_mask() -> Option { - #[cfg(target_pointer_width = "64")] - let mut process_mask: u64 = 0; - #[cfg(target_pointer_width = "32")] - let mut process_mask: u32 = 0; - #[cfg(target_pointer_width = "64")] - let mut system_mask: u64 = 0; - #[cfg(target_pointer_width = "32")] - let mut system_mask: u32 = 0; + let mut process_mask: usize = 0; + let mut system_mask: usize = 0; let res = unsafe { - GetProcessAffinityMask( - GetCurrentProcess(), - &mut process_mask as PDWORD_PTR, - &mut system_mask as PDWORD_PTR, - ) + // Good luck with other architectures. + // Since Windows is already like a cartoon: + // Tinky winky, dipsy, laa laa, po. + #[cfg(target_pointer_width = "32")] + let mut pm = process_mask as u32; + #[cfg(target_pointer_width = "64")] + let mut pm = process_mask as u64; + #[cfg(target_pointer_width = "32")] + let mut sm = system_mask as u32; + #[cfg(target_pointer_width = "64")] + let mut sm = system_mask as u64; + + GetProcessAffinityMask(GetCurrentProcess(), &mut pm, &mut sm) }; // Successfully retrieved affinity mask