aboutsummaryrefslogtreecommitdiff
path: root/reference_bytes_mixer.cc
blob: d6edd3a9c2f5abdcc5d566459d15505b4cf27f37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/zucchini/reference_bytes_mixer.h"

#include "base/check_op.h"
#include "base/notreached.h"
#include "components/zucchini/disassembler.h"

namespace zucchini {

/******** ReferenceBytesMixer ********/

// Default implementation is a stub, i.e., for architectures whose references
// have operation bits and payload bits stored in separate bytes. So during
// patch application, payload bits are copied for matched blocks, ignored by
// bytewise corrections, and fixed by reference target corrections.
ReferenceBytesMixer::ReferenceBytesMixer() {}

ReferenceBytesMixer::~ReferenceBytesMixer() = default;

// static.
std::unique_ptr<ReferenceBytesMixer> ReferenceBytesMixer::Create(
    const Disassembler& src_dis,
    const Disassembler& dst_dis) {
  ExecutableType exe_type = src_dis.GetExeType();
  DCHECK_EQ(exe_type, dst_dis.GetExeType());
  // TODO(huangs): Add ARM handling code when ARM is ready.
  return std::make_unique<ReferenceBytesMixer>();
}

// Stub implementation.
int ReferenceBytesMixer::NumBytes(uint8_t type) const {
  return 0;
}

// Base class implementation is a stub that should not be called.
ConstBufferView ReferenceBytesMixer::Mix(uint8_t type,
                                         ConstBufferView old_view,
                                         offset_t old_offset,
                                         ConstBufferView new_view,
                                         offset_t new_offset) {
  NOTREACHED() << "Stub.";
  return ConstBufferView();
}

}  // namespace zucchini