0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd::mods: Propagate our own exception through ld.so.

This commit is contained in:
Jason Volk 2019-05-28 03:47:02 -07:00
parent 008325d6e8
commit 090fda072b
3 changed files with 94 additions and 25 deletions

View file

@ -134,6 +134,9 @@ if AIO
libircd_la_SOURCES += fs_aio.cc
endif
libircd_la_SOURCES += mods.cc
if LINUX
libircd_la_SOURCES += mods_dl.cc
endif
libircd_la_SOURCES += db_port.cc
libircd_la_SOURCES += db_env.cc
libircd_la_SOURCES += db.cc

View file

@ -40,31 +40,6 @@ ircd::mods::autoload
{ "persist", false },
};
//
// (internal) dlsym hooker
//
extern "C" void *
__libc_dlsym(void *, const char *);
#ifdef IRCD_MODS_HOOK_DLSYM
extern "C" void *
dlsym(void *const handle,
const char *const symbol)
{
#ifdef RB_DEBUG_MODS_HOOK_DLSYM
ircd::log::debug
{
ircd::mods::log, "handle:%p symbol lookup '%s'",
handle,
symbol
};
#endif
return __libc_dlsym(handle, symbol);
}
#endif
//
// mods::mod
//

91
ircd/mods_dl.cc Normal file
View file

@ -0,0 +1,91 @@
// 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.
#include <RB_INC_LINK_H
///////////////////////////////////////////////////////////////////////////////
//
// Symbolic dl-error redefinition to throw our C++ exception for the symbol
// lookup failure, during the lazy binding, directly from the callsite. THIS IS
// BETTER than the default glibc/elf/dl behavior of terminating the program.
//
// We probably need asynchronous-unwind-tables for an exception to safely
// 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.
//
// glibc/sysdeps/generic/ldsodefs.h
struct dl_exception
{
const char *objname;
const char *errstring;
char *message_buffer;
};
extern "C" void
_dl_exception_free(struct dl_exception *)
__attribute__ ((nonnull(1)));
extern "C" void
__attribute__((noreturn))
_dl_signal_exception(int errcode,
struct dl_exception *e,
const char *occasion)
{
const ircd::unwind free
{
std::bind(_dl_exception_free, e)
};
ircd::log::derror
{
ircd::mods::log, "dynamic linker (%d) %s in `%s' :%s",
errcode,
occasion,
e->objname,
e->errstring
};
throw ircd::mods::error
{
"%s in %s (%d) %s",
occasion,
e->objname,
errcode,
e->errstring,
};
}
///////////////////////////////////////////////////////////////////////////////
//
// symbolic dlsym hook
//
#ifdef IRCD_MODS_HOOK_DLSYM
extern "C" void *
__libc_dlsym(void *, const char *);
extern "C" void *
dlsym(void *const handle,
const char *const symbol)
{
#ifdef RB_DEBUG_MODS_HOOK_DLSYM
ircd::log::debug
{
ircd::mods::log, "handle:%p symbol lookup '%s'",
handle,
symbol
};
#endif
return __libc_dlsym(handle, symbol);
}
#endif IRCD_MODS_HOOK_DLSYM