Browse Source

Fixed problem with dlsym lookup. This resolve bug 2477.

Partially inspired by posts at
https://stackoverflow.com/questions/15599026/how-can-i-intercept-dlsym-calls-using-ld-preload

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Michele Calgaro 8 months ago
parent
commit
af8244e3e0
2 changed files with 44 additions and 51 deletions
  1. 25
    38
      gtk2/kgtk2.c
  2. 19
    13
      tqt/kqt3.cpp

+ 25
- 38
gtk2/kgtk2.c View File

@@ -67,10 +67,6 @@ TODO
67 67
 #include "connect.h"
68 68
 #include "config.h"
69 69
 
70
-#ifndef KGTK_DLSYM_VERSION
71
-#define KGTK_DLSYM_VERSION "GLIBC_2.0"
72
-#endif
73
-
74 70
 #define BLACKLIST_UNKNOWN_GTK_APPS 0
75 71
 
76 72
 /*
@@ -78,15 +74,10 @@ TODO
78 74
 */
79 75
 
80 76
 /*
81
- * For SWT apps (e.g. eclipse) we need to override dlsym, but we can only do this if
82
- * dlvsym is present in libdl. dlvsym is needed so that we can access the real dlsym
83
- * as well as our fake dlsym
77
+ * For SWT apps (e.g. eclipse) we need to override dlsym.
84 78
  */
85
-#ifdef HAVE_DLVSYM
79
+extern void *_dl_sym(void *, const char *, void *);
86 80
 static void * real_dlsym (void *handle, const char *name);
87
-#else
88
-#define real_dlsym(A, B) dlsym(A, B)
89
-#endif
90 81
 
91 82
 typedef enum
92 83
 {
@@ -2241,41 +2232,38 @@ void * PR_FindFunctionSymbol(struct PR_LoadLibrary *lib, const char *raw_name)
2241 2232
         return NULL;
2242 2233
 }
2243 2234
 
2244
-#ifdef HAVE_DLVSYM
2245 2235
 /* Overriding dlsym is required for SWT - which dlsym's the gtk_file_chooser functions! */
2246 2236
 static void * real_dlsym(void *handle, const char *name)
2247 2237
 {
2248
-    static void * (*realFunction)() = NULL;
2249
-
2250
-#ifdef KGTK_DEBUG_DLSYM
2251
-    printf("KGTK::real_dlsym : %s\n", name);
2252
-#endif
2253
-
2254
-    if (!realFunction)
2255
-    {
2256
-        void *ldHandle=dlopen("libdl.so", RTLD_NOW);
2238
+	static void * (*realFunction)() = NULL;
2257 2239
 
2258 2240
 #ifdef KGTK_DEBUG_DLSYM
2259
-        printf("KGTK::real_dlsym : %s\n", name);
2260
-#endif
2261
-
2262
-        if(ldHandle)
2263
-        {
2264
-            static const char * versions[]={KGTK_DLSYM_VERSION, "GLIBC_2.3", "GLIBC_2.2.5",
2265
-                                            "GLIBC_2.2", "GLIBC_2.1", "GLIBC_2.0", NULL};
2266
-
2267
-            int i;
2268
-
2269
-            for(i=0; versions[i] && !realFunction; ++i)
2270
-                realFunction=dlvsym(ldHandle, "dlsym", versions[i]);
2271
-        }
2272
-    }
2273
-
2274
-    return realFunction(handle, name);
2241
+	printf("KGTK::real_dlsym : %s\n", name);
2242
+#endif
2243
+
2244
+	if (!realFunction)
2245
+	{
2246
+		// Get the real dlsym function
2247
+		realFunction = _dl_sym(RTLD_NEXT, "dlsym", dlsym);
2248
+	}
2249
+
2250
+	if (realFunction)
2251
+		return realFunction(handle, name);
2252
+	else
2253
+	{
2254
+		printf("kgtk-qt3 gtk2 real_dlsymc() realFunction not found!!\n");
2255
+		return NULL;
2256
+	}
2275 2257
 }
2276 2258
 
2277 2259
 void * dlsym(void *handle, const char *name)
2278 2260
 {
2261
+		// Need this so _dl_sym will be able to find the next dlsym, i.e. the real dlsym!
2262
+		if (!strcmp(name, "dlsym"))
2263
+		{
2264
+			return (void*)dlsym;
2265
+		}
2266
+
2279 2267
     void *rv=NULL;
2280 2268
 
2281 2269
 #ifdef KGTK_DEBUG_DLSYM
@@ -2294,4 +2282,3 @@ void * dlsym(void *handle, const char *name)
2294 2282
 #endif
2295 2283
     return rv;
2296 2284
 }
2297
-#endif

+ 19
- 13
tqt/kqt3.cpp View File

@@ -120,19 +120,25 @@ static const char * getAppName(bool useTQt=true)
120 120
 
121 121
 int TQApplication::exec()
122 122
 {
123
-    static bool init=false;
124
-
125
-    if(!init)
126
-    {
127
-        connectToKDialogD(getAppName(false));
128
-        init=true;
129
-    }
130
-
131
-    static int (*realFunction)(void *);
132
-
133
-    if(!realFunction)
134
-        realFunction = (int (*)(void *)) dlsym(RTLD_NEXT, KQT_QAPPLICATION_EXEC);
135
-    return (int)realFunction(this);
123
+	static bool init=false;
124
+
125
+	if(!init)
126
+	{
127
+		connectToKDialogD(getAppName(false));
128
+		init=true;
129
+	}
130
+
131
+	static int (*realFunction)(void *);
132
+
133
+	if(!realFunction)
134
+		realFunction = (int (*)(void *)) dlsym(RTLD_NEXT, KQT_QAPPLICATION_EXEC);
135
+	if (realFunction)
136
+		return (int)realFunction(this);
137
+	else
138
+	{
139
+		tqWarning("kgtk-qt3 tqt TQApplication::exec() realFunction not found!!");
140
+		return 255;
141
+	}
136 142
 };
137 143
 
138 144
 static TQString qt2KdeFilter(const TQString &f)

Loading…
Cancel
Save