Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sts=4 et sw=4 tw=99:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "gc/Marking.h"
8 #include "jit/JitCompartment.h"
9 #if defined(JS_CODEGEN_X86)
10 # include "jit/x86/MacroAssembler-x86.h"
11 #elif defined(JS_CODEGEN_X64)
12 # include "jit/x64/MacroAssembler-x64.h"
13 #else
14 # error "Wrong architecture. Only x86 and x64 should build this file!"
15 #endif
17 using namespace js;
18 using namespace js::jit;
20 void
21 AssemblerX86Shared::copyJumpRelocationTable(uint8_t *dest)
22 {
23 if (jumpRelocations_.length())
24 memcpy(dest, jumpRelocations_.buffer(), jumpRelocations_.length());
25 }
27 void
28 AssemblerX86Shared::copyDataRelocationTable(uint8_t *dest)
29 {
30 if (dataRelocations_.length())
31 memcpy(dest, dataRelocations_.buffer(), dataRelocations_.length());
32 }
34 void
35 AssemblerX86Shared::copyPreBarrierTable(uint8_t *dest)
36 {
37 if (preBarriers_.length())
38 memcpy(dest, preBarriers_.buffer(), preBarriers_.length());
39 }
41 static void
42 TraceDataRelocations(JSTracer *trc, uint8_t *buffer, CompactBufferReader &reader)
43 {
44 while (reader.more()) {
45 size_t offset = reader.readUnsigned();
46 void **ptr = JSC::X86Assembler::getPointerRef(buffer + offset);
48 #ifdef JS_PUNBOX64
49 // All pointers on x64 will have the top bits cleared. If those bits
50 // are not cleared, this must be a Value.
51 uintptr_t *word = reinterpret_cast<uintptr_t *>(ptr);
52 if (*word >> JSVAL_TAG_SHIFT) {
53 jsval_layout layout;
54 layout.asBits = *word;
55 Value v = IMPL_TO_JSVAL(layout);
56 gc::MarkValueUnbarriered(trc, &v, "ion-masm-value");
57 JS_ASSERT(*word == JSVAL_TO_IMPL(v).asBits);
58 continue;
59 }
60 #endif
62 // No barrier needed since these are constants.
63 gc::MarkGCThingUnbarriered(trc, reinterpret_cast<void **>(ptr), "ion-masm-ptr");
64 }
65 }
68 void
69 AssemblerX86Shared::TraceDataRelocations(JSTracer *trc, JitCode *code, CompactBufferReader &reader)
70 {
71 ::TraceDataRelocations(trc, code->raw(), reader);
72 }
74 void
75 AssemblerX86Shared::trace(JSTracer *trc)
76 {
77 for (size_t i = 0; i < jumps_.length(); i++) {
78 RelativePatch &rp = jumps_[i];
79 if (rp.kind == Relocation::JITCODE) {
80 JitCode *code = JitCode::FromExecutable((uint8_t *)rp.target);
81 MarkJitCodeUnbarriered(trc, &code, "masmrel32");
82 JS_ASSERT(code == JitCode::FromExecutable((uint8_t *)rp.target));
83 }
84 }
85 if (dataRelocations_.length()) {
86 CompactBufferReader reader(dataRelocations_);
87 ::TraceDataRelocations(trc, masm.buffer(), reader);
88 }
89 }
91 void
92 AssemblerX86Shared::executableCopy(void *buffer)
93 {
94 masm.executableCopy(buffer);
95 }
97 void
98 AssemblerX86Shared::processCodeLabels(uint8_t *rawCode)
99 {
100 for (size_t i = 0; i < codeLabels_.length(); i++) {
101 CodeLabel label = codeLabels_[i];
102 Bind(rawCode, label.dest(), rawCode + label.src()->offset());
103 }
104 }
106 AssemblerX86Shared::Condition
107 AssemblerX86Shared::InvertCondition(Condition cond)
108 {
109 switch (cond) {
110 case Zero:
111 return NonZero;
112 case NonZero:
113 return Zero;
114 case LessThan:
115 return GreaterThanOrEqual;
116 case LessThanOrEqual:
117 return GreaterThan;
118 case GreaterThan:
119 return LessThanOrEqual;
120 case GreaterThanOrEqual:
121 return LessThan;
122 case Above:
123 return BelowOrEqual;
124 case AboveOrEqual:
125 return Below;
126 case Below:
127 return AboveOrEqual;
128 case BelowOrEqual:
129 return Above;
130 default:
131 MOZ_ASSUME_UNREACHABLE("unexpected condition");
132 }
133 }