hi again all, I'm trying to get WASI code working in the browser. I'm using the following example code (minimal example):
#include <stdio.h>
int main(int argc, const char** argv)
{
FILE* f = fopen("file.txt", "wb");
fprintf(f, "%s", "Hello World!\n");
fclose(f);
return 0;
}
The program works fine when compiled natively, and when compiled to wasm and run inside wasmtime. But when I try to run it inside either Chromium or Firefox, I get an exception. From Chromium (which seems to find more debug info):
Uncaught (in promise) RuntimeError: function signature mismatch
at fclose (wasm-function[85]:0x19097)
at main (wasm-function[15]:0x468)
(...)
Poking around some more in the debugger, it looks like that error corresponds to this line inside the implementation of fclose(), in the sysroot that I'm using: (I don't immediately see a function signature mismatch here, but function pointers are weird so...)
r |= f->close(f);
The code works fine if I comment out the fclose() call (but presumably leaks the file handle -- doesn't matter in this trivial example but not ideal for real code :-) )
Anyway, I don't suppose anyone has any idea what's up?
Last updated: Dec 06 2025 at 05:03 UTC