template <class ElfLayout = elfldltl::Elf<>, template <typename> class SegmentContainer =
              elfldltl::StaticVector<kMaxSegments>::Container, AbiModuleInline InlineModule = AbiModuleInline::kNo, DecodedModuleRelocInfo WithRelocInfo = DecodedModuleRelocInfo::kYes, template <class SegmentType> class SegmentWrapper = elfldltl::NoSegmentWrapper>

class DecodedModuleInMemory

Defined at line 33 of file ../../sdk/lib/ld/include/lib/ld/decoded-module-in-memory.h

This is a subclass of ld::DecodedModule specifically for decoding a module

by loading it with a Loader API object (see

<lib

/elfldltl/mmap-loader.h> and

<lib

/elfldltl/vmar-loader.h>), and then decoding its metadata segments in

place in the current process's own memory.

The LoadFromFile method uses the Loader and File template APIs to populate

load_info() and the vaddr / phdrs parts of module().

Public Methods

const Region & relro_bounds ()

Set when the PT_GNU_RELRO phdr is seen by set_relro or DecodeFromMemory.

If no such phdr is seen, this will be empty. It can be passed directly to

the Loader::Commit method. Note these are the unadjusted module-relative

vaddr bounds without the load bias applied.

Defined at line 63 of file ../../sdk/lib/ld/include/lib/ld/decoded-module-in-memory.h

void set_relro (std::optional<Phdr> relro_phdr, size_t page_size)

Defined at line 65 of file ../../sdk/lib/ld/include/lib/ld/decoded-module-in-memory.h

void set_relro (std::optional<Phdr> relro_phdr, size_t page_size)

Defined at line 65 of file ../../sdk/lib/ld/include/lib/ld/decoded-module-in-memory.h

template <class Diagnostics, class Loader, class File, typename PhdrAllocator = FixedPhdrAllocator, class... PhdrObservers>
decltype(elfldltl::LoadHeadersFromFile<Elf>(diag, file, std::forward<PhdrAllocator>(phdr_allocator))) LoadFromFile (Diagnostics & diag, Loader & loader, File && file, PhdrAllocator && phdr_allocator, PhdrObservers &&... phdr_observers)

This uses Loader API and File API objects to get the file's memory image

set up, which populates load_info(). This must be called after

HasModule() is true, so it can initialize the module() fields for phdrs

and vaddr bounds. It returns the elfldltl::LoadHeadersFromFile return

value, so the ehdr and phdrs can be examined further. (Note that

module().phdrs might validly be empty, so the returned phdrs buffer should

be used for further decoding.) The File object should no longer be needed

after this, so it can be passed as an rvalue and consumed if convenient.

As long as the PhdrAllocator object does not own the allocations it

returns, then it can be a consumed rvalue too.

Defined at line 83 of file ../../sdk/lib/ld/include/lib/ld/decoded-module-in-memory.h

template <class Diagnostics, class Memory, class... DynamicObservers>
std::optional<DecodeResult> DecodeFromMemory (Diagnostics & diag, Memory && memory, size_t page_size, const Ehdr & ehdr, std::span<const Phdr> phdrs, size_type & max_tls_modid, DynamicObservers &&... dynamic_observers)

After the module's image is in memory via LoadFromFile, this decodes the

ehdr and phdrs for everything else but the PT_LOADs for load_info(),

already filled by LoadFromFile. Now module() is getting filled in with

direct pointers into the loaded image. If it has a PT_TLS, max_tls_modid

will be incremented to set module().tls_modid. The reloc_info() and

module() data is filled from the PT_DYNAMIC, but additional observer

objects for elfldltl::DecodeDynamic can be passed for e.g. DT_NEEDED.

The return value's `dynamic` member points to the PT_DYNAMIC as read using

the Memory object; it also has the stack size request (if any) and the

e_entry header field without load bias adjustment applied.

Defined at line 134 of file ../../sdk/lib/ld/include/lib/ld/decoded-module-in-memory.h

template <class Diagnostics, class Memory, class... DynamicObservers>
std::optional<DecodeResult> DecodeFromMemory (Diagnostics & diag, Memory && memory, size_t page_size, const Ehdr & ehdr, std::span<const Phdr> phdrs, size_type & max_tls_modid, DynamicObservers &&... dynamic_observers)

After the module's image is in memory via LoadFromFile, this decodes the

ehdr and phdrs for everything else but the PT_LOADs for load_info(),

already filled by LoadFromFile. Now module() is getting filled in with

direct pointers into the loaded image. If it has a PT_TLS, max_tls_modid

will be incremented to set module().tls_modid. The reloc_info() and

module() data is filled from the PT_DYNAMIC, but additional observer

objects for elfldltl::DecodeDynamic can be passed for e.g. DT_NEEDED.

The return value's `dynamic` member points to the PT_DYNAMIC as read using

the Memory object; it also has the stack size request (if any) and the

e_entry header field without load bias adjustment applied.

Defined at line 134 of file ../../sdk/lib/ld/include/lib/ld/decoded-module-in-memory.h

template <class Diagnostics, class Memory, class Headers, class... DynamicObservers>
std::optional<DecodeResult> DecodeFromMemory (Diagnostics & diag, Memory && memory, size_t page_size, Headers && headers, size_type & max_tls_modid, DynamicObservers &&... dynamic_observers)

This is a shorthand taking the successful return value from LoadFromFile

(that is, the std::optional

<

...>::value_type of that std::optional

<

...>).

Defined at line 171 of file ../../sdk/lib/ld/include/lib/ld/decoded-module-in-memory.h

template <class Diagnostics, class Memory, class Headers, class... DynamicObservers>
std::optional<DecodeResult> DecodeFromMemory (Diagnostics & diag, Memory && memory, size_t page_size, Headers && headers, size_type & max_tls_modid, DynamicObservers &&... dynamic_observers)

This is a shorthand taking the successful return value from LoadFromFile

(that is, the std::optional

<

...>::value_type of that std::optional

<

...>).

Defined at line 171 of file ../../sdk/lib/ld/include/lib/ld/decoded-module-in-memory.h

template <class Loader>
auto CommitLoader (Loader loader)

This consumes some Loader API object by calling its Commit method with the

RELRO bounds. The caller always takes ownership of the module load image

mappings that the Loader previously owned. The returned Loader::Relro

object can be used to protect the RELRO region or can be explicitly

discarded to (on Fuchsia) prevent further protection changes.

Defined at line 186 of file ../../sdk/lib/ld/include/lib/ld/decoded-module-in-memory.h

Records