X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=glaze.c;h=72070256fb4365d6874ba58a3d28f94495c5f9e9;hb=f2c5ebbfe53ee598aa2b354f0e013aba3a10fffc;hp=0c2eada8d458ea1ca672a1e9a90df365032909ce;hpb=adf4faac47e4136b879913b6ae9e2018de64af93;p=glaze diff --git a/glaze.c b/glaze.c index 0c2eada..7207025 100644 --- a/glaze.c +++ b/glaze.c @@ -22,81 +22,42 @@ #define _GNU_SOURCE #include +#include "glaze.h" + #include #include -void *libgl_handle; -void *wrapper_handle; - -static void -open_libgl_handle (void) +void * +glaze_lookup (char *function) { - const char *path; - - if (libgl_handle) - return; - - path = getenv ("GLAZE_LIBGL"); - if (path == NULL) { - fprintf (stderr, "GLAZE_LIBGL unset. Please set to path of real libGL.so under glaze.\n"); - exit (1); - } + static void *libgl_handle = NULL; + void *ret; - libgl_handle = dlopen (path, RTLD_LAZY | RTLD_GLOBAL); if (libgl_handle == NULL) { - fprintf (stderr, "Error: Failed to dlopen %s\n", path); - exit (1); + const char *path; + + path = getenv ("GLAZE_LIBGL"); + if (path == NULL) { + fprintf (stderr, "GLAZE_LIBGL unset. " + "Please set to path of libGL.so under glaze.\n" + ); + exit (1); + } + + libgl_handle = dlopen (path, RTLD_LAZY | RTLD_GLOBAL); + if (libgl_handle == NULL) { + fprintf (stderr, "Error: Failed to dlopen %s\n", path); + exit (1); + } } -} - -static void -open_wrapper_handle (void) -{ - const char *path; - if (wrapper_handle) - return; + ret = dlsym (libgl_handle, function); - path = getenv ("GLAZE_WRAPPER"); - if (path == NULL) { - fprintf (stderr, "GLAZE_WRAPPER unset. Please set to path of real libGL.so under glaze.\n"); + if (ret == NULL) { + fprintf (stderr, "Error: glaze_lookup failed to dlsym %s\n", + function); exit (1); } - wrapper_handle = dlopen (path, RTLD_LAZY); - if (wrapper_handle == NULL) { - fprintf (stderr, "Error: Failed to dlopen %s\n", path); - exit (1); - } + return ret; } - -static void -glaze_init (void) __attribute__((constructor)); - -static void -glaze_init (void) -{ - open_libgl_handle (); - open_wrapper_handle (); -} - -static void * -resolve (const char *name) -{ - void *symbol; - - /* The wrapper gets first choice on all symbols. */ - symbol = dlsym (wrapper_handle, name); - if (symbol) - return symbol; - - return dlsym (libgl_handle, name); -} - -#define GLAZE_API(name) \ -void * name() __attribute__((ifunc(#name "_resolver"))); \ -static void * \ -name ## _resolver (void) { return resolve (#name); } - -#include "specs/gl.def" -#include "specs/glx.def"