fix stack alignement

- adjust align() in RawBlockTraits impl for Stack
- ensure ptr is always aligned in RawBlock::allock
This commit is contained in:
Bennet Bleßmann
2024-07-06 16:21:20 +02:00
parent 8e53d12776
commit fee7ba58b0
2 changed files with 6 additions and 4 deletions

View File

@@ -15,7 +15,9 @@ impl RawBlockTraits for Stack {
#[inline]
fn align() -> usize {
mem::align_of::<HeapCellValue>()
mem::align_of::<OrFrame>()
.max(mem::align_of::<AndFrame>())
.max(mem::align_of::<HeapCellValue>())
}
}
@@ -281,7 +283,6 @@ mod tests {
use crate::machine::mock_wam::*;
#[test]
#[cfg_attr(miri, ignore = "blocked on stack.rs UB")]
fn stack_tests() {
let mut wam = MockWAM::new();

View File

@@ -96,9 +96,10 @@ impl<T: RawBlockTraits> RawBlock<T> {
}
pub unsafe fn alloc(&self, size: usize) -> *mut u8 {
if self.free_space() >= size {
let aligned_size = size.next_multiple_of(size);
if self.free_space() >= aligned_size {
let ptr = *self.ptr.get();
*self.ptr.get() = ptr.add(size) as *mut _;
*self.ptr.get() = ptr.add(aligned_size) as *mut _;
ptr
} else {
ptr::null_mut()