-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve other WASI functions as well. Signed-off-by: Zoltan Herczeg [email protected]
- Loading branch information
1 parent
20d770b
commit ed31dc5
Showing
4 changed files
with
197 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
(module | ||
(import "wasi_snapshot_preview1" "path_open" (func $path_open (param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32))) | ||
(import "wasi_snapshot_preview1" "fd_close" (func $fd_close (param i32) (result i32))) | ||
(import "wasi_snapshot_preview1" "fd_fdstat_get" (func $fd_fdstat_get (param i32 i32) (result i32))) | ||
|
||
(memory 1 1) | ||
(data (i32.const 100) "./fd_fdstat_get.wast") | ||
|
||
(func (export "fdstatGet") (result i32 i32 i32) | ||
i32.const 3 ;; Directory file descriptior, by default 3 is the first opened directory | ||
i32.const 1 ;; uvwasi_lookupflags_t: UVWASI_LOOKUP_SYMLINK_FOLLOW | ||
i32.const 100 ;; Offset of file name in memory | ||
i32.const 20 ;; Length of file name | ||
i32.const 0 ;; uvwasi_oflags_t: none | ||
i64.const 0x42000 ;; base uvwasi_rights_t: UVWASI_RIGHT_PATH_OPEN, UVWASI_RIGHT_FD_FILESTAT_GET | ||
i64.const 0x42000 ;; inherited uvwasi_rights_t: UVWASI_RIGHT_PATH_OPEN, UVWASI_RIGHT_FD_FILESTAT_GET | ||
i32.const 0 ;; uvwasi_fdflags_t: none | ||
i32.const 0 ;; Offset to store at the opened file descriptor in memory | ||
call $path_open | ||
|
||
i32.const 0 | ||
i32.load | ||
i32.const 200 | ||
call $fd_fdstat_get | ||
|
||
i32.const 0 | ||
i32.load | ||
call $fd_close | ||
) | ||
|
||
(func (export "fdstatGetBad") (result i32 i32 i32 i32) | ||
i32.const 3 ;; Directory file descriptior, by default 3 is the first opened directory | ||
i32.const 1 ;; uvwasi_lookupflags_t: UVWASI_LOOKUP_SYMLINK_FOLLOW | ||
i32.const 100 ;; Offset of file name in memory | ||
i32.const 20 ;; Length of file name | ||
i32.const 0 ;; uvwasi_oflags_t: none | ||
i64.const 0x42000 ;; base uvwasi_rights_t: UVWASI_RIGHT_PATH_OPEN, UVWASI_RIGHT_FD_FILESTAT_GET | ||
i64.const 0x42000 ;; inherited uvwasi_rights_t: UVWASI_RIGHT_PATH_OPEN, UVWASI_RIGHT_FD_FILESTAT_GET | ||
i32.const 0 ;; uvwasi_fdflags_t: none | ||
i32.const 0 ;; Offset to store at the opened file descriptor in memory | ||
call $path_open | ||
|
||
i32.const 0 | ||
i32.load | ||
i32.const 65535 | ||
call $fd_fdstat_get | ||
|
||
i32.const -1 | ||
i32.const 200 | ||
call $fd_fdstat_get | ||
|
||
i32.const 0 | ||
i32.load | ||
call $fd_close | ||
) | ||
) | ||
|
||
(assert_return (invoke "fdstatGet") (i32.const 0) (i32.const 0) (i32.const 0)) | ||
(assert_return (invoke "fdstatGetBad") (i32.const 0) (i32.const 28) (i32.const 8) (i32.const 0)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
(module | ||
(import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) | ||
|
||
(memory $memory 1 1) | ||
(data (i32.const 100) "Hello ") | ||
(data (i32.const 200) "World!\n") | ||
|
||
(func (export "writeToStdout") (result i32 i32) | ||
;; Write iovs into memory from offset 16 | ||
i32.const 16 | ||
i32.const 100 | ||
i32.store | ||
|
||
i32.const 20 | ||
i32.const 6 | ||
i32.store | ||
|
||
i32.const 24 | ||
i32.const 200 | ||
i32.store | ||
|
||
i32.const 28 | ||
i32.const 7 | ||
i32.store | ||
|
||
i32.const 1 ;; stdout | ||
i32.const 16 ;; iovs offset | ||
i32.const 2 ;; iovsLen | ||
i32.const 8 ;; nwritten | ||
|
||
call $fd_write | ||
|
||
i32.const 8 | ||
i32.load | ||
) | ||
|
||
(func (export "badWrite") (result i32 i32 i32 i32) | ||
i32.const 100000 ;; invalid descriptor | ||
i32.const 8 ;; iovs offset | ||
i32.const 1 ;; iovsLen | ||
i32.const 4 ;; nwritten | ||
|
||
call $fd_write | ||
|
||
i32.const 1 ;; stdout | ||
i32.const 65529 ;; bad iovs offset | ||
i32.const 1 ;; iovsLen | ||
i32.const 8 ;; nwritten | ||
|
||
call $fd_write | ||
|
||
i32.const 1 ;; stdout | ||
i32.const 16 ;; iovs offset | ||
i32.const 1 ;; iovsLen | ||
i32.const 65533 ;; bad nwritten | ||
|
||
call $fd_write | ||
|
||
i32.const 1 ;; stdout | ||
i32.const 8 ;; iovs offset | ||
i32.const 8192 ;; bad iovsLen | ||
i32.const 0 ;; nwritten | ||
|
||
call $fd_write | ||
) | ||
) | ||
|
||
(assert_return (invoke "writeToStdout") (i32.const 0) (i32.const 13)) | ||
(assert_return (invoke "badWrite") (i32.const 8) (i32.const 28) (i32.const 28) (i32.const 28)) |