2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2016 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 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_CODE_RELOCATION_H_
17 #define incl_HPHP_CODE_RELOCATION_H_
19 #include "hphp/runtime/vm/jit/types.h"
20 #include "hphp/util/data-block.h"
26 namespace HPHP
{ namespace jit
{
31 struct RelocationInfo
{
34 void recordRange(TCA start
, TCA end
,
35 TCA destStart
, TCA destEnd
);
36 void recordAddress(TCA src
, TCA dest
, int range
);
37 TCA
adjustedAddressAfter(TCA addr
) const;
38 TCA
adjustedAddressBefore(TCA addr
) const;
39 CTCA
adjustedAddressAfter(CTCA addr
) const {
40 return adjustedAddressAfter(const_cast<TCA
>(addr
));
42 CTCA
adjustedAddressBefore(CTCA addr
) const {
43 return adjustedAddressBefore(const_cast<TCA
>(addr
));
45 void rewind(TCA start
, TCA end
);
46 void markAddressImmediates(const std::set
<TCA
>& ai
) {
47 addressImmediates
.insert(ai
.begin(), ai
.end());
49 bool isAddressImmediate(TCA ip
) {
50 return addressImmediates
.count(ip
);
52 void markSmashableRelocation(TCA ip
) {
53 m_smashableRelocations
.insert(ip
);
55 bool isSmashableRelocation(TCA ip
) {
56 return m_smashableRelocations
.count(ip
);
58 typedef std::vector
<std::pair
<TCA
,TCA
>> RangeVec
;
59 const RangeVec
& srcRanges() { return m_srcRanges
; }
60 const RangeVec
& dstRanges() { return m_dstRanges
; }
65 * maps from src address, to range of destination address
66 * This is because we could insert nops before the instruction
67 * corresponding to src. Most things want the address of the
68 * instruction corresponding to the src instruction; but eg
69 * the fixup map would want the address of the nop.
71 std::map
<TCA
,std::pair
<TCA
,TCA
>> m_adjustedAddresses
;
72 std::set
<TCA
> addressImmediates
;
73 std::set
<TCA
> m_smashableRelocations
;
76 void adjustForRelocation(RelocationInfo
&);
77 void adjustForRelocation(RelocationInfo
& rel
, TCA srcStart
, TCA srcEnd
);
78 void adjustCodeForRelocation(RelocationInfo
& rel
, CGMeta
& fixups
);
79 void adjustMetaDataForRelocation(RelocationInfo
& rel
,
82 void findFixups(TCA start
, TCA end
, CGMeta
& fixups
);
83 size_t relocate(RelocationInfo
& rel
,