MCPcopy Create free account
hub / github.com/D7EAD/mkPIVM / resolve_branches

Method resolve_branches

include/mkpivm/bytecode.h:52–67  ·  view source on GitHub ↗

walk the fixup list once every block has an offset

Source from the content-addressed store, hash-verified

50
51 // walk the fixup list once every block has an offset
52 void resolve_branches() {
53 for (const auto& f : branch_fixups_) {
54 auto it = block_offsets_.find(f.target_block_id);
55
56 if (it == block_offsets_.end()) throw Error("resolve_branches: missing block");
57 const std::int64_t rel = static_cast<std::int64_t>(it->second) - (static_cast<std::int64_t>(f.patch_pos) + 4);
58
59 if (rel < INT32_MIN || rel > INT32_MAX) throw Error("resolve_branches: oob");
60 const std::uint32_t v = static_cast<std::uint32_t>(static_cast<std::int32_t>(rel));
61
62 for (int i = 0; i < 4; ++i) {
63 buf_[f.patch_pos + i] = static_cast<std::uint8_t>(v >> (8*i));
64 }
65 }
66 branch_fixups_.clear();
67 }
68
69 // placeholder offset into the data island for an original VA. encoder
70 // fills it in using the IRProgram data map

Callers 2

encode_bytecodeFunction · 0.80
package_shellcodeFunction · 0.80

Calls 3

ErrorClass · 0.85
findMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected