X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=glaze.c;h=0c2eada8d458ea1ca672a1e9a90df365032909ce;hb=a60d550273984e5a553338c410eea587eff22bc2;hp=5ad3af33a59301cb6e4da0857948fd3e49962624;hpb=75d3372ac4784383f6cdc8b5260098f81f8b2751;p=glaze diff --git a/glaze.c b/glaze.c index 5ad3af3..0c2eada 100644 --- a/glaze.c +++ b/glaze.c @@ -26,6 +26,7 @@ #include void *libgl_handle; +void *wrapper_handle; static void open_libgl_handle (void) @@ -48,6 +49,27 @@ open_libgl_handle (void) } } +static void +open_wrapper_handle (void) +{ + const char *path; + + if (wrapper_handle) + return; + + path = getenv ("GLAZE_WRAPPER"); + if (path == NULL) { + fprintf (stderr, "GLAZE_WRAPPER unset. Please set to path of real libGL.so under glaze.\n"); + exit (1); + } + + wrapper_handle = dlopen (path, RTLD_LAZY); + if (wrapper_handle == NULL) { + fprintf (stderr, "Error: Failed to dlopen %s\n", path); + exit (1); + } +} + static void glaze_init (void) __attribute__((constructor)); @@ -55,11 +77,19 @@ 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); } @@ -68,4 +98,5 @@ void * name() __attribute__((ifunc(#name "_resolver"))); \ static void * \ name ## _resolver (void) { return resolve (#name); } -#include "glapi.def" +#include "specs/gl.def" +#include "specs/glx.def"