Source file
src/runtime/sys_openbsd2.go
1
2
3
4
5
6
7 package runtime
8
9 import (
10 "internal/abi"
11 "unsafe"
12 )
13
14
15
16
17
18 func exit(code int32) {
19 libcCall(unsafe.Pointer(abi.FuncPCABI0(exit_trampoline)), unsafe.Pointer(&code))
20 }
21 func exit_trampoline()
22
23
24
25 func getthrid() (tid int32) {
26 libcCall(unsafe.Pointer(abi.FuncPCABI0(getthrid_trampoline)), unsafe.Pointer(&tid))
27 return
28 }
29 func getthrid_trampoline()
30
31
32
33 func raiseproc(sig uint32) {
34 libcCall(unsafe.Pointer(abi.FuncPCABI0(raiseproc_trampoline)), unsafe.Pointer(&sig))
35 }
36 func raiseproc_trampoline()
37
38
39
40 func thrkill(tid int32, sig int) {
41 libcCall(unsafe.Pointer(abi.FuncPCABI0(thrkill_trampoline)), unsafe.Pointer(&tid))
42 }
43 func thrkill_trampoline()
44
45
46
47
48
49 func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (unsafe.Pointer, int) {
50 args := struct {
51 addr unsafe.Pointer
52 n uintptr
53 prot, flags, fd int32
54 off uint32
55 ret1 unsafe.Pointer
56 ret2 int
57 }{addr, n, prot, flags, fd, off, nil, 0}
58 libcCall(unsafe.Pointer(abi.FuncPCABI0(mmap_trampoline)), unsafe.Pointer(&args))
59 KeepAlive(addr)
60 return args.ret1, args.ret2
61 }
62 func mmap_trampoline()
63
64
65
66 func munmap(addr unsafe.Pointer, n uintptr) {
67 libcCall(unsafe.Pointer(abi.FuncPCABI0(munmap_trampoline)), unsafe.Pointer(&addr))
68 KeepAlive(addr)
69 }
70 func munmap_trampoline()
71
72
73
74 func madvise(addr unsafe.Pointer, n uintptr, flags int32) {
75 libcCall(unsafe.Pointer(abi.FuncPCABI0(madvise_trampoline)), unsafe.Pointer(&addr))
76 KeepAlive(addr)
77 }
78 func madvise_trampoline()
79
80
81
82 func open(name *byte, mode, perm int32) (ret int32) {
83 ret = libcCall(unsafe.Pointer(abi.FuncPCABI0(open_trampoline)), unsafe.Pointer(&name))
84 KeepAlive(name)
85 return
86 }
87 func open_trampoline()
88
89
90
91 func closefd(fd int32) int32 {
92 return libcCall(unsafe.Pointer(abi.FuncPCABI0(close_trampoline)), unsafe.Pointer(&fd))
93 }
94 func close_trampoline()
95
96
97
98 func read(fd int32, p unsafe.Pointer, n int32) int32 {
99 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(read_trampoline)), unsafe.Pointer(&fd))
100 KeepAlive(p)
101 return ret
102 }
103 func read_trampoline()
104
105
106
107 func write1(fd uintptr, p unsafe.Pointer, n int32) int32 {
108 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(write_trampoline)), unsafe.Pointer(&fd))
109 KeepAlive(p)
110 return ret
111 }
112 func write_trampoline()
113
114 func pipe() (r, w int32, errno int32) {
115 return pipe2(0)
116 }
117
118 func pipe2(flags int32) (r, w int32, errno int32) {
119 var p [2]int32
120 args := struct {
121 p unsafe.Pointer
122 flags int32
123 }{noescape(unsafe.Pointer(&p)), flags}
124 errno = libcCall(unsafe.Pointer(abi.FuncPCABI0(pipe2_trampoline)), unsafe.Pointer(&args))
125 return p[0], p[1], errno
126 }
127 func pipe2_trampoline()
128
129
130
131 func setitimer(mode int32, new, old *itimerval) {
132 libcCall(unsafe.Pointer(abi.FuncPCABI0(setitimer_trampoline)), unsafe.Pointer(&mode))
133 KeepAlive(new)
134 KeepAlive(old)
135 }
136 func setitimer_trampoline()
137
138
139
140 func usleep(usec uint32) {
141 libcCall(unsafe.Pointer(abi.FuncPCABI0(usleep_trampoline)), unsafe.Pointer(&usec))
142 }
143 func usleep_trampoline()
144
145
146
147 func usleep_no_g(usec uint32) {
148 asmcgocall_no_g(unsafe.Pointer(abi.FuncPCABI0(usleep_trampoline)), unsafe.Pointer(&usec))
149 }
150
151
152
153 func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, ndst uintptr) int32 {
154 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(sysctl_trampoline)), unsafe.Pointer(&mib))
155 KeepAlive(mib)
156 KeepAlive(out)
157 KeepAlive(size)
158 KeepAlive(dst)
159 return ret
160 }
161 func sysctl_trampoline()
162
163
164
165 func fcntl(fd, cmd, arg int32) int32 {
166 return libcCall(unsafe.Pointer(abi.FuncPCABI0(fcntl_trampoline)), unsafe.Pointer(&fd))
167 }
168 func fcntl_trampoline()
169
170
171 func nanotime1() int64 {
172 var ts timespec
173 args := struct {
174 clock_id int32
175 tp unsafe.Pointer
176 }{_CLOCK_MONOTONIC, unsafe.Pointer(&ts)}
177 if errno := libcCall(unsafe.Pointer(abi.FuncPCABI0(clock_gettime_trampoline)), unsafe.Pointer(&args)); errno < 0 {
178
179 systemstack(func() {
180 println("runtime: errno", -errno)
181 throw("clock_gettime failed")
182 })
183 }
184 return ts.tv_sec*1e9 + int64(ts.tv_nsec)
185 }
186 func clock_gettime_trampoline()
187
188
189 func walltime() (int64, int32) {
190 var ts timespec
191 args := struct {
192 clock_id int32
193 tp unsafe.Pointer
194 }{_CLOCK_REALTIME, unsafe.Pointer(&ts)}
195 if errno := libcCall(unsafe.Pointer(abi.FuncPCABI0(clock_gettime_trampoline)), unsafe.Pointer(&args)); errno < 0 {
196
197 systemstack(func() {
198 println("runtime: errno", -errno)
199 throw("clock_gettime failed")
200 })
201 }
202 return ts.tv_sec, int32(ts.tv_nsec)
203 }
204
205
206
207 func kqueue() int32 {
208 return libcCall(unsafe.Pointer(abi.FuncPCABI0(kqueue_trampoline)), nil)
209 }
210 func kqueue_trampoline()
211
212
213
214 func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32 {
215 ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(kevent_trampoline)), unsafe.Pointer(&kq))
216 KeepAlive(ch)
217 KeepAlive(ev)
218 KeepAlive(ts)
219 return ret
220 }
221 func kevent_trampoline()
222
223
224
225 func sigaction(sig uint32, new *sigactiont, old *sigactiont) {
226 libcCall(unsafe.Pointer(abi.FuncPCABI0(sigaction_trampoline)), unsafe.Pointer(&sig))
227 KeepAlive(new)
228 KeepAlive(old)
229 }
230 func sigaction_trampoline()
231
232
233
234 func sigprocmask(how uint32, new *sigset, old *sigset) {
235
236
237 asmcgocall_no_g(unsafe.Pointer(abi.FuncPCABI0(sigprocmask_trampoline)), unsafe.Pointer(&how))
238 KeepAlive(new)
239 KeepAlive(old)
240 }
241 func sigprocmask_trampoline()
242
243
244
245 func sigaltstack(new *stackt, old *stackt) {
246 libcCall(unsafe.Pointer(abi.FuncPCABI0(sigaltstack_trampoline)), unsafe.Pointer(&new))
247 KeepAlive(new)
248 KeepAlive(old)
249 }
250 func sigaltstack_trampoline()
251
252
253 func exitThread(wait *uint32) {
254 }
255
256
257 func closeonexec(fd int32) {
258 fcntl(fd, _F_SETFD, _FD_CLOEXEC)
259 }
260
261
262 func setNonblock(fd int32) {
263 flags := fcntl(fd, _F_GETFL, 0)
264 fcntl(fd, _F_SETFL, flags|_O_NONBLOCK)
265 }
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
View as plain text