diff options
author | Dimitry Ivanov <dimitry@google.com> | 2018-09-12 17:49:36 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-09-12 17:49:36 +0000 |
commit | 6590255dbbcbd35c527b3a2e6871275ec88fee64 (patch) | |
tree | 8cc60a310225069b30e153901cb391c8bcb67e08 | |
parent | dc78882bd1f193a4721e791f0d31c99625f80e16 (diff) | |
parent | 3150f7c7af68c78e410c328b406223d748f9c7ba (diff) | |
download | system_core-6590255dbbcbd35c527b3a2e6871275ec88fee64.tar.gz system_core-6590255dbbcbd35c527b3a2e6871275ec88fee64.tar.bz2 system_core-6590255dbbcbd35c527b3a2e6871275ec88fee64.zip |
Merge "Add error_msg argument to CloseNativeLibrary"
-rw-r--r-- | libnativebridge/include/nativebridge/native_bridge.h | 2 | ||||
-rw-r--r-- | libnativeloader/include/nativeloader/native_loader.h | 5 | ||||
-rw-r--r-- | libnativeloader/native_loader.cpp | 18 |
3 files changed, 19 insertions, 6 deletions
diff --git a/libnativebridge/include/nativebridge/native_bridge.h b/libnativebridge/include/nativebridge/native_bridge.h index 9bfc93523..28f192748 100644 --- a/libnativebridge/include/nativebridge/native_bridge.h +++ b/libnativebridge/include/nativebridge/native_bridge.h @@ -99,7 +99,7 @@ bool NativeBridgeError(); bool NativeBridgeNameAcceptable(const char* native_bridge_library_filename); // Decrements the reference count on the dynamic library handler. If the reference count drops -// to zero then the dynamic library is unloaded. +// to zero then the dynamic library is unloaded. Returns 0 on success and non-zero on error. int NativeBridgeUnloadLibrary(void* handle); // Get last error message of native bridge when fail to load library or search symbol. diff --git a/libnativeloader/include/nativeloader/native_loader.h b/libnativeloader/include/nativeloader/native_loader.h index 19a17832e..c1d9d2a92 100644 --- a/libnativeloader/include/nativeloader/native_loader.h +++ b/libnativeloader/include/nativeloader/native_loader.h @@ -47,8 +47,9 @@ void* OpenNativeLibrary(JNIEnv* env, bool* needs_native_bridge, std::string* error_msg); -__attribute__((visibility("default"))) -bool CloseNativeLibrary(void* handle, const bool needs_native_bridge); +__attribute__((visibility("default"))) bool CloseNativeLibrary(void* handle, + const bool needs_native_bridge, + std::string* error_msg); #if defined(__ANDROID__) // Look up linker namespace by class_loader. Returns nullptr if diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp index 67c1c103b..b3e2b97fe 100644 --- a/libnativeloader/native_loader.cpp +++ b/libnativeloader/native_loader.cpp @@ -710,9 +710,21 @@ void* OpenNativeLibrary(JNIEnv* env, #endif } -bool CloseNativeLibrary(void* handle, const bool needs_native_bridge) { - return needs_native_bridge ? NativeBridgeUnloadLibrary(handle) : - dlclose(handle); +bool CloseNativeLibrary(void* handle, const bool needs_native_bridge, std::string* error_msg) { + bool success; + if (needs_native_bridge) { + success = (NativeBridgeUnloadLibrary(handle) == 0); + if (!success) { + *error_msg = NativeBridgeGetError(); + } + } else { + success = (dlclose(handle) == 0); + if (!success) { + *error_msg = dlerror(); + } + } + + return success; } #if defined(__ANDROID__) |