]> Cypherpunks repositories - gostls13.git/commitdiff
internal/poll, internal/syscall/unix, net, runtime: convert openbsd (except mips64...
authorTobias Klauser <tklauser@distanz.ch>
Fri, 26 Aug 2022 10:09:34 +0000 (12:09 +0200)
committerTobias Klauser <tobias.klauser@gmail.com>
Wed, 31 Aug 2022 16:59:38 +0000 (16:59 +0000)
Call libc wrappers directly rather than calling using syscall(2).

Updates golang/go#36435

Change-Id: I40be410c7472f7d89cbec2ebdc7c841c7726ca4a
Reviewed-on: https://go-review.googlesource.com/c/go/+/425637
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Joel Sing <joel@sing.id.au>
14 files changed:
src/internal/poll/fcntl_libc.go
src/internal/poll/fcntl_syscall.go
src/internal/syscall/unix/at.go
src/internal/syscall/unix/at_fstatat.go
src/internal/syscall/unix/at_libc2.go [moved from src/internal/syscall/unix/at_darwin.go with 95% similarity]
src/internal/syscall/unix/getentropy_openbsd.go
src/internal/syscall/unix/getentropy_openbsd_mips64.go [new file with mode: 0644]
src/internal/syscall/unix/nonblocking.go
src/internal/syscall/unix/nonblocking_libc.go
src/net/fcntl_libc_test.go
src/net/fcntl_syscall_test.go
src/runtime/export_openbsd_test.go [new file with mode: 0644]
src/runtime/nbpipe_fcntl_libc_test.go
src/runtime/nbpipe_fcntl_unix_test.go

index 13614dc3e8d5f3c6dc715ed3e78275c8cb9e19d9..529b8e123a8a74a23ad09acd11663322ed6fb0fb 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build aix || darwin || solaris
+//go:build aix || darwin || (openbsd && !mips64) || solaris
 
 package poll
 
index accff5e0438955757eb0ba6a94651123fdfadda0..bbfc8a8be50bc783649c3a4203fa0fe44e907bda 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build dragonfly || freebsd || linux || netbsd || openbsd
+//go:build dragonfly || freebsd || linux || netbsd || (openbsd && mips64)
 
 package poll
 
index 965162e3d2f0fefef0e50c55d3586ed8b191797c..876ca9ff578b94ee640400fa033b9816ad88aa3c 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build linux || openbsd || netbsd || dragonfly
+//go:build dragonfly || linux || netbsd || (openbsd && mips64)
 
 package unix
 
index 25318d2014942705b85597fd50075a41fdc74a03..8f25fe9f64edb0a3f834be47e74e7790b407aca6 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build (linux && !loong64) || openbsd || netbsd || dragonfly
+//go:build dragonfly || (linux && !loong64) || netbsd || (openbsd && mips64)
 
 package unix
 
similarity index 95%
rename from src/internal/syscall/unix/at_darwin.go
rename to src/internal/syscall/unix/at_libc2.go
index a88a27e0c6c527813dd5b61e7fffb0e9326f0b59..93d0cf4443f1f366c0883a99ade6b01f032e11f4 100644 (file)
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+//go:build darwin || (openbsd && !mips64)
+
 package unix
 
 import (
index d5caa8095a68bf3091e65967c20bb3c8a46ccb4e..ad0914da903b98efca1abc7ccfbdef69be39e34c 100644 (file)
@@ -1,25 +1,17 @@
-// Copyright 2016 The Go Authors. All rights reserved.
+// Copyright 2022 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.
 
-package unix
+//go:build openbsd && !mips64
 
-import (
-       "syscall"
-       "unsafe"
-)
+package unix
 
-// getentropy(2)'s syscall number, from /usr/src/sys/kern/syscalls.master
-const entropyTrap uintptr = 7
+import _ "unsafe" // for linkname
 
 // GetEntropy calls the OpenBSD getentropy system call.
 func GetEntropy(p []byte) error {
-       _, _, errno := syscall.Syscall(entropyTrap,
-               uintptr(unsafe.Pointer(&p[0])),
-               uintptr(len(p)),
-               0)
-       if errno != 0 {
-               return errno
-       }
-       return nil
+       return getentropy(p)
 }
+
+//go:linkname getentropy syscall.getentropy
+func getentropy(p []byte) error
diff --git a/src/internal/syscall/unix/getentropy_openbsd_mips64.go b/src/internal/syscall/unix/getentropy_openbsd_mips64.go
new file mode 100644 (file)
index 0000000..d5caa80
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2016 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.
+
+package unix
+
+import (
+       "syscall"
+       "unsafe"
+)
+
+// getentropy(2)'s syscall number, from /usr/src/sys/kern/syscalls.master
+const entropyTrap uintptr = 7
+
+// GetEntropy calls the OpenBSD getentropy system call.
+func GetEntropy(p []byte) error {
+       _, _, errno := syscall.Syscall(entropyTrap,
+               uintptr(unsafe.Pointer(&p[0])),
+               uintptr(len(p)),
+               0)
+       if errno != 0 {
+               return errno
+       }
+       return nil
+}
index 9e5f0fb4a2d57a7e2c9d78943fd604050726fd39..a0becd1e01e04d3db393f8562f5e17114c684d06 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build dragonfly || freebsd || linux || netbsd || openbsd
+//go:build dragonfly || freebsd || linux || netbsd || (openbsd && mips64)
 
 package unix
 
index 84940714c3cc57d32db65d95745bbb9c857e89d9..bff668496236e680aa21772299db9369abc402a5 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build aix || darwin || solaris
+//go:build aix || darwin || (openbsd && !mips64) || solaris
 
 package unix
 
index 78892e3a9fac168123f1acb4eaca97a4cf099c44..5858865cf0a366722c6a427fef7075438cf6687b 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build aix || darwin || solaris
+//go:build aix || darwin || (openbsd && !mips64) || solaris
 
 package net
 
index 2d1f7e22a459fcdb2dcbdb52265ed3eb49d65be9..b9ac1d3effd664797076ee30ddfd5cc084b5639d 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build dragonfly || freebsd || linux || netbsd || openbsd
+//go:build dragonfly || freebsd || linux || netbsd || (openbsd && mips64)
 
 package net
 
diff --git a/src/runtime/export_openbsd_test.go b/src/runtime/export_openbsd_test.go
new file mode 100644 (file)
index 0000000..ef680dc
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2022 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.
+
+//go:build openbsd && !mips64
+
+package runtime
+
+func Fcntl(fd, cmd, arg uintptr) (uintptr, uintptr) {
+       r := fcntl(int32(fd), int32(cmd), int32(arg))
+       if r < 0 {
+               return ^uintptr(0), uintptr(-r)
+       }
+       return uintptr(r), 0
+}
index a9c8987438defec3b430b7657db746d16dbf3de9..170245defec8f6a108ca343197e44b88d3546f72 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build aix || darwin || solaris
+//go:build aix || darwin || (openbsd && !mips64) || solaris
 
 package runtime_test
 
index 97607fa2cf7a1bca191c01b10bc2072a73ff2f6c..b7252ea9fafec3aa6721c54d269c25601191e802 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build dragonfly || freebsd || linux || netbsd || openbsd
+//go:build dragonfly || freebsd || linux || netbsd || (openbsd && mips64)
 
 package runtime_test