github.com/dylandreimerink/gobpfld@v0.6.1-0.20220205171531-e79c330ad608/internal/syscall/bpf.go (about)

     1  package syscall
     2  
     3  import (
     4  	"unsafe"
     5  
     6  	"golang.org/x/sys/unix"
     7  )
     8  
     9  type BPFAttribute interface {
    10  	ToPtr() unsafe.Pointer
    11  	Size() uintptr
    12  }
    13  
    14  // Bpf is a wrapper around the BPF syscall, so a very low level function.
    15  func Bpf(cmd int, attr BPFAttribute, size int) (fd uintptr, err error) {
    16  	fd, _, errno := unix.Syscall(unix.SYS_BPF, uintptr(cmd), uintptr(attr.ToPtr()), uintptr(size))
    17  	if errno != 0 {
    18  		err = &Error{
    19  			Errno: errno,
    20  		}
    21  	}
    22  	return
    23  }