aboutsummaryrefslogtreecommitdiffstats
path: root/sys/fuchsia/test
diff options
context:
space:
mode:
authorLaura Peskin <pesk@google.com>2022-11-11 14:29:03 -0800
committerglpesk <114444708+glpesk@users.noreply.github.com>2022-11-17 14:51:18 -0800
commit5bb7001449cd1dae6cbff2d660374d6d17cbd2c4 (patch)
tree785850b16d345640c0d5e314a8df5f29f6f700e4 /sys/fuchsia/test
parent4ba8ab94b872006785aeb11e8c22c9dd578b3d1e (diff)
sys/fuchsia: add test for vmar syscall descriptions
Also made some small updates to the vmar descriptions: - In a few places, a `len` arg was incorrectly tagged as the length of another arg when it actually represents a region size; fixed. - The `buffer` and `buffer_size` args to `zx_vmar_op_range` must be null; replaced with constants. - Added a `zx_vaddr` resource type wrapping `intptr` and used it in place of `vma`, since it's not clear how to use `vma` as the pointee type of an outptr in a program.
Diffstat (limited to 'sys/fuchsia/test')
-rw-r--r--sys/fuchsia/test/vmar57
1 files changed, 57 insertions, 0 deletions
diff --git a/sys/fuchsia/test/vmar b/sys/fuchsia/test/vmar
new file mode 100644
index 000000000..6c3be624a
--- /dev/null
+++ b/sys/fuchsia/test/vmar
@@ -0,0 +1,57 @@
+# TODO: This test assumes that the system page size is 4KiB (or a divisor of 4KiB), since
+# some arguments must be page-aligned, and some tests will fail if the page size is larger.
+
+r0 = syz_vmar_root_self()
+
+# Allocate a vmar with the ZX_VM_CAN_MAP_SPECIFIC permission.
+
+zx_vmar_allocate(r0, 0x40, 0x0, 0x2000, &AUTO=<r1=>0x0, &AUTO)
+
+# Create a vmo and map it into the vmar at a specific offset (of 0 bytes), then unmap the full subregion.
+
+zx_vmo_create(0x1000, 0x0, &AUTO=<r2=>0x0)
+zx_vmar_map(r1, 0x10, 0x0, r2, 0x0, 0x1000, &AUTO=<r3=>0x0)
+zx_vmar_unmap(r1, r3, 0x1000)
+
+# Attempting to map the same vmo should fail when the vmar offset + stated size is larger than the allocated vmar, or the vmar offset is not page-aligned.
+
+zx_vmar_map(r1, 0x10, 0x0, r2, 0x0, 0x3001, &AUTO=<r3=>0x0) # ZX_ERR_INVALID_ARGS
+zx_vmar_map(r1, 0x10, 0x2000, r2, 0x0, 0x1001, &AUTO=<r3=>0x0) # ZX_ERR_INVALID_ARGS
+zx_vmar_map(r1, 0x10, 0x100, r2, 0x0, 0x1000, &AUTO=<r3=>0x0) # ZX_ERR_INVALID_ARGS
+
+# Repeatedly map a vmo into the vmar with the ZX_VM_OFFSET_IS_UPPER_LIMIT option.
+# Mapping should succeed until the upper limit is reached.
+
+zx_vmar_map(r1, 0x2000, 0x2000, r2, 0x0, 0x1000, &AUTO=<r5=>0x0)
+zx_vmar_map(r1, 0x2000, 0x2000, r2, 0x0, 0x1000, &AUTO=<r6=>0x0)
+zx_vmar_map(r1, 0x2000, 0x2000, r2, 0x0, 0x1000, &AUTO) # ZX_ERR_NO_RESOURCES
+
+# Destroy a vmar. Afterwards, uses of that vmar handle should fail.
+
+zx_vmar_destroy(r1)
+zx_vmar_unmap(r1, r5, 0x1000) # ZX_ERR_BAD_STATE
+zx_vmar_allocate(r1, 0x40, 0x0, 0x1000, &AUTO, &AUTO) # ZX_ERR_BAD_STATE
+
+# Allocate a vmar with the ZX_VM_CAN_MAP_READ and ZX_VM_CAN_MAP_WRITE permissions,
+# then map in a vmo with the ZX_VM_PERM_READ and ZX_VM_PERM_WRITE permissions.
+# Remove the write permission from the mapped region, leaving the read permission.
+# Restore the write permission to the mapped region.
+# Attempt to increase permissions to include ZX_VM_PERM_EXECUTE; this should fail.
+
+zx_vmar_allocate(r0, 0x180, 0x0, 0x3000, &AUTO=<r7=>0x0, &AUTO=<r8=>0x0)
+zx_vmar_map(r7, 0x3, 0x0, r2, 0x0, 0x1000, &AUTO=<r9=>0x0)
+zx_vmar_protect(r7, 0x1, r9, 0x1000)
+zx_vmar_protect(r7, 0x3, r9, 0x1000)
+zx_vmar_protect(r7, 0x7, r9, 0x1000) # ZX_ERR_ACCESS_DENIED
+zx_vmar_unmap(r7, r9, 0x1000)
+
+# Create a vmo and map it into a vmar, leaving part of the vmar unmapped.
+# Verify that a sequence of operations succeeds on the full mapped region and on a page-aligned subregion.
+# An operation on a range including an unmapped region should fail.
+
+zx_vmo_create(0x2000, 0x0, &AUTO=<r10=>0x0)
+zx_vmar_map(r7, 0x3, 0x0, r10, 0x0, 0x2000, &AUTO=<r11=>0x0)
+zx_vmar_op_range(r7, 0x1, r11, 0x2000, 0x0, 0x0)
+zx_vmar_op_range(r7, 0x2, r11, 0x1000, 0x0, 0x0)
+zx_vmar_op_range(r7, 0x3, r11, 0x2000, 0x0, 0x0)
+zx_vmar_op_range(r7, 0x3, r8, 0x3000, 0x0, 0x0) # ZX_ERR_BAD_STATE \ No newline at end of file