blob: 2b5e7151667cc3cb72adf30d4c45b6bbc3178d9b [file] [log] [blame]
Austin Schuh36244a12019-09-21 17:52:38 -07001//
2// Copyright 2018 The Abseil Authors.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// https://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16// Helper function for measuring stack consumption of signal handlers.
17
18#ifndef ABSL_DEBUGGING_INTERNAL_STACK_CONSUMPTION_H_
19#define ABSL_DEBUGGING_INTERNAL_STACK_CONSUMPTION_H_
20
Austin Schuhb4691e92020-12-31 12:37:18 -080021#include "absl/base/config.h"
22
Austin Schuh36244a12019-09-21 17:52:38 -070023// The code in this module is not portable.
24// Use this feature test macro to detect its availability.
25#ifdef ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION
26#error ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION cannot be set directly
Austin Schuhb4691e92020-12-31 12:37:18 -080027#elif !defined(__APPLE__) && !defined(_WIN32) && \
28 (defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || \
29 defined(__aarch64__))
Austin Schuh36244a12019-09-21 17:52:38 -070030#define ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION 1
31
32namespace absl {
Austin Schuhb4691e92020-12-31 12:37:18 -080033ABSL_NAMESPACE_BEGIN
Austin Schuh36244a12019-09-21 17:52:38 -070034namespace debugging_internal {
35
36// Returns the stack consumption in bytes for the code exercised by
37// signal_handler. To measure stack consumption, signal_handler is registered
38// as a signal handler, so the code that it exercises must be async-signal
39// safe. The argument of signal_handler is an implementation detail of signal
40// handlers and should ignored by the code for signal_handler. Use global
41// variables to pass information between your test code and signal_handler.
42int GetSignalHandlerStackConsumption(void (*signal_handler)(int));
43
44} // namespace debugging_internal
Austin Schuhb4691e92020-12-31 12:37:18 -080045ABSL_NAMESPACE_END
Austin Schuh36244a12019-09-21 17:52:38 -070046} // namespace absl
47
48#endif // ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION
49
50#endif // ABSL_DEBUGGING_INTERNAL_STACK_CONSUMPTION_H_