mirror of https://github.com/golang/go.git
syscall: remove RtlGenRandom and move it into internal/syscall
There's on need to expose this to the frozen syscall package, and it also doesn't need to be unsafe. So we move it into internal/syscall and have the generator make a safer function signature. Fixes #43704. Change-Id: Iccae69dc273a0aa97ee6846eb537f1dc1412f2de Reviewed-on: https://go-review.googlesource.com/c/go/+/283992 Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Trust: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
1deae0b597
commit
bb5075a525
|
|
@ -430,10 +430,8 @@ pkg syscall (linux-arm-cgo), func AllThreadsSyscall(uintptr, uintptr, uintptr, u
|
||||||
pkg syscall (linux-arm-cgo), func AllThreadsSyscall6(uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr) (uintptr, uintptr, Errno)
|
pkg syscall (linux-arm-cgo), func AllThreadsSyscall6(uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr) (uintptr, uintptr, Errno)
|
||||||
pkg syscall (linux-arm-cgo), func Setegid(int) error
|
pkg syscall (linux-arm-cgo), func Setegid(int) error
|
||||||
pkg syscall (linux-arm-cgo), func Seteuid(int) error
|
pkg syscall (linux-arm-cgo), func Seteuid(int) error
|
||||||
pkg syscall (windows-386), func RtlGenRandom(*uint8, uint32) error
|
|
||||||
pkg syscall (windows-386), method (*DLLError) Unwrap() error
|
pkg syscall (windows-386), method (*DLLError) Unwrap() error
|
||||||
pkg syscall (windows-386), type SysProcAttr struct, NoInheritHandles bool
|
pkg syscall (windows-386), type SysProcAttr struct, NoInheritHandles bool
|
||||||
pkg syscall (windows-amd64), func RtlGenRandom(*uint8, uint32) error
|
|
||||||
pkg syscall (windows-amd64), method (*DLLError) Unwrap() error
|
pkg syscall (windows-amd64), method (*DLLError) Unwrap() error
|
||||||
pkg syscall (windows-amd64), type SysProcAttr struct, NoInheritHandles bool
|
pkg syscall (windows-amd64), type SysProcAttr struct, NoInheritHandles bool
|
||||||
pkg testing/fstest, func TestFS(fs.FS, ...string) error
|
pkg testing/fstest, func TestFS(fs.FS, ...string) error
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@
|
||||||
package rand
|
package rand
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"internal/syscall/windows"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { Reader = &rngReader{} }
|
func init() { Reader = &rngReader{} }
|
||||||
|
|
@ -24,7 +24,7 @@ func (r *rngReader) Read(b []byte) (n int, err error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = syscall.RtlGenRandom(&b[0], inputLen)
|
err = windows.RtlGenRandom(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, os.NewSyscallError("RtlGenRandom", err)
|
return 0, os.NewSyscallError("RtlGenRandom", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -342,3 +342,5 @@ func LoadGetFinalPathNameByHandle() error {
|
||||||
|
|
||||||
//sys CreateEnvironmentBlock(block **uint16, token syscall.Token, inheritExisting bool) (err error) = userenv.CreateEnvironmentBlock
|
//sys CreateEnvironmentBlock(block **uint16, token syscall.Token, inheritExisting bool) (err error) = userenv.CreateEnvironmentBlock
|
||||||
//sys DestroyEnvironmentBlock(block *uint16) (err error) = userenv.DestroyEnvironmentBlock
|
//sys DestroyEnvironmentBlock(block *uint16) (err error) = userenv.DestroyEnvironmentBlock
|
||||||
|
|
||||||
|
//sys RtlGenRandom(buf []byte) (err error) = advapi32.SystemFunction036
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ var (
|
||||||
procOpenThreadToken = modadvapi32.NewProc("OpenThreadToken")
|
procOpenThreadToken = modadvapi32.NewProc("OpenThreadToken")
|
||||||
procRevertToSelf = modadvapi32.NewProc("RevertToSelf")
|
procRevertToSelf = modadvapi32.NewProc("RevertToSelf")
|
||||||
procSetTokenInformation = modadvapi32.NewProc("SetTokenInformation")
|
procSetTokenInformation = modadvapi32.NewProc("SetTokenInformation")
|
||||||
|
procSystemFunction036 = modadvapi32.NewProc("SystemFunction036")
|
||||||
procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses")
|
procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses")
|
||||||
procGetACP = modkernel32.NewProc("GetACP")
|
procGetACP = modkernel32.NewProc("GetACP")
|
||||||
procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
|
procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
|
||||||
|
|
@ -140,6 +141,18 @@ func SetTokenInformation(tokenHandle syscall.Token, tokenInformationClass uint32
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RtlGenRandom(buf []byte) (err error) {
|
||||||
|
var _p0 *byte
|
||||||
|
if len(buf) > 0 {
|
||||||
|
_p0 = &buf[0]
|
||||||
|
}
|
||||||
|
r1, _, e1 := syscall.Syscall(procSystemFunction036.Addr(), 2, uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), 0)
|
||||||
|
if r1 == 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) {
|
func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) {
|
||||||
r0, _, _ := syscall.Syscall6(procGetAdaptersAddresses.Addr(), 5, uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer)), 0)
|
r0, _, _ := syscall.Syscall6(procGetAdaptersAddresses.Addr(), 5, uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer)), 0)
|
||||||
if r0 != 0 {
|
if r0 != 0 {
|
||||||
|
|
|
||||||
|
|
@ -234,7 +234,6 @@ func NewCallbackCDecl(fn interface{}) uintptr {
|
||||||
//sys CryptAcquireContext(provhandle *Handle, container *uint16, provider *uint16, provtype uint32, flags uint32) (err error) = advapi32.CryptAcquireContextW
|
//sys CryptAcquireContext(provhandle *Handle, container *uint16, provider *uint16, provtype uint32, flags uint32) (err error) = advapi32.CryptAcquireContextW
|
||||||
//sys CryptReleaseContext(provhandle Handle, flags uint32) (err error) = advapi32.CryptReleaseContext
|
//sys CryptReleaseContext(provhandle Handle, flags uint32) (err error) = advapi32.CryptReleaseContext
|
||||||
//sys CryptGenRandom(provhandle Handle, buflen uint32, buf *byte) (err error) = advapi32.CryptGenRandom
|
//sys CryptGenRandom(provhandle Handle, buflen uint32, buf *byte) (err error) = advapi32.CryptGenRandom
|
||||||
//sys RtlGenRandom(buf *uint8, bytes uint32) (err error) = advapi32.SystemFunction036
|
|
||||||
//sys GetEnvironmentStrings() (envs *uint16, err error) [failretval==nil] = kernel32.GetEnvironmentStringsW
|
//sys GetEnvironmentStrings() (envs *uint16, err error) [failretval==nil] = kernel32.GetEnvironmentStringsW
|
||||||
//sys FreeEnvironmentStrings(envs *uint16) (err error) = kernel32.FreeEnvironmentStringsW
|
//sys FreeEnvironmentStrings(envs *uint16) (err error) = kernel32.FreeEnvironmentStringsW
|
||||||
//sys GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32, err error) = kernel32.GetEnvironmentVariableW
|
//sys GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32, err error) = kernel32.GetEnvironmentVariableW
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,6 @@ var (
|
||||||
procRegOpenKeyExW = modadvapi32.NewProc("RegOpenKeyExW")
|
procRegOpenKeyExW = modadvapi32.NewProc("RegOpenKeyExW")
|
||||||
procRegQueryInfoKeyW = modadvapi32.NewProc("RegQueryInfoKeyW")
|
procRegQueryInfoKeyW = modadvapi32.NewProc("RegQueryInfoKeyW")
|
||||||
procRegQueryValueExW = modadvapi32.NewProc("RegQueryValueExW")
|
procRegQueryValueExW = modadvapi32.NewProc("RegQueryValueExW")
|
||||||
procSystemFunction036 = modadvapi32.NewProc("SystemFunction036")
|
|
||||||
procCertAddCertificateContextToStore = modcrypt32.NewProc("CertAddCertificateContextToStore")
|
procCertAddCertificateContextToStore = modcrypt32.NewProc("CertAddCertificateContextToStore")
|
||||||
procCertCloseStore = modcrypt32.NewProc("CertCloseStore")
|
procCertCloseStore = modcrypt32.NewProc("CertCloseStore")
|
||||||
procCertCreateCertificateContext = modcrypt32.NewProc("CertCreateCertificateContext")
|
procCertCreateCertificateContext = modcrypt32.NewProc("CertCreateCertificateContext")
|
||||||
|
|
@ -333,14 +332,6 @@ func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func RtlGenRandom(buf *uint8, bytes uint32) (err error) {
|
|
||||||
r1, _, e1 := Syscall(procSystemFunction036.Addr(), 2, uintptr(unsafe.Pointer(buf)), uintptr(bytes), 0)
|
|
||||||
if r1 == 0 {
|
|
||||||
err = errnoErr(e1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func CertAddCertificateContextToStore(store Handle, certContext *CertContext, addDisposition uint32, storeContext **CertContext) (err error) {
|
func CertAddCertificateContextToStore(store Handle, certContext *CertContext, addDisposition uint32, storeContext **CertContext) (err error) {
|
||||||
r1, _, e1 := Syscall6(procCertAddCertificateContextToStore.Addr(), 4, uintptr(store), uintptr(unsafe.Pointer(certContext)), uintptr(addDisposition), uintptr(unsafe.Pointer(storeContext)), 0, 0)
|
r1, _, e1 := Syscall6(procCertAddCertificateContextToStore.Addr(), 4, uintptr(store), uintptr(unsafe.Pointer(certContext)), uintptr(addDisposition), uintptr(unsafe.Pointer(storeContext)), 0, 0)
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue