blob: 7599bcc311f0ef264f2b5569f195447bafc6752b [file] [log] [blame]
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001/*
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
23#define _DALVIK_NATIVE
24
Carl Shapiroae188c62011-04-08 13:11:58 -070025#ifdef __cplusplus
26extern "C" {
27#endif
28
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080029/*
30 * Method description; equivalent to a JNI struct.
31 */
32typedef struct DalvikNativeMethod {
33 const char* name;
34 const char* signature;
35 DalvikNativeFunc fnPtr;
36} DalvikNativeMethod;
37
38/*
39 * All methods for one class. The last "methodInfo" has a NULL "name".
40 */
41typedef struct DalvikNativeClass {
42 const char* classDescriptor;
43 const DalvikNativeMethod* methodInfo;
44 u4 classDescriptorHash; /* initialized at runtime */
45} DalvikNativeClass;
46
47
48/* init/shutdown */
49bool dvmNativeStartup(void);
50void dvmNativeShutdown(void);
51
52
53/*
54 * Convert argc/argv into a function call. This is platform-specific.
55 */
56void dvmPlatformInvoke(void* pEnv, ClassObject* clazz, int argInfo, int argc,
57 const u4* argv, const char* signature, void* func, JValue* pResult);
58
59/*
60 * Generate hints to speed native calls. This is platform specific.
61 */
62u4 dvmPlatformInvokeHints(const DexProto* proto);
63
64/*
65 * Convert a short library name ("jpeg") to a system-dependent name
66 * ("libjpeg.so"). Returns a newly-allocated string.
67 */
68char* dvmCreateSystemLibraryName(char* libName);
69//void dvmLoadNativeLibrary(StringObject* libNameObj, Object* classLoader);
Elliott Hughesf584b4a2010-09-30 15:51:31 -070070bool dvmLoadNativeCode(const char* fileName, Object* classLoader,
71 char** detail);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080072
73
74/*
75 * Resolve a native method. This uses the same prototype as a
76 * DalvikBridgeFunc, because it takes the place of the actual function
77 * until the first time that it's invoked.
78 *
79 * Causes the method's class to be initialized.
80 *
81 * Throws an exception and returns NULL on failure.
82 */
83void dvmResolveNativeMethod(const u4* args, JValue* pResult,
84 const Method* method, struct Thread* self);
85
Andy McFadden1e83b4d2010-07-15 17:20:24 -070086/*
87 * Unregister all JNI native methods associated with a class.
88 */
89void dvmUnregisterJNINativeMethods(ClassObject* clazz);
90
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080091//#define GET_ARG_LONG(_args, _elem) (*(s8*)(&(_args)[_elem]))
92#define GET_ARG_LONG(_args, _elem) dvmGetArgLong(_args, _elem)
93
94/*
95 * Helpful function for accessing long integers in "u4* args".
96 *
97 * We can't just return *(s8*)(&args[elem]), because that breaks if our
98 * architecture requires 64-bit alignment of 64-bit values.
99 *
100 * Big/little endian shouldn't matter here -- ordering of words within a
101 * long seems consistent across our supported platforms.
102 */
103INLINE s8 dvmGetArgLong(const u4* args, int elem)
104{
105#if 0
106 union { u4 parts[2]; s8 whole; } conv;
107 conv.parts[0] = args[elem];
108 conv.parts[1] = args[elem+1];
109 return conv.whole;
110#else
111 /* with gcc's optimizer, memcpy() turns into simpler assignments */
112 s8 val;
113 memcpy(&val, &args[elem], 8);
114 return val;
115#endif
116}
117
Elliott Hughes8afa9df2010-07-07 14:47:25 -0700118/*
119 * Used to implement -Xjnitrace.
120 */
121struct Thread;
Elliott Hughesde66fcb2010-07-30 13:34:49 -0700122void dvmLogNativeMethodEntry(const Method* method, const u4* newFp);
Elliott Hughes8afa9df2010-07-07 14:47:25 -0700123void dvmLogNativeMethodExit(const Method* method, struct Thread* self,
124 const JValue retval);
125
Carl Shapiroae188c62011-04-08 13:11:58 -0700126#ifdef __cplusplus
127}
128#endif
129
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800130#endif /*_DALVIK_NATIVE*/