1 /* 2 * Copyright (C) 2008 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 * Dalvik's native call interface. 18 * 19 * You should follow the JNI function naming conventions, but prefix with 20 * "Dalvik_" instead of "Java_". 21 */ 22 #ifndef DALVIK_NATIVE_H_ 23 #define DALVIK_NATIVE_H_ 24 25 /* 26 * Method description; equivalent to a JNI struct. 27 */ 28 struct DalvikNativeMethod { 29 const char* name; 30 const char* signature; 31 DalvikNativeFunc fnPtr; 32 }; 33 34 /* 35 * All methods for one class. The last "methodInfo" has a NULL "name". 36 */ 37 struct DalvikNativeClass { 38 const char* classDescriptor; 39 const DalvikNativeMethod* methodInfo; 40 u4 classDescriptorHash; /* initialized at runtime */ 41 }; 42 43 44 /* init/shutdown */ 45 bool dvmNativeStartup(void); 46 void dvmNativeShutdown(void); 47 48 49 /* 50 * Convert argc/argv into a function call. This is platform-specific. 51 */ 52 extern "C" void dvmPlatformInvoke(void* pEnv, ClassObject* clazz, int argInfo, 53 int argc, const u4* argv, const char* signature, void* func, JValue* pResult); 54 55 /* 56 * Generate hints to speed native calls. This is platform specific. 57 */ 58 u4 dvmPlatformInvokeHints(const DexProto* proto); 59 60 /* 61 * Convert a short library name ("jpeg") to a system-dependent name 62 * ("libjpeg.so"). Returns a newly-allocated string. 63 */ 64 char* dvmCreateSystemLibraryName(char* libName); 65 bool dvmLoadNativeCode(const char* fileName, Object* classLoader, 66 char** detail); 67 68 69 /* 70 * Resolve a native method. This uses the same prototype as a 71 * DalvikBridgeFunc, because it takes the place of the actual function 72 * until the first time that it's invoked. 73 * 74 * Causes the method's class to be initialized. 75 * 76 * Throws an exception and returns NULL on failure. 77 */ 78 void dvmResolveNativeMethod(const u4* args, JValue* pResult, 79 const Method* method, struct Thread* self); 80 81 /* 82 * Unregister all JNI native methods associated with a class. 83 */ 84 void dvmUnregisterJNINativeMethods(ClassObject* clazz); 85 86 #define GET_ARG_LONG(_args, _elem) dvmGetArgLong(_args, _elem) 87 88 /* 89 * Helpful function for accessing long integers in "u4* args". 90 * 91 * We can't just return *(s8*)(&args[elem]), because that breaks if our 92 * architecture requires 64-bit alignment of 64-bit values. 93 * 94 * Big/little endian shouldn't matter here -- ordering of words within a 95 * long seems consistent across our supported platforms. 96 */ 97 INLINE s8 dvmGetArgLong(const u4* args, int elem) 98 { 99 s8 val; 100 memcpy(&val, &args[elem], sizeof(val)); 101 return val; 102 } 103 104 #endif // DALVIK_NATIVE_H_ 105