2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * Dalvik's native call interface.
19 * You should follow the JNI function naming conventions, but prefix with
20 * "Dalvik_" instead of "Java_".
22 #ifndef DALVIK_NATIVE_H_
23 #define DALVIK_NATIVE_H_
26 * Method description; equivalent to a JNI struct.
28 struct DalvikNativeMethod {
30 const char* signature;
31 DalvikNativeFunc fnPtr;
35 * All methods for one class. The last "methodInfo" has a NULL "name".
37 struct DalvikNativeClass {
38 const char* classDescriptor;
39 const DalvikNativeMethod* methodInfo;
40 u4 classDescriptorHash; /* initialized at runtime */
45 bool dvmNativeStartup(void);
46 void dvmNativeShutdown(void);
50 * Convert argc/argv into a function call. This is platform-specific.
52 extern "C" void dvmPlatformInvoke(void* pEnv, ClassObject* clazz, int argInfo,
53 int argc, const u4* argv, const char* signature, void* func, JValue* pResult);
56 * Generate hints to speed native calls. This is platform specific.
58 u4 dvmPlatformInvokeHints(const DexProto* proto);
61 * Convert a short library name ("jpeg") to a system-dependent name
62 * ("libjpeg.so"). Returns a newly-allocated string.
64 char* dvmCreateSystemLibraryName(char* libName);
65 bool dvmLoadNativeCode(const char* fileName, Object* classLoader,
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.
74 * Causes the method's class to be initialized.
76 * Throws an exception and returns NULL on failure.
78 void dvmResolveNativeMethod(const u4* args, JValue* pResult,
79 const Method* method, struct Thread* self);
82 * Unregister all JNI native methods associated with a class.
84 void dvmUnregisterJNINativeMethods(ClassObject* clazz);
86 #define GET_ARG_LONG(_args, _elem) dvmGetArgLong(_args, _elem)
89 * Helpful function for accessing long integers in "u4* args".
91 * We can't just return *(s8*)(&args[elem]), because that breaks if our
92 * architecture requires 64-bit alignment of 64-bit values.
94 * Big/little endian shouldn't matter here -- ordering of words within a
95 * long seems consistent across our supported platforms.
97 INLINE s8 dvmGetArgLong(const u4* args, int elem)
100 memcpy(&val, &args[elem], sizeof(val));
104 #endif // DALVIK_NATIVE_H_