github.com/aloncn/graphics-go@v0.0.1/src/runtime/cgo/signal_darwin_arm.s (about)

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  #include "textflag.h"
     6  
     7  // panicmem is the entrypoint for SIGSEGV as intercepted via a
     8  // mach thread port as EXC_BAD_ACCESS. As the segfault may have happened
     9  // in C code, we first need to load_g then call panicmem.
    10  //
    11  //	R1 - LR at moment of fault
    12  //	R2 - PC at moment of fault
    13  TEXT ·panicmem(SB),NOSPLIT,$-4
    14  	// If in external C code, we need to load the g register.
    15  	BL  runtime·load_g(SB)
    16  	CMP $0, g
    17  	BNE ongothread
    18  
    19  	// On a foreign thread. We call badsignal, which will, if all
    20  	// goes according to plan, not return.
    21  	SUB  $4, R13
    22  	MOVW $11, R1
    23  	MOVW $11, R2
    24  	MOVM.DB.W [R1,R2], (R13)
    25  	// TODO: badsignal should not return, but it does. Issue #10139.
    26  	//BL runtime·badsignal(SB)
    27  	MOVW $139, R1
    28  	MOVW R1, 4(R13)
    29  	B    runtime·exit(SB)
    30  
    31  ongothread:
    32  	// Trigger a SIGSEGV panic.
    33  	//
    34  	// The goal is to arrange the stack so it looks like the runtime
    35  	// function sigpanic was called from the PC that faulted. It has
    36  	// to be sigpanic, as the stack unwinding code in traceback.go
    37  	// looks explicitly for it.
    38  	//
    39  	// To do this we call into runtime·setsigsegv, which sets the
    40  	// appropriate state inside the g object. We give it the faulting
    41  	// PC on the stack, then put it in the LR before calling sigpanic.
    42  	MOVM.DB.W [R1,R2], (R13)
    43  	BL runtime·setsigsegv(SB)
    44  	MOVM.IA.W (R13), [R1,R2]
    45  
    46  	SUB $4, R13
    47  	MOVW R1, 0(R13)
    48  	MOVW R2, R14
    49  	B runtime·sigpanic(SB)