Skip to content

Commit

Permalink
Merge pull request #133 from nwnk/glx-detection-paranoia
Browse files Browse the repository at this point in the history
Try even harder to not load GLX
  • Loading branch information
ebassi authored Jul 13, 2017
2 parents b157a4d + 7c4817f commit e0426c9
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/dispatch_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,18 @@ epoxy_internal_has_gl_extension(const char *ext, bool invalid_op_mode)
}
}

void *
epoxy_conservative_glx_dlsym(const char *name, bool exit_if_fails)
{
#ifdef GLVND_GLX_LIB
/* prefer the glvnd library if it exists */
if (!api.glx_handle)
get_dlopen_handle(&api.glx_handle, GLVND_GLX_LIB, false);
#endif

return do_dlsym(&api.glx_handle, GLX_LIB, name, exit_if_fails);
}

/**
* Tests whether the currently bound context is EGL or GLX, trying to
* avoid loading libraries unless necessary.
Expand All @@ -510,14 +522,23 @@ epoxy_current_context_is_glx(void)
#if !PLATFORM_HAS_GLX
return false;
#else
void *sym;

/* If we've been called already, don't load more */
if (!api.egl_handle != !api.glx_handle) {
if (api.glx_handle)
return true;
else if (api.egl_handle)
return false;
}

/* If the application hasn't explicitly called some of our GLX
* or EGL code but has presumably set up a context on its own,
* then we need to figure out how to getprocaddress anyway.
*
* If there's a public GetProcAddress loaded in the
* application's namespace, then use that.
*/
void *sym;

sym = dlsym(NULL, "glXGetCurrentContext");
if (sym) {
Expand All @@ -541,7 +562,7 @@ epoxy_current_context_is_glx(void)
* Presumably they dlopened with RTLD_LOCAL, which hides it
* from us. Just go dlopen()ing likely libraries and try them.
*/
sym = do_dlsym(&api.glx_handle, GLX_LIB, "glXGetCurrentContext", false);
sym = epoxy_conservative_glx_dlsym("glXGetCurrentContext", false);
if (sym && glXGetCurrentContext())
return true;

Expand Down Expand Up @@ -594,16 +615,6 @@ epoxy_egl_dlsym(const char *name)
return epoxy_conservative_egl_dlsym(name, true);
}

void *
epoxy_conservative_glx_dlsym(const char *name, bool exit_if_fails)
{
/* prefer the glvnd library if it exists */
if (!api.glx_handle)
get_dlopen_handle(&api.glx_handle, GLVND_GLX_LIB, false);

return do_dlsym(&api.glx_handle, GLX_LIB, name, exit_if_fails);
}

void *
epoxy_glx_dlsym(const char *name)
{
Expand Down

0 comments on commit e0426c9

Please sign in to comment.