]> Cypherpunks repositories - gostls13.git/commitdiff
internal/syscall/unix: use atomic.Bool for getrandomUnsupported
authorTobias Klauser <tklauser@distanz.ch>
Thu, 26 Jan 2023 12:44:30 +0000 (13:44 +0100)
committerTobias Klauser <tobias.klauser@gmail.com>
Thu, 26 Jan 2023 21:54:02 +0000 (21:54 +0000)
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>
src/internal/syscall/unix/getrandom.go
src/internal/syscall/unix/getrandom_netbsd.go
src/internal/syscall/unix/getrandom_solaris.go

index a6659331e46d87c022ac76b84c3d31761556c6a1..e83f0cd6f95733783e9a2e1fc79e278966311176 100644 (file)
@@ -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
        }
index 724228b380fa5d5afbc2e01be5a424f9d8259954..c83e3b21a5ee8524e30c1a652d790dedeb8da12d 100644 (file)
@@ -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
        }
index d86775cd98cdc7e42c99c34e52f7064a3f3bc1e7..cf4f35a4198d1f4931167d599e8ad1dea9ab8d76 100644 (file)
@@ -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
        }