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
30ee348
Documentation
LICENSES
arch
block
certs
crypto
drivers
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
accounting
arch
bpf
build
cgroup
debugging
firewire
firmware
gpio
hv
iio
include
io_uring
kvm
laptop
leds
lib
api
bpf
.gitignore
Build
Makefile
README.rst
bpf.c
bpf.h
bpf_core_read.h
bpf_endian.h
bpf_helpers.h
bpf_prog_linfo.c
bpf_tracing.h
btf.c
btf.h
btf_dump.c
hashmap.c
hashmap.h
libbpf.c
libbpf.h
libbpf.map
libbpf.pc.template
libbpf_errno.c
libbpf_internal.h
libbpf_probes.c
libbpf_util.h
netlink.c
nlattr.c
nlattr.h
str_error.c
str_error.h
test_libbpf.c
xsk.c
xsk.h
lockdep
subcmd
symbol
traceevent
argv_split.c
bitmap.c
ctype.c
find_bit.c
hweight.c
rbtree.c
str_error_r.c
string.c
vsprintf.c
zalloc.c
memory-model
nfsd
objtool
pci
pcmcia
perf
power
scripts
spi
testing
thermal
time
usb
virtio
vm
wmi
Makefile
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
tools
/
lib
/
bpf
/
bpf_prog_linfo.c
Blame
Blame
Latest commit
History
History
246 lines (204 loc) · 6 KB
Breadcrumbs
linux
/
tools
/
lib
/
bpf
/
bpf_prog_linfo.c
Top
File metadata and controls
Code
Blame
246 lines (204 loc) · 6 KB
Raw
// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) /* Copyright (c) 2018 Facebook */ #include <string.h> #include <stdlib.h> #include <linux/err.h> #include <linux/bpf.h> #include "libbpf.h" #include "libbpf_internal.h" struct bpf_prog_linfo { void *raw_linfo; void *raw_jited_linfo; __u32 *nr_jited_linfo_per_func; __u32 *jited_linfo_func_idx; __u32 nr_linfo; __u32 nr_jited_func; __u32 rec_size; __u32 jited_rec_size; }; static int dissect_jited_func(struct bpf_prog_linfo *prog_linfo, const __u64 *ksym_func, const __u32 *ksym_len) { __u32 nr_jited_func, nr_linfo; const void *raw_jited_linfo; const __u64 *jited_linfo; __u64 last_jited_linfo; /* * Index to raw_jited_linfo: * i: Index for searching the next ksym_func * prev_i: Index to the last found ksym_func */ __u32 i, prev_i; __u32 f; /* Index to ksym_func */ raw_jited_linfo = prog_linfo->raw_jited_linfo; jited_linfo = raw_jited_linfo; if (ksym_func[0] != *jited_linfo) goto errout; prog_linfo->jited_linfo_func_idx[0] = 0; nr_jited_func = prog_linfo->nr_jited_func; nr_linfo = prog_linfo->nr_linfo; for (prev_i = 0, i = 1, f = 1; i < nr_linfo && f < nr_jited_func; i++) { raw_jited_linfo += prog_linfo->jited_rec_size; last_jited_linfo = *jited_linfo; jited_linfo = raw_jited_linfo; if (ksym_func[f] == *jited_linfo) { prog_linfo->jited_linfo_func_idx[f] = i; /* Sanity check */ if (last_jited_linfo - ksym_func[f - 1] + 1 > ksym_len[f - 1]) goto errout; prog_linfo->nr_jited_linfo_per_func[f - 1] = i - prev_i; prev_i = i; /* * The ksym_func[f] is found in jited_linfo. * Look for the next one. */ f++; } else if (*jited_linfo <= last_jited_linfo) { /* Ensure the addr is increasing _within_ a func */ goto errout; } } if (f != nr_jited_func) goto errout; prog_linfo->nr_jited_linfo_per_func[nr_jited_func - 1] = nr_linfo - prev_i; return 0; errout: return -EINVAL; } void bpf_prog_linfo__free(struct bpf_prog_linfo *prog_linfo) { if (!prog_linfo) return; free(prog_linfo->raw_linfo); free(prog_linfo->raw_jited_linfo); free(prog_linfo->nr_jited_linfo_per_func); free(prog_linfo->jited_linfo_func_idx); free(prog_linfo); } struct bpf_prog_linfo *bpf_prog_linfo__new(const struct bpf_prog_info *info) { struct bpf_prog_linfo *prog_linfo; __u32 nr_linfo, nr_jited_func; __u64 data_sz; nr_linfo = info->nr_line_info; if (!nr_linfo) return NULL; /* * The min size that bpf_prog_linfo has to access for * searching purpose. */ if (info->line_info_rec_size < offsetof(struct bpf_line_info, file_name_off)) return NULL; prog_linfo = calloc(1, sizeof(*prog_linfo)); if (!prog_linfo) return NULL; /* Copy xlated line_info */ prog_linfo->nr_linfo = nr_linfo; prog_linfo->rec_size = info->line_info_rec_size; data_sz = (__u64)nr_linfo * prog_linfo->rec_size; prog_linfo->raw_linfo = malloc(data_sz); if (!prog_linfo->raw_linfo) goto err_free; memcpy(prog_linfo->raw_linfo, (void *)(long)info->line_info, data_sz); nr_jited_func = info->nr_jited_ksyms; if (!nr_jited_func || !info->jited_line_info || info->nr_jited_line_info != nr_linfo || info->jited_line_info_rec_size < sizeof(__u64) || info->nr_jited_func_lens != nr_jited_func || !info->jited_ksyms || !info->jited_func_lens) /* Not enough info to provide jited_line_info */ return prog_linfo; /* Copy jited_line_info */ prog_linfo->nr_jited_func = nr_jited_func; prog_linfo->jited_rec_size = info->jited_line_info_rec_size; data_sz = (__u64)nr_linfo * prog_linfo->jited_rec_size; prog_linfo->raw_jited_linfo = malloc(data_sz); if (!prog_linfo->raw_jited_linfo) goto err_free; memcpy(prog_linfo->raw_jited_linfo, (void *)(long)info->jited_line_info, data_sz); /* Number of jited_line_info per jited func */ prog_linfo->nr_jited_linfo_per_func = malloc(nr_jited_func * sizeof(__u32)); if (!prog_linfo->nr_jited_linfo_per_func) goto err_free; /* * For each jited func, * the start idx to the "linfo" and "jited_linfo" array, */ prog_linfo->jited_linfo_func_idx = malloc(nr_jited_func * sizeof(__u32)); if (!prog_linfo->jited_linfo_func_idx) goto err_free; if (dissect_jited_func(prog_linfo, (__u64 *)(long)info->jited_ksyms, (__u32 *)(long)info->jited_func_lens)) goto err_free; return prog_linfo; err_free: bpf_prog_linfo__free(prog_linfo); return NULL; } const struct bpf_line_info * bpf_prog_linfo__lfind_addr_func(const struct bpf_prog_linfo *prog_linfo, __u64 addr, __u32 func_idx, __u32 nr_skip) { __u32 jited_rec_size, rec_size, nr_linfo, start, i; const void *raw_jited_linfo, *raw_linfo; const __u64 *jited_linfo; if (func_idx >= prog_linfo->nr_jited_func) return NULL; nr_linfo = prog_linfo->nr_jited_linfo_per_func[func_idx]; if (nr_skip >= nr_linfo) return NULL; start = prog_linfo->jited_linfo_func_idx[func_idx] + nr_skip; jited_rec_size = prog_linfo->jited_rec_size; raw_jited_linfo = prog_linfo->raw_jited_linfo + (start * jited_rec_size); jited_linfo = raw_jited_linfo; if (addr < *jited_linfo) return NULL; nr_linfo -= nr_skip; rec_size = prog_linfo->rec_size; raw_linfo = prog_linfo->raw_linfo + (start * rec_size); for (i = 0; i < nr_linfo; i++) { if (addr < *jited_linfo) break; raw_linfo += rec_size; raw_jited_linfo += jited_rec_size; jited_linfo = raw_jited_linfo; } return raw_linfo - rec_size; } const struct bpf_line_info * bpf_prog_linfo__lfind(const struct bpf_prog_linfo *prog_linfo, __u32 insn_off, __u32 nr_skip) { const struct bpf_line_info *linfo; __u32 rec_size, nr_linfo, i; const void *raw_linfo; nr_linfo = prog_linfo->nr_linfo; if (nr_skip >= nr_linfo) return NULL; rec_size = prog_linfo->rec_size; raw_linfo = prog_linfo->raw_linfo + (nr_skip * rec_size); linfo = raw_linfo; if (insn_off < linfo->insn_off) return NULL; nr_linfo -= nr_skip; for (i = 0; i < nr_linfo; i++) { if (insn_off < linfo->insn_off) break; raw_linfo += rec_size; linfo = raw_linfo; } return raw_linfo - rec_size; }
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
You can’t perform that action at this time.