| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 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 |
| 23 | #define _DALVIK_NATIVE |
| 24 | |
| Carl Shapiro | ae188c6 | 2011-04-08 13:11:58 -0700 | [diff] [blame] | 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 29 | /* |
| 30 | * Method description; equivalent to a JNI struct. |
| 31 | */ |
| 32 | typedef 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 | */ |
| 41 | typedef struct DalvikNativeClass { |
| 42 | const char* classDescriptor; |
| 43 | const DalvikNativeMethod* methodInfo; |
| 44 | u4 classDescriptorHash; /* initialized at runtime */ |
| 45 | } DalvikNativeClass; |
| 46 | |
| 47 | |
| 48 | /* init/shutdown */ |
| 49 | bool dvmNativeStartup(void); |
| 50 | void dvmNativeShutdown(void); |
| 51 | |
| 52 | |
| 53 | /* |
| 54 | * Convert argc/argv into a function call. This is platform-specific. |
| 55 | */ |
| 56 | void 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 | */ |
| 62 | u4 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 | */ |
| 68 | char* dvmCreateSystemLibraryName(char* libName); |
| 69 | //void dvmLoadNativeLibrary(StringObject* libNameObj, Object* classLoader); |
| Elliott Hughes | f584b4a | 2010-09-30 15:51:31 -0700 | [diff] [blame] | 70 | bool dvmLoadNativeCode(const char* fileName, Object* classLoader, |
| 71 | char** detail); |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 72 | |
| 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 | */ |
| 83 | void dvmResolveNativeMethod(const u4* args, JValue* pResult, |
| 84 | const Method* method, struct Thread* self); |
| 85 | |
| Andy McFadden | 1e83b4d | 2010-07-15 17:20:24 -0700 | [diff] [blame] | 86 | /* |
| 87 | * Unregister all JNI native methods associated with a class. |
| 88 | */ |
| 89 | void dvmUnregisterJNINativeMethods(ClassObject* clazz); |
| 90 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 91 | //#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 | */ |
| 103 | INLINE 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 Hughes | 8afa9df | 2010-07-07 14:47:25 -0700 | [diff] [blame] | 118 | /* |
| 119 | * Used to implement -Xjnitrace. |
| 120 | */ |
| 121 | struct Thread; |
| Elliott Hughes | de66fcb | 2010-07-30 13:34:49 -0700 | [diff] [blame] | 122 | void dvmLogNativeMethodEntry(const Method* method, const u4* newFp); |
| Elliott Hughes | 8afa9df | 2010-07-07 14:47:25 -0700 | [diff] [blame] | 123 | void dvmLogNativeMethodExit(const Method* method, struct Thread* self, |
| 124 | const JValue retval); |
| 125 | |
| Carl Shapiro | ae188c6 | 2011-04-08 13:11:58 -0700 | [diff] [blame] | 126 | #ifdef __cplusplus |
| 127 | } |
| 128 | #endif |
| 129 | |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 130 | #endif /*_DALVIK_NATIVE*/ |