Read a 64-bit little-endian value from bytes at the given offset
(bytes: &[u8], offset: usize)
| 119 | let slice = bytes |
| 120 | .get(offset..end) |
| 121 | .ok_or_else(|| VmError::Other("ELF read out of bounds".to_owned()))?; |
| 122 | Ok(u64::from_le_bytes([ |
| 123 | slice[0], slice[1], slice[2], slice[3], slice[4], slice[5], slice[6], slice[7], |
| 124 | ])) |
| 125 | } |
| 126 | |
| 127 | /// Align a value up to the nearest multiple of alignment |
| 128 | pub fn align_up(value: u64, alignment: u64) -> u64 { |
| 129 | let alignment = alignment.max(1); |
| 130 | (value + alignment - 1) & !(alignment - 1) |
| 131 | } |