diff options
author | Adam Jackson <ajax@redhat.com> | 2018-04-09 16:10:52 -0400 |
---|---|---|
committer | Adam Jackson <ajax@redhat.com> | 2018-04-30 15:38:01 -0400 |
commit | a33623dca7cc430a9edecdc44f1c76bfb251d576 (patch) | |
tree | edc9f5aa84ba70fb061de47621559be6c6ce60f3 | |
parent | b5a4b16799a30cb74db1916d52f2756a7a5345ed (diff) | |
download | libepoxy-a33623dca7cc430a9edecdc44f1c76bfb251d576.tar.gz |
dispatch: Be even gentler about probing for GLX
dlsym(NULL) can only see (symbols in) libraries that are loaded
RTLD_GLOBAL, but our dlopen()s are RTLD_LOCAL and probably so was the
one the app did if it did one. So use RTLD_NOLOAD to probe for the
library even if it's LOCAL, iff the lookup is non-fatal.
Having done that, don't ever load any libraries on this path. We only
perform this check while resolving rendering API functions, and the
window system resolution paths already load the appropriate library if
they need to. Since you have to have gone through a winsys to get a
context, and our resolvers only run when a function is _called_, this
would only introduce a failure mode if you tried to call a function
without a context bound.
Signed-off-by: Adam Jackson <ajax@redhat.com>
-rw-r--r-- | src/dispatch_common.c | 41 |
1 files changed, 7 insertions, 34 deletions
diff --git a/src/dispatch_common.c b/src/dispatch_common.c index bf10d52..244938b 100644 --- a/src/dispatch_common.c +++ b/src/dispatch_common.c @@ -305,7 +305,11 @@ get_dlopen_handle(void **handle, const char *lib_name, bool exit_on_fail) #else pthread_mutex_lock(&api.mutex); if (!*handle) { - *handle = dlopen(lib_name, RTLD_LAZY | RTLD_LOCAL); + int flags = RTLD_LAZY | RTLD_LOCAL; + if (!exit_on_fail) + flags |= RTLD_NOLOAD; + + *handle = dlopen(lib_name, flags); if (!*handle) { if (exit_on_fail) { fprintf(stderr, "Couldn't open %s: %s\n", lib_name, dlerror()); @@ -572,23 +576,7 @@ epoxy_current_context_is_glx(void) #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. - */ - - sym = dlsym(NULL, "glXGetCurrentContext"); + sym = epoxy_conservative_glx_dlsym("glXGetCurrentContext", false); if (sym) { if (glXGetCurrentContext()) return true; @@ -597,7 +585,7 @@ epoxy_current_context_is_glx(void) } #if PLATFORM_HAS_EGL - sym = dlsym(NULL, "eglGetCurrentContext"); + sym = epoxy_conservative_egl_dlsym("eglGetCurrentContext", false); if (sym) { if (epoxy_egl_get_current_gl_context_api() != EGL_NONE) return false; @@ -606,21 +594,6 @@ epoxy_current_context_is_glx(void) } #endif /* PLATFORM_HAS_EGL */ - /* OK, couldn't find anything in the app's address space. - * Presumably they dlopened with RTLD_LOCAL, which hides it - * from us. Just go dlopen()ing likely libraries and try them. - */ - sym = epoxy_conservative_glx_dlsym("glXGetCurrentContext", false); - if (sym && glXGetCurrentContext()) - return true; - -#if PLATFORM_HAS_EGL - sym = do_dlsym(&api.egl_handle, EGL_LIB, "eglGetCurrentContext", - false); - if (sym && epoxy_egl_get_current_gl_context_api() != EGL_NONE) - return false; -#endif /* PLATFORM_HAS_EGL */ - return false; #endif /* PLATFORM_HAS_GLX */ } |