Implementing callback functionality for exception routines
[folly.git] / folly / experimental / exception_tracer / ExceptionTracerLib.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 #ifndef FOLLY_EXPERIMENTAL_EXCEPTION_TRACER_EXCEPTIONTRACERLIB_H_
18 #define FOLLY_EXPERIMENTAL_EXCEPTION_TRACER_EXCEPTIONTRACERLIB_H_
19
20 #include <typeinfo>
21 #include <exception>
22
23 namespace folly {
24 namespace exception_tracer {
25
26 namespace detail {
27 /*
28  * Unfortunately due to ambiguous nature of exception specifiers,
29  * standard does not allow them to appear in typedefs or alias-declarations.
30  * We, however, want callbacks to be exception safe.
31  * This dummies are an ugly workaround that problem.
32  */
33 void dummyCxaThrow(void*, std::type_info*, void (*)(void*)) noexcept;
34 void dummyCxaBeginCatch(void*) noexcept;
35 void dummyCxaRethrow(void) noexcept;
36 void dummyCxaEndCatch(void) noexcept;
37 void dummyRethrowException(std::exception_ptr) noexcept;
38 }
39
40 using CxaThrowType = decltype(&detail::dummyCxaThrow);
41 using CxaBeginCatchType = decltype(&detail::dummyCxaBeginCatch);
42 using CxaRethrowType = decltype(&detail::dummyCxaRethrow);
43 using CxaEndCatchType = decltype(&detail::dummyCxaEndCatch);
44 using RethrowExceptionType = decltype(&detail::dummyRethrowException);
45
46 void registerCxaThrowCallback(CxaThrowType callback);
47 void registerCxaBeginCatchCallback(CxaBeginCatchType callback);
48 void registerCxaRethrowCallback(CxaRethrowType callback);
49 void registerCxaEndCatchCallback(CxaEndCatchType callback);
50 void registerRethrowExceptionCallback(RethrowExceptionType callback);
51 }
52 }
53
54 #endif /* FOLLY_EXPERIMENTAL_EXCEPTION_TRACER_EXCEPTIONTRACERLIB_H_ */