45 handle_ = std::exchange(other.handle_,
nullptr);
46 systems_ = std::exchange(other.systems_, {});
47 contract_ = std::exchange(other.contract_, 0);
59 bool open(
const char* path, std::uint64_t expected, std::string* why =
nullptr) {
60 const auto fail = [why](
const char* msg) {
if (why !=
nullptr) *why = msg;
return false; };
63 if (next.handle_ ==
nullptr)
return fail(
"the platform could not load it");
66 const auto* count =
static_cast<const std::uint32_t*
>(
core::librarySymbol(next.handle_,
"es_system_count"));
68 if (
hash ==
nullptr || count ==
nullptr || decls ==
nullptr) {
71 return fail(
"it carries no declaration table — built for a host that shares memory?");
73 if (*
hash != expected) {
74 return fail(
"it was built against a different engine or address width");
76 next.systems_ = std::span<const EsSystemDecl>(decls, *count);
77 next.contract_ = next.readContract_();
80 *
this = std::move(next);
89 std::uint64_t
contract()
const {
return contract_; }
91 bool isOpen()
const {
return handle_ !=
nullptr; }
94 std::span<const EsSystemDecl>
systems()
const {
return systems_; }
98 for (
const auto& decl : systems_) {
99 if (decl.name !=
nullptr && std::strcmp(decl.name, name) == 0)
return &decl;
118 std::uint64_t readContract_()
const {
119 using Half = std::uint32_t (*)();
122 if (lo ==
nullptr || hi ==
nullptr)
return 0;
123 return (
static_cast<std::uint64_t
>(hi()) << 32) | lo();
126 void* handle_ =
nullptr;
127 std::span<const EsSystemDecl> systems_{};
128 std::uint64_t contract_ = 0;
The host half of the Estella ABI.
Open a shared library and take a symbol out of it.
std::uint64_t contract() const
Module & operator=(Module &&other) noexcept
Module(Module &&other) noexcept
Module(const Module &)=delete
Module & operator=(const Module &)=delete
const EsSystemDecl * find(const char *name) const
std::span< const EsSystemDecl > systems() const
bool open(const char *path, std::uint64_t expected, std::string *why=nullptr)
void closeLibrary(void *handle)
void * openLibrary(const char *path)
void * librarySymbol(void *handle, const char *name)