| 80 | } |
| 81 | |
| 82 | struct rte_bpf * |
| 83 | rte_bpf_load(const struct rte_bpf_prm *prm) |
| 84 | { |
| 85 | struct rte_bpf *bpf; |
| 86 | int32_t rc; |
| 87 | uint32_t i; |
| 88 | |
| 89 | if (prm == NULL || prm->ins == NULL || |
| 90 | (prm->nb_xsym != 0 && prm->xsym == NULL)) { |
| 91 | rte_errno = EINVAL; |
| 92 | return NULL; |
| 93 | } |
| 94 | |
| 95 | rc = 0; |
| 96 | for (i = 0; i != prm->nb_xsym && rc == 0; i++) |
| 97 | rc = bpf_check_xsym(prm->xsym + i); |
| 98 | |
| 99 | if (rc != 0) { |
| 100 | rte_errno = -rc; |
| 101 | RTE_BPF_LOG(ERR, "%s: %d-th xsym is invalid\n", __func__, i); |
| 102 | return NULL; |
| 103 | } |
| 104 | |
| 105 | bpf = bpf_load(prm); |
| 106 | if (bpf == NULL) { |
| 107 | rte_errno = ENOMEM; |
| 108 | return NULL; |
| 109 | } |
| 110 | |
| 111 | rc = __rte_bpf_validate(bpf); |
| 112 | if (rc == 0) { |
| 113 | __rte_bpf_jit(bpf); |
| 114 | if (mprotect(bpf, bpf->sz, PROT_READ) != 0) |
| 115 | rc = -ENOMEM; |
| 116 | } |
| 117 | |
| 118 | if (rc != 0) { |
| 119 | rte_bpf_destroy(bpf); |
| 120 | rte_errno = -rc; |
| 121 | return NULL; |
| 122 | } |
| 123 | |
| 124 | return bpf; |
| 125 | } |