|
12 | 12 |
|
13 | 13 | use std::io; |
14 | 14 | use std::os::unix::io::AsRawFd; |
15 | | -use std::ptr::null_mut; |
| 15 | +use std::ptr::{null_mut, NonNull}; |
16 | 16 | use std::result; |
17 | 17 |
|
18 | 18 | use crate::bitmap::{Bitmap, BS}; |
@@ -57,7 +57,7 @@ pub struct MmapRegionBuilder<B = ()> { |
57 | 57 | prot: i32, |
58 | 58 | flags: i32, |
59 | 59 | file_offset: Option<FileOffset>, |
60 | | - raw_ptr: Option<*mut u8>, |
| 60 | + raw_ptr: Option<NonNull<u8>>, |
61 | 61 | hugetlbfs: Option<bool>, |
62 | 62 | bitmap: B, |
63 | 63 | } |
@@ -119,7 +119,7 @@ impl<B: Bitmap> MmapRegionBuilder<B> { |
119 | 119 | /// To use this safely, the caller must guarantee that `raw_addr` and `self.size` define a |
120 | 120 | /// region within a valid mapping that is already present in the process. |
121 | 121 | pub unsafe fn with_raw_mmap_pointer(mut self, raw_ptr: *mut u8) -> Self { |
122 | | - self.raw_ptr = Some(raw_ptr); |
| 122 | + self.raw_ptr = Some(NonNull::new_unchecked(raw_ptr)); |
123 | 123 | self |
124 | 124 | } |
125 | 125 |
|
@@ -189,7 +189,7 @@ impl<B: Bitmap> MmapRegionBuilder<B> { |
189 | 189 | // SAFETY: Safe because this call just returns the page size and doesn't have any side |
190 | 190 | // effects. |
191 | 191 | let page_size = unsafe { libc::sysconf(libc::_SC_PAGESIZE) } as usize; |
192 | | - let addr = self.raw_ptr.unwrap(); |
| 192 | + let addr = self.raw_ptr.unwrap().as_ptr(); |
193 | 193 |
|
194 | 194 | // Check that the pointer to the mapping is page-aligned. |
195 | 195 | if (addr as usize) & (page_size - 1) != 0 { |
|
0 commit comments