mirror of
https://github.com/golang/go
synced 2024-11-23 14:50:07 -07:00
internal/syscall/unix: use atomic.Bool for getrandomUnsupported
Change-Id: I50522ed782dd963f445419fc45495f6608909c47 Reviewed-on: https://go-review.googlesource.com/c/go/+/463124 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
da9761303c
commit
ea6d4b0eaf
@ -12,7 +12,7 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var getrandomUnsupported int32 // atomic
|
||||
var getrandomUnsupported atomic.Bool
|
||||
|
||||
// GetRandomFlag is a flag supported by the getrandom system call.
|
||||
type GetRandomFlag uintptr
|
||||
@ -22,7 +22,7 @@ func GetRandom(p []byte, flags GetRandomFlag) (n int, err error) {
|
||||
if len(p) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
if atomic.LoadInt32(&getrandomUnsupported) != 0 {
|
||||
if getrandomUnsupported.Load() {
|
||||
return 0, syscall.ENOSYS
|
||||
}
|
||||
r1, _, errno := syscall.Syscall(getrandomTrap,
|
||||
@ -31,7 +31,7 @@ func GetRandom(p []byte, flags GetRandomFlag) (n int, err error) {
|
||||
uintptr(flags))
|
||||
if errno != 0 {
|
||||
if errno == syscall.ENOSYS {
|
||||
atomic.StoreInt32(&getrandomUnsupported, 1)
|
||||
getrandomUnsupported.Store(true)
|
||||
}
|
||||
return 0, errno
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
// NetBSD getrandom system call number.
|
||||
const getrandomTrap uintptr = 91
|
||||
|
||||
var getrandomUnsupported int32 // atomic
|
||||
var getrandomUnsupported atomic.Bool
|
||||
|
||||
// GetRandomFlag is a flag supported by the getrandom system call.
|
||||
type GetRandomFlag uintptr
|
||||
@ -24,12 +24,12 @@ func GetRandom(p []byte, flags GetRandomFlag) (n int, err error) {
|
||||
if len(p) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
if atomic.LoadInt32(&getrandomUnsupported) != 0 {
|
||||
if getrandomUnsupported.Load() {
|
||||
return 0, syscall.ENOSYS
|
||||
}
|
||||
// getrandom(2) was added in NetBSD 10.0
|
||||
if getOSRevision() < 1000000000 {
|
||||
atomic.StoreInt32(&getrandomUnsupported, 1)
|
||||
getrandomUnsupported.Store(true)
|
||||
return 0, syscall.ENOSYS
|
||||
}
|
||||
r1, _, errno := syscall.Syscall(getrandomTrap,
|
||||
@ -38,7 +38,7 @@ func GetRandom(p []byte, flags GetRandomFlag) (n int, err error) {
|
||||
uintptr(flags))
|
||||
if errno != 0 {
|
||||
if errno == syscall.ENOSYS {
|
||||
atomic.StoreInt32(&getrandomUnsupported, 1)
|
||||
getrandomUnsupported.Store(true)
|
||||
}
|
||||
return 0, errno
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
|
||||
var procGetrandom uintptr
|
||||
|
||||
var getrandomUnsupported int32 // atomic
|
||||
var getrandomUnsupported atomic.Bool
|
||||
|
||||
// GetRandomFlag is a flag supported by the getrandom system call.
|
||||
type GetRandomFlag uintptr
|
||||
@ -34,7 +34,7 @@ func GetRandom(p []byte, flags GetRandomFlag) (n int, err error) {
|
||||
if len(p) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
if atomic.LoadInt32(&getrandomUnsupported) != 0 {
|
||||
if getrandomUnsupported.Load() {
|
||||
return 0, syscall.ENOSYS
|
||||
}
|
||||
r1, _, errno := syscall6(uintptr(unsafe.Pointer(&procGetrandom)),
|
||||
@ -45,7 +45,7 @@ func GetRandom(p []byte, flags GetRandomFlag) (n int, err error) {
|
||||
0, 0, 0)
|
||||
if errno != 0 {
|
||||
if errno == syscall.ENOSYS {
|
||||
atomic.StoreInt32(&getrandomUnsupported, 1)
|
||||
getrandomUnsupported.Store(true)
|
||||
}
|
||||
return 0, errno
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user