Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does WASI stdio work? #15

Open
konsumer opened this issue Sep 25, 2023 · 2 comments
Open

Does WASI stdio work? #15

konsumer opened this issue Sep 25, 2023 · 2 comments

Comments

@konsumer
Copy link

konsumer commented Sep 25, 2023

I am using this to route WASI calls to web49_api_wasi

web49_env_func_t web49_main_import_func(void* state, const char* mod, const char* func) {
  printf("called: %s.%s\n", mod, func);

  if (strcmp(mod, "null0") == 0) {
    return web49_api_null0(state, mod, func);
  } else if (strcmp(mod, "wasi_snapshot_preview1") == 0) {
    return web49_api_wasi(state, mod, func);
  }
  fprintf(stderr, "Unhandled import: %s.%s\n", mod, func);
  return NULL;
}

and for a printf from the wasm, it seems to just output huge chunks of memory. Do I need to put more in state?

@konsumer
Copy link
Author

konsumer commented Sep 25, 2023

Ah, I see this I will try to set it up.

Update: still seems to be a problem.

extern const char** environ;
const char** args;

args = argv + 1;
web49_wasi_t* wasi = web49_wasi_new(args, environ);
web49_interp_add_import_func(&interp, wasi, &web49_main_import_func);

@konsumer
Copy link
Author

konsumer commented Sep 25, 2023

Even compiling miniwasm and running on this code:

#include "stdio.h"

int main() {
  printf("hello!\n");
  printf("You should see a newline at end of both of these lines, and no memory-dump.\n");
  return 0;
}

compiled like this:

clang test.c --target=wasm32-wasi --sysroot=${WASI_SYSROOT} -Oz -std=c11 -o test.wasm

does not output newlines:

./bin/miniwasm test.wasm
hello!You should see a newline at end of both of these lines, and no memory-dump.

Versions:

(in debian:latest docker)
Linux deda87241c50 5.15.49-linuxkit #1 SMP PREEMPT Tue Sep 13 07:51:32 UTC 2022 aarch64 GNU/Linux
Debian clang version 14.0.6
Mac M1 running 13.5.2 (22G91)
Apple clang version 14.0.0 (clang-1400.0.29.202)

@konsumer konsumer changed the title Does WASI fs stuff work? Does WASI stdio work? Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant