18 #ifdef ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION 30 namespace debugging_internal {
44 #if defined(__i386__) || defined(__x86_64__) || defined(__ppc__) 45 constexpr
bool kStackGrowsDown =
true;
47 #error Need to define kStackGrowsDown 64 void EmptySignalHandler(
int) {}
68 constexpr
int kAlternateStackSize = 64 << 10;
70 constexpr
int kSafetyMargin = 32;
71 constexpr
char kAlternateStackFillValue = 0x55;
79 int GetStackConsumption(
const void*
const altstack) {
82 if (kStackGrowsDown) {
83 begin =
reinterpret_cast<const char*
>(altstack);
86 begin =
reinterpret_cast<const char*
>(altstack) + kAlternateStackSize - 1;
90 for (
int usage_count = kAlternateStackSize; usage_count > 0; --usage_count) {
91 if (*begin != kAlternateStackFillValue) {
93 "Buffer has overflowed or is about to overflow");
105 int GetSignalHandlerStackConsumption(
void (*signal_handler)(
int)) {
111 void* altstack = mmap(
nullptr, kAlternateStackSize, PROT_READ | PROT_WRITE,
112 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
117 memset(&sigstk, 0,
sizeof(sigstk));
119 sigstk.ss_sp = altstack;
120 sigstk.ss_size = kAlternateStackSize;
123 "sigaltstack() failed");
127 memset(&sa, 0,
sizeof(sa));
128 struct sigaction old_sa1, old_sa2;
129 sigemptyset(&sa.sa_mask);
130 sa.sa_flags = SA_ONSTACK;
133 sa.sa_handler = EmptySignalHandler;
134 ABSL_RAW_CHECK(sigaction(SIGUSR1, &sa, &old_sa1) == 0,
"sigaction() failed");
137 sa.sa_handler = signal_handler;
138 ABSL_RAW_CHECK(sigaction(SIGUSR2, &sa, &old_sa2) == 0,
"sigaction() failed");
146 memset(altstack, kAlternateStackFillValue, kAlternateStackSize);
148 int base_stack_consumption = GetStackConsumption(altstack);
152 int signal_handler_stack_consumption = GetStackConsumption(altstack);
156 "sigaltstack() failed");
158 "sigaction() failed");
160 "sigaction() failed");
162 ABSL_RAW_CHECK(munmap(altstack, kAlternateStackSize) == 0,
"munmap() failed");
163 if (signal_handler_stack_consumption != -1 && base_stack_consumption != -1) {
164 return signal_handler_stack_consumption - base_stack_consumption;
172 #endif // ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION
#define ABSL_RAW_LOG(severity,...)
#define ABSL_RAW_CHECK(condition, message)