1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker #ifndef ART_LIBNATIVELOADER_INCLUDE_NATIVELOADER_NATIVE_LOADER_H_ 18*795d594fSAndroid Build Coastguard Worker #define ART_LIBNATIVELOADER_INCLUDE_NATIVELOADER_NATIVE_LOADER_H_ 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker #include <stdbool.h> 21*795d594fSAndroid Build Coastguard Worker #include <stdint.h> 22*795d594fSAndroid Build Coastguard Worker #include "jni.h" 23*795d594fSAndroid Build Coastguard Worker #if defined(__ANDROID__) 24*795d594fSAndroid Build Coastguard Worker #include <android/dlext.h> 25*795d594fSAndroid Build Coastguard Worker #endif 26*795d594fSAndroid Build Coastguard Worker 27*795d594fSAndroid Build Coastguard Worker #ifdef __cplusplus 28*795d594fSAndroid Build Coastguard Worker namespace android { 29*795d594fSAndroid Build Coastguard Worker extern "C" { 30*795d594fSAndroid Build Coastguard Worker #endif // __cplusplus 31*795d594fSAndroid Build Coastguard Worker 32*795d594fSAndroid Build Coastguard Worker // README: the char** error message parameter being passed 33*795d594fSAndroid Build Coastguard Worker // to the methods below need to be freed through calling NativeLoaderFreeErrorMessage. 34*795d594fSAndroid Build Coastguard Worker // It's the caller's responsibility to call that method. 35*795d594fSAndroid Build Coastguard Worker 36*795d594fSAndroid Build Coastguard Worker __attribute__((visibility("default"))) 37*795d594fSAndroid Build Coastguard Worker void InitializeNativeLoader(); 38*795d594fSAndroid Build Coastguard Worker 39*795d594fSAndroid Build Coastguard Worker __attribute__((visibility("default"))) jstring CreateClassLoaderNamespace( 40*795d594fSAndroid Build Coastguard Worker JNIEnv* env, int32_t target_sdk_version, jobject class_loader, bool is_shared, jstring dex_path, 41*795d594fSAndroid Build Coastguard Worker jstring library_path, jstring permitted_path, jstring uses_library_list); 42*795d594fSAndroid Build Coastguard Worker 43*795d594fSAndroid Build Coastguard Worker __attribute__((visibility("default"))) void* OpenNativeLibrary( 44*795d594fSAndroid Build Coastguard Worker JNIEnv* env, int32_t target_sdk_version, const char* path, jobject class_loader, 45*795d594fSAndroid Build Coastguard Worker const char* caller_location, jstring library_path, bool* needs_native_bridge, char** error_msg); 46*795d594fSAndroid Build Coastguard Worker 47*795d594fSAndroid Build Coastguard Worker __attribute__((visibility("default"))) bool CloseNativeLibrary(void* handle, 48*795d594fSAndroid Build Coastguard Worker const bool needs_native_bridge, 49*795d594fSAndroid Build Coastguard Worker char** error_msg); 50*795d594fSAndroid Build Coastguard Worker 51*795d594fSAndroid Build Coastguard Worker __attribute__((visibility("default"))) void NativeLoaderFreeErrorMessage(char* msg); 52*795d594fSAndroid Build Coastguard Worker 53*795d594fSAndroid Build Coastguard Worker #if defined(__ANDROID__) 54*795d594fSAndroid Build Coastguard Worker // Look up linker namespace by class_loader. Returns nullptr if 55*795d594fSAndroid Build Coastguard Worker // there is no namespace associated with the class_loader. 56*795d594fSAndroid Build Coastguard Worker // TODO(b/79940628): move users to FindNativeLoaderNamespaceByClassLoader and remove this function. 57*795d594fSAndroid Build Coastguard Worker __attribute__((visibility("default"))) struct android_namespace_t* FindNamespaceByClassLoader( 58*795d594fSAndroid Build Coastguard Worker JNIEnv* env, jobject class_loader); 59*795d594fSAndroid Build Coastguard Worker // That version works with native bridge namespaces, but requires use of OpenNativeLibrary. 60*795d594fSAndroid Build Coastguard Worker struct NativeLoaderNamespace; 61*795d594fSAndroid Build Coastguard Worker __attribute__((visibility("default"))) struct NativeLoaderNamespace* 62*795d594fSAndroid Build Coastguard Worker FindNativeLoaderNamespaceByClassLoader(JNIEnv* env, jobject class_loader); 63*795d594fSAndroid Build Coastguard Worker // Load library. Unlinke OpenNativeLibrary above couldn't create namespace on demand, but does 64*795d594fSAndroid Build Coastguard Worker // not require access to JNIEnv either. 65*795d594fSAndroid Build Coastguard Worker __attribute__((visibility("default"))) void* OpenNativeLibraryInNamespace( 66*795d594fSAndroid Build Coastguard Worker struct NativeLoaderNamespace* ns, const char* path, bool* needs_native_bridge, 67*795d594fSAndroid Build Coastguard Worker char** error_msg); 68*795d594fSAndroid Build Coastguard Worker 69*795d594fSAndroid Build Coastguard Worker __attribute__((visibility("default"))) bool IsNamespaceNativeBridged( 70*795d594fSAndroid Build Coastguard Worker const struct NativeLoaderNamespace* ns); 71*795d594fSAndroid Build Coastguard Worker #endif 72*795d594fSAndroid Build Coastguard Worker 73*795d594fSAndroid Build Coastguard Worker __attribute__((visibility("default"))) 74*795d594fSAndroid Build Coastguard Worker void ResetNativeLoader(); 75*795d594fSAndroid Build Coastguard Worker 76*795d594fSAndroid Build Coastguard Worker #ifdef __cplusplus 77*795d594fSAndroid Build Coastguard Worker } // extern "C" 78*795d594fSAndroid Build Coastguard Worker } // namespace android 79*795d594fSAndroid Build Coastguard Worker #endif // __cplusplus 80*795d594fSAndroid Build Coastguard Worker 81*795d594fSAndroid Build Coastguard Worker #endif // ART_LIBNATIVELOADER_INCLUDE_NATIVELOADER_NATIVE_LOADER_H_ 82