class ElfImage
Defined at line 35 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
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> 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> 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<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> 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 321 of file ../../zircon/kernel/phys/elf-image.cc
Allocation Load (memalloc::Type type, 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, 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
void Relocate ()
Apply relocations to the image in place after setting the load address.
Defined at line 244 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
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
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
void PublishDebugdata (PublishDebugdataFunction publish_debugdata)
Publish instrumentation VMOs for this module. 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 32 of file ../../zircon/kernel/phys/elf-image-vmos.cc
void PublishDebugdata (PublishDebugdataFunction publish_debugdata)
Publish instrumentation VMOs for this module. 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 32 of file ../../zircon/kernel/phys/elf-image-vmos.cc
void PublishDebugdata (PublishDebugdataFunction publish_debugdata)
Publish instrumentation VMOs for this module. 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 32 of file ../../zircon/kernel/phys/elf-image-vmos.cc
ktl::string_view name ()
Defined at line 72 of file ../../zircon/kernel/phys/include/phys/elf-image.h
LoadInfo & load_info ()
Defined at line 74 of file ../../zircon/kernel/phys/include/phys/elf-image.h
const LoadInfo & load_info ()
Defined at line 75 of file ../../zircon/kernel/phys/include/phys/elf-image.h
elfldltl::DirectMemory & image ()
Defined at line 77 of file ../../zircon/kernel/phys/include/phys/elf-image.h
const elfldltl::DirectMemory & image ()
Defined at line 78 of file ../../zircon/kernel/phys/include/phys/elf-image.h
uintptr_t load_bias ()
Defined at line 80 of file ../../zircon/kernel/phys/include/phys/elf-image.h
bool contains_vaddr_range (Elf::size_type vaddr, Elf::size_type len)
Defined at line 85 of file ../../zircon/kernel/phys/include/phys/elf-image.h
bool contains_vaddr_range (Elf::size_type vaddr, Elf::size_type len)
Defined at line 85 of file ../../zircon/kernel/phys/include/phys/elf-image.h
bool contains_vaddr_range (Elf::size_type vaddr, Elf::size_type len)
Defined at line 85 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 92 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 96 of file ../../zircon/kernel/phys/include/phys/elf-image.h
uint64_t entry ()
Defined at line 103 of file ../../zircon/kernel/phys/include/phys/elf-image.h
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 111 of file ../../zircon/kernel/phys/include/phys/elf-image.h
elfldltl::ElfMachine machine ()
Defined at line 115 of file ../../zircon/kernel/phys/include/phys/elf-image.h
const elfldltl::InitFiniInfo<> & init_info ()
Defined at line 117 of file ../../zircon/kernel/phys/include/phys/elf-image.h
ktl::optional<uint64_t> cfi_check_function ()
Defined at line 119 of file ../../zircon/kernel/phys/include/phys/elf-image.h
void set_cfi_check_function (uint64_t cfi_check)
Defined at line 121 of file ../../zircon/kernel/phys/include/phys/elf-image.h
void set_cfi_check_function (uint64_t cfi_check)
Defined at line 121 of file ../../zircon/kernel/phys/include/phys/elf-image.h
ktl::optional<size_t> stack_size ()
Defined at line 123 of file ../../zircon/kernel/phys/include/phys/elf-image.h
ktl::optional<ktl::string_view> interp ()
Defined at line 125 of file ../../zircon/kernel/phys/include/phys/elf-image.h
const ktl::optional<elfldltl::ElfNote> & build_id ()
Defined at line 127 of file ../../zircon/kernel/phys/include/phys/elf-image.h
bool has_patches ()
Defined at line 129 of file ../../zircon/kernel/phys/include/phys/elf-image.h
size_t patch_count ()
Defined at line 131 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 141 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 141 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 141 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 162 of file ../../zircon/kernel/phys/include/phys/elf-image.h
size_t vaddr_size ()
Defined at line 184 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 188 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 195 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 195 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 202 of file ../../zircon/kernel/phys/include/phys/elf-image.h
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 234 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 248 of file ../../zircon/kernel/phys/include/phys/elf-image.h
template <typename F, typename... Args>
void Handoff (Args &&... args)
Call the image's entry point as a [[noreturn]] function type F.
Defined at line 255 of file ../../zircon/kernel/phys/include/phys/elf-image.h
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().
void OnHandoff ()
A function called by Handoff calls this on its own module to provide code
that must be instantiated separately in each module to publish per-module
instrumentation data.
Defined at line 264 of file ../../zircon/kernel/phys/include/phys/elf-image.h
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 270 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 291 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 291 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 291 of file ../../zircon/kernel/phys/elf-image.cc
void Printf (const char * fmt)
Describes the file before ": " and then does printf.
Defined at line 371 of file ../../zircon/kernel/phys/elf-image.cc
void Printf ()
Defined at line 365 of file ../../zircon/kernel/phys/elf-image.cc
void Printf (Error error)
Defined at line 379 of file ../../zircon/kernel/phys/elf-image.cc
void Printf (Error error)
Defined at line 379 of file ../../zircon/kernel/phys/elf-image.cc
void Printf (Error error)
Defined at line 379 of file ../../zircon/kernel/phys/elf-image.cc