Showing detailed dumps - dart

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;
}

Related

Yaml File Format used in OpenCV

Here is a example (part of code) from OpenCV (https://docs.opencv.org/3.4.0/d4/da4/group__core__xml.html):
test.yml
%YAML:1.0
---
frameCount: 5
read.cpp
#include "opencv2/opencv.hpp"
#include <time.h>
using namespace cv;
using namespace std;
int main()
{
FileStorage fs("test.yml", FileStorage::READ);
int frameCount = (int) fs["frameCount"];
cout << frameCount << endl;
return 0;
}
Given the code, it works well and reads the yaml file. But when I remove %YAML:1.0, the code throws:
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/pengfei/Documents/opencv-3.3.1/modules/core/src/persistence.cpp, line 4484
terminate called after throwing an instance of 'cv::Exception'
what(): /home/pengfei/Documents/opencv-3.3.1/modules/core/src/persistence.cpp:4484: error: (-49) Input file is empty in function cvOpenFileStorage
[1] 27146 abort (core dumped) ./Read
But I checked the yaml.org. There is no rule stating %YAML:1.0 is necessary. (http://yaml.org/start.html)
**My questions are (updated according to answer from #zindarod ): **
1. Is this OpenCV specific feature??
Yes, this is OpenCV specific requirment.
const char* yaml_signature = "%YAML";
const char* json_signature = "{";
const char* xml_signature = "<?xml";
OpenCV checks the file signature, then decide how to interpret the file.
2. How to know the yaml version I should use??
The yaml verison doesn't matter too much.
But it's better to use 1.0 specification. Probably OpenCV cannot parse other new specifications.
In OpenCV-3.3.1 in function cvOpenFileStorage located at /modules/core/src/persistence.cpp:
...
else
{
if( mem )
{
fs->strbuf = filename;
fs->strbufsize = fnamelen;
}
size_t buf_size = 1 << 20;
const char* yaml_signature = "%YAML";
const char* json_signature = "{";
const char* xml_signature = "<?xml";
char buf[16];
icvGets( fs, buf, sizeof(buf)-2 );
char* bufPtr = cv_skip_BOM(buf);
size_t bufOffset = bufPtr - buf;
if(strncmp( bufPtr, yaml_signature, strlen(yaml_signature) ) == 0)
fs->fmt = CV_STORAGE_FORMAT_YAML;
else if(strncmp( bufPtr, json_signature, strlen(json_signature) ) == 0)
fs->fmt = CV_STORAGE_FORMAT_JSON;
else if(strncmp( bufPtr, xml_signature, strlen(xml_signature) ) == 0)
fs->fmt = CV_STORAGE_FORMAT_XML;
else if(fs->strbufsize == bufOffset)
CV_Error(CV_BADARG_ERR, "Input file is empty");
...
OpenCV checks for file signature (json, yaml and xml). The version of YAML does not matter, as long as the first line contains the string "%YAML" in it.

Ocaml : segfault at GC when using a custom block containing a C pointer

I am trying to create a binding between a C library and an Ocaml program. I have encountered a problem when interfacing with the Gc.
I made a small program to duplicate my problem.
The objective is to pass a custom_block allocated in the C program and containing a pointer on a C structure to the main program in Ocaml.
Then, I am trying to use it (just printing a value in the example) before cleaning (I force a call to the GC).
In the main program below in ocaml, I can either comment the line "my_print_block" or the line "Gc.compact()" and everything works fine.The address of the pointer is correct, I can print the value and the destructor is called to free the C allocated pointer.
But when the two are activated, I get a segmentation fault.
Mail.ml
type ptr
external create_block: String.t -> ptr = "create_block"
external print_block: ptr -> unit = "print_block"
let my_print_block x :unit =
print_block x;
()
let main () =
let z = create_block "2.4" in
let _ = my_print_block z in
let () = Gc.compact () in
()
let _ = main ()
Interface.c
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/alloc.h>
#include <caml/custom.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct foo
{
float x;
};
void local_destroy(value v)
{
struct foo* p = *((struct foo**)Data_custom_val(v));
printf( "freeing p now (%p)\n with *p=%f \n", p, p->x );
fflush(stdout);
free(p);
}
static struct custom_operations ops = {
"ufpa custom_operations",
local_destroy,
custom_compare_default, //default function, should not be used
custom_hash_default, //default function, should not be used
custom_serialize_default, //default function, should not be used
custom_deserialize_default, //default function, should not be used
custom_compare_ext_default //default function, should not be used
};
void print_block(value type_str)
{
CAMLparam1(type_str);
struct foo* p = *( (struct foo**)Data_custom_val(type_str));
printf("value float = %f\n", p->x);
}
CAMLprim value create_block(value type_str)
{
CAMLparam1(type_str);
//retrieving str and creating a float value
char* fval = String_val(type_str);
float val = atof(fval);
//creating and allocating a custom_block
CAMLlocal1(res);
res = alloc_custom(&ops, sizeof(struct foo*), 10, 100);
//creating and allocating a struct pointer
struct foo* ptr = malloc(sizeof(struct foo));
printf("allocating : %p\n", ptr);
ptr->x = val;
//copying the pointer itself in the custom block
memcpy(Data_custom_val(res), &ptr, sizeof(struct foo*));
CAMLreturn(res);
}
Makefile
main.native: interface.c main.ml
rm -rf _build
rm -f main.native main.byte
ocamlbuild -cflags -g interface.o
ocamlbuild -lflag -custom -cflags -g -lflags -g main.byte -lflags interface.o
#ocamlbuild -cflags -g -lflags -g main.native -lflags interface.o
With ocamldebug, the program seems to crash on my_print_block but I wasn't able to extract more sense from the trace.
With gdb, the error is located in the Gc
#0 0x000000000040433d in caml_oldify_one ()
#1 0x0000000000406060 in caml_oldify_local_roots ()
#2 0x000000000040470f in caml_empty_minor_heap ()
#3 0x00000000004141ca in caml_gc_compaction ()
#4 0x000000000041bfd0 in caml_interprete ()
#5 0x000000000041df48 in caml_main ()
#6 0x000000000040234c in main ()
I have seen several examples and I have read the documentation about C bindings at https://caml.inria.fr/pub/docs/manual-ocaml/intfc.html but I couldn't figure what am I doing wrong. I am using ocaml version4.04.0+flambda
Thank you for your assistance
Your print_block function uses CAMLparam1() so it should return with CAMLreturn0. I'm not sure this is your problem, it's just something I noticed. But it might be the problem.

NMAKE : fatal error U1077 while building OpenBR

I'm trying to build OpenBR, I followed the steps on http://openbiometrics.org/docs/install/#windows but I get stuck on this. The first time I used nmake, I got to 19%. Last week it worked on another computer
(thesame compiler, cmd, ...). It broke down now I have to rebuild it. I've been looking for over 15 hours now.
C:\openbr\build-msvc2013>nmake
Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
Copyright (C) Microsoft Corporation. All rights reserved.
[ 2%] Built target models
[ 3%] Automatic moc for target openbr
[ 3%] Built target openbr_automoc
[ 4%] Building CXX object openbr/CMakeFiles/openbr.dir/plugins/classification/cascade_classifier.cpp.obj
cascade_classifier.cpp
C:\openbr\openbr\plugins\classification\cascade_classifier.cpp(229) : error C2660: 'br::Classifier::train' : function does not take 1 arguments
NMAKE : fatal error U1077: 'C:\PROGRA~2\MICROS~2.0\VC\bin\X86_AM~1\cl.exe' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.
This is the part where it goes wrong:
void train(const TemplateList &data)
{
foreach (const Template &t, data)
t.file.get<float>("Label") == 1.0f ? posImages.append(t) : negImages.append(t);
qDebug() << "Total images:" << data.size()
<< "\nTotal positive images:" << posImages.size()
<< "\nTotal negative images:" << negImages.size();
posIndices = Common::RandSample(posImages.size(), posImages.size(), true);
negIndices = Common::RandSample(negImages.size(), negImages.size(), true);
stages.reserve(numStages);
for (int i = 0; i < numStages; i++) {
qDebug() << "===== TRAINING" << i << "stage =====";
qDebug() << "<BEGIN";
Classifier *next_stage = Classifier::make(stageDescription, NULL);
stages.append(next_stage);
float currFAR = getSamples();
if (currFAR < maxFAR && !requireAllStages) {
qDebug() << "FAR is below required level! Terminating early";
return;
}
stages.last()->train(posSamples + negSamples);
qDebug() << "END>";
}
}
This is the whole file:
https://github.com/biometrics/openbr/blob/master/openbr/plugins/classification/cascade_classifier.cpp

Lua module with Visual Studio

I'm trying to make a Lua module with Visual Studio 2013, the main ccp is here along with the module.hpp and the other include is here.
I changed the main ccp to remove a unneeded include file and two unneeded functions so I get this:
#include <lua.hpp>
#include <GeoIP.h>
#include "module.hpp"
static GeoIP * geoip = NULL;
static int load_geoip_database(lua_State * L)
{
const char * filename = luaL_checkstring(L, 1);
if (geoip) GeoIP_delete(geoip);
geoip = GeoIP_open(filename, GEOIP_MEMORY_CACHE);
lua_pushboolean(L, geoip != NULL);
return 1;
}
static int ip_to_country(lua_State * L)
{
if (!geoip) return luaL_error(L, "missing GeoIP database");
const char * ipaddr = luaL_checkstring(L, 1);
const char * country = GeoIP_country_name_by_addr(geoip, ipaddr);
lua_pushstring(L, (country ? country : ""));
return 1;
}
static int ip_to_country_code(lua_State * L)
{
if (!geoip) return luaL_error(L, "missing GeoIP database");
const char * ipaddr = luaL_checkstring(L, 1);
const char * code = GeoIP_country_code_by_addr(geoip, ipaddr);
lua_pushstring(L, (code ? code : ""));
return 1;
}
static int shutdown_geoip(lua_State * L)
{
GeoIP_delete(geoip);
geoip = NULL;
return 0;
}
namespace lua{
namespace module{
void open_geoip(lua_State * L)
{
static luaL_Reg functions[] = {
{ "load_geoip_database", load_geoip_database },
{ "ip_to_country", ip_to_country },
{ "ip_to_country_code", ip_to_country_code },
{ NULL, NULL }
};
luaL_register(L, "geoip", functions);
lua_pop(L, 1);
lua::on_shutdown(L, shutdown_geoip);
}
} //namespace module
} //namespace lua
Visual Studio throws me the following errors:
1>------ Build started: Project: GeoIP, Configuration: Release Win32 ------
1> Main.cpp
1>Main.obj : error LNK2001: unresolved external symbol _GeoIP_delete
1>Main.obj : error LNK2001: unresolved external symbol _luaL_checklstring
1>Main.obj : error LNK2001: unresolved external symbol _luaL_register
1>Main.obj : error LNK2001: unresolved external symbol _lua_pushstring
1>Main.obj : error LNK2001: unresolved external symbol _GeoIP_country_name_by_addr
1>Main.obj : error LNK2001: unresolved external symbol _lua_settop
1>Main.obj : error LNK2001: unresolved external symbol "void __cdecl lua::on_shutdown(struct lua_State *,int (__cdecl*)(struct lua_State *))" (?on_shutdown#lua##YAXPAUlua_State##P6AH0#Z#Z)
1>Main.obj : error LNK2001: unresolved external symbol _GeoIP_country_code_by_addr
1>Main.obj : error LNK2001: unresolved external symbol _GeoIP_open
1>Main.obj : error LNK2001: unresolved external symbol _luaL_error
1>Main.obj : error LNK2001: unresolved external symbol _lua_pushboolean
1>C:\Users\User\Documents\Visual Studio 2013\Projects\Win32Project1\Release\GeoIP_win32.dll : fatal error LNK1120: 11 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
and I dont know what the errors are meaning, the module has been built before by others so the code should be OK.
Looks like you forgot to configure your build so the linker knows what libraries to link to your module. Looks like you should link to GeoIP DLL and, of course, the Lua DLL. In the project's Properties dialog, look for Linker | General | Additional Library Directories, it must indicate the folder where your Lua DLL is located, and the folder where the GeoIP DLL is located. Then look at Linker | Input | Additional Dependencies, it must indicate the name of the Lua export lib for the Lua DLL (such as lua51.lib), and same for GeoIP (something like libgeoip.lib).

Network stats gatherer (loadable kernel module) isn't working?

I'm kinda new to linux kernel modules and I'm trying to write my own module that gives me some statistics about a device ( the NIC here).
although I'm using kernel 2.6.35 and I've included linux/netdevices, compiling keeps saying that the function ndo_get_stats is implicitly declared. can anyone tell me what's going on ?
here's the module, simple I know,
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/netdevice.h> /* Needed for netdevice*/
static int __init hello_start(void)
{
struct net_device *dev;
struct net_device_stats *devstats;
printk(KERN_INFO "Loading Stats module...\n");
printk(KERN_ALERT "Hello world\n");
dev = first_net_device(&init_net);
while (dev)
{
printk(KERN_INFO "found [%s] and it's [%d]\n", dev->name, dev->flags & IFF_UP);
printk(KERN_INFO "End of dev struct ... now starts the get_stats struct\n");
devstats = ndo_get_stats(dev);
printk(KERN_INFO "recive errors: [%li]\n transmission errors: [%li]\n number of collisions: [%li]", devstats->rx_errors , devstats->tx_errors, devstats->collisions);
dev = next_net_device(dev);
}
return 0;
}
static void __exit hello_end(void)
{
printk(KERN_ALERT "Goodbye.\n");
}
module_init(hello_start);
module_exit(hello_end);

Resources