Skip to content

Commit e84ba4e

Browse files
ftang1acmel
authored andcommitted
perf header: Add is_perf_magic() func
With this function, other modules can basically check whether a file is a legal perf data file by checking its first 8 bytes against all possible perf magic numbers. Change the function name from check_perf_magic to more meaningful is_perf_magic as suggested by acme. Signed-off-by: Feng Tang <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent cdbab7c commit e84ba4e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

tools/perf/util/header.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,6 +2341,16 @@ static int try_all_pipe_abis(uint64_t hdr_sz, struct perf_header *ph)
23412341
return -1;
23422342
}
23432343

2344+
bool is_perf_magic(u64 magic)
2345+
{
2346+
if (!memcmp(&magic, __perf_magic1, sizeof(magic))
2347+
|| magic == __perf_magic2
2348+
|| magic == __perf_magic2_sw)
2349+
return true;
2350+
2351+
return false;
2352+
}
2353+
23442354
static int check_magic_endian(u64 magic, uint64_t hdr_sz,
23452355
bool is_pipe, struct perf_header *ph)
23462356
{

tools/perf/util/header.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ int perf_event__synthesize_build_id(struct perf_tool *tool,
154154
int perf_event__process_build_id(struct perf_tool *tool,
155155
union perf_event *event,
156156
struct perf_session *session);
157+
bool is_perf_magic(u64 magic);
157158

158159
/*
159160
* arch specific callback

0 commit comments

Comments
 (0)