aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/util/session.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 948327d9e92b..64500fc78799 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -960,6 +960,30 @@ out_err:
960 return err; 960 return err;
961} 961}
962 962
963static union perf_event *
964fetch_mmaped_event(struct perf_session *session,
965 u64 head, size_t mmap_size, char *buf)
966{
967 union perf_event *event;
968
969 /*
970 * Ensure we have enough space remaining to read
971 * the size of the event in the headers.
972 */
973 if (head + sizeof(event->header) > mmap_size)
974 return NULL;
975
976 event = (union perf_event *)(buf + head);
977
978 if (session->header.needs_swap)
979 perf_event_header__bswap(&event->header);
980
981 if (head + event->header.size > mmap_size)
982 return NULL;
983
984 return event;
985}
986
963int __perf_session__process_events(struct perf_session *session, 987int __perf_session__process_events(struct perf_session *session,
964 u64 data_offset, u64 data_size, 988 u64 data_offset, u64 data_size,
965 u64 file_size, struct perf_event_ops *ops) 989 u64 file_size, struct perf_event_ops *ops)
@@ -1014,19 +1038,8 @@ remap:
1014 file_pos = file_offset + head; 1038 file_pos = file_offset + head;
1015 1039
1016more: 1040more:
1017 /* 1041 event = fetch_mmaped_event(session, head, mmap_size, buf);
1018 * Ensure we have enough space remaining to read 1042 if (!event) {
1019 * the size of the event in the headers.
1020 */
1021 if (head + sizeof(event->header) > mmap_size)
1022 goto remap;
1023
1024 event = (union perf_event *)(buf + head);
1025
1026 if (session->header.needs_swap)
1027 perf_event_header__bswap(&event->header);
1028
1029 if (head + event->header.size > mmap_size) {
1030 if (mmaps[map_idx]) { 1043 if (mmaps[map_idx]) {
1031 munmap(mmaps[map_idx], mmap_size); 1044 munmap(mmaps[map_idx], mmap_size);
1032 mmaps[map_idx] = NULL; 1045 mmaps[map_idx] = NULL;