SignalHandler.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2013-present Facebook, Inc.
  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. * http://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. #pragma once
  17. #include <functional>
  18. namespace folly {
  19. namespace symbolizer {
  20. /**
  21. * Install handler for fatal signals. The list of signals being handled is in
  22. * SignalHandler.cpp.
  23. *
  24. * The handler will dump signal and time information followed by a stack trace
  25. * to stderr, and then call the callbacks registered below.
  26. */
  27. void installFatalSignalHandler();
  28. /**
  29. * Add a callback to be run when receiving a fatal signal. They will also
  30. * be called by LOG(FATAL) and abort() (as those raise SIGABRT internally).
  31. *
  32. * These callbacks must be async-signal-safe, so don't even think of using
  33. * LOG(...) or printf or malloc / new or doing anything even remotely fun.
  34. *
  35. * All these fatal callback must be added before calling
  36. * installFatalSignalCallbacks(), below.
  37. */
  38. typedef void (*SignalCallback)();
  39. void addFatalSignalCallback(SignalCallback callback);
  40. /**
  41. * Install the fatal signal callbacks; fatal signals will call these
  42. * callbacks in the order in which they were added.
  43. */
  44. void installFatalSignalCallbacks();
  45. } // namespace symbolizer
  46. } // namespace folly