Skip to content

Commit 7408db4

Browse files
author
YAMAMOTO Yuji
authored
Document atomicity of write and pwrite, and technical fix about POSIX (#257)
* Techinically speaking, preadv and pwritev are not in POSIX. Ref: https://pubs.opengroup.org/onlinepubs/9699919799/idx/ip.html * Document about atomicity of `write` and `pwrite` Related thread of ZULIP: https://bytecodealliance.zulipchat.com/#narrow/stream/219900-wasi/topic/Why.20is.20.60iovecs.60.20an.20array.20of.20strings.3F The thread refers atomicity of `read`, but I couldn't make a good expression for the atomicity of `read`. So I add document only in `write` and `pwrite`. * Limit the scope of atomicity The related POSIX document refers only to threads. https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_07 So the atomicity is limited in the process * Fix test * Fix after review #257 (comment) The atomicity is guaranteed only for regular files or symbolic links (only symbolic links for a regular files, right?) Delete expressions indicating 'all or nothing' to reflect the actual behavior of POSIX's`write` etc. * Fix after review #257 (comment) Delete the sentences related to 'all data' completely Don't refer to symlink * Fix after review #257 (review)
1 parent 8125353 commit 7408db4

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

phases/ephemeral/docs.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ The permissions associated with the file.
14151415

14161416
#### <a href="#pread" name="pread"></a> `pread(fd: fd, iovs: iovec_array, offset: filesize) -> (errno, size)`
14171417
Read from a file descriptor, without using and updating the file descriptor's offset.
1418-
Note: This is similar to `preadv` in POSIX.
1418+
Note: This is similar to `preadv` in Linux (and other Unix-es).
14191419

14201420
##### Params
14211421
- <a href="#pread.fd" name="pread.fd"></a> `fd`: [`fd`](#fd)
@@ -1469,7 +1469,11 @@ A buffer into which to write the preopened directory name.
14691469

14701470
#### <a href="#pwrite" name="pwrite"></a> `pwrite(fd: fd, iovs: ciovec_array, offset: filesize) -> (errno, size)`
14711471
Write to a file descriptor, without using and updating the file descriptor's offset.
1472-
Note: This is similar to `pwritev` in POSIX.
1472+
Note: This is similar to `pwritev` in Linux (and other Unix-es).
1473+
1474+
Like Linux (and other Unix-es), any calls of [`pwrite`](#pwrite) (and other
1475+
functions to read or write) for a regular file by other threads in the
1476+
WASI process should not be interleaved while [`pwrite`](#pwrite) is executed.
14731477

14741478
##### Params
14751479
- <a href="#pwrite.fd" name="pwrite.fd"></a> `fd`: [`fd`](#fd)
@@ -1616,6 +1620,10 @@ The current offset of the file descriptor, relative to the start of the file.
16161620
Write to a file descriptor.
16171621
Note: This is similar to `writev` in POSIX.
16181622

1623+
Like POSIX, any calls of [`write`](#write) (and other functions to read or write)
1624+
for a regular file by other threads in the WASI process should not be
1625+
interleaved while [`write`](#write) is executed.
1626+
16191627
##### Params
16201628
- <a href="#write.fd" name="write.fd"></a> `fd`: [`fd`](#fd)
16211629

phases/ephemeral/witx/wasi_ephemeral_fd.witx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
)
128128

129129
;;; Read from a file descriptor, without using and updating the file descriptor's offset.
130-
;;; Note: This is similar to `preadv` in POSIX.
130+
;;; Note: This is similar to `preadv` in Linux (and other Unix-es).
131131
(@interface func (export "pread")
132132
(param $fd $fd)
133133
;;; List of scatter/gather vectors in which to store data.
@@ -157,7 +157,11 @@
157157
)
158158

159159
;;; Write to a file descriptor, without using and updating the file descriptor's offset.
160-
;;; Note: This is similar to `pwritev` in POSIX.
160+
;;; Note: This is similar to `pwritev` in Linux (and other Unix-es).
161+
;;;
162+
;;; Like Linux (and other Unix-es), any calls of `pwrite` (and other
163+
;;; functions to read or write) for a regular file by other threads in the
164+
;;; WASI process should not be interleaved while `pwrite` is executed.
161165
(@interface func (export "pwrite")
162166
(param $fd $fd)
163167
;;; List of scatter/gather vectors from which to retrieve data.
@@ -250,6 +254,10 @@
250254

251255
;;; Write to a file descriptor.
252256
;;; Note: This is similar to `writev` in POSIX.
257+
;;;
258+
;;; Like POSIX, any calls of `write` (and other functions to read or write)
259+
;;; for a regular file by other threads in the WASI process should not be
260+
;;; interleaved while `write` is executed.
253261
(@interface func (export "write")
254262
(param $fd $fd)
255263
;;; List of scatter/gather vectors from which to retrieve data.

0 commit comments

Comments
 (0)