1 //===-- tsan_stack_trace.cpp ----------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of ThreadSanitizer (TSan), a race detector.
11 //===----------------------------------------------------------------------===//
12 #include "tsan_stack_trace.h"
14 #include "tsan_mman.h"
18 VarSizeStackTrace::VarSizeStackTrace()
19 : StackTrace(nullptr, 0), trace_buffer(nullptr) {}
21 VarSizeStackTrace::~VarSizeStackTrace() {
25 void VarSizeStackTrace::ResizeBuffer(uptr new_size
) {
27 trace_buffer
= (new_size
> 0)
28 ? (uptr
*)Alloc(new_size
* sizeof(trace_buffer
[0]))
34 void VarSizeStackTrace::Init(const uptr
*pcs
, uptr cnt
, uptr extra_top_pc
) {
35 ResizeBuffer(cnt
+ !!extra_top_pc
);
36 internal_memcpy(trace_buffer
, pcs
, cnt
* sizeof(trace_buffer
[0]));
38 trace_buffer
[cnt
] = extra_top_pc
;
41 void VarSizeStackTrace::ReverseOrder() {
42 for (u32 i
= 0; i
< (size
>> 1); i
++)
43 Swap(trace_buffer
[i
], trace_buffer
[size
- 1 - i
]);
49 void __sanitizer::BufferedStackTrace::UnwindImpl(
50 uptr pc
, uptr bp
, void *context
, bool request_fast
, u32 max_depth
) {
53 GetThreadStackTopAndBottom(false, &top
, &bottom
);
54 bool fast
= StackTrace::WillUseFastUnwind(request_fast
);
55 Unwind(max_depth
, pc
, bp
, context
, top
, bottom
, fast
);
57 #endif // SANITIZER_GO