1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "partition_alloc/partition_alloc_base/debug/stack_trace.h"
6 
7 #include "build/build_config.h"
8 #include "partition_alloc/partition_alloc_base/debug/debugging_buildflags.h"
9 
10 namespace partition_alloc::internal::base::debug {
11 
CollectStackTrace(const void ** trace,size_t count)12 size_t CollectStackTrace(const void** trace, size_t count) {
13   // NOTE: This code MUST be async-signal safe (it's used by in-process
14   // stack dumping signal handler). NO malloc or stdio is allowed here.
15 
16 #if BUILDFLAG(PA_CAN_UNWIND_WITH_FRAME_POINTERS)
17   // Regarding Linux and Android, backtrace API internally invokes malloc().
18   // So the API is not available inside memory allocation. Instead try tracing
19   // using frame pointers.
20   return base::debug::TraceStackFramePointers(trace, count, 0);
21 #else
22   // Not able to obtain stack traces.
23   return 0;
24 #endif
25 }
26 
27 }  // namespace partition_alloc::internal::base::debug
28