stack_consumption.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  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. // Helper function for measuring stack consumption of signal handlers.
  16. #ifndef ABSL_DEBUGGING_INTERNAL_STACK_CONSUMPTION_H_
  17. #define ABSL_DEBUGGING_INTERNAL_STACK_CONSUMPTION_H_
  18. #include "absl/base/config.h"
  19. // The code in this module is not portable.
  20. // Use this feature test macro to detect its availability.
  21. #ifdef ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION
  22. #error ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION cannot be set directly
  23. #elif !defined(__APPLE__) && !defined(_WIN32) && \
  24. (defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || \
  25. defined(__aarch64__) || defined(__riscv))
  26. #define ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION 1
  27. namespace absl {
  28. ABSL_NAMESPACE_BEGIN
  29. namespace debugging_internal {
  30. // Returns the stack consumption in bytes for the code exercised by
  31. // signal_handler. To measure stack consumption, signal_handler is registered
  32. // as a signal handler, so the code that it exercises must be async-signal
  33. // safe. The argument of signal_handler is an implementation detail of signal
  34. // handlers and should ignored by the code for signal_handler. Use global
  35. // variables to pass information between your test code and signal_handler.
  36. int GetSignalHandlerStackConsumption(void (*signal_handler)(int));
  37. } // namespace debugging_internal
  38. ABSL_NAMESPACE_END
  39. } // namespace absl
  40. #endif // ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION
  41. #endif // ABSL_DEBUGGING_INTERNAL_STACK_CONSUMPTION_H_