• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- tsan_stack_trace.cc -----------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is a part of ThreadSanitizer (TSan), a race detector.
11 //
12 //===----------------------------------------------------------------------===//
13 #include "tsan_stack_trace.h"
14 #include "tsan_rtl.h"
15 #include "tsan_mman.h"
16 
17 namespace __tsan {
18 
VarSizeStackTrace()19 VarSizeStackTrace::VarSizeStackTrace()
20     : StackTrace(nullptr, 0), trace_buffer(nullptr) {}
21 
~VarSizeStackTrace()22 VarSizeStackTrace::~VarSizeStackTrace() {
23   ResizeBuffer(0);
24 }
25 
ResizeBuffer(uptr new_size)26 void VarSizeStackTrace::ResizeBuffer(uptr new_size) {
27   if (trace_buffer) {
28     internal_free(trace_buffer);
29   }
30   trace_buffer =
31       (new_size > 0)
32           ? (uptr *)internal_alloc(MBlockStackTrace,
33                                    new_size * sizeof(trace_buffer[0]))
34           : nullptr;
35   trace = trace_buffer;
36   size = new_size;
37 }
38 
Init(const uptr * pcs,uptr cnt,uptr extra_top_pc)39 void VarSizeStackTrace::Init(const uptr *pcs, uptr cnt, uptr extra_top_pc) {
40   ResizeBuffer(cnt + !!extra_top_pc);
41   internal_memcpy(trace_buffer, pcs, cnt * sizeof(trace_buffer[0]));
42   if (extra_top_pc)
43     trace_buffer[cnt] = extra_top_pc;
44 }
45 
46 }  // namespace __tsan
47