Skip to content

Commit

Permalink
Make sure vmoffset are aligned to pointer size (for #4059)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Aug 21, 2023
1 parent 0ea42da commit 4bfd562
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/types/src/vmoffsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
};
use more_asserts::assert_lt;
use std::convert::TryFrom;
use std::mem::size_of;

/// An index type for builtin functions.
#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -280,9 +281,11 @@ impl VMOffsets {

fn precompute(&mut self) {
/// Offset base by num_items items of size item_size, panicking on overflow
/// Also, will align the value on pointer size boundary,
/// to avoid misalignement issue
fn offset_by(base: u32, num_items: u32, item_size: u32) -> u32 {
base.checked_add(num_items.checked_mul(item_size).unwrap())
.unwrap()
align(base.checked_add(num_items.checked_mul(item_size).unwrap())
.unwrap(), size_of::<&u32>() as u32)
}

self.vmctx_signature_ids_begin = 0;
Expand Down

0 comments on commit 4bfd562

Please sign in to comment.