MCPcopy Create free account
hub / github.com/GJDuck/e9patch / flattenMapping

Function flattenMapping

src/e9patch/e9mapping.cpp:680–708  ·  view source on GitHub ↗

* Flatten a mapping into a memory buffer. */

Source from the content-addressed store, hash-verified

678 * Flatten a mapping into a memory buffer.
679 */
680void flattenMapping(const Binary *B, uint8_t *buf, const Mapping *mapping,
681 uint8_t fill)
682{
683 memset(buf, fill, mapping->size);
684
685 auto iend = Allocator::end();
686 for (; mapping != nullptr; mapping = mapping->merged)
687 {
688 auto i = mapping->i;
689 const Alloc *a = *i;
690 const size_t SIZE = mapping->size;
691 const intptr_t BASE = mapping->base;
692 const intptr_t END = BASE + SIZE;
693 for (; i != iend; ++i)
694 {
695 a = *i;
696 if (a->lb >= END)
697 break;
698 if (a->bytes == nullptr)
699 continue;
700
701 intptr_t lb = a->lb, ub = a->ub;
702 off_t offset = (lb < BASE? BASE - lb: 0);
703 lb = (lb < BASE? BASE: lb);
704 ub = (ub > END? END: ub);
705 memcpy(buf + (lb - BASE), a->bytes + offset, (ub - lb));
706 }
707 }
708}
709
710/*
711 * Get the virtual bounds of a mapping.

Callers 2

emitElfFunction · 0.85
emitPEFunction · 0.85

Calls 2

memsetFunction · 0.85
memcpyFunction · 0.85

Tested by

no test coverage detected