Closed usuyuki closed 10 months ago
m3ApiRawFunction(m3_printFloat2)
{
m3ApiGetArg(float, num);
m3ApiGetArg(int, format);
Serial.print(num, format);
m3ApiSuccess();
}
型の不一致の可能性も加味して、WebAssemblyにあう方にしてみたが、変わらず
printFloat(1.1111):1.1111Guru Meditation Error: Core 1 panic'ed (Double exception).
Core 1 register dump:
PC : 0x40092012 PS : 0x00040136 A0 : 0x8008ee8d A1 : 0x3ffdaaa0
A2 : 0x4008cee8 A3 : 0x3ffbb9e4 A4 : 0x3f801b68 A5 : 0x3ffdac40
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x40080080 A9 : 0x3ffdabf0
A10 : 0x00060336 A11 : 0x00040026 A12 : 0x3f801b68 A13 : 0x3ffd7684
A14 : 0x00000000 A15 : 0x00000000 SAR : 0x0000001e EXCCAUSE: 0x00000002
EXCVADDR: 0xffffffe0 LBEG : 0x400900ad LEND : 0x400900bd LCOUNT : 0xffffffff
https://github.com/project-mahiwa/mahiwa-backend/issues/91#issuecomment-1857391497
だったが、target.jsonのstack-sizeを増やしても効果なし
serial.print(num,format);
serial.print("print end"
ではprint endまで行ったので、serial.print自体では問題なし
m3ApiSuccess();
が問題
引数多いが問題な気がする
serial.Print("cos(1.0):")
cos1 := arduino.Max(1, 0)
でもcosのprintした直後に出たので、引数2つだと壊れるで間違いなさそう。
if ;; label = @2
i64.const 1
i64.const 0
call $max
ただ、wasm内での呼び出しは適切に2つ引数渡せていて謎。
RustのprintDoubleの箇所
(func (;10;) (type 4) (param f64 i32)
local.get 0
local.get 1
i32.const 255
i32.and
call 4)
WebAssemblyの表現では同じなのに、Goだけエラーになる。
wasm-ldのオプションで-sつけるとエラーになるのも気になる。 gcのせい?
tinygoのビルドオプションはデフォルトがzなので、サイズは一番小さいはずなのに、rustと比べるとあまりにも大きい。
gc=noneにしてコンパイル
tinygo build -target ./target.json -o main.wasm main.go
tinygo:wasm-ld: error: /tmp/tinygo2970132202/main.o: undef
ined symbol: runtime.alloc
"no-debug": true, も効果なし
"panic": "trap", やheap-sizeの変更も意味なし
最適化かけるときに出てくる
unexpected false: Bu
mory operation (bulk memory is disabled),
が気になる。そもそもちゃんとしたwasmになっていない説がある。
ただしこれは単純なprintだけするプロジェクトでも同じエラーが出るので、謎。
wasm3公式のexampleとか見たが、やはり問題なさそう。違うのはTinyGoのバージョンだけ。
core2だけでなくstampc3uとかでやってみたが変わらず。
println("")でもエラーが出ていた。
printlnなしにしてのエラー
Guru Meditation Error: Core 1 panic'ed (Unhandled debug exception).
Debug exception reason: Stack canary watchpoint triggered (wasm3)
いやこれおかしい。printlnでエラーになるときとならないときがある。 でもずっと動かなかった2引数が動くようになった。
serial.Print("max(1,0)")
cos1 := arduino.Max(1, 0)
serial.PrintLong(cos1)
max(1,0)0Project Mahiwa : WebAssembly done
これにserial.Println("")をつけるとパニックする。
serial.Print("max(1,0)")
cos1 := arduino.Max(1, 0)
serial.PrintLong(cos1)
serial.Println("")
serial.Println("")はそれより前で何度も呼べてるのに……
max(1,0)0Guru Meditation Error: Core 1 panic'ed (Unhandled debug exception).
Debug exception reason: Stack canary watchpoint triggered (wasm3)
↓ このエラーは https://www.1ft-seabass.jp/memo/2017/07/31/esp32-developer-aws-iot-tips/ より、FreeRTOSでタスクに割り当てるメモリ不足らしい。
ただ
xTaskCreatePinnedToCore(&wasm_task, "wasm3", NATIVE_STACK_SIZE, NULL, 5, NULL,
1);
のNATIVE_STACK_SIZEを増やすと、今度はメモリ確保できずエラーになるので難しい。
とりあえず
#define NATIVE_STACK_SIZE (16 * 1024)
を
#define NATIVE_STACK_SIZE (16 * 2024)
にしてみる
実行できてしまった……・
https://docs.espressif.com/projects/esp-idf/en/v4.3/esp32/api-reference/system/freertos.html ESP32のやつはFreeRTOSと実は違うらしい。 タスクスタックのサイズであることに間違いはないらしい。
いやでもtarget.jsonで指定した、スタックは2048byteで、もともと1024*16byteと比べると小さいので、wasm3のインタプリタが想像以上にスタックを消費している可能性もある
ひとまず解決
🐛 概要
https://github.com/project-mahiwa/mahiwa-backend/issues/91 で見つかった問題
原因
備考