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