From 12211fa573ebe103a8602c7fcfda1da3f2b1b1c5 Mon Sep 17 00:00:00 2001 From: fj Date: Wed, 30 Oct 2024 22:29:16 +0300 Subject: [PATCH] tweak: added os guards for the windows ci build --- src/lib.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 013e68d..bf7c860 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 = 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 = 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`]