(&mut self, size: usize, align: u64)
| 70 | } |
| 71 | |
| 72 | pub(crate) fn allocate(&mut self, size: usize, align: u64) -> io::Result<*mut u8> { |
| 73 | let align = usize::try_from(align).expect("alignment too big"); |
| 74 | if self.position % align != 0 { |
| 75 | self.position += align - self.position % align; |
| 76 | debug_assert!(self.position % align == 0); |
| 77 | } |
| 78 | |
| 79 | if size <= self.current.len - self.position { |
| 80 | // TODO: Ensure overflow is not possible. |
| 81 | let ptr = unsafe { self.current.ptr.add(self.position) }; |
| 82 | self.position += size; |
| 83 | return Ok(ptr); |
| 84 | } |
| 85 | |
| 86 | self.finish_current(); |
| 87 | |
| 88 | // TODO: Allocate more at a time. |
| 89 | self.current = PtrLen::with_size(size)?; |
| 90 | self.position = size; |
| 91 | |
| 92 | Ok(self.current.ptr) |
| 93 | } |
| 94 | |
| 95 | /// Set all memory allocated in this `Memory` up to now as readable and executable. |
| 96 | pub(crate) fn set_readable_and_executable( |
no test coverage detected