1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
13 #include <rte_common.h>
15 #include <rte_debug.h>
16 #include <rte_memory.h>
18 #include <rte_byteorder.h>
19 #include <rte_errno.h>
23 static struct rte_bpf *
24 bpf_load(const struct rte_bpf_prm *prm)
28 size_t sz, bsz, insz, xsz;
30 xsz = prm->nb_xsym * sizeof(prm->xsym[0]);
31 insz = prm->nb_ins * sizeof(prm->ins[0]);
33 sz = insz + xsz + bsz;
35 buf = mmap(NULL, sz, PROT_READ | PROT_WRITE,
36 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
37 if (buf == MAP_FAILED)
43 memcpy(&bpf->prm, prm, sizeof(bpf->prm));
45 memcpy(buf + bsz, prm->xsym, xsz);
46 memcpy(buf + bsz + xsz, prm->ins, insz);
48 bpf->prm.xsym = (void *)(buf + bsz);
49 bpf->prm.ins = (void *)(buf + bsz + xsz);
54 __rte_experimental struct rte_bpf *
55 rte_bpf_load(const struct rte_bpf_prm *prm)
60 if (prm == NULL || prm->ins == NULL) {
71 rc = bpf_validate(bpf);
74 if (mprotect(bpf, bpf->sz, PROT_READ) != 0)
87 __rte_experimental __attribute__ ((weak)) struct rte_bpf *
88 rte_bpf_elf_load(const struct rte_bpf_prm *prm, const char *fname,
91 if (prm == NULL || fname == NULL || sname == NULL) {
96 RTE_BPF_LOG(ERR, "%s() is not supported with current config\n"
97 "rebuild with libelf installed\n",