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