systemstack stop traceback

87 views
Skip to first unread message

wangjin...@gmail.com

unread,
Jul 30, 2019, 11:58:54 PM7/30/19
to golang-nuts
I read go runtime code,but I'm poor in assembly language,
i can't understand the following code
        // switch to g0
        MOVQ    DX, g(CX)
        MOVQ    (g_sched+gobuf_sp)(DX), BX
        // make it look like mstart called systemstack on g0, to stop traceback
        SUBQ    $8, BX
        MOVQ    $runtime·mstart(SB), DX
        MOVQ    DX, 0(BX)
        MOVQ    BX, SP


what does copy runtime·mstart to stack means,could someone help me

Ian Lance Taylor

unread,
Jul 31, 2019, 12:08:51 AM7/31/19
to wangjin...@gmail.com, golang-nuts
It does exactly what the comment says: when doing a stack traceback,
it makes it appear that mstart called systemstack. When a function is
called, the return address is placed on the stack. In this case the
assembly code is deliberately putting mstart on the stack, so that
that is what a traceback will see.

Ian

jin wang

unread,
Jul 31, 2019, 4:45:01 AM7/31/19
to golang-nuts


在 2019年7月31日星期三 UTC+8下午12:08:51,Ian Lance Taylor写道:

jin wang

unread,
Jul 31, 2019, 7:49:39 AM7/31/19
to golang-nuts
so mstart just put on stack for call traceback , but actually will not return at mstart?


在 2019年7月31日星期三 UTC+8下午12:08:51,Ian Lance Taylor写道:
On Tue, Jul 30, 2019 at 8:58 PM <wangjin...@gmail.com> wrote:

Ian Lance Taylor

unread,
Jul 31, 2019, 9:49:04 AM7/31/19
to jin wang, golang-nuts
On Wed, Jul 31, 2019 at 4:49 AM jin wang <wangjin...@gmail.com> wrote:
>
> so mstart just put on stack for call traceback , but actually will not return at mstart?

Yes. As you can see, the systemstack function changes the stack
pointer back to its original value before it returns to its caller.
It does not return on the stack where mstart is stored.

Ian
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c8587ec0-a09f-4215-8989-6133d307c7f8%40googlegroups.com.

jin wang

unread,
Jul 31, 2019, 10:06:20 PM7/31/19
to golang-nuts
Thank you very much.

在 2019年7月31日星期三 UTC+8下午9:49:04,Ian Lance Taylor写道:
> To unsubscribe from this group and stop receiving emails from it, send an email to golan...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages