libstdc++: Define __glibcxx_assert_fail for non-verbose build [PR115585]
[official-gcc.git] / libgo / go / runtime / export_unix_test.go
blob158c59024fcfbe40b41bfc501cc9756312dc5afd
1 // Copyright 2017 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.
5 //go:build aix || darwin || dragonfly || freebsd || hurd || linux || netbsd || openbsd || solaris
7 package runtime
9 import "unsafe"
11 var NonblockingPipe = nonblockingPipe
12 var SetNonblock = setNonblock
13 var Closeonexec = closeonexec
15 func sigismember(mask *sigset, i int) bool {
16 clear := *mask
17 sigdelset(&clear, i)
18 return clear != *mask
21 func Sigisblocked(i int) bool {
22 var sigmask sigset
23 sigprocmask(_SIG_SETMASK, nil, &sigmask)
24 return sigismember(&sigmask, i)
27 type M = m
29 var waitForSigusr1 struct {
30 rdpipe int32
31 wrpipe int32
32 mID int64
35 // WaitForSigusr1 blocks until a SIGUSR1 is received. It calls ready
36 // when it is set up to receive SIGUSR1. The ready function should
37 // cause a SIGUSR1 to be sent. The r and w arguments are a pipe that
38 // the signal handler can use to report when the signal is received.
40 // Once SIGUSR1 is received, it returns the ID of the current M and
41 // the ID of the M the SIGUSR1 was received on. If the caller writes
42 // a non-zero byte to w, WaitForSigusr1 returns immediately with -1, -1.
43 func WaitForSigusr1(r, w int32, ready func(mp *M)) (int64, int64) {
44 lockOSThread()
45 // Make sure we can receive SIGUSR1.
46 unblocksig(_SIGUSR1)
48 waitForSigusr1.rdpipe = r
49 waitForSigusr1.wrpipe = w
51 mp := getg().m
52 testSigusr1 = waitForSigusr1Callback
53 ready(mp)
55 // Wait for the signal. We use a pipe rather than a note
56 // because write is always async-signal-safe.
57 entersyscallblock()
58 var b byte
59 read(waitForSigusr1.rdpipe, noescape(unsafe.Pointer(&b)), 1)
60 exitsyscall()
62 gotM := waitForSigusr1.mID
63 testSigusr1 = nil
65 unlockOSThread()
67 if b != 0 {
68 // timeout signal from caller
69 return -1, -1
71 return mp.id, gotM
74 // waitForSigusr1Callback is called from the signal handler during
75 // WaitForSigusr1. It must not have write barriers because there may
76 // not be a P.
78 //go:nowritebarrierrec
79 func waitForSigusr1Callback(gp *g) bool {
80 if gp == nil || gp.m == nil {
81 waitForSigusr1.mID = -1
82 } else {
83 waitForSigusr1.mID = gp.m.id
85 b := byte(0)
86 write(uintptr(waitForSigusr1.wrpipe), noescape(unsafe.Pointer(&b)), 1)
87 return true
90 // SendSigusr1 sends SIGUSR1 to mp.
91 func SendSigusr1(mp *M) {
92 panic("SendSigusr1")