class ElfImage

Defined at line 36 of file ../../zircon/kernel/phys/include/phys/elf-image.h

Public Members

static basic_string_view kImageName
static const size_t kMaxLoad
static const size_t kMaxBuildIdLen

Public Methods

fit::result<Error> Init (BootfsDir dir, ktl::string_view name, bool relocated)

An ELF image is found at "dir/name". That can be an ELF file or a subtree.

The subtree should contain "image.elf", "code-patches.bin", etc. A

singleton file will be treated as the image with no patches to apply.

Defined at line 59 of file ../../zircon/kernel/phys/elf-image.cc

fit::result<Error> Init (BootfsDir dir, ktl::string_view name, bool relocated)

An ELF image is found at "dir/name". That can be an ELF file or a subtree.

The subtree should contain "image.elf", "code-patches.bin", etc. A

singleton file will be treated as the image with no patches to apply.

Defined at line 59 of file ../../zircon/kernel/phys/elf-image.cc

ktl::string_view name ()

Defined at line 73 of file ../../zircon/kernel/phys/include/phys/elf-image.h

LoadInfo & load_info ()

Defined at line 75 of file ../../zircon/kernel/phys/include/phys/elf-image.h

const LoadInfo & load_info ()

Defined at line 76 of file ../../zircon/kernel/phys/include/phys/elf-image.h

elfldltl::DirectMemory & image ()

Defined at line 78 of file ../../zircon/kernel/phys/include/phys/elf-image.h

const elfldltl::DirectMemory & image ()

Defined at line 79 of file ../../zircon/kernel/phys/include/phys/elf-image.h

uintptr_t load_bias ()

Defined at line 81 of file ../../zircon/kernel/phys/include/phys/elf-image.h

ktl::span<const ktl::byte> memory_image ()

Return the memory image within the current address space. Must be called

after Init().

Defined at line 88 of file ../../zircon/kernel/phys/include/phys/elf-image.h

ktl::span<const ktl::byte> aligned_memory_image ()

This aligns the size up to include the page-alignment padding always

present in the filesystem image.

Defined at line 92 of file ../../zircon/kernel/phys/include/phys/elf-image.h

uint64_t entry ()

Defined at line 99 of file ../../zircon/kernel/phys/include/phys/elf-image.h

fit::result<Error> InitFromFile (BootfsDir::iterator file, bool relocated)

This does the same with a singleton file already located in the BootfsDir.

Defined at line 102 of file ../../zircon/kernel/phys/elf-image.cc

fit::result<Error> InitFromFile (BootfsDir::iterator file, bool relocated)

This does the same with a singleton file already located in the BootfsDir.

Defined at line 102 of file ../../zircon/kernel/phys/elf-image.cc

fit::result<Error> InitFromDir (BootfsDir subdir, ktl::string_view name, bool relocated)

This does the same with an ELF image subdirectory already located.

Defined at line 77 of file ../../zircon/kernel/phys/elf-image.cc

fit::result<Error> InitFromDir (BootfsDir subdir, ktl::string_view name, bool relocated)

This does the same with an ELF image subdirectory already located.

Defined at line 77 of file ../../zircon/kernel/phys/elf-image.cc

fit::result<arch::MapError> MapInto (MapSegmentFunction map_segment)

Generalized form of MapInto uses a MapSegmentFunction callback in place of

aspace.Map; the translation from image() offset to paddr is handled by the

callback. The callback need not require Load() beforehand, if can handle

memsz > filesz (.bss) without adding physically contiguous space past the

end of the original image() of ELF file contents left by Init().

Defined at line 13 of file ../../zircon/kernel/phys/elf-image-mapinto.cc

template <typename T>
T * ImageEntry ()

The entry point is some sort of pointer into the image. It could be a

function pointer or a data pointer. Note that when it's a function

pointer, the type parameter should be a _function_ (not pointer) type and

should include the [[clang::cfi_unchecked_callee]] attribute _in the type_

if it's intended!

Defined at line 107 of file ../../zircon/kernel/phys/include/phys/elf-image.h

elfldltl::ElfMachine machine ()

Defined at line 111 of file ../../zircon/kernel/phys/include/phys/elf-image.h

const elfldltl::InitFiniInfo<> & init_info ()

Defined at line 113 of file ../../zircon/kernel/phys/include/phys/elf-image.h

ktl::optional<size_t> stack_size ()

Defined at line 115 of file ../../zircon/kernel/phys/include/phys/elf-image.h

ktl::optional<ktl::string_view> interp ()

Defined at line 117 of file ../../zircon/kernel/phys/include/phys/elf-image.h

const ktl::optional<elfldltl::ElfNote> & build_id ()

Defined at line 119 of file ../../zircon/kernel/phys/include/phys/elf-image.h

bool has_patches ()

Defined at line 121 of file ../../zircon/kernel/phys/include/phys/elf-image.h

size_t patch_count ()

Defined at line 123 of file ../../zircon/kernel/phys/include/phys/elf-image.h

template <typename Id, typename Callback>
fit::result<Error> ForEachPatch (Callback && callback)

The template parameter must be an `enum class Id : uint32_t` type. Calls

the callback as fit::result

<Error

>(code_patching::Patcher

&

, Id,

ktl::span

<ktl

::byte>, PrintPatchFunction) for each patch in the file

(Print is as for ArchCodePatch in

<lib

/code-patching/code-patches.h>).

Before Load() this patches the BOOTFS file image in place. After Load()

this patches the load image (which could sometimes still be using the file

image in place).

Defined at line 133 of file ../../zircon/kernel/phys/include/phys/elf-image.h

template <typename Id, typename Callback>
fit::result<Error> ForEachPatch (Callback && callback)

The template parameter must be an `enum class Id : uint32_t` type. Calls

the callback as fit::result

<Error

>(code_patching::Patcher

&

, Id,

ktl::span

<ktl

::byte>, PrintPatchFunction) for each patch in the file

(Print is as for ArchCodePatch in

<lib

/code-patching/code-patches.h>).

Before Load() this patches the BOOTFS file image in place. After Load()

this patches the load image (which could sometimes still be using the file

image in place).

Defined at line 133 of file ../../zircon/kernel/phys/include/phys/elf-image.h

bool CanLoadInPlace ()

Return true if the memory within the BOOTFS image for this file is

sufficient to be used in place as the load image.

Defined at line 159 of file ../../zircon/kernel/phys/include/phys/elf-image.h

fit::result<Error> SeparateZeroFill ()

Rewrite the load_info().segments() list after Init() so that each

DataWithZeroFillSegment is replaced with a separate DataSegment and

ZeroFillSegment. Any partial page after the filesz is zero-filled in

place in the file image.

Defined at line 313 of file ../../zircon/kernel/phys/elf-image.cc

Allocation Load (memalloc::Type type, unsigned int module_id, ktl::optional<uint64_t> relocation_address, bool in_place_ok)

Load in place if possible, or else copy into a new Allocation

A virtual load address at which relocation is expected to occur may be

provided; if not, the image will be loaded within the current address

space.

The Allocation returned is null if LoadInPlace was used; otherwise, it

owns the memory backing the new load image and should be kept alive for

the lifetime of the ElfImage. In general, the returned allocation should

not be consulted for addresses within the load image; that is what

memory_image() is for.

Defined at line 164 of file ../../zircon/kernel/phys/elf-image.cc

Allocation Load (memalloc::Type type, unsigned int module_id, ktl::optional<uint64_t> relocation_address, bool in_place_ok)

Load in place if possible, or else copy into a new Allocation

A virtual load address at which relocation is expected to occur may be

provided; if not, the image will be loaded within the current address

space.

The Allocation returned is null if LoadInPlace was used; otherwise, it

owns the memory backing the new load image and should be kept alive for

the lifetime of the ElfImage. In general, the returned allocation should

not be consulted for addresses within the load image; that is what

memory_image() is for.

Defined at line 164 of file ../../zircon/kernel/phys/elf-image.cc

fit::result<arch::MapError> MapInto (MapSegmentFunction map_segment)

Generalized form of MapInto uses a MapSegmentFunction callback in place of

aspace.Map; the translation from image() offset to paddr is handled by the

callback. The callback need not require Load() beforehand, if can handle

memsz > filesz (.bss) without adding physically contiguous space past the

end of the original image() of ELF file contents left by Init().

size_t vaddr_size ()

Defined at line 181 of file ../../zircon/kernel/phys/include/phys/elf-image.h

uintptr_t load_address ()

Returns the virtual address where the image will be loaded. Must be called

after Load().

Defined at line 185 of file ../../zircon/kernel/phys/include/phys/elf-image.h

void set_load_address (uint64_t address)

Set the virtual address where the image will be loaded.

This is the address Relocate() adjusts things for.

Defined at line 192 of file ../../zircon/kernel/phys/include/phys/elf-image.h

void set_load_address (uint64_t address)

Set the virtual address where the image will be loaded.

This is the address Relocate() adjusts things for.

Defined at line 192 of file ../../zircon/kernel/phys/include/phys/elf-image.h

uintptr_t physical_load_address ()

Returns the physical address where the image will be loaded. Must be

called after Load().

Defined at line 199 of file ../../zircon/kernel/phys/include/phys/elf-image.h

void Relocate ()

Apply relocations to the image in place after setting the load address.

Defined at line 245 of file ../../zircon/kernel/phys/elf-image.cc

fit::result<arch::MapError> MapInto (AddressSpace & aspace)

Maps the image at its loaded address, mapping each of its load segments

with appropriate access permissions (modulo the execute-only exception of

AddressSpace::Map()). Must be called after Load().

Defined at line 28 of file ../../zircon/kernel/phys/elf-image-mapinto.cc

void AssertInterpMatchesBuildId (ktl::string_view prefix, const elfldltl::ElfNote & build_id)

Panic if the loaded file doesn't have a PT_INTERP matching the hex string

corresponding to this build ID note; the prefix is used in panic messages.

Defined at line 264 of file ../../zircon/kernel/phys/elf-image.cc

void InitSelf (ktl::string_view name, elfldltl::DirectMemory & memory, uintptr_t load_bias, const Elf::Phdr & load_segment, ktl::span<const ktl::byte> build_id_note)

Set up state to describe the running phys executable.

Defined at line 285 of file ../../zircon/kernel/phys/elf-image.cc

void InitSelf (ktl::string_view name, elfldltl::DirectMemory & memory, uintptr_t load_bias, const Elf::Phdr & load_segment, ktl::span<const ktl::byte> build_id_note)

Set up state to describe the running phys executable.

Defined at line 285 of file ../../zircon/kernel/phys/elf-image.cc

void PublishDebugdata (PublishDebugdataFunction publish_debugdata)

Publish this image's llvm-profdata (if any) as an instrumentation VMO.

This is only meaningful for the running phys executable's own image, i.e.

the one set up by InitSelf. The argument is similar called like

HandoffPrep::PublishExtraVmo, which see; PublishDebugdataFunction takes

different arguments to name the data, so it can be used to compose either

a ZBI_TYPE_DEBUGDATA payload or a named VMO.

Defined at line 18 of file ../../zircon/kernel/phys/elf-image-vmos.cc

void PublishDebugdata (PublishDebugdataFunction publish_debugdata)

Publish this image's llvm-profdata (if any) as an instrumentation VMO.

This is only meaningful for the running phys executable's own image, i.e.

the one set up by InitSelf. The argument is similar called like

HandoffPrep::PublishExtraVmo, which see; PublishDebugdataFunction takes

different arguments to name the data, so it can be used to compose either

a ZBI_TYPE_DEBUGDATA payload or a named VMO.

Defined at line 18 of file ../../zircon/kernel/phys/elf-image-vmos.cc

template <class Writer>
Writer & SymbolizerContext (Writer & writer, unsigned int id, ktl::string_view prefix, bool physical)

This uses the symbolizer_markup::Writer API to emit the contextual

elements describing this ELF module. The ID number should be unique among

modules in the same address space, i.e. since the last Reset() in the same

markup output stream.

Defined at line 231 of file ../../zircon/kernel/phys/include/phys/elf-image.h

template <typename F, typename... Args>
decltype(auto) Call (Args &&... args)

Call the image's entry point as a function type F.

Defined at line 247 of file ../../zircon/kernel/phys/include/phys/elf-image.h

void Printf (const char * fmt)

Describes the file before ": " and then does printf.

Defined at line 363 of file ../../zircon/kernel/phys/elf-image.cc

void Printf ()

Defined at line 357 of file ../../zircon/kernel/phys/elf-image.cc

void Printf (Error error)

Defined at line 371 of file ../../zircon/kernel/phys/elf-image.cc

void Printf (Error error)

Defined at line 371 of file ../../zircon/kernel/phys/elf-image.cc