home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / include / md / _freebsd.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.8 KB  |  181 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_freebsd_defs_h___
  20. #define nspr_freebsd_defs_h___
  21.  
  22. #include <sys/syscall.h>
  23.  
  24. #define PR_LINKER_ARCH    "freebsd"
  25. #define _PR_SI_SYSNAME  "FREEBSD"
  26. #define _PR_SI_ARCHITECTURE "x86"
  27. #define PR_DLL_SUFFIX        ".so.1.0"
  28.  
  29. #define _PR_VMBASE              0x30000000
  30. #define _PR_STACK_VMBASE    0x50000000
  31. #define _MD_DEFAULT_STACK_SIZE    65536L
  32. #define _MD_MMAP_FLAGS          MAP_PRIVATE
  33.  
  34. #undef  HAVE_STACK_GROWING_UP
  35. #define HAVE_DLL
  36. #define USE_DLFCN
  37.  
  38. #define USE_SETJMP
  39.  
  40. #ifndef _PR_PTHREADS
  41. #include <setjmp.h>
  42.  
  43. #define PR_CONTEXT_TYPE    sigjmp_buf
  44.  
  45. #define CONTEXT(_th) ((_th)->md.context)
  46.  
  47. #define _MD_GET_SP(_th)    (_th)->md.context[0]._sjb[2]
  48. #define PR_NUM_GCREGS    _JBLEN
  49.  
  50. /*
  51. ** Initialize a thread context to run "_main()" when started
  52. */
  53. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
  54. {  \
  55.     *status = PR_TRUE;  \
  56.     if (sigsetjmp(CONTEXT(_thread), 1)) {  \
  57.         _main();  \
  58.     }  \
  59.     _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
  60. }
  61.  
  62. #define _MD_SWITCH_CONTEXT(_thread)  \
  63.     if (!sigsetjmp(CONTEXT(_thread), 1)) {  \
  64.     (_thread)->md.errcode = errno;  \
  65.     _PR_Schedule();  \
  66.     }
  67.  
  68. /*
  69. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
  70. */
  71. #define _MD_RESTORE_CONTEXT(_thread) \
  72. {   \
  73.     errno = (_thread)->md.errcode;  \
  74.     _MD_SET_CURRENT_THREAD(_thread);  \
  75.     siglongjmp(CONTEXT(_thread), 1);  \
  76. }
  77.  
  78. /* Machine-dependent (MD) data structures */
  79.  
  80. struct _MDThread {
  81.     PR_CONTEXT_TYPE context;
  82.     int id;
  83.     int errcode;
  84. };
  85.  
  86. struct _MDThreadStack {
  87.     PRInt8 notused;
  88. };
  89.  
  90. struct _MDLock {
  91.     PRInt8 notused;
  92. };
  93.  
  94. struct _MDSemaphore {
  95.     PRInt8 notused;
  96. };
  97.  
  98. struct _MDCVar {
  99.     PRInt8 notused;
  100. };
  101.  
  102. struct _MDSegment {
  103.     PRInt8 notused;
  104. };
  105.  
  106. struct _MDCPU {
  107.     struct _MDCPU_Unix md_unix;
  108. };
  109.  
  110. #define _MD_INIT_LOCKS()
  111. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  112. #define _MD_FREE_LOCK(lock)
  113. #define _MD_LOCK(lock)
  114. #define _MD_UNLOCK(lock)
  115. #define _MD_INIT_IO()
  116. #define _MD_IOQ_LOCK()
  117. #define _MD_IOQ_UNLOCK()
  118.  
  119. #define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
  120. #define _MD_INIT_THREAD                 _MD_InitializeThread
  121. #define _MD_EXIT_THREAD(thread)
  122. #define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
  123. #define _MD_RESUME_THREAD(thread)       _MD_resume_thread
  124. #define _MD_CLEAN_THREAD(_thread)
  125.  
  126. #endif /* ! _PR_PTHREADS */
  127.  
  128. #define _MD_EARLY_INIT                  _MD_EarlyInit
  129. #define _MD_FINAL_INIT            _PR_UnixInit
  130. #define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
  131. #define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
  132.  
  133. /*
  134.  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
  135.  * unwrapped version.
  136.  */
  137. #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
  138.  
  139. #if defined(_PR_NEED_FAKE_POLL)
  140.  
  141. /*
  142.  * XXX: FreeBSD2 doesn't have poll(), but our pthreads code calls poll().
  143.  * As a temporary measure, I implemented a fake poll() using select().
  144.  * Here are the struct and macro definitions copied from sys/poll.h
  145.  * on Solaris 2.5.
  146.  */
  147.  
  148. struct pollfd {
  149.     int fd;
  150.     short events;
  151.     short revents;
  152. };
  153.  
  154. /* poll events */
  155.  
  156. #define    POLLIN        0x0001        /* fd is readable */
  157. #define    POLLPRI        0x0002        /* high priority info at fd */
  158. #define    POLLOUT        0x0004        /* fd is writeable (won't block) */
  159. #define    POLLRDNORM    0x0040        /* normal data is readable */
  160. #define    POLLWRNORM    POLLOUT
  161. #define    POLLRDBAND    0x0080        /* out-of-band data is readable */
  162. #define    POLLWRBAND    0x0100        /* out-of-band data is writeable */
  163.  
  164. #define    POLLNORM    POLLRDNORM
  165.  
  166. #define    POLLERR        0x0008        /* fd has error condition */
  167. #define    POLLHUP        0x0010        /* fd has been hung up on */
  168. #define    POLLNVAL    0x0020        /* invalid pollfd entry */
  169.  
  170. extern int poll(struct pollfd *, unsigned long, int);
  171.  
  172. #endif /* _PR_NEED_FAKE_POLL */
  173.  
  174. /* freebsd has INADDR_LOOPBACK defined, but in /usr/include/rpc/types.h, and I didn't
  175.    want to be including that.. */
  176. #ifndef INADDR_LOOPBACK
  177. #define INADDR_LOOPBACK         (u_long)0x7F000001
  178. #endif
  179.  
  180. #endif /* nspr_linux_defs_h___ */
  181.