Skip to content

examples/python/basic.py segfault when using shared lib (ctypes) #11

@jtakakura

Description

@jtakakura

Description

Python ctypes example crashes with SIGSEGV when invoking a simple exported wasm function.

Steps to reproduce

  • Build shared library: zig build lib
  • Run example: python3 examples/python/basic.py
  • Observed: immediate SIGSEGV (core dump)

zwasm version

1.6.0 (d83c0ff)

Platform

Linux x86_64

Additional context

Environment

  • Python: Python 3.12.3
  • Zig: Zig 0.15.2
  • libc: glibc 2.39

Backtrace

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6618935 in vm.Vm.callFunction (self=0x7ffff62e3000, instance=0x7ffff7b80308, func_ptr=0x7ffff7b60380, args=..., results=...) from <REPO_ROOT>/examples/python/../../zig-out/lib/libzwasm.so
#0  0x00007ffff6618935 in vm.Vm.callFunction (self=0x7ffff62e3000, instance=0x7ffff7b80308, func_ptr=0x7ffff7b60380, args=..., results=...) from <REPO_ROOT>/examples/python/../../zig-out/lib/libzwasm.so
        inst = 0x0
        has_v128 = true
        param_slots = 0
        result_start = 21474836481
        wf = 0x7ffff7b603a0
        base = 0
        result_slots = 0
#1  0x00007ffff6859545 in vm.Vm.invoke (self=0x7ffff62e3000, instance=0x7ffff7b80308, name=..., args=..., results=...) from <REPO_ROOT>/examples/python/../../zig-out/lib/libzwasm.so
        func_addr = 0
        func_ptr = 0x7ffff7b60380
#2  0x00007ffff6858e17 in types.WasmModule.invoke (self=0x7ffff7b80000, name=..., args=..., results=...) from <REPO_ROOT>/examples/python/../../zig-out/lib/libzwasm.so
No locals.
#3  0x00007ffff68591b5 in zwasm_module_invoke (module=0x7ffff7faf000, name_ptr=0xb39410 <_PyRuntime+16464> "f", args=..., nargs=0, results=..., nresults=1) from <REPO_ROOT>/examples/python/../../zig-out/lib/libzwasm.so
        name = {ptr = 0xb39410 <_PyRuntime+16464> "f", len = 1}
        args_slice = {ptr = 0x7fffffffd050, len = 0}
        results_slice = {ptr = 0x7ffff6a3a2a0, len = 1}
#4  0x00007ffff7bb7b16 in ?? () from /lib/x86_64-linux-gnu/libffi.so.8
No symbol table info available.
#5  0x00007ffff7bb43ef in ?? () from /lib/x86_64-linux-gnu/libffi.so.8
No symbol table info available.
#6  0x00007ffff7bb70be in ffi_call () from /lib/x86_64-linux-gnu/libffi.so.8
No symbol table info available.
#7  0x00007ffff7bca11c in ?? () from /usr/lib/python3.12/lib-dynload/_ctypes.cpython-312-x86_64-linux-gnu.so
No symbol table info available.
#8  0x00007ffff7bc52af in ?? () from /usr/lib/python3.12/lib-dynload/_ctypes.cpython-312-x86_64-linux-gnu.so
No symbol table info available.
#9  0x0000000000548f75 in _PyObject_MakeTpCall ()
No symbol table info available.
#10 0x00000000005d6f09 in _PyEval_EvalFrameDefault ()
No symbol table info available.
#11 0x00000000005d543b in PyEval_EvalCode ()
No symbol table info available.
#12 0x00000000006085d2 in ?? ()
No symbol table info available.
#13 0x00000000006b4d03 in ?? ()
No symbol table info available.
#14 0x00000000006b4a6a in _PyRun_SimpleFileObject ()
No symbol table info available.
#15 0x00000000006b489f in _PyRun_AnyFileObject ()
No symbol table info available.
#16 0x00000000006bc905 in Py_RunMain ()
No symbol table info available.
#17 0x00000000006bc3ed in Py_BytesMain ()
No symbol table info available.
#18 0x00007ffff7c2a1ca in __libc_start_call_main (main=main@entry=0x518930, argc=argc@entry=2, argv=argv@entry=0x7fffffffdc18) at ../sysdeps/nptl/libc_start_call_main.h:58
        self = <optimized out>
        result = <optimized out>
        unwind_buf = {cancel_jmp_buf = {{jmp_buf = {140737488346136, 5310030842174122640, 2, 0, 10649040, 140737354125312, 5310030842188802704, 5310048045328116368}, mask_was_saved = 0}}, priv = {pad = {0x0, 0x0, 0x2, 0x7fffffffdc10}, data = {prev = 0x0, cleanup = 0x0, canceltype = 2}}}
        not_first_call = <optimized out>
#19 0x00007ffff7c2a28b in __libc_start_main_impl (main=0x518930, argc=2, argv=0x7fffffffdc18, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdc08) at ../csu/libc-start.c:360
No locals.
#20 0x00000000006576c5 in _start ()
No symbol table info available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions