2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | (c) Copyright IBM Corporation 2015 |
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 #include "hphp/runtime/vm/jit/func-guard-ppc64.h"
19 #include "hphp/runtime/vm/jit/abi.h"
20 #include "hphp/runtime/vm/jit/abi-ppc64.h"
21 #include "hphp/runtime/vm/jit/mc-generator.h"
22 #include "hphp/runtime/vm/jit/smashable-instr-ppc64.h"
23 #include "hphp/runtime/vm/jit/unique-stubs.h"
25 #include "hphp/ppc64-asm/asm-ppc64.h"
26 #include "hphp/util/data-block.h"
27 #include "hphp/util/immed.h"
29 namespace HPHP
{ namespace jit
{ namespace ppc64
{
31 ///////////////////////////////////////////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////////////////
37 constexpr auto kFuncGuardLen
= 0x38;
39 ALWAYS_INLINE
bool isPrologueStub(TCA addr
) {
40 return addr
== mcg
->ustubs().fcallHelperThunk
;
43 ///////////////////////////////////////////////////////////////////////////////
47 ///////////////////////////////////////////////////////////////////////////////
49 void emitFuncGuard(const Func
* func
, CodeBlock
& cb
, CGMeta
& fixups
) {
50 ppc64_asm::Assembler a
{ cb
};
52 const auto tmp1
= ppc64_asm::reg::r3
;
53 const auto tmp2
= ppc64_asm::reg::r4
;
55 assertx(ppc64::abi(CodeKind::CrossTrace
).gpUnreserved
.contains(tmp1
));
56 assertx(ppc64::abi(CodeKind::CrossTrace
).gpUnreserved
.contains(tmp2
));
58 emitSmashableMovq(a
.code(), fixups
, uint64_t(func
), tmp1
);
59 a
. ld (tmp2
, rvmfp()[AROFF(m_func
)]);
60 a
. cmpld (tmp1
, tmp2
);
62 a
. branchAuto(mcg
->ustubs().funcPrologueRedispatch
,
63 ppc64_asm::BranchConditions::NotEqual
);
65 DEBUG_ONLY
auto guard
= funcGuardFromPrologue(a
.frontier(), func
);
66 assertx(funcGuardMatches(guard
, func
));
69 TCA
funcGuardFromPrologue(TCA prologue
, const Func
* func
) {
70 if (isPrologueStub(prologue
)) return prologue
;
71 return (prologue
- kFuncGuardLen
);
74 bool funcGuardMatches(TCA guard
, const Func
* func
) {
75 if (isPrologueStub(guard
)) return false;
77 auto const ifunc
= reinterpret_cast<uintptr_t>(func
);
78 return static_cast<uintptr_t>(ppc64_asm::Assembler::getLi64(guard
)) == ifunc
;
81 void clobberFuncGuard(TCA guard
, const Func
* func
) {
85 ///////////////////////////////////////////////////////////////////////////////