问题描述
嗨,我正在尝试使用 dart ffi,但我遇到了以下转储问题
===== 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)
我不确定如何更好地了解导致错误的原因,因为它感觉有点神秘。
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 胶水代码
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,);
void wasm_instance_exports(
ffi.Pointer<wasm_instance_t> arg0,) {
_wasm_instance_exports ??= _dylib.lookupFunction<_c_wasm_instance_exports,_dart_wasm_instance_exports>('wasm_instance_exports');
return _wasm_instance_exports(
arg0,out,);
}
是的,我可以参考有关调查这些崩溃的任何资源吗?
##edit##
api 是一个从 rust wasmer 项目中导出的 C api
导出的标题是
#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 实现是在
更详细的代码
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;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)