Skip to content

Commit

Permalink
tweak: added os guards for the windows ci build
Browse files Browse the repository at this point in the history
  • Loading branch information
fj committed Oct 30, 2024
1 parent d264a18 commit 12211fa
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,37 @@ use std::ffi::c_void;
#[cfg(unix)]
use libc::{mlock, munlock, sysconf, _SC_PAGESIZE};

#[cfg(windows)]
use windows_sys::Win32::System::SystemInformation::{GetSystemInfo, SYSTEM_INFO};

#[cfg(target_os = "linux")]
use libc::{madvise, MADV_DODUMP, MADV_DONTDUMP};

pub use zeroize;
pub use zeroize::{Zeroize, ZeroizeOnDrop};

#[cfg(unix)]
static mut PAGE_SIZE: LazyCell<i64> = LazyCell::new(|| {
let page_size = unsafe { sysconf(_SC_PAGESIZE) };
if page_size == -1 {
panic!("Error getting page size: \n {}", errno())
{
let page_size = unsafe { sysconf(_SC_PAGESIZE) };
if page_size == -1 {
panic!("Error getting page size: \n {}", errno())
}
page_size
}
});

#[allow(dead_code)]
#[cfg(windows)]
static mut PAGE_SIZE: LazyCell<i64> = LazyCell::new(|| {
{
unsafe {
// Initialize SYSTEM_INFO using zeroed memory
let mut system_info: SYSTEM_INFO = std::mem::zeroed();
GetSystemInfo(&mut system_info);
system_info.dwPageSize as i64
}
}
page_size
});

/// Wrapper for the inner secret. Can be exposed by [`ExposeSecret`]
Expand Down

0 comments on commit 12211fa

Please sign in to comment.