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. barwasmtime 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.
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".
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. barwasmtime 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.
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")
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:
- kubkon: wasi
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
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 aniovec
, but I suspect I need to encode the integer into a UTF-8 format first.
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 aniovec
, but I suspect I need to encode the integer into a UTF-8 format first.
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: Dec 23 2024 at 13:07 UTC