// Code generated by bpf2go; DO NOT EDIT.
//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mips64le || mips64p32le || mipsle || ppc64le || riscv64

package main

import (
	"bytes"
	_ "embed"
	"fmt"
	"io"

	"github.com/cilium/ebpf"
)

type vmBpfVmProg struct {
	Insns [4096]struct {
		Code uint8
		_    [1]byte /* unsupported bitfield */
		Off  int16
		Imm  int32
	}
	InsnsCnt   uint32
	StackDepth uint32
}

type vmBpfVmStack struct{ Stack [2097152]uint8 }

// loadVm returns the embedded CollectionSpec for vm.
func loadVm() (*ebpf.CollectionSpec, error) {
	reader := bytes.NewReader(_VmBytes)
	spec, err := ebpf.LoadCollectionSpecFromReader(reader)
	if err != nil {
		return nil, fmt.Errorf("can't load vm: %w", err)
	}

	return spec, err
}

// loadVmObjects loads vm and converts it into a struct.
//
// The following types are suitable as obj argument:
//
//	*vmObjects
//	*vmPrograms
//	*vmMaps
//
// See ebpf.CollectionSpec.LoadAndAssign documentation for details.
func loadVmObjects(obj interface{}, opts *ebpf.CollectionOptions) error {
	spec, err := loadVm()
	if err != nil {
		return err
	}

	return spec.LoadAndAssign(obj, opts)
}

// vmSpecs contains maps and programs before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type vmSpecs struct {
	vmProgramSpecs
	vmMapSpecs
}

// vmSpecs contains programs before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type vmProgramSpecs struct {
	BpfVmXdp *ebpf.ProgramSpec `ebpf:"bpf_vm_xdp"`
}

// vmMapSpecs contains maps before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type vmMapSpecs struct {
	BpfVmProgs  *ebpf.MapSpec `ebpf:"bpf_vm_progs"`
	BpfVmStacks *ebpf.MapSpec `ebpf:"bpf_vm_stacks"`
}

// vmObjects contains all objects after they have been loaded into the kernel.
//
// It can be passed to loadVmObjects or ebpf.CollectionSpec.LoadAndAssign.
type vmObjects struct {
	vmPrograms
	vmMaps
}

func (o *vmObjects) Close() error {
	return _VmClose(
		&o.vmPrograms,
		&o.vmMaps,
	)
}

// vmMaps contains all maps after they have been loaded into the kernel.
//
// It can be passed to loadVmObjects or ebpf.CollectionSpec.LoadAndAssign.
type vmMaps struct {
	BpfVmProgs  *ebpf.Map `ebpf:"bpf_vm_progs"`
	BpfVmStacks *ebpf.Map `ebpf:"bpf_vm_stacks"`
}

func (m *vmMaps) Close() error {
	return _VmClose(
		m.BpfVmProgs,
		m.BpfVmStacks,
	)
}

// vmPrograms contains all programs after they have been loaded into the kernel.
//
// It can be passed to loadVmObjects or ebpf.CollectionSpec.LoadAndAssign.
type vmPrograms struct {
	BpfVmXdp *ebpf.Program `ebpf:"bpf_vm_xdp"`
}

func (p *vmPrograms) Close() error {
	return _VmClose(
		p.BpfVmXdp,
	)
}

func _VmClose(closers ...io.Closer) error {
	for _, closer := range closers {
		if err := closer.Close(); err != nil {
			return err
		}
	}
	return nil
}

// Do not access this directly.
//
//go:embed vm_bpfel.o
var _VmBytes []byte
