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