Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
2ee89fb
Documentation
arch
block
certs
crypto
drivers
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
accounting
arch
build
cgroup
firewire
gpio
hv
iio
include
kvm
laptop
leds
lguest
lib
net
nfsd
objtool
pcmcia
perf
power
scripts
spi
testing
fault-injection
ktest
nvdimm
radix-tree
selftests
bpf
.gitignore
Makefile
bpf_sys.h
bpf_util.h
config
test_kmod.sh
test_lpm_map.c
test_lru_map.c
test_maps.c
test_tag.c
test_verifier.c
breakpoints
capabilities
cpu-hotplug
drivers
efivarfs
exec
filesystems
firmware
ftrace
futex
gpio
ia64
intel_pstate
ipc
kcmp
lib
media_tests
membarrier
memfd
memory-hotplug
mount
mqueue
net
networking
nsfs
ntb
powerpc
prctl
pstore
ptp
ptrace
rcutorture
seccomp
sigaltstack
size
static_keys
sync
sysctl
timers
user
vDSO
vm
watchdog
x86
zram
.gitignore
Makefile
gen_kselftest_tar.sh
kselftest.h
kselftest_install.sh
lib.mk
thermal
time
usb
virtio
vm
Makefile
usr
virt
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
tools
/
testing
/
selftests
/
bpf
/
bpf_sys.h
Blame
Blame
Latest commit
History
History
87 lines (66 loc) · 1.82 KB
Breadcrumbs
linux
/
tools
/
testing
/
selftests
/
bpf
/
bpf_sys.h
Top
File metadata and controls
Code
Blame
87 lines (66 loc) · 1.82 KB
Raw
#ifndef __BPF_SYS__ #define __BPF_SYS__ #include <stdint.h> #include <stdlib.h> #include <sys/syscall.h> #include <linux/bpf.h> static inline __u64 bpf_ptr_to_u64(const void *ptr) { return (__u64)(unsigned long) ptr; } static inline int bpf(int cmd, union bpf_attr *attr, unsigned int size) { #ifdef __NR_bpf return syscall(__NR_bpf, cmd, attr, size); #else fprintf(stderr, "No bpf syscall, kernel headers too old?\n"); errno = ENOSYS; return -1; #endif } static inline int bpf_map_lookup(int fd, const void *key, void *value) { union bpf_attr attr = {}; attr.map_fd = fd; attr.key = bpf_ptr_to_u64(key); attr.value = bpf_ptr_to_u64(value); return bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr)); } static inline int bpf_map_update(int fd, const void *key, const void *value, uint64_t flags) { union bpf_attr attr = {}; attr.map_fd = fd; attr.key = bpf_ptr_to_u64(key); attr.value = bpf_ptr_to_u64(value); attr.flags = flags; return bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)); } static inline int bpf_map_delete(int fd, const void *key) { union bpf_attr attr = {}; attr.map_fd = fd; attr.key = bpf_ptr_to_u64(key); return bpf(BPF_MAP_DELETE_ELEM, &attr, sizeof(attr)); } static inline int bpf_map_next_key(int fd, const void *key, void *next_key) { union bpf_attr attr = {}; attr.map_fd = fd; attr.key = bpf_ptr_to_u64(key); attr.next_key = bpf_ptr_to_u64(next_key); return bpf(BPF_MAP_GET_NEXT_KEY, &attr, sizeof(attr)); } static inline int bpf_map_create(enum bpf_map_type type, uint32_t size_key, uint32_t size_value, uint32_t max_elem, uint32_t flags) { union bpf_attr attr = {}; attr.map_type = type; attr.key_size = size_key; attr.value_size = size_value; attr.max_entries = max_elem; attr.map_flags = flags; return bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); } #endif /* __BPF_SYS__ */
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
You can’t perform that action at this time.