doc: add Meson coding style to contributors guide
[dpdk.git] / lib / librte_bpf / bpf.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #include <stdarg.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <errno.h>
9 #include <stdint.h>
10 #include <inttypes.h>
11
12 #include <rte_common.h>
13 #include <rte_eal.h>
14
15 #include "bpf_impl.h"
16
17 void
18 rte_bpf_destroy(struct rte_bpf *bpf)
19 {
20         if (bpf != NULL) {
21                 if (bpf->jit.func != NULL)
22                         munmap(bpf->jit.func, bpf->jit.sz);
23                 munmap(bpf, bpf->sz);
24         }
25 }
26
27 int
28 rte_bpf_get_jit(const struct rte_bpf *bpf, struct rte_bpf_jit *jit)
29 {
30         if (bpf == NULL || jit == NULL)
31                 return -EINVAL;
32
33         jit[0] = bpf->jit;
34         return 0;
35 }
36
37 int
38 bpf_jit(struct rte_bpf *bpf)
39 {
40         int32_t rc;
41
42 #if defined(RTE_ARCH_X86_64)
43         rc = bpf_jit_x86(bpf);
44 #elif defined(RTE_ARCH_ARM64)
45         rc = bpf_jit_arm64(bpf);
46 #else
47         rc = -ENOTSUP;
48 #endif
49
50         if (rc != 0)
51                 RTE_BPF_LOG(WARNING, "%s(%p) failed, error code: %d;\n",
52                         __func__, bpf, rc);
53         return rc;
54 }
55
56 RTE_LOG_REGISTER(rte_bpf_logtype, lib.bpf, INFO);