33
33
#include < android-base/errors.h>
34
34
#endif
35
35
36
+ #include " DlHelp.h"
36
37
#include " JniConstants.h"
37
38
38
39
namespace {
@@ -65,43 +66,6 @@ int GetLibrarySystemProperty(char* buffer) {
65
66
#define FUNC_POINTER void *
66
67
#endif
67
68
68
- void * OpenLibrary (const char * filename) {
69
- #ifdef _WIN32
70
- return LoadLibrary (filename);
71
- #else
72
- // Load with RTLD_NODELETE in order to ensure that libart.so is not unmapped when it is closed.
73
- // This is due to the fact that it is possible that some threads might have yet to finish
74
- // exiting even after JNI_DeleteJavaVM returns, which can lead to segfaults if the library is
75
- // unloaded.
76
- const int kDlopenFlags = RTLD_NOW | RTLD_NODELETE;
77
- return dlopen (filename, kDlopenFlags );
78
- #endif
79
- }
80
-
81
- int CloseLibrary (void * handle) {
82
- #ifdef _WIN32
83
- return FreeLibrary (static_cast <HMODULE>(handle));
84
- #else
85
- return dlclose (handle);
86
- #endif
87
- }
88
-
89
- FUNC_POINTER GetSymbol (void * handle, const char * symbol) {
90
- #ifdef _WIN32
91
- return GetProcAddress (static_cast <HMODULE>(handle), symbol);
92
- #else
93
- return dlsym (handle, symbol);
94
- #endif
95
- }
96
-
97
- std::string GetError () {
98
- #ifdef _WIN32
99
- return android::base::SystemErrorCodeToString (GetLastError ());
100
- #else
101
- return std::string (dlerror ());
102
- #endif
103
- }
104
-
105
69
} // namespace
106
70
107
71
struct JniInvocationImpl final {
@@ -158,7 +122,7 @@ JniInvocationImpl::JniInvocationImpl() :
158
122
JniInvocationImpl::~JniInvocationImpl () {
159
123
jni_invocation_ = NULL ;
160
124
if (handle_ != NULL ) {
161
- CloseLibrary (handle_);
125
+ DlCloseLibrary (handle_);
162
126
}
163
127
}
164
128
@@ -213,11 +177,11 @@ bool JniInvocationImpl::Init(const char* library) {
213
177
char * buffer = NULL ;
214
178
#endif
215
179
library = GetLibrary (library, buffer);
216
- handle_ = OpenLibrary (library);
180
+ handle_ = DlOpenLibrary (library);
217
181
if (handle_ == NULL ) {
218
182
if (strcmp (library, kLibraryFallback ) == 0 ) {
219
183
// Nothing else to try.
220
- ALOGE (" Failed to dlopen %s: %s" , library, GetError (). c_str ());
184
+ ALOGE (" Failed to dlopen %s: %s" , library, DlGetError ());
221
185
return false ;
222
186
}
223
187
// Note that this is enough to get something like the zygote
@@ -226,11 +190,11 @@ bool JniInvocationImpl::Init(const char* library) {
226
190
// RuntimeInit.commonInit for where we fix up the property to
227
191
// avoid future fallbacks. http://b/11463182
228
192
ALOGW (" Falling back from %s to %s after dlopen error: %s" ,
229
- library, kLibraryFallback , GetError (). c_str ());
193
+ library, kLibraryFallback , DlGetError ());
230
194
library = kLibraryFallback ;
231
- handle_ = OpenLibrary (library);
195
+ handle_ = DlOpenLibrary (library);
232
196
if (handle_ == NULL ) {
233
- ALOGE (" Failed to dlopen %s: %s" , library, GetError (). c_str ());
197
+ ALOGE (" Failed to dlopen %s: %s" , library, DlGetError ());
234
198
return false ;
235
199
}
236
200
}
@@ -262,10 +226,10 @@ jint JniInvocationImpl::JNI_GetCreatedJavaVMs(JavaVM** vms, jsize size, jsize* v
262
226
}
263
227
264
228
bool JniInvocationImpl::FindSymbol (FUNC_POINTER* pointer, const char * symbol) {
265
- *pointer = GetSymbol ( handle_, symbol);
229
+ *pointer = reinterpret_cast <FUNC_POINTER>( DlGetSymbol ( handle_, symbol) );
266
230
if (*pointer == NULL ) {
267
- ALOGE (" Failed to find symbol %s: %s\n " , symbol, GetError (). c_str ());
268
- CloseLibrary (handle_);
231
+ ALOGE (" Failed to find symbol %s: %s\n " , symbol, DlGetError ());
232
+ DlCloseLibrary (handle_);
269
233
handle_ = NULL ;
270
234
return false ;
271
235
}
0 commit comments