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