Files
sdk/runtime/bin/elf_loader.h
T
Ryan Macnak 4ab313cf09 [vm, test] Enable some AOT testing for Fuchsia.
Fix the standalone embedder's ELF loader to open files with the executable permission.

TEST=ci
Bug: b/399714829
Bug: https://github.com/dart-lang/sdk/issues/60442
Cq-Include-Trybots: luci.dart.try:vm-fuchsia-release-arm64-try,vm-fuchsia-release-x64-try
Change-Id: I2652a5849462ce63585550e6c581cc578a228955
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419341
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Zijie He <zijiehe@google.com>
2025-04-01 09:50:12 -07:00

66 lines
2.9 KiB
C

// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef RUNTIME_BIN_ELF_LOADER_H_
#define RUNTIME_BIN_ELF_LOADER_H_
#include "../include/dart_api.h"
typedef struct {
} Dart_LoadedElf;
/// 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.
#if defined(__Fuchsia__) || defined(__linux__) || defined(__FreeBSD__)
DART_EXPORT Dart_LoadedElf* Dart_LoadELF_Fd(int fd,
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);
#endif
/// Please see documentation for Dart_LoadElf_Fd.
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.
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);
/// 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.
DART_EXPORT void Dart_UnloadELF(Dart_LoadedElf* loaded);
#endif // RUNTIME_BIN_ELF_LOADER_H_