aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorJoel Sing <joel@sing.id.au>2021-01-16 04:38:50 +1100
committerJoel Sing <joel@sing.id.au>2021-01-20 09:06:08 +0000
commit928bda4f4a88efe2e53f3607e8d2ad0796b449c0 (patch)
treed9cd405d88ffc881d8d903535c3582d96f85fb1b /src/runtime
parent824f2d635ca96a7bded6ed039f8a9c0f06ee1443 (diff)
downloadgo-928bda4f4a88efe2e53f3607e8d2ad0796b449c0.tar.gz
go-928bda4f4a88efe2e53f3607e8d2ad0796b449c0.zip
runtime: convert openbsd/amd64 locking to libc
Switch openbsd/amd64 to locking via libc, rather than performing direct system calls. Update #36435 Change-Id: I5e92bd70ce557b78ff385577088a9775cc468ea9 Reviewed-on: https://go-review.googlesource.com/c/go/+/270378 Trust: Joel Sing <joel@sing.id.au> Run-TryBot: Joel Sing <joel@sing.id.au> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/os_openbsd.go8
-rw-r--r--src/runtime/os_openbsd_syscall1.go15
-rw-r--r--src/runtime/sys_openbsd1.go34
-rw-r--r--src/runtime/sys_openbsd_amd64.s40
4 files changed, 71 insertions, 26 deletions
diff --git a/src/runtime/os_openbsd.go b/src/runtime/os_openbsd.go
index 61be627c27..56b686a2fa 100644
--- a/src/runtime/os_openbsd.go
+++ b/src/runtime/os_openbsd.go
@@ -46,14 +46,6 @@ func raiseproc(sig uint32)
func getthrid() int32
func thrkill(tid int32, sig int)
-//go:noescape
-func thrsleep(ident uintptr, clock_id int32, tsp *timespec, lock uintptr, abort *uint32) int32
-
-//go:noescape
-func thrwakeup(ident uintptr, n int32) int32
-
-func osyield()
-
func kqueue() int32
//go:noescape
diff --git a/src/runtime/os_openbsd_syscall1.go b/src/runtime/os_openbsd_syscall1.go
new file mode 100644
index 0000000000..08928cfef4
--- /dev/null
+++ b/src/runtime/os_openbsd_syscall1.go
@@ -0,0 +1,15 @@
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build openbsd,!amd64
+
+package runtime
+
+//go:noescape
+func thrsleep(ident uintptr, clock_id int32, tsp *timespec, lock uintptr, abort *uint32) int32
+
+//go:noescape
+func thrwakeup(ident uintptr, n int32) int32
+
+func osyield()
diff --git a/src/runtime/sys_openbsd1.go b/src/runtime/sys_openbsd1.go
new file mode 100644
index 0000000000..a201a16c53
--- /dev/null
+++ b/src/runtime/sys_openbsd1.go
@@ -0,0 +1,34 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build openbsd,amd64
+
+package runtime
+
+import "unsafe"
+
+//go:nosplit
+//go:cgo_unsafe_args
+func thrsleep(ident uintptr, clock_id int32, tsp *timespec, lock uintptr, abort *uint32) int32 {
+ return libcCall(unsafe.Pointer(funcPC(thrsleep_trampoline)), unsafe.Pointer(&ident))
+}
+func thrsleep_trampoline()
+
+//go:nosplit
+//go:cgo_unsafe_args
+func thrwakeup(ident uintptr, n int32) int32 {
+ return libcCall(unsafe.Pointer(funcPC(thrwakeup_trampoline)), unsafe.Pointer(&ident))
+}
+func thrwakeup_trampoline()
+
+func osyield() {
+ libcCall(unsafe.Pointer(funcPC(sched_yield_trampoline)), unsafe.Pointer(nil))
+}
+func sched_yield_trampoline()
+
+//go:cgo_import_dynamic libc_thrsleep __thrsleep "libc.so"
+//go:cgo_import_dynamic libc_thrwakeup __thrwakeup "libc.so"
+//go:cgo_import_dynamic libc_sched_yield sched_yield "libc.so"
+
+//go:cgo_import_dynamic _ _ "libc.so"
diff --git a/src/runtime/sys_openbsd_amd64.s b/src/runtime/sys_openbsd_amd64.s
index 455234d7cd..ac0ae27e45 100644
--- a/src/runtime/sys_openbsd_amd64.s
+++ b/src/runtime/sys_openbsd_amd64.s
@@ -168,28 +168,32 @@ TEXT runtime·pthread_kill_trampoline(SB),NOSPLIT,$0
POPQ BP
RET
-TEXT runtime·osyield(SB),NOSPLIT,$0
- MOVL $298, AX // sys_sched_yield
- SYSCALL
+TEXT runtime·thrsleep_trampoline(SB),NOSPLIT,$0
+ PUSHQ BP
+ MOVQ SP, BP
+ MOVL 8(DI), SI // arg 2 - clock_id
+ MOVQ 16(DI), DX // arg 3 - abstime
+ MOVQ 24(DI), CX // arg 3 - lock
+ MOVQ 32(DI), R8 // arg 4 - abort
+ MOVQ 0(DI), DI // arg 1 - id
+ CALL libc_thrsleep(SB)
+ POPQ BP
RET
-TEXT runtime·thrsleep(SB),NOSPLIT,$0
- MOVQ ident+0(FP), DI // arg 1 - ident
- MOVL clock_id+8(FP), SI // arg 2 - clock_id
- MOVQ tsp+16(FP), DX // arg 3 - tp
- MOVQ lock+24(FP), R10 // arg 4 - lock
- MOVQ abort+32(FP), R8 // arg 5 - abort
- MOVL $94, AX // sys___thrsleep
- SYSCALL
- MOVL AX, ret+40(FP)
+TEXT runtime·thrwakeup_trampoline(SB),NOSPLIT,$0
+ PUSHQ BP
+ MOVQ SP, BP
+ MOVL 8(DI), SI // arg 2 - count
+ MOVQ 0(DI), DI // arg 1 - id
+ CALL libc_thrwakeup(SB)
+ POPQ BP
RET
-TEXT runtime·thrwakeup(SB),NOSPLIT,$0
- MOVQ ident+0(FP), DI // arg 1 - ident
- MOVL n+8(FP), SI // arg 2 - n
- MOVL $301, AX // sys___thrwakeup
- SYSCALL
- MOVL AX, ret+16(FP)
+TEXT runtime·sched_yield_trampoline(SB),NOSPLIT,$0
+ PUSHQ BP
+ MOVQ SP, BP
+ CALL libc_sched_yield(SB)
+ POPQ BP
RET
// Exit the entire program (like C exit)