// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build dragonfly || freebsd || linux

package unix

import (
	
	
	
)

//go:linkname vgetrandom runtime.vgetrandom
//go:noescape
func vgetrandom( []byte,  uint32) ( int,  bool)

var getrandomUnsupported atomic.Bool

// GetRandomFlag is a flag supported by the getrandom system call.
type GetRandomFlag uintptr

// GetRandom calls the getrandom system call.
func ( []byte,  GetRandomFlag) ( int,  error) {
	,  := vgetrandom(, uint32())
	if  {
		if  < 0 {
			return 0, syscall.Errno(-)
		}
		return , nil
	}
	if getrandomUnsupported.Load() {
		return 0, syscall.ENOSYS
	}
	, ,  := syscall.Syscall(getrandomTrap,
		uintptr(unsafe.Pointer(unsafe.SliceData())),
		uintptr(len()),
		uintptr())
	if  != 0 {
		if  == syscall.ENOSYS {
			getrandomUnsupported.Store(true)
		}
		return 0, 
	}
	return int(), nil
}