tsan_stack_trace.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //===-- tsan_stack_trace.cpp ----------------------------------------------===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file is a part of ThreadSanitizer (TSan), a race detector.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "tsan_stack_trace.h"
  13. #include "tsan_rtl.h"
  14. #include "tsan_mman.h"
  15. namespace __tsan {
  16. VarSizeStackTrace::VarSizeStackTrace()
  17. : StackTrace(nullptr, 0), trace_buffer(nullptr) {}
  18. VarSizeStackTrace::~VarSizeStackTrace() {
  19. ResizeBuffer(0);
  20. }
  21. void VarSizeStackTrace::ResizeBuffer(uptr new_size) {
  22. Free(trace_buffer);
  23. trace_buffer = (new_size > 0)
  24. ? (uptr *)Alloc(new_size * sizeof(trace_buffer[0]))
  25. : nullptr;
  26. trace = trace_buffer;
  27. size = new_size;
  28. }
  29. void VarSizeStackTrace::Init(const uptr *pcs, uptr cnt, uptr extra_top_pc) {
  30. ResizeBuffer(cnt + !!extra_top_pc);
  31. internal_memcpy(trace_buffer, pcs, cnt * sizeof(trace_buffer[0]));
  32. if (extra_top_pc)
  33. trace_buffer[cnt] = extra_top_pc;
  34. }
  35. void VarSizeStackTrace::ReverseOrder() {
  36. for (u32 i = 0; i < (size >> 1); i++)
  37. Swap(trace_buffer[i], trace_buffer[size - 1 - i]);
  38. }
  39. } // namespace __tsan
  40. #if !SANITIZER_GO
  41. void __sanitizer::BufferedStackTrace::UnwindImpl(
  42. uptr pc, uptr bp, void *context, bool request_fast, u32 max_depth) {
  43. uptr top = 0;
  44. uptr bottom = 0;
  45. GetThreadStackTopAndBottom(false, &top, &bottom);
  46. bool fast = StackTrace::WillUseFastUnwind(request_fast);
  47. Unwind(max_depth, pc, bp, context, top, bottom, fast);
  48. }
  49. #endif // SANITIZER_GO