The previous implementation of android_dlwarning was not thread-safe
and could return a pointer soon to become invalid in some situations.
This change fixed the problem. I have also removed android_dlwarning
from the dlext.h header file in case we decide to keep
android_dlwarning in the final release.
Bug: http://b/
27453994
Change-Id: If6c896a80a17c4be0e18795e617712ad36a106fe
uint64_t type,
const char* permitted_when_isolated_path);
-const char* android_dlwarning();
-
__END_DECLS
#endif /* __ANDROID_DLEXT_H__ */
return 0;
}
-const char* android_dlwarning(void) { return 0; }
+void android_dlwarning(void* obj, void (*f)(void*, const char*)) { f(obj, 0); }
return get_application_target_sdk_version();
}
-const char* android_dlwarning() {
+void android_dlwarning(void* obj, void (*f)(void*, const char*)) {
ScopedPthreadMutexLocker locker(&g_dl_mutex);
- return get_dlwarning();
+ get_dlwarning(obj, f);
}
bool android_init_namespaces(const char* public_ns_sonames,
#include <string>
static std::string current_msg;
-static std::string old_msg;
void add_dlwarning(const char* sopath, const char* message, const char* value) {
if (!current_msg.empty()) {
// Resets the current one (like dlerror but instead of
// being thread-local it is process-local).
-const char* get_dlwarning() {
+void get_dlwarning(void* obj, void (*f)(void*, const char*)) {
if (current_msg.empty()) {
- return nullptr;
+ f(obj, nullptr);
+ } else {
+ std::string msg = current_msg;
+ current_msg.clear();
+ f(obj, msg.c_str());
}
-
- old_msg = current_msg;
- current_msg.clear();
-
- return old_msg.c_str();
}
void add_dlwarning(const char* sopath, const char* message, const char* value = nullptr);
// Resets the current one (like dlerror but instead of
-// being thread-local it is process-local).
-const char* get_dlwarning();
+// being thread-local it is process-local). The user_data
+// is used to avoid forcing user into saving the message
+// to a global variable.
+void get_dlwarning(void* user_data, void (*f)(void*, const char*));
#endif /* __LINKER_DLWARNING_H */