folly: symbolizer: increase default signal-handler symbolizer elf file cache size...
[folly.git] / folly / experimental / symbolizer / SignalHandler.h
1 /*
2  * Copyright 2016 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
17 #pragma once
18
19 #include <functional>
20
21 namespace folly { namespace symbolizer {
22
23 /**
24  * Install handler for fatal signals. The list of signals being handled is in
25  * SignalHandler.cpp.
26  *
27  * The handler will dump signal and time information followed by a stack trace
28  * to stderr, and then call the callbacks registered below.
29  */
30 void installFatalSignalHandler();
31
32 /**
33  * NOTE: The signal handler cache has a fixed size. ELF files for the
34  * binary and DSOs are added to the cache but never removed.
35  *
36  * Addresses from ELF files not in the cache will (silently) NOT be symbolized.
37  */
38 constexpr size_t kFatalSignalHandlerCacheSize = 10000;
39
40 /**
41  * Add a callback to be run when receiving a fatal signal. They will also
42  * be called by LOG(FATAL) and abort() (as those raise SIGABRT internally).
43  *
44  * These callbacks must be async-signal-safe, so don't even think of using
45  * LOG(...) or printf or malloc / new or doing anything even remotely fun.
46  *
47  * All these fatal callback must be added before calling
48  * installFatalSignalCallbacks(), below.
49  */
50 typedef void (*SignalCallback)(void);
51 void addFatalSignalCallback(SignalCallback callback);
52
53 /**
54  * Install the fatal signal callbacks; fatal signals will call these
55  * callbacks in the order in which they were added.
56  */
57 void installFatalSignalCallbacks();
58
59
60 }}  // namespaces