Source file
src/runtime/os_dragonfly.go
Documentation: runtime
1
2
3
4
5 package runtime
6
7 import (
8 "internal/abi"
9 "internal/goarch"
10 "unsafe"
11 )
12
13 const (
14 _NSIG = 33
15 _SI_USER = 0
16 _SS_DISABLE = 4
17 _SIG_BLOCK = 1
18 _SIG_UNBLOCK = 2
19 _SIG_SETMASK = 3
20 )
21
22 type mOS struct{}
23
24
25 func lwp_create(param *lwpparams) int32
26
27
28 func sigaltstack(new, old *stackt)
29
30
31 func sigaction(sig uint32, new, old *sigactiont)
32
33
34 func sigprocmask(how int32, new, old *sigset)
35
36
37 func setitimer(mode int32, new, old *itimerval)
38
39
40 func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, ndst uintptr) int32
41
42 func raiseproc(sig uint32)
43
44 func lwp_gettid() int32
45 func lwp_kill(pid, tid int32, sig int)
46
47
48 func sys_umtx_sleep(addr *uint32, val, timeout int32) int32
49
50
51 func sys_umtx_wakeup(addr *uint32, val int32) int32
52
53 func osyield()
54
55
56 func osyield_no_g() {
57 osyield()
58 }
59
60 func kqueue() int32
61
62
63 func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32
64
65 func pipe2(flags int32) (r, w int32, errno int32)
66 func fcntl(fd, cmd, arg int32) (ret int32, errno int32)
67
68 func issetugid() int32
69
70
71 const (
72 _CTL_HW = 6
73 _HW_NCPU = 3
74 _HW_PAGESIZE = 7
75 )
76
77 var sigset_all = sigset{[4]uint32{^uint32(0), ^uint32(0), ^uint32(0), ^uint32(0)}}
78
79 func getncpu() int32 {
80 mib := [2]uint32{_CTL_HW, _HW_NCPU}
81 out := uint32(0)
82 nout := unsafe.Sizeof(out)
83 ret := sysctl(&mib[0], 2, (*byte)(unsafe.Pointer(&out)), &nout, nil, 0)
84 if ret >= 0 {
85 return int32(out)
86 }
87 return 1
88 }
89
90 func getPageSize() uintptr {
91 mib := [2]uint32{_CTL_HW, _HW_PAGESIZE}
92 out := uint32(0)
93 nout := unsafe.Sizeof(out)
94 ret := sysctl(&mib[0], 2, (*byte)(unsafe.Pointer(&out)), &nout, nil, 0)
95 if ret >= 0 {
96 return uintptr(out)
97 }
98 return 0
99 }
100
101
102 func futexsleep(addr *uint32, val uint32, ns int64) {
103 systemstack(func() {
104 futexsleep1(addr, val, ns)
105 })
106 }
107
108 func futexsleep1(addr *uint32, val uint32, ns int64) {
109 var timeout int32
110 if ns >= 0 {
111
112
113
114 timeout = timediv(ns, 1000, nil)
115 if timeout == 0 {
116 timeout = 1
117 }
118 }
119
120
121
122 ret := sys_umtx_sleep(addr, int32(val), timeout)
123 if ret >= 0 || ret == -_EINTR || ret == -_EAGAIN || ret == -_EBUSY {
124 return
125 }
126
127 print("umtx_sleep addr=", addr, " val=", val, " ret=", ret, "\n")
128 *(*int32)(unsafe.Pointer(uintptr(0x1005))) = 0x1005
129 }
130
131
132 func futexwakeup(addr *uint32, cnt uint32) {
133 ret := sys_umtx_wakeup(addr, int32(cnt))
134 if ret >= 0 {
135 return
136 }
137
138 systemstack(func() {
139 print("umtx_wake_addr=", addr, " ret=", ret, "\n")
140 *(*int32)(unsafe.Pointer(uintptr(0x1006))) = 0x1006
141 })
142 }
143
144 func lwp_start(uintptr)
145
146
147
148
149 func newosproc(mp *m) {
150 stk := unsafe.Pointer(mp.g0.stack.hi)
151 if false {
152 print("newosproc stk=", stk, " m=", mp, " g=", mp.g0, " lwp_start=", abi.FuncPCABI0(lwp_start), " id=", mp.id, " ostk=", &mp, "\n")
153 }
154
155 var oset sigset
156 sigprocmask(_SIG_SETMASK, &sigset_all, &oset)
157
158 params := lwpparams{
159 start_func: abi.FuncPCABI0(lwp_start),
160 arg: unsafe.Pointer(mp),
161 stack: uintptr(stk),
162 tid1: nil,
163 tid2: nil,
164 }
165
166
167 retryOnEAGAIN(func() int32 {
168 lwp_create(¶ms)
169 return 0
170 })
171 sigprocmask(_SIG_SETMASK, &oset, nil)
172 }
173
174 func osinit() {
175 ncpu = getncpu()
176 if physPageSize == 0 {
177 physPageSize = getPageSize()
178 }
179 }
180
181 var urandom_dev = []byte("/dev/urandom\x00")
182
183
184 func readRandom(r []byte) int {
185 fd := open(&urandom_dev[0], 0 , 0)
186 n := read(fd, unsafe.Pointer(&r[0]), int32(len(r)))
187 closefd(fd)
188 return int(n)
189 }
190
191 func goenvs() {
192 goenvs_unix()
193 }
194
195
196
197 func mpreinit(mp *m) {
198 mp.gsignal = malg(32 * 1024)
199 mp.gsignal.m = mp
200 }
201
202
203
204 func minit() {
205 getg().m.procid = uint64(lwp_gettid())
206 minitSignals()
207 }
208
209
210
211
212 func unminit() {
213 unminitSignals()
214 getg().m.procid = 0
215 }
216
217
218
219 func mdestroy(mp *m) {
220 }
221
222 func sigtramp()
223
224 type sigactiont struct {
225 sa_sigaction uintptr
226 sa_flags int32
227 sa_mask sigset
228 }
229
230
231
232 func setsig(i uint32, fn uintptr) {
233 var sa sigactiont
234 sa.sa_flags = _SA_SIGINFO | _SA_ONSTACK | _SA_RESTART
235 sa.sa_mask = sigset_all
236 if fn == abi.FuncPCABIInternal(sighandler) {
237 fn = abi.FuncPCABI0(sigtramp)
238 }
239 sa.sa_sigaction = fn
240 sigaction(i, &sa, nil)
241 }
242
243
244
245 func setsigstack(i uint32) {
246 throw("setsigstack")
247 }
248
249
250
251 func getsig(i uint32) uintptr {
252 var sa sigactiont
253 sigaction(i, nil, &sa)
254 return sa.sa_sigaction
255 }
256
257
258
259
260 func setSignalstackSP(s *stackt, sp uintptr) {
261 s.ss_sp = sp
262 }
263
264
265
266 func sigaddset(mask *sigset, i int) {
267 mask.__bits[(i-1)/32] |= 1 << ((uint32(i) - 1) & 31)
268 }
269
270 func sigdelset(mask *sigset, i int) {
271 mask.__bits[(i-1)/32] &^= 1 << ((uint32(i) - 1) & 31)
272 }
273
274
275 func (c *sigctxt) fixsigcode(sig uint32) {
276 }
277
278 func setProcessCPUProfiler(hz int32) {
279 setProcessCPUProfilerTimer(hz)
280 }
281
282 func setThreadCPUProfiler(hz int32) {
283 setThreadCPUProfilerHz(hz)
284 }
285
286
287 func validSIGPROF(mp *m, c *sigctxt) bool {
288 return true
289 }
290
291 func sysargs(argc int32, argv **byte) {
292 n := argc + 1
293
294
295 for argv_index(argv, n) != nil {
296 n++
297 }
298
299
300 n++
301
302 auxvp := (*[1 << 28]uintptr)(add(unsafe.Pointer(argv), uintptr(n)*goarch.PtrSize))
303 pairs := sysauxv(auxvp[:])
304 auxv = auxvp[: pairs*2 : pairs*2]
305 }
306
307 const (
308 _AT_NULL = 0
309 _AT_PAGESZ = 6
310 )
311
312 func sysauxv(auxv []uintptr) (pairs int) {
313 var i int
314 for i = 0; auxv[i] != _AT_NULL; i += 2 {
315 tag, val := auxv[i], auxv[i+1]
316 switch tag {
317 case _AT_PAGESZ:
318 physPageSize = val
319 }
320 }
321 return i / 2
322 }
323
324
325
326
327
328
329
330 func raise(sig uint32) {
331 lwp_kill(-1, lwp_gettid(), int(sig))
332 }
333
334 func signalM(mp *m, sig int) {
335 lwp_kill(-1, int32(mp.procid), sig)
336 }
337
338
339
340 const sigPerThreadSyscall = 1 << 31
341
342
343 func runPerThreadSyscall() {
344 throw("runPerThreadSyscall only valid on linux")
345 }
346
View as plain text