2018-02-09 08:35:42 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
namespace ircd::mods
|
|
|
|
{
|
|
|
|
struct mod;
|
|
|
|
|
|
|
|
struct log::log extern log;
|
|
|
|
extern const filesystem::path suffix;
|
|
|
|
|
|
|
|
filesystem::path prefix_if_relative(const filesystem::path &path);
|
|
|
|
filesystem::path postfixed(const filesystem::path &path);
|
|
|
|
filesystem::path unpostfixed(const filesystem::path &path);
|
|
|
|
|
|
|
|
template<class R, class F> R info(const filesystem::path &, F&& closure);
|
|
|
|
std::vector<std::string> sections(const filesystem::path &path);
|
|
|
|
std::vector<std::string> symbols(const filesystem::path &path);
|
2018-03-25 23:32:24 +02:00
|
|
|
std::vector<std::string> symbols(const filesystem::path &path, const string_view §ion);
|
2018-02-09 08:35:42 +01:00
|
|
|
std::unordered_map<std::string, std::string> mangles(const std::vector<std::string> &);
|
|
|
|
std::unordered_map<std::string, std::string> mangles(const filesystem::path &path);
|
2018-03-25 23:32:24 +02:00
|
|
|
std::unordered_map<std::string, std::string> mangles(const filesystem::path &path, const string_view §ion);
|
2018-02-09 08:35:42 +01:00
|
|
|
|
|
|
|
// Get the full path of a [valid] available module by name
|
2018-03-25 23:32:24 +02:00
|
|
|
filesystem::path fullpath(const string_view &name);
|
2018-02-09 08:35:42 +01:00
|
|
|
|
|
|
|
// Checks if loadable module containing a mapi header (does not verify the magic)
|
|
|
|
bool is_module(const filesystem::path &);
|
|
|
|
bool is_module(const filesystem::path &, std::string &why);
|
|
|
|
bool is_module(const filesystem::path &, std::nothrow_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Internal module representation
|
|
|
|
struct ircd::mods::mod
|
|
|
|
:std::enable_shared_from_this<mod>
|
|
|
|
{
|
2018-10-23 19:46:45 +02:00
|
|
|
static std::forward_list<mod *> loading; // State of current dlopen() recursion.
|
2018-10-23 19:59:16 +02:00
|
|
|
static std::forward_list<mod *> unloading; // dlclose() is not recursive but we have this
|
2018-03-25 23:32:24 +02:00
|
|
|
static std::map<string_view, mod *, std::less<>> loaded;
|
2018-02-09 08:35:42 +01:00
|
|
|
|
|
|
|
filesystem::path path;
|
|
|
|
load_mode::type mode;
|
|
|
|
std::deque<mod *> children;
|
|
|
|
std::unordered_map<std::string, std::string> mangles;
|
|
|
|
boost::dll::shared_library handle;
|
|
|
|
const std::string _name;
|
|
|
|
const std::string _location;
|
|
|
|
mapi::header *header;
|
|
|
|
|
|
|
|
// Metadata
|
2018-10-25 22:03:07 +02:00
|
|
|
const string_view &operator[](const string_view &s) const;
|
|
|
|
string_view &operator[](const string_view &s);
|
2018-02-09 08:35:42 +01:00
|
|
|
|
2018-10-25 22:03:07 +02:00
|
|
|
// Convenience accessors
|
2018-02-09 08:35:42 +01:00
|
|
|
auto &name() const { return _name; }
|
|
|
|
auto &location() const { return _location; }
|
|
|
|
auto &version() const { return header->version; }
|
|
|
|
auto &description() const { return (*this)["description"]; }
|
|
|
|
|
|
|
|
bool unload();
|
|
|
|
|
|
|
|
mod(const filesystem::path &,
|
|
|
|
const load_mode::type & = load_mode::rtld_local | load_mode::rtld_now);
|
|
|
|
|
2018-03-26 00:25:32 +02:00
|
|
|
mod(mod &&) = delete;
|
|
|
|
mod(const mod &) = delete;
|
|
|
|
mod &operator=(mod &&) = delete;
|
|
|
|
mod &operator=(const mod &) = delete;
|
2018-02-09 08:35:42 +01:00
|
|
|
~mod() noexcept;
|
|
|
|
};
|