MapMemory maps the memory range rng relative to the absolute pointer that is on the top of the stack. Any ObservedPointers that are used while the pointer is mapped will be automatically adjusted to the remapped address. The mapped memory range can be unmapped with a call to UnmapMemory.
(rng memory.Range)
| 567 | // is mapped will be automatically adjusted to the remapped address. |
| 568 | // The mapped memory range can be unmapped with a call to UnmapMemory. |
| 569 | func (b *Builder) MapMemory(rng memory.Range) { |
| 570 | if ty := b.peekStack().ty; ty != protocol.Type_AbsolutePointer { |
| 571 | panic(fmt.Errorf("MapMemory can only map to absolute pointers. Got type: %v", ty)) |
| 572 | } |
| 573 | |
| 574 | // Allocate memory to hold the target mapped base address. |
| 575 | target := b.AllocateMemory(uint64(b.memoryLayout.GetPointer().GetSize())) |
| 576 | b.Store(target) |
| 577 | |
| 578 | s := rng.Span() |
| 579 | i := interval.Merge(&b.mappedMemory, s, false) |
| 580 | if b.mappedMemory[i].Span() != s { |
| 581 | panic(fmt.Errorf("MapMemory range (%v) collides with existing mapped range (%v)", |
| 582 | rng, b.mappedMemory[i])) |
| 583 | } |
| 584 | |
| 585 | b.mappedMemory[i].Target = target |
| 586 | } |
| 587 | |
| 588 | // UnmapMemory unmaps the memory range rng that was previously mapped with a |
| 589 | // call to MapMemory. If the memory range is not exactly a range previously |