0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-27 11:18:51 +02:00

ircd::mods::ldso: Improve interposition of exceptions for runtime behavior switching.

This commit is contained in:
Jason Volk 2022-06-22 11:00:45 -07:00
parent d5302087bc
commit 830a5b9d2a
3 changed files with 60 additions and 7 deletions

View file

@ -25,6 +25,7 @@ extern "C"
namespace ircd::mods::ldso
{
struct info;
struct exceptions;
IRCD_EXCEPTION(mods::error, error)
IRCD_EXCEPTION(error, not_found);
@ -73,3 +74,27 @@ struct ircd::mods::ldso::info
info(const void *const &addr);
info() = default;
};
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;
}

View file

@ -34,6 +34,7 @@ AM_LDFLAGS = \
-Wl,--wrap=pthread_clockjoin_np \
-Wl,--wrap=pthread_self \
-Wl,--wrap=pthread_setname_np \
-Wl,--wrap=_dl_signal_exception \
-Wl,-z,nodelete \
-Wl,-z,nodlopen \
-Wl,-z,lazy \

View file

@ -16,6 +16,8 @@
#include <RB_INC_DLFCN_H
#include <RB_INC_LINK_H
#include "mods.h"
///////////////////////////////////////////////////////////////////////////////
//
// dlfcn suite
@ -308,7 +310,12 @@ ircd::mods::ldso::fullname(const struct link_map &map)
// transit from here through libdl and out of a random PLT slot. non-call-
// exceptions does not appear to be necessary, at least for FUNC symbols.
//
#if defined(HAVE_DLFCN_H)
decltype(ircd::mods::ldso::exceptions::enable)
ircd::mods::ldso::exceptions::enable
{
true
};
// glibc/sysdeps/generic/ldsodefs.h
struct dl_exception
@ -326,11 +333,32 @@ extern "C" void
__attribute__((noreturn))
_dl_signal_exception(int, struct dl_exception *, const char *);
extern "C" void
__real__dl_signal_exception(int, struct dl_exception *, const char *);
extern "C" void
__attribute__((noreturn))
_dl_signal_exception(int errcode,
struct dl_exception *e,
const char *occasion)
ircd_dl_signal_exception(int, struct dl_exception *, const char *);
extern "C" void
__wrap__dl_signal_exception(int errcode,
struct dl_exception *e,
const char *occasion)
{
#if defined(HAVE_DLFCN_H)
if(ircd::mods::ldso::exceptions::enable)
return ircd_dl_signal_exception(errcode, e, occasion);
#endif
__real__dl_signal_exception(errcode, e, occasion);
}
#if defined(HAVE_DLFCN_H)
extern "C" void
__attribute__((noreturn))
ircd_dl_signal_exception(int errcode,
struct dl_exception *e,
const char *occasion)
{
using namespace ircd;
@ -346,7 +374,7 @@ _dl_signal_exception(int errcode,
errcode,
occasion,
e->objname,
e->errstring
e->errstring,
};
static const auto &undefined_symbol_prefix
@ -379,8 +407,7 @@ _dl_signal_exception(int errcode,
e->errstring,
};
}
#endif // defined(HAVE_DLFCN_H
#endif // defined(HAVE_DLFCN_H)
///////////////////////////////////////////////////////////////////////////////
//