Commit Graph

36 Commits

Author SHA1 Message Date
Jakub Konka
44584bccfc Refactor memory module
This commit refactors and reorganises the `memory.rs` module. Now,
it consists of two submodules: `memory::ptr` which contains `GuestPtr`
and `GuestRef` (and their mutable versions), and `memory::array` which
contains `GuestArray` and `GuestArrayRef` (and their mutable versions).

This commit also adds basic unit sanity tests for the `memory::ptr`
submodule.
2020-02-09 17:52:27 -08:00
Jakub Konka
664f7d38e0 Add first pass at GuestArray (#5)
* Add first pass at GuestArray

* Return &'a [T] instead of Vec<Refs>

Also, add a sanity test for `GuestArray`.

* Change approach in GuestArray::as_ref

The new approach should avoid unnecessary copying (does it?) by
iterating through the memory and firstly validating the guest pointers,
to then extracting the slice `&'a [T]` using the unsafe `slice::from_raw_parts`
fn.

* Redo implementation of GuestArray and GuestArrayMut

This commit:
* redos the impl of `as_ref` and `as_ref_mut` for `GuestArray` and
  `GuestArrayMut` structs in that they now return dynamically borrow
  checked `GuestArrayRef` and `GuestArrayRefMut` structs
* introduces `GuestArrayRef` and `GuestArrayRefMut` structs which
  perform dynamic borrow-checking of memory region at runtime, and
  can be derefed to `&[T]` and `&mut [T]`
* adds a few sanity checks for the introduced types

* Rename r#ref to ref_

* Add constructors for GuestArray and GuestArrayMut

This commit:
* adds constructors for `GuestArray` and `GuestArrayMut` both of
  which can now *only* be constructed from `GuestPtr::array` and
  `GuestPtrMut::array_mut` respectively
* changes `Region::extend` to extend the region by adding to the
  current `len` (avoids problem of asserting for > 0)
* implements `fmt::Debug` for most of memory types for easier testing
  (implementation is *not* enforced on the generic parameter `T` in
   the struct; rather, if `T` impls `fmt::Debug` then so does the
   memory type such as `GuestPtr<'_, T>`)
2020-02-07 08:27:21 +01:00
Jakub Konka
2687b01474 Refactor Region struct (#4)
* Add some basic sanity tests for Region

This commit adds some basic sanity tests for `overlap` method
of `Region`.

* Refactor overlaps method of Region struct

This commit refactors `Region::overlaps` method.

* Add some docs

* Assert Region's len is nonzero
2020-02-04 23:26:18 +01:00
Pat Hickey
67d2ce6d85 Refactor tests to use proptest (#6)
* generator: take an &mut GuestMemory

rather than pass the owned GuestMemory in, just give exclusive access
to it. Makes testing easier.

* tests: start transforming tests to check abi-level generated code as well

* finish lowering of test funcs

* tests: rename variables to more sensible names

* proptesting: reliably finds that we dont allow stuff to be right against end of memory!

* memory: fix off-by-one calc in GuestMemory::contains(&self, Region)

ty proptest!

also, refactored the Region::overlaps to be the same code but easier to
read.

* generator: better location information in GuestError

* testing: proptest generates memory areas, tests everything
2020-02-04 22:35:38 +01:00
Jakub Konka
e6cec049cb Add basic CI conf (#3)
* Add basic CI conf

* Pull in submodules in Rustfmt job

* Exclude WASI from workspace; fix name clash in memory crate

* Refactor CI conf
2020-02-03 09:59:09 +01:00
Jakub Konka
3d428b828f Add some (incomplete set) basic sanity end-to-end tests (#2)
* Add some (incomplete set) basic sanity end-to-end tests

This commit adds some (an incomplete set of) basic sanity end-to-end
tests. It uses `test.witx` to autogenerate types and module interface
functions (aka the syscalls), and tests their implementation. For
the host memory, it uses simplistic `&mut [u8]` where we have full
control of the addressing and contents.

* Add sanity test for baz interface func

This commit adds a sanity test for the `Foo::baz` interface func.

* Upcast start/len for Region to avoid overflow

* Reenable alignment checking for memory

* use an array to implement hostmemory

Co-authored-by: Pat Hickey <pat@moreproductive.org>
2020-02-03 07:38:48 +01:00
Pat Hickey
f321f05a98 use lifetimes on types that require it 2020-01-31 15:18:49 -08:00
Pat Hickey
29c3ef9d09 we now parse witx paths and the ctx type name in the macro invocation 2020-01-30 16:38:16 -08:00
Pat Hickey
0ba8e73184 change proc macro argument parsing to use syn 2020-01-30 14:29:53 -08:00
Pat Hickey
e2079c085d report which field a struct validation error occured in 2020-01-29 13:18:57 -08:00
Pat Hickey
814dd19488 structs that contain pointers work! 2020-01-28 18:17:48 -08:00
Pat Hickey
35d9373976 we now validate Copy structs 2020-01-28 16:34:34 -08:00
Pat Hickey
62e00434b0 structs implementing Copy are scaffolded out.
todo: need an unsafe method for casting pointers in order to validate
contents via recursive descent
2020-01-28 15:45:52 -08:00
Pat Hickey
373560b88a and now funcs work again 2020-01-27 20:28:27 -08:00
Pat Hickey
c780421c28 i think the memory model is fixed now? at least until arrays.... 2020-01-27 20:21:53 -08:00
Pat Hickey
ec456e9e50 new memory model. not quite complete 2020-01-27 18:20:47 -08:00
Pat Hickey
e6a4ae205c return values written to pointers! 2020-01-27 12:40:54 -08:00
Pat Hickey
a20ef36a49 multiple layers of pointers work! 2020-01-24 19:57:18 -08:00
Pat Hickey
020778b7da we can handle one layer of pointers! 2020-01-24 18:08:37 -08:00
Pat Hickey
e789033651 bugfix 2020-01-24 15:16:09 -08:00
Pat Hickey
42eca19b50 types: make the tryfrom/to impl for the abi type, not the signed variant 2020-01-24 15:12:51 -08:00
Pat Hickey
b6d342ccb5 some progress on marshalling args 2020-01-23 17:55:59 -08:00
Pat Hickey
b4f21752b0 generate a module trait and call it 2020-01-23 12:53:10 -08:00
Pat Hickey
cb24fd97c0 better error trait design 2020-01-23 11:21:04 -08:00
Pat Hickey
7cc0073a3e hmm my first idea was bad but not too bad 2020-01-22 21:03:24 -08:00
Pat Hickey
c05475b806 generate: now we have a way to do errors, i guess 2020-01-22 20:47:40 -08:00
Pat Hickey
97077954f8 enum generation: fill in GuestTypeCopy impl 2020-01-22 17:23:29 -08:00
Pat Hickey
aa5c5f7018 flesh out the guest type traits a bit further 2020-01-22 16:38:25 -08:00
Pat Hickey
b8feffe6e1 funcs get abi type definitions 2020-01-20 15:10:11 -08:00
Pat Hickey
9291495e57 put names all in one place. some stub code for funcs! 2020-01-19 19:33:41 -08:00
Pat Hickey
cd686915aa clear out a bunch of old code, reorganize 2020-01-19 18:46:16 -08:00
Pat Hickey
4c7b3e8685 import some other helpers from pat's crate
* parse the proc macro argument into a file path
* use a much simpler witx spec by default
2020-01-17 15:48:51 -08:00
Pat Hickey
0d47556cf7 import memory sub-crate 2020-01-17 15:41:19 -08:00
Jakub Konka
f24b0240ae Start tweaking original wig with Pat's suggestion 2020-01-17 19:30:37 +01:00
Jakub Konka
64f0793388 Fix incorrect hardcoded path to witx spec 2020-01-17 14:59:51 +01:00
Jakub Konka
6f6c6499c6 Set up machinery 2020-01-17 14:54:05 +01:00