0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-11 06:28:55 +02:00

ircd::mods::ldso: Add a DT_NEEDED iterator.

This commit is contained in:
Jason Volk 2019-06-04 03:18:03 -07:00
parent 8a69adb9c5
commit 8a6e9158fe
3 changed files with 56 additions and 0 deletions

View file

@ -28,6 +28,7 @@ namespace ircd::mods::ldso
IRCD_EXCEPTION(error, not_found);
using link_closure = std::function<bool (struct link_map &)>;
using string_closure = std::function<bool (const string_view &)>;
using semantic_version = std::array<long, 3>;
// Util
@ -52,4 +53,5 @@ namespace ircd::mods::ldso
// Query link
string_view string(const struct link_map &, const size_t &idx);
bool for_each_needed(const struct link_map &, const string_closure &);
}

View file

@ -21,6 +21,33 @@
// mods/ldso.h
//
bool
ircd::mods::ldso::for_each_needed(const struct link_map &map,
const string_closure &closure)
{
const char *strtab {nullptr};
for(auto d(map.l_ld); d->d_tag != DT_NULL; ++d)
if(d->d_tag == DT_STRTAB)
{
strtab = reinterpret_cast<const char *>(d->d_un.d_ptr);
break;
}
if(!strtab)
return true;
for(auto d(map.l_ld); d->d_tag != DT_NULL; ++d)
{
if(d->d_tag != DT_NEEDED)
continue;
if(!closure(strtab + d->d_un.d_val))
return false;
}
return true;
}
ircd::string_view
ircd::mods::ldso::string(const struct link_map &map,
const size_t &idx)

View file

@ -1690,6 +1690,33 @@ console_cmd__mod__links(opt &out, const string_view &line)
return true;
}
bool
console_cmd__mod__needed(opt &out, const string_view &line)
{
const params param{line, " ",
{
"name"
}};
const string_view name
{
param.at("name")
};
size_t i(0);
mods::ldso::for_each_needed(mods::ldso::get(name), [&out, &i]
(const string_view &name)
{
out << std::setw(2) << (i++)
<< " " << name
<< std::endl;
return true;
});
return true;
}
//
// ctx
//