github.com/rsc/go@v0.0.0-20150416155037-e040fd465409/src/runtime/cgo/signal_darwin_arm64.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,$-8
    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.
    20  	// TODO(crawshaw): call badsignal
    21  	MOVW $139, R1
    22  	MOVW R1, (RSP)
    23  	B    runtime·exit(SB)
    24  
    25  ongothread:
    26  	// Trigger a SIGSEGV panic.
    27  	//
    28  	// The goal is to arrange the stack so it looks like the runtime
    29  	// function sigpanic was called from the PC that faulted. It has
    30  	// to be sigpanic, as the stack unwinding code in traceback.go
    31  	// looks explicitly for it.
    32  	//
    33  	// To do this we call into runtime·setsigsegv, which sets the
    34  	// appropriate state inside the g object. We give it the faulting
    35  	// PC on the stack, then put it in the LR before calling sigpanic.
    36  	STP.W (R1, R2), -16(RSP)
    37  	BL runtime·setsigsegv(SB)
    38  	LDP.P 16(RSP), (R1, R2)
    39  
    40  	MOVD R1, 8(RSP)
    41  	MOVD R2, R30 // link register
    42  	B runtime·sigpanic(SB)