• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef ART_LIBNATIVELOADER_INCLUDE_NATIVELOADER_NATIVE_LOADER_H_
18 #define ART_LIBNATIVELOADER_INCLUDE_NATIVELOADER_NATIVE_LOADER_H_
19 
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
28 namespace android {
29 extern "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")))
37 void 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,
41     jstring library_path, jstring permitted_path);
42 
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.
60 struct NativeLoaderNamespace;
61 __attribute__((visibility("default"))) struct NativeLoaderNamespace*
62 FindNativeLoaderNamespaceByClassLoader(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")))
71 void ResetNativeLoader();
72 
73 #ifdef __cplusplus
74 }  // extern "C"
75 }  // namespace android
76 #endif  // __cplusplus
77 
78 #endif  // ART_LIBNATIVELOADER_INCLUDE_NATIVELOADER_NATIVE_LOADER_H_
79