forked from microsoft/retina
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update bpf related files from libbpf upstream (microsoft#674)
# Description As title. We are pulling header files from https://github.com/libbpf/libbpf for building and compiling our eBPF program. This will update the files in `_src` and adding new files to `_include`. ## Related Issue If this pull request is related to any issue, please mention it here. Additionally, make sure that the issue is assigned to you before submitting this pull request. ## Checklist - [ ] I have read the [contributing documentation](https://retina.sh/docs/contributing). - [ ] I signed and signed-off the commits (`git commit -S -s ...`). See [this documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification) on signing commits. - [ ] I have correctly attributed the author(s) of the code. - [ ] I have tested the changes locally. - [ ] I have followed the project's style guidelines. - [ ] I have updated the documentation, if necessary. - [ ] I have added tests, if applicable. ## Screenshots (if applicable) or Testing Completed Confirmed that all plugins successfully compiled and running normally ![image](https://github.com/user-attachments/assets/2de1d9a7-868b-4e7d-be0b-94f0aff7d098) ## Additional Notes Add any additional notes or context about the pull request here. --- Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more information on how to contribute to this project.
- Loading branch information
Showing
63 changed files
with
25,698 additions
and
5,341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ | ||
#ifndef __ASM_BARRIER_H | ||
#define __ASM_BARRIER_H | ||
|
||
#include <linux/compiler.h> | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package asm //nolint:all | ||
|
||
// This file is a placeholder to make Go include this directory when vendoring. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ | ||
|
||
#ifndef __LINUX_COMPILER_H | ||
#define __LINUX_COMPILER_H | ||
|
||
#define likely(x) __builtin_expect(!!(x), 1) | ||
#define unlikely(x) __builtin_expect(!!(x), 0) | ||
|
||
#define READ_ONCE(x) (*(volatile typeof(x) *)&x) | ||
#define WRITE_ONCE(x, v) (*(volatile typeof(x) *)&x) = (v) | ||
|
||
#define barrier() asm volatile("" ::: "memory") | ||
|
||
#if defined(__x86_64__) | ||
|
||
# define smp_rmb() barrier() | ||
# define smp_wmb() barrier() | ||
# define smp_mb() asm volatile("lock; addl $0,-132(%%rsp)" ::: "memory", "cc") | ||
|
||
# define smp_store_release(p, v) \ | ||
do { \ | ||
barrier(); \ | ||
WRITE_ONCE(*p, v); \ | ||
} while (0) | ||
|
||
# define smp_load_acquire(p) \ | ||
({ \ | ||
typeof(*p) ___p = READ_ONCE(*p); \ | ||
barrier(); \ | ||
___p; \ | ||
}) | ||
|
||
#elif defined(__aarch64__) | ||
|
||
# define smp_rmb() asm volatile("dmb ishld" ::: "memory") | ||
# define smp_wmb() asm volatile("dmb ishst" ::: "memory") | ||
# define smp_mb() asm volatile("dmb ish" ::: "memory") | ||
|
||
#endif | ||
|
||
#ifndef smp_mb | ||
# define smp_mb() __sync_synchronize() | ||
#endif | ||
|
||
#ifndef smp_rmb | ||
# define smp_rmb() smp_mb() | ||
#endif | ||
|
||
#ifndef smp_wmb | ||
# define smp_wmb() smp_mb() | ||
#endif | ||
|
||
#ifndef smp_store_release | ||
# define smp_store_release(p, v) \ | ||
do { \ | ||
smp_mb(); \ | ||
WRITE_ONCE(*p, v); \ | ||
} while (0) | ||
#endif | ||
|
||
#ifndef smp_load_acquire | ||
# define smp_load_acquire(p) \ | ||
({ \ | ||
typeof(*p) ___p = READ_ONCE(*p); \ | ||
smp_mb(); \ | ||
___p; \ | ||
}) | ||
#endif | ||
|
||
#endif /* __LINUX_COMPILER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ | ||
|
||
#ifndef __LINUX_ERR_H | ||
#define __LINUX_ERR_H | ||
|
||
#include <linux/types.h> | ||
#include <asm/errno.h> | ||
|
||
#define MAX_ERRNO 4095 | ||
|
||
#define IS_ERR_VALUE(x) ((x) >= (unsigned long)-MAX_ERRNO) | ||
|
||
static inline void * ERR_PTR(long error_) | ||
{ | ||
return (void *) error_; | ||
} | ||
|
||
static inline long PTR_ERR(const void *ptr) | ||
{ | ||
return (long) ptr; | ||
} | ||
|
||
static inline bool IS_ERR(const void *ptr) | ||
{ | ||
return IS_ERR_VALUE((unsigned long)ptr); | ||
} | ||
|
||
static inline bool IS_ERR_OR_NULL(const void *ptr) | ||
{ | ||
return (!ptr) || IS_ERR_VALUE((unsigned long)ptr); | ||
} | ||
|
||
static inline long PTR_ERR_OR_ZERO(const void *ptr) | ||
{ | ||
return IS_ERR(ptr) ? PTR_ERR(ptr) : 0; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ | ||
|
||
#ifndef __LINUX_FILTER_H | ||
#define __LINUX_FILTER_H | ||
|
||
#include <linux/bpf.h> | ||
|
||
#define BPF_RAW_INSN(CODE, DST, SRC, OFF, IMM) \ | ||
((struct bpf_insn) { \ | ||
.code = CODE, \ | ||
.dst_reg = DST, \ | ||
.src_reg = SRC, \ | ||
.off = OFF, \ | ||
.imm = IMM }) | ||
|
||
#define BPF_ALU32_IMM(OP, DST, IMM) \ | ||
((struct bpf_insn) { \ | ||
.code = BPF_ALU | BPF_OP(OP) | BPF_K, \ | ||
.dst_reg = DST, \ | ||
.src_reg = 0, \ | ||
.off = 0, \ | ||
.imm = IMM }) | ||
|
||
#define BPF_ALU64_IMM(OP, DST, IMM) \ | ||
((struct bpf_insn) { \ | ||
.code = BPF_ALU64 | BPF_OP(OP) | BPF_K, \ | ||
.dst_reg = DST, \ | ||
.src_reg = 0, \ | ||
.off = 0, \ | ||
.imm = IMM }) | ||
|
||
#define BPF_MOV64_IMM(DST, IMM) \ | ||
((struct bpf_insn) { \ | ||
.code = BPF_ALU64 | BPF_MOV | BPF_K, \ | ||
.dst_reg = DST, \ | ||
.src_reg = 0, \ | ||
.off = 0, \ | ||
.imm = IMM }) | ||
|
||
#define BPF_CALL_REL(DST) \ | ||
((struct bpf_insn) { \ | ||
.code = BPF_JMP | BPF_CALL, \ | ||
.dst_reg = 0, \ | ||
.src_reg = BPF_PSEUDO_CALL, \ | ||
.off = 0, \ | ||
.imm = DST }) | ||
|
||
#define BPF_EXIT_INSN() \ | ||
((struct bpf_insn) { \ | ||
.code = BPF_JMP | BPF_EXIT, \ | ||
.dst_reg = 0, \ | ||
.src_reg = 0, \ | ||
.off = 0, \ | ||
.imm = 0 }) | ||
|
||
#define BPF_EMIT_CALL(FUNC) \ | ||
((struct bpf_insn) { \ | ||
.code = BPF_JMP | BPF_CALL, \ | ||
.dst_reg = 0, \ | ||
.src_reg = 0, \ | ||
.off = 0, \ | ||
.imm = ((FUNC) - BPF_FUNC_unspec) }) | ||
|
||
#define BPF_LDX_MEM(SIZE, DST, SRC, OFF) \ | ||
((struct bpf_insn) { \ | ||
.code = BPF_LDX | BPF_SIZE(SIZE) | BPF_MEM, \ | ||
.dst_reg = DST, \ | ||
.src_reg = SRC, \ | ||
.off = OFF, \ | ||
.imm = 0 }) | ||
|
||
#define BPF_STX_MEM(SIZE, DST, SRC, OFF) \ | ||
((struct bpf_insn) { \ | ||
.code = BPF_STX | BPF_SIZE(SIZE) | BPF_MEM, \ | ||
.dst_reg = DST, \ | ||
.src_reg = SRC, \ | ||
.off = OFF, \ | ||
.imm = 0 }) | ||
|
||
#define BPF_ST_MEM(SIZE, DST, OFF, IMM) \ | ||
((struct bpf_insn) { \ | ||
.code = BPF_ST | BPF_SIZE(SIZE) | BPF_MEM, \ | ||
.dst_reg = DST, \ | ||
.src_reg = 0, \ | ||
.off = OFF, \ | ||
.imm = IMM }) | ||
|
||
#define BPF_MOV64_REG(DST, SRC) \ | ||
((struct bpf_insn) { \ | ||
.code = BPF_ALU64 | BPF_MOV | BPF_X, \ | ||
.dst_reg = DST, \ | ||
.src_reg = SRC, \ | ||
.off = 0, \ | ||
.imm = 0 }) | ||
|
||
#define BPF_MOV32_IMM(DST, IMM) \ | ||
((struct bpf_insn) { \ | ||
.code = BPF_ALU | BPF_MOV | BPF_K, \ | ||
.dst_reg = DST, \ | ||
.src_reg = 0, \ | ||
.off = 0, \ | ||
.imm = IMM }) | ||
|
||
#define BPF_LD_IMM64_RAW_FULL(DST, SRC, OFF1, OFF2, IMM1, IMM2) \ | ||
((struct bpf_insn) { \ | ||
.code = BPF_LD | BPF_DW | BPF_IMM, \ | ||
.dst_reg = DST, \ | ||
.src_reg = SRC, \ | ||
.off = OFF1, \ | ||
.imm = IMM1 }), \ | ||
((struct bpf_insn) { \ | ||
.code = 0, \ | ||
.dst_reg = 0, \ | ||
.src_reg = 0, \ | ||
.off = OFF2, \ | ||
.imm = IMM2 }) | ||
|
||
#define BPF_LD_MAP_FD(DST, MAP_FD) \ | ||
BPF_LD_IMM64_RAW_FULL(DST, BPF_PSEUDO_MAP_FD, 0, 0, \ | ||
MAP_FD, 0) | ||
|
||
#define BPF_LD_MAP_VALUE(DST, MAP_FD, VALUE_OFF) \ | ||
BPF_LD_IMM64_RAW_FULL(DST, BPF_PSEUDO_MAP_VALUE, 0, 0, \ | ||
MAP_FD, VALUE_OFF) | ||
|
||
#define BPF_JMP_IMM(OP, DST, IMM, OFF) \ | ||
((struct bpf_insn) { \ | ||
.code = BPF_JMP | BPF_OP(OP) | BPF_K, \ | ||
.dst_reg = DST, \ | ||
.src_reg = 0, \ | ||
.off = OFF, \ | ||
.imm = IMM }) | ||
|
||
#define BPF_JMP32_IMM(OP, DST, IMM, OFF) \ | ||
((struct bpf_insn) { \ | ||
.code = BPF_JMP32 | BPF_OP(OP) | BPF_K, \ | ||
.dst_reg = DST, \ | ||
.src_reg = 0, \ | ||
.off = OFF, \ | ||
.imm = IMM }) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ | ||
|
||
#ifndef __LINUX_KERNEL_H | ||
#define __LINUX_KERNEL_H | ||
|
||
#include <linux/compiler.h> | ||
|
||
#ifndef offsetof | ||
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) | ||
#endif | ||
|
||
#ifndef container_of | ||
#define container_of(ptr, type, member) ({ \ | ||
const typeof(((type *)0)->member) * __mptr = (ptr); \ | ||
(type *)((char *)__mptr - offsetof(type, member)); }) | ||
#endif | ||
|
||
#ifndef max | ||
#define max(x, y) ({ \ | ||
typeof(x) _max1 = (x); \ | ||
typeof(y) _max2 = (y); \ | ||
(void) (&_max1 == &_max2); \ | ||
_max1 > _max2 ? _max1 : _max2; }) | ||
#endif | ||
|
||
#ifndef min | ||
#define min(x, y) ({ \ | ||
typeof(x) _min1 = (x); \ | ||
typeof(y) _min2 = (y); \ | ||
(void) (&_min1 == &_min2); \ | ||
_min1 < _min2 ? _min1 : _min2; }) | ||
#endif | ||
|
||
#ifndef roundup | ||
#define roundup(x, y) ( \ | ||
{ \ | ||
const typeof(y) __y = y; \ | ||
(((x) + (__y - 1)) / __y) * __y; \ | ||
} \ | ||
) | ||
#endif | ||
|
||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) | ||
#define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) | ||
|
||
#endif |
Oops, something went wrong.