mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 07:23:53 +01:00
ircd::mods::ldso: Simplify and extend interface functionality.
This commit is contained in:
parent
0fd7dd998f
commit
28f86802d2
3 changed files with 36 additions and 14 deletions
|
@ -24,9 +24,11 @@ extern "C"
|
|||
/// Platform-dependent interface on ELF+ld.so supporting compilations.
|
||||
namespace ircd::mods::ldso
|
||||
{
|
||||
using link_map_closure = std::function<bool (struct link_map &)>;
|
||||
using link_name_closure = std::function<bool (const string_view &)>;
|
||||
using link_closure = std::function<bool (struct link_map &)>;
|
||||
|
||||
bool for_each(const link_map_closure &);
|
||||
bool for_each(const link_name_closure &);
|
||||
string_view name(const struct link_map &);
|
||||
|
||||
bool for_each(const link_closure &);
|
||||
bool has(const string_view &name);
|
||||
size_t count();
|
||||
}
|
||||
|
|
|
@ -20,18 +20,32 @@
|
|||
// mods/ldso.h
|
||||
//
|
||||
|
||||
bool
|
||||
ircd::mods::ldso::for_each(const link_name_closure &closure)
|
||||
size_t
|
||||
ircd::mods::ldso::count()
|
||||
{
|
||||
return !for_each(link_map_closure{[&closure]
|
||||
(struct link_map &map)
|
||||
size_t ret(0);
|
||||
for_each([&ret](const struct link_map &)
|
||||
{
|
||||
return closure(map.l_name);
|
||||
}});
|
||||
++ret;
|
||||
return true;
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::mods::ldso::for_each(const link_map_closure &closure)
|
||||
ircd::mods::ldso::has(const string_view &name)
|
||||
{
|
||||
return !for_each([&name]
|
||||
(const auto &link)
|
||||
{
|
||||
// false to break
|
||||
return name == ldso::name(link)? false : true;
|
||||
});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::mods::ldso::for_each(const link_closure &closure)
|
||||
{
|
||||
auto *map
|
||||
{
|
||||
|
@ -51,6 +65,12 @@ ircd::mods::ldso::for_each(const link_map_closure &closure)
|
|||
return true;
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::mods::ldso::name(const struct link_map &map)
|
||||
{
|
||||
return map.l_name;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Symbolic dl-error redefinition to throw our C++ exception for the symbol
|
||||
|
|
|
@ -1603,14 +1603,14 @@ console_cmd__mod__unload(opt &out, const string_view &line)
|
|||
}
|
||||
|
||||
bool
|
||||
console_cmd__mod__link_map(opt &out, const string_view &line)
|
||||
console_cmd__mod__links(opt &out, const string_view &line)
|
||||
{
|
||||
size_t i(0);
|
||||
mods::ldso::for_each([&out, &i]
|
||||
(const string_view &name)
|
||||
(const auto &link)
|
||||
{
|
||||
out << std::setw(2) << (i++)
|
||||
<< " " << name
|
||||
<< " " << mods::ldso::name(link)
|
||||
<< std::endl;
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue