Jiyong Park | 6291da2 | 2019-04-26 18:55:48 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | #pragma once |
| 17 | #if !defined(__ANDROID__) |
| 18 | #error "Not available for host" |
| 19 | #endif |
| 20 | |
Jiyong Park | 40a6077 | 2019-05-03 16:21:31 +0900 | [diff] [blame] | 21 | #define LOG_TAG "nativeloader" |
| 22 | |
Jiyong Park | 6291da2 | 2019-04-26 18:55:48 +0900 | [diff] [blame] | 23 | #include "native_loader_namespace.h" |
| 24 | |
| 25 | #include <list> |
| 26 | #include <string> |
| 27 | |
Jiyong Park | 16a9896 | 2019-05-04 03:10:48 +0900 | [diff] [blame] | 28 | #include <jni.h> |
Jiyong Park | 6291da2 | 2019-04-26 18:55:48 +0900 | [diff] [blame] | 29 | |
Jiyong Park | 40a6077 | 2019-05-03 16:21:31 +0900 | [diff] [blame] | 30 | namespace android::nativeloader { |
Jiyong Park | 6291da2 | 2019-04-26 18:55:48 +0900 | [diff] [blame] | 31 | |
| 32 | // LibraryNamespaces is a singleton object that manages NativeLoaderNamespace |
| 33 | // objects for an app process. Its main job is to create (and configure) a new |
| 34 | // NativeLoaderNamespace object for a Java ClassLoader, and to find an existing |
| 35 | // object for a given ClassLoader. |
| 36 | class LibraryNamespaces { |
| 37 | public: |
| 38 | LibraryNamespaces() : initialized_(false) {} |
| 39 | |
| 40 | LibraryNamespaces(LibraryNamespaces&&) = default; |
| 41 | LibraryNamespaces(const LibraryNamespaces&) = delete; |
| 42 | LibraryNamespaces& operator=(const LibraryNamespaces&) = delete; |
| 43 | |
| 44 | void Initialize(); |
| 45 | void Reset() { namespaces_.clear(); } |
| 46 | NativeLoaderNamespace* Create(JNIEnv* env, uint32_t target_sdk_version, jobject class_loader, |
| 47 | bool is_shared, jstring dex_path, jstring java_library_path, |
| 48 | jstring java_permitted_path, std::string* error_msg); |
| 49 | NativeLoaderNamespace* FindNamespaceByClassLoader(JNIEnv* env, jobject class_loader); |
| 50 | |
| 51 | private: |
| 52 | bool InitPublicNamespace(const char* library_path, std::string* error_msg); |
| 53 | NativeLoaderNamespace* FindParentNamespaceByClassLoader(JNIEnv* env, jobject class_loader); |
| 54 | |
| 55 | bool initialized_; |
| 56 | std::list<std::pair<jweak, NativeLoaderNamespace>> namespaces_; |
Jiyong Park | 6291da2 | 2019-04-26 18:55:48 +0900 | [diff] [blame] | 57 | }; |
| 58 | |
Jiyong Park | 40a6077 | 2019-05-03 16:21:31 +0900 | [diff] [blame] | 59 | } // namespace android::nativeloader |