]> git.cworth.org Git - glfps/commitdiff
Switch to Glaze to implement glfps
authorCarl Worth <cworth@cworth.org>
Mon, 23 Sep 2013 14:08:38 +0000 (07:08 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 23 Sep 2013 15:23:32 +0000 (08:23 -0700)
With Glaze, things are comparably as easy as using LD_PRELOAD, yet we
still get the robustness of working with applications using dlsym or
GetProcAddress, (as well as the robustness of having a real libGL.so
for the application to use rather than an LD_PRELOAD which can confuse
some applications).

Makefile
glfps-test
glfps.c

index 5ebf41bd149e130ae4a437d58a1cb5ad725ec5cf..52feeb257a5fc3dd524de55e6b1e892830671764 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,15 +1,17 @@
 CC ?= gcc
 CFLAGS ?= -g -Wall -Wextra -Wmissing-declarations
+GLAZE_FLAGS = $(shell pkg-config --cflags --libs glaze)
+GLAZE_32_FLAGS = $(shell pkg-config --cflags --libs glaze-32)
 
 TARGETS=libglfps.so libglfps-32.so
 
 all: $(TARGETS)
 
 libglfps.so: glfps.c
-       $(CC) $(CFLAGS) -fPIC -shared -Wl,-Bsymbolic -o $@ $<
+       $(CC) $(CFLAGS) $(GLAZE_FLAGS) -fPIC -shared -Wl,-Bsymbolic -o $@ $<
 
 libglfps-32.so: glfps.c
-       $(CC) $(CFLAGS) -m32 -fPIC -shared -Wl,-Bsymbolic -o $@ $<
+       $(CC) $(CFLAGS) $(GLAZE_32_FLAGS) -m32 -fPIC -shared -Wl,-Bsymbolic -o $@ $<
 
 clean:
        rm -f $(TARGETS)
index f424686a0b7ecf903109bb3b8321a9887ad42e50..30600c6689bbbf678623c3530fa902579600e720 100755 (executable)
@@ -17,7 +17,7 @@ test ()
 
     tests=$((tests + 1))
 
-    if ${FIPS_TEST_DIR}/${script} | grep -q "^glfps"; then
+    if glaze --wrapper=libglfps.so ${FIPS_TEST_DIR}/${script} | grep -q "^glfps"; then
        printf "PASS\n"
     else
        printf "FAIL\n"
@@ -29,8 +29,6 @@ echo "Testing glfps with programs using different window-system interfaces to"
 echo "OpenGL, different linking mechanisms, and different symbol-lookup."
 echo ""
 
-export LD_PRELOAD=./libglfps.so
-
 printf "       Window sys.     Link-mode       Lookup\n"
 printf "       -----------     -------------   -----------------\n"
 
diff --git a/glfps.c b/glfps.c
index 6c9cd4988bfb46c055f7fcd8922e72d75f985535..dca09dda5abb3e9a5fdf3e03c106ac25e0e30cbd 100644 (file)
--- a/glfps.c
+++ b/glfps.c
@@ -11,6 +11,8 @@
 #include <sys/time.h>
 #include <string.h>
 
+#include <glaze.h>
+
 /* How many frames between reports. */
 #define REPORT_FREQ 60
 
@@ -36,88 +38,10 @@ on_each_frame (void)
        count++;
 }
 
-static void *do_real_dlsym (void *handle, const char *symbol);
-
-static typeof(&glXSwapBuffers) real_glXSwapBuffers;
-
 void
 glXSwapBuffers (Display *dpy, GLXDrawable drawable)
 {
-       if (real_glXSwapBuffers == NULL)
-               real_glXSwapBuffers = do_real_dlsym (RTLD_NEXT, "glXSwapBuffers");
-
        on_each_frame ();
 
-       real_glXSwapBuffers (dpy, drawable);
-}
-
-static typeof(&glXGetProcAddressARB) real_glXGetProcAddressARB;
-
-void
-(*glXGetProcAddressARB (const GLubyte *func))(void)
-{
-       if (strcmp((char *) func, "glXSwapBuffers") == 0)
-               return (void*) glXSwapBuffers;
-
-       if (real_glXGetProcAddressARB == NULL)
-               real_glXGetProcAddressARB = do_real_dlsym (RTLD_NEXT, "glXGetProcAddressARB");
-
-       return real_glXGetProcAddressARB (func);
-}
-
-static typeof(&glXGetProcAddress) real_glXGetProcAddress;
-
-void
-(*glXGetProcAddress (const GLubyte *func))(void)
-{
-       if (strcmp((char *) func, "glXSwapBuffers") == 0)
-               return (void*) glXSwapBuffers;
-
-       if (real_glXGetProcAddress == NULL)
-               real_glXGetProcAddress = do_real_dlsym (RTLD_NEXT, "glXGetProcAddress");
-
-       return real_glXGetProcAddress (func);
-}
-
-/* We rely on an internal symbol within glibc in order to be able to
- * get a handle on the real dlsym function, (we can't call dlsym to
- * find the address of dlsym itself of course). */
-void * __libc_dlsym(void *, const char *);
-
-static void *
-do_real_dlsym (void *handle, const char *symbol)
-{
-       static typeof(&dlsym) real_dlsym = NULL;
-
-       if (real_dlsym == NULL) {
-               void *libdl_handle = dlopen ("libdl.so.2", RTLD_LAZY);
-               real_dlsym = __libc_dlsym(libdl_handle, "dlsym");
-       }
-
-       return real_dlsym (handle, symbol);
-}
-
-void *
-dlsym (void *handle, const char *symbol)
-{
-       void *ret;
-
-       ret = do_real_dlsym (handle, symbol);
-
-       if (strcmp (symbol, "glXSwapBuffers") == 0) {
-               real_glXSwapBuffers = ret;
-               return &glXSwapBuffers;
-       }
-
-       if (strcmp (symbol, "glXGetProcAddressARB") == 0) {
-               real_glXGetProcAddressARB = ret;
-               return &glXGetProcAddressARB;
-       }
-
-       if (strcmp (symbol, "glXGetProcAddress") == 0) {
-               real_glXGetProcAddress = ret;
-               return &glXGetProcAddress;
-       }
-
-       return ret;
+       GLAZE_DEFER (glXSwapBuffers, dpy, drawable);
 }