--- /dev/null
+/**************************************************************************
+ *
+ * Copyright 2011 Jose Fonseca
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/*
+ * Provides access to real dlopen, as tracing libraries interpose it.
+ */
+
+#ifndef _DLOPEN_HPP_
+#define _DLOPEN_HPP_
+
+#include <dlfcn.h>
+
+#include "os.hpp"
+
+
+/*
+ * Invoke the true dlopen() function.
+ */
+static void *_dlopen(const char *filename, int flag)
+{
+ typedef void * (*PFN_DLOPEN)(const char *, int);
+ static PFN_DLOPEN dlopen_ptr = NULL;
+
+ if (!dlopen_ptr) {
+#ifdef ANDROID
+ /* Android does not have dlopen in libdl.so; instead, the
+ * implementation is available in the dynamic linker itself.
+ * Oddly enough, we still can interpose it, but need to use
+ * RTLD_DEFAULT to get pointer to the original function. */
+ dlopen_ptr = (PFN_DLOPEN)dlsym(RTLD_DEFAULT, "dlopen");
+#else
+ dlopen_ptr = (PFN_DLOPEN)dlsym(RTLD_NEXT, "dlopen");
+#endif
+ if (!dlopen_ptr) {
+ os::log("apitrace: error: failed to look up real dlopen\n");
+ return NULL;
+ }
+ }
+
+ return dlopen_ptr(filename, flag);
+}
+
+#endif /* _DLOPEN_HPP_ */
#if !defined(_WIN32)
-#include <dlfcn.h>
+#include "dlopen.hpp"
#endif
if (procName[0] == 'e' && procName[1] == 'g' && procName[2] == 'l') {
static void *libEGL = NULL;
if (!libEGL) {
- libEGL = dlopen("libEGL.so", RTLD_LOCAL | RTLD_LAZY);
+ libEGL = _dlopen("libEGL.so", RTLD_LOCAL | RTLD_LAZY);
if (!libEGL) {
return NULL;
}
static void *libGLESv2 = NULL;
if (!libGLESv2) {
- libGLESv2 = dlopen("libGLESv2.so", RTLD_LOCAL | RTLD_LAZY);
+ libGLESv2 = _dlopen("libGLESv2.so", RTLD_LOCAL | RTLD_LAZY);
}
if (libGLESv2) {
sym = dlsym(libGLESv2, procName);
static void *libGLESv1 = NULL;
if (!libGLESv1) {
- libGLESv1 = dlopen("libGLESv1_CM.so", RTLD_LOCAL | RTLD_LAZY);
+ libGLESv1 = _dlopen("libGLESv1_CM.so", RTLD_LOCAL | RTLD_LAZY);
}
if (libGLESv1) {
sym = dlsym(libGLESv1, procName);
#if !defined(_WIN32)
#include <unistd.h> // for symlink
-#include <dlfcn.h>
+#include "dlopen.hpp"
#endif
#else
-/*
- * Invoke the true dlopen() function.
- */
-static void *
-_dlopen(const char *filename, int flag)
-{
- typedef void * (*PFNDLOPEN)(const char *, int);
- static PFNDLOPEN dlopen_ptr = NULL;
-
- if (!dlopen_ptr) {
- dlopen_ptr = (PFNDLOPEN)dlsym(RTLD_NEXT, "dlopen");
- if (!dlopen_ptr) {
- os::log("apitrace: error: dlsym(RTLD_NEXT, \"dlopen\") failed\n");
- return NULL;
- }
- }
-
- return dlopen_ptr(filename, flag);
-}
-
-
/*
* Lookup a libGL symbol
*/
if __name__ == '__main__':
print '#include <stdlib.h>'
print '#include <string.h>'
- print '#include <dlfcn.h>'
+ print '#include "dlopen.hpp"'
print
print '#include "trace_writer_local.hpp"'
print
print r'''
-/*
- * Android does not support LD_PRELOAD.
- */
-#if !defined(ANDROID)
-
-
-/*
- * Invoke the true dlopen() function.
- */
-static void *_dlopen(const char *filename, int flag)
-{
- typedef void * (*PFN_DLOPEN)(const char *, int);
- static PFN_DLOPEN dlopen_ptr = NULL;
-
- if (!dlopen_ptr) {
- dlopen_ptr = (PFN_DLOPEN)dlsym(RTLD_NEXT, "dlopen");
- if (!dlopen_ptr) {
- os::log("apitrace: error: dlsym(RTLD_NEXT, \"dlopen\") failed\n");
- return NULL;
- }
- }
-
- return dlopen_ptr(filename, flag);
-}
-
/*
* Several applications, such as Quake3, use dlopen("libGL.so.1"), but
{
bool intercept = false;
- if (filename) {
+ if (filename && trace::isTracingEnabled()) {
intercept =
strcmp(filename, "libEGL.so") == 0 ||
strcmp(filename, "libEGL.so.1") == 0 ||
}
-#endif /* !ANDROID */
-
-
#if defined(ANDROID)
/*