Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Functions
elf_loader.cc File Reference
#include "bin/elf_loader.h"
#include "platform/globals.h"
#include <memory>
#include <utility>
#include "bin/file.h"
#include "bin/virtual_memory.h"
#include "platform/elf.h"
#include "platform/unwinding_records.h"

Go to the source code of this file.

Classes

class  dart::bin::elf::Mappable
 
class  dart::bin::elf::FileMappable
 
class  dart::bin::elf::MemoryMappable
 
class  dart::bin::elf::LoadedElf
 

Namespaces

namespace  dart
 
namespace  dart::bin
 
namespace  dart::bin::elf
 

Macros

#define CHECK(value)
 
#define ERROR(message)
 
#define CHECK_ERROR(value, message)
 

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.
 
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.
 
DART_EXPORT void Dart_UnloadELF (Dart_LoadedElf *loaded)
 

Macro Definition Documentation

◆ CHECK

#define CHECK (   value)
Value:
if (!(value)) { \
ASSERT(error_ != nullptr); \
return false; \
}

Definition at line 254 of file elf_loader.cc.

255 { \
256 ASSERT(error_ != nullptr); \
257 return false; \
258 }

◆ CHECK_ERROR

#define CHECK_ERROR (   value,
  message 
)
Value:
if (!(value)) { \
error_ = (message); \
return false; \
}
Win32Message message

Definition at line 266 of file elf_loader.cc.

267 { \
268 error_ = (message); \
269 return false; \
270 }

◆ ERROR

#define ERROR (   message)
Value:
{ \
error_ = (message); \
return false; \
}

Definition at line 260 of file elf_loader.cc.

261 { \
262 error_ = (message); \
263 return false; \
264 }

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}
static Mappable * FromPath(const char *path)
const uint8_t uint32_t uint32_t GError ** error

◆ 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}
static Mappable * FromMemory(const uint8_t *memory, size_t size)

◆ 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}