github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/syscall/unix/getentropy_netbsd.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build netbsd 6 7 package unix 8 9 import ( 10 "syscall" 11 "unsafe" 12 ) 13 14 const ( 15 _CTL_KERN = 1 16 17 _KERN_ARND = 81 18 ) 19 20 func GetEntropy(p []byte) error { 21 mib := [2]uint32{_CTL_KERN, _KERN_ARND} 22 n := uintptr(len(p)) 23 _, _, errno := syscall.Syscall6( 24 syscall.SYS___SYSCTL, 25 uintptr(unsafe.Pointer(&mib[0])), 26 uintptr(len(mib)), 27 uintptr(unsafe.Pointer(&p[0])), // olddata 28 uintptr(unsafe.Pointer(&n)), // &oldlen 29 uintptr(unsafe.Pointer(nil)), // newdata 30 0) // newlen 31 if errno != 0 { 32 return syscall.Errno(errno) 33 } 34 if n != uintptr(len(p)) { 35 return syscall.EINVAL 36 } 37 return nil 38 }