1
0
mirror of https://github.com/golang/go synced 2024-07-05 09:50:19 +00:00

internal/poll, internal/syscall/unix, net, runtime: convert openbsd (except mips64) to direct libc calls

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>
This commit is contained in:
Tobias Klauser 2022-08-26 12:09:34 +02:00 committed by Tobias Klauser
parent 59b15726d1
commit 0d6a7f9d2e
14 changed files with 60 additions and 26 deletions

View 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

View 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

View 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

View 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

View 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 (

View 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.
//go:build openbsd && !mips64
package unix
import (
"syscall"
"unsafe"
)
// 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

View File

@ -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
}

View 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

View 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

View 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

View 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

View File

@ -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
}

View 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

View 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