gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/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  	"gitee.com/ks-custle/core-gm/internal/abi"
    12  	"syscall"
    13  	"unsafe"
    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)