blob: 92d192ff255bbed1d55e54e8e48e6ce650012729 [file] [log] [blame]
Orion Hodson9b16e342019-10-09 13:29:16 +01001/*
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
Orion Hodson31b3ffa2019-10-14 10:27:00 +010017#ifndef ART_LIBNATIVELOADER_INCLUDE_NATIVELOADER_NATIVE_LOADER_H_
18#define ART_LIBNATIVELOADER_INCLUDE_NATIVELOADER_NATIVE_LOADER_H_
Orion Hodson9b16e342019-10-09 13:29:16 +010019
20#include <stdbool.h>
21#include <stdint.h>
22#include "jni.h"
23#if defined(__ANDROID__)
24#include <android/dlext.h>
25#endif
26
27#ifdef __cplusplus
28namespace android {
29extern "C" {
30#endif // __cplusplus
31
32// README: the char** error message parameter being passed
33// to the methods below need to be freed through calling NativeLoaderFreeErrorMessage.
34// It's the caller's responsibility to call that method.
35
36__attribute__((visibility("default")))
37void InitializeNativeLoader();
38
39__attribute__((visibility("default"))) jstring CreateClassLoaderNamespace(
40 JNIEnv* env, int32_t target_sdk_version, jobject class_loader, bool is_shared, jstring dex_path,
Jiyong Park14626a72020-07-02 23:17:58 +090041 jstring library_path, jstring permitted_path, jstring uses_library_list);
Orion Hodson9b16e342019-10-09 13:29:16 +010042
43__attribute__((visibility("default"))) void* OpenNativeLibrary(
44 JNIEnv* env, int32_t target_sdk_version, const char* path, jobject class_loader,
45 const char* caller_location, jstring library_path, bool* needs_native_bridge, char** error_msg);
46
47__attribute__((visibility("default"))) bool CloseNativeLibrary(void* handle,
48 const bool needs_native_bridge,
49 char** error_msg);
50
51__attribute__((visibility("default"))) void NativeLoaderFreeErrorMessage(char* msg);
52
53#if defined(__ANDROID__)
54// Look up linker namespace by class_loader. Returns nullptr if
55// there is no namespace associated with the class_loader.
56// TODO(b/79940628): move users to FindNativeLoaderNamespaceByClassLoader and remove this function.
57__attribute__((visibility("default"))) struct android_namespace_t* FindNamespaceByClassLoader(
58 JNIEnv* env, jobject class_loader);
59// That version works with native bridge namespaces, but requires use of OpenNativeLibrary.
60struct NativeLoaderNamespace;
61__attribute__((visibility("default"))) struct NativeLoaderNamespace*
62FindNativeLoaderNamespaceByClassLoader(JNIEnv* env, jobject class_loader);
63// Load library. Unlinke OpenNativeLibrary above couldn't create namespace on demand, but does
64// not require access to JNIEnv either.
65__attribute__((visibility("default"))) void* OpenNativeLibraryInNamespace(
66 struct NativeLoaderNamespace* ns, const char* path, bool* needs_native_bridge,
67 char** error_msg);
68#endif
69
70__attribute__((visibility("default")))
71void ResetNativeLoader();
72
73#ifdef __cplusplus
74} // extern "C"
75} // namespace android
76#endif // __cplusplus
77
Orion Hodson31b3ffa2019-10-14 10:27:00 +010078#endif // ART_LIBNATIVELOADER_INCLUDE_NATIVELOADER_NATIVE_LOADER_H_