Speculative fix - try to avoid crashes if hooked dlopen is called early

* This isn't particularly stable/nice, probably needs a complete rethink
This commit is contained in:
baldurk
2015-10-01 00:51:22 +02:00
parent e2871e1245
commit 079a44b4a9
4 changed files with 21 additions and 1 deletions
+1 -1
View File
@@ -81,7 +81,7 @@ class Hook
// just need this for dlsym
#include <dlfcn.h>
#define HOOKS_BEGIN()
#define HOOKS_BEGIN() LinuxHookInit()
#define HOOKS_END()
#define HOOKS_REMOVE()
+16
View File
@@ -35,6 +35,16 @@
#include <map>
#include <string>
// depending on symbol resolution, dlopen could get called really early.
// until we've initialised, just skip any fancy stuff
static uint32_t hookInited = 0;
#define HOOK_MAGIC_NUMBER 0xAAF00F00
void LinuxHookInit()
{
hookInited = HOOK_MAGIC_NUMBER;
}
// need to lock around use of realdlopen and libraryHooks
Threading::CriticalSection libLock;
@@ -52,6 +62,12 @@ DLOPENPROC realdlopen = NULL;
__attribute__ ((visibility ("default")))
void *dlopen(const char *filename, int flag)
{
if(hookInited != HOOK_MAGIC_NUMBER)
{
DLOPENPROC passthru = (DLOPENPROC)dlsym(RTLD_NEXT, "dlopen");
return passthru(filename, flag);
}
SCOPED_LOCK(libLock);
if(realdlopen == NULL) realdlopen = (DLOPENPROC)dlsym(RTLD_NEXT, "dlopen");
+2
View File
@@ -26,6 +26,8 @@
typedef void (*dlopenCallback)(void *realLib);
void LinuxHookInit();
// if this name is dlopen'd, the real library will be passed
// to the callback and librenderdoc.so will be returned to user code
void LinuxHookLibrary(const char *name, dlopenCallback cb);
+2
View File
@@ -26,6 +26,8 @@
#include "hooks/hooks.h"
#include "os/os_specific.h"
void dlopen_hook_init();
void readCapOpts(const char *str, CaptureOptions *opts)
{
// serialise from string with two chars per byte