fix stack alignement
- adjust align() in RawBlockTraits impl for Stack - ensure ptr is always aligned in RawBlock::allock
This commit is contained in:
@@ -15,7 +15,9 @@ impl RawBlockTraits for Stack {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn align() -> usize {
|
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::*;
|
use crate::machine::mock_wam::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg_attr(miri, ignore = "blocked on stack.rs UB")]
|
|
||||||
fn stack_tests() {
|
fn stack_tests() {
|
||||||
let mut wam = MockWAM::new();
|
let mut wam = MockWAM::new();
|
||||||
|
|
||||||
|
|||||||
@@ -96,9 +96,10 @@ impl<T: RawBlockTraits> RawBlock<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn alloc(&self, size: usize) -> *mut u8 {
|
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();
|
let ptr = *self.ptr.get();
|
||||||
*self.ptr.get() = ptr.add(size) as *mut _;
|
*self.ptr.get() = ptr.add(aligned_size) as *mut _;
|
||||||
ptr
|
ptr
|
||||||
} else {
|
} else {
|
||||||
ptr::null_mut()
|
ptr::null_mut()
|
||||||
|
|||||||
Reference in New Issue
Block a user