Wasmer: Error in running wasm (siglongjmp)

Created on 22 Sep 2020  路  4Comments  路  Source: wasmerio/wasmer

Describe the bug

I am trying to run a complied emscripten wasm file, however, I get an error message. The wasm file runs fine with the accompanied autogenerated JavaScript file.

wasmer run file.wasm

Steps to reproduce

I should be able to upload this on Github if it helps

Expected behavior

The wasm should run by printing some information and waiting for input

Actual behavior

Error while importing "env"."siglongjmp": unknown import. Expected Function(FunctionType { params: [I32, I32], results: [] })

Context

The autogenerated emscripten javascript has the following asm functions:

var asmLibraryArg = {
  __asctime_r: ___asctime_r,
  __assert_fail: ___assert_fail,
  __clock_gettime: ___clock_gettime,
  __indirect_function_table: wasmTable,
  __localtime_r: ___localtime_r,
  __sys_access: ___sys_access,
  __sys_chdir: ___sys_chdir,
  __sys_dup2: ___sys_dup2,
  __sys_dup3: ___sys_dup3,
  __sys_fcntl64: ___sys_fcntl64,
  __sys_fstat64: ___sys_fstat64,
  __sys_getcwd: ___sys_getcwd,
  __sys_getdents64: ___sys_getdents64,
  __sys_getpid: ___sys_getpid,
  __sys_getrusage: ___sys_getrusage,
  __sys_getuid32: ___sys_getuid32,
  __sys_ioctl: ___sys_ioctl,
  __sys_open: ___sys_open,
  __sys_pipe: ___sys_pipe,
  __sys_read: ___sys_read,
  __sys_readlink: ___sys_readlink,
  __sys_rmdir: ___sys_rmdir,
  __sys_stat64: ___sys_stat64,
  __sys_unlink: ___sys_unlink,
  __sys_wait4: ___sys_wait4,
  __wait: ___wait,
  abort: _abort,
  atexit: _atexit,
  clock: _clock,
  emscripten_longjmp: _emscripten_longjmp,
  emscripten_memcpy_big: _emscripten_memcpy_big,
  emscripten_resize_heap: _emscripten_resize_heap,
  endpwent: _endpwent,
  environ_get: _environ_get,
  environ_sizes_get: _environ_sizes_get,
  execve: _execve,
  exit: _exit,
  fd_close: _fd_close,
  fd_fdstat_get: _fd_fdstat_get,
  fd_read: _fd_read,
  fd_seek: _fd_seek,
  fd_write: _fd_write,
  fork: _fork,
  ftime: _ftime,
  getTempRet0: _getTempRet0,
  getpwent: _getpwent,
  getpwnam: _getpwnam,
  getpwuid: _getpwuid,
  invoke_i: invoke_i,
  invoke_ii: invoke_ii,
  invoke_iii: invoke_iii,
  invoke_iiii: invoke_iiii,
  invoke_iiiii: invoke_iiiii,
  invoke_iiiiii: invoke_iiiiii,
  invoke_iiiiiiiii: invoke_iiiiiiiii,
  invoke_v: invoke_v,
  invoke_vi: invoke_vi,
  invoke_viii: invoke_viii,
  kill: _kill,
  memory: wasmMemory,
  setTempRet0: _setTempRet0,
  siglongjmp: _siglongjmp,
  signal: _signal,
  sysconf: _sysconf,
  system: _system,
  time: _time,
  usleep: _usleep,
};
馃悶 bug 馃摝 lib-emscripten

Most helpful comment

@danchitnis That demo implemented longjmp using asyncify - a way to work around current wasm limitations. It ran on any VM.

Otherwise, siglongjmp is the same as longjmp. If wasmer supports the latter, doing the same for siglongjmp should work.

All 4 comments

Thanks for letting us know! I thought the issue might be that this is using a version of emscripten that's too new, we generally support 1.38.43 and earlier right now; supporting later versions isn't necessarily hard but there's no simple way to identify which version of Emscripten was used to compile the Wasm module and there are differences with every release. Emscripten Wasm is pretty tightly coupled to the generated Emscripten JavaScript in a fundamental way so it's not a high priority for us at the moment. But also it looks like we're definitely missing siglongjmp in our Emscripten implementation.

If anyone is interested in picking up this issue, it should be as simple as translating the generated JS for that syscall into Rust. As it's some kind of longjmp, it might be a bit tricky, but feel free to ping me if you need help with it.

As for @danchitnis , you may have better luck with WASI if your code can be compiled to WASI Wasm. WASI is a more stable ABI and we're prioritizing 100% support for it.

@MarkMcCaskey Thanks for looking into this. It seem that setjmp/longjmp are not implemented in WASI yet.

@MarkMcCaskey I noticed that @kripken gives a demo at the end of his talk that uses wasmer with longjmp. Not sure if this was a custom configuration or default wasmer.

@danchitnis That demo implemented longjmp using asyncify - a way to work around current wasm limitations. It ran on any VM.

Otherwise, siglongjmp is the same as longjmp. If wasmer supports the latter, doing the same for siglongjmp should work.

Was this page helpful?
0 / 5 - 0 ratings