Black Lives Matter. Support the Equal Justice Initiative.

Source file src/runtime/signal_unix.go

Documentation: runtime

     1  // Copyright 2012 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  // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
     6  
     7  package runtime
     8  
     9  import (
    10  	"runtime/internal/atomic"
    11  	"unsafe"
    12  )
    13  
    14  // sigTabT is the type of an entry in the global sigtable array.
    15  // sigtable is inherently system dependent, and appears in OS-specific files,
    16  // but sigTabT is the same for all Unixy systems.
    17  // The sigtable array is indexed by a system signal number to get the flags
    18  // and printable name of each signal.
    19  type sigTabT struct {
    20  	flags int32
    21  	name  string
    22  }
    23  
    24  //go:linkname os_sigpipe os.sigpipe
    25  func os_sigpipe() {
    26  	systemstack(sigpipe)
    27  }
    28  
    29  func signame(sig uint32) string {
    30  	if sig >= uint32(len(sigtable)) {
    31  		return ""
    32  	}
    33  	return sigtable[sig].name
    34  }
    35  
    36  const (
    37  	_SIG_DFL uintptr = 0
    38  	_SIG_IGN uintptr = 1
    39  )
    40  
    41  // sigPreempt is the signal used for non-cooperative preemption.
    42  //
    43  // There's no good way to choose this signal, but there are some
    44  // heuristics:
    45  //
    46  // 1. It should be a signal that's passed-through by debuggers by
    47  // default. On Linux, this is SIGALRM, SIGURG, SIGCHLD, SIGIO,
    48  // SIGVTALRM, SIGPROF, and SIGWINCH, plus some glibc-internal signals.
    49  //
    50  // 2. It shouldn't be used internally by libc in mixed Go/C binaries
    51  // because libc may assume it's the only thing that can handle these
    52  // signals. For example SIGCANCEL or SIGSETXID.
    53  //
    54  // 3. It should be a signal that can happen spuriously without
    55  // consequences. For example, SIGALRM is a bad choice because the
    56  // signal handler can't tell if it was caused by the real process
    57  // alarm or not (arguably this means the signal is broken, but I
    58  // digress). SIGUSR1 and SIGUSR2 are also bad because those are often
    59  // used in meaningful ways by applications.
    60  //
    61  // 4. We need to deal with platforms without real-time signals (like
    62  // macOS), so those are out.
    63  //
    64  // We use SIGURG because it meets all of these criteria, is extremely
    65  // unlikely to be used by an application for its "real" meaning (both
    66  // because out-of-band data is basically unused and because SIGURG
    67  // doesn't report which socket has the condition, making it pretty
    68  // useless), and even if it is, the application has to be ready for
    69  // spurious SIGURG. SIGIO wouldn't be a bad choice either, but is more
    70  // likely to be used for real.
    71  const sigPreempt = _SIGURG
    72  
    73  // Stores the signal handlers registered before Go installed its own.
    74  // These signal handlers will be invoked in cases where Go doesn't want to
    75  // handle a particular signal (e.g., signal occurred on a non-Go thread).
    76  // See sigfwdgo for more information on when the signals are forwarded.
    77  //
    78  // This is read by the signal handler; accesses should use
    79  // atomic.Loaduintptr and atomic.Storeuintptr.
    80  var fwdSig [_NSIG]uintptr
    81  
    82  // handlingSig is indexed by signal number and is non-zero if we are
    83  // currently handling the signal. Or, to put it another way, whether
    84  // the signal handler is currently set to the Go signal handler or not.
    85  // This is uint32 rather than bool so that we can use atomic instructions.
    86  var handlingSig [_NSIG]uint32
    87  
    88  // channels for synchronizing signal mask updates with the signal mask
    89  // thread
    90  var (
    91  	disableSigChan  chan uint32
    92  	enableSigChan   chan uint32
    93  	maskUpdatedChan chan struct{}
    94  )
    95  
    96  func init() {
    97  	// _NSIG is the number of signals on this operating system.
    98  	// sigtable should describe what to do for all the possible signals.
    99  	if len(sigtable) != _NSIG {
   100  		print("runtime: len(sigtable)=", len(sigtable), " _NSIG=", _NSIG, "\n")
   101  		throw("bad sigtable len")
   102  	}
   103  }
   104  
   105  var signalsOK bool
   106  
   107  // Initialize signals.
   108  // Called by libpreinit so runtime may not be initialized.
   109  //go:nosplit
   110  //go:nowritebarrierrec
   111  func initsig(preinit bool) {
   112  	if !preinit {
   113  		// It's now OK for signal handlers to run.
   114  		signalsOK = true
   115  	}
   116  
   117  	// For c-archive/c-shared this is called by libpreinit with
   118  	// preinit == true.
   119  	if (isarchive || islibrary) && !preinit {
   120  		return
   121  	}
   122  
   123  	for i := uint32(0); i < _NSIG; i++ {
   124  		t := &sigtable[i]
   125  		if t.flags == 0 || t.flags&_SigDefault != 0 {
   126  			continue
   127  		}
   128  
   129  		// We don't need to use atomic operations here because
   130  		// there shouldn't be any other goroutines running yet.
   131  		fwdSig[i] = getsig(i)
   132  
   133  		if !sigInstallGoHandler(i) {
   134  			// Even if we are not installing a signal handler,
   135  			// set SA_ONSTACK if necessary.
   136  			if fwdSig[i] != _SIG_DFL && fwdSig[i] != _SIG_IGN {
   137  				setsigstack(i)
   138  			} else if fwdSig[i] == _SIG_IGN {
   139  				sigInitIgnored(i)
   140  			}
   141  			continue
   142  		}
   143  
   144  		handlingSig[i] = 1
   145  		setsig(i, funcPC(sighandler))
   146  	}
   147  }
   148  
   149  //go:nosplit
   150  //go:nowritebarrierrec
   151  func sigInstallGoHandler(sig uint32) bool {
   152  	// For some signals, we respect an inherited SIG_IGN handler
   153  	// rather than insist on installing our own default handler.
   154  	// Even these signals can be fetched using the os/signal package.
   155  	switch sig {
   156  	case _SIGHUP, _SIGINT:
   157  		if atomic.Loaduintptr(&fwdSig[sig]) == _SIG_IGN {
   158  			return false
   159  		}
   160  	}
   161  
   162  	t := &sigtable[sig]
   163  	if t.flags&_SigSetStack != 0 {
   164  		return false
   165  	}
   166  
   167  	// When built using c-archive or c-shared, only install signal
   168  	// handlers for synchronous signals and SIGPIPE.
   169  	if (isarchive || islibrary) && t.flags&_SigPanic == 0 && sig != _SIGPIPE {
   170  		return false
   171  	}
   172  
   173  	return true
   174  }
   175  
   176  // sigenable enables the Go signal handler to catch the signal sig.
   177  // It is only called while holding the os/signal.handlers lock,
   178  // via os/signal.enableSignal and signal_enable.
   179  func sigenable(sig uint32) {
   180  	if sig >= uint32(len(sigtable)) {
   181  		return
   182  	}
   183  
   184  	// SIGPROF is handled specially for profiling.
   185  	if sig == _SIGPROF {
   186  		return
   187  	}
   188  
   189  	t := &sigtable[sig]
   190  	if t.flags&_SigNotify != 0 {
   191  		ensureSigM()
   192  		enableSigChan <- sig
   193  		<-maskUpdatedChan
   194  		if atomic.Cas(&handlingSig[sig], 0, 1) {
   195  			atomic.Storeuintptr(&fwdSig[sig], getsig(sig))
   196  			setsig(sig, funcPC(sighandler))
   197  		}
   198  	}
   199  }
   200  
   201  // sigdisable disables the Go signal handler for the signal sig.
   202  // It is only called while holding the os/signal.handlers lock,
   203  // via os/signal.disableSignal and signal_disable.
   204  func sigdisable(sig uint32) {
   205  	if sig >= uint32(len(sigtable)) {
   206  		return
   207  	}
   208  
   209  	// SIGPROF is handled specially for profiling.
   210  	if sig == _SIGPROF {
   211  		return
   212  	}
   213  
   214  	t := &sigtable[sig]
   215  	if t.flags&_SigNotify != 0 {
   216  		ensureSigM()
   217  		disableSigChan <- sig
   218  		<-maskUpdatedChan
   219  
   220  		// If initsig does not install a signal handler for a
   221  		// signal, then to go back to the state before Notify
   222  		// we should remove the one we installed.
   223  		if !sigInstallGoHandler(sig) {
   224  			atomic.Store(&handlingSig[sig], 0)
   225  			setsig(sig, atomic.Loaduintptr(&fwdSig[sig]))
   226  		}
   227  	}
   228  }
   229  
   230  // sigignore ignores the signal sig.
   231  // It is only called while holding the os/signal.handlers lock,
   232  // via os/signal.ignoreSignal and signal_ignore.
   233  func sigignore(sig uint32) {
   234  	if sig >= uint32(len(sigtable)) {
   235  		return
   236  	}
   237  
   238  	// SIGPROF is handled specially for profiling.
   239  	if sig == _SIGPROF {
   240  		return
   241  	}
   242  
   243  	t := &sigtable[sig]
   244  	if t.flags&_SigNotify != 0 {
   245  		atomic.Store(&handlingSig[sig], 0)
   246  		setsig(sig, _SIG_IGN)
   247  	}
   248  }
   249  
   250  // clearSignalHandlers clears all signal handlers that are not ignored
   251  // back to the default. This is called by the child after a fork, so that
   252  // we can enable the signal mask for the exec without worrying about
   253  // running a signal handler in the child.
   254  //go:nosplit
   255  //go:nowritebarrierrec
   256  func clearSignalHandlers() {
   257  	for i := uint32(0); i < _NSIG; i++ {
   258  		if atomic.Load(&handlingSig[i]) != 0 {
   259  			setsig(i, _SIG_DFL)
   260  		}
   261  	}
   262  }
   263  
   264  // setProcessCPUProfiler is called when the profiling timer changes.
   265  // It is called with prof.lock held. hz is the new timer, and is 0 if
   266  // profiling is being disabled. Enable or disable the signal as
   267  // required for -buildmode=c-archive.
   268  func setProcessCPUProfiler(hz int32) {
   269  	if hz != 0 {
   270  		// Enable the Go signal handler if not enabled.
   271  		if atomic.Cas(&handlingSig[_SIGPROF], 0, 1) {
   272  			atomic.Storeuintptr(&fwdSig[_SIGPROF], getsig(_SIGPROF))
   273  			setsig(_SIGPROF, funcPC(sighandler))
   274  		}
   275  	} else {
   276  		// If the Go signal handler should be disabled by default,
   277  		// switch back to the signal handler that was installed
   278  		// when we enabled profiling. We don't try to handle the case
   279  		// of a program that changes the SIGPROF handler while Go
   280  		// profiling is enabled.
   281  		//
   282  		// If no signal handler was installed before, then start
   283  		// ignoring SIGPROF signals. We do this, rather than change
   284  		// to SIG_DFL, because there may be a pending SIGPROF
   285  		// signal that has not yet been delivered to some other thread.
   286  		// If we change to SIG_DFL here, the program will crash
   287  		// when that SIGPROF is delivered. We assume that programs
   288  		// that use profiling don't want to crash on a stray SIGPROF.
   289  		// See issue 19320.
   290  		if !sigInstallGoHandler(_SIGPROF) {
   291  			if atomic.Cas(&handlingSig[_SIGPROF], 1, 0) {
   292  				h := atomic.Loaduintptr(&fwdSig[_SIGPROF])
   293  				if h == _SIG_DFL {
   294  					h = _SIG_IGN
   295  				}
   296  				setsig(_SIGPROF, h)
   297  			}
   298  		}
   299  	}
   300  }
   301  
   302  // setThreadCPUProfiler makes any thread-specific changes required to
   303  // implement profiling at a rate of hz.
   304  func setThreadCPUProfiler(hz int32) {
   305  	var it itimerval
   306  	if hz == 0 {
   307  		setitimer(_ITIMER_PROF, &it, nil)
   308  	} else {
   309  		it.it_interval.tv_sec = 0
   310  		it.it_interval.set_usec(1000000 / hz)
   311  		it.it_value = it.it_interval
   312  		setitimer(_ITIMER_PROF, &it, nil)
   313  	}
   314  	_g_ := getg()
   315  	_g_.m.profilehz = hz
   316  }
   317  
   318  func sigpipe() {
   319  	if signal_ignored(_SIGPIPE) || sigsend(_SIGPIPE) {
   320  		return
   321  	}
   322  	dieFromSignal(_SIGPIPE)
   323  }
   324  
   325  // doSigPreempt handles a preemption signal on gp.
   326  func doSigPreempt(gp *g, ctxt *sigctxt) {
   327  	// Check if this G wants to be preempted and is safe to
   328  	// preempt.
   329  	if wantAsyncPreempt(gp) {
   330  		if ok, newpc := isAsyncSafePoint(gp, ctxt.sigpc(), ctxt.sigsp(), ctxt.siglr()); ok {
   331  			// Adjust the PC and inject a call to asyncPreempt.
   332  			ctxt.pushCall(funcPC(asyncPreempt), newpc)
   333  		}
   334  	}
   335  
   336  	// Acknowledge the preemption.
   337  	atomic.Xadd(&gp.m.preemptGen, 1)
   338  	atomic.Store(&gp.m.signalPending, 0)
   339  }
   340  
   341  const preemptMSupported = true
   342  
   343  // preemptM sends a preemption request to mp. This request may be
   344  // handled asynchronously and may be coalesced with other requests to
   345  // the M. When the request is received, if the running G or P are
   346  // marked for preemption and the goroutine is at an asynchronous
   347  // safe-point, it will preempt the goroutine. It always atomically
   348  // increments mp.preemptGen after handling a preemption request.
   349  func preemptM(mp *m) {
   350  	if GOOS == "darwin" && GOARCH == "arm64" && !iscgo {
   351  		// On darwin, we use libc calls, and cgo is required on ARM64
   352  		// so we have TLS set up to save/restore G during C calls. If cgo is
   353  		// absent, we cannot save/restore G in TLS, and if a signal is
   354  		// received during C execution we cannot get the G. Therefore don't
   355  		// send signals.
   356  		// This can only happen in the go_bootstrap program (otherwise cgo is
   357  		// required).
   358  		return
   359  	}
   360  	if atomic.Cas(&mp.signalPending, 0, 1) {
   361  		// If multiple threads are preempting the same M, it may send many
   362  		// signals to the same M such that it hardly make progress, causing
   363  		// live-lock problem. Apparently this could happen on darwin. See
   364  		// issue #37741.
   365  		// Only send a signal if there isn't already one pending.
   366  		signalM(mp, sigPreempt)
   367  	}
   368  }
   369  
   370  // sigFetchG fetches the value of G safely when running in a signal handler.
   371  // On some architectures, the g value may be clobbered when running in a VDSO.
   372  // See issue #32912.
   373  //
   374  //go:nosplit
   375  func sigFetchG(c *sigctxt) *g {
   376  	switch GOARCH {
   377  	case "arm", "arm64":
   378  		if !iscgo && inVDSOPage(c.sigpc()) {
   379  			// When using cgo, we save the g on TLS and load it from there
   380  			// in sigtramp. Just use that.
   381  			// Otherwise, before making a VDSO call we save the g to the
   382  			// bottom of the signal stack. Fetch from there.
   383  			// TODO: in efence mode, stack is sysAlloc'd, so this wouldn't
   384  			// work.
   385  			sp := getcallersp()
   386  			s := spanOf(sp)
   387  			if s != nil && s.state.get() == mSpanManual && s.base() < sp && sp < s.limit {
   388  				gp := *(**g)(unsafe.Pointer(s.base()))
   389  				return gp
   390  			}
   391  			return nil
   392  		}
   393  	}
   394  	return getg()
   395  }
   396  
   397  // sigtrampgo is called from the signal handler function, sigtramp,
   398  // written in assembly code.
   399  // This is called by the signal handler, and the world may be stopped.
   400  //
   401  // It must be nosplit because getg() is still the G that was running
   402  // (if any) when the signal was delivered, but it's (usually) called
   403  // on the gsignal stack. Until this switches the G to gsignal, the
   404  // stack bounds check won't work.
   405  //
   406  //go:nosplit
   407  //go:nowritebarrierrec
   408  func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
   409  	if sigfwdgo(sig, info, ctx) {
   410  		return
   411  	}
   412  	c := &sigctxt{info, ctx}
   413  	g := sigFetchG(c)
   414  	setg(g)
   415  	if g == nil {
   416  		if sig == _SIGPROF {
   417  			sigprofNonGoPC(c.sigpc())
   418  			return
   419  		}
   420  		if sig == sigPreempt && preemptMSupported && debug.asyncpreemptoff == 0 {
   421  			// This is probably a signal from preemptM sent
   422  			// while executing Go code but received while
   423  			// executing non-Go code.
   424  			// We got past sigfwdgo, so we know that there is
   425  			// no non-Go signal handler for sigPreempt.
   426  			// The default behavior for sigPreempt is to ignore
   427  			// the signal, so badsignal will be a no-op anyway.
   428  			return
   429  		}
   430  		c.fixsigcode(sig)
   431  		badsignal(uintptr(sig), c)
   432  		return
   433  	}
   434  
   435  	setg(g.m.gsignal)
   436  
   437  	// If some non-Go code called sigaltstack, adjust.
   438  	var gsignalStack gsignalStack
   439  	setStack := adjustSignalStack(sig, g.m, &gsignalStack)
   440  	if setStack {
   441  		g.m.gsignal.stktopsp = getcallersp()
   442  	}
   443  
   444  	if g.stackguard0 == stackFork {
   445  		signalDuringFork(sig)
   446  	}
   447  
   448  	c.fixsigcode(sig)
   449  	sighandler(sig, info, ctx, g)
   450  	setg(g)
   451  	if setStack {
   452  		restoreGsignalStack(&gsignalStack)
   453  	}
   454  }
   455  
   456  // adjustSignalStack adjusts the current stack guard based on the
   457  // stack pointer that is actually in use while handling a signal.
   458  // We do this in case some non-Go code called sigaltstack.
   459  // This reports whether the stack was adjusted, and if so stores the old
   460  // signal stack in *gsigstack.
   461  //go:nosplit
   462  func adjustSignalStack(sig uint32, mp *m, gsigStack *gsignalStack) bool {
   463  	sp := uintptr(unsafe.Pointer(&sig))
   464  	if sp >= mp.gsignal.stack.lo && sp < mp.gsignal.stack.hi {
   465  		return false
   466  	}
   467  
   468  	if sp >= mp.g0.stack.lo && sp < mp.g0.stack.hi {
   469  		// The signal was delivered on the g0 stack.
   470  		// This can happen when linked with C code
   471  		// using the thread sanitizer, which collects
   472  		// signals then delivers them itself by calling
   473  		// the signal handler directly when C code,
   474  		// including C code called via cgo, calls a
   475  		// TSAN-intercepted function such as malloc.
   476  		st := stackt{ss_size: mp.g0.stack.hi - mp.g0.stack.lo}
   477  		setSignalstackSP(&st, mp.g0.stack.lo)
   478  		setGsignalStack(&st, gsigStack)
   479  		return true
   480  	}
   481  
   482  	var st stackt
   483  	sigaltstack(nil, &st)
   484  	if st.ss_flags&_SS_DISABLE != 0 {
   485  		setg(nil)
   486  		needm(0)
   487  		noSignalStack(sig)
   488  		dropm()
   489  	}
   490  	stsp := uintptr(unsafe.Pointer(st.ss_sp))
   491  	if sp < stsp || sp >= stsp+st.ss_size {
   492  		setg(nil)
   493  		needm(0)
   494  		sigNotOnStack(sig)
   495  		dropm()
   496  	}
   497  	setGsignalStack(&st, gsigStack)
   498  	return true
   499  }
   500  
   501  // crashing is the number of m's we have waited for when implementing
   502  // GOTRACEBACK=crash when a signal is received.
   503  var crashing int32
   504  
   505  // testSigtrap and testSigusr1 are used by the runtime tests. If
   506  // non-nil, it is called on SIGTRAP/SIGUSR1. If it returns true, the
   507  // normal behavior on this signal is suppressed.
   508  var testSigtrap func(info *siginfo, ctxt *sigctxt, gp *g) bool
   509  var testSigusr1 func(gp *g) bool
   510  
   511  // sighandler is invoked when a signal occurs. The global g will be
   512  // set to a gsignal goroutine and we will be running on the alternate
   513  // signal stack. The parameter g will be the value of the global g
   514  // when the signal occurred. The sig, info, and ctxt parameters are
   515  // from the system signal handler: they are the parameters passed when
   516  // the SA is passed to the sigaction system call.
   517  //
   518  // The garbage collector may have stopped the world, so write barriers
   519  // are not allowed.
   520  //
   521  //go:nowritebarrierrec
   522  func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
   523  	_g_ := getg()
   524  	c := &sigctxt{info, ctxt}
   525  
   526  	if sig == _SIGPROF {
   527  		sigprof(c.sigpc(), c.sigsp(), c.siglr(), gp, _g_.m)
   528  		return
   529  	}
   530  
   531  	if sig == _SIGTRAP && testSigtrap != nil && testSigtrap(info, (*sigctxt)(noescape(unsafe.Pointer(c))), gp) {
   532  		return
   533  	}
   534  
   535  	if sig == _SIGUSR1 && testSigusr1 != nil && testSigusr1(gp) {
   536  		return
   537  	}
   538  
   539  	if sig == sigPreempt && debug.asyncpreemptoff == 0 {
   540  		// Might be a preemption signal.
   541  		doSigPreempt(gp, c)
   542  		// Even if this was definitely a preemption signal, it
   543  		// may have been coalesced with another signal, so we
   544  		// still let it through to the application.
   545  	}
   546  
   547  	flags := int32(_SigThrow)
   548  	if sig < uint32(len(sigtable)) {
   549  		flags = sigtable[sig].flags
   550  	}
   551  	if c.sigcode() != _SI_USER && flags&_SigPanic != 0 && gp.throwsplit {
   552  		// We can't safely sigpanic because it may grow the
   553  		// stack. Abort in the signal handler instead.
   554  		flags = _SigThrow
   555  	}
   556  	if isAbortPC(c.sigpc()) {
   557  		// On many architectures, the abort function just
   558  		// causes a memory fault. Don't turn that into a panic.
   559  		flags = _SigThrow
   560  	}
   561  	if c.sigcode() != _SI_USER && flags&_SigPanic != 0 {
   562  		// The signal is going to cause a panic.
   563  		// Arrange the stack so that it looks like the point
   564  		// where the signal occurred made a call to the
   565  		// function sigpanic. Then set the PC to sigpanic.
   566  
   567  		// Have to pass arguments out of band since
   568  		// augmenting the stack frame would break
   569  		// the unwinding code.
   570  		gp.sig = sig
   571  		gp.sigcode0 = uintptr(c.sigcode())
   572  		gp.sigcode1 = uintptr(c.fault())
   573  		gp.sigpc = c.sigpc()
   574  
   575  		c.preparePanic(sig, gp)
   576  		return
   577  	}
   578  
   579  	if c.sigcode() == _SI_USER || flags&_SigNotify != 0 {
   580  		if sigsend(sig) {
   581  			return
   582  		}
   583  	}
   584  
   585  	if c.sigcode() == _SI_USER && signal_ignored(sig) {
   586  		return
   587  	}
   588  
   589  	if flags&_SigKill != 0 {
   590  		dieFromSignal(sig)
   591  	}
   592  
   593  	// _SigThrow means that we should exit now.
   594  	// If we get here with _SigPanic, it means that the signal
   595  	// was sent to us by a program (c.sigcode() == _SI_USER);
   596  	// in that case, if we didn't handle it in sigsend, we exit now.
   597  	if flags&(_SigThrow|_SigPanic) == 0 {
   598  		return
   599  	}
   600  
   601  	_g_.m.throwing = 1
   602  	_g_.m.caughtsig.set(gp)
   603  
   604  	if crashing == 0 {
   605  		startpanic_m()
   606  	}
   607  
   608  	if sig < uint32(len(sigtable)) {
   609  		print(sigtable[sig].name, "\n")
   610  	} else {
   611  		print("Signal ", sig, "\n")
   612  	}
   613  
   614  	print("PC=", hex(c.sigpc()), " m=", _g_.m.id, " sigcode=", c.sigcode(), "\n")
   615  	if _g_.m.lockedg != 0 && _g_.m.ncgo > 0 && gp == _g_.m.g0 {
   616  		print("signal arrived during cgo execution\n")
   617  		gp = _g_.m.lockedg.ptr()
   618  	}
   619  	if sig == _SIGILL {
   620  		// It would be nice to know how long the instruction is.
   621  		// Unfortunately, that's complicated to do in general (mostly for x86
   622  		// and s930x, but other archs have non-standard instruction lengths also).
   623  		// Opt to print 16 bytes, which covers most instructions.
   624  		const maxN = 16
   625  		n := uintptr(maxN)
   626  		// We have to be careful, though. If we're near the end of
   627  		// a page and the following page isn't mapped, we could
   628  		// segfault. So make sure we don't straddle a page (even though
   629  		// that could lead to printing an incomplete instruction).
   630  		// We're assuming here we can read at least the page containing the PC.
   631  		// I suppose it is possible that the page is mapped executable but not readable?
   632  		pc := c.sigpc()
   633  		if n > physPageSize-pc%physPageSize {
   634  			n = physPageSize - pc%physPageSize
   635  		}
   636  		print("instruction bytes:")
   637  		b := (*[maxN]byte)(unsafe.Pointer(pc))
   638  		for i := uintptr(0); i < n; i++ {
   639  			print(" ", hex(b[i]))
   640  		}
   641  		println()
   642  	}
   643  	print("\n")
   644  
   645  	level, _, docrash := gotraceback()
   646  	if level > 0 {
   647  		goroutineheader(gp)
   648  		tracebacktrap(c.sigpc(), c.sigsp(), c.siglr(), gp)
   649  		if crashing > 0 && gp != _g_.m.curg && _g_.m.curg != nil && readgstatus(_g_.m.curg)&^_Gscan == _Grunning {
   650  			// tracebackothers on original m skipped this one; trace it now.
   651  			goroutineheader(_g_.m.curg)
   652  			traceback(^uintptr(0), ^uintptr(0), 0, _g_.m.curg)
   653  		} else if crashing == 0 {
   654  			tracebackothers(gp)
   655  			print("\n")
   656  		}
   657  		dumpregs(c)
   658  	}
   659  
   660  	if docrash {
   661  		crashing++
   662  		if crashing < mcount()-int32(extraMCount) {
   663  			// There are other m's that need to dump their stacks.
   664  			// Relay SIGQUIT to the next m by sending it to the current process.
   665  			// All m's that have already received SIGQUIT have signal masks blocking
   666  			// receipt of any signals, so the SIGQUIT will go to an m that hasn't seen it yet.
   667  			// When the last m receives the SIGQUIT, it will fall through to the call to
   668  			// crash below. Just in case the relaying gets botched, each m involved in
   669  			// the relay sleeps for 5 seconds and then does the crash/exit itself.
   670  			// In expected operation, the last m has received the SIGQUIT and run
   671  			// crash/exit and the process is gone, all long before any of the
   672  			// 5-second sleeps have finished.
   673  			print("\n-----\n\n")
   674  			raiseproc(_SIGQUIT)
   675  			usleep(5 * 1000 * 1000)
   676  		}
   677  		crash()
   678  	}
   679  
   680  	printDebugLog()
   681  
   682  	exit(2)
   683  }
   684  
   685  // sigpanic turns a synchronous signal into a run-time panic.
   686  // If the signal handler sees a synchronous panic, it arranges the
   687  // stack to look like the function where the signal occurred called
   688  // sigpanic, sets the signal's PC value to sigpanic, and returns from
   689  // the signal handler. The effect is that the program will act as
   690  // though the function that got the signal simply called sigpanic
   691  // instead.
   692  //
   693  // This must NOT be nosplit because the linker doesn't know where
   694  // sigpanic calls can be injected.
   695  //
   696  // The signal handler must not inject a call to sigpanic if
   697  // getg().throwsplit, since sigpanic may need to grow the stack.
   698  //
   699  // This is exported via linkname to assembly in runtime/cgo.
   700  //go:linkname sigpanic
   701  func sigpanic() {
   702  	g := getg()
   703  	if !canpanic(g) {
   704  		throw("unexpected signal during runtime execution")
   705  	}
   706  
   707  	switch g.sig {
   708  	case _SIGBUS:
   709  		if g.sigcode0 == _BUS_ADRERR && g.sigcode1 < 0x1000 {
   710  			panicmem()
   711  		}
   712  		// Support runtime/debug.SetPanicOnFault.
   713  		if g.paniconfault {
   714  			panicmem()
   715  		}
   716  		print("unexpected fault address ", hex(g.sigcode1), "\n")
   717  		throw("fault")
   718  	case _SIGSEGV:
   719  		if (g.sigcode0 == 0 || g.sigcode0 == _SEGV_MAPERR || g.sigcode0 == _SEGV_ACCERR) && g.sigcode1 < 0x1000 {
   720  			panicmem()
   721  		}
   722  		// Support runtime/debug.SetPanicOnFault.
   723  		if g.paniconfault {
   724  			panicmem()
   725  		}
   726  		print("unexpected fault address ", hex(g.sigcode1), "\n")
   727  		throw("fault")
   728  	case _SIGFPE:
   729  		switch g.sigcode0 {
   730  		case _FPE_INTDIV:
   731  			panicdivide()
   732  		case _FPE_INTOVF:
   733  			panicoverflow()
   734  		}
   735  		panicfloat()
   736  	}
   737  
   738  	if g.sig >= uint32(len(sigtable)) {
   739  		// can't happen: we looked up g.sig in sigtable to decide to call sigpanic
   740  		throw("unexpected signal value")
   741  	}
   742  	panic(errorString(sigtable[g.sig].name))
   743  }
   744  
   745  // dieFromSignal kills the program with a signal.
   746  // This provides the expected exit status for the shell.
   747  // This is only called with fatal signals expected to kill the process.
   748  //go:nosplit
   749  //go:nowritebarrierrec
   750  func dieFromSignal(sig uint32) {
   751  	unblocksig(sig)
   752  	// Mark the signal as unhandled to ensure it is forwarded.
   753  	atomic.Store(&handlingSig[sig], 0)
   754  	raise(sig)
   755  
   756  	// That should have killed us. On some systems, though, raise
   757  	// sends the signal to the whole process rather than to just
   758  	// the current thread, which means that the signal may not yet
   759  	// have been delivered. Give other threads a chance to run and
   760  	// pick up the signal.
   761  	osyield()
   762  	osyield()
   763  	osyield()
   764  
   765  	// If that didn't work, try _SIG_DFL.
   766  	setsig(sig, _SIG_DFL)
   767  	raise(sig)
   768  
   769  	osyield()
   770  	osyield()
   771  	osyield()
   772  
   773  	// If we are still somehow running, just exit with the wrong status.
   774  	exit(2)
   775  }
   776  
   777  // raisebadsignal is called when a signal is received on a non-Go
   778  // thread, and the Go program does not want to handle it (that is, the
   779  // program has not called os/signal.Notify for the signal).
   780  func raisebadsignal(sig uint32, c *sigctxt) {
   781  	if sig == _SIGPROF {
   782  		// Ignore profiling signals that arrive on non-Go threads.
   783  		return
   784  	}
   785  
   786  	var handler uintptr
   787  	if sig >= _NSIG {
   788  		handler = _SIG_DFL
   789  	} else {
   790  		handler = atomic.Loaduintptr(&fwdSig[sig])
   791  	}
   792  
   793  	// Reset the signal handler and raise the signal.
   794  	// We are currently running inside a signal handler, so the
   795  	// signal is blocked. We need to unblock it before raising the
   796  	// signal, or the signal we raise will be ignored until we return
   797  	// from the signal handler. We know that the signal was unblocked
   798  	// before entering the handler, or else we would not have received
   799  	// it. That means that we don't have to worry about blocking it
   800  	// again.
   801  	unblocksig(sig)
   802  	setsig(sig, handler)
   803  
   804  	// If we're linked into a non-Go program we want to try to
   805  	// avoid modifying the original context in which the signal
   806  	// was raised. If the handler is the default, we know it
   807  	// is non-recoverable, so we don't have to worry about
   808  	// re-installing sighandler. At this point we can just
   809  	// return and the signal will be re-raised and caught by
   810  	// the default handler with the correct context.
   811  	//
   812  	// On FreeBSD, the libthr sigaction code prevents
   813  	// this from working so we fall through to raise.
   814  	if GOOS != "freebsd" && (isarchive || islibrary) && handler == _SIG_DFL && c.sigcode() != _SI_USER {
   815  		return
   816  	}
   817  
   818  	raise(sig)
   819  
   820  	// Give the signal a chance to be delivered.
   821  	// In almost all real cases the program is about to crash,
   822  	// so sleeping here is not a waste of time.
   823  	usleep(1000)
   824  
   825  	// If the signal didn't cause the program to exit, restore the
   826  	// Go signal handler and carry on.
   827  	//
   828  	// We may receive another instance of the signal before we
   829  	// restore the Go handler, but that is not so bad: we know
   830  	// that the Go program has been ignoring the signal.
   831  	setsig(sig, funcPC(sighandler))
   832  }
   833  
   834  //go:nosplit
   835  func crash() {
   836  	// OS X core dumps are linear dumps of the mapped memory,
   837  	// from the first virtual byte to the last, with zeros in the gaps.
   838  	// Because of the way we arrange the address space on 64-bit systems,
   839  	// this means the OS X core file will be >128 GB and even on a zippy
   840  	// workstation can take OS X well over an hour to write (uninterruptible).
   841  	// Save users from making that mistake.
   842  	if GOOS == "darwin" && GOARCH == "amd64" {
   843  		return
   844  	}
   845  
   846  	dieFromSignal(_SIGABRT)
   847  }
   848  
   849  // ensureSigM starts one global, sleeping thread to make sure at least one thread
   850  // is available to catch signals enabled for os/signal.
   851  func ensureSigM() {
   852  	if maskUpdatedChan != nil {
   853  		return
   854  	}
   855  	maskUpdatedChan = make(chan struct{})
   856  	disableSigChan = make(chan uint32)
   857  	enableSigChan = make(chan uint32)
   858  	go func() {
   859  		// Signal masks are per-thread, so make sure this goroutine stays on one
   860  		// thread.
   861  		LockOSThread()
   862  		defer UnlockOSThread()
   863  		// The sigBlocked mask contains the signals not active for os/signal,
   864  		// initially all signals except the essential. When signal.Notify()/Stop is called,
   865  		// sigenable/sigdisable in turn notify this thread to update its signal
   866  		// mask accordingly.
   867  		sigBlocked := sigset_all
   868  		for i := range sigtable {
   869  			if !blockableSig(uint32(i)) {
   870  				sigdelset(&sigBlocked, i)
   871  			}
   872  		}
   873  		sigprocmask(_SIG_SETMASK, &sigBlocked, nil)
   874  		for {
   875  			select {
   876  			case sig := <-enableSigChan:
   877  				if sig > 0 {
   878  					sigdelset(&sigBlocked, int(sig))
   879  				}
   880  			case sig := <-disableSigChan:
   881  				if sig > 0 && blockableSig(sig) {
   882  					sigaddset(&sigBlocked, int(sig))
   883  				}
   884  			}
   885  			sigprocmask(_SIG_SETMASK, &sigBlocked, nil)
   886  			maskUpdatedChan <- struct{}{}
   887  		}
   888  	}()
   889  }
   890  
   891  // This is called when we receive a signal when there is no signal stack.
   892  // This can only happen if non-Go code calls sigaltstack to disable the
   893  // signal stack.
   894  func noSignalStack(sig uint32) {
   895  	println("signal", sig, "received on thread with no signal stack")
   896  	throw("non-Go code disabled sigaltstack")
   897  }
   898  
   899  // This is called if we receive a signal when there is a signal stack
   900  // but we are not on it. This can only happen if non-Go code called
   901  // sigaction without setting the SS_ONSTACK flag.
   902  func sigNotOnStack(sig uint32) {
   903  	println("signal", sig, "received but handler not on signal stack")
   904  	throw("non-Go code set up signal handler without SA_ONSTACK flag")
   905  }
   906  
   907  // signalDuringFork is called if we receive a signal while doing a fork.
   908  // We do not want signals at that time, as a signal sent to the process
   909  // group may be delivered to the child process, causing confusion.
   910  // This should never be called, because we block signals across the fork;
   911  // this function is just a safety check. See issue 18600 for background.
   912  func signalDuringFork(sig uint32) {
   913  	println("signal", sig, "received during fork")
   914  	throw("signal received during fork")
   915  }
   916  
   917  var badginsignalMsg = "fatal: bad g in signal handler\n"
   918  
   919  // This runs on a foreign stack, without an m or a g. No stack split.
   920  //go:nosplit
   921  //go:norace
   922  //go:nowritebarrierrec
   923  func badsignal(sig uintptr, c *sigctxt) {
   924  	if !iscgo && !cgoHasExtraM {
   925  		// There is no extra M. needm will not be able to grab
   926  		// an M. Instead of hanging, just crash.
   927  		// Cannot call split-stack function as there is no G.
   928  		s := stringStructOf(&badginsignalMsg)
   929  		write(2, s.str, int32(s.len))
   930  		exit(2)
   931  		*(*uintptr)(unsafe.Pointer(uintptr(123))) = 2
   932  	}
   933  	needm(0)
   934  	if !sigsend(uint32(sig)) {
   935  		// A foreign thread received the signal sig, and the
   936  		// Go code does not want to handle it.
   937  		raisebadsignal(uint32(sig), c)
   938  	}
   939  	dropm()
   940  }
   941  
   942  //go:noescape
   943  func sigfwd(fn uintptr, sig uint32, info *siginfo, ctx unsafe.Pointer)
   944  
   945  // Determines if the signal should be handled by Go and if not, forwards the
   946  // signal to the handler that was installed before Go's. Returns whether the
   947  // signal was forwarded.
   948  // This is called by the signal handler, and the world may be stopped.
   949  //go:nosplit
   950  //go:nowritebarrierrec
   951  func sigfwdgo(sig uint32, info *siginfo, ctx unsafe.Pointer) bool {
   952  	if sig >= uint32(len(sigtable)) {
   953  		return false
   954  	}
   955  	fwdFn := atomic.Loaduintptr(&fwdSig[sig])
   956  	flags := sigtable[sig].flags
   957  
   958  	// If we aren't handling the signal, forward it.
   959  	if atomic.Load(&handlingSig[sig]) == 0 || !signalsOK {
   960  		// If the signal is ignored, doing nothing is the same as forwarding.
   961  		if fwdFn == _SIG_IGN || (fwdFn == _SIG_DFL && flags&_SigIgn != 0) {
   962  			return true
   963  		}
   964  		// We are not handling the signal and there is no other handler to forward to.
   965  		// Crash with the default behavior.
   966  		if fwdFn == _SIG_DFL {
   967  			setsig(sig, _SIG_DFL)
   968  			dieFromSignal(sig)
   969  			return false
   970  		}
   971  
   972  		sigfwd(fwdFn, sig, info, ctx)
   973  		return true
   974  	}
   975  
   976  	// This function and its caller sigtrampgo assumes SIGPIPE is delivered on the
   977  	// originating thread. This property does not hold on macOS (golang.org/issue/33384),
   978  	// so we have no choice but to ignore SIGPIPE.
   979  	if GOOS == "darwin" && sig == _SIGPIPE {
   980  		return true
   981  	}
   982  
   983  	// If there is no handler to forward to, no need to forward.
   984  	if fwdFn == _SIG_DFL {
   985  		return false
   986  	}
   987  
   988  	c := &sigctxt{info, ctx}
   989  	// Only forward synchronous signals and SIGPIPE.
   990  	// Unfortunately, user generated SIGPIPEs will also be forwarded, because si_code
   991  	// is set to _SI_USER even for a SIGPIPE raised from a write to a closed socket
   992  	// or pipe.
   993  	if (c.sigcode() == _SI_USER || flags&_SigPanic == 0) && sig != _SIGPIPE {
   994  		return false
   995  	}
   996  	// Determine if the signal occurred inside Go code. We test that:
   997  	//   (1) we weren't in VDSO page,
   998  	//   (2) we were in a goroutine (i.e., m.curg != nil), and
   999  	//   (3) we weren't in CGO.
  1000  	g := sigFetchG(c)
  1001  	if g != nil && g.m != nil && g.m.curg != nil && !g.m.incgo {
  1002  		return false
  1003  	}
  1004  
  1005  	// Signal not handled by Go, forward it.
  1006  	if fwdFn != _SIG_IGN {
  1007  		sigfwd(fwdFn, sig, info, ctx)
  1008  	}
  1009  
  1010  	return true
  1011  }
  1012  
  1013  // msigsave saves the current thread's signal mask into mp.sigmask.
  1014  // This is used to preserve the non-Go signal mask when a non-Go
  1015  // thread calls a Go function.
  1016  // This is nosplit and nowritebarrierrec because it is called by needm
  1017  // which may be called on a non-Go thread with no g available.
  1018  //go:nosplit
  1019  //go:nowritebarrierrec
  1020  func msigsave(mp *m) {
  1021  	sigprocmask(_SIG_SETMASK, nil, &mp.sigmask)
  1022  }
  1023  
  1024  // msigrestore sets the current thread's signal mask to sigmask.
  1025  // This is used to restore the non-Go signal mask when a non-Go thread
  1026  // calls a Go function.
  1027  // This is nosplit and nowritebarrierrec because it is called by dropm
  1028  // after g has been cleared.
  1029  //go:nosplit
  1030  //go:nowritebarrierrec
  1031  func msigrestore(sigmask sigset) {
  1032  	sigprocmask(_SIG_SETMASK, &sigmask, nil)
  1033  }
  1034  
  1035  // sigblock blocks all signals in the current thread's signal mask.
  1036  // This is used to block signals while setting up and tearing down g
  1037  // when a non-Go thread calls a Go function.
  1038  // The OS-specific code is expected to define sigset_all.
  1039  // This is nosplit and nowritebarrierrec because it is called by needm
  1040  // which may be called on a non-Go thread with no g available.
  1041  //go:nosplit
  1042  //go:nowritebarrierrec
  1043  func sigblock() {
  1044  	sigprocmask(_SIG_SETMASK, &sigset_all, nil)
  1045  }
  1046  
  1047  // unblocksig removes sig from the current thread's signal mask.
  1048  // This is nosplit and nowritebarrierrec because it is called from
  1049  // dieFromSignal, which can be called by sigfwdgo while running in the
  1050  // signal handler, on the signal stack, with no g available.
  1051  //go:nosplit
  1052  //go:nowritebarrierrec
  1053  func unblocksig(sig uint32) {
  1054  	var set sigset
  1055  	sigaddset(&set, int(sig))
  1056  	sigprocmask(_SIG_UNBLOCK, &set, nil)
  1057  }
  1058  
  1059  // minitSignals is called when initializing a new m to set the
  1060  // thread's alternate signal stack and signal mask.
  1061  func minitSignals() {
  1062  	minitSignalStack()
  1063  	minitSignalMask()
  1064  }
  1065  
  1066  // minitSignalStack is called when initializing a new m to set the
  1067  // alternate signal stack. If the alternate signal stack is not set
  1068  // for the thread (the normal case) then set the alternate signal
  1069  // stack to the gsignal stack. If the alternate signal stack is set
  1070  // for the thread (the case when a non-Go thread sets the alternate
  1071  // signal stack and then calls a Go function) then set the gsignal
  1072  // stack to the alternate signal stack. We also set the alternate
  1073  // signal stack to the gsignal stack if cgo is not used (regardless
  1074  // of whether it is already set). Record which choice was made in
  1075  // newSigstack, so that it can be undone in unminit.
  1076  func minitSignalStack() {
  1077  	_g_ := getg()
  1078  	var st stackt
  1079  	sigaltstack(nil, &st)
  1080  	if st.ss_flags&_SS_DISABLE != 0 || !iscgo {
  1081  		signalstack(&_g_.m.gsignal.stack)
  1082  		_g_.m.newSigstack = true
  1083  	} else {
  1084  		setGsignalStack(&st, &_g_.m.goSigStack)
  1085  		_g_.m.newSigstack = false
  1086  	}
  1087  }
  1088  
  1089  // minitSignalMask is called when initializing a new m to set the
  1090  // thread's signal mask. When this is called all signals have been
  1091  // blocked for the thread.  This starts with m.sigmask, which was set
  1092  // either from initSigmask for a newly created thread or by calling
  1093  // msigsave if this is a non-Go thread calling a Go function. It
  1094  // removes all essential signals from the mask, thus causing those
  1095  // signals to not be blocked. Then it sets the thread's signal mask.
  1096  // After this is called the thread can receive signals.
  1097  func minitSignalMask() {
  1098  	nmask := getg().m.sigmask
  1099  	for i := range sigtable {
  1100  		if !blockableSig(uint32(i)) {
  1101  			sigdelset(&nmask, i)
  1102  		}
  1103  	}
  1104  	sigprocmask(_SIG_SETMASK, &nmask, nil)
  1105  }
  1106  
  1107  // unminitSignals is called from dropm, via unminit, to undo the
  1108  // effect of calling minit on a non-Go thread.
  1109  //go:nosplit
  1110  func unminitSignals() {
  1111  	if getg().m.newSigstack {
  1112  		st := stackt{ss_flags: _SS_DISABLE}
  1113  		sigaltstack(&st, nil)
  1114  	} else {
  1115  		// We got the signal stack from someone else. Restore
  1116  		// the Go-allocated stack in case this M gets reused
  1117  		// for another thread (e.g., it's an extram). Also, on
  1118  		// Android, libc allocates a signal stack for all
  1119  		// threads, so it's important to restore the Go stack
  1120  		// even on Go-created threads so we can free it.
  1121  		restoreGsignalStack(&getg().m.goSigStack)
  1122  	}
  1123  }
  1124  
  1125  // blockableSig reports whether sig may be blocked by the signal mask.
  1126  // We never want to block the signals marked _SigUnblock;
  1127  // these are the synchronous signals that turn into a Go panic.
  1128  // In a Go program--not a c-archive/c-shared--we never want to block
  1129  // the signals marked _SigKill or _SigThrow, as otherwise it's possible
  1130  // for all running threads to block them and delay their delivery until
  1131  // we start a new thread. When linked into a C program we let the C code
  1132  // decide on the disposition of those signals.
  1133  func blockableSig(sig uint32) bool {
  1134  	flags := sigtable[sig].flags
  1135  	if flags&_SigUnblock != 0 {
  1136  		return false
  1137  	}
  1138  	if isarchive || islibrary {
  1139  		return true
  1140  	}
  1141  	return flags&(_SigKill|_SigThrow) == 0
  1142  }
  1143  
  1144  // gsignalStack saves the fields of the gsignal stack changed by
  1145  // setGsignalStack.
  1146  type gsignalStack struct {
  1147  	stack       stack
  1148  	stackguard0 uintptr
  1149  	stackguard1 uintptr
  1150  	stktopsp    uintptr
  1151  }
  1152  
  1153  // setGsignalStack sets the gsignal stack of the current m to an
  1154  // alternate signal stack returned from the sigaltstack system call.
  1155  // It saves the old values in *old for use by restoreGsignalStack.
  1156  // This is used when handling a signal if non-Go code has set the
  1157  // alternate signal stack.
  1158  //go:nosplit
  1159  //go:nowritebarrierrec
  1160  func setGsignalStack(st *stackt, old *gsignalStack) {
  1161  	g := getg()
  1162  	if old != nil {
  1163  		old.stack = g.m.gsignal.stack
  1164  		old.stackguard0 = g.m.gsignal.stackguard0
  1165  		old.stackguard1 = g.m.gsignal.stackguard1
  1166  		old.stktopsp = g.m.gsignal.stktopsp
  1167  	}
  1168  	stsp := uintptr(unsafe.Pointer(st.ss_sp))
  1169  	g.m.gsignal.stack.lo = stsp
  1170  	g.m.gsignal.stack.hi = stsp + st.ss_size
  1171  	g.m.gsignal.stackguard0 = stsp + _StackGuard
  1172  	g.m.gsignal.stackguard1 = stsp + _StackGuard
  1173  }
  1174  
  1175  // restoreGsignalStack restores the gsignal stack to the value it had
  1176  // before entering the signal handler.
  1177  //go:nosplit
  1178  //go:nowritebarrierrec
  1179  func restoreGsignalStack(st *gsignalStack) {
  1180  	gp := getg().m.gsignal
  1181  	gp.stack = st.stack
  1182  	gp.stackguard0 = st.stackguard0
  1183  	gp.stackguard1 = st.stackguard1
  1184  	gp.stktopsp = st.stktopsp
  1185  }
  1186  
  1187  // signalstack sets the current thread's alternate signal stack to s.
  1188  //go:nosplit
  1189  func signalstack(s *stack) {
  1190  	st := stackt{ss_size: s.hi - s.lo}
  1191  	setSignalstackSP(&st, s.lo)
  1192  	sigaltstack(&st, nil)
  1193  }
  1194  
  1195  // setsigsegv is used on darwin/arm64 to fake a segmentation fault.
  1196  //
  1197  // This is exported via linkname to assembly in runtime/cgo.
  1198  //
  1199  //go:nosplit
  1200  //go:linkname setsigsegv
  1201  func setsigsegv(pc uintptr) {
  1202  	g := getg()
  1203  	g.sig = _SIGSEGV
  1204  	g.sigpc = pc
  1205  	g.sigcode0 = _SEGV_MAPERR
  1206  	g.sigcode1 = 0 // TODO: emulate si_addr
  1207  }
  1208  

View as plain text