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 | 8f4afc8 | 2019-07-22 14:20:40 +0900 | [diff] [blame^] | 28 | #include <android-base/result.h> |
Jiyong Park | 16a9896 | 2019-05-04 03:10:48 +0900 | [diff] [blame] | 29 | #include <jni.h> |
Jiyong Park | 6291da2 | 2019-04-26 18:55:48 +0900 | [diff] [blame] | 30 | |
Jiyong Park | 40a6077 | 2019-05-03 16:21:31 +0900 | [diff] [blame] | 31 | namespace android::nativeloader { |
Jiyong Park | 6291da2 | 2019-04-26 18:55:48 +0900 | [diff] [blame] | 32 | |
Jiyong Park | 8f4afc8 | 2019-07-22 14:20:40 +0900 | [diff] [blame^] | 33 | using android::base::Result; |
| 34 | |
Jiyong Park | 6291da2 | 2019-04-26 18:55:48 +0900 | [diff] [blame] | 35 | // LibraryNamespaces is a singleton object that manages NativeLoaderNamespace |
| 36 | // objects for an app process. Its main job is to create (and configure) a new |
| 37 | // NativeLoaderNamespace object for a Java ClassLoader, and to find an existing |
| 38 | // object for a given ClassLoader. |
| 39 | class LibraryNamespaces { |
| 40 | public: |
| 41 | LibraryNamespaces() : initialized_(false) {} |
| 42 | |
| 43 | LibraryNamespaces(LibraryNamespaces&&) = default; |
| 44 | LibraryNamespaces(const LibraryNamespaces&) = delete; |
| 45 | LibraryNamespaces& operator=(const LibraryNamespaces&) = delete; |
| 46 | |
| 47 | void Initialize(); |
Jiyong Park | 78cc06a | 2019-07-19 09:02:38 +0900 | [diff] [blame] | 48 | void Reset() { |
| 49 | namespaces_.clear(); |
| 50 | initialized_ = false; |
| 51 | } |
Jiyong Park | 8f4afc8 | 2019-07-22 14:20:40 +0900 | [diff] [blame^] | 52 | Result<NativeLoaderNamespace*> Create(JNIEnv* env, uint32_t target_sdk_version, |
| 53 | jobject class_loader, bool is_shared, jstring dex_path, |
| 54 | jstring java_library_path, jstring java_permitted_path); |
Jiyong Park | 6291da2 | 2019-04-26 18:55:48 +0900 | [diff] [blame] | 55 | NativeLoaderNamespace* FindNamespaceByClassLoader(JNIEnv* env, jobject class_loader); |
| 56 | |
| 57 | private: |
Jiyong Park | 8f4afc8 | 2019-07-22 14:20:40 +0900 | [diff] [blame^] | 58 | Result<void> InitPublicNamespace(const char* library_path); |
Jiyong Park | 6291da2 | 2019-04-26 18:55:48 +0900 | [diff] [blame] | 59 | NativeLoaderNamespace* FindParentNamespaceByClassLoader(JNIEnv* env, jobject class_loader); |
| 60 | |
| 61 | bool initialized_; |
| 62 | std::list<std::pair<jweak, NativeLoaderNamespace>> namespaces_; |
Jiyong Park | 6291da2 | 2019-04-26 18:55:48 +0900 | [diff] [blame] | 63 | }; |
| 64 | |
Jiyong Park | 40a6077 | 2019-05-03 16:21:31 +0900 | [diff] [blame] | 65 | } // namespace android::nativeloader |