|
25 | 25 | Storage::FileSystem::{ |
26 | 26 | FILE_FLAG_BACKUP_SEMANTICS, INVALID_SET_FILE_POINTER, SetFilePointer, SetFileTime, |
27 | 27 | }, |
| 28 | + System::SystemInformation::{GetSystemInfo, SYSTEM_INFO}, |
28 | 29 | }, |
29 | 30 | }; |
30 | 31 |
|
@@ -132,6 +133,48 @@ pub fn cpu_count() -> usize { |
132 | 133 | 1 |
133 | 134 | } |
134 | 135 |
|
| 136 | +#[cfg(unix)] |
| 137 | +pub fn page_size() -> usize { |
| 138 | + rustix::param::page_size() |
| 139 | +} |
| 140 | + |
| 141 | +#[cfg(target_arch = "wasm32")] |
| 142 | +pub const fn page_size() -> usize { |
| 143 | + // WebAssembly's page size is a constant defined by the spec. |
| 144 | + 1024 * 64 |
| 145 | +} |
| 146 | + |
| 147 | +#[cfg(windows)] |
| 148 | +pub fn page_size() -> usize { |
| 149 | + let info = SYSTEM_INFO::default(); |
| 150 | + unsafe { |
| 151 | + GetSystemInfo(&mut info); |
| 152 | + } |
| 153 | + info.dwPageSize as _ |
| 154 | +} |
| 155 | + |
| 156 | +#[cfg(unix)] |
| 157 | +pub fn alloc_granularity() -> usize { |
| 158 | + // On Unix-likes, the page size is the smallest allocation unit rather than a separate concept |
| 159 | + // of allocation granularity. |
| 160 | + page_size() |
| 161 | +} |
| 162 | + |
| 163 | +#[cfg(target_arch = "wasm32")] |
| 164 | +pub const fn alloc_granularity() -> usize { |
| 165 | + // Like Unix, WebAssembly doesn't separate page size and alloc granularity. |
| 166 | + page_size() |
| 167 | +} |
| 168 | + |
| 169 | +#[cfg(windows)] |
| 170 | +pub fn page_size() -> usize { |
| 171 | + let info = SYSTEM_INFO::default(); |
| 172 | + unsafe { |
| 173 | + GetSystemInfo(&mut info); |
| 174 | + } |
| 175 | + info.dwAllocationGranularity as _ |
| 176 | +} |
| 177 | + |
135 | 178 | pub fn device_encoding(_fd: i32) -> Option<String> { |
136 | 179 | #[cfg(any( |
137 | 180 | target_os = "android", |
|
0 commit comments