Skip to content

Commit 928bda4

Browse files
committed
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 <[email protected]> Run-TryBot: Joel Sing <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 824f2d6 commit 928bda4

File tree

4 files changed

+71
-26
lines changed

4 files changed

+71
-26
lines changed

src/runtime/os_openbsd.go

-8
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ func raiseproc(sig uint32)
4646
func getthrid() int32
4747
func thrkill(tid int32, sig int)
4848

49-
//go:noescape
50-
func thrsleep(ident uintptr, clock_id int32, tsp *timespec, lock uintptr, abort *uint32) int32
51-
52-
//go:noescape
53-
func thrwakeup(ident uintptr, n int32) int32
54-
55-
func osyield()
56-
5749
func kqueue() int32
5850

5951
//go:noescape

src/runtime/os_openbsd_syscall1.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2011 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+
//go:noescape
10+
func thrsleep(ident uintptr, clock_id int32, tsp *timespec, lock uintptr, abort *uint32) int32
11+
12+
//go:noescape
13+
func thrwakeup(ident uintptr, n int32) int32
14+
15+
func osyield()

src/runtime/sys_openbsd1.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 "unsafe"
10+
11+
//go:nosplit
12+
//go:cgo_unsafe_args
13+
func thrsleep(ident uintptr, clock_id int32, tsp *timespec, lock uintptr, abort *uint32) int32 {
14+
return libcCall(unsafe.Pointer(funcPC(thrsleep_trampoline)), unsafe.Pointer(&ident))
15+
}
16+
func thrsleep_trampoline()
17+
18+
//go:nosplit
19+
//go:cgo_unsafe_args
20+
func thrwakeup(ident uintptr, n int32) int32 {
21+
return libcCall(unsafe.Pointer(funcPC(thrwakeup_trampoline)), unsafe.Pointer(&ident))
22+
}
23+
func thrwakeup_trampoline()
24+
25+
func osyield() {
26+
libcCall(unsafe.Pointer(funcPC(sched_yield_trampoline)), unsafe.Pointer(nil))
27+
}
28+
func sched_yield_trampoline()
29+
30+
//go:cgo_import_dynamic libc_thrsleep __thrsleep "libc.so"
31+
//go:cgo_import_dynamic libc_thrwakeup __thrwakeup "libc.so"
32+
//go:cgo_import_dynamic libc_sched_yield sched_yield "libc.so"
33+
34+
//go:cgo_import_dynamic _ _ "libc.so"

src/runtime/sys_openbsd_amd64.s

+22-18
Original file line numberDiff line numberDiff line change
@@ -168,28 +168,32 @@ TEXT runtime·pthread_kill_trampoline(SB),NOSPLIT,$0
168168
POPQ BP
169169
RET
170170

171-
TEXT runtime·osyield(SB),NOSPLIT,$0
172-
MOVL $298, AX // sys_sched_yield
173-
SYSCALL
171+
TEXT runtime·thrsleep_trampoline(SB),NOSPLIT,$0
172+
PUSHQ BP
173+
MOVQ SP, BP
174+
MOVL 8(DI), SI // arg 2 - clock_id
175+
MOVQ 16(DI), DX // arg 3 - abstime
176+
MOVQ 24(DI), CX // arg 3 - lock
177+
MOVQ 32(DI), R8 // arg 4 - abort
178+
MOVQ 0(DI), DI // arg 1 - id
179+
CALL libc_thrsleep(SB)
180+
POPQ BP
174181
RET
175182

176-
TEXT runtime·thrsleep(SB),NOSPLIT,$0
177-
MOVQ ident+0(FP), DI // arg 1 - ident
178-
MOVL clock_id+8(FP), SI // arg 2 - clock_id
179-
MOVQ tsp+16(FP), DX // arg 3 - tp
180-
MOVQ lock+24(FP), R10 // arg 4 - lock
181-
MOVQ abort+32(FP), R8 // arg 5 - abort
182-
MOVL $94, AX // sys___thrsleep
183-
SYSCALL
184-
MOVL AX, ret+40(FP)
183+
TEXT runtime·thrwakeup_trampoline(SB),NOSPLIT,$0
184+
PUSHQ BP
185+
MOVQ SP, BP
186+
MOVL 8(DI), SI // arg 2 - count
187+
MOVQ 0(DI), DI // arg 1 - id
188+
CALL libc_thrwakeup(SB)
189+
POPQ BP
185190
RET
186191

187-
TEXT runtime·thrwakeup(SB),NOSPLIT,$0
188-
MOVQ ident+0(FP), DI // arg 1 - ident
189-
MOVL n+8(FP), SI // arg 2 - n
190-
MOVL $301, AX // sys___thrwakeup
191-
SYSCALL
192-
MOVL AX, ret+16(FP)
192+
TEXT runtime·sched_yield_trampoline(SB),NOSPLIT,$0
193+
PUSHQ BP
194+
MOVQ SP, BP
195+
CALL libc_sched_yield(SB)
196+
POPQ BP
193197
RET
194198

195199
// Exit the entire program (like C exit)

0 commit comments

Comments
 (0)