]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert openbsd/amd64 locking to libc
authorJoel Sing <joel@sing.id.au>
Fri, 15 Jan 2021 17:38:50 +0000 (04:38 +1100)
committerJoel Sing <joel@sing.id.au>
Wed, 20 Jan 2021 09:06:08 +0000 (09:06 +0000)
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>
src/runtime/os_openbsd.go
src/runtime/os_openbsd_syscall1.go [new file with mode: 0644]
src/runtime/sys_openbsd1.go [new file with mode: 0644]
src/runtime/sys_openbsd_amd64.s

index 61be627c270edd0edf3bb82699cf460f50ad5519..56b686a2fa668f695adb1be34112acc5b9d4d037 100644 (file)
@@ -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 (file)
index 0000000..08928cf
--- /dev/null
@@ -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 (file)
index 0000000..a201a16
--- /dev/null
@@ -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"
index 455234d7cdffa85a22d2eb248f8a15c139bac3c0..ac0ae27e45d38d6cb4d8d71988ea1106eb6a303a 100644 (file)
@@ -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)