Source file src/internal/syscall/unix/arc4random_darwin.go
1 // Copyright 2024 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 package unix 6 7 import ( 8 "internal/abi" 9 "unsafe" 10 ) 11 12 //go:cgo_import_dynamic libc_arc4random_buf arc4random_buf "/usr/lib/libSystem.B.dylib" 13 14 func libc_arc4random_buf_trampoline() 15 16 // ARC4Random calls the macOS arc4random_buf(3) function. 17 func ARC4Random(p []byte) { 18 // macOS 11 and 12 abort if length is 0. 19 if len(p) == 0 { 20 return 21 } 22 syscall_syscall(abi.FuncPCABI0(libc_arc4random_buf_trampoline), 23 uintptr(unsafe.Pointer(unsafe.SliceData(p))), uintptr(len(p)), 0) 24 } 25