LCOV - code coverage report
Current view: top level - js/src/jit/x86-shared - Patching-x86-shared.h (source / functions) Hit Total Coverage
Test: output.info Lines: 39 40 97.5 %
Date: 2017-07-14 16:53:18 Functions: 12 12 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       6             : 
       7             : #ifndef jit_x86_shared_Patching_x86_shared_h
       8             : #define jit_x86_shared_Patching_x86_shared_h
       9             : 
      10             : namespace js {
      11             : namespace jit {
      12             : 
      13             : namespace X86Encoding {
      14             : 
      15             : inline void*
      16           6 : GetPointer(const void* where)
      17             : {
      18             :     void* res;
      19           6 :     memcpy(&res, (const char*)where - sizeof(void*), sizeof(void*));
      20           6 :     return res;
      21             : }
      22             : 
      23             : inline void
      24       12563 : SetPointer(void* where, const void* value)
      25             : {
      26       12563 :     memcpy((char*)where - sizeof(void*), &value, sizeof(void*));
      27       12563 : }
      28             : 
      29             : inline int32_t
      30       47664 : GetInt32(const void* where)
      31             : {
      32             :     int32_t res;
      33       47664 :     memcpy(&res, (const char*)where - sizeof(int32_t), sizeof(int32_t));
      34       47664 :     return res;
      35             : }
      36             : 
      37             : inline void
      38      114101 : SetInt32(void* where, int32_t value)
      39             : {
      40      114101 :     memcpy((char*)where - sizeof(int32_t), &value, sizeof(int32_t));
      41      114101 : }
      42             : 
      43             : inline void
      44       66472 : SetRel32(void* from, void* to)
      45             : {
      46       66472 :     intptr_t offset = reinterpret_cast<intptr_t>(to) - reinterpret_cast<intptr_t>(from);
      47       66472 :     MOZ_ASSERT(offset == static_cast<int32_t>(offset),
      48             :                "offset is too great for a 32-bit relocation");
      49       66472 :     if (offset != static_cast<int32_t>(offset))
      50           0 :         MOZ_CRASH("offset is too great for a 32-bit relocation");
      51             : 
      52       66472 :     SetInt32(from, offset);
      53       66472 : }
      54             : 
      55             : inline void*
      56          36 : GetRel32Target(void* where)
      57             : {
      58          36 :     int32_t rel = GetInt32(where);
      59          36 :     return (char*)where + rel;
      60             : }
      61             : 
      62             : class JmpSrc {
      63             :   public:
      64       47628 :     JmpSrc()
      65       47628 :         : offset_(-1)
      66             :     {
      67       47628 :     }
      68             : 
      69      162551 :     explicit JmpSrc(int32_t offset)
      70      162551 :         : offset_(offset)
      71             :     {
      72      162551 :     }
      73             : 
      74      765874 :     int32_t offset() const {
      75      765874 :         return offset_;
      76             :     }
      77             : 
      78             :     bool isSet() const {
      79             :         return offset_ != -1;
      80             :     }
      81             : 
      82             :   private:
      83             :     int offset_;
      84             : };
      85             : 
      86             : class JmpDst {
      87             :   public:
      88             :     JmpDst()
      89             :         : offset_(-1)
      90             :         , used_(false)
      91             :     {
      92             :     }
      93             : 
      94             :     bool isUsed() const { return used_; }
      95             :     void used() { used_ = true; }
      96             :     bool isValid() const { return offset_ != -1; }
      97             : 
      98      202126 :     explicit JmpDst(int32_t offset)
      99      202126 :         : offset_(offset)
     100      202126 :         , used_(false)
     101             :     {
     102      202126 :         MOZ_ASSERT(offset_ == offset);
     103      202126 :     }
     104      593560 :     int32_t offset() const {
     105      593560 :         return offset_;
     106             :     }
     107             :   private:
     108             :     int32_t offset_ : 31;
     109             :     bool used_ : 1;
     110             : };
     111             : 
     112             : inline bool
     113       19127 : CanRelinkJump(void* from, void* to)
     114             : {
     115       19127 :     intptr_t offset = static_cast<char*>(to) - static_cast<char*>(from);
     116       19127 :     return (offset == static_cast<int32_t>(offset));
     117             : }
     118             : 
     119             : } // namespace X86Encoding
     120             : 
     121             : } // namespace jit
     122             : } // namespace js
     123             : 
     124             : #endif /* jit_x86_shared_Patching_x86_shared_h */

Generated by: LCOV version 1.13