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
23 #define _DALVIK_NATIVE
26 * Method description; equivalent to a JNI struct.
28 typedef struct DalvikNativeMethod {
30 const char* signature;
31 DalvikNativeFunc fnPtr;
35 * All methods for one class. The last "methodInfo" has a NULL "name".
37 typedef 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 void dvmPlatformInvoke(void* pEnv, ClassObject* clazz, int argInfo, int argc,
53 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 //void dvmLoadNativeLibrary(StringObject* libNameObj, Object* classLoader);
66 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);
81 //#define GET_ARG_LONG(_args, _elem) (*(s8*)(&(_args)[_elem]))
82 #define GET_ARG_LONG(_args, _elem) dvmGetArgLong(_args, _elem)
85 * Helpful function for accessing long integers in "u4* args".
87 * We can't just return *(s8*)(&args[elem]), because that breaks if our
88 * architecture requires 64-bit alignment of 64-bit values.
90 * Big/little endian shouldn't matter here -- ordering of words within a
91 * long seems consistent across our supported platforms.
93 INLINE s8 dvmGetArgLong(const u4* args, int elem)
96 union { u4 parts[2]; s8 whole; } conv;
97 conv.parts[0] = args[elem];
98 conv.parts[1] = args[elem+1];
101 /* with gcc's optimizer, memcpy() turns into simpler assignments */
103 memcpy(&val, &args[elem], 8);
108 #endif /*_DALVIK_NATIVE*/