Flutter Engine
The Flutter Engine
Classes | Functions
elf_loader.h File Reference
#include "../include/dart_api.h"

Go to the source code of this file.

Classes

struct  Dart_LoadedElf
 

Functions

DART_EXPORT Dart_LoadedElfDart_LoadELF (const char *filename, uint64_t file_offset, const char **error, const uint8_t **vm_snapshot_data, const uint8_t **vm_snapshot_instrs, const uint8_t **vm_isolate_data, const uint8_t **vm_isolate_instrs)
 Please see documentation for Dart_LoadElf_Fd. More...
 
DART_EXPORT Dart_LoadedElfDart_LoadELF_Memory (const uint8_t *snapshot, uint64_t snapshot_size, const char **error, const uint8_t **vm_snapshot_data, const uint8_t **vm_snapshot_instrs, const uint8_t **vm_isolate_data, const uint8_t **vm_isolate_instrs)
 Please see documentation for Dart_LoadElf_Fd. More...
 
DART_EXPORT void Dart_UnloadELF (Dart_LoadedElf *loaded)
 

Function Documentation

◆ Dart_LoadELF()

DART_EXPORT Dart_LoadedElf * Dart_LoadELF ( const char *  filename,
uint64_t  file_offset,
const char **  error,
const uint8_t **  vm_snapshot_data,
const uint8_t **  vm_snapshot_instrs,
const uint8_t **  vm_isolate_data,
const uint8_t **  vm_isolate_instrs 
)

Please see documentation for Dart_LoadElf_Fd.

Load an ELF object from a file.

On success, return a handle to the library which may be used to close it in Dart_UnloadELF. On error, returns 'nullptr' and sets 'error'. The error string should not be 'free'-d.

file_offset may be non-zero to read an ELF object embedded inside another type of file.

Look up the Dart snapshot symbols "_kVmSnapshotData", "_kVmSnapshotInstructions", "_kVmIsolateData" and "_kVmIsolateInstructions" into the respectively named out-parameters.

Dart_LoadELF_Fd takes ownership of the file descriptor. Dart_LoadELF_Memory does not take ownership of the memory, but borrows it for the duration of the call. The memory can be release as soon as Dart_LoadELF_Memory returns.

Definition at line 590 of file elf_loader.cc.

596 {
597 std::unique_ptr<Mappable> mappable(Mappable::FromPath(filename));
598 if (mappable == nullptr) {
599 *error = "Couldn't open file.";
600 return nullptr;
601 }
602 std::unique_ptr<LoadedElf> elf(
603 new LoadedElf(std::move(mappable), file_offset));
604
605 if (!elf->Load() ||
606 !elf->ResolveSymbols(vm_snapshot_data, vm_snapshot_instrs,
607 vm_isolate_data, vm_isolate_instrs)) {
608 *error = elf->error();
609 return nullptr;
610 }
611
612 return reinterpret_cast<Dart_LoadedElf*>(elf.release());
613}
const uint8_t uint32_t uint32_t GError ** error
const uint8_t * vm_snapshot_data
Definition: main_impl.cc:52

◆ Dart_LoadELF_Memory()

DART_EXPORT Dart_LoadedElf * Dart_LoadELF_Memory ( const uint8_t *  snapshot,
uint64_t  snapshot_size,
const char **  error,
const uint8_t **  vm_snapshot_data,
const uint8_t **  vm_snapshot_instrs,
const uint8_t **  vm_isolate_data,
const uint8_t **  vm_isolate_instrs 
)

Please see documentation for Dart_LoadElf_Fd.

Definition at line 616 of file elf_loader.cc.

623 {
624 std::unique_ptr<Mappable> mappable(
625 Mappable::FromMemory(snapshot, snapshot_size));
626 if (mappable == nullptr) {
627 *error = "Couldn't open file.";
628 return nullptr;
629 }
630 std::unique_ptr<LoadedElf> elf(
631 new LoadedElf(std::move(mappable), /*file_offset=*/0));
632
633 if (!elf->Load() ||
634 !elf->ResolveSymbols(vm_snapshot_data, vm_snapshot_instrs,
635 vm_isolate_data, vm_isolate_instrs)) {
636 *error = elf->error();
637 return nullptr;
638 }
639
640 return reinterpret_cast<Dart_LoadedElf*>(elf.release());
641}

◆ Dart_UnloadELF()

DART_EXPORT void Dart_UnloadELF ( Dart_LoadedElf loaded)

Unloads an ELF object loaded through Dart_LoadELF{_Fd, _Memory}.

Unlike dlclose(), this does not use reference counting. Dart_LoadELF{_Fd, _Memory} will return load the target library separately each time it is called, and the results must be unloaded separately.

Definition at line 643 of file elf_loader.cc.

643 {
644 delete reinterpret_cast<LoadedElf*>(loaded);
645}