mirror of
https://github.com/urbit/ares.git
synced 2024-12-22 21:01:29 +03:00
UB fixes (#287)
Validating Cell construction with NockStack Use the active fork, memmap2
This commit is contained in:
parent
f9915a75ea
commit
92fa0f864b
9
Cargo.lock
generated
9
Cargo.lock
generated
@ -770,13 +770,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "memmap"
|
||||
version = "0.7.0"
|
||||
name = "memmap2"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b"
|
||||
checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1255,7 +1254,7 @@ dependencies = [
|
||||
"json",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"memmap",
|
||||
"memmap2",
|
||||
"murmur3",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
|
@ -212,6 +212,7 @@ mod tests {
|
||||
use rand::prelude::*;
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(miri, ignore)]
|
||||
fn test_fast_divide_small() {
|
||||
let mut rng = StdRng::seed_from_u64(1);
|
||||
for _ in 0..1000000 {
|
||||
@ -227,6 +228,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(miri, ignore)]
|
||||
fn test_fast_divide_normalized() {
|
||||
let mut rng = StdRng::seed_from_u64(1);
|
||||
for _ in 0..1000000 {
|
||||
|
@ -21,7 +21,7 @@ intmap = "1.1.0"
|
||||
json = "0.12.4"
|
||||
lazy_static = "1.4.0"
|
||||
libc = "0.2.126"
|
||||
memmap = "0.7.0"
|
||||
memmap2 = "^0.9.5"
|
||||
num-derive = "0.3"
|
||||
num-traits = "0.2"
|
||||
rand = "0.8.5"
|
||||
|
@ -4,7 +4,7 @@ use crate::{assert_acyclic, assert_no_forwarding_pointers, assert_no_junior_poin
|
||||
use assert_no_alloc::permit_alloc;
|
||||
use either::Either::{self, Left, Right};
|
||||
use ibig::Stack;
|
||||
use memmap::MmapMut;
|
||||
use memmap2::MmapMut;
|
||||
use std::alloc::Layout;
|
||||
use std::panic::panic_any;
|
||||
use std::ptr::copy_nonoverlapping;
|
||||
@ -196,8 +196,8 @@ impl NockStack {
|
||||
return Err(NewStackError::StackTooSmall);
|
||||
}
|
||||
let free = size - (top_slots + RESERVED);
|
||||
let memory = MmapMut::map_anon(size << 3)?;
|
||||
let start = memory.as_ptr() as *const u64;
|
||||
let mut memory = MmapMut::map_anon(size << 3)?;
|
||||
let start = memory.as_mut_ptr() as *mut u64;
|
||||
// Here, frame_pointer < alloc_pointer, so the initial frame is West
|
||||
let frame_pointer = unsafe { start.add(RESERVED + top_slots) } as *mut u64;
|
||||
let stack_pointer = frame_pointer;
|
||||
@ -213,7 +213,7 @@ impl NockStack {
|
||||
);
|
||||
Ok((
|
||||
NockStack {
|
||||
start,
|
||||
start: start as *const u64,
|
||||
size,
|
||||
frame_pointer,
|
||||
stack_pointer,
|
||||
|
@ -662,6 +662,7 @@ impl Cell {
|
||||
|
||||
pub unsafe fn new_raw_mut<A: NounAllocator>(allocator: &mut A) -> (Cell, *mut CellMemory) {
|
||||
let memory = allocator.alloc_cell();
|
||||
assert!(memory as usize % std::mem::align_of::<CellMemory>() == 0, "Memory is not aligned, {} {}", memory as usize, std::mem::align_of::<CellMemory>());
|
||||
(*memory).metadata = 0;
|
||||
(Self::from_raw_pointer(memory), memory)
|
||||
}
|
||||
|
@ -715,4 +715,11 @@ mod tests {
|
||||
println!("got expected error: {:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cell_construction() {
|
||||
let mut stack = setup_stack();
|
||||
let (cell, cell_mem_ptr) = unsafe { Cell::new_raw_mut(&mut stack) };
|
||||
unsafe { assert!(cell_mem_ptr as *const CellMemory == cell.to_raw_pointer()) };
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user