Stream: git-wasmtime

Topic: wasmtime / Issue #1547 fd_write not printing to stdout


view this post on Zulip Wasmtime GitHub notifications bot (Apr 17 2020 at 20:16):

vedantroy edited Issue #1547:

Run the following file in wasmtime 0.15.0 and in whatever version of wasmer is installed with curl https://get.wasmer.io -sSfL | sh

wasmer prints the expected output:

no foo.
bar

wasmtime prints nothing

;; Taken from: https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-tutorial.md and modified
(module
    (import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))

    (memory 1)

    (data (i32.const 1024) "no foo.\nbar\n")

    (func $print_msg (param $array_ptr i32)
        (call $fd_write
          (i32.const 1) ;; file descriptor
          (local.get $array_ptr) ;; pointer to first iovec in array
          (i32.const 1) ;; len of array
          (i32.const 2048) ;; place to write number of bytes written
        )
        drop
    )

    (func $main (export "_start")
        ;; Creating a new io vector within linear memory
        (i32.store (i32.const 0) (i32.const 1024))
        (i32.store (i32.const 4) (i32.const 8))

        (i32.store (i32.const 8) (i32.const 1032))
        (i32.store (i32.const 12) (i32.const 4))

        (call $print_msg (i32.const 0))
        (call $print_msg (i32.const 8))
    )
)

I assume the issue is with wasmtime.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 17 2020 at 20:19):

vedantroy commented on Issue #1547:

Thank you for the explanation. What is the difference between (memory (export "memory") 1) and

(memory 1)
(export "memory" (memory 0))

I assume the 2nd one does the same thing, because (memory 1) indicates "give this program 1 page of memory" while (export "memory" (memory 0)) indicates "export the memory starting at location 0".

view this post on Zulip Wasmtime GitHub notifications bot (Apr 17 2020 at 20:20):

vedantroy closed Issue #1547:

Run the following file in wasmtime 0.15.0 and in whatever version of wasmer is installed with curl https://get.wasmer.io -sSfL | sh

wasmer prints the expected output:

no foo.
bar

wasmtime prints nothing

;; Taken from: https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-tutorial.md and modified
(module
    (import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))

    (memory 1)

    (data (i32.const 1024) "no foo.\nbar\n")

    (func $print_msg (param $array_ptr i32)
        (call $fd_write
          (i32.const 1) ;; file descriptor
          (local.get $array_ptr) ;; pointer to first iovec in array
          (i32.const 1) ;; len of array
          (i32.const 2048) ;; place to write number of bytes written
        )
        drop
    )

    (func $main (export "_start")
        ;; Creating a new io vector within linear memory
        (i32.store (i32.const 0) (i32.const 1024))
        (i32.store (i32.const 4) (i32.const 8))

        (i32.store (i32.const 8) (i32.const 1032))
        (i32.store (i32.const 12) (i32.const 4))

        (call $print_msg (i32.const 0))
        (call $print_msg (i32.const 8))
    )
)

I assume the issue is with wasmtime.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 17 2020 at 20:21):

alexcrichton commented on Issue #1547:

Oh one is just shorthand for the other. The (export "memory" (memory 0)) isn't necessarily exporting a memory that starts at 0, but rather exports the 0th memory (memory index zero), which in this case was defined by (memory 1) (which was indeed "define a memory with at least one page in size")

view this post on Zulip Wasmtime GitHub notifications bot (Apr 17 2020 at 20:35):

github-actions[bot] commented on Issue #1547:

Subscribe to Label Action

cc @kubkon

<details>
This issue or pull request has been labeled: "wasi"

Thus the following users have been cc'd because of the following labels:

To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.

Learn more.
</details>

view this post on Zulip Wasmtime GitHub notifications bot (Apr 17 2020 at 22:15):

vedantroy commented on Issue #1547:

@alexcrichton For future reference, what would be an easy way to print out the error coder returned by $fd_write(or any other wasi system call)? I could try storing the integer in an array pointed to by an iovec, but I suspect I need to encode the integer into a UTF-8 format first.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 17 2020 at 22:15):

vedantroy edited a comment on Issue #1547:

@alexcrichton This question is off topic, but I would greatly appreciate if you could answer it. What would be an easy way to print out the error coder returned by $fd_write(or any other wasi system call)? I could try storing the integer in an array pointed to by an iovec, but I suspect I need to encode the integer into a UTF-8 format first.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 17 2020 at 22:18):

alexcrichton commented on Issue #1547:

Ah yeah currently WASI has no way to print an integer, so there's not really an easy way to do that with *.wat. At that point you'd probably want to use a source language like Rust/C/etc.


Last updated: Nov 22 2024 at 16:03 UTC