duke@435: /* duke@435: * Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: /* duke@435: * HotSpot integration note: duke@435: * duke@435: * This is a consolidation of these two files: duke@435: * src/share/hpi/export/hpi.h 1.15 99/06/18 JDK1.3 beta build I duke@435: * src/share/hpi/export/dll.h 1.3 98/09/15 JDK1.3 beta build I duke@435: * from the classic VM. duke@435: * duke@435: * bool_t is a type in the classic VM, and we define it here, duke@435: * but in the future this should be a jboolean. duke@435: * duke@435: * The files are included verbatim expect for local includes removed from hpi.h. duke@435: */ duke@435: duke@435: #ifndef _JAVASOFT_HPI_H_ duke@435: #define _JAVASOFT_HPI_H_ duke@435: duke@435: #ifdef __cplusplus duke@435: extern "C" { duke@435: #endif duke@435: duke@435: /* A classic VMism that should become a jboolean. Fix in 1.2.1? */ duke@435: typedef enum { HPI_FALSE = 0, HPI_TRUE = 1 } bool_t; duke@435: duke@435: /* duke@435: * DLL.H: A common interface for helper DLLs loaded by the VM. duke@435: * Each library exports the main entry point "DLL_Initialize". Through duke@435: * that function the programmer can obtain a function pointer which has duke@435: * type "GetInterfaceFunc." Through the function pointer the programmer duke@435: * can obtain other interfaces supported in the DLL. duke@435: */ duke@435: typedef jint (JNICALL * GetInterfaceFunc) duke@435: (void **intfP, const char *name, jint ver); duke@435: duke@435: jint JNICALL DLL_Initialize(GetInterfaceFunc *, void *args); duke@435: duke@435: duke@435: /* duke@435: * Host Porting Interface. This defines the "porting layer" for duke@435: * POSIX.1 compliant operating systems. duke@435: */ duke@435: duke@435: /* duke@435: * memory allocations duke@435: */ duke@435: typedef struct { duke@435: /* duke@435: * Malloc must return a unique pointer if size == 0. duke@435: */ duke@435: void * (*Malloc)(size_t size); duke@435: void * (*Realloc)(void *ptr, size_t new_size); duke@435: /* duke@435: * Free must allow ptr == NULL to be a no-op. duke@435: */ duke@435: void (*Free)(void *ptr); duke@435: /* duke@435: * Calloc must return a unique pointer for if duke@435: * n_item == 0 || item_size == 0. duke@435: */ duke@435: void * (*Calloc)(size_t n_item, size_t item_size); duke@435: char * (*Strdup)(const char *str); duke@435: duke@435: void * (*MapMem)(size_t req_size, size_t *maped_size); duke@435: void * (*UnmapMem)(void *req_addr, size_t req_size, size_t *unmap_size); duke@435: /* duke@435: * CommitMem should round the ptr down to the nearest page and duke@435: * round the size up to the nearest page so that the committed duke@435: * region is at least as large as the requested region. duke@435: */ duke@435: void * (*CommitMem)(void *ptr, size_t size, size_t *actual); duke@435: /* duke@435: * sysDecommitMem should round the ptr up to the nearest page and duke@435: * round the size down to the nearest page so that the decommitted duke@435: * region is no greater than the requested region. duke@435: */ duke@435: void * (*DecommitMem)(void *ptr, size_t size, size_t *actual); duke@435: duke@435: #define HPI_PAGE_ALIGNMENT (64 * 1024) duke@435: duke@435: void * (*AllocBlock)(size_t size, void **headP); duke@435: void (*FreeBlock)(void *head); duke@435: } HPI_MemoryInterface; duke@435: duke@435: /* duke@435: * dynamic linking libraries duke@435: */ duke@435: typedef struct { duke@435: void (*BuildLibName)(char *buf, int buf_len, char *path, const char *name); duke@435: int (*BuildFunName)(char *name, int name_len, int arg_size, int en_idx); duke@435: duke@435: void * (*LoadLibrary)(const char *name, char *err_buf, int err_buflen); duke@435: void (*UnloadLibrary)(void *lib); duke@435: void * (*FindLibraryEntry)(void *lib, const char *name); duke@435: } HPI_LibraryInterface; duke@435: duke@435: typedef void (*signal_handler_t)(int sig, void *siginfo, void *context); duke@435: duke@435: #define HPI_SIG_DFL (signal_handler_t)0 duke@435: #define HPI_SIG_ERR (signal_handler_t)-1 duke@435: #define HPI_SIG_IGN (signal_handler_t)1 duke@435: duke@435: typedef struct { duke@435: char *name; /* name such as green/native threads. */ duke@435: int isMP; duke@435: } HPI_SysInfo; duke@435: duke@435: typedef struct { duke@435: HPI_SysInfo * (*GetSysInfo)(void); duke@435: long (*GetMilliTicks)(void); duke@435: jlong (*TimeMillis)(void); duke@435: duke@435: signal_handler_t (*Signal)(int sig, signal_handler_t handler); duke@435: void (*Raise)(int sig); duke@435: void (*SignalNotify)(int sig); duke@435: int (*SignalWait)(void); duke@435: duke@435: int (*Shutdown)(void); duke@435: duke@435: int (*SetLoggingLevel)(int level); duke@435: bool_t (*SetMonitoringOn)(bool_t on); duke@435: int (*GetLastErrorString)(char *buf, int len); duke@435: } HPI_SystemInterface; duke@435: duke@435: /* duke@435: * threads and monitors duke@435: */ duke@435: typedef struct sys_thread sys_thread_t; duke@435: typedef struct sys_mon sys_mon_t; duke@435: duke@435: #define HPI_OK 0 duke@435: #define HPI_ERR -1 duke@435: #define HPI_INTRPT -2 /* Operation was interrupted */ duke@435: #define HPI_TIMEOUT -3 /* A timer ran out */ duke@435: #define HPI_NOMEM -5 /* Ran out of memory */ duke@435: #define HPI_NORESOURCE -6 /* Ran out of some system resource */ duke@435: duke@435: /* There are three basic states: RUNNABLE, MONITOR_WAIT, and CONDVAR_WAIT. duke@435: * When the thread is suspended in any of these states, the duke@435: * HPI_THREAD_SUSPENDED bit will be set duke@435: */ duke@435: enum { duke@435: HPI_THREAD_RUNNABLE = 1, duke@435: HPI_THREAD_MONITOR_WAIT, duke@435: HPI_THREAD_CONDVAR_WAIT duke@435: }; duke@435: duke@435: #define HPI_MINIMUM_PRIORITY 1 duke@435: #define HPI_MAXIMUM_PRIORITY 10 duke@435: #define HPI_NORMAL_PRIORITY 5 duke@435: duke@435: #define HPI_THREAD_SUSPENDED 0x8000 duke@435: #define HPI_THREAD_INTERRUPTED 0x4000 duke@435: duke@435: typedef struct { duke@435: sys_thread_t *owner; duke@435: int entry_count; duke@435: sys_thread_t **monitor_waiters; duke@435: sys_thread_t **condvar_waiters; duke@435: int sz_monitor_waiters; duke@435: int sz_condvar_waiters; duke@435: int n_monitor_waiters; duke@435: int n_condvar_waiters; duke@435: } sys_mon_info; duke@435: duke@435: typedef struct { duke@435: int (*ThreadBootstrap)(sys_thread_t **tidP, duke@435: sys_mon_t **qlockP, duke@435: int nReservedBytes); duke@435: int (*ThreadCreate)(sys_thread_t **tidP, duke@435: long stk_size, duke@435: void (*func)(void *), duke@435: void *arg); duke@435: sys_thread_t * (*ThreadSelf)(void); duke@435: void (*ThreadYield)(void); duke@435: int (*ThreadSuspend)(sys_thread_t *tid); duke@435: int (*ThreadResume)(sys_thread_t *tid); duke@435: int (*ThreadSetPriority)(sys_thread_t *tid, int prio); duke@435: int (*ThreadGetPriority)(sys_thread_t *tid, int *prio); duke@435: void * (*ThreadStackPointer)(sys_thread_t *tid); duke@435: void * (*ThreadStackTop)(sys_thread_t *tid); duke@435: long * (*ThreadRegs)(sys_thread_t *tid, int *regs); duke@435: int (*ThreadSingle)(void); duke@435: void (*ThreadMulti)(void); duke@435: int (*ThreadEnumerateOver)(int (*func)(sys_thread_t *, void *), duke@435: void *arg); duke@435: int (*ThreadCheckStack)(void); duke@435: void (*ThreadPostException)(sys_thread_t *tid, void *arg); duke@435: void (*ThreadInterrupt)(sys_thread_t *tid); duke@435: int (*ThreadIsInterrupted)(sys_thread_t *tid, int clear); duke@435: int (*ThreadAlloc)(sys_thread_t **tidP); duke@435: int (*ThreadFree)(void); duke@435: jlong (*ThreadCPUTime)(void); duke@435: int (*ThreadGetStatus)(sys_thread_t *tid, sys_mon_t **monitor); duke@435: void * (*ThreadInterruptEvent)(void); duke@435: void * (*ThreadNativeID)(sys_thread_t *tid); duke@435: duke@435: /* These three functions are used by the CPU time profiler. duke@435: * sysThreadIsRunning determines whether the thread is running (not just duke@435: * runnable). It is only safe to call this function after calling duke@435: * sysThreadProfSuspend. duke@435: */ duke@435: bool_t (*ThreadIsRunning)(sys_thread_t *tid); duke@435: void (*ThreadProfSuspend)(sys_thread_t *tid); duke@435: void (*ThreadProfResume)(sys_thread_t *tid); duke@435: duke@435: int (*AdjustTimeSlice)(int ms); duke@435: duke@435: size_t (*MonitorSizeof)(void); duke@435: int (*MonitorInit)(sys_mon_t *mid); duke@435: int (*MonitorDestroy)(sys_mon_t *mid); duke@435: int (*MonitorEnter)(sys_thread_t *self, sys_mon_t *mid); duke@435: bool_t (*MonitorEntered)(sys_thread_t *self, sys_mon_t *mid); duke@435: int (*MonitorExit)(sys_thread_t *self, sys_mon_t *mid); duke@435: int (*MonitorNotify)(sys_thread_t *self, sys_mon_t *mid); duke@435: int (*MonitorNotifyAll)(sys_thread_t *self, sys_mon_t *mid); duke@435: int (*MonitorWait)(sys_thread_t *self, sys_mon_t *mid, jlong ms); duke@435: bool_t (*MonitorInUse)(sys_mon_t *mid); duke@435: sys_thread_t * (*MonitorOwner)(sys_mon_t *mid); duke@435: int (*MonitorGetInfo)(sys_mon_t *mid, sys_mon_info *info); duke@435: duke@435: } HPI_ThreadInterface; duke@435: duke@435: /* duke@435: * files duke@435: */ duke@435: duke@435: #define HPI_FILETYPE_REGULAR (0) duke@435: #define HPI_FILETYPE_DIRECTORY (1) duke@435: #define HPI_FILETYPE_OTHER (2) duke@435: duke@435: typedef struct { duke@435: char * (*NativePath)(char *path); duke@435: int (*FileType)(const char *path); duke@435: int (*Open)(const char *name, int openMode, int filePerm); duke@435: int (*Close)(int fd); duke@435: jlong (*Seek)(int fd, jlong offset, int whence); duke@435: int (*SetLength)(int fd, jlong length); duke@435: int (*Sync)(int fd); duke@435: int (*Available)(int fd, jlong *bytes); duke@435: size_t (*Read)(int fd, void *buf, unsigned int nBytes); duke@435: size_t (*Write)(int fd, const void *buf, unsigned int nBytes); duke@435: int (*FileSizeFD)(int fd, jlong *size); duke@435: } HPI_FileInterface; duke@435: duke@435: /* duke@435: * sockets duke@435: */ duke@435: struct sockaddr; duke@435: struct hostent; duke@435: duke@435: typedef struct { duke@435: int (*Close)(int fd); duke@435: long (*Available)(int fd, jint *pbytes); duke@435: int (*Connect)(int fd, struct sockaddr *him, int len); duke@435: int (*Accept)(int fd, struct sockaddr *him, int *len); duke@435: int (*SendTo)(int fd, char *buf, int len, int flags, duke@435: struct sockaddr *to, int tolen); duke@435: int (*RecvFrom)(int fd, char *buf, int nbytes, int flags, duke@435: struct sockaddr *from, int *fromlen); duke@435: int (*Listen)(int fd, long count); duke@435: int (*Recv)(int fd, char *buf, int nBytes, int flags); duke@435: int (*Send)(int fd, char *buf, int nBytes, int flags); duke@435: int (*Timeout)(int fd, long timeout); duke@435: struct hostent * (*GetHostByName)(char *hostname); duke@435: int (*Socket)(int domain, int type, int protocol); duke@435: int (*SocketShutdown)(int fd, int howto); duke@435: int (*Bind)(int fd, struct sockaddr *him, int len); duke@435: int (*GetSocketName)(int fd, struct sockaddr *him, int *len); duke@435: int (*GetHostName)(char *hostname, int namelen); duke@435: struct hostent * (*GetHostByAddr)(const char *hostname, int len, int type); duke@435: int (*SocketGetOption)(int fd, int level, int optname, char *optval, int *optlen); duke@435: int (*SocketSetOption)(int fd, int level, int optname, const char *optval, int optlen); duke@435: struct protoent * (*GetProtoByName)(char* name); duke@435: } HPI_SocketInterface; duke@435: duke@435: /* duke@435: * callbacks. duke@435: */ duke@435: typedef struct vm_calls { duke@435: int (*jio_fprintf)(FILE *fp, const char *fmt, ...); duke@435: void (*panic)(const char *fmt, ...); duke@435: void (*monitorRegister)(sys_mon_t *mid, char *info_str); duke@435: duke@435: void (*monitorContendedEnter)(sys_thread_t *self, sys_mon_t *mid); duke@435: void (*monitorContendedEntered)(sys_thread_t *self, sys_mon_t *mid); duke@435: void (*monitorContendedExit)(sys_thread_t *self, sys_mon_t *mid); duke@435: } vm_calls_t; duke@435: duke@435: #ifdef __cplusplus duke@435: } duke@435: #endif duke@435: duke@435: #endif /* !_JAVASOFT_HPI_H_ */