home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / j2sdk / files / linux / j2sdklin.bin / jdk1.3.1 / include-old / hpi.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-06  |  9.5 KB  |  281 lines

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