perf: Fix unaligned accesses while fetching trace values
authorFrederic Weisbecker <fweisbec@gmail.com>
Thu, 20 May 2010 08:34:59 +0000 (10:34 +0200)
committerFrederic Weisbecker <fweisbec@gmail.com>
Thu, 20 May 2010 09:21:57 +0000 (11:21 +0200)
Accessing trace values of an 8 size may end up in a segfault
on archs that can't deal with misaligned access, which is the
case for sparc 64. This is because PERF_SAMPLE_RAW are aligned
to 4 and not to 8.

Fix this on the macros that get the values of 8 size.

This fixes segfaults on perf tools in sparc 64.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: David Miller <davem@davemloft.net>
tools/perf/util/trace-event.h

index 406d452956db1f15e1026d97b56a7991e6b4f8c3..b3e86b1e44443909e518573ab0a1d49f8167f151 100644 (file)
@@ -233,7 +233,12 @@ static inline unsigned long long __data2host8(unsigned long long data)
 
 #define data2host2(ptr)                __data2host2(*(unsigned short *)ptr)
 #define data2host4(ptr)                __data2host4(*(unsigned int *)ptr)
-#define data2host8(ptr)                __data2host8(*(unsigned long long *)ptr)
+#define data2host8(ptr)                ({                              \
+       unsigned long long __val;                               \
+                                                               \
+       memcpy(&__val, (ptr), sizeof(unsigned long long));      \
+       __data2host8(__val);                                    \
+})
 
 extern int header_page_ts_offset;
 extern int header_page_ts_size;