aboutsummaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorLaura Peskin <pesk@google.com>2022-11-18 15:04:26 -0800
committerAnge Albertini <105304039+corkamig@users.noreply.github.com>2022-11-23 21:34:24 +0000
commitff68ff8f0e1a62984fe933655e14994ae3e16809 (patch)
treebb645550b0f1cbec894cbb744f501afe71f47310 /sys
parentdefe14d671072c1341aefae2f3a2c313343fd9fc (diff)
sys/fuchsia: add test for stream syscall definitions
Also added a `zx_offset` resource type to stream.txt, since the syscall interface uses a distinguished type for offsets here; used `intptr` for sizes and `flags` for options; updated const lists and definitions; corrected in/out direction for a few pointers.
Diffstat (limited to 'sys')
-rw-r--r--sys/fuchsia/stream.txt27
-rw-r--r--sys/fuchsia/stream_amd64.const8
-rw-r--r--sys/fuchsia/stream_arm64.const8
-rw-r--r--sys/fuchsia/test/stream34
4 files changed, 66 insertions, 11 deletions
diff --git a/sys/fuchsia/stream.txt b/sys/fuchsia/stream.txt
index 8234b72cf..a1d9839b0 100644
--- a/sys/fuchsia/stream.txt
+++ b/sys/fuchsia/stream.txt
@@ -6,21 +6,26 @@
include <zircon/syscalls.h>
resource zx_stream[zx_handle]
+resource zx_offset[intptr]
-zx_stream_create(options int32, vmo zx_vmo, seek int64, out_stream ptr[out, zx_stream])
+zx_stream_create(options flags[stream_create_options], vmo zx_vmo, seek zx_offset, out_stream ptr[out, zx_stream])
-zx_iovec {
- buffer int8
- capacity int64
-}
+zx_stream_writev(handle zx_stream, options flags[stream_writev_options], vector ptr[in, array[zx_iovec]], num_vector len[vector], actual ptr[out, intptr])
+
+zx_stream_writev_at(handle zx_stream, options flags[stream_writev_options], offset zx_offset, vector ptr[in, array[zx_iovec]], num_vector len[vector], actual ptr[out, intptr])
-zx_stream_writev(handle zx_stream, options int32, vector ptr[in, array[zx_iovec]], num_vector len[vector], actual ptr[out, int64])
+zx_stream_readv(handle zx_stream, options flags[stream_readv_options], vector ptr[out, array[zx_iovec]], num_vector len[vector], actual ptr[out, intptr])
-zx_stream_writev_at(handle zx_stream, options int32, offset int64, vector ptr[in, array[zx_iovec]], num_vector len[vector], actual ptr[out, int64])
+zx_stream_readv_at(handle zx_stream, options flags[stream_readv_options], offset zx_offset, vector ptr[out, array[zx_iovec]], num_vector len[vector], actual ptr[out, intptr])
-zx_stream_readv(handle zx_stream, options int32, vector ptr[out, array[zx_iovec]], num_vector len[vector], actual ptr[out, int64])
+zx_stream_seek(handle zx_handle, whence flags[stream_seek_origin], offset int64, out_seek ptr[out, zx_offset])
-zx_stream_readv_at(handle zx_stream, options int32, offset int64, vector ptr[out, array[zx_iovec]], num_vector len[vector], actual ptr[out, int64])
+zx_iovec {
+ buffer ptr[inout, array[int8]]
+ capacity len[buffer, intptr]
+}
-zx_stream_seek_origin = ZX_STREAM_SEEK_ORIGIN_START, ZX_STREAM_SEEK_ORIGIN_CURRENT, ZX_STREAM_SEEK_ORIGIN_END
-zx_stream_seek(handle zx_handle, whence flags[zx_stream_seek_origin], offset int64, out_seek ptr[out, int64])
+stream_create_options = ZX_STREAM_MODE_READ, ZX_STREAM_MODE_WRITE, ZX_STREAM_MODE_APPEND
+stream_writev_options = 0, ZX_STREAM_APPEND
+stream_readv_options = 0
+stream_seek_origin = ZX_STREAM_SEEK_ORIGIN_START, ZX_STREAM_SEEK_ORIGIN_CURRENT, ZX_STREAM_SEEK_ORIGIN_END
diff --git a/sys/fuchsia/stream_amd64.const b/sys/fuchsia/stream_amd64.const
new file mode 100644
index 000000000..d00776c56
--- /dev/null
+++ b/sys/fuchsia/stream_amd64.const
@@ -0,0 +1,8 @@
+ZX_STREAM_MODE_READ = 1
+ZX_STREAM_MODE_WRITE = 2
+ZX_STREAM_MODE_APPEND = 4
+ZX_STREAM_CREATE_MASK = 7
+ZX_STREAM_APPEND = 1
+ZX_STREAM_SEEK_ORIGIN_START = 0
+ZX_STREAM_SEEK_ORIGIN_CURRENT = 1
+ZX_STREAM_SEEK_ORIGIN_END = 2 \ No newline at end of file
diff --git a/sys/fuchsia/stream_arm64.const b/sys/fuchsia/stream_arm64.const
new file mode 100644
index 000000000..d00776c56
--- /dev/null
+++ b/sys/fuchsia/stream_arm64.const
@@ -0,0 +1,8 @@
+ZX_STREAM_MODE_READ = 1
+ZX_STREAM_MODE_WRITE = 2
+ZX_STREAM_MODE_APPEND = 4
+ZX_STREAM_CREATE_MASK = 7
+ZX_STREAM_APPEND = 1
+ZX_STREAM_SEEK_ORIGIN_START = 0
+ZX_STREAM_SEEK_ORIGIN_CURRENT = 1
+ZX_STREAM_SEEK_ORIGIN_END = 2 \ No newline at end of file
diff --git a/sys/fuchsia/test/stream b/sys/fuchsia/test/stream
new file mode 100644
index 000000000..ed4b1cbe7
--- /dev/null
+++ b/sys/fuchsia/test/stream
@@ -0,0 +1,34 @@
+zx_vmo_create(0x100, 0x0, &AUTO=<r0=>0x0)
+
+# Create a read/write stream and initialize the seek offset to 0.
+
+zx_stream_create(0x3, r0, 0x0, &AUTO=<r1=>0x0)
+
+# Write to the stream, first in write mode, then in append mode.
+
+zx_stream_writev(r1, 0x0, &AUTO=[{&AUTO='abcd', 0x4}, {&AUTO='efg', 0x3}], 0x2, &AUTO)
+zx_stream_writev(r1, 0x1, &AUTO=[{&AUTO='hi', 0x2}], 0x1, &AUTO)
+
+# Attempt to write with an invalid input pointer.
+
+zx_stream_writev(r1, 0x1, 0x0, 0x1, &AUTO) # ZX_ERR_INVALID_ARGS
+
+# Read from the stream.
+
+zx_stream_readv(r1, 0x0, &AUTO, 0x1, &AUTO)
+
+# Move the cursor back to the beginning of the stream.
+# Seek forward 1 byte from the current position in the stream.
+# Seeking fails if the offset (after wrapping around) falls before the beginning of the stream.
+# Seek to an offset past the current end of the stream.
+
+zx_stream_seek(r1, 0x0, 0x0, &AUTO)
+zx_stream_seek(r1, 0x1, 0x1, &AUTO)
+zx_stream_seek(r1, 0x0, 0xffffffffffffffff, &AUTO) # ZX_ERR_INVALID_ARGS
+zx_stream_seek(r1, 0x1, 0xfffffffffffffffe, &AUTO) # ZX_ERR_INVALID_ARGS
+zx_stream_seek(r1, 0x2, 0x1, &AUTO=<r2=>0x0)
+
+# With the cursor after the end of the stream, read and write some bytes.
+
+zx_stream_readv_at(r1, 0x0, r2, &AUTO, 0x1, &AUTO)
+zx_stream_writev_at(r1, 0x0, r2, &AUTO=[{&AUTO='jk', 0x2}], 0x1, &AUTO)