0

Hi i'm experimenting with dart ffi and i'm having an issue with the following dump


===== CRASH =====
si_signo=Segmentation fault(11), si_code=1, si_addr=(nil)
version=2.12.0-157.0.dev (dev) (Wed Dec 16 01:04:40 2020 -0800) on "linux_x64"
pid=262571, thread=262578, isolate_group=main(0x373e8c0), isolate=main(0x373f140)
isolate_instructions=17fde20, vm_instructions=17fde20
  pc 0x00007f1633a00543 fp 0x00007f1656c1d540 wasm_instance_exports+0x13
  pc 0x00007f163ce30505 fp 0x00007f1656c1d578 Unknown symbol
  pc 0x00007f163ce3023f fp 0x00007f1656c1d5e0 Unknown symbol
  pc 0x00007f163ce25553 fp 0x00007f1656c1d6b8 Unknown symbol
  pc 0x00007f163ce2453c fp 0x00007f1656c1d700 Unknown symbol
  pc 0x00007f163ce24233 fp 0x00007f1656c1d728 Unknown symbol
  pc 0x00007f163ce2419f fp 0x00007f1656c1d750 Unknown symbol
  pc 0x00007f163ce240cf fp 0x00007f1656c1d7a8 Unknown symbol
  pc 0x00007f163ce2300e fp 0x00007f1656c1d7d8 Unknown symbol
  pc 0x00007f163ce22d72 fp 0x00007f1656c1d838 Unknown symbol
  pc 0x00007f163ce2276e fp 0x00007f1656c1d870 Unknown symbol
  pc 0x00007f1656d8265f fp 0x00007f1656c1d8e8 Unknown symbol
-- End of DumpStackTrace
[exit     : sp(0) fp(0x7f1656c1d540) pc(0)]
[dart     : sp(0x7f1656c1d550) fp(0x7f1656c1d578) pc(0x7f163ce30505) *dart:ffi_::_FfiTrampoline ]
[dart     : sp(0x7f1656c1d588) fp(0x7f1656c1d5e0) pc(0x7f163ce3023f) file:///home/kingwill101/code/wasm-dart/generated_bindings.dart_Wasmer_wasm_instance_exports ]
[dart     : sp(0x7f1656c1d5f0) fp(0x7f1656c1d6b8) pc(0x7f163ce25553) file:///home/kingwill101/code/wasm-dart/bin/main.dart_::_helloWorld__async_op ]
[dart     : sp(0x7f1656c1d6c8) fp(0x7f1656c1d700) pc(0x7f163ce2453c) file:///home/kingwill101/code/wasm-dart/bin/main.dart_::_helloWorld ]
[dart     : sp(0x7f1656c1d710) fp(0x7f1656c1d728) pc(0x7f163ce24233) file:///home/kingwill101/code/wasm-dart/bin/main.dart_::_main ]
[dart     : sp(0x7f1656c1d738) fp(0x7f1656c1d750) pc(0x7f163ce2419f) file:///home/kingwill101/code/wasm-dart/bin/main.dart_::_main_main ]
[dart     : sp(0x7f1656c1d760) fp(0x7f1656c1d7a8) pc(0x7f163ce240cf) dart:core__Closure@0150898_dyn_call ]
[dart     : sp(0x7f1656c1d7b8) fp(0x7f1656c1d7d8) pc(0x7f163ce2300e) dart:isolate_::__delayEntrypointInvocation@1026248_<anonymous closure> ]
[dart     : sp(0x7f1656c1d7e8) fp(0x7f1656c1d838) pc(0x7f163ce22d72) dart:core__Closure@0150898_dyn_call ]
[dart     : sp(0x7f1656c1d848) fp(0x7f1656c1d870) pc(0x7f163ce2276e) dart:isolate__RawReceivePortImpl@1026248__handleMessage@1026248 ]
[entry    : sp(0x7f1656c1d880) fp(0x7f1656c1d8e8) pc(0x7f1656d8265f)]
Aborted (core dumped)

I'm not sure how to get a better output of what exactly is causing the errors as it feels a bit cryptic.

Code crashes here

 Pointer<wasm_extern_vec_t> exports = allocate<wasm_extern_vec_t>();
  w.wasm_extern_vec_new_empty(exports);
  w.wasm_instance_exports(instance, exports);

ffi glue code

typedef _c_wasm_instance_exports = ffi.Void Function(
  ffi.Pointer<wasm_instance_t> arg0,
  ffi.Pointer<wasm_extern_vec_t> out,
);

typedef _dart_wasm_instance_exports = void Function(
  ffi.Pointer<wasm_instance_t> arg0,
  ffi.Pointer<wasm_extern_vec_t> out,
);

void wasm_instance_exports(
    ffi.Pointer<wasm_instance_t> arg0,
    ffi.Pointer<wasm_extern_vec_t> out,
  ) {
    _wasm_instance_exports ??= _dylib.lookupFunction<_c_wasm_instance_exports,
        _dart_wasm_instance_exports>('wasm_instance_exports');
    return _wasm_instance_exports(
      arg0,
      out,
    );
  }

So yeah, are there any resources i can refer to about investigating these crashes?

##edit##

The api is a C exported api from the rust wasmer project

exported header is

#ifndef WASM_API_EXTERN
#ifdef _WIN32
#define WASM_API_EXTERN __declspec(dllimport)
#else
#define WASM_API_EXTERN
#endif
#endif

WASM_API_EXTERN void wasm_instance_exports(const wasm_instance_t*, own wasm_extern_vec_t* out);

rust implementation is at

https://github.com/wasmerio/wasmer/blob/0a4a2c7d24d718e48eb9aa895292d3cbf950f7ed/lib/c-api/src/wasm_c_api/instance.rs#L178

more detailed code

Pointer<wasm_byte_vec_t> wat = allocate<wasm_byte_vec_t>() ;
  Pointer<wasm_byte_vec_t> wasm_bytes  = allocate<wasm_byte_vec_t>();

  w.wasm_byte_vec_new(wat, code.length, Utf8.toUtf8(code).cast());
  w.wat2wasm(wat, wasm_bytes);

  var engine = w.wasm_engine_new();
  var store = w.wasm_store_new(engine);
  var module = w.wasm_module_new(store, wasm_bytes);

  if (module == nullptr) {
    print("> Error compiling module!\n");
    return;
  }

  w.wasm_byte_vec_delete(wasm_bytes);

  Pointer<wasm_extern_vec_t> imports = allocate<wasm_extern_vec_t>();
  w.wasm_extern_vec_new_empty(imports);

 var  instance = w.wasm_instance_new(store, module, imports, nullptr);

  if (instance != nullptr) {
    print("> Error instantiating module %d!\n");

    return ;
  }
  //
 Pointer<wasm_extern_vec_t> exports = allocate<wasm_extern_vec_t>();
  w.wasm_extern_vec_new_empty(exports);
  w.wasm_instance_exports(instance, exports);
  
  if (exports.ref.size == 0) {
    print("> Error accessing exports!\n");
  
    return;
  }
kignwill101
  • 133
  • 5

0 Answers0