blob: fd46cdce345adb394d2203789a4386abae43378e [file] [log] [blame]
Jiyong Park6291da22019-04-26 18:55:48 +09001/*
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 Park40a60772019-05-03 16:21:31 +090021#define LOG_TAG "nativeloader"
22
Jiyong Park6291da22019-04-26 18:55:48 +090023#include "native_loader_namespace.h"
24
25#include <list>
26#include <string>
27
Jiyong Park16a98962019-05-04 03:10:48 +090028#include <jni.h>
Jiyong Park6291da22019-04-26 18:55:48 +090029
Jiyong Park40a60772019-05-03 16:21:31 +090030namespace android::nativeloader {
Jiyong Park6291da22019-04-26 18:55:48 +090031
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.
36class 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 Park6291da22019-04-26 18:55:48 +090057};
58
Jiyong Park40a60772019-05-03 16:21:31 +090059} // namespace android::nativeloader