Skip to content

Commit

Permalink
internal/poll, internal/syscall/unix, net, runtime: convert openbsd (…
Browse files Browse the repository at this point in the history
…except mips64) to direct libc calls

Call libc wrappers directly rather than calling using syscall(2).

Updates #36435

Change-Id: I40be410c7472f7d89cbec2ebdc7c841c7726ca4a
Reviewed-on: https://go-review.googlesource.com/c/go/+/425637
Reviewed-by: David Chase <[email protected]>
Reviewed-by: Heschi Kreinick <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Run-TryBot: Tobias Klauser <[email protected]>
Reviewed-by: Joel Sing <[email protected]>
  • Loading branch information
tklauser committed Aug 31, 2022
1 parent 59b1572 commit 0d6a7f9
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/internal/poll/fcntl_libc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/internal/poll/fcntl_syscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/internal/syscall/unix/at.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/internal/syscall/unix/at_fstatat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
24 changes: 8 additions & 16 deletions src/internal/syscall/unix/getentropy_openbsd.go
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions src/internal/syscall/unix/getentropy_openbsd_mips64.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion src/internal/syscall/unix/nonblocking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/internal/syscall/unix/nonblocking_libc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/net/fcntl_libc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/net/fcntl_syscall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions src/runtime/export_openbsd_test.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion src/runtime/nbpipe_fcntl_libc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/nbpipe_fcntl_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0d6a7f9

Please sign in to comment.