1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/types.h>
3 #include <linux/string.h>
4 #include <linux/zalloc.h>
6 #include "../../../util/event.h"
7 #include "../../../util/synthetic-events.h"
8 #include "../../../util/machine.h"
9 #include "../../../util/tool.h"
10 #include "../../../util/map.h"
11 #include "../../../util/debug.h"
13 #if defined(__x86_64__)
15 int perf_event__synthesize_extra_kmaps(struct perf_tool
*tool
,
16 perf_event__handler_t process
,
17 struct machine
*machine
)
21 struct maps
*kmaps
= &machine
->kmaps
;
22 union perf_event
*event
= zalloc(sizeof(event
->mmap
) +
23 machine
->id_hdr_size
);
26 pr_debug("Not enough memory synthesizing mmap event "
27 "for extra kernel maps\n");
31 maps__for_each_entry(kmaps
, pos
) {
35 if (!__map__is_extra_kernel_map(pos
))
38 kmap
= map__kmap(pos
);
40 size
= sizeof(event
->mmap
) - sizeof(event
->mmap
.filename
) +
41 PERF_ALIGN(strlen(kmap
->name
) + 1, sizeof(u64
)) +
44 memset(event
, 0, size
);
46 event
->mmap
.header
.type
= PERF_RECORD_MMAP
;
49 * kernel uses 0 for user space maps, see kernel/perf_event.c
52 if (machine__is_host(machine
))
53 event
->header
.misc
= PERF_RECORD_MISC_KERNEL
;
55 event
->header
.misc
= PERF_RECORD_MISC_GUEST_KERNEL
;
57 event
->mmap
.header
.size
= size
;
59 event
->mmap
.start
= pos
->start
;
60 event
->mmap
.len
= pos
->end
- pos
->start
;
61 event
->mmap
.pgoff
= pos
->pgoff
;
62 event
->mmap
.pid
= machine
->pid
;
64 strlcpy(event
->mmap
.filename
, kmap
->name
, PATH_MAX
);
66 if (perf_tool__process_synth_event(tool
, event
, machine
,