class SegmentWithVmo

Defined at line 62 of file ../../src/lib/elfldltl/include/lib/elfldltl/segment-with-vmo.h

elfldltl::SegmentWithVmo::Copy and elfldltl::SegmentWithVmo::NoCopy can be

used as the SegmentWrapper template template parameter in elfldltl::LoadInfo

instantiations. Partial specializations of elfldltl::VmarLoader::SegmentVmo

provided below will then check segment.vmo() when mapping a segment. If

it's a valid handle, then the segment is mapped from that VMO at offset 0;

otherwise it's mapped from the main file VMO at segment.offset() as usual.

The Copy version has the usual behavior of treating the VMO as read-only and

making a copy-on-write child VMO for a writable segment. The NoCopy version

will instead map segment.vmo() itself writable, so it can only be used once

as that VMO's contents will be modified by the process using it.

The NoCopy case allows for simple out-of-process dynamic linking where

nothing is cached for reuse. The Copy case allows for the "zygote" model

where VMOs can be reused to get copy-on-write sharing of segments where

relocation has already been done.

elfldltl::SegmentWithVmo::AlignSegments adjusts any LoadInfo segments that

have a partial page of data followed by zero-fill bytes so that all segments

can be mapped page-aligned without additional partial-page zeroing work (as

elfldltl::AlignedRemoteVmarLoader requires). To do this, it installs a

per-segment VMO that copies (via copy-on-write snapshot) the data and then

zero-fills the partial page directly in the VMO contents. Using this with

an elfldltl::SegmentWithVmo::NoCopy instantiation of elfldltl::LoadInfo

really just does the zeroing work ahead of time; elfldltl::RemoteVmarLoader

would do the same thing when mapping. An elfldltl::SegmentWithVmo::Copy

instantiation can be used either for a full zygote model where the

relocations are applied in the stored VMOs, or simply to share the zeroing

work across multiple separate loads with their own relocations applied to

their own copies (this may be beneficial to overall page-sharing if the

final data page didn't need to be touched for any relocations).

elfldltl::SegmentWithVmo::MakeMutable can be applied to a particular segment

to install its own copied VMO. This is what out-of-process dynamic linking

must do before applying relocations that touch that segment's contents.

The elfldltl::SegmentWithVmo::GetMutableMemory class is meant for use with

the elfldltl::LoadInfoMutableMemory adapter object.

Public Members

static const zx_rights_t kReadonlyRights

Public Methods

template <class Diagnostics, class Segment>
bool MakeMutable (Diagnostics & diag, Segment & segment, zx::unowned_vmo vmo)

This takes a LoadInfo::*Segment type that has file contents (i.e. not

ZeroFillSegment), and ensures that segment.vmo() is a valid segment.

Unless there's a VMO handle there already, it creates a new copy-on-write

child VMO from the original file VMO.

Defined at line 263 of file ../../src/lib/elfldltl/include/lib/elfldltl/segment-with-vmo.h

template <class Diagnostics, class LoadInfo>
bool AlignSegments (Diagnostics & diag, LoadInfo & info, zx::unowned_vmo vmo, typename LoadInfo::size_type page_size, bool readonly)

elfldltl::SegmentWithVmo::AlignSegments modifies a LoadInfo that uses the

SegmentWithVmo wrappers. It ensures that all segment.filesz() values are

page-aligned, so that elfldltl::AlignedRemoteVmarLoader can be used later.

To start with, each segment must have no vmo() handle installed. If a

segment has a misaligned filesz(), then a new copy-on-write child of the

main file VMO is installed as its vmo(). In the modified VMO, the partial

page has been cleared to all zero bytes. The segment.filesz() has been

rounded up to whole pages so it can be mapped with no additional zeroing.

With the optional readonly flag set, make each new per-segment VMO

immutable by replacing the segment .vmo() handle without ZX_RIGHT_WRITE.

Defined at line 286 of file ../../src/lib/elfldltl/include/lib/elfldltl/segment-with-vmo.h

Records