|
| 1 | +(module |
| 2 | + (import "wasi_snapshot_preview1" "path_open" (func $path_open (param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32))) |
| 3 | + (import "wasi_snapshot_preview1" "fd_close" (func $fd_close (param i32) (result i32))) |
| 4 | + (import "wasi_snapshot_preview1" "fd_filestat_get" (func $fd_filestat_get (param i32 i32) (result i32))) |
| 5 | + |
| 6 | + (memory 1 1) |
| 7 | + (data (i32.const 100) "./fd_filestat_get.wast") |
| 8 | + |
| 9 | + (func (export "fd_filestat_get") (result i32 i32 i32) |
| 10 | + i32.const 3 ;; Directory file descriptior, by default 3 is the first opened directory |
| 11 | + i32.const 1 ;; uvwasi_lookupflags_t: UVWASI_LOOKUP_SYMLINK_FOLLOW |
| 12 | + i32.const 100 ;; Offset of file name in memory |
| 13 | + i32.const 23 ;; Length of file name |
| 14 | + i32.const 0 ;; uvwasi_oflags_t: none |
| 15 | + i64.const 0x202000 ;; base uvwasi_rights_t: UVWASI_RIGHT_PATH_OPEN, UVWASI_RIGHT_FD_FILESTAT_GET |
| 16 | + i64.const 0x202000 ;; inherited uvwasi_rights_t: UVWASI_RIGHT_PATH_OPEN, UVWASI_RIGHT_FD_FILESTAT_GET |
| 17 | + i32.const 0 ;; uvwasi_fdflags_t: none |
| 18 | + i32.const 0 ;; Offset to store at the opened file descriptor in memory |
| 19 | + call $path_open |
| 20 | + |
| 21 | + i32.const 0 |
| 22 | + i32.load |
| 23 | + i32.const 1000 |
| 24 | + call $fd_filestat_get |
| 25 | + |
| 26 | + i32.const 0 |
| 27 | + i32.load |
| 28 | + call $fd_close |
| 29 | + ) |
| 30 | + |
| 31 | + (func (export "fd_filestat_get_bad") (result i32 i32 i32 i32) |
| 32 | + i32.const 3 ;; Directory file descriptior, by default 3 is the first opened directory |
| 33 | + i32.const 1 ;; uvwasi_lookupflags_t: UVWASI_LOOKUP_SYMLINK_FOLLOW |
| 34 | + i32.const 100 ;; Offset of file name in memory |
| 35 | + i32.const 23 ;; Length of file name |
| 36 | + i32.const 0 ;; uvwasi_oflags_t: none |
| 37 | + i64.const 0x202000 ;; base uvwasi_rights_t: UVWASI_RIGHT_PATH_OPEN, UVWASI_RIGHT_FD_FILESTAT_GET |
| 38 | + i64.const 0x202000 ;; inherited uvwasi_rights_t: UVWASI_RIGHT_PATH_OPEN, UVWASI_RIGHT_FD_FILESTAT_GET |
| 39 | + i32.const 0 ;; uvwasi_fdflags_t: none |
| 40 | + i32.const 0 ;; Offset to store at the opened file descriptor in memory |
| 41 | + call $path_open |
| 42 | + |
| 43 | + i32.const 0 |
| 44 | + i32.load |
| 45 | + i32.const 65535 |
| 46 | + call $fd_filestat_get |
| 47 | + |
| 48 | + i32.const -1 |
| 49 | + i32.const 1000 |
| 50 | + call $fd_filestat_get |
| 51 | + |
| 52 | + i32.const 0 |
| 53 | + i32.load |
| 54 | + call $fd_close |
| 55 | + ) |
| 56 | +) |
| 57 | + |
| 58 | +(assert_return (invoke "fd_filestat_get") (i32.const 0) (i32.const 0) (i32.const 0)) |
| 59 | +(assert_return (invoke "fd_filestat_get_bad") (i32.const 0) (i32.const 28) (i32.const 8) (i32.const 0)) |
0 commit comments