Source file
src/runtime/cgo/cgo_linux_sigaction.go
1
2
3
4
5
6
7 package cgo
8
9 import "unsafe"
10
11
12 var _cgo_libc_sigaction byte
13 var libc_sigaction = unsafe.Pointer(&_cgo_libc_sigaction)
14
15
16 var _cgoSigaction = cgoSigaction
17
18
19
20
21
22
23
24
25
26 func sigactionCall(noG bool, fn, a0, a1, a2 uintptr) uintptr {
27 var f cgoCallFrame
28 f.fn, f.a0, f.a1, f.a2 = fn, a0, a1, a2
29 if noG {
30 runtime_asmcgocall_no_g(cgoCallTrampolinePC(), unsafe.Pointer(&f))
31 } else {
32 runtime_asmcgocall(cgoCallTrampolinePC(), unsafe.Pointer(&f))
33 }
34 return f.r1
35 }
36
37
38
39
40
41
42
43
44
45 func (act *cSigaction) restrictMask(gomask uint64) {
46 act.mask[0] &= uintptr(gomask)
47 n := 1
48 if unsafe.Sizeof(uintptr(0)) == 4 && len(act.mask) > 1 {
49 act.mask[:][1] &= uintptr(gomask >> 32)
50 n = 2
51 }
52 for i := n; i < len(act.mask); i++ {
53 act.mask[i] = 0
54 }
55 }
56
57
58
59
60 func cgoSigaction(signum uintptr, goact, oldgoact *goSigaction, noG bool) int32 {
61
62
63
64 const _SA_RESTORER = 0x4000000
65
66 tsanAcquireMode(noG)
67
68 var oldact cSigaction
69 var actPtr, oldactPtr uintptr
70
71 if goact != nil {
72 var act cSigaction
73 act.handler = goact.handler
74 sigactionCall(noG, uintptr(libc_sigfillset), uintptr(unsafe.Pointer(&act.mask)), 0, 0)
75 act.restrictMask(goact.mask)
76 act.flags = int32(goact.flags &^ _SA_RESTORER)
77 msanUnpoisonMode(noG, unsafe.Pointer(&act), unsafe.Sizeof(act))
78 actPtr = uintptr(unsafe.Pointer(&act))
79 }
80 if oldgoact != nil {
81 oldactPtr = uintptr(unsafe.Pointer(&oldact))
82 }
83
84 ret := int32(sigactionCall(noG, uintptr(libc_sigaction), uintptr(int32(signum)), actPtr, oldactPtr))
85 if ret == -1 {
86
87 errnoPtr := sigactionCall(noG, uintptr(libc_errno_location), 0, 0, 0)
88 errno := *(*int32)(unsafe.Pointer(errnoPtr))
89 tsanReleaseMode(noG)
90 return errno
91 }
92
93 if oldgoact != nil {
94 oldgoact.handler = oldact.handler
95 oldgoact.mask = uint64(oldact.mask[0])
96 if unsafe.Sizeof(uintptr(0)) == 4 && len(oldact.mask) > 1 {
97 oldgoact.mask |= uint64(oldact.mask[:][1]) << 32
98 }
99 oldgoact.flags = uintptr(uint32(oldact.flags))
100 msanUnpoisonMode(noG, unsafe.Pointer(oldgoact), unsafe.Sizeof(*oldgoact))
101 }
102
103 tsanReleaseMode(noG)
104 return ret
105 }
106
View as plain text