Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorvald Natvig <slicer@users.sourceforge.net>2007-07-13 18:15:25 +0400
committerThorvald Natvig <slicer@users.sourceforge.net>2007-07-13 18:15:25 +0400
commit40ca34fa288bd4f484636468c071705b1ae68460 (patch)
tree8bde2b7958ff3f3b956a48f734ce4a7d0d1023a0 /overlay_gl
parent12416a48592df4ee36fceb6de89ae02315ba0220 (diff)
More stable LD_PRELOAD for GL overlay
git-svn-id: https://mumble.svn.sourceforge.net/svnroot/mumble/trunk@587 05730e5d-ab1b-0410-a4ac-84af385074fa
Diffstat (limited to 'overlay_gl')
-rw-r--r--overlay_gl/Makefile2
-rw-r--r--overlay_gl/overlay.c43
2 files changed, 30 insertions, 15 deletions
diff --git a/overlay_gl/Makefile b/overlay_gl/Makefile
index 6d7de905a..7690d9a51 100644
--- a/overlay_gl/Makefile
+++ b/overlay_gl/Makefile
@@ -24,7 +24,7 @@ libGL.so.1: overlay.o libGL.link.so.1
strip $@
libmumble.so.1: overlay_p.o
- $(CXX) -shared -Wl,-soname,$@ -o $@ $^ -lrt
+ $(CXX) -shared -Wl,-soname,$@ -o $@ $^ -lrt -ldl
strip $@
clean:
diff --git a/overlay_gl/overlay.c b/overlay_gl/overlay.c
index 1273cb699..ab1cdc704 100644
--- a/overlay_gl/overlay.c
+++ b/overlay_gl/overlay.c
@@ -74,15 +74,13 @@ static Context *contexts = NULL;
#define FDEF(name) static __typeof__(&name) o##name = NULL
-#ifdef PRELOAD
FDEF(dlsym);
-#endif
FDEF(glXSwapBuffers);
FDEF(glXGetProcAddressARB);
FDEF(glXGetProcAddress);
-#define RESOLVE(x) if (! o##x) o##x = (__typeof__(&x)) dlsym(RTLD_NEXT, #x)
+#define RESOLVE(x) if (! o##x) o##x = (__typeof__(&x)) odlsym(RTLD_NEXT, #x)
static void resolveOpenGL()
{
@@ -387,7 +385,7 @@ void (*glXGetProcAddress(const GLubyte * func)) (void)
else if (oglXGetProcAddressARB)
return oglXGetProcAddressARB(func);
else
- return (__GLXextFuncPtr) (dlsym(RTLD_NEXT, (const char *) (func)));
+ return (__GLXextFuncPtr) (odlsym(RTLD_NEXT, (const char *) (func)));
}
__attribute__ ((visibility("default")))
@@ -396,29 +394,46 @@ __GLXextFuncPtr glXGetProcAddressARB(const GLubyte * func)
return (void (*)(void)) glXGetProcAddress(func);
}
-#ifdef PRELOAD
+__attribute__ ((constructor))
+void initializeLibrary() {
+ if (odlsym)
+ return;
-#define OGRAB(name) if (handle == RTLD_DEFAULT) handle = RTLD_NEXT; __typeof__(&name) t = (__typeof__(&name)) (__typeof__(&name))(odlsym(handle, #name)); if (t) { o##name = t; return (void *)(name); } else { return NULL;}
-
-__attribute__ ((visibility("default")))
-void *dlsym(void *handle, const char *name)
-{
- if (!odlsym) {
+#ifdef PRELOAD
+ printf("Library is HOT\n");
void *dl = dlopen("libdl.so.2", RTLD_LAZY);
if (!dl) {
ods("Failed to open libdl.so.2\n");
} else {
odlsym = (__typeof__(&dlsym)) __libc_dlsym(dl, "dlsym");
}
- }
+#else
+ odlsym = &dlsym;
+#endif
+}
+
+#ifdef PRELOAD
+#define OGRAB(name) if (handle == RTLD_DEFAULT) handle = RTLD_NEXT; symbol = odlsym(handle, #name); if (symbol) { o##name = (__typeof__(&name)) symbol; symbol = (void *) name;}
+__attribute__ ((visibility("default")))
+void *dlsym(void *handle, const char *name)
+{
+ if (! odlsym)
+ initializeLibrary();
+
+ void *symbol;
+
+ printf("Request for symbol %s (%p)\n", name, odlsym);
+
if (strcmp(name, "glXSwapBuffers") == 0) {
OGRAB(glXSwapBuffers);
} else if (strcmp(name, "glXGetProcAddress") == 0) {
OGRAB(glXGetProcAddress);
} else if (strcmp(name, "glXGetProcAddressARB") == 0) {
OGRAB(glXGetProcAddressARB);
+ } else {
+ symbol = odlsym(handle, name);
}
- return odlsym(handle, name);
+ printf("Returning %p\n", symbol);
+ return symbol;
}
-
#endif