1 /*
   2  * Copyright (c) 1998, 2010, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "prims/jvm.h"
  27 #include "runtime/hpi.hpp"
  28 
  29 extern "C" {
  30   static void unimplemented_panic(const char *fmt, ...) {
  31     // mitigate testing damage from bug 6626677
  32     warning("hpi::unimplemented_panic called");
  33   }
  34 
  35   static void unimplemented_monitorRegister(sys_mon_t *mid, char *info_str) {
  36     Unimplemented();
  37   }
  38 }
  39 
  40 static vm_calls_t callbacks = {
  41   jio_fprintf,
  42   unimplemented_panic,
  43   unimplemented_monitorRegister,
  44 
  45   NULL, // unused
  46   NULL, // unused
  47   NULL  // unused
  48 };
  49 
  50 GetInterfaceFunc        hpi::_get_interface = NULL;
  51 HPI_FileInterface*      hpi::_file          = NULL;
  52 HPI_SocketInterface*    hpi::_socket        = NULL;
  53 HPI_LibraryInterface*   hpi::_library       = NULL;
  54 HPI_SystemInterface*    hpi::_system        = NULL;
  55 
  56 jint hpi::initialize()
  57 {
  58   initialize_get_interface(&callbacks);
  59   if (_get_interface == NULL)
  60     return JNI_ERR;
  61 
  62   jint result;
  63 
  64   result = (*_get_interface)((void **)&_file, "File", 1);
  65   if (result != 0) {
  66     if (TraceHPI) tty->print_cr("Can't find HPI_FileInterface");
  67     return JNI_ERR;
  68   }
  69 
  70 
  71   result = (*_get_interface)((void **)&_library, "Library", 1);
  72   if (result != 0) {
  73     if (TraceHPI) tty->print_cr("Can't find HPI_LibraryInterface");
  74     return JNI_ERR;
  75   }
  76 
  77   result = (*_get_interface)((void **)&_system, "System", 1);
  78   if (result != 0) {
  79     if (TraceHPI) tty->print_cr("Can't find HPI_SystemInterface");
  80     return JNI_ERR;
  81   }
  82 
  83   return JNI_OK;
  84 }
  85 
  86 jint hpi::initialize_socket_library()
  87 {
  88   if (_get_interface == NULL) {
  89     if (TraceHPI) {
  90       tty->print_cr("Fatal HPI error: reached initialize_socket_library with NULL _get_interface");
  91     }
  92     return JNI_ERR;
  93   }
  94 
  95   jint result;
  96   result = (*_get_interface)((void **)&_socket, "Socket", 1);
  97   if (result != 0) {
  98     if (TraceHPI) tty->print_cr("Can't find HPI_SocketInterface");
  99     return JNI_ERR;
 100   }
 101 
 102   return JNI_OK;
 103 }