| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "nativeloader" |
| 18 | |
| 19 | #include "nativeloader/native_loader.h" |
| 20 | |
| 21 | #include <dlfcn.h> |
| 22 | #include <sys/types.h> |
| 23 | |
| Kiyoung Kim | 272b36d | 2020-02-19 16:08:47 +0900 | [diff] [blame] | 24 | #include <algorithm> |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 25 | #include <memory> |
| 26 | #include <mutex> |
| 27 | #include <string> |
| 28 | #include <vector> |
| 29 | |
| 30 | #include <android-base/file.h> |
| 31 | #include <android-base/macros.h> |
| Martin Stjernholm | 0d0f8df | 2021-04-28 16:47:01 +0100 | [diff] [blame] | 32 | #include <android-base/properties.h> |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 33 | #include <android-base/strings.h> |
| Martin Stjernholm | 0d0f8df | 2021-04-28 16:47:01 +0100 | [diff] [blame] | 34 | #include <android-base/thread_annotations.h> |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 35 | #include <nativebridge/native_bridge.h> |
| Orion Hodson | 6dc0a43 | 2020-02-06 14:28:28 +0000 | [diff] [blame] | 36 | #include <nativehelper/scoped_utf_chars.h> |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 37 | |
| Nicolas Geoffray | 7ca8b67 | 2020-04-24 15:43:48 +0100 | [diff] [blame] | 38 | #ifdef ART_TARGET_ANDROID |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 39 | #include <log/log.h> |
| 40 | #include "library_namespaces.h" |
| 41 | #include "nativeloader/dlext_namespaces.h" |
| 42 | #endif |
| 43 | |
| 44 | namespace android { |
| 45 | |
| 46 | namespace { |
| Martin Stjernholm | 0d0f8df | 2021-04-28 16:47:01 +0100 | [diff] [blame] | 47 | |
| Nicolas Geoffray | 7ca8b67 | 2020-04-24 15:43:48 +0100 | [diff] [blame] | 48 | #if defined(ART_TARGET_ANDROID) |
| Martin Stjernholm | 0d0f8df | 2021-04-28 16:47:01 +0100 | [diff] [blame] | 49 | |
| 50 | // NATIVELOADER_DEFAULT_NAMESPACE_LIBS is an environment variable that can be |
| 51 | // used when ro.debuggable is true to list extra libraries (separated by ":") |
| Martin Stjernholm | b94401e | 2021-04-26 23:06:57 +0100 | [diff] [blame^] | 52 | // that libnativeloader will load from the default namespace. The libraries |
| 53 | // must be listed without paths, and then LD_LIBRARY_PATH is typically set to the |
| Martin Stjernholm | 0d0f8df | 2021-04-28 16:47:01 +0100 | [diff] [blame] | 54 | // directories to load them from. The libraries will be available in all |
| 55 | // classloader namespaces, and also in the fallback namespace used when no |
| 56 | // classloader is given. |
| 57 | // |
| 58 | // kNativeloaderExtraLibs is the name of that fallback namespace. |
| 59 | // |
| 60 | // NATIVELOADER_DEFAULT_NAMESPACE_LIBS is intended to be used for testing only, |
| 61 | // and in particular in the ART run tests that are executed through dalvikvm in |
| 62 | // the APEX. In that case the default namespace links to the ART namespace |
| 63 | // (com_android_art) for all libraries, which means this can be used to load |
| 64 | // test libraries that depend on ART internal libraries. |
| 65 | constexpr const char* kNativeloaderExtraLibs = "nativeloader-extra-libs"; |
| 66 | |
| 67 | bool Debuggable() { |
| 68 | static bool debuggable = android::base::GetBoolProperty("ro.debuggable", false); |
| 69 | return debuggable; |
| 70 | } |
| 71 | |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 72 | using android::nativeloader::LibraryNamespaces; |
| 73 | |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 74 | std::mutex g_namespaces_mutex; |
| 75 | LibraryNamespaces* g_namespaces = new LibraryNamespaces; |
| Martin Stjernholm | 0d0f8df | 2021-04-28 16:47:01 +0100 | [diff] [blame] | 76 | NativeLoaderNamespace* g_nativeloader_extra_libs_namespace = nullptr; |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 77 | |
| 78 | android_namespace_t* FindExportedNamespace(const char* caller_location) { |
| Jooyung Han | 538f99a | 2020-03-03 00:46:50 +0900 | [diff] [blame] | 79 | auto name = nativeloader::FindApexNamespaceName(caller_location); |
| 80 | if (name.ok()) { |
| 81 | android_namespace_t* boot_namespace = android_get_exported_namespace(name->c_str()); |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 82 | LOG_ALWAYS_FATAL_IF((boot_namespace == nullptr), |
| Jooyung Han | 538f99a | 2020-03-03 00:46:50 +0900 | [diff] [blame] | 83 | "Error finding namespace of apex: no namespace called %s", name->c_str()); |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 84 | return boot_namespace; |
| 85 | } |
| 86 | return nullptr; |
| 87 | } |
| Martin Stjernholm | 0d0f8df | 2021-04-28 16:47:01 +0100 | [diff] [blame] | 88 | |
| 89 | Result<void> CreateNativeloaderDefaultNamespaceLibsLink(NativeLoaderNamespace& ns) |
| 90 | REQUIRES(g_namespaces_mutex) { |
| 91 | const char* links = getenv("NATIVELOADER_DEFAULT_NAMESPACE_LIBS"); |
| 92 | if (links == nullptr || *links == 0) { |
| 93 | return {}; |
| 94 | } |
| 95 | // Pass nullptr to Link() to create a link to the default namespace without |
| 96 | // requiring it to be visible. |
| 97 | return ns.Link(nullptr, links); |
| 98 | } |
| 99 | |
| 100 | Result<NativeLoaderNamespace*> GetNativeloaderExtraLibsNamespace() REQUIRES(g_namespaces_mutex) { |
| 101 | if (g_nativeloader_extra_libs_namespace != nullptr) { |
| 102 | return g_nativeloader_extra_libs_namespace; |
| 103 | } |
| 104 | |
| 105 | Result<NativeLoaderNamespace> ns = |
| 106 | NativeLoaderNamespace::Create(kNativeloaderExtraLibs, |
| 107 | /*search_paths=*/"", |
| 108 | /*permitted_paths=*/"", |
| 109 | /*parent=*/nullptr, |
| 110 | /*is_shared=*/false, |
| 111 | /*is_exempt_list_enabled=*/false, |
| 112 | /*also_used_as_anonymous=*/false); |
| 113 | if (!ns.ok()) { |
| 114 | return ns.error(); |
| 115 | } |
| 116 | g_nativeloader_extra_libs_namespace = new NativeLoaderNamespace(std::move(ns.value())); |
| 117 | Result<void> linked = |
| 118 | CreateNativeloaderDefaultNamespaceLibsLink(*g_nativeloader_extra_libs_namespace); |
| 119 | if (!linked.ok()) { |
| 120 | return linked.error(); |
| 121 | } |
| 122 | return g_nativeloader_extra_libs_namespace; |
| 123 | } |
| 124 | |
| 125 | // If the given path matches a library in NATIVELOADER_DEFAULT_NAMESPACE_LIBS |
| 126 | // then load it in the nativeloader-extra-libs namespace, otherwise return |
| 127 | // nullptr without error. This is only enabled if the ro.debuggable is true. |
| 128 | Result<void*> TryLoadNativeloaderExtraLib(const char* path) { |
| 129 | if (!Debuggable()) { |
| 130 | return nullptr; |
| 131 | } |
| 132 | const char* links = getenv("NATIVELOADER_DEFAULT_NAMESPACE_LIBS"); |
| 133 | if (links == nullptr || *links == 0) { |
| 134 | return nullptr; |
| 135 | } |
| 136 | std::vector<std::string> lib_list = base::Split(links, ":"); |
| 137 | if (std::find(lib_list.begin(), lib_list.end(), path) == lib_list.end()) { |
| 138 | return nullptr; |
| 139 | } |
| 140 | |
| 141 | std::lock_guard<std::mutex> guard(g_namespaces_mutex); |
| 142 | Result<NativeLoaderNamespace*> ns = GetNativeloaderExtraLibsNamespace(); |
| 143 | if (!ns.ok()) { |
| 144 | return ns.error(); |
| 145 | } |
| 146 | return ns.value()->Load(path); |
| 147 | } |
| 148 | |
| 149 | Result<NativeLoaderNamespace*> CreateClassLoaderNamespaceLocked(JNIEnv* env, |
| 150 | int32_t target_sdk_version, |
| 151 | jobject class_loader, |
| 152 | bool is_shared, |
| 153 | jstring dex_path, |
| 154 | jstring library_path, |
| 155 | jstring permitted_path, |
| 156 | jstring uses_library_list) |
| 157 | REQUIRES(g_namespaces_mutex) { |
| 158 | Result<NativeLoaderNamespace*> ns = g_namespaces->Create(env, |
| 159 | target_sdk_version, |
| 160 | class_loader, |
| 161 | is_shared, |
| 162 | dex_path, |
| 163 | library_path, |
| 164 | permitted_path, |
| 165 | uses_library_list); |
| 166 | if (!ns.ok()) { |
| 167 | return ns; |
| 168 | } |
| 169 | if (Debuggable()) { |
| 170 | Result<void> linked = CreateNativeloaderDefaultNamespaceLibsLink(*ns.value()); |
| 171 | if (!linked.ok()) { |
| 172 | return linked.error(); |
| 173 | } |
| 174 | } |
| 175 | return ns; |
| 176 | } |
| 177 | |
| Nicolas Geoffray | 7ca8b67 | 2020-04-24 15:43:48 +0100 | [diff] [blame] | 178 | #endif // #if defined(ART_TARGET_ANDROID) |
| Martin Stjernholm | 0d0f8df | 2021-04-28 16:47:01 +0100 | [diff] [blame] | 179 | |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 180 | } // namespace |
| 181 | |
| 182 | void InitializeNativeLoader() { |
| Nicolas Geoffray | 7ca8b67 | 2020-04-24 15:43:48 +0100 | [diff] [blame] | 183 | #if defined(ART_TARGET_ANDROID) |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 184 | std::lock_guard<std::mutex> guard(g_namespaces_mutex); |
| 185 | g_namespaces->Initialize(); |
| 186 | #endif |
| 187 | } |
| 188 | |
| 189 | void ResetNativeLoader() { |
| Nicolas Geoffray | 7ca8b67 | 2020-04-24 15:43:48 +0100 | [diff] [blame] | 190 | #if defined(ART_TARGET_ANDROID) |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 191 | std::lock_guard<std::mutex> guard(g_namespaces_mutex); |
| 192 | g_namespaces->Reset(); |
| Martin Stjernholm | 0d0f8df | 2021-04-28 16:47:01 +0100 | [diff] [blame] | 193 | delete(g_nativeloader_extra_libs_namespace); |
| 194 | g_nativeloader_extra_libs_namespace = nullptr; |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 195 | #endif |
| 196 | } |
| 197 | |
| 198 | jstring CreateClassLoaderNamespace(JNIEnv* env, int32_t target_sdk_version, jobject class_loader, |
| 199 | bool is_shared, jstring dex_path, jstring library_path, |
| Jiyong Park | 14626a7 | 2020-07-02 23:17:58 +0900 | [diff] [blame] | 200 | jstring permitted_path, jstring uses_library_list) { |
| Nicolas Geoffray | 7ca8b67 | 2020-04-24 15:43:48 +0100 | [diff] [blame] | 201 | #if defined(ART_TARGET_ANDROID) |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 202 | std::lock_guard<std::mutex> guard(g_namespaces_mutex); |
| Martin Stjernholm | 0d0f8df | 2021-04-28 16:47:01 +0100 | [diff] [blame] | 203 | Result<NativeLoaderNamespace*> ns = CreateClassLoaderNamespaceLocked(env, |
| 204 | target_sdk_version, |
| 205 | class_loader, |
| 206 | is_shared, |
| 207 | dex_path, |
| 208 | library_path, |
| 209 | permitted_path, |
| 210 | uses_library_list); |
| Bernie Innocenti | 4bd5895 | 2020-02-06 15:43:57 +0900 | [diff] [blame] | 211 | if (!ns.ok()) { |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 212 | return env->NewStringUTF(ns.error().message().c_str()); |
| 213 | } |
| 214 | #else |
| Jiyong Park | 14626a7 | 2020-07-02 23:17:58 +0900 | [diff] [blame] | 215 | UNUSED(env, target_sdk_version, class_loader, is_shared, dex_path, library_path, permitted_path, |
| 216 | uses_library_list); |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 217 | #endif |
| 218 | return nullptr; |
| 219 | } |
| 220 | |
| 221 | void* OpenNativeLibrary(JNIEnv* env, int32_t target_sdk_version, const char* path, |
| 222 | jobject class_loader, const char* caller_location, jstring library_path, |
| 223 | bool* needs_native_bridge, char** error_msg) { |
| Nicolas Geoffray | 7ca8b67 | 2020-04-24 15:43:48 +0100 | [diff] [blame] | 224 | #if defined(ART_TARGET_ANDROID) |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 225 | UNUSED(target_sdk_version); |
| Martin Stjernholm | 0d0f8df | 2021-04-28 16:47:01 +0100 | [diff] [blame] | 226 | |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 227 | if (class_loader == nullptr) { |
| 228 | *needs_native_bridge = false; |
| 229 | if (caller_location != nullptr) { |
| 230 | android_namespace_t* boot_namespace = FindExportedNamespace(caller_location); |
| 231 | if (boot_namespace != nullptr) { |
| 232 | const android_dlextinfo dlextinfo = { |
| 233 | .flags = ANDROID_DLEXT_USE_NAMESPACE, |
| 234 | .library_namespace = boot_namespace, |
| 235 | }; |
| 236 | void* handle = android_dlopen_ext(path, RTLD_NOW, &dlextinfo); |
| 237 | if (handle == nullptr) { |
| 238 | *error_msg = strdup(dlerror()); |
| 239 | } |
| 240 | return handle; |
| 241 | } |
| 242 | } |
| Martin Stjernholm | 0d0f8df | 2021-04-28 16:47:01 +0100 | [diff] [blame] | 243 | |
| 244 | // Check if the library is in NATIVELOADER_DEFAULT_NAMESPACE_LIBS and should |
| 245 | // be loaded from the kNativeloaderExtraLibs namespace. |
| 246 | { |
| 247 | Result<void*> handle = TryLoadNativeloaderExtraLib(path); |
| 248 | if (!handle.ok()) { |
| 249 | *error_msg = strdup(handle.error().message().c_str()); |
| 250 | return nullptr; |
| 251 | } |
| 252 | if (handle.value() != nullptr) { |
| 253 | return handle.value(); |
| 254 | } |
| 255 | } |
| 256 | |
| Martin Stjernholm | 2665943 | 2021-04-16 19:55:03 +0100 | [diff] [blame] | 257 | // Fall back to the system namespace. This happens for preloaded JNI |
| 258 | // libraries in the zygote. |
| 259 | // TODO(b/185833744): Investigate if this should fall back to the app main |
| 260 | // namespace (aka anonymous namespace) instead. |
| 261 | void* handle = OpenSystemLibrary(path, RTLD_NOW); |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 262 | if (handle == nullptr) { |
| 263 | *error_msg = strdup(dlerror()); |
| 264 | } |
| 265 | return handle; |
| 266 | } |
| 267 | |
| 268 | std::lock_guard<std::mutex> guard(g_namespaces_mutex); |
| 269 | NativeLoaderNamespace* ns; |
| 270 | |
| 271 | if ((ns = g_namespaces->FindNamespaceByClassLoader(env, class_loader)) == nullptr) { |
| 272 | // This is the case where the classloader was not created by ApplicationLoaders |
| 273 | // In this case we create an isolated not-shared namespace for it. |
| 274 | Result<NativeLoaderNamespace*> isolated_ns = |
| Martin Stjernholm | 0d0f8df | 2021-04-28 16:47:01 +0100 | [diff] [blame] | 275 | CreateClassLoaderNamespaceLocked(env, |
| 276 | target_sdk_version, |
| 277 | class_loader, |
| 278 | /*is_shared=*/false, |
| 279 | /*dex_path=*/nullptr, |
| 280 | library_path, |
| 281 | /*permitted_path=*/nullptr, |
| 282 | /*uses_library_list=*/nullptr); |
| Bernie Innocenti | 4bd5895 | 2020-02-06 15:43:57 +0900 | [diff] [blame] | 283 | if (!isolated_ns.ok()) { |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 284 | *error_msg = strdup(isolated_ns.error().message().c_str()); |
| 285 | return nullptr; |
| 286 | } else { |
| 287 | ns = *isolated_ns; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | return OpenNativeLibraryInNamespace(ns, path, needs_native_bridge, error_msg); |
| 292 | #else |
| 293 | UNUSED(env, target_sdk_version, class_loader, caller_location); |
| 294 | |
| 295 | // Do some best effort to emulate library-path support. It will not |
| 296 | // work for dependencies. |
| 297 | // |
| 298 | // Note: null has a special meaning and must be preserved. |
| 299 | std::string c_library_path; // Empty string by default. |
| 300 | if (library_path != nullptr && path != nullptr && path[0] != '/') { |
| 301 | ScopedUtfChars library_path_utf_chars(env, library_path); |
| 302 | c_library_path = library_path_utf_chars.c_str(); |
| 303 | } |
| 304 | |
| 305 | std::vector<std::string> library_paths = base::Split(c_library_path, ":"); |
| 306 | |
| 307 | for (const std::string& lib_path : library_paths) { |
| 308 | *needs_native_bridge = false; |
| 309 | const char* path_arg; |
| 310 | std::string complete_path; |
| 311 | if (path == nullptr) { |
| 312 | // Preserve null. |
| 313 | path_arg = nullptr; |
| 314 | } else { |
| 315 | complete_path = lib_path; |
| 316 | if (!complete_path.empty()) { |
| 317 | complete_path.append("/"); |
| 318 | } |
| 319 | complete_path.append(path); |
| 320 | path_arg = complete_path.c_str(); |
| 321 | } |
| 322 | void* handle = dlopen(path_arg, RTLD_NOW); |
| 323 | if (handle != nullptr) { |
| 324 | return handle; |
| 325 | } |
| 326 | if (NativeBridgeIsSupported(path_arg)) { |
| 327 | *needs_native_bridge = true; |
| 328 | handle = NativeBridgeLoadLibrary(path_arg, RTLD_NOW); |
| 329 | if (handle != nullptr) { |
| 330 | return handle; |
| 331 | } |
| 332 | *error_msg = strdup(NativeBridgeGetError()); |
| 333 | } else { |
| 334 | *error_msg = strdup(dlerror()); |
| 335 | } |
| 336 | } |
| 337 | return nullptr; |
| 338 | #endif |
| 339 | } |
| 340 | |
| 341 | bool CloseNativeLibrary(void* handle, const bool needs_native_bridge, char** error_msg) { |
| 342 | bool success; |
| 343 | if (needs_native_bridge) { |
| 344 | success = (NativeBridgeUnloadLibrary(handle) == 0); |
| 345 | if (!success) { |
| 346 | *error_msg = strdup(NativeBridgeGetError()); |
| 347 | } |
| 348 | } else { |
| 349 | success = (dlclose(handle) == 0); |
| 350 | if (!success) { |
| 351 | *error_msg = strdup(dlerror()); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | return success; |
| 356 | } |
| 357 | |
| 358 | void NativeLoaderFreeErrorMessage(char* msg) { |
| 359 | // The error messages get allocated through strdup, so we must call free on them. |
| 360 | free(msg); |
| 361 | } |
| 362 | |
| Nicolas Geoffray | 7ca8b67 | 2020-04-24 15:43:48 +0100 | [diff] [blame] | 363 | #if defined(ART_TARGET_ANDROID) |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 364 | void* OpenNativeLibraryInNamespace(NativeLoaderNamespace* ns, const char* path, |
| 365 | bool* needs_native_bridge, char** error_msg) { |
| 366 | auto handle = ns->Load(path); |
| Bernie Innocenti | 4bd5895 | 2020-02-06 15:43:57 +0900 | [diff] [blame] | 367 | if (!handle.ok() && error_msg != nullptr) { |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 368 | *error_msg = strdup(handle.error().message().c_str()); |
| 369 | } |
| 370 | if (needs_native_bridge != nullptr) { |
| 371 | *needs_native_bridge = ns->IsBridged(); |
| 372 | } |
| Bernie Innocenti | 4bd5895 | 2020-02-06 15:43:57 +0900 | [diff] [blame] | 373 | return handle.ok() ? *handle : nullptr; |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | // native_bridge_namespaces are not supported for callers of this function. |
| 377 | // This function will return nullptr in the case when application is running |
| 378 | // on native bridge. |
| 379 | android_namespace_t* FindNamespaceByClassLoader(JNIEnv* env, jobject class_loader) { |
| 380 | std::lock_guard<std::mutex> guard(g_namespaces_mutex); |
| 381 | NativeLoaderNamespace* ns = g_namespaces->FindNamespaceByClassLoader(env, class_loader); |
| 382 | if (ns != nullptr && !ns->IsBridged()) { |
| 383 | return ns->ToRawAndroidNamespace(); |
| 384 | } |
| 385 | return nullptr; |
| 386 | } |
| 387 | |
| 388 | NativeLoaderNamespace* FindNativeLoaderNamespaceByClassLoader(JNIEnv* env, jobject class_loader) { |
| 389 | std::lock_guard<std::mutex> guard(g_namespaces_mutex); |
| 390 | return g_namespaces->FindNamespaceByClassLoader(env, class_loader); |
| 391 | } |
| Martin Stjernholm | 0d0f8df | 2021-04-28 16:47:01 +0100 | [diff] [blame] | 392 | |
| 393 | void LinkNativeLoaderNamespaceToExportedNamespaceLibrary(struct NativeLoaderNamespace* ns, |
| 394 | const char* exported_ns_name, |
| 395 | const char* library_name, |
| 396 | char** error_msg) { |
| 397 | Result<NativeLoaderNamespace> exported_ns = |
| 398 | NativeLoaderNamespace::GetExportedNamespace(exported_ns_name, ns->IsBridged()); |
| 399 | if (!exported_ns.ok()) { |
| 400 | *error_msg = strdup(exported_ns.error().message().c_str()); |
| 401 | return; |
| 402 | } |
| 403 | |
| 404 | Result<void> linked = ns->Link(&exported_ns.value(), std::string(library_name)); |
| 405 | if (!linked.ok()) { |
| 406 | *error_msg = strdup(linked.error().message().c_str()); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | #endif // ART_TARGET_ANDROID |
| Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 411 | |
| 412 | }; // namespace android |