1 //===-- sanitizer_stacktrace_sparc.cc -------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is shared between AddressSanitizer and ThreadSanitizer
11 // run-time libraries.
13 // Implemention of fast stack unwinding for Sparc.
14 //===----------------------------------------------------------------------===//
16 // This file is ported to Sparc v8, but it should be easy to port to
18 #if defined(__sparcv8__)
20 #include "sanitizer_common.h"
21 #include "sanitizer_stacktrace.h"
23 namespace __sanitizer {
25 void BufferedStackTrace::FastUnwindStack(uptr pc, uptr bp, uptr stack_top,
26 uptr stack_bottom, u32 max_depth) {
27 const uptr kPageSize = GetPageSizeCached();
28 CHECK_GE(max_depth, 2);
31 if (stack_top < 4096) return; // Sanity check for stack top.
32 // Flush register windows to memory
33 asm volatile("ta 3" ::: "memory");
34 uhwptr *frame = (uhwptr*)bp;
35 // Lowest possible address that makes sense as the next frame pointer.
36 // Goes up as we walk the stack.
37 uptr bottom = stack_bottom;
38 // Avoid infinite loop when frame == frame[0] by using frame > prev_frame.
39 while (IsValidFrame((uptr)frame, stack_top, bottom) &&
40 IsAligned((uptr)frame, sizeof(*frame)) &&
42 uhwptr pc1 = frame[15];
43 // Let's assume that any pointer in the 0th page is invalid and
44 // stop unwinding here. If we're adding support for a platform
45 // where this isn't true, we need to reconsider this check.
49 trace_buffer[size++] = (uptr) pc1;
52 frame = (uhwptr*)frame[14];
56 } // namespace __sanitizer
58 #endif // !defined(__sparcv8__)