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!({
@@ -75,31 +75,35 @@ impl ReduceExcusesExcercise {
}
pub fn test(&self) {
let mut ctx = WasiCtx::new();
let mut host_memory = HostMemory::new();
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
// Populate memory with pointers to generated Excuse values
for (&excuse, ptr) in self.excuse_values.iter().zip(self.excuse_ptr_locs.iter()) {
host_memory
.ptr(ptr.ptr)
.ptr(&bc, ptr.ptr)
.write(excuse)
.expect("deref ptr mut to Excuse value");
}
// Populate the array with pointers to generated Excuse values
{
let array: GuestPtr<'_, [GuestPtr<types::Excuse>]> =
host_memory.ptr((self.array_ptr_loc.ptr, self.excuse_ptr_locs.len() as u32));
let array: GuestPtr<'_, [GuestPtr<types::Excuse>]> = host_memory.ptr(
&bc,
(self.array_ptr_loc.ptr, self.excuse_ptr_locs.len() as u32),
);
for (slot, ptr) in array.iter().zip(&self.excuse_ptr_locs) {
let slot = slot.expect("array should be in bounds");
slot.write(host_memory.ptr(ptr.ptr))
slot.write(host_memory.ptr(&bc, ptr.ptr))
.expect("should succeed in writing array");
}
}
let res = arrays::reduce_excuses(
&mut ctx,
&mut host_memory,
&ctx,
&host_memory,
&bc,
self.array_ptr_loc.ptr as i32,
self.excuse_ptr_locs.len() as i32,
self.return_ptr_loc.ptr as i32,
@@ -112,7 +116,7 @@ impl ReduceExcusesExcercise {
.last()
.expect("generated vec of excuses should be non-empty");
let given: types::Excuse = host_memory
.ptr(self.return_ptr_loc.ptr)
.ptr(&bc, self.return_ptr_loc.ptr)
.read()
.expect("deref ptr to returned value");
assert_eq!(expected, given, "reduce excuses return val");
@@ -165,28 +169,30 @@ impl PopulateExcusesExcercise {
pub fn test(&self) {
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
// Populate array with valid pointers to Excuse type in memory
let ptr = host_memory.ptr::<[GuestPtr<'_, types::Excuse>]>((
self.array_ptr_loc.ptr,
self.elements.len() as u32,
));
let ptr = host_memory.ptr::<[GuestPtr<'_, types::Excuse>]>(
&bc,
(self.array_ptr_loc.ptr, self.elements.len() as u32),
);
for (ptr, val) in ptr.iter().zip(&self.elements) {
ptr.expect("should be valid pointer")
.write(host_memory.ptr(val.ptr))
.write(host_memory.ptr(&bc, val.ptr))
.expect("failed to write value");
}
let res = arrays::populate_excuses(
&ctx,
&host_memory,
&bc,
self.array_ptr_loc.ptr as i32,
self.elements.len() as i32,
);
assert_eq!(res, types::Errno::Ok.into(), "populate excuses errno");
let arr: GuestPtr<'_, [GuestPtr<'_, types::Excuse>]> =
host_memory.ptr((self.array_ptr_loc.ptr, self.elements.len() as u32));
host_memory.ptr(&bc, (self.array_ptr_loc.ptr, self.elements.len() as u32));
for el in arr.iter() {
let ptr_to_ptr = el
.expect("valid ptr to ptr")

View File

@@ -1,5 +1,5 @@
use proptest::prelude::*;
use wiggle::GuestMemory;
use wiggle::{BorrowChecker, GuestMemory};
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
wiggle::from_witx!({
@@ -31,8 +31,9 @@ impl IntFloatExercise {
pub fn test(&self) {
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
let e = atoms::int_float_args(&ctx, &host_memory, self.an_int as i32, self.an_float);
let e = atoms::int_float_args(&ctx, &host_memory, &bc, self.an_int as i32, self.an_float);
assert_eq!(e, types::Errno::Ok.into(), "int_float_args error");
}
@@ -60,16 +61,18 @@ impl DoubleIntExercise {
pub fn test(&self) {
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
let e = atoms::double_int_return_float(
&ctx,
&host_memory,
&bc,
self.input as i32,
self.return_loc.ptr as i32,
);
let return_val = host_memory
.ptr::<types::AliasToFloat>(self.return_loc.ptr)
.ptr::<types::AliasToFloat>(&bc, self.return_loc.ptr)
.read()
.expect("failed to read return");
assert_eq!(e, types::Errno::Ok.into(), "errno");

View File

@@ -1,6 +1,6 @@
use proptest::prelude::*;
use std::convert::TryFrom;
use wiggle::{GuestMemory, GuestPtr};
use wiggle::{BorrowChecker, GuestMemory, GuestPtr};
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
wiggle::from_witx!({
@@ -65,16 +65,18 @@ impl ConfigureCarExercise {
pub fn test(&self) {
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
// Populate input ptr
host_memory
.ptr(self.other_config_by_ptr.ptr)
.ptr(&bc, self.other_config_by_ptr.ptr)
.write(self.other_config)
.expect("deref ptr mut to CarConfig");
let res = flags::configure_car(
&ctx,
&host_memory,
&bc,
self.old_config.into(),
self.other_config_by_ptr.ptr as i32,
self.return_ptr_loc.ptr as i32,
@@ -82,7 +84,7 @@ impl ConfigureCarExercise {
assert_eq!(res, types::Errno::Ok.into(), "configure car errno");
let res_config = host_memory
.ptr::<types::CarConfig>(self.return_ptr_loc.ptr)
.ptr::<types::CarConfig>(&bc, self.return_ptr_loc.ptr)
.read()
.expect("deref to CarConfig value");

View File

@@ -1,5 +1,5 @@
use proptest::prelude::*;
use wiggle::{GuestMemory, GuestType};
use wiggle::{BorrowChecker, GuestMemory, GuestType};
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
const FD_VAL: u32 = 123;
@@ -34,23 +34,24 @@ impl HandleExercise {
pub fn test(&self) {
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
let e = handle_examples::fd_create(&ctx, &host_memory, self.return_loc.ptr as i32);
let e = handle_examples::fd_create(&ctx, &host_memory, &bc, self.return_loc.ptr as i32);
assert_eq!(e, types::Errno::Ok.into(), "fd_create error");
let h_got: u32 = host_memory
.ptr(self.return_loc.ptr)
.ptr(&bc, self.return_loc.ptr)
.read()
.expect("return ref_mut");
assert_eq!(h_got, 123, "fd_create return val");
let e = handle_examples::fd_consume(&ctx, &host_memory, h_got as i32);
let e = handle_examples::fd_consume(&ctx, &host_memory, &bc, h_got as i32);
assert_eq!(e, types::Errno::Ok.into(), "fd_consume error");
let e = handle_examples::fd_consume(&ctx, &host_memory, h_got as i32 + 1);
let e = handle_examples::fd_consume(&ctx, &host_memory, &bc, h_got as i32 + 1);
assert_eq!(
e,

View File

@@ -1,6 +1,6 @@
use proptest::prelude::*;
use std::convert::TryFrom;
use wiggle::GuestMemory;
use wiggle::{BorrowChecker, GuestMemory};
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
wiggle::from_witx!({
@@ -46,17 +46,19 @@ impl CookieCutterExercise {
pub fn test(&self) {
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
let res = ints::cookie_cutter(
&ctx,
&host_memory,
&bc,
self.cookie.into(),
self.return_ptr_loc.ptr as i32,
);
assert_eq!(res, types::Errno::Ok.into(), "cookie cutter errno");
let is_cookie_start = host_memory
.ptr::<types::Bool>(self.return_ptr_loc.ptr)
.ptr::<types::Bool>(&bc, self.return_ptr_loc.ptr)
.read()
.expect("deref to Bool value");

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");

View File

@@ -1,5 +1,5 @@
use proptest::prelude::*;
use wiggle::{GuestBorrows, GuestMemory, GuestPtr};
use wiggle::{BorrowChecker, GuestMemory, GuestPtr};
use wiggle_test::{impl_errno, HostMemory, MemArea, MemAreas, WasiCtx};
wiggle::from_witx!({
@@ -11,12 +11,9 @@ impl_errno!(types::Errno, types::GuestErrorConversion);
impl<'a> strings::Strings for WasiCtx<'a> {
fn hello_string(&self, a_string: &GuestPtr<str>) -> Result<u32, types::Errno> {
let mut bc = GuestBorrows::new();
let s = a_string.as_raw(&mut bc).expect("should be valid string");
unsafe {
println!("a_string='{}'", &*s);
Ok((*s).len() as u32)
}
let s = a_string.as_str().expect("should be valid string");
println!("a_string='{}'", &*s);
Ok(s.len() as u32)
}
fn multi_string(
@@ -25,18 +22,15 @@ impl<'a> strings::Strings for WasiCtx<'a> {
b: &GuestPtr<str>,
c: &GuestPtr<str>,
) -> Result<u32, types::Errno> {
let mut bc = GuestBorrows::new();
let sa = a.as_raw(&mut bc).expect("A should be valid string");
let sb = b.as_raw(&mut bc).expect("B should be valid string");
let sc = c.as_raw(&mut bc).expect("C should be valid string");
unsafe {
let total_len = (&*sa).len() + (&*sb).len() + (&*sc).len();
println!(
"len={}, a='{}', b='{}', c='{}'",
total_len, &*sa, &*sb, &*sc
);
Ok(total_len as u32)
}
let sa = a.as_str().expect("A should be valid string");
let sb = b.as_str().expect("B should be valid string");
let sc = c.as_str().expect("C should be valid string");
let total_len = sa.len() + sb.len() + sc.len();
println!(
"len={}, a='{}', b='{}', c='{}'",
total_len, &*sa, &*sb, &*sc
);
Ok(total_len as u32)
}
}
@@ -75,9 +69,11 @@ impl HelloStringExercise {
pub fn test(&self) {
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
// Populate string in guest's memory
let ptr = host_memory.ptr::<str>((self.string_ptr_loc.ptr, self.test_word.len() as u32));
let ptr =
host_memory.ptr::<str>(&bc, (self.string_ptr_loc.ptr, self.test_word.len() as u32));
for (slot, byte) in ptr.as_bytes().iter().zip(self.test_word.bytes()) {
slot.expect("should be valid pointer")
.write(byte)
@@ -87,6 +83,7 @@ impl HelloStringExercise {
let res = strings::hello_string(
&ctx,
&host_memory,
&bc,
self.string_ptr_loc.ptr as i32,
self.test_word.len() as i32,
self.return_ptr_loc.ptr as i32,
@@ -94,7 +91,7 @@ impl HelloStringExercise {
assert_eq!(res, types::Errno::Ok.into(), "hello string errno");
let given = host_memory
.ptr::<u32>(self.return_ptr_loc.ptr)
.ptr::<u32>(&bc, self.return_ptr_loc.ptr)
.read()
.expect("deref ptr to return value");
assert_eq!(self.test_word.len() as u32, given);
@@ -181,9 +178,10 @@ impl MultiStringExercise {
pub fn test(&self) {
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
let write_string = |val: &str, loc: MemArea| {
let ptr = host_memory.ptr::<str>((loc.ptr, val.len() as u32));
let ptr = host_memory.ptr::<str>(&bc, (loc.ptr, val.len() as u32));
for (slot, byte) in ptr.as_bytes().iter().zip(val.bytes()) {
slot.expect("should be valid pointer")
.write(byte)
@@ -198,6 +196,7 @@ impl MultiStringExercise {
let res = strings::multi_string(
&ctx,
&host_memory,
&bc,
self.sa_ptr_loc.ptr as i32,
self.a.len() as i32,
self.sb_ptr_loc.ptr as i32,
@@ -209,7 +208,7 @@ impl MultiStringExercise {
assert_eq!(res, types::Errno::Ok.into(), "multi string errno");
let given = host_memory
.ptr::<u32>(self.return_ptr_loc.ptr)
.ptr::<u32>(&bc, self.return_ptr_loc.ptr)
.read()
.expect("deref ptr to return value");
assert_eq!((self.a.len() + self.b.len() + self.c.len()) as u32, given);

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!({
@@ -83,18 +83,20 @@ impl SumOfPairExercise {
pub fn test(&self) {
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
host_memory
.ptr(self.input_loc.ptr)
.ptr(&bc, self.input_loc.ptr)
.write(self.input.first)
.expect("input ref_mut");
host_memory
.ptr(self.input_loc.ptr + 4)
.ptr(&bc, self.input_loc.ptr + 4)
.write(self.input.second)
.expect("input ref_mut");
let sum_err = structs::sum_of_pair(
&ctx,
&host_memory,
&bc,
self.input_loc.ptr as i32,
self.return_loc.ptr as i32,
);
@@ -102,7 +104,7 @@ impl SumOfPairExercise {
assert_eq!(sum_err, types::Errno::Ok.into(), "sum errno");
let return_val: i64 = host_memory
.ptr(self.return_loc.ptr)
.ptr(&bc, self.return_loc.ptr)
.read()
.expect("return ref");
@@ -171,28 +173,30 @@ impl SumPairPtrsExercise {
pub fn test(&self) {
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
host_memory
.ptr(self.input_first_loc.ptr)
.ptr(&bc, self.input_first_loc.ptr)
.write(self.input_first)
.expect("input_first ref");
host_memory
.ptr(self.input_second_loc.ptr)
.ptr(&bc, self.input_second_loc.ptr)
.write(self.input_second)
.expect("input_second ref");
host_memory
.ptr(self.input_struct_loc.ptr)
.ptr(&bc, self.input_struct_loc.ptr)
.write(self.input_first_loc.ptr)
.expect("input_struct ref");
host_memory
.ptr(self.input_struct_loc.ptr + 4)
.ptr(&bc, self.input_struct_loc.ptr + 4)
.write(self.input_second_loc.ptr)
.expect("input_struct ref");
let res = structs::sum_of_pair_of_ptrs(
&ctx,
&host_memory,
&bc,
self.input_struct_loc.ptr as i32,
self.return_loc.ptr as i32,
);
@@ -200,7 +204,7 @@ impl SumPairPtrsExercise {
assert_eq!(res, types::Errno::Ok.into(), "sum of pair of ptrs errno");
let doubled: i64 = host_memory
.ptr(self.return_loc.ptr)
.ptr(&bc, self.return_loc.ptr)
.read()
.expect("return ref");
@@ -255,23 +259,25 @@ impl SumIntAndPtrExercise {
pub fn test(&self) {
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
host_memory
.ptr(self.input_first_loc.ptr)
.ptr(&bc, self.input_first_loc.ptr)
.write(self.input_first)
.expect("input_first ref");
host_memory
.ptr(self.input_struct_loc.ptr)
.ptr(&bc, self.input_struct_loc.ptr)
.write(self.input_first_loc.ptr)
.expect("input_struct ref");
host_memory
.ptr(self.input_struct_loc.ptr + 4)
.ptr(&bc, self.input_struct_loc.ptr + 4)
.write(self.input_second)
.expect("input_struct ref");
let res = structs::sum_of_int_and_ptr(
&ctx,
&host_memory,
&bc,
self.input_struct_loc.ptr as i32,
self.return_loc.ptr as i32,
);
@@ -279,7 +285,7 @@ impl SumIntAndPtrExercise {
assert_eq!(res, types::Errno::Ok.into(), "sum of int and ptr errno");
let doubled: i64 = host_memory
.ptr(self.return_loc.ptr)
.ptr(&bc, self.return_loc.ptr)
.read()
.expect("return ref");
@@ -312,13 +318,14 @@ impl ReturnPairInts {
pub fn test(&self) {
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
let err = structs::return_pair_ints(&ctx, &host_memory, self.return_loc.ptr as i32);
let err = structs::return_pair_ints(&ctx, &host_memory, &bc, self.return_loc.ptr as i32);
assert_eq!(err, types::Errno::Ok.into(), "return struct errno");
let return_struct: types::PairInts = host_memory
.ptr(self.return_loc.ptr)
.ptr(&bc, self.return_loc.ptr)
.read()
.expect("return ref");
@@ -377,19 +384,21 @@ impl ReturnPairPtrsExercise {
pub fn test(&self) {
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
host_memory
.ptr(self.input_first_loc.ptr)
.ptr(&bc, self.input_first_loc.ptr)
.write(self.input_first)
.expect("input_first ref");
host_memory
.ptr(self.input_second_loc.ptr)
.ptr(&bc, self.input_second_loc.ptr)
.write(self.input_second)
.expect("input_second ref");
let res = structs::return_pair_of_ptrs(
&ctx,
&host_memory,
&bc,
self.input_first_loc.ptr as i32,
self.input_second_loc.ptr as i32,
self.return_loc.ptr as i32,
@@ -398,7 +407,7 @@ impl ReturnPairPtrsExercise {
assert_eq!(res, types::Errno::Ok.into(), "return pair of ptrs errno");
let ptr_pair_int_ptrs: types::PairIntPtrs<'_> = host_memory
.ptr(self.return_loc.ptr)
.ptr(&bc, self.return_loc.ptr)
.read()
.expect("failed to read return location");
let ret_first_ptr = ptr_pair_int_ptrs.first;

View File

@@ -1,5 +1,5 @@
use proptest::prelude::*;
use wiggle::{GuestMemory, GuestType};
use wiggle::{BorrowChecker, GuestMemory, GuestType};
use wiggle_test::{impl_errno, HostMemory, MemArea, WasiCtx};
wiggle::from_witx!({
@@ -107,21 +107,22 @@ impl GetTagExercise {
pub fn test(&self) {
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
let discriminant: u8 = reason_tag(&self.input).into();
host_memory
.ptr(self.input_loc.ptr)
.ptr(&bc, self.input_loc.ptr)
.write(discriminant)
.expect("input discriminant ptr");
match self.input {
types::Reason::DogAte(f) => {
host_memory
.ptr(self.input_loc.ptr + 4)
.ptr(&bc, self.input_loc.ptr + 4)
.write(f)
.expect("input contents ref_mut");
}
types::Reason::Traffic(v) => host_memory
.ptr(self.input_loc.ptr + 4)
.ptr(&bc, self.input_loc.ptr + 4)
.write(v)
.expect("input contents ref_mut"),
types::Reason::Sleeping => {} // Do nothing
@@ -129,6 +130,7 @@ impl GetTagExercise {
let e = union_example::get_tag(
&ctx,
&host_memory,
&bc,
self.input_loc.ptr as i32,
self.return_loc.ptr as i32,
);
@@ -136,7 +138,7 @@ impl GetTagExercise {
assert_eq!(e, types::Errno::Ok.into(), "get_tag errno");
let return_val: types::Excuse = host_memory
.ptr(self.return_loc.ptr)
.ptr(&bc, self.return_loc.ptr)
.read()
.expect("return ref");
@@ -184,27 +186,28 @@ impl ReasonMultExercise {
pub fn test(&self) {
let ctx = WasiCtx::new();
let host_memory = HostMemory::new();
let bc = BorrowChecker::new();
let discriminant: u8 = reason_tag(&self.input).into();
host_memory
.ptr(self.input_loc.ptr)
.ptr(&bc, self.input_loc.ptr)
.write(discriminant)
.expect("input discriminant ref_mut");
host_memory
.ptr(self.input_loc.ptr + 4)
.ptr(&bc, self.input_loc.ptr + 4)
.write(self.input_pointee_loc.ptr)
.expect("input pointer ref_mut");
match self.input {
types::Reason::DogAte(f) => {
host_memory
.ptr(self.input_pointee_loc.ptr)
.ptr(&bc, self.input_pointee_loc.ptr)
.write(f)
.expect("input contents ref_mut");
}
types::Reason::Traffic(v) => {
host_memory
.ptr(self.input_pointee_loc.ptr)
.ptr(&bc, self.input_pointee_loc.ptr)
.write(v)
.expect("input contents ref_mut");
}
@@ -213,6 +216,7 @@ impl ReasonMultExercise {
let e = union_example::reason_mult(
&ctx,
&host_memory,
&bc,
self.input_loc.ptr as i32,
self.multiply_by as i32,
);
@@ -222,7 +226,7 @@ impl ReasonMultExercise {
match self.input {
types::Reason::DogAte(f) => {
let f_result: f32 = host_memory
.ptr(self.input_pointee_loc.ptr)
.ptr(&bc, self.input_pointee_loc.ptr)
.read()
.expect("input contents ref_mut");
assert_eq!(
@@ -233,7 +237,7 @@ impl ReasonMultExercise {
}
types::Reason::Traffic(v) => {
let v_result: i32 = host_memory
.ptr(self.input_pointee_loc.ptr)
.ptr(&bc, self.input_pointee_loc.ptr)
.read()
.expect("input contents ref_mut");
assert_eq!(

View File

@@ -1,4 +1,4 @@
use wiggle::{GuestBorrows, GuestError, GuestErrorType, GuestPtr};
use wiggle::{GuestError, GuestErrorType, GuestPtr, GuestSlice};
use wiggle_test::WasiCtx;
// This test file exists to make sure that the entire `wasi.witx` file can be
@@ -141,11 +141,11 @@ impl<'a> crate::wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx<'a> {
// that we can use the wiggle API to create the datastructures we want
// for efficient implementation of this function elsewhere.
let mut bc = GuestBorrows::new();
let mut slices: Vec<&'_ mut [u8]> = Vec::new();
let mut slices: Vec<GuestSlice<'_, u8>> = Vec::new();
// XXX FIXME make sure this property still holds:
// Mark the iov elements as borrowed, to ensure that they does not
// overlap with any of the as_raw regions.
bc.borrow_slice(&iovs).expect("borrow iovec array");
// bc.borrow_slice(&iovs).expect("borrow iovec array");
for iov_ptr in iovs.iter() {
let iov_ptr = iov_ptr.expect("iovec element pointer is valid");
@@ -153,10 +153,14 @@ impl<'a> crate::wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx<'a> {
let base: GuestPtr<u8> = iov.buf;
let len: u32 = iov.buf_len;
let buf: GuestPtr<[u8]> = base.as_array(len);
let slice = buf.as_raw(&mut bc).expect("borrow slice from iovec");
slices.push(unsafe { &mut *slice });
let slice = buf.as_slice().expect("borrow slice from iovec");
slices.push(slice);
}
println!("iovec slices: {:?}", slices);
println!("iovec slices: [");
for slice in slices {
println!(" {:?},", &*slice);
}
println!("]");
unimplemented!("fd_pread")
}