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