github.com/cilium/ebpf@v0.10.0/examples/ringbuffer/bpf_bpfel.go (about) 1 // Code generated by bpf2go; DO NOT EDIT. 2 //go:build 386 || amd64 || amd64p32 || arm || arm64 || mips64le || mips64p32le || mipsle || ppc64le || riscv64 3 // +build 386 amd64 amd64p32 arm arm64 mips64le mips64p32le mipsle ppc64le riscv64 4 5 package main 6 7 import ( 8 "bytes" 9 _ "embed" 10 "fmt" 11 "io" 12 13 "github.com/cilium/ebpf" 14 ) 15 16 type bpfEvent struct { 17 Pid uint32 18 Comm [80]uint8 19 } 20 21 // loadBpf returns the embedded CollectionSpec for bpf. 22 func loadBpf() (*ebpf.CollectionSpec, error) { 23 reader := bytes.NewReader(_BpfBytes) 24 spec, err := ebpf.LoadCollectionSpecFromReader(reader) 25 if err != nil { 26 return nil, fmt.Errorf("can't load bpf: %w", err) 27 } 28 29 return spec, err 30 } 31 32 // loadBpfObjects loads bpf and converts it into a struct. 33 // 34 // The following types are suitable as obj argument: 35 // 36 // *bpfObjects 37 // *bpfPrograms 38 // *bpfMaps 39 // 40 // See ebpf.CollectionSpec.LoadAndAssign documentation for details. 41 func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error { 42 spec, err := loadBpf() 43 if err != nil { 44 return err 45 } 46 47 return spec.LoadAndAssign(obj, opts) 48 } 49 50 // bpfSpecs contains maps and programs before they are loaded into the kernel. 51 // 52 // It can be passed ebpf.CollectionSpec.Assign. 53 type bpfSpecs struct { 54 bpfProgramSpecs 55 bpfMapSpecs 56 } 57 58 // bpfSpecs contains programs before they are loaded into the kernel. 59 // 60 // It can be passed ebpf.CollectionSpec.Assign. 61 type bpfProgramSpecs struct { 62 KprobeExecve *ebpf.ProgramSpec `ebpf:"kprobe_execve"` 63 } 64 65 // bpfMapSpecs contains maps before they are loaded into the kernel. 66 // 67 // It can be passed ebpf.CollectionSpec.Assign. 68 type bpfMapSpecs struct { 69 Events *ebpf.MapSpec `ebpf:"events"` 70 } 71 72 // bpfObjects contains all objects after they have been loaded into the kernel. 73 // 74 // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. 75 type bpfObjects struct { 76 bpfPrograms 77 bpfMaps 78 } 79 80 func (o *bpfObjects) Close() error { 81 return _BpfClose( 82 &o.bpfPrograms, 83 &o.bpfMaps, 84 ) 85 } 86 87 // bpfMaps contains all maps after they have been loaded into the kernel. 88 // 89 // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. 90 type bpfMaps struct { 91 Events *ebpf.Map `ebpf:"events"` 92 } 93 94 func (m *bpfMaps) Close() error { 95 return _BpfClose( 96 m.Events, 97 ) 98 } 99 100 // bpfPrograms contains all programs after they have been loaded into the kernel. 101 // 102 // It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign. 103 type bpfPrograms struct { 104 KprobeExecve *ebpf.Program `ebpf:"kprobe_execve"` 105 } 106 107 func (p *bpfPrograms) Close() error { 108 return _BpfClose( 109 p.KprobeExecve, 110 ) 111 } 112 113 func _BpfClose(closers ...io.Closer) error { 114 for _, closer := range closers { 115 if err := closer.Close(); err != nil { 116 return err 117 } 118 } 119 return nil 120 } 121 122 // Do not access this directly. 123 // 124 //go:embed bpf_bpfel.o 125 var _BpfBytes []byte