2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_VM_TRANSLATOR_UNWIND_X64_H_
18 #define incl_HPHP_VM_TRANSLATOR_UNWIND_X64_H_
28 #include "hphp/runtime/base/rds.h"
29 #include "hphp/runtime/base/typed-value.h"
30 #include "hphp/runtime/base/types.h"
31 #include "hphp/runtime/vm/jit/types.h"
32 #include "hphp/runtime/vm/tread-hash-map.h"
33 #include "hphp/util/asm-x64.h"
34 #include "hphp/util/assertions.h"
36 namespace HPHP
{ namespace JIT
{
38 //////////////////////////////////////////////////////////////////////
40 typedef TreadHashMap
<CTCA
, TCA
, ctca_identity_hash
> CatchTraceMap
;
43 * Information the unwinder needs stored in RDS, and the RDS::Link for
44 * it. Used to pass values between unwinder code and catch traces.
47 int64_t unwinderScratch
;
48 TypedValue unwinderTv
;
51 extern RDS::Link
<UnwindRDS
> unwindRdsInfo
;
53 inline ptrdiff_t unwinderScratchOff() {
54 return unwindRdsInfo
.handle() + offsetof(UnwindRDS
, unwinderScratch
);
57 inline ptrdiff_t unwinderSideExitOff() {
58 return unwindRdsInfo
.handle() + offsetof(UnwindRDS
, doSideExit
);
61 inline ptrdiff_t unwinderTvOff() {
62 return unwindRdsInfo
.handle() + offsetof(UnwindRDS
, unwinderTv
);
65 //////////////////////////////////////////////////////////////////////
68 * Meant to work like __cxxabiv1::__is_dependent_exception
69 * See libstdc++-v3/libsupc++/unwind-cxx.h in GCC
71 static inline bool isDependentException(uint64_t c
)
77 * Meant to work like __cxxabiv1::__get_object_from_ue() but with a specific
79 * See libstdc++-v3/libsupc++/unwind-cxx.h in GCC
81 inline std::exception
* exceptionFromUnwindException(
82 _Unwind_Exception
* exceptionObj
)
84 constexpr size_t sizeOfDependentException
= 112;
85 if (isDependentException(exceptionObj
->exception_class
)) {
86 return *reinterpret_cast<std::exception
**>(
87 reinterpret_cast<char*>(exceptionObj
+ 1) - sizeOfDependentException
);
89 return reinterpret_cast<std::exception
*>(exceptionObj
+ 1);
93 inline const std::type_info
& typeInfoFromUnwindException(
94 _Unwind_Exception
* exceptionObj
97 if (isDependentException(exceptionObj
->exception_class
)) {
98 // like __cxxabiv1::__get_refcounted_exception_header_from_obj()
99 constexpr size_t sizeOfRefcountedException
= 128;
100 char * obj
= reinterpret_cast<char*>(
101 exceptionFromUnwindException(exceptionObj
));
102 char * header
= obj
- sizeOfRefcountedException
;
103 // Dereference the exc field, the type_info* is the first field inside that
104 constexpr size_t excOffset
= 16;
105 return *reinterpret_cast<std::type_info
*>(header
+ excOffset
);
107 // like __cxxabiv1::__get_exception_header_from_ue()
108 constexpr size_t sizeOfCxaException
= 112;
109 return **reinterpret_cast<std::type_info
**>(
110 reinterpret_cast<char*>(exceptionObj
+ 1) - sizeOfCxaException
);
115 * Called whenever we create a new translation cache for the whole
118 typedef std::shared_ptr
<void> UnwindInfoHandle
;
119 UnwindInfoHandle
register_unwind_region(unsigned char* address
, size_t size
);
121 //////////////////////////////////////////////////////////////////////