|
1 | 1 | use std::alloc::{self, Layout};
|
2 | 2 | use std::sync;
|
3 | 3 |
|
4 |
| -use nix::sys::mman::ProtFlags; |
5 |
| - |
6 | 4 | use crate::helpers::ToU64;
|
7 | 5 |
|
8 | 6 | static ALLOCATOR: sync::Mutex<MachineAlloc> = sync::Mutex::new(MachineAlloc::empty());
|
@@ -219,53 +217,4 @@ impl MachineAlloc {
|
219 | 217 | alloc::dealloc(ptr, layout);
|
220 | 218 | }
|
221 | 219 | }
|
222 |
| - |
223 |
| - // Protection-related methods |
224 |
| - |
225 |
| - /// Protects all owned memory, preventing accesses. |
226 |
| - /// |
227 |
| - /// SAFETY: Accessing memory after this point will result in a segfault |
228 |
| - /// unless it is first unprotected. |
229 |
| - #[expect(dead_code)] |
230 |
| - pub unsafe fn prepare_ffi() -> Result<(), nix::errno::Errno> { |
231 |
| - let mut alloc = ALLOCATOR.lock().unwrap(); |
232 |
| - unsafe { |
233 |
| - alloc.mprotect(ProtFlags::PROT_NONE)?; |
234 |
| - } |
235 |
| - Ok(()) |
236 |
| - } |
237 |
| - |
238 |
| - /// Deprotects all owned memory by setting it to RW. Erroring here is very |
239 |
| - /// likely unrecoverable, so it may panic if applying those permissions |
240 |
| - /// fails. |
241 |
| - #[expect(dead_code)] |
242 |
| - pub fn unprep_ffi() { |
243 |
| - let mut alloc = ALLOCATOR.lock().unwrap(); |
244 |
| - let default_flags = ProtFlags::PROT_READ | ProtFlags::PROT_WRITE; |
245 |
| - unsafe { |
246 |
| - alloc.mprotect(default_flags).unwrap(); |
247 |
| - } |
248 |
| - } |
249 |
| - |
250 |
| - /// Applies `prot` to every page managed by the allocator. |
251 |
| - /// |
252 |
| - /// SAFETY: Accessing memory in violation of the protection flags will |
253 |
| - /// trigger a segfault. |
254 |
| - unsafe fn mprotect(&mut self, prot: ProtFlags) -> Result<(), nix::errno::Errno> { |
255 |
| - for &pg in &self.pages { |
256 |
| - unsafe { |
257 |
| - // We already know only non-null ptrs are pushed to self.pages |
258 |
| - let addr: std::ptr::NonNull<std::ffi::c_void> = |
259 |
| - std::ptr::NonNull::new_unchecked(pg.cast()); |
260 |
| - nix::sys::mman::mprotect(addr, self.page_size, prot)?; |
261 |
| - } |
262 |
| - } |
263 |
| - for &(hpg, size) in &self.huge_allocs { |
264 |
| - unsafe { |
265 |
| - let addr = std::ptr::NonNull::new_unchecked(hpg.cast()); |
266 |
| - nix::sys::mman::mprotect(addr, size, prot)?; |
267 |
| - } |
268 |
| - } |
269 |
| - Ok(()) |
270 |
| - } |
271 | 220 | }
|
0 commit comments