xref: /llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup_fuchsia.cpp (revision c146c3b7471af576103971354f0d4c7b78f11495)
193a2be26SAndres Villegas //===-- sanitizer_symbolizer_markup_fuchsia.cpp ---------------------------===//
293a2be26SAndres Villegas //
393a2be26SAndres Villegas // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
493a2be26SAndres Villegas // See https://llvm.org/LICENSE.txt for license information.
593a2be26SAndres Villegas // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
693a2be26SAndres Villegas //
793a2be26SAndres Villegas //===----------------------------------------------------------------------===//
893a2be26SAndres Villegas //
993a2be26SAndres Villegas // This file is shared between various sanitizers' runtime libraries.
1093a2be26SAndres Villegas //
1193a2be26SAndres Villegas // Fuchsia specific implementation of offline markup symbolizer.
1293a2be26SAndres Villegas //===----------------------------------------------------------------------===//
1393a2be26SAndres Villegas #include "sanitizer_platform.h"
1493a2be26SAndres Villegas 
1593a2be26SAndres Villegas #if SANITIZER_SYMBOLIZER_MARKUP
1693a2be26SAndres Villegas 
1793a2be26SAndres Villegas #  include "sanitizer_common.h"
1893a2be26SAndres Villegas #  include "sanitizer_stacktrace_printer.h"
1993a2be26SAndres Villegas #  include "sanitizer_symbolizer.h"
2093a2be26SAndres Villegas #  include "sanitizer_symbolizer_markup.h"
2193a2be26SAndres Villegas #  include "sanitizer_symbolizer_markup_constants.h"
2293a2be26SAndres Villegas 
2393a2be26SAndres Villegas namespace __sanitizer {
2493a2be26SAndres Villegas 
2593a2be26SAndres Villegas // This is used by UBSan for type names, and by ASan for global variable names.
2693a2be26SAndres Villegas // It's expected to return a static buffer that will be reused on each call.
Demangle(const char * name)2793a2be26SAndres Villegas const char *Symbolizer::Demangle(const char *name) {
2893a2be26SAndres Villegas   static char buffer[kFormatDemangleMax];
2993a2be26SAndres Villegas   internal_snprintf(buffer, sizeof(buffer), kFormatDemangle, name);
3093a2be26SAndres Villegas   return buffer;
3193a2be26SAndres Villegas }
3293a2be26SAndres Villegas 
3393a2be26SAndres Villegas // This is used mostly for suppression matching.  Making it work
3493a2be26SAndres Villegas // would enable "interceptor_via_lib" suppressions.  It's also used
3593a2be26SAndres Villegas // once in UBSan to say "in module ..." in a message that also
3693a2be26SAndres Villegas // includes an address in the module, so post-processing can already
3793a2be26SAndres Villegas // pretty-print that so as to indicate the module.
GetModuleNameAndOffsetForPC(uptr pc,const char ** module_name,uptr * module_address)3893a2be26SAndres Villegas bool Symbolizer::GetModuleNameAndOffsetForPC(uptr pc, const char **module_name,
3993a2be26SAndres Villegas                                              uptr *module_address) {
4093a2be26SAndres Villegas   return false;
4193a2be26SAndres Villegas }
4293a2be26SAndres Villegas 
4393a2be26SAndres Villegas // This is mainly used by hwasan for online symbolization. This isn't needed
4493a2be26SAndres Villegas // since hwasan can always just dump stack frames for offline symbolization.
SymbolizeFrame(uptr addr,FrameInfo * info)4593a2be26SAndres Villegas bool Symbolizer::SymbolizeFrame(uptr addr, FrameInfo *info) { return false; }
4693a2be26SAndres Villegas 
4793a2be26SAndres Villegas // This is used in some places for suppression checking, which we
4893a2be26SAndres Villegas // don't really support for Fuchsia.  It's also used in UBSan to
4993a2be26SAndres Villegas // identify a PC location to a function name, so we always fill in
5093a2be26SAndres Villegas // the function member with a string containing markup around the PC
5193a2be26SAndres Villegas // value.
5293a2be26SAndres Villegas // TODO(mcgrathr): Under SANITIZER_GO, it's currently used by TSan
5393a2be26SAndres Villegas // to render stack frames, but that should be changed to use
5493a2be26SAndres Villegas // RenderStackFrame.
SymbolizePC(uptr addr)5593a2be26SAndres Villegas SymbolizedStack *Symbolizer::SymbolizePC(uptr addr) {
5693a2be26SAndres Villegas   SymbolizedStack *s = SymbolizedStack::New(addr);
5793a2be26SAndres Villegas   char buffer[kFormatFunctionMax];
5893a2be26SAndres Villegas   internal_snprintf(buffer, sizeof(buffer), kFormatFunction, addr);
5993a2be26SAndres Villegas   s->info.function = internal_strdup(buffer);
6093a2be26SAndres Villegas   return s;
6193a2be26SAndres Villegas }
6293a2be26SAndres Villegas 
6393a2be26SAndres Villegas // Always claim we succeeded, so that RenderDataInfo will be called.
SymbolizeData(uptr addr,DataInfo * info)6493a2be26SAndres Villegas bool Symbolizer::SymbolizeData(uptr addr, DataInfo *info) {
6593a2be26SAndres Villegas   info->Clear();
6693a2be26SAndres Villegas   info->start = addr;
6793a2be26SAndres Villegas   return true;
6893a2be26SAndres Villegas }
6993a2be26SAndres Villegas 
7093a2be26SAndres Villegas // Fuchsia only uses MarkupStackTracePrinter
NewStackTracePrinter()7193a2be26SAndres Villegas StackTracePrinter *StackTracePrinter::NewStackTracePrinter() {
7293a2be26SAndres Villegas   return new (GetGlobalLowLevelAllocator()) MarkupStackTracePrinter();
7393a2be26SAndres Villegas }
7493a2be26SAndres Villegas 
RenderContext(InternalScopedString *)75*c146c3b7SAndres Villegas void MarkupStackTracePrinter::RenderContext(InternalScopedString *) {}
76*c146c3b7SAndres Villegas 
PlatformInit()7793a2be26SAndres Villegas Symbolizer *Symbolizer::PlatformInit() {
7893a2be26SAndres Villegas   return new (symbolizer_allocator_) Symbolizer({});
7993a2be26SAndres Villegas }
8093a2be26SAndres Villegas 
LateInitialize()8193a2be26SAndres Villegas void Symbolizer::LateInitialize() { Symbolizer::GetOrInit(); }
8293a2be26SAndres Villegas 
8393a2be26SAndres Villegas }  // namespace __sanitizer
8493a2be26SAndres Villegas 
8593a2be26SAndres Villegas #endif  // SANITIZER_SYMBOLIZER_MARKUP
86