Open4

WasmLinux: 放置でクラッシュする問題

okuokuokuoku

どのくらい放置が必要なのかも今のところ判明していない。。

  • VisualStudio版でしか見たことがない
  • 常にwasm2c的な FUNC_PROLOGUEWASM_RT_TRAP_EXHAUSTION する
  • backtrace的には write の内部。。?
 	ucrtbased.dll!issue_debug_notification(const wchar_t * const message=0x00007ff9c40eca90) Line 28	C++	Symbols loaded.
 	ucrtbased.dll!__acrt_report_runtime_error(const wchar_t * message=0x00007ff9c40eca90) Line 154	C++	Symbols loaded.
 	ucrtbased.dll!abort() Line 61	C++	Symbols loaded.
>	runner.exe!wasm_rt_trap(<unnamed-tag> code=WASM_RT_TRAP_EXHAUSTION) Line 75	C	Symbols loaded.
 	runner.exe!w2c_kernel_host_time(w2c_kernel * instance=0x000001a4e65c49b0) Line 1703945	C	Symbols loaded.
 	runner.exe!w2c_kernel_sched_clock(w2c_kernel * instance=0x000001a4e65c49b0) Line 504264	C	Symbols loaded.
 	runner.exe!w2c_kernel_sched_clock_cpu(w2c_kernel * instance=0x000001a4e65c49b0, unsigned int var_p0=0x00000000) Line 1461950	C	Symbols loaded.
 	runner.exe!w2c_kernel_try_to_wake_up(w2c_kernel * instance=0x000001a4e65c49b0, unsigned int var_p0=0x388ab000, unsigned int var_p1=0x00000000, unsigned int var_p2=0x00000010) Line 1425135	C	Symbols loaded.
 	runner.exe!w2c_kernel_default_wake_function(w2c_kernel * instance=0x000001a4e65c49b0, unsigned int var_p0=0x41e5fdfc, unsigned int var_p1=0x00000001, unsigned int var_p2=0x00000010, unsigned int var_p3=0x000000c3) Line 1427100	C	Symbols loaded.
 	runner.exe!w2c_kernel_autoremove_wake_function(w2c_kernel * instance=0x000001a4e65c49b0, unsigned int var_p0=0x41e5fdfc, unsigned int var_p1=0x00000001, unsigned int var_p2=0x00000010, unsigned int var_p3=0x000000c3) Line 1471271	C	Symbols loaded.
 	runner.exe!w2c_kernel_0x5F_wake_up_common_lock(w2c_kernel * instance=0x000001a4e65c49b0, unsigned int var_p0=0x38407538, unsigned int var_p1=0x00000001, unsigned int var_p2=0x00000001, unsigned int var_p3=0x00000010, unsigned int var_p4=0x000000c3) Line 1472102	C	Symbols loaded.
 	runner.exe!w2c_kernel_0x5F_wake_up_sync_key(w2c_kernel * instance=0x000001a4e65c49b0, unsigned int var_p0=0x38407538, unsigned int var_p1=0x00000001, unsigned int var_p2=0x000000c3) Line 1472920	C	Symbols loaded.
 	runner.exe!w2c_kernel_sock_def_readable(w2c_kernel * instance=0x000001a4e65c49b0, unsigned int var_p0=0x38a40000) Line 937736	C	Symbols loaded.
 	runner.exe!w2c_kernel_unix_stream_sendmsg(w2c_kernel * instance=0x000001a4e65c49b0, unsigned int var_p0=0x384076c0, unsigned int var_p1=0x41effe38, unsigned int var_p2=0x00000004) Line 1819679	C	Symbols loaded.
 	runner.exe!w2c_kernel_sock_write_iter(w2c_kernel * instance=0x000001a4e65c49b0, unsigned int var_p0=0x41effea8, unsigned int var_p1=0x41effe90) Line 368572	C	Symbols loaded.
 	runner.exe!w2c_kernel_vfs_write(w2c_kernel * instance=0x000001a4e65c49b0, unsigned int var_p0=0x383e55a0, unsigned int var_p1=0x38a44838, unsigned int var_p2=0x00000000, unsigned int var_p3=0x00000000) Line 352341	C	Symbols loaded.
 	runner.exe!w2c_kernel_ksys_write(w2c_kernel * instance=0x000001a4e65c49b0, unsigned int var_p0=0x383e55a0, unsigned int var_p1=0x38a44838, unsigned int var_p2=0x00000004) Line 352666	C	Symbols loaded.
 	runner.exe!w2c_kernel_0x5F_se_sys_write(w2c_kernel * instance=0x000001a4e65c49b0, unsigned int var_p0=0x00000001, unsigned int var_p1=0x38a44838, unsigned int var_p2=0x00000004) Line 352711	C	Symbols loaded.
 	runner.exe!w2c_kernel_lkl_syscall(w2c_kernel * instance=0x000001a4e65c49b0, unsigned int var_p0=0x00000040, unsigned int var_p1=0x00000003, unsigned int var_p2=0x3e43fe00) Line 1690101	C	Symbols loaded.
 	runner.exe!w2c_kernel_syscall_0(w2c_kernel * instance=0x000001a4e65c49b0, unsigned int var_p0=0x00000040, unsigned int var_p1=0x00000003, unsigned int var_p2=0x3e43fe00) Line 1702340	C	Symbols loaded.
 	runner.exe!w2c_kernel_syscall(w2c_kernel * instance=0x000001a4e65c49b0, unsigned int var_p0=0x00000040, unsigned int var_p1=0x00000003, unsigned int var_p2=0x3e43fe00) Line 191309	C	Symbols loaded.
 	runner.exe!runsyscall32(unsigned int no=0x00000040, unsigned int nargs=0x00000006, unsigned int in=0x3e43fe00) Line 622	C++	Symbols loaded.
 	runner.exe!w2c_env_wasmlinux_syscall32(w2c_env * env=0x0000000000000000, unsigned int argc=0x00000006, unsigned int no=0x00000040, unsigned int args=0x3e43fe00) Line 690	C++	Symbols loaded.
 	runner.exe!w2c_busybox__base__w2c_sccp(w2c_busybox__base__w2c * instance=0x000001a6e8b2a130, unsigned int var_p0=0x00000040, unsigned int var_p1=0x00000001, unsigned int var_p2=0x38a44838, unsigned int var_p3=0x00000004, unsigned int var_p4=0x00000000, unsigned int var_p5=0x00000000, unsigned int var_p6=0x00000000) Line 38529	C	Symbols loaded.
 	runner.exe!w2c_busybox__base__w2c_0x5F_syscall_cp(w2c_busybox__base__w2c * instance=0x000001a6e8b2a130, unsigned int var_p0=0x00000040, unsigned int var_p1=0x00000001, unsigned int var_p2=0x38a44838, unsigned int var_p3=0x00000004, unsigned int var_p4=0x00000000, unsigned int var_p5=0x00000000, unsigned int var_p6=0x00000000) Line 38550	C	Symbols loaded.
 	runner.exe!w2c_busybox__base__w2c_write(w2c_busybox__base__w2c * instance=0x000001a6e8b2a130, unsigned int var_p0=0x00000001, unsigned int var_p1=0x38a44838, unsigned int var_p2=0x00000004) Line 281213	C	Symbols loaded.
 	runner.exe!w2c_busybox__base__w2c_safe_write(w2c_busybox__base__w2c * instance=0x000001a6e8b2a130, unsigned int var_p0=0x00000001, unsigned int var_p1=0x38a44838, unsigned int var_p2=0x00000004) Line 609118	C	Symbols loaded.
 	runner.exe!w2c_busybox__base__w2c_safe_write_double_iac(w2c_busybox__base__w2c * instance=0x000001a6e8b2a130, unsigned int var_p0=0x00000001, unsigned int var_p1=0x38a44838, unsigned int var_p2=0x00000004) Line 1048272	C	Symbols loaded.
 	runner.exe!w2c_busybox__base__w2c_telnetd_main(w2c_busybox__base__w2c * instance=0x000001a6e8b2a130, unsigned int var_p0=0x00000004, unsigned int var_p1=0x3f27e104) Line 1044669	C	Symbols loaded.
 	runner.exe!w2c_busybox__base__w2c_run_applet_no_and_exit(w2c_busybox__base__w2c * instance=0x000001a6e8b2a130, unsigned int var_p0=0x0000014e, unsigned int var_p1=0x3f27e120, unsigned int var_p2=0x3f27e104) Line 536006	C	Symbols loaded.
 	runner.exe!w2c_busybox__base__w2c_run_applet_and_exit(w2c_busybox__base__w2c * instance=0x000001a6e8b2a130, unsigned int var_p0=0x3f27e120, unsigned int var_p1=0x3f27e104) Line 538353	C	Symbols loaded.
 	runner.exe!w2c_busybox__base__w2c_main0x2E1(w2c_busybox__base__w2c * instance=0x000001a6e8b2a130, unsigned int var_p0=0x00000004, unsigned int var_p1=0x3f27e104) Line 537039	C	Symbols loaded.
 	runner.exe!w2c_busybox__base__w2c_main(w2c_busybox__base__w2c * instance=0x000001a6e8b2a130, unsigned int var_p0=0x00000004, unsigned int var_p1=0x3f27e104, unsigned int var_p2=0x3f27e118) Line 32329	C	Symbols loaded.
 	runner.exe!w2c_busybox__base__w2c_wasmlinux_libc_main(w2c_busybox__base__w2c * instance=0x000001a6e8b2a130, unsigned int var_p0=0x00000004, unsigned int var_p1=0x3f27e104, unsigned int var_p2=0x3f27e118) Line 32365	C	Symbols loaded.
 	runner.exe!w2c_busybox__base__w2c_libc_start_main_stage2(w2c_busybox__base__w2c * instance=0x000001a6e8b2a130, unsigned int var_p0=0x00000001, unsigned int var_p1=0x00000004, unsigned int var_p2=0x3f27e104) Line 33161	C	Symbols loaded.
 	runner.exe!w2c_busybox__base__w2c_0x5F_libc_start_main(w2c_busybox__base__w2c * instance=0x000001a6e8b2a130, unsigned int var_p0=0x00000001, unsigned int var_p1=0x00000004, unsigned int var_p2=0x3f27e104, unsigned int var_p3=0x00000002, unsigned int var_p4=0x00000000, unsigned int var_p5=0x00000000) Line 33142	C	Symbols loaded.
 	runner.exe!w2c_busybox__base__w2c_0x5Fstart_c_0(w2c_busybox__base__w2c * instance=0x000001a6e8b2a130, unsigned int var_p0=0x3f27e100) Line 32355	C	Symbols loaded.
 	runner.exe!w2c_busybox__base__w2c_0x5Fstart_c(w2c_busybox__base__w2c * instance=0x000001a6e8b2a130, unsigned int var_p0=0x3f27e100) Line 23307	C	Symbols loaded.
 	runner.exe!wasmlinux_modquery__embedded(int cmd=0x00000003, int modidx=0x00000000, unsigned __int64 ctx=0x000001a6e8b2a130, unsigned __int64 param=0x000000003f27e100) Line 49	C	Symbols loaded.
 	runner.exe!wasmlinux_user_ctx_exec32(int type=0x00000000, unsigned int func=0x00000000, unsigned int param0=0x3f27e100, unsigned int param1=0x00000000, unsigned int param2=0x00000000, unsigned int param3=0x00000000) Line 105	C	Symbols loaded.
 	runner.exe!thr_pinetd_proc(pinetd_pair_s * param=0x000001a6e8ad0f10) Line 1460	C++	Symbols loaded.
 	runner.exe!std::invoke<void (*)(pinetd_pair_s *),pinetd_pair_s *>(void(*)(pinetd_pair_s *) && _Obj=0x00007ff69baf43f0, pinetd_pair_s * && _Arg1=0x000001a6e8ad0f10) Line 1574	C++	Symbols loaded.
 	runner.exe!std::thread::_Invoke<std::tuple<void (*)(pinetd_pair_s *),pinetd_pair_s *>,0,1>(void * _RawVals=0x000001a4e669e890) Line 55	C++	Symbols loaded.
 	ucrtbased.dll!thread_start<unsigned int (__cdecl*)(void *),1>(void * const parameter=0x000001a6e8200790) Line 97	C++	Symbols loaded.
 	kernel32.dll!BaseThreadInitThunk()	Unknown	Symbols loaded.
 	ntdll.dll!RtlUserThreadStart()	Unknown	Symbols loaded.

このときのstack pointerは 0x41effde0

okuokuokuoku

telnet接続後の放置で発生

 	ucrtbased.dll!issue_debug_notification(const wchar_t * const message=0x00007ff9dc68ca90) Line 28	C++	Symbols loaded.
 	ucrtbased.dll!__acrt_report_runtime_error(const wchar_t * message=0x00007ff9dc68ca90) Line 154	C++	Symbols loaded.
 	ucrtbased.dll!abort() Line 61	C++	Symbols loaded.
>	runner.exe!wasm_rt_trap(<unnamed-tag> code=WASM_RT_TRAP_EXHAUSTION) Line 75	C	Symbols loaded.
 	runner.exe!w2c_kernel_memcpy(w2c_kernel * instance=0x00000270ab1ea1d0, unsigned int var_p0=0x00163248, unsigned int var_p1=0x001e6398, unsigned int var_p2=0x00000038) Line 1702019	C	Symbols loaded.
 	runner.exe!w2c_kernel_host_memcpy(w2c_kernel * instance=0x00000270ab1ea1d0, unsigned int var_p0=0x00163248, unsigned int var_p1=0x001e6398, unsigned int var_p2=0x00000038) Line 1704511	C	Symbols loaded.
 	runner.exe!w2c_kernel_timekeeping_update(w2c_kernel * instance=0x00000270ab1ea1d0, unsigned int var_p0=0x001e6398, unsigned int var_p1=0x00000000) Line 1360328	C	Symbols loaded.
 	runner.exe!w2c_kernel_timekeeping_advance(w2c_kernel * instance=0x00000270ab1ea1d0, unsigned int var_p0=0x00000000) Line 1364213	C	Symbols loaded.
 	runner.exe!w2c_kernel_update_wall_time(w2c_kernel * instance=0x00000270ab1ea1d0) Line 1363145	C	Symbols loaded.
 	runner.exe!w2c_kernel_tick_do_update_jiffies64(w2c_kernel * instance=0x00000270ab1ea1d0, unsigned __int64 var_p0=0x0000000000000001) Line 1098897	C	Symbols loaded.
 	runner.exe!w2c_kernel_tick_sched_timer(w2c_kernel * instance=0x00000270ab1ea1d0, unsigned int var_p0=0x00160810) Line 1099232	C	Symbols loaded.
 	runner.exe!w2c_kernel_0x5F_hrtimer_run_queues(w2c_kernel * instance=0x00000270ab1ea1d0, unsigned __int64 var_p0=0x00000057e250d4b4, unsigned int var_p1=0x00000000, unsigned int var_p2=0x00160810) Line 1367055	C	Symbols loaded.
 	runner.exe!w2c_kernel_hrtimer_interrupt(w2c_kernel * instance=0x00000270ab1ea1d0, unsigned int var_p0=0x00000000) Line 1366703	C	Symbols loaded.
 	runner.exe!w2c_kernel_timer_irq_handler(w2c_kernel * instance=0x00000270ab1ea1d0, unsigned int var_p0=0x00000001, unsigned int var_p1=0x0015b8e0) Line 504373	C	Symbols loaded.
 	runner.exe!w2c_kernel_0x5F_handle_irq_event_percpu(w2c_kernel * instance=0x00000270ab1ea1d0, unsigned int var_p0=0x00137950) Line 500411	C	Symbols loaded.
 	runner.exe!w2c_kernel_handle_irq_event(w2c_kernel * instance=0x00000270ab1ea1d0, unsigned int var_p0=0x00137950) Line 500546	C	Symbols loaded.
 	runner.exe!w2c_kernel_handle_simple_irq(w2c_kernel * instance=0x00000270ab1ea1d0, unsigned int var_p0=0x00137950) Line 499038	C	Symbols loaded.
 	runner.exe!w2c_kernel_generic_handle_irq(w2c_kernel * instance=0x00000270ab1ea1d0, unsigned int var_p0=0x00000001) Line 500797	C	Symbols loaded.
 	runner.exe!w2c_kernel_run_irq(w2c_kernel * instance=0x00000270ab1ea1d0, unsigned int var_p0=0x00000001) Line 1691874	C	Symbols loaded.
 	runner.exe!w2c_kernel_lkl_trigger_irq(w2c_kernel * instance=0x00000270ab1ea1d0, unsigned int var_p0=0x00000001) Line 1691847	C	Symbols loaded.
 	runner.exe!w2c_kernel_timer_fn(w2c_kernel * instance=0x00000270ab1ea1d0, unsigned int var_p0=0x00000000) Line 504418	C	Symbols loaded.
 	runner.exe!thr_timer(int objid=0x00000008) Line 1788	C++	Symbols loaded.
 	runner.exe!std::invoke<void (*)(int),int>(void(*)(int) && _Obj=0x00007ff678084f70, int && _Arg1=0x00000008) Line 1574	C++	Symbols loaded.
 	runner.exe!std::thread::_Invoke<std::tuple<void (*)(int),int>,0,1>(void * _RawVals=0x00000270ab1fca60) Line 55	C++	Symbols loaded.
 	ucrtbased.dll!thread_start<unsigned int (__cdecl*)(void *),1>(void * const parameter=0x00000270ab1ffc70) Line 97	C++	Symbols loaded.
 	kernel32.dll!BaseThreadInitThunk()	Unknown	Symbols loaded.
 	ntdll.dll!RtlUserThreadStart()	Unknown	Symbols loaded.

このときのstack pointerは 0x4037fe80 、 trapは同様に WASM_RT_TRAP_EXHAUSTION

okuokuokuoku

Stack call depth countだな。。

変換後のソースには、

#if WASM_RT_USE_STACK_DEPTH_COUNT
#define FUNC_PROLOGUE                                            \
  if (++wasm_rt_call_stack_depth > WASM_RT_MAX_CALL_STACK_DEPTH) \
    TRAP(EXHAUSTION); // ★ これでクラッシュしていると見られる

#define FUNC_EPILOGUE --wasm_rt_call_stack_depth
#else
#define FUNC_PROLOGUE

#define FUNC_EPILOGUE
#endif

これはWin32でのみ使われる。

https://github.com/WebAssembly/wabt/blob/1263c6ab42997ebdc354e6dc203890c59791f337/wasm2c/wasm-rt.h#L208-L221

wasm2cした関数からsetjmp/longjmpする際は、wasmのスタックポインタと同時にこのカウンタもsave/loadしてやる必要があると見られる。...これ確かにやってないな。。