2019-05-28 23:53:55 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2019 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_LDSO_H
|
|
|
|
|
|
|
|
// This is a platform dependent interface. While this header and these decls
|
|
|
|
// are unconditionally included in the standard include stack, the defs
|
|
|
|
// behind them may not be compiled and linked on all platforms.
|
|
|
|
|
|
|
|
// Forward declarations for <link.h> because it is not included here.
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
struct link_map;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Platform-dependent interface on ELF+ld.so supporting compilations.
|
|
|
|
namespace ircd::mods::ldso
|
|
|
|
{
|
2020-05-02 20:35:08 +02:00
|
|
|
struct info;
|
2022-06-22 20:00:45 +02:00
|
|
|
struct exceptions;
|
2020-05-02 20:35:08 +02:00
|
|
|
|
2019-06-03 02:05:36 +02:00
|
|
|
IRCD_EXCEPTION(mods::error, error)
|
|
|
|
IRCD_EXCEPTION(error, not_found);
|
|
|
|
|
2019-05-30 00:41:43 +02:00
|
|
|
using link_closure = std::function<bool (struct link_map &)>;
|
2019-06-04 12:18:03 +02:00
|
|
|
using string_closure = std::function<bool (const string_view &)>;
|
2019-06-03 00:12:32 +02:00
|
|
|
using semantic_version = std::array<long, 3>;
|
2019-05-28 23:53:55 +02:00
|
|
|
|
2019-06-03 05:38:00 +02:00
|
|
|
// Util
|
2019-06-03 00:12:32 +02:00
|
|
|
string_view fullname(const struct link_map &); // /lib/x86_64-linux-gnu/libz.so.1
|
|
|
|
string_view soname(const string_view &fullname); // libz.so.1
|
|
|
|
string_view soname(const struct link_map &); // libz.so.1
|
|
|
|
string_view name(const string_view &soname); // z
|
|
|
|
string_view name(const struct link_map &); // z
|
|
|
|
semantic_version version(const string_view &soname); // 1.0.0
|
|
|
|
semantic_version version(const struct link_map &map); // 1.0.0
|
2020-05-02 22:28:26 +02:00
|
|
|
const void *addr(const struct link_map &); // 0x7ffff...
|
2019-05-30 00:41:43 +02:00
|
|
|
|
2019-06-03 05:38:00 +02:00
|
|
|
// Iteration
|
2019-05-30 00:41:43 +02:00
|
|
|
bool for_each(const link_closure &);
|
2019-06-03 00:12:32 +02:00
|
|
|
bool has_fullname(const string_view &path);
|
|
|
|
bool has_soname(const string_view &name);
|
2019-05-30 00:41:43 +02:00
|
|
|
bool has(const string_view &name);
|
|
|
|
size_t count();
|
2019-06-03 02:05:36 +02:00
|
|
|
|
2019-06-03 05:38:00 +02:00
|
|
|
// Get link
|
2019-06-03 02:05:36 +02:00
|
|
|
struct link_map *get(std::nothrow_t, const string_view &name);
|
|
|
|
struct link_map &get(const string_view &name);
|
2019-06-03 05:38:00 +02:00
|
|
|
|
|
|
|
// Query link
|
2020-05-03 01:22:21 +02:00
|
|
|
const char *strtab(const struct link_map &);
|
2019-06-03 05:38:00 +02:00
|
|
|
string_view string(const struct link_map &, const size_t &idx);
|
2019-06-04 12:18:03 +02:00
|
|
|
bool for_each_needed(const struct link_map &, const string_closure &);
|
2020-03-09 02:55:33 +01:00
|
|
|
|
|
|
|
// dlfcn suite
|
|
|
|
bool loaded(const string_view &name);
|
2019-05-28 23:53:55 +02:00
|
|
|
}
|
2020-05-02 20:35:08 +02:00
|
|
|
|
|
|
|
struct ircd::mods::ldso::info
|
|
|
|
{
|
|
|
|
string_view fname;
|
|
|
|
const void *fbase {nullptr};
|
|
|
|
string_view sname;
|
|
|
|
const void *saddr {nullptr};
|
|
|
|
|
|
|
|
info(const void *const &addr);
|
|
|
|
info() = default;
|
|
|
|
};
|
2022-06-22 20:00:45 +02:00
|
|
|
|
|
|
|
struct ircd::mods::ldso::exceptions
|
|
|
|
{
|
|
|
|
static bool enable;
|
|
|
|
const bool theirs;
|
|
|
|
|
|
|
|
public:
|
|
|
|
exceptions(const bool enable = true);
|
|
|
|
~exceptions() noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline
|
|
|
|
ircd::mods::ldso::exceptions::exceptions(const bool ours)
|
|
|
|
:theirs{enable}
|
|
|
|
{
|
|
|
|
enable = ours;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
ircd::mods::ldso::exceptions::~exceptions()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
enable = theirs;
|
|
|
|
}
|