Coverage for /Syzygy/pe/transforms/add_hot_patching_metadata_transform.h

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
100.0%660.C++source

Line-by-line coverage:

   1    :  // Copyright 2015 Google Inc. All Rights Reserved.
   2    :  //
   3    :  // Licensed under the Apache License, Version 2.0 (the "License");
   4    :  // you may not use this file except in compliance with the License.
   5    :  // You may obtain a copy of the License at
   6    :  //
   7    :  //     http://www.apache.org/licenses/LICENSE-2.0
   8    :  //
   9    :  // Unless required by applicable law or agreed to in writing, software
  10    :  // distributed under the License is distributed on an "AS IS" BASIS,
  11    :  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12    :  // See the License for the specific language governing permissions and
  13    :  // limitations under the License.
  14    :  //
  15    :  // A BlockGraph transform that saves a hot patching metadata stream (.syzyhp)
  16    :  // that contains the locations and sizes of the blocks that have been prepared
  17    :  // for hot patching.
  18    :  //
  19    :  // Before using this transform, one should prepare blocks for hot patching
  20    :  // using the PEHotPatchingBasicBlockTransfrom and use the set_blocks_prepared
  21    :  // method to pass the vector of prepared blocks.
  22    :  
  23    :  #ifndef SYZYGY_PE_TRANSFORMS_ADD_HOT_PATCHING_METADATA_TRANSFORM_H_
  24    :  #define SYZYGY_PE_TRANSFORMS_ADD_HOT_PATCHING_METADATA_TRANSFORM_H_
  25    :  
  26    :  #include <vector>
  27    :  
  28    :  #include "base/basictypes.h"
  29    :  #include "base/callback.h"
  30    :  #include "syzygy/block_graph/transforms/named_transform.h"
  31    :  
  32    :  namespace pe {
  33    :  namespace transforms {
  34    :  
  35    :  class AddHotPatchingMetadataTransform
  36    :      : public block_graph::transforms::NamedBlockGraphTransformImpl<
  37    :            AddHotPatchingMetadataTransform> {
  38    :   public:
  39    :    typedef block_graph::BlockGraph BlockGraph;
  40    :    typedef block_graph::TransformPolicyInterface TransformPolicyInterface;
  41    :    typedef std::vector<BlockGraph::Block*> BlockVector;
  42    :  
  43    :    // The transform name.
  44    :    static const char kTransformName[];
  45    :  
  46    :    AddHotPatchingMetadataTransform();
  47    :  
  48    :    // @name NamedBlockGraphTransformImpl implementation.
  49    :    // @{
  50    :    // Add the metadata stream to the BlockGraph.
  51    :    // @param policy The policy object restricting how the transform is applied.
  52    :    // @param block_graph the block graph being transformed.
  53    :    // @param header_block the header block.
  54    :    // @returns true on success, false otherwise.
  55    :    bool TransformBlockGraph(const TransformPolicyInterface* policy,
  56    :                             BlockGraph* block_graph,
  57    :                             BlockGraph::Block* header_block);
  58    :    // @}
  59    :  
  60    :    // @name Accessors.
  61    :    // @{
  62    :    // Before using this transform, one should pass a pointer to a vector of
  63    :    // blocks that have been prepared for hot patching to this function.
  64    :    // @param blocks_prepared The vector that contains the prepared blocks.
  65  E :    void set_blocks_prepared(const BlockVector* blocks_prepared) {
  66  E :      blocks_prepared_ = blocks_prepared;
  67  E :    }
  68    :    // Retrieves the pointer to vector of blocks that have been prepared for
  69    :    // hot patching.
  70    :    // @returns the pointer to the vector of blocks.
  71  E :    const BlockVector* blocks_prepared() {
  72  E :      return blocks_prepared_;
  73  E :    }
  74    :    // @}
  75    :  
  76    :   protected:
  77    :    // Adds a section containing the hot patching metadata.
  78    :    // @param block_graph The block_graph to modify.
  79    :    void AddHotPatchingSection(BlockGraph* block_graph);
  80    :  
  81    :    // Calculates the code size of a block. It assumes that everything before the
  82    :    // first DATA_LABEL is code. If the block contains no data labels, the whole
  83    :    // data of the block is considered to be code.
  84    :    // @param block The block to calculate
  85    :    // @returns the size of the code the block contains.
  86    :    static size_t CalculateCodeSize(const BlockGraph::Block* block);
  87    :  
  88    :   private:
  89    :    // This is a pointer to a vector that contains the blocks prepared for
  90    :    // hot patching. The TransformBlockGraph uses this data to build the
  91    :    // hot patching stream.
  92    :    const BlockVector* blocks_prepared_;
  93    :  
  94    :    DISALLOW_COPY_AND_ASSIGN(AddHotPatchingMetadataTransform);
  95    :  };
  96    :  
  97    :  }  // namespace transforms
  98    :  }  // namespace pe
  99    :  
 100    :  #endif  // SYZYGY_PE_TRANSFORMS_ADD_HOT_PATCHING_METADATA_TRANSFORM_H_

Coverage information generated Thu Jan 14 17:40:38 2016.