home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / md / _sunos4.h < prev    next >
C/C++ Source or Header  |  1998-11-02  |  6KB  |  218 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef nspr_sunos_defs_h___
  20. #define nspr_sunos_defs_h___
  21.  
  22. #include "md/sunos4.h"
  23.  
  24. /* On SunOS 4, memset is declared in memory.h */
  25. #include <memory.h>
  26. #include <errno.h>
  27. #include <sys/syscall.h>
  28.  
  29. /*
  30.  * Internal configuration macros
  31.  */
  32.  
  33. #define PR_LINKER_ARCH    "sunos"
  34. #define _PR_SI_SYSNAME    "SUNOS"
  35. #define _PR_SI_ARCHITECTURE "sparc"
  36. #define PR_DLL_SUFFIX        ".so.1.0"
  37.  
  38. /*
  39. ** For sunos type machines, don't specify an address because the
  40. ** NetBSD/SPARC O.S. does the wrong thing.
  41. */
  42. #define _PR_VMBASE        0x30000000
  43. #define _PR_STACK_VMBASE    0x50000000
  44. #define _MD_DEFAULT_STACK_SIZE    65536L
  45. #define _MD_MMAP_FLAGS          MAP_PRIVATE
  46.  
  47. #undef  HAVE_STACK_GROWING_UP
  48. #undef    HAVE_WEAK_IO_SYMBOLS
  49. #undef    HAVE_WEAK_MALLOC_SYMBOLS
  50. #define    HAVE_DLL
  51. #define    USE_DLFCN
  52. #define NEED_STRFTIME_LOCK
  53. #define NEED_TIME_R
  54. #define HAVE_BSD_FLOCK
  55. #define _PR_NO_LARGE_FILES
  56. #define _PR_STAT_HAS_ONLY_ST_ATIME
  57.  
  58. #define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
  59. #define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
  60.  
  61. #define USE_SETJMP
  62.  
  63. #include <setjmp.h>
  64.  
  65. #define _MD_GET_SP(_t)    (_t)->md.context[2]
  66.  
  67. #define PR_NUM_GCREGS    _JBLEN
  68.  
  69. #define CONTEXT(_th) ((_th)->md.context)
  70.  
  71. /*
  72. ** Initialize the thread context preparing it to execute _main.
  73. */
  74. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)          \
  75.     PR_BEGIN_MACRO                      \
  76.     int *context = (_thread)->md.context;          \
  77.         *status = PR_TRUE;              \
  78.     asm("ta 3");                    \
  79.     (void) setjmp(context);                  \
  80.     (_thread)->md.context[2] = (int) ((_sp) - 64); \
  81.     (_thread)->md.context[2] &= ~7;        \
  82.     (_thread)->md.context[3] = (int) _main;  \
  83.     (_thread)->md.context[4] = (int) _main + 4;  \
  84.     PR_END_MACRO
  85.  
  86. #define _MD_SWITCH_CONTEXT(_thread)  \
  87.     asm("ta 3");            \
  88.     if (!setjmp(CONTEXT(_thread))) { \
  89.     (_thread)->md.errcode = errno;  \
  90.     _PR_Schedule();             \
  91.     }
  92.  
  93. /*
  94. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
  95. */
  96. #define _MD_RESTORE_CONTEXT(_thread) \
  97. {                     \
  98.     errno = (_thread)->md.errcode;         \
  99.     _MD_SET_CURRENT_THREAD(_thread);     \
  100.     longjmp(CONTEXT(_thread), 1);    \
  101. }
  102.  
  103. #pragma unknown_control_flow(longjmp)
  104. #pragma unknown_control_flow(setjmp)
  105. #pragma unknown_control_flow(_PR_Schedule)
  106.  
  107. /*
  108. ** Missing function prototypes
  109. */
  110.  
  111. extern int socket (int domain, int type, int protocol);
  112. extern int getsockname (int s, struct sockaddr *name, int *namelen);
  113. extern int getpeername (int s, struct sockaddr *name, int *namelen);
  114. extern int getsockopt (int s, int level, int optname, char* optval, int* optlen);
  115. extern int setsockopt (int s, int level, int optname, const char* optval, int optlen);
  116. extern int accept (int s, struct sockaddr *addr, int *addrlen);
  117. extern int listen (int s, int backlog);
  118. extern int brk(void *);
  119. extern void *sbrk(int);
  120.  
  121.  
  122. /* Machine-dependent (MD) data structures.  SunOS 4 has no native threads. */
  123.  
  124. struct _MDThread {
  125.     jmp_buf context;
  126.     int id;
  127.     int errcode;
  128. };
  129.  
  130. struct _MDThreadStack {
  131.     PRInt8 notused;
  132. };
  133.  
  134. struct _MDLock {
  135.     PRInt8 notused;
  136. };
  137.  
  138. struct _MDSemaphore {
  139.     PRInt8 notused;
  140. };
  141.  
  142. struct _MDCVar {
  143.     PRInt8 notused;
  144. };
  145.  
  146. struct _MDSegment {
  147.     PRInt8 notused;
  148. };
  149.  
  150. /*
  151.  * md-specific cpu structure field
  152.  */
  153. #define _PR_MD_MAX_OSFD FD_SETSIZE
  154.  
  155. struct _MDCPU_Unix {
  156.     PRCList ioQ;
  157.     PRUint32 ioq_timeout;
  158.     PRInt32 ioq_max_osfd;
  159.     PRInt32 ioq_osfd_cnt;
  160. #ifndef _PR_USE_POLL
  161.     fd_set fd_read_set, fd_write_set, fd_exception_set;
  162.     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
  163.                 fd_exception_cnt[_PR_MD_MAX_OSFD];
  164. #else
  165.     struct pollfd *ioq_pollfds;
  166.     int ioq_pollfds_size;
  167. #endif    /* _PR_USE_POLL */
  168. };
  169.  
  170. #define _PR_IOQ(_cpu)            ((_cpu)->md.md_unix.ioQ)
  171. #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
  172. #define _PR_FD_READ_SET(_cpu)        ((_cpu)->md.md_unix.fd_read_set)
  173. #define _PR_FD_READ_CNT(_cpu)        ((_cpu)->md.md_unix.fd_read_cnt)
  174. #define _PR_FD_WRITE_SET(_cpu)        ((_cpu)->md.md_unix.fd_write_set)
  175. #define _PR_FD_WRITE_CNT(_cpu)        ((_cpu)->md.md_unix.fd_write_cnt)
  176. #define _PR_FD_EXCEPTION_SET(_cpu)    ((_cpu)->md.md_unix.fd_exception_set)
  177. #define _PR_FD_EXCEPTION_CNT(_cpu)    ((_cpu)->md.md_unix.fd_exception_cnt)
  178. #define _PR_IOQ_TIMEOUT(_cpu)        ((_cpu)->md.md_unix.ioq_timeout)
  179. #define _PR_IOQ_MAX_OSFD(_cpu)        ((_cpu)->md.md_unix.ioq_max_osfd)
  180. #define _PR_IOQ_OSFD_CNT(_cpu)        ((_cpu)->md.md_unix.ioq_osfd_cnt)
  181. #define _PR_IOQ_POLLFDS(_cpu)        ((_cpu)->md.md_unix.ioq_pollfds)
  182. #define _PR_IOQ_POLLFDS_SIZE(_cpu)    ((_cpu)->md.md_unix.ioq_pollfds_size)
  183.  
  184. #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)    32
  185.  
  186. struct _MDCPU {
  187.     struct _MDCPU_Unix md_unix;
  188. };
  189.  
  190. #define _MD_INIT_LOCKS()
  191. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  192. #define _MD_FREE_LOCK(lock)
  193. #define _MD_LOCK(lock)
  194. #define _MD_UNLOCK(lock)
  195. #define _MD_INIT_IO()
  196. #define _MD_IOQ_LOCK()
  197. #define _MD_IOQ_UNLOCK()
  198.  
  199. /* These are copied from _solaris.h */
  200.  
  201. #define _MD_EARLY_INIT          _MD_EarlyInit
  202. #define _MD_FINAL_INIT            _PR_UnixInit
  203. #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
  204. #define _MD_INIT_THREAD         _MD_InitializeThread
  205. #define _MD_EXIT_THREAD(thread)
  206. #define    _MD_SUSPEND_THREAD(thread)
  207. #define    _MD_RESUME_THREAD(thread)
  208. #define _MD_CLEAN_THREAD(_thread)
  209.  
  210. /*
  211.  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
  212.  * unwrapped version.
  213.  */
  214. #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
  215. #define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
  216.  
  217. #endif /* nspr_sparc_defs_h___ */
  218.