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
1
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
46b1fa8
Documentation
arch
block
crypto
drivers
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
cgroup
firewire
hv
include
lguest
lib
net
nfsd
perf
Documentation
arch
bench
config
python
scripts
tests
ui
util
include
scripting-engines
PERF-VERSION-GEN
abspath.c
alias.c
annotate.c
annotate.h
bitmap.c
build-id.c
build-id.h
cache.h
callchain.c
callchain.h
cgroup.c
cgroup.h
cloexec.c
cloexec.h
color.c
color.h
comm.c
comm.h
config.c
cpumap.c
cpumap.h
ctype.c
data.c
data.h
debug.c
debug.h
dso.c
dso.h
dwarf-aux.c
dwarf-aux.h
environment.c
event.c
event.h
evlist.c
evlist.h
evsel.c
evsel.h
exec_cmd.c
exec_cmd.h
find-vdso-map.c
generate-cmdlist.sh
header.c
header.h
help.c
help.h
hist.c
hist.h
hweight.c
intlist.c
intlist.h
kvm-stat.h
levenshtein.c
levenshtein.h
machine.c
machine.h
map.c
map.h
ordered-events.c
ordered-events.h
pager.c
parse-events.c
parse-events.h
parse-events.l
parse-events.y
parse-options.c
parse-options.h
path.c
perf_regs.c
perf_regs.h
pmu.c
pmu.h
pmu.l
pmu.y
probe-event.c
probe-event.h
probe-finder.c
probe-finder.h
pstack.c
pstack.h
python-ext-sources
python.c
quote.c
quote.h
rblist.c
rblist.h
record.c
run-command.c
run-command.h
session.c
session.h
setup.py
sigchain.c
sigchain.h
sort.c
sort.h
srcline.c
stat.c
stat.h
strbuf.c
strbuf.h
strfilter.c
strfilter.h
string.c
strlist.c
strlist.h
svghelper.c
svghelper.h
symbol-elf.c
symbol-minimal.c
symbol.c
symbol.h
target.c
target.h
thread.c
thread.h
thread_map.c
thread_map.h
tool.h
top.c
top.h
trace-event-info.c
trace-event-parse.c
trace-event-read.c
trace-event-scripting.c
trace-event.c
trace-event.h
tsc.c
tsc.h
unwind-libdw.c
unwind-libdw.h
unwind-libunwind.c
unwind.h
usage.c
util.c
util.h
values.c
values.h
vdso.c
vdso.h
wrapper.c
xyarray.c
xyarray.h
.gitignore
CREDITS
MANIFEST
Makefile
Makefile.perf
builtin-annotate.c
builtin-bench.c
builtin-buildid-cache.c
builtin-buildid-list.c
builtin-diff.c
builtin-evlist.c
builtin-help.c
builtin-inject.c
builtin-kmem.c
builtin-kvm.c
builtin-list.c
builtin-lock.c
builtin-mem.c
builtin-probe.c
builtin-record.c
builtin-report.c
builtin-sched.c
builtin-script.c
builtin-stat.c
builtin-timechart.c
builtin-top.c
builtin-trace.c
builtin.h
command-list.txt
design.txt
perf-archive.sh
perf-completion.sh
perf-read-vdso.c
perf-sys.h
perf-with-kcore.sh
perf.c
perf.h
power
scripts
testing
thermal
time
usb
virtio
vm
Makefile
usr
virt
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
REPORTING-BUGS
Breadcrumbs
linux
/
tools
/
perf
/
util
/
vdso.c
Copy path
Blame
Blame
Latest commit
History
History
321 lines (255 loc) · 6.14 KB
Breadcrumbs
linux
/
tools
/
perf
/
util
/
vdso.c
Top
File metadata and controls
Code
Blame
321 lines (255 loc) · 6.14 KB
Raw
#include <unistd.h> #include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #include <linux/kernel.h> #include "vdso.h" #include "util.h" #include "symbol.h" #include "machine.h" #include "thread.h" #include "linux/string.h" #include "debug.h" /* * Include definition of find_vdso_map() also used in perf-read-vdso.c for * building perf-read-vdso32 and perf-read-vdsox32. */ #include "find-vdso-map.c" #define VDSO__TEMP_FILE_NAME "/tmp/perf-vdso.so-XXXXXX" struct vdso_file { bool found; bool error; char temp_file_name[sizeof(VDSO__TEMP_FILE_NAME)]; const char *dso_name; const char *read_prog; }; struct vdso_info { struct vdso_file vdso; #if BITS_PER_LONG == 64 struct vdso_file vdso32; struct vdso_file vdsox32; #endif }; static struct vdso_info *vdso_info__new(void) { static const struct vdso_info vdso_info_init = { .vdso = { .temp_file_name = VDSO__TEMP_FILE_NAME, .dso_name = DSO__NAME_VDSO, }, #if BITS_PER_LONG == 64 .vdso32 = { .temp_file_name = VDSO__TEMP_FILE_NAME, .dso_name = DSO__NAME_VDSO32, .read_prog = "perf-read-vdso32", }, .vdsox32 = { .temp_file_name = VDSO__TEMP_FILE_NAME, .dso_name = DSO__NAME_VDSOX32, .read_prog = "perf-read-vdsox32", }, #endif }; return memdup(&vdso_info_init, sizeof(vdso_info_init)); } static char *get_file(struct vdso_file *vdso_file) { char *vdso = NULL; char *buf = NULL; void *start, *end; size_t size; int fd; if (vdso_file->found) return vdso_file->temp_file_name; if (vdso_file->error || find_vdso_map(&start, &end)) return NULL; size = end - start; buf = memdup(start, size); if (!buf) return NULL; fd = mkstemp(vdso_file->temp_file_name); if (fd < 0) goto out; if (size == (size_t) write(fd, buf, size)) vdso = vdso_file->temp_file_name; close(fd); out: free(buf); vdso_file->found = (vdso != NULL); vdso_file->error = !vdso_file->found; return vdso; } void vdso__exit(struct machine *machine) { struct vdso_info *vdso_info = machine->vdso_info; if (!vdso_info) return; if (vdso_info->vdso.found) unlink(vdso_info->vdso.temp_file_name); #if BITS_PER_LONG == 64 if (vdso_info->vdso32.found) unlink(vdso_info->vdso32.temp_file_name); if (vdso_info->vdsox32.found) unlink(vdso_info->vdsox32.temp_file_name); #endif zfree(&machine->vdso_info); } static struct dso *vdso__new(struct machine *machine, const char *short_name, const char *long_name) { struct dso *dso; dso = dso__new(short_name); if (dso != NULL) { dsos__add(&machine->user_dsos, dso); dso__set_long_name(dso, long_name, false); } return dso; } #if BITS_PER_LONG == 64 static enum dso_type machine__thread_dso_type(struct machine *machine, struct thread *thread) { enum dso_type dso_type = DSO__TYPE_UNKNOWN; struct map *map; struct dso *dso; map = map_groups__first(thread->mg, MAP__FUNCTION); for (; map ; map = map_groups__next(map)) { dso = map->dso; if (!dso || dso->long_name[0] != '/') continue; dso_type = dso__type(dso, machine); if (dso_type != DSO__TYPE_UNKNOWN) break; } return dso_type; } static int vdso__do_copy_compat(FILE *f, int fd) { char buf[4096]; size_t count; while (1) { count = fread(buf, 1, sizeof(buf), f); if (ferror(f)) return -errno; if (feof(f)) break; if (count && writen(fd, buf, count) != (ssize_t)count) return -errno; } return 0; } static int vdso__copy_compat(const char *prog, int fd) { FILE *f; int err; f = popen(prog, "r"); if (!f) return -errno; err = vdso__do_copy_compat(f, fd); if (pclose(f) == -1) return -errno; return err; } static int vdso__create_compat_file(const char *prog, char *temp_name) { int fd, err; fd = mkstemp(temp_name); if (fd < 0) return -errno; err = vdso__copy_compat(prog, fd); if (close(fd) == -1) return -errno; return err; } static const char *vdso__get_compat_file(struct vdso_file *vdso_file) { int err; if (vdso_file->found) return vdso_file->temp_file_name; if (vdso_file->error) return NULL; err = vdso__create_compat_file(vdso_file->read_prog, vdso_file->temp_file_name); if (err) { pr_err("%s failed, error %d\n", vdso_file->read_prog, err); vdso_file->error = true; return NULL; } vdso_file->found = true; return vdso_file->temp_file_name; } static struct dso *vdso__findnew_compat(struct machine *machine, struct vdso_file *vdso_file) { const char *file_name; struct dso *dso; dso = dsos__find(&machine->user_dsos, vdso_file->dso_name, true); if (dso) return dso; file_name = vdso__get_compat_file(vdso_file); if (!file_name) return NULL; return vdso__new(machine, vdso_file->dso_name, file_name); } static int vdso__dso_findnew_compat(struct machine *machine, struct thread *thread, struct vdso_info *vdso_info, struct dso **dso) { enum dso_type dso_type; dso_type = machine__thread_dso_type(machine, thread); #ifndef HAVE_PERF_READ_VDSO32 if (dso_type == DSO__TYPE_32BIT) return 0; #endif #ifndef HAVE_PERF_READ_VDSOX32 if (dso_type == DSO__TYPE_X32BIT) return 0; #endif switch (dso_type) { case DSO__TYPE_32BIT: *dso = vdso__findnew_compat(machine, &vdso_info->vdso32); return 1; case DSO__TYPE_X32BIT: *dso = vdso__findnew_compat(machine, &vdso_info->vdsox32); return 1; case DSO__TYPE_UNKNOWN: case DSO__TYPE_64BIT: default: return 0; } } #endif struct dso *vdso__dso_findnew(struct machine *machine, struct thread *thread __maybe_unused) { struct vdso_info *vdso_info; struct dso *dso; if (!machine->vdso_info) machine->vdso_info = vdso_info__new(); vdso_info = machine->vdso_info; if (!vdso_info) return NULL; #if BITS_PER_LONG == 64 if (vdso__dso_findnew_compat(machine, thread, vdso_info, &dso)) return dso; #endif dso = dsos__find(&machine->user_dsos, DSO__NAME_VDSO, true); if (!dso) { char *file; file = get_file(&vdso_info->vdso); if (!file) return NULL; dso = vdso__new(machine, DSO__NAME_VDSO, file); } return dso; } bool dso__is_vdso(struct dso *dso) { return !strcmp(dso->short_name, DSO__NAME_VDSO) || !strcmp(dso->short_name, DSO__NAME_VDSO32) || !strcmp(dso->short_name, DSO__NAME_VDSOX32); }
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
You can’t perform that action at this time.