Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: badmorestackg0 is never called on wasm #63953

Closed
mauri870 opened this issue Nov 5, 2023 · 2 comments · Fixed by ferrmin/go#697
Closed

runtime: badmorestackg0 is never called on wasm #63953

mauri870 opened this issue Nov 5, 2023 · 2 comments · Fixed by ferrmin/go#697
Assignees
Labels
arch-wasm WebAssembly issues compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@mauri870
Copy link
Member

mauri870 commented Nov 5, 2023

While investigating crash stack on wasm, i found that badmorestackg0 is behind a condition that is never true.

go/src/runtime/asm_wasm.s

Lines 217 to 230 in d72f454

TEXT runtime·morestack(SB), NOSPLIT, $0-0
// R1 = g.m
MOVD g_m(g), R1
// R2 = g0
MOVD m_g0(R1), R2
// Cannot grow scheduler stack (m->g0).
Get g
Get R1
I64Eq
If
CALLNORESUME runtime·badmorestackg0(SB)
End

As you can see above, it is comparing g == R1, R1 being g.m. We should be comparing it to g0, which is stored in R2.

It is also present in 1.20 and 1.21, but I'm not sure if we need to backport this given that it is not a significant issue.

@mauri870 mauri870 added arch-wasm WebAssembly issues compiler/runtime Issues related to the Go compiler and/or runtime. labels Nov 5, 2023
@mauri870
Copy link
Member Author

mauri870 commented Nov 5, 2023

Original behavior:

RuntimeError: memory access out of bounds
    at runtime.morestack (wasm://wasm/0370d90e:wasm-function[1436]:0x134e6f)
    at runtime.morestack_noctxt (wasm://wasm/0370d90e:wasm-function[1437]:0x134eab)
    at runtime.newstack (wasm://wasm/0370d90e:wasm-function[977]:0xe4596)
    at runtime.morestack (wasm://wasm/0370d90e:wasm-function[1436]:0x134e8d)
    at runtime.morestack_noctxt (wasm://wasm/0370d90e:wasm-function[1437]:0x134eab)
    at runtime.newstack (wasm://wasm/0370d90e:wasm-function[977]:0xe4596)
    at runtime.morestack (wasm://wasm/0370d90e:wasm-function[1436]:0x134e8d)
    at runtime.morestack_noctxt (wasm://wasm/0370d90e:wasm-function[1437]:0x134eab)
    at runtime.newstack (wasm://wasm/0370d90e:wasm-function[977]:0xe4596)
    at runtime.morestack (wasm://wasm/0370d90e:wasm-function[1436]:0x134e8d)

With the fix applied:

RuntimeError: memory access out of bounds
    at runtime.morestack (wasm://wasm/0370d90e:wasm-function[1436]:0x134e6f)
    at runtime.morestack_noctxt (wasm://wasm/0370d90e:wasm-function[1437]:0x134eab)
    at runtime.write1 (wasm://wasm/0370d90e:wasm-function[662]:0x9c78f)
    at runtime.write (wasm://wasm/0370d90e:wasm-function[1056]:0xfbefc)
    at runtime.badmorestackg0 (wasm://wasm/0370d90e:wasm-function[766]:0xad590)
    at runtime.morestack (wasm://wasm/0370d90e:wasm-function[1436]:0x134df1)
    at runtime.morestack_noctxt (wasm://wasm/0370d90e:wasm-function[1437]:0x134eab)
    at runtime.write1 (wasm://wasm/0370d90e:wasm-function[662]:0x9c78f)
    at runtime.write (wasm://wasm/0370d90e:wasm-function[1056]:0xfbefc)
    at runtime.badmorestackg0 (wasm://wasm/0370d90e:wasm-function[766]:0xad590)

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/539840 mentions this issue: runtime: fix badmorestackg0 never called on wasm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly issues compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
2 participants