mirror of
https://github.com/matrix-construct/construct
synced 2024-05-18 10:53:48 +02:00
ircd::mods::ldso: Add a strtab lookup tool.
This commit is contained in:
parent
b4e44a0ce1
commit
29cdca5fbe
|
@ -762,6 +762,7 @@ RB_CHK_SYSHEADER(unistd.h, [UNISTD_H])
|
|||
RB_CHK_SYSHEADER(signal.h, [SIGNAL_H])
|
||||
RB_CHK_SYSHEADER(ifaddrs.h, [IFADDRS_H])
|
||||
RB_CHK_SYSHEADER(fcntl.h, [FCNTL_H])
|
||||
RB_CHK_SYSHEADER(elf.h, [ELF_H])
|
||||
RB_CHK_SYSHEADER(link.h, [LINK_H])
|
||||
RB_CHK_SYSHEADER(dlfcn.h, [DLFCN_H])
|
||||
RB_CHK_SYSHEADER(sys/types.h, [SYS_TYPES_H])
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace ircd::mods::ldso
|
|||
using link_closure = std::function<bool (struct link_map &)>;
|
||||
using semantic_version = std::array<long, 3>;
|
||||
|
||||
// Util
|
||||
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
|
||||
|
@ -38,12 +39,17 @@ namespace ircd::mods::ldso
|
|||
semantic_version version(const string_view &soname); // 1.0.0
|
||||
semantic_version version(const struct link_map &map); // 1.0.0
|
||||
|
||||
// Iteration
|
||||
bool for_each(const link_closure &);
|
||||
bool has_fullname(const string_view &path);
|
||||
bool has_soname(const string_view &name);
|
||||
bool has(const string_view &name);
|
||||
size_t count();
|
||||
|
||||
// Get link
|
||||
struct link_map *get(std::nothrow_t, const string_view &name);
|
||||
struct link_map &get(const string_view &name);
|
||||
|
||||
// Query link
|
||||
string_view string(const struct link_map &, const size_t &idx);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
// in libircd glibc+ELF supporting environments. Do not rely on these
|
||||
// definitions being available on all platforms.
|
||||
|
||||
#include <RB_INC_ELF_H
|
||||
#include <RB_INC_DLFCN_H
|
||||
#include <RB_INC_LINK_H
|
||||
|
||||
|
@ -20,6 +21,30 @@
|
|||
// mods/ldso.h
|
||||
//
|
||||
|
||||
ircd::string_view
|
||||
ircd::mods::ldso::string(const struct link_map &map,
|
||||
const size_t &idx)
|
||||
{
|
||||
const char *str {nullptr};
|
||||
for(auto d(map.l_ld); d->d_tag != DT_NULL; ++d)
|
||||
if(d->d_tag == DT_STRTAB)
|
||||
{
|
||||
str = reinterpret_cast<const char *>(d->d_un.d_ptr);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!str)
|
||||
return {};
|
||||
|
||||
size_t i(1);
|
||||
for(++str; *str && i < idx; str += strlen(str) + 1)
|
||||
++i;
|
||||
|
||||
return i == idx?
|
||||
string_view{str}:
|
||||
string_view{};
|
||||
}
|
||||
|
||||
struct link_map &
|
||||
ircd::mods::ldso::get(const string_view &name)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue