Source file src/internal/syscall/unix/getentropy_darwin.go
1 // Copyright 2021 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 darwin && !ios 6 7 package unix 8 9 import ( 10 "internal/abi" 11 "syscall" 12 "unsafe" 13 ) 14 15 //go:cgo_import_dynamic libc_getentropy getentropy "/usr/lib/libSystem.B.dylib" 16 17 func libc_getentropy_trampoline() 18 19 // GetEntropy calls the macOS getentropy system call. 20 func GetEntropy(p []byte) error { 21 _, _, errno := syscall_syscall(abi.FuncPCABI0(libc_getentropy_trampoline), 22 uintptr(unsafe.Pointer(&p[0])), 23 uintptr(len(p)), 24 0) 25 if errno != 0 { 26 return errno 27 } 28 return nil 29 } 30 31 //go:linkname syscall_syscall syscall.syscall 32 func syscall_syscall(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) 33