atomvm / AtomVM

Tiny Erlang VM
https://www.atomvm.net
Apache License 2.0
1.49k stars 106 forks source link

`gpio:stop/0` on esp32 causes VM crash #816

Closed UncleGrumpy closed 8 months ago

UncleGrumpy commented 1 year ago

I have deleted the AtomVM/build and AtomVM/src/platforms/esp32/build directories and done a complete clean rebuild of the esp32 image several times. The following is the simplest way to reproduce the crash is:

start() ->
    _GPIO = gpio:start(),
    timer:sleep(500),
    io:format("Stopping GPIO driver.~n"),
    gpio:stop().

For some reason I have not had stack traces with the last several rebuild of the image either, but the output is similar to:

AtomVM init.
I (876) sys: Loaded BEAM partition main.avm at address 0x210000 (size=1048576 bytes)
Starting application...

assert failed: tlsf_free tlsf.c:1119 (!block_is_free(block) && "block already marked as free")

Backtrace: 0x4008214e:0x3ffc63a0 0x4008c15d:0x3ffc63c0 0x40093c01:0x3ffc63e0 0x400918b7:0x3ffc6500 0x40091760:0x3ffc6520 0x4008251a:0x3ffc6540 0x40093c31:0x3ffc6560 0x400e4afe:0x3ffc6580 0x4013b31d:0x3ffc65a0 0x4013b3b3:0x3ffc65c0 0x400e5199:0x3ffc65e0 0x400da626:0x3ffc6670 0x400d16c4:0x3ffc6690 0x4008f655:0x3ffc66b0

ELF file SHA256: 759c8a1d95a85310

CPU halted.
UncleGrumpy commented 8 months ago

Here is idf.py monitor output of the crash when gpio:stop() is called:

...
Stopping GPIO driver <0.3.0>.

assert failed: tlsf_free tlsf.c:1119 (!block_is_free(block) && "block already marked as free")

Backtrace: 0x40081de2:0x3ffba5d0 0x4008c831:0x3ffba5f0 0x40094979:0x3ffba610 0x4009240e:0x3ffba730 0x400922b8:0x3ffba750 0x400826a2:0x3ffba770 0x400949a9:0x3ffba790 0x400e693e:0x3ffba7b0 0x40130c25:0x3ffba800 0x40130cc0:0x3ffba820 0x40130d46:0x3ffba840 0x400e9977:0x3ffba860 0x4010976d:0x3ffba910 0x400d9a5c:0x3ffba930 0x401d7d87:0x3ffba970 0x4008f321:0x3ffba9a0
0x40081de2: panic_abort at /home/winford/esp/esp-idf-v5.1/components/esp_system/panic.c:452

0x4008c831: esp_system_abort at /home/winford/esp/esp-idf-v5.1/components/esp_system/port/esp_system_chip.c:84

0x40094979: __assert_func at /home/winford/esp/esp-idf-v5.1/components/newlib/assert.c:81

0x4009240e: tlsf_free at /home/winford/esp/esp-idf-v5.1/components/heap/tlsf/tlsf.c:1119 (discriminator 1)

0x400922b8: multi_heap_free_impl at /home/winford/esp/esp-idf-v5.1/components/heap/multi_heap.c:231

0x400826a2: heap_caps_free at /home/winford/esp/esp-idf-v5.1/components/heap/heap_caps.c:388

0x400949a9: free at /home/winford/esp/esp-idf-v5.1/components/newlib/heap.c:39

0x400e693e: context_destroy at /home/winford/github/UncleGrumpy/AtomVM/src/libAtomVM/context.c:171

0x40130c25: scheduler_terminate at /home/winford/github/UncleGrumpy/AtomVM/src/libAtomVM/scheduler.c:352

0x40130cc0: scheduler_run at /home/winford/github/UncleGrumpy/AtomVM/src/libAtomVM/scheduler.c:262

0x40130d46: scheduler_wait at /home/winford/github/UncleGrumpy/AtomVM/src/libAtomVM/scheduler.c:86

0x400e9977: scheduler_entry_point at /home/winford/github/UncleGrumpy/AtomVM/src/libAtomVM/opcodesswitch.h:2311

0x4010976d: context_execute_loop at /home/winford/github/UncleGrumpy/AtomVM/src/libAtomVM/opcodesswitch.h:1550

0x400d9a5c: app_main at /home/winford/github/UncleGrumpy/AtomVM/src/platforms/esp32/main/main.c:114

0x401d7d87: main_task at /home/winford/esp/esp-idf-v5.1/components/freertos/app_startup.c:208 (discriminator 13)

0x4008f321: vPortTaskWrapper at /home/winford/esp/esp-idf-v5.1/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162

ELF file SHA256: b0e41eca7508d65d

CPU halted.