aboutsummaryrefslogtreecommitdiffstats
path: root/sys/fuchsia/test/vmar
blob: 6c3be624aac75baf03bc693276dcbec8e9ef2946 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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