github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/experimental/logging/testdata/listener.wat (about)

     1  (module $listener
     2    (import "wasi_snapshot_preview1" "random_get"
     3      (func $wasi.random_get (param $buf i32) (param $buf_len i32) (result (;errno;) i32)))
     4  
     5    (import "wasi_snapshot_preview1" "fd_write"
     6      (func $wasi.fd_write (param $fd i32) (param $iovs i32) (param $iovs_len i32) (param $result.size i32) (result (;errno;) i32)))
     7  
     8    (table 8 funcref) ;; Define a function table with a single element at index 3.
     9    (elem (i32.const 3) $wasi.random_get)
    10  
    11    (memory 1 1) ;; Memory is needed for WASI
    12  
    13    (func $wasi_rand (param $len i32)
    14      ;; call fd_write with an unsampled FD, inside a sampled function.
    15      i32.const 1 ;; $fd = stdout
    16      i32.const 0 i32.const 0 i32.const 0 ;; $iovs, $iovs_len $result.size = 0.
    17      call $wasi.fd_write
    18      drop ;; errno
    19  
    20      i32.const 4 local.get 0 ;; buf, buf_len
    21      call $wasi.random_get
    22      drop ;; errno
    23  
    24      i32.const 8 local.get 0 ;; buf, buf_len
    25      i32.const 3 call_indirect (type 0) ;; element 3, func type 0
    26      drop ;; errno
    27    )
    28  
    29    (func $rand (export "rand") (param $len i32)
    30      local.get 0 ;; buf_len
    31      call $wasi_rand
    32    )
    33  )