From 44a388bd8880166d84c8d6282956517258f11460 Mon Sep 17 00:00:00 2001 From: Mahmut Bulut Date: Fri, 13 Dec 2019 20:52:02 +0100 Subject: [PATCH] Remove old dependency --- bastion-executor/Cargo.toml | 1 - bastion-executor/src/placement.rs | 37 +++++++++++++++++++------------ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/bastion-executor/Cargo.toml b/bastion-executor/Cargo.toml index ff00822a..37e3ace6 100644 --- a/bastion-executor/Cargo.toml +++ b/bastion-executor/Cargo.toml @@ -42,7 +42,6 @@ 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 a2105c35..81277302 100644 --- a/bastion-executor/src/placement.rs +++ b/bastion-executor/src/placement.rs @@ -185,7 +185,7 @@ mod windows { use kernel32::{ GetCurrentProcess, GetCurrentThread, GetProcessAffinityMask, SetThreadAffinityMask, }; - use winapi::shared::basetsd::{DWORD_PTR, PDWORD_PTR}; + use winapi::shared::basetsd::{DWORD32, DWORD64, PDWORD32, PDWORD64}; use super::CoreId; @@ -214,31 +214,40 @@ mod windows { // Set core affinity for current thread. unsafe { - #[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); + SetThreadAffinityMask(GetCurrentThread(), mask as DWORD64); } } fn get_affinity_mask() -> Option { - let mut process_mask: usize = 0; - let mut system_mask: usize = 0; + #[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 res = unsafe { // 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; + let r = GetProcessAffinityMask( + GetCurrentProcess(), + &mut process_mask as PDWORD32, + &mut system_mask as PDWORD32, + ); + #[cfg(target_pointer_width = "64")] - let mut sm = system_mask as u64; + let r = GetProcessAffinityMask( + GetCurrentProcess(), + &mut process_mask as PDWORD64, + &mut system_mask as PDWORD64, + ); - GetProcessAffinityMask(GetCurrentProcess(), &mut pm, &mut sm) + r }; // Successfully retrieved affinity mask