Skip to content

Commit

Permalink
Fix pointer width, goddamit
Browse files Browse the repository at this point in the history
  • Loading branch information
vertexclique committed Dec 13, 2019
1 parent fd9b033 commit b593647
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions bastion-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
33 changes: 19 additions & 14 deletions bastion-executor/src/placement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64> {
#[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
Expand Down

0 comments on commit b593647

Please sign in to comment.