wiggle: automate borrow checking, explicitly passing borrow checker throughout

This commit is contained in:
Pat Hickey
2020-05-18 11:45:12 -07:00
parent e229fbc79c
commit 52e8300f01
14 changed files with 313 additions and 191 deletions

View File

@@ -1,5 +1,5 @@
use proptest::prelude::*;
use wiggle::{GuestMemory, GuestPtr};
use wiggle::{BorrowChecker, GuestMemory, GuestPtr};
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
wiggle::from_witx!({
@@ -128,30 +128,32 @@ impl PointersAndEnumsExercise {
pub fn test(&self) {
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
host_memory
.ptr(self.input2_loc.ptr)
.ptr(&bc, self.input2_loc.ptr)
.write(self.input2)
.expect("input2 ref_mut");
host_memory
.ptr(self.input3_loc.ptr)
.ptr(&bc, self.input3_loc.ptr)
.write(self.input3)
.expect("input3 ref_mut");
host_memory
.ptr(self.input4_loc.ptr)
.ptr(&bc, self.input4_loc.ptr)
.write(self.input4)
.expect("input4 ref_mut");
host_memory
.ptr(self.input4_ptr_loc.ptr)
.ptr(&bc, self.input4_ptr_loc.ptr)
.write(self.input4_loc.ptr)
.expect("input4 ptr ref_mut");
let e = pointers::pointers_and_enums(
&ctx,
&host_memory,
&bc,
self.input1.into(),
self.input2_loc.ptr as i32,
self.input3_loc.ptr as i32,
@@ -161,7 +163,7 @@ impl PointersAndEnumsExercise {
// Implementation of pointers_and_enums writes input3 to the input2_loc:
let written_to_input2_loc: i32 = host_memory
.ptr(self.input2_loc.ptr)
.ptr(&bc, self.input2_loc.ptr)
.read()
.expect("input2 ref");
@@ -173,7 +175,7 @@ impl PointersAndEnumsExercise {
// Implementation of pointers_and_enums writes input2_loc to input4_ptr_loc:
let written_to_input4_ptr: u32 = host_memory
.ptr(self.input4_ptr_loc.ptr)
.ptr(&bc, self.input4_ptr_loc.ptr)
.read()
.expect("input4_ptr_loc ref");