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

Function shrinkMapping

src/e9patch/e9mapping.cpp:611–642  ·  view source on GitHub ↗

* Shrink a mapping (if possible). */

Source from the content-addressed store, hash-verified

609 * Shrink a mapping (if possible).
610 */
611static void shrinkMapping(Mapping *mapping0, size_t granularity)
612{
613 if (mapping0->size == granularity)
614 return;
615
616 intptr_t lb = INTPTR_MAX, ub = INTPTR_MIN;
617 for (auto mapping = mapping0; mapping != nullptr;
618 mapping = mapping->merged)
619 {
620 lb = std::min(lb, mapping->lb);
621 ub = std::max(ub, mapping->ub);
622 }
623
624 lb = lb - lb % granularity;
625 if (ub % granularity != 0)
626 {
627 ub += granularity;
628 ub = ub - ub % granularity;
629 }
630 size_t size = ub - lb;
631 if (size >= mapping0->size)
632 return;
633
634 for (auto mapping = mapping0; mapping != nullptr;
635 mapping = mapping->merged)
636 {
637 mapping->base += lb;
638 mapping->size = size;
639 mapping->lb -= lb;
640 mapping->ub -= lb;
641 }
642}
643
644/*
645 * Optimize the given set of mappings.

Callers 1

optimizeMappingsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected