proxygen
folly::symbolizer::UnsafeSelfAllocateStackTracePrinter Class Reference

#include <Symbolizer.h>

Inheritance diagram for folly::symbolizer::UnsafeSelfAllocateStackTracePrinter:
folly::symbolizer::SafeStackTracePrinter

Protected Member Functions

void printSymbolizedStackTrace () override
 

Protected Attributes

const long pageSizeUnchecked_ = sysconf(_SC_PAGESIZE)
 

Additional Inherited Members

- Public Member Functions inherited from folly::symbolizer::SafeStackTracePrinter
 SafeStackTracePrinter (size_t minSignalSafeElfCacheSize=kDefaultMinSignalSafeElfCacheSize, int fd=STDERR_FILENO)
 
virtual ~SafeStackTracePrinter ()
 
FOLLY_NOINLINE void printStackTrace (bool symbolize)
 
void print (StringPiece sp)
 
void flush ()
 
- Static Public Attributes inherited from folly::symbolizer::SafeStackTracePrinter
static constexpr size_t kDefaultMinSignalSafeElfCacheSize = 500
 

Detailed Description

Use this class in rare situations where signal handlers are running in a tiny stack specified by sigaltstack.

This is neither thread-safe nor signal-safe. However, it can usually print something useful while SafeStackTracePrinter would stack overflow.

Signal handlers would need to block other signals to make this safer. Note it's still unsafe even with that.

Definition at line 434 of file Symbolizer.h.

Member Function Documentation

void folly::symbolizer::UnsafeSelfAllocateStackTracePrinter::printSymbolizedStackTrace ( )
overrideprotectedvirtual

Reimplemented from folly::symbolizer::SafeStackTracePrinter.

Definition at line 563 of file Symbolizer.cpp.

563  {
564  if (pageSizeUnchecked_ <= 0) {
565  return;
566  }
567 
568  ucontext_t cur;
569  memset(&cur, 0, sizeof(cur));
570  ucontext_t alt;
571  memset(&alt, 0, sizeof(alt));
572 
573  if (getcontext(&alt) != 0) {
574  return;
575  }
576  alt.uc_link = &cur;
577 
578  MmapPtr p = allocateStack(&alt, (size_t)pageSizeUnchecked_);
579  if (!p) {
580  return;
581  }
582 
583  auto contextStart = [](UnsafeSelfAllocateStackTracePrinter* that) {
584  that->SafeStackTracePrinter::printSymbolizedStackTrace();
585  };
586 
587  makecontext(
588  &alt,
589  (void (*)())(void (*)(UnsafeSelfAllocateStackTracePrinter*))(
590  contextStart),
591  /* argc */ 1,
592  /* arg */ this);
593  // NOTE: swapcontext is not async-signal-safe
594  if (swapcontext(&cur, &alt) != 0) {
595  return;
596  }
597 }

Member Data Documentation

const long folly::symbolizer::UnsafeSelfAllocateStackTracePrinter::pageSizeUnchecked_ = sysconf(_SC_PAGESIZE)
protected

Definition at line 437 of file Symbolizer.h.


The documentation for this class was generated from the following files: