1 /* src/native/vm/openjdk/hpi.c - HotSpot HPI interface functions
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 /* We include hpi_md.h before hpi.h as the latter includes the
31 #include INCLUDE_HPI_MD_H
32 #include INCLUDE_HPI_H
34 #include "mm/memory.h"
36 #include "native/jni.h"
37 #include "native/native.h"
39 #include "native/vm/openjdk/hpi.h"
41 #include "vm/properties.h"
44 #include "vmcore/options.h"
45 #include "vmcore/os.hpp"
46 #include "vmcore/utf8.h"
49 /* VM callback functions ******************************************************/
51 static vm_calls_t callbacks = {
52 /* TODO What should we use here? */
54 /* unimplemented_panic, */
55 /* unimplemented_monitorRegister, */
66 /* HPI interfaces *************************************************************/
68 GetInterfaceFunc hpi_get_interface = NULL;
69 HPI_FileInterface *hpi_file = NULL;
70 HPI_SocketInterface *hpi_socket = NULL;
71 HPI_LibraryInterface *hpi_library = NULL;
72 HPI_SystemInterface *hpi_system = NULL;
75 /* hpi_initialize **************************************************************
77 Initialize the Host Porting Interface (HPI).
79 *******************************************************************************/
81 void hpi_initialize(void)
83 const char* boot_library_path;
91 jint (JNICALL * DLL_Initialize)(GetInterfaceFunc *, void *);
93 TRACESUBSYSTEMINITIALIZATION("hpi_init");
97 boot_library_path = properties_get("sun.boot.library.path");
100 os_strlen(boot_library_path) +
101 os_strlen("/native_threads/libhpi.so") +
106 os_strcpy(p, boot_library_path);
107 os_strcat(p, "/native_threads/libhpi.so");
112 log_println("hpi_init: Loading HPI %s ", p);
116 handle = native_library_open(u);
120 vm_abort("hpi_init: HPI open failed");
122 /* Resolve the DLL_Initialize function from the library. */
124 dll_initialize = os_dlsym(handle, "DLL_Initialize");
126 DLL_Initialize = (jint (JNICALL *)(GetInterfaceFunc *, void *)) (intptr_t) dll_initialize;
128 if (opt_TraceHPI && DLL_Initialize == NULL)
129 log_println("hpi_init: HPI dlsym of DLL_Initialize failed: %s", os_dlerror());
131 if (DLL_Initialize == NULL ||
132 (*DLL_Initialize)(&hpi_get_interface, &callbacks) < 0) {
135 vm_abort("hpi_init: HPI DLL_Initialize failed");
138 native_library_add(u, NULL, handle);
141 log_println("hpi_init: HPI loaded successfully");
143 /* Resolve the interfaces. */
144 /* NOTE: The intptr_t-case is only to prevent the a compiler
145 warning with -O2: warning: dereferencing type-punned pointer
146 will break strict-aliasing rules */
148 result = (*hpi_get_interface)((void **) (intptr_t) &hpi_file, "File", 1);
151 vm_abort("hpi_init: Can't find HPI_FileInterface");
153 result = (*hpi_get_interface)((void **) (intptr_t) &hpi_library, "Library", 1);
156 vm_abort("hpi_init: Can't find HPI_LibraryInterface");
158 result = (*hpi_get_interface)((void **) (intptr_t) &hpi_system, "System", 1);
161 vm_abort("hpi_init: Can't find HPI_SystemInterface");
165 /* hpi_initialize_socket_library ***********************************************
167 Initialize the library Host Porting Interface (HPI).
169 *******************************************************************************/
171 int hpi_initialize_socket_library(void)
175 /* Resolve the socket library interface. */
177 result = (*hpi_get_interface)((void **) (intptr_t) &hpi_socket, "Socket", 1);
181 log_println("hpi_initialize_socket_library: Can't find HPI_SocketInterface");
191 * These are local overrides for various environment variables in Emacs.
192 * Please do not remove this and leave it at the end of the file, where
193 * Emacs will automagically detect them.
194 * ---------------------------------------------------------------------
197 * indent-tabs-mode: t
201 * vim:noexpandtab:sw=4:ts=4: