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 /* 26 * HotSpot integration note: 27 * 28 * This is a consolidation of these two files: 29 * src/share/hpi/export/hpi.h 1.15 99/06/18 JDK1.3 beta build I 30 * src/share/hpi/export/dll.h 1.3 98/09/15 JDK1.3 beta build I 31 * from the classic VM. 32 * 33 * bool_t is a type in the classic VM, and we define it here, 34 * but in the future this should be a jboolean. 35 * 36 * The files are included verbatim expect for local includes removed from hpi.h. 37 */ 38 39 #ifndef SHARE_VM_PRIMS_HPI_IMPORTED_H 40 #define SHARE_VM_PRIMS_HPI_IMPORTED_H 41 42 #include "jni.h" 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 /* A classic VMism that should become a jboolean. Fix in 1.2.1? */ 49 typedef enum { HPI_FALSE = 0, HPI_TRUE = 1 } bool_t; 50 51 /* 52 * DLL.H: A common interface for helper DLLs loaded by the VM. 53 * Each library exports the main entry point "DLL_Initialize". Through 54 * that function the programmer can obtain a function pointer which has 55 * type "GetInterfaceFunc." Through the function pointer the programmer 56 * can obtain other interfaces supported in the DLL. 57 */ 58 typedef jint (JNICALL * GetInterfaceFunc) 59 (void **intfP, const char *name, jint ver); 60 61 jint JNICALL DLL_Initialize(GetInterfaceFunc *, void *args); 62 63 64 /* 65 * Host Porting Interface. This defines the "porting layer" for 66 * POSIX.1 compliant operating systems. 67 */ 68 69 /* 70 * memory allocations 71 */ 72 typedef struct { 73 /* 74 * Malloc must return a unique pointer if size == 0. 75 */ 76 void * (*Malloc)(size_t size); 77 void * (*Realloc)(void *ptr, size_t new_size); 78 /* 79 * Free must allow ptr == NULL to be a no-op. 80 */ 81 void (*Free)(void *ptr); 82 /* 83 * Calloc must return a unique pointer for if 84 * n_item == 0 || item_size == 0. 85 */ 86 void * (*Calloc)(size_t n_item, size_t item_size); 87 char * (*Strdup)(const char *str); 88 89 void * (*MapMem)(size_t req_size, size_t *maped_size); 90 void * (*UnmapMem)(void *req_addr, size_t req_size, size_t *unmap_size); 91 /* 92 * CommitMem should round the ptr down to the nearest page and 93 * round the size up to the nearest page so that the committed 94 * region is at least as large as the requested region. 95 */ 96 void * (*CommitMem)(void *ptr, size_t size, size_t *actual); 97 /* 98 * sysDecommitMem should round the ptr up to the nearest page and 99 * round the size down to the nearest page so that the decommitted 100 * region is no greater than the requested region. 101 */ 102 void * (*DecommitMem)(void *ptr, size_t size, size_t *actual); 103 104 #define HPI_PAGE_ALIGNMENT (64 * 1024) 105 106 void * (*AllocBlock)(size_t size, void **headP); 107 void (*FreeBlock)(void *head); 108 } HPI_MemoryInterface; 109 110 /* 111 * dynamic linking libraries 112 */ 113 typedef struct { 114 void (*BuildLibName)(char *buf, int buf_len, char *path, const char *name); 115 int (*BuildFunName)(char *name, int name_len, int arg_size, int en_idx); 116 117 void * (*LoadLibrary)(const char *name, char *err_buf, int err_buflen); 118 void (*UnloadLibrary)(void *lib); 119 void * (*FindLibraryEntry)(void *lib, const char *name); 120 } HPI_LibraryInterface; 121 122 typedef void (*signal_handler_t)(int sig, void *siginfo, void *context); 123 124 #define HPI_SIG_DFL (signal_handler_t)0 125 #define HPI_SIG_ERR (signal_handler_t)-1 126 #define HPI_SIG_IGN (signal_handler_t)1 127 128 typedef struct { 129 char *name; /* name such as green/native threads. */ 130 int isMP; 131 } HPI_SysInfo; 132 133 typedef struct { 134 HPI_SysInfo * (*GetSysInfo)(void); 135 long (*GetMilliTicks)(void); 136 jlong (*TimeMillis)(void); 137 138 signal_handler_t (*Signal)(int sig, signal_handler_t handler); 139 void (*Raise)(int sig); 140 void (*SignalNotify)(int sig); 141 int (*SignalWait)(void); 142 143 int (*Shutdown)(void); 144 145 int (*SetLoggingLevel)(int level); 146 bool_t (*SetMonitoringOn)(bool_t on); 147 int (*GetLastErrorString)(char *buf, int len); 148 } HPI_SystemInterface; 149 150 /* 151 * threads and monitors 152 */ 153 typedef struct sys_thread sys_thread_t; 154 typedef struct sys_mon sys_mon_t; 155 156 #define HPI_OK 0 157 #define HPI_ERR -1 158 #define HPI_INTRPT -2 /* Operation was interrupted */ 159 #define HPI_TIMEOUT -3 /* A timer ran out */ 160 #define HPI_NOMEM -5 /* Ran out of memory */ 161 #define HPI_NORESOURCE -6 /* Ran out of some system resource */ 162 163 /* There are three basic states: RUNNABLE, MONITOR_WAIT, and CONDVAR_WAIT. 164 * When the thread is suspended in any of these states, the 165 * HPI_THREAD_SUSPENDED bit will be set 166 */ 167 enum { 168 HPI_THREAD_RUNNABLE = 1, 169 HPI_THREAD_MONITOR_WAIT, 170 HPI_THREAD_CONDVAR_WAIT 171 }; 172 173 #define HPI_MINIMUM_PRIORITY 1 174 #define HPI_MAXIMUM_PRIORITY 10 175 #define HPI_NORMAL_PRIORITY 5 176 177 #define HPI_THREAD_SUSPENDED 0x8000 178 #define HPI_THREAD_INTERRUPTED 0x4000 179 180 typedef struct { 181 sys_thread_t *owner; 182 int entry_count; 183 sys_thread_t **monitor_waiters; 184 sys_thread_t **condvar_waiters; 185 int sz_monitor_waiters; 186 int sz_condvar_waiters; 187 int n_monitor_waiters; 188 int n_condvar_waiters; 189 } sys_mon_info; 190 191 typedef struct { 192 int (*ThreadBootstrap)(sys_thread_t **tidP, 193 sys_mon_t **qlockP, 194 int nReservedBytes); 195 int (*ThreadCreate)(sys_thread_t **tidP, 196 long stk_size, 197 void (*func)(void *), 198 void *arg); 199 sys_thread_t * (*ThreadSelf)(void); 200 void (*ThreadYield)(void); 201 int (*ThreadSuspend)(sys_thread_t *tid); 202 int (*ThreadResume)(sys_thread_t *tid); 203 int (*ThreadSetPriority)(sys_thread_t *tid, int prio); 204 int (*ThreadGetPriority)(sys_thread_t *tid, int *prio); 205 void * (*ThreadStackPointer)(sys_thread_t *tid); 206 void * (*ThreadStackTop)(sys_thread_t *tid); 207 long * (*ThreadRegs)(sys_thread_t *tid, int *regs); 208 int (*ThreadSingle)(void); 209 void (*ThreadMulti)(void); 210 int (*ThreadEnumerateOver)(int (*func)(sys_thread_t *, void *), 211 void *arg); 212 int (*ThreadCheckStack)(void); 213 void (*ThreadPostException)(sys_thread_t *tid, void *arg); 214 void (*ThreadInterrupt)(sys_thread_t *tid); 215 int (*ThreadIsInterrupted)(sys_thread_t *tid, int clear); 216 int (*ThreadAlloc)(sys_thread_t **tidP); 217 int (*ThreadFree)(void); 218 jlong (*ThreadCPUTime)(void); 219 int (*ThreadGetStatus)(sys_thread_t *tid, sys_mon_t **monitor); 220 void * (*ThreadInterruptEvent)(void); 221 void * (*ThreadNativeID)(sys_thread_t *tid); 222 223 /* These three functions are used by the CPU time profiler. 224 * sysThreadIsRunning determines whether the thread is running (not just 225 * runnable). It is only safe to call this function after calling 226 * sysThreadProfSuspend. 227 */ 228 bool_t (*ThreadIsRunning)(sys_thread_t *tid); 229 void (*ThreadProfSuspend)(sys_thread_t *tid); 230 void (*ThreadProfResume)(sys_thread_t *tid); 231 232 int (*AdjustTimeSlice)(int ms); 233 234 size_t (*MonitorSizeof)(void); 235 int (*MonitorInit)(sys_mon_t *mid); 236 int (*MonitorDestroy)(sys_mon_t *mid); 237 int (*MonitorEnter)(sys_thread_t *self, sys_mon_t *mid); 238 bool_t (*MonitorEntered)(sys_thread_t *self, sys_mon_t *mid); 239 int (*MonitorExit)(sys_thread_t *self, sys_mon_t *mid); 240 int (*MonitorNotify)(sys_thread_t *self, sys_mon_t *mid); 241 int (*MonitorNotifyAll)(sys_thread_t *self, sys_mon_t *mid); 242 int (*MonitorWait)(sys_thread_t *self, sys_mon_t *mid, jlong ms); 243 bool_t (*MonitorInUse)(sys_mon_t *mid); 244 sys_thread_t * (*MonitorOwner)(sys_mon_t *mid); 245 int (*MonitorGetInfo)(sys_mon_t *mid, sys_mon_info *info); 246 247 } HPI_ThreadInterface; 248 249 /* 250 * files 251 */ 252 253 #define HPI_FILETYPE_REGULAR (0) 254 #define HPI_FILETYPE_DIRECTORY (1) 255 #define HPI_FILETYPE_OTHER (2) 256 257 typedef struct { 258 char * (*NativePath)(char *path); 259 int (*FileType)(const char *path); 260 int (*Open)(const char *name, int openMode, int filePerm); 261 int (*Close)(int fd); 262 jlong (*Seek)(int fd, jlong offset, int whence); 263 int (*SetLength)(int fd, jlong length); 264 int (*Sync)(int fd); 265 int (*Available)(int fd, jlong *bytes); 266 size_t (*Read)(int fd, void *buf, unsigned int nBytes); 267 size_t (*Write)(int fd, const void *buf, unsigned int nBytes); 268 int (*FileSizeFD)(int fd, jlong *size); 269 } HPI_FileInterface; 270 271 /* 272 * sockets 273 */ 274 struct sockaddr; 275 struct hostent; 276 277 typedef struct { 278 int (*Close)(int fd); 279 long (*Available)(int fd, jint *pbytes); 280 int (*Connect)(int fd, struct sockaddr *him, int len); 281 int (*Accept)(int fd, struct sockaddr *him, int *len); 282 int (*SendTo)(int fd, char *buf, int len, int flags, 283 struct sockaddr *to, int tolen); 284 int (*RecvFrom)(int fd, char *buf, int nbytes, int flags, 285 struct sockaddr *from, int *fromlen); 286 int (*Listen)(int fd, long count); 287 int (*Recv)(int fd, char *buf, int nBytes, int flags); 288 int (*Send)(int fd, char *buf, int nBytes, int flags); 289 int (*Timeout)(int fd, long timeout); 290 struct hostent * (*GetHostByName)(char *hostname); 291 int (*Socket)(int domain, int type, int protocol); 292 int (*SocketShutdown)(int fd, int howto); 293 int (*Bind)(int fd, struct sockaddr *him, int len); 294 int (*GetSocketName)(int fd, struct sockaddr *him, int *len); 295 int (*GetHostName)(char *hostname, int namelen); 296 struct hostent * (*GetHostByAddr)(const char *hostname, int len, int type); 297 int (*SocketGetOption)(int fd, int level, int optname, char *optval, int *optlen); 298 int (*SocketSetOption)(int fd, int level, int optname, const char *optval, int optlen); 299 struct protoent * (*GetProtoByName)(char* name); 300 } HPI_SocketInterface; 301 302 /* 303 * callbacks. 304 */ 305 typedef struct vm_calls { 306 int (*jio_fprintf)(FILE *fp, const char *fmt, ...); 307 void (*panic)(const char *fmt, ...); 308 void (*monitorRegister)(sys_mon_t *mid, char *info_str); 309 310 void (*monitorContendedEnter)(sys_thread_t *self, sys_mon_t *mid); 311 void (*monitorContendedEntered)(sys_thread_t *self, sys_mon_t *mid); 312 void (*monitorContendedExit)(sys_thread_t *self, sys_mon_t *mid); 313 } vm_calls_t; 314 315 #ifdef __cplusplus 316 } 317 #endif 318 319 #endif // SHARE_VM_PRIMS_HPI_IMPORTED_H