]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/runtime/asm_amd64.s
[dev.power64] all: merge default (dd5014ed9b01) into dev.power64
[gostls13.git] / src / runtime / asm_amd64.s
index 7a0fdfa73a2bbe593fccfad34d9c009fd41232d5..ac9c58cf3e2cce8e23304fdd418f88af7aea9eab 100644 (file)
@@ -717,6 +717,20 @@ needm:
        get_tls(CX)
        MOVQ    g(CX), BP
        MOVQ    g_m(BP), BP
+       
+       // Set m->sched.sp = SP, so that if a panic happens
+       // during the function we are about to execute, it will
+       // have a valid SP to run on the g0 stack.
+       // The next few lines (after the havem label)
+       // will save this SP onto the stack and then write
+       // the same SP back to m->sched.sp. That seems redundant,
+       // but if an unrecovered panic happens, unwindm will
+       // restore the g->sched.sp from the stack location
+       // and then onM will try to use it. If we don't set it here,
+       // that restored SP will be uninitialized (typically 0) and
+       // will not be usable.
+       MOVQ    m_g0(BP), SI
+       MOVQ    SP, (g_sched+gobuf_sp)(SI)
 
 havem:
        // Now there's a valid m, and we're running on its m->g0.