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 "jit/x86/Assembler-x86.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "gc/Marking.h" |
michael@0 | 10 | |
michael@0 | 11 | using namespace js; |
michael@0 | 12 | using namespace js::jit; |
michael@0 | 13 | |
michael@0 | 14 | ABIArgGenerator::ABIArgGenerator() |
michael@0 | 15 | : stackOffset_(0), |
michael@0 | 16 | current_() |
michael@0 | 17 | {} |
michael@0 | 18 | |
michael@0 | 19 | ABIArg |
michael@0 | 20 | ABIArgGenerator::next(MIRType type) |
michael@0 | 21 | { |
michael@0 | 22 | current_ = ABIArg(stackOffset_); |
michael@0 | 23 | switch (type) { |
michael@0 | 24 | case MIRType_Int32: |
michael@0 | 25 | case MIRType_Pointer: |
michael@0 | 26 | stackOffset_ += sizeof(uint32_t); |
michael@0 | 27 | break; |
michael@0 | 28 | case MIRType_Float32: // Float32 moves are actually double moves |
michael@0 | 29 | case MIRType_Double: |
michael@0 | 30 | stackOffset_ += sizeof(uint64_t); |
michael@0 | 31 | break; |
michael@0 | 32 | default: |
michael@0 | 33 | MOZ_ASSUME_UNREACHABLE("Unexpected argument type"); |
michael@0 | 34 | } |
michael@0 | 35 | return current_; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | const Register ABIArgGenerator::NonArgReturnVolatileReg0 = ecx; |
michael@0 | 39 | const Register ABIArgGenerator::NonArgReturnVolatileReg1 = edx; |
michael@0 | 40 | const Register ABIArgGenerator::NonVolatileReg = ebx; |
michael@0 | 41 | |
michael@0 | 42 | void |
michael@0 | 43 | Assembler::executableCopy(uint8_t *buffer) |
michael@0 | 44 | { |
michael@0 | 45 | AssemblerX86Shared::executableCopy(buffer); |
michael@0 | 46 | |
michael@0 | 47 | for (size_t i = 0; i < jumps_.length(); i++) { |
michael@0 | 48 | RelativePatch &rp = jumps_[i]; |
michael@0 | 49 | JSC::X86Assembler::setRel32(buffer + rp.offset, rp.target); |
michael@0 | 50 | } |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | class RelocationIterator |
michael@0 | 54 | { |
michael@0 | 55 | CompactBufferReader reader_; |
michael@0 | 56 | uint32_t offset_; |
michael@0 | 57 | |
michael@0 | 58 | public: |
michael@0 | 59 | RelocationIterator(CompactBufferReader &reader) |
michael@0 | 60 | : reader_(reader) |
michael@0 | 61 | { } |
michael@0 | 62 | |
michael@0 | 63 | bool read() { |
michael@0 | 64 | if (!reader_.more()) |
michael@0 | 65 | return false; |
michael@0 | 66 | offset_ = reader_.readUnsigned(); |
michael@0 | 67 | return true; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | uint32_t offset() const { |
michael@0 | 71 | return offset_; |
michael@0 | 72 | } |
michael@0 | 73 | }; |
michael@0 | 74 | |
michael@0 | 75 | static inline JitCode * |
michael@0 | 76 | CodeFromJump(uint8_t *jump) |
michael@0 | 77 | { |
michael@0 | 78 | uint8_t *target = (uint8_t *)JSC::X86Assembler::getRel32Target(jump); |
michael@0 | 79 | return JitCode::FromExecutable(target); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | void |
michael@0 | 83 | Assembler::TraceJumpRelocations(JSTracer *trc, JitCode *code, CompactBufferReader &reader) |
michael@0 | 84 | { |
michael@0 | 85 | RelocationIterator iter(reader); |
michael@0 | 86 | while (iter.read()) { |
michael@0 | 87 | JitCode *child = CodeFromJump(code->raw() + iter.offset()); |
michael@0 | 88 | MarkJitCodeUnbarriered(trc, &child, "rel32"); |
michael@0 | 89 | JS_ASSERT(child == CodeFromJump(code->raw() + iter.offset())); |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 |