Skip to content

Commit dab3e5a

Browse files
committed
runtime: switch runtime to libc for openbsd/amd64
Use libc rather than performing direct system calls for the runtime on openbsd/amd64. Updates #36435 Change-Id: Ib708009c3743f56a3fd6cb3bc731451e4a398849 Reviewed-on: https://go-review.googlesource.com/c/go/+/270379 Trust: Joel Sing <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent a1b53d8 commit dab3e5a

12 files changed

+641
-343
lines changed

src/runtime/defs_openbsd.go

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ const (
5656

5757
PTHREAD_CREATE_DETACHED = C.PTHREAD_CREATE_DETACHED
5858

59+
F_SETFD = C.F_SETFD
60+
F_GETFL = C.F_GETFL
61+
F_SETFL = C.F_SETFL
62+
FD_CLOEXEC = C.FD_CLOEXEC
63+
5964
SIGHUP = C.SIGHUP
6065
SIGINT = C.SIGINT
6166
SIGQUIT = C.SIGQUIT

src/runtime/defs_openbsd_amd64.go

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ const (
3232

3333
_PTHREAD_CREATE_DETACHED = 0x1
3434

35+
_F_SETFD = 0x2
36+
_F_GETFL = 0x3
37+
_F_SETFL = 0x4
38+
_FD_CLOEXEC = 0x1
39+
3540
_SIGHUP = 0x1
3641
_SIGINT = 0x2
3742
_SIGQUIT = 0x3

src/runtime/mmap.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
// +build !aix
6+
// +build !darwin
7+
// +build !js
8+
// +build !linux !amd64
9+
// +build !linux !arm64
10+
// +build !openbsd
511
// +build !plan9
612
// +build !solaris
713
// +build !windows
8-
// +build !linux !amd64
9-
// +build !linux !arm64
10-
// +build !js
11-
// +build !darwin
12-
// +build !aix
1314

1415
package runtime
1516

src/runtime/os_openbsd.go

-43
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,6 @@ type mOS struct {
1313
waitsemacount uint32
1414
}
1515

16-
//go:noescape
17-
func setitimer(mode int32, new, old *itimerval)
18-
19-
//go:noescape
20-
func sigaction(sig uint32, new, old *sigactiont)
21-
22-
//go:noescape
23-
func sigaltstack(new, old *stackt)
24-
25-
//go:noescape
26-
func obsdsigprocmask(how int32, new sigset) sigset
27-
28-
//go:nosplit
29-
//go:nowritebarrierrec
30-
func sigprocmask(how int32, new, old *sigset) {
31-
n := sigset(0)
32-
if new != nil {
33-
n = *new
34-
}
35-
r := obsdsigprocmask(how, n)
36-
if old != nil {
37-
*old = r
38-
}
39-
}
40-
41-
//go:noescape
42-
func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, ndst uintptr) int32
43-
44-
func raiseproc(sig uint32)
45-
46-
func getthrid() int32
47-
func thrkill(tid int32, sig int)
48-
49-
func kqueue() int32
50-
51-
//go:noescape
52-
func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32
53-
54-
func pipe() (r, w int32, errno int32)
55-
func pipe2(flags int32) (r, w int32, errno int32)
56-
func closeonexec(fd int32)
57-
func setNonblock(fd int32)
58-
5916
const (
6017
_ESRCH = 3
6118
_EWOULDBLOCK = _EAGAIN

src/runtime/os_openbsd_syscall2.go

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright 2020 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 openbsd,!amd64
6+
7+
package runtime
8+
9+
import (
10+
"unsafe"
11+
)
12+
13+
//go:noescape
14+
func sigaction(sig uint32, new, old *sigactiont)
15+
16+
func kqueue() int32
17+
18+
//go:noescape
19+
func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32
20+
21+
func raiseproc(sig uint32)
22+
23+
func getthrid() int32
24+
func thrkill(tid int32, sig int)
25+
26+
// read calls the read system call.
27+
// It returns a non-negative number of bytes written or a negative errno value.
28+
func read(fd int32, p unsafe.Pointer, n int32) int32
29+
30+
func closefd(fd int32) int32
31+
32+
func exit(code int32)
33+
func usleep(usec uint32)
34+
35+
// write calls the write system call.
36+
// It returns a non-negative number of bytes written or a negative errno value.
37+
//go:noescape
38+
func write1(fd uintptr, p unsafe.Pointer, n int32) int32
39+
40+
//go:noescape
41+
func open(name *byte, mode, perm int32) int32
42+
43+
// return value is only set on linux to be used in osinit()
44+
func madvise(addr unsafe.Pointer, n uintptr, flags int32) int32
45+
46+
// exitThread terminates the current thread, writing *wait = 0 when
47+
// the stack is safe to reclaim.
48+
//
49+
//go:noescape
50+
func exitThread(wait *uint32)
51+
52+
//go:noescape
53+
func obsdsigprocmask(how int32, new sigset) sigset
54+
55+
//go:nosplit
56+
//go:nowritebarrierrec
57+
func sigprocmask(how int32, new, old *sigset) {
58+
n := sigset(0)
59+
if new != nil {
60+
n = *new
61+
}
62+
r := obsdsigprocmask(how, n)
63+
if old != nil {
64+
*old = r
65+
}
66+
}
67+
68+
func pipe() (r, w int32, errno int32)
69+
func pipe2(flags int32) (r, w int32, errno int32)
70+
71+
//go:noescape
72+
func setitimer(mode int32, new, old *itimerval)
73+
74+
//go:noescape
75+
func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, ndst uintptr) int32
76+
77+
// mmap calls the mmap system call. It is implemented in assembly.
78+
// We only pass the lower 32 bits of file offset to the
79+
// assembly routine; the higher bits (if required), should be provided
80+
// by the assembly routine as 0.
81+
// The err result is an OS error code such as ENOMEM.
82+
func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (p unsafe.Pointer, err int)
83+
84+
// munmap calls the munmap system call. It is implemented in assembly.
85+
func munmap(addr unsafe.Pointer, n uintptr)
86+
87+
func nanotime1() int64
88+
89+
//go:noescape
90+
func sigaltstack(new, old *stackt)
91+
92+
func closeonexec(fd int32)
93+
func setNonblock(fd int32)
94+
95+
func walltime1() (sec int64, nsec int32)

src/runtime/proc.go

+2
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,8 @@ func usesLibcall() bool {
12121212
switch GOOS {
12131213
case "aix", "darwin", "illumos", "ios", "solaris", "windows":
12141214
return true
1215+
case "openbsd":
1216+
return GOARCH == "amd64"
12151217
}
12161218
return false
12171219
}

src/runtime/signal_openbsd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ var sigtable = [...]sigTabT{
3737
/* 29 */ {_SigNotify, "SIGINFO: status request from keyboard"},
3838
/* 30 */ {_SigNotify, "SIGUSR1: user-defined signal 1"},
3939
/* 31 */ {_SigNotify, "SIGUSR2: user-defined signal 2"},
40-
/* 32 */ {_SigNotify, "SIGTHR: reserved"},
40+
/* 32 */ {0, "SIGTHR: reserved"}, // thread AST - cannot be registered.
4141
}

src/runtime/stubs2.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
// +build !aix
6+
// +build !darwin
7+
// +build !js
8+
// +build !openbsd
59
// +build !plan9
610
// +build !solaris
711
// +build !windows
8-
// +build !js
9-
// +build !darwin
10-
// +build !aix
1112

1213
package runtime
1314

src/runtime/stubs3.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
// +build !aix
6+
// +build !darwin
7+
// +build !freebsd
8+
// +build !openbsd
59
// +build !plan9
610
// +build !solaris
7-
// +build !freebsd
8-
// +build !darwin
9-
// +build !aix
1011

1112
package runtime
1213

0 commit comments

Comments
 (0)