1 /* Copyright (C) 2014 The Android Open Source Project 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #define LOG_TAG "libcore" // We'll be next to "dalvikvm" in the log; make the distinction clear. 27 28 #include "cutils/log.h" 29 #include "JniConstants.h" 30 #include "ScopedLocalFrame.h" 31 32 #include <stdlib.h> 33 34 extern "C" { 35 36 extern void register_java_io_Console(JNIEnv* env); 37 extern void register_java_io_FileDescriptor(JNIEnv*); 38 extern void register_java_io_FileInputStream(JNIEnv*); 39 extern void register_java_io_FileOutputStream(JNIEnv*); 40 extern void register_java_io_FileSystem(JNIEnv*); 41 extern void register_java_io_ObjectInputStream(JNIEnv*); 42 extern void register_java_io_ObjectOutputStream(JNIEnv*); 43 extern void register_java_io_ObjectStreamClass(JNIEnv*); 44 extern void register_java_io_UnixFileSystem(JNIEnv*); 45 extern void register_java_lang_Double(JNIEnv*); 46 extern void register_java_lang_Float(JNIEnv*); 47 extern void register_java_lang_ProcessEnvironment(JNIEnv*); 48 extern void register_java_lang_Runtime(JNIEnv*); 49 extern void register_java_lang_Shutdown(JNIEnv*); 50 extern void register_java_lang_StrictMath(JNIEnv*); 51 extern void register_java_lang_Math(JNIEnv*); 52 extern void register_java_lang_System(JNIEnv*); 53 extern void register_java_lang_Thread(JNIEnv*); 54 extern void register_java_lang_UNIXProcess(JNIEnv*); 55 extern void register_java_net_DatagramPacket(JNIEnv*); 56 extern void register_java_net_Inet4Address(JNIEnv*); 57 extern void register_java_net_Inet6Address(JNIEnv*); 58 extern void register_java_net_Inet6AddressImpl(JNIEnv*); 59 extern void register_java_net_InetAddress(JNIEnv*); 60 extern void register_java_net_NetworkInterface(JNIEnv*); 61 extern void register_java_net_PlainDatagramSocketImpl(JNIEnv*); 62 extern void register_java_net_PlainSocketImpl(JNIEnv*); 63 extern void register_java_net_SocketInputStream(JNIEnv*); 64 extern void register_java_net_SocketOutputStream(JNIEnv*); 65 extern void register_java_nio_Bits(JNIEnv* env); 66 extern void register_java_nio_MappedByteBuffer(JNIEnv* env); 67 extern void register_java_util_zip_Adler32(JNIEnv* env); 68 extern void register_java_util_zip_CRC32(JNIEnv*); 69 extern void register_java_util_zip_Deflater(JNIEnv*); 70 extern void register_java_util_zip_Inflater(JNIEnv*); 71 extern void register_java_util_zip_ZipFile(JNIEnv*); 72 extern void register_java_util_prefs_FileSystemPreferences(JNIEnv*); 73 extern void register_sun_nio_ch_DatagramChannelImpl(JNIEnv*); 74 extern void register_sun_nio_ch_DatagramDispatcher(JNIEnv*); 75 extern void register_sun_nio_ch_FileChannelImpl(JNIEnv*); 76 extern void register_sun_nio_ch_FileDispatcherImpl(JNIEnv*); 77 extern void register_sun_nio_ch_FileKey(JNIEnv*); 78 extern void register_sun_nio_ch_IOUtil(JNIEnv*); 79 extern void register_sun_nio_ch_NativeThread(JNIEnv*); 80 extern void register_sun_nio_ch_Net(JNIEnv*); 81 extern void register_sun_nio_ch_ServerSocketChannelImpl(JNIEnv* env); 82 extern void register_sun_nio_ch_SocketChannelImpl(JNIEnv* env); 83 extern void register_sun_nio_ch_InheritedChannel(JNIEnv* env); 84 extern void register_sun_nio_ch_PollArrayWrapper(JNIEnv* env); 85 86 extern jint net_JNI_OnLoad(JavaVM*, void*); 87 88 } 89 90 extern void register_java_lang_Character(JNIEnv*); 91 92 // DalvikVM calls this on startup, so we can statically register all our native methods. 93 jint JNI_OnLoad(JavaVM* vm, void*) { JNIEnv* env; 94 if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { 95 ALOGE("JavaVM::GetEnv() failed"); 96 abort(); 97 } 98 99 ScopedLocalFrame localFrame(env); 100 register_java_util_zip_ZipFile(env); 101 register_java_util_zip_Inflater(env); 102 register_java_util_zip_Deflater(env); 103 register_java_util_zip_CRC32(env); 104 register_java_util_zip_Adler32(env); 105 register_java_io_FileSystem(env); 106 register_sun_nio_ch_IOUtil(env); 107 register_sun_nio_ch_FileChannelImpl(env); 108 register_sun_nio_ch_FileDispatcherImpl(env); 109 register_java_io_Console(env); 110 register_java_io_FileOutputStream(env); 111 register_java_io_FileInputStream(env); 112 register_java_io_FileDescriptor(env); 113 register_java_io_ObjectInputStream(env); 114 register_java_io_ObjectOutputStream(env); 115 register_java_io_UnixFileSystem(env); 116 register_sun_nio_ch_NativeThread(env); 117 register_sun_nio_ch_FileKey(env); 118 register_java_io_ObjectStreamClass(env); 119 register_java_lang_Character(env); 120 register_java_lang_Float(env); 121 register_java_lang_Double(env); 122 register_java_lang_StrictMath(env); 123 register_java_lang_Math(env); 124 register_java_lang_ProcessEnvironment(env); 125 register_java_lang_Runtime(env); 126 register_java_lang_System(env); 127 register_java_lang_Shutdown(env); 128 register_java_lang_UNIXProcess(env); 129 // register_java_net_InetAddress depends on java_lang_Float & Math being 130 // fully registered (getMethodId on InetAddress class triggers its 131 // <clinit> which depends on java.lang.Float) 132 register_java_net_InetAddress(env); 133 register_java_net_Inet4Address(env); 134 register_java_net_Inet6Address(env); 135 register_java_net_PlainSocketImpl(env); 136 register_java_net_PlainDatagramSocketImpl(env); 137 register_java_net_NetworkInterface(env); 138 register_java_net_DatagramPacket(env); 139 register_java_net_Inet6AddressImpl(env); 140 register_java_net_SocketInputStream(env); 141 register_java_net_SocketOutputStream(env); 142 register_java_nio_Bits(env); 143 register_java_util_prefs_FileSystemPreferences(env); 144 register_sun_nio_ch_ServerSocketChannelImpl(env); 145 register_sun_nio_ch_SocketChannelImpl(env); 146 register_sun_nio_ch_InheritedChannel(env); 147 register_sun_nio_ch_Net(env); 148 register_sun_nio_ch_DatagramChannelImpl(env); 149 register_sun_nio_ch_DatagramDispatcher(env); 150 register_sun_nio_ch_PollArrayWrapper(env); 151 register_java_nio_MappedByteBuffer(env); 152 net_JNI_OnLoad(vm, NULL); 153 return JNI_VERSION_1_6; 154 } 155