2018-03-24 05:40:20 +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.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_MODS_MODS_H
|
|
|
|
|
|
|
|
/// Modules system
|
|
|
|
namespace ircd::mods
|
|
|
|
{
|
|
|
|
struct mod;
|
|
|
|
|
|
|
|
IRCD_EXCEPTION(ircd::error, error)
|
|
|
|
IRCD_EXCEPTION(error, invalid_export)
|
|
|
|
IRCD_EXCEPTION(error, expired_symbol)
|
|
|
|
IRCD_EXCEPTION(error, undefined_symbol)
|
2018-09-14 03:02:10 +02:00
|
|
|
IRCD_EXCEPTION(expired_symbol, unavailable)
|
2018-03-24 05:40:20 +01:00
|
|
|
|
2019-01-06 02:18:08 +01:00
|
|
|
extern log::log log;
|
2018-12-09 00:17:13 +01:00
|
|
|
extern conf::item<bool> enable;
|
|
|
|
extern conf::item<bool> autoload;
|
|
|
|
|
2018-03-24 05:40:20 +01:00
|
|
|
string_view name(const mod &);
|
|
|
|
string_view path(const mod &);
|
2018-10-23 20:15:21 +02:00
|
|
|
bool loaded(const mod &);
|
|
|
|
bool loading(const mod &);
|
|
|
|
bool unloading(const mod &);
|
2018-03-25 23:32:24 +02:00
|
|
|
bool has(const mod &, const string_view &sym);
|
2019-02-10 00:51:55 +01:00
|
|
|
const std::map<std::string, std::string> &exports(const mod &);
|
|
|
|
|
2019-02-09 08:47:07 +01:00
|
|
|
template<class T = uint8_t> const T *ptr(const mod &, const string_view &sym) noexcept;
|
|
|
|
template<class T = uint8_t> T *ptr(mod &, const string_view &sym) noexcept;
|
2018-03-25 23:32:24 +02:00
|
|
|
template<class T> const T &get(const mod &, const string_view &sym);
|
|
|
|
template<class T> T &get(mod &, const string_view &sym);
|
2018-03-24 05:40:20 +01:00
|
|
|
|
2018-10-23 20:15:21 +02:00
|
|
|
// Utils by name
|
2018-03-25 23:32:24 +02:00
|
|
|
bool loaded(const string_view &name);
|
2018-10-23 19:59:16 +02:00
|
|
|
bool loading(const string_view &name);
|
|
|
|
bool unloading(const string_view &name);
|
2018-03-25 23:32:24 +02:00
|
|
|
bool available(const string_view &name);
|
2018-10-23 20:15:21 +02:00
|
|
|
|
2018-03-24 05:40:20 +01:00
|
|
|
// returns dir/name of first dir containing 'name' (and this will be
|
|
|
|
// a loadable module). Unlike libltdl, the reason each individual
|
|
|
|
// candidate failed is presented in a vector.
|
2018-03-25 23:32:24 +02:00
|
|
|
std::string search(const string_view &name, std::vector<std::string> &why);
|
|
|
|
std::string search(const string_view &name);
|
2019-02-08 05:51:38 +01:00
|
|
|
std::string fullpath(const string_view &name);
|
|
|
|
|
|
|
|
// Utils by path
|
|
|
|
bool is_module(const string_view &fullpath);
|
|
|
|
bool is_module(const string_view &fullpath, std::nothrow_t);
|
|
|
|
bool is_module(const string_view &fullpath, std::string &why);
|
2018-03-24 05:40:20 +01:00
|
|
|
|
|
|
|
// Potential modules available to load
|
|
|
|
std::forward_list<std::string> available();
|
|
|
|
}
|
|
|
|
|
2018-10-23 20:15:21 +02:00
|
|
|
#include "paths.h"
|
|
|
|
#include "symbols.h"
|
|
|
|
#include "module.h"
|
|
|
|
#include "sym_ptr.h"
|
|
|
|
#include "import.h"
|
|
|
|
#include "import_shared.h"
|
2019-05-28 23:53:55 +02:00
|
|
|
#include "ldso.h"
|
2018-10-23 20:15:21 +02:00
|
|
|
|
2018-03-24 05:40:20 +01:00
|
|
|
// Exports down into ircd::
|
|
|
|
namespace ircd
|
|
|
|
{
|
|
|
|
using mods::module;
|
|
|
|
using mods::import;
|
|
|
|
using mods::import_shared;
|
|
|
|
}
|
2018-03-25 23:32:24 +02:00
|
|
|
|
|
|
|
namespace ircd::mods
|
|
|
|
{
|
2019-02-09 08:47:07 +01:00
|
|
|
template<> const uint8_t *ptr<const uint8_t>(const mod &, const string_view &sym) noexcept;
|
|
|
|
template<> uint8_t *ptr<uint8_t>(mod &, const string_view &sym) noexcept;
|
|
|
|
|
|
|
|
template<> const uint8_t &get<const uint8_t>(const mod &, const string_view &sym);
|
|
|
|
template<> uint8_t &get<uint8_t>(mod &, const string_view &sym);
|
2018-03-25 23:32:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
T &
|
|
|
|
ircd::mods::get(mod &mod,
|
|
|
|
const string_view &sym)
|
|
|
|
{
|
2019-02-09 08:47:07 +01:00
|
|
|
return reinterpret_cast<T &>(get<uint8_t>(mod, sym));
|
2018-03-25 23:32:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
const T &
|
|
|
|
ircd::mods::get(const mod &mod,
|
|
|
|
const string_view &sym)
|
|
|
|
{
|
2019-02-09 08:47:07 +01:00
|
|
|
return reinterpret_cast<const T &>(get<const uint8_t>(mod, sym));
|
2018-03-25 23:32:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
T *
|
|
|
|
ircd::mods::ptr(mod &mod,
|
|
|
|
const string_view &sym)
|
2019-02-09 08:47:07 +01:00
|
|
|
noexcept
|
2018-03-25 23:32:24 +02:00
|
|
|
{
|
|
|
|
return reinterpret_cast<T *>(ptr<uint8_t>(mod, sym));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
const T *
|
|
|
|
ircd::mods::ptr(const mod &mod,
|
|
|
|
const string_view &sym)
|
2019-02-09 08:47:07 +01:00
|
|
|
noexcept
|
2018-03-25 23:32:24 +02:00
|
|
|
{
|
|
|
|
return reinterpret_cast<const T *>(ptr<const uint8_t>(mod, sym));
|
|
|
|
}
|