1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#[cfg(windows)]
extern crate kernel32;
#[cfg(windows)]
extern crate winapi;
mod hugepage;
pub use self::hugepage::*;
#[cfg(any(unix, windows))]
#[cfg_attr(feature = "cargo-clippy", allow(inline_always))]
#[inline(always)]
#[cfg(feature = "nightly")]
pub fn pagesize() -> usize {
*PAGESIZE
}
#[cfg(any(unix, windows))]
#[cfg_attr(feature = "cargo-clippy", allow(inline_always))]
#[inline(always)]
#[cfg(not(feature = "nightly"))]
pub fn pagesize() -> usize {
priv_pagesize()
}
#[cfg(feature = "nightly")]
#[cfg(any(unix, windows))]
lazy_static!{ static ref PAGESIZE: usize = priv_pagesize(); }
#[cfg(unix)]
fn priv_pagesize() -> usize {
::raw::sysconf(::raw::SysconfVariable::ScPagesize).expect("sysconf(_SC_PAGESIZE) failed, but _SC_PAGESIZE is required by POSIX 1003.1") as usize
}
#[cfg(windows)]
fn priv_pagesize() -> usize {
use self::kernel32::GetSystemInfo;
use self::winapi::SYSTEM_INFO;
use core::mem::uninitialized;
unsafe {
let mut info = uninitialized::<SYSTEM_INFO>();
GetSystemInfo(&mut info);
info.dwPageSize as usize
}
}