Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update windows datatypes #129

Merged
merged 3 commits into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bastion-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ allocator-suite = { version = "^0.1", optional = true, default-features = false
jemallocator = { version = "^0.3", optional = true, default-features = false }

[target.'cfg(target_os = "windows")'.dependencies]
winapi = "^0.2.8"
winapi = { version = "^0.3.8", features = ["basetsd"] }
kernel32-sys = "^0.2.2"

[dev-dependencies]
Expand Down
29 changes: 23 additions & 6 deletions bastion-executor/src/placement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ mod windows {
use kernel32::{
GetCurrentProcess, GetCurrentThread, GetProcessAffinityMask, SetThreadAffinityMask,
};
use winapi::basetsd::{DWORD_PTR, PDWORD_PTR};
use winapi::shared::basetsd::{DWORD32, DWORD64, PDWORD32, PDWORD64};

use super::CoreId;

Expand Down Expand Up @@ -214,7 +214,10 @@ mod windows {

// Set core affinity for current thread.
unsafe {
SetThreadAffinityMask(GetCurrentThread(), mask as DWORD_PTR);
#[cfg(target_pointer_width = "32")]
SetThreadAffinityMask(GetCurrentThread(), mask as DWORD32);
#[cfg(target_pointer_width = "64")]
SetThreadAffinityMask(GetCurrentThread(), mask as DWORD64);
}
}

Expand All @@ -229,11 +232,25 @@ mod windows {
let mut system_mask: u32 = 0;

let res = unsafe {
GetProcessAffinityMask(
// Good luck with other architectures.
// Since Windows is already like a cartoon:
// Tinky winky, dipsy, laa laa, po.

#[cfg(target_pointer_width = "32")]
let r = GetProcessAffinityMask(
GetCurrentProcess(),
&mut process_mask as PDWORD_PTR,
&mut system_mask as PDWORD_PTR,
)
&mut process_mask as PDWORD32,
&mut system_mask as PDWORD32,
);

#[cfg(target_pointer_width = "64")]
let r = GetProcessAffinityMask(
GetCurrentProcess(),
&mut process_mask as PDWORD64,
&mut system_mask as PDWORD64,
);

r
};

// Successfully retrieved affinity mask
Expand Down