summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2011-09-14 07:44:09 +0000
committerVincent Torri <vincent.torri@gmail.com>2011-09-14 07:44:09 +0000
commit585938123d122a24107d358195b8e31f7e472d95 (patch)
tree2f8cde98bd4b954ab9821c481015d017f2905e92 /legacy
parent61b786c4e8b95a33e6c8dd1bca661a646bf0dd94 (diff)
Evil: add RTLD_DEFAULT support for dlsym()
SVN revision: 63373
Diffstat (limited to 'legacy')
-rw-r--r--legacy/evil/ChangeLog5
-rw-r--r--legacy/evil/src/lib/dlfcn/Makefile.am4
-rw-r--r--legacy/evil/src/lib/dlfcn/dlfcn.c45
-rw-r--r--legacy/evil/src/lib/dlfcn/dlfcn.h6
-rw-r--r--legacy/evil/src/lib/evil_util.c4
5 files changed, 51 insertions, 13 deletions
diff --git a/legacy/evil/ChangeLog b/legacy/evil/ChangeLog
index f6ebdd5593..4dce120be6 100644
--- a/legacy/evil/ChangeLog
+++ b/legacy/evil/ChangeLog
@@ -1,3 +1,8 @@
12011-09-14 Vincent Torri <doursse at users dot sf dot net>
2
3 * src/lib/dlfcn/dlfcn.c:
4 add RTLD_DEFAULT support in dlsym()
5
12011-05-19 Vincent Torri <doursse at users dot sf dot net> 62011-05-19 Vincent Torri <doursse at users dot sf dot net>
2 7
3 * src/lib/dlfcn/dlfcn.c: 8 * src/lib/dlfcn/dlfcn.c:
diff --git a/legacy/evil/src/lib/dlfcn/Makefile.am b/legacy/evil/src/lib/dlfcn/Makefile.am
index bb9580ca83..cfb35a6663 100644
--- a/legacy/evil/src/lib/dlfcn/Makefile.am
+++ b/legacy/evil/src/lib/dlfcn/Makefile.am
@@ -9,7 +9,7 @@ dist_stdheaders_DATA = dlfcn.h
9 9
10libdl_la_SOURCES = dlfcn.c 10libdl_la_SOURCES = dlfcn.c
11 11
12libdl_la_CPPFLAGS = -DEFL_EVIL_DLFCN_BUILD 12libdl_la_CPPFLAGS = @win32_cppflags@ -DEFL_EVIL_DLFCN_BUILD -DPSAPI_VERSION=1
13libdl_la_CFLAGS = @win32_cflags@ 13libdl_la_CFLAGS = @win32_cflags@
14libdl_la_LIBADD = $(top_builddir)/src/lib/libevil.la $(EFL_MPATROL_LIBS) 14libdl_la_LIBADD = $(top_builddir)/src/lib/libevil.la $(EFL_MPATROL_LIBS) -lpsapi
15libdl_la_LDFLAGS = -no-undefined -Wl,--enable-auto-import -version-info @version_info@ 15libdl_la_LDFLAGS = -no-undefined -Wl,--enable-auto-import -version-info @version_info@
diff --git a/legacy/evil/src/lib/dlfcn/dlfcn.c b/legacy/evil/src/lib/dlfcn/dlfcn.c
index 782d61c6a2..4edefaf9d2 100644
--- a/legacy/evil/src/lib/dlfcn/dlfcn.c
+++ b/legacy/evil/src/lib/dlfcn/dlfcn.c
@@ -8,6 +8,9 @@
8# include <limits.h> 8# include <limits.h>
9#endif /* __MINGW32CE__ || _MSC_VER */ 9#endif /* __MINGW32CE__ || _MSC_VER */
10 10
11#include <windows.h>
12#include <psapi.h> /* EnumProcessModules(Ex) */
13
11#include "../Evil.h" 14#include "../Evil.h"
12 15
13#include "dlfcn.h" 16#include "dlfcn.h"
@@ -115,19 +118,41 @@ dlclose(void* handle)
115void * 118void *
116dlsym(void *handle, const char *symbol) 119dlsym(void *handle, const char *symbol)
117{ 120{
118 FARPROC fp; 121 FARPROC fp = NULL;
122 LPCTSTR new_symbol;
119 123
120#ifdef UNICODE 124 if (!symbol || !*symbol) return NULL;
121 {
122 wchar_t *wsymbol;
123 125
124 wsymbol = evil_char_to_wchar(symbol); 126#ifdef UNICODE
125 fp = GetProcAddress(handle, wsymbol); 127 new_symbol = evil_char_to_wchar(symbol);
126 free(wsymbol);
127 }
128#else 128#else
129 fp = GetProcAddress(handle, symbol); 129 new_symbol = symbol;
130#endif /* ! UNICODE */ 130#endif /* UNICODE */
131
132 if (handle == RTLD_DEFAULT)
133 {
134 HMODULE modules[1024];
135 DWORD needed;
136 DWORD i;
137
138 /* TODO: use EnumProcessModulesEx() on Windows >= Vista */
139 if (!EnumProcessModules(GetCurrentProcess(),
140 modules, sizeof(modules), &needed))
141 return NULL;
142
143 for (i = 0; i < (needed / sizeof(HMODULE)); i++)
144 {
145 fp = GetProcAddress(modules[i], new_symbol);
146 if (fp) break;
147 }
148 }
149 else
150 fp = GetProcAddress(handle, new_symbol);
151
152#ifdef UNICODE
153 free(new_symbol);
154#endif /* UNICODE */
155
131 if (!fp) 156 if (!fp)
132 get_last_error("GetProcAddress returned: "); 157 get_last_error("GetProcAddress returned: ");
133 158
diff --git a/legacy/evil/src/lib/dlfcn/dlfcn.h b/legacy/evil/src/lib/dlfcn/dlfcn.h
index b388b4fcde..655dade6ad 100644
--- a/legacy/evil/src/lib/dlfcn/dlfcn.h
+++ b/legacy/evil/src/lib/dlfcn/dlfcn.h
@@ -59,12 +59,18 @@ extern "C" {
59 * Symbols in this dlopen'ed obj are visible to other dlopen'ed objs 59 * Symbols in this dlopen'ed obj are visible to other dlopen'ed objs
60 */ 60 */
61 61
62/**
63 * @def RTLD_DEFAULT
64 * Symbols are searched in all the DLL opened by the current process
65 */
66
62# define RTLD_LAZY 0x00001 /* lazy function call binding */ 67# define RTLD_LAZY 0x00001 /* lazy function call binding */
63# define RTLD_NOW 0x00002 /* immediate function call binding */ 68# define RTLD_NOW 0x00002 /* immediate function call binding */
64# define RTLD_GLOBAL 0x00100 /* symbols in this dlopen'ed obj are visible 69# define RTLD_GLOBAL 0x00100 /* symbols in this dlopen'ed obj are visible
65 to other dlopen'ed objs */ 70 to other dlopen'ed objs */
66#define RTLD_NODELETE 0x01000 /* do not delete object when closed. */ 71#define RTLD_NODELETE 0x01000 /* do not delete object when closed. */
67 72
73#define RTLD_DEFAULT ((void*)1) /* search the symbol on all the DLL of the current process */
68 74
69/** 75/**
70 * @typedef Dl_info 76 * @typedef Dl_info
diff --git a/legacy/evil/src/lib/evil_util.c b/legacy/evil/src/lib/evil_util.c
index af410010c2..30f52ac997 100644
--- a/legacy/evil/src/lib/evil_util.c
+++ b/legacy/evil/src/lib/evil_util.c
@@ -81,7 +81,7 @@ evil_format_message(long err)
81#ifdef UNICODE 81#ifdef UNICODE
82 str = evil_wchar_to_char(msg); 82 str = evil_wchar_to_char(msg);
83#else 83#else
84 str = strdup(msg); 84 str = msg;
85#endif /* UNICODE */ 85#endif /* UNICODE */
86 86
87 LocalFree(msg); 87 LocalFree(msg);
@@ -93,7 +93,9 @@ evil_format_message(long err)
93 snprintf(disp, strlen(str) + strlen("(00000) ") + 1, 93 snprintf(disp, strlen(str) + strlen("(00000) ") + 1,
94 "(%5ld) %s", err, str); 94 "(%5ld) %s", err, str);
95 95
96#ifdef UNICODE
96 free(str); 97 free(str);
98#endif /* UNICODE */
97 99
98 return disp; 100 return disp;
99} 101}