home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / md / _freebsd.h < prev    next >
C/C++ Source or Header  |  1998-11-21  |  6KB  |  220 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 "prthread.h"
  23.  
  24. #include <sys/syscall.h>
  25.  
  26. #define PR_LINKER_ARCH    "freebsd"
  27. #define _PR_SI_SYSNAME  "FREEBSD"
  28. #define _PR_SI_ARCHITECTURE "x86"
  29. #if defined(__ELF__)
  30. #define PR_DLL_SUFFIX          ".so"
  31. #else
  32. #define PR_DLL_SUFFIX          ".so.1.0"
  33. #endif
  34.  
  35. #define _PR_VMBASE              0x30000000
  36. #define _PR_STACK_VMBASE    0x50000000
  37. #define _MD_DEFAULT_STACK_SIZE    65536L
  38. #define _MD_MMAP_FLAGS          MAP_PRIVATE
  39.  
  40. #undef  HAVE_STACK_GROWING_UP
  41. #define HAVE_DLL
  42. #define USE_DLFCN
  43. #define _PR_HAVE_SOCKADDR_LEN
  44. #define _PR_STAT_HAS_ST_ATIMESPEC
  45. #define _PR_NO_LARGE_FILES
  46. #if ( __FreeBSD__ > 2 )
  47. #define _PR_POLL_AVAILABLE
  48. #define _PR_USE_POLL
  49. #endif
  50.  
  51. #define USE_SETJMP
  52.  
  53. #ifndef _PR_PTHREADS
  54. #include <setjmp.h>
  55.  
  56. #define PR_CONTEXT_TYPE    sigjmp_buf
  57.  
  58. #define CONTEXT(_th) ((_th)->md.context)
  59.  
  60. #define _MD_GET_SP(_th)    (_th)->md.context[0]._sjb[2]
  61. #define PR_NUM_GCREGS    _JBLEN
  62.  
  63. /*
  64. ** Initialize a thread context to run "_main()" when started
  65. */
  66. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
  67. {  \
  68.     *status = PR_TRUE;  \
  69.     if (sigsetjmp(CONTEXT(_thread), 1)) {  \
  70.         _main();  \
  71.     }  \
  72.     _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
  73. }
  74.  
  75. #define _MD_SWITCH_CONTEXT(_thread)  \
  76.     if (!sigsetjmp(CONTEXT(_thread), 1)) {  \
  77.     (_thread)->md.errcode = errno;  \
  78.     _PR_Schedule();  \
  79.     }
  80.  
  81. /*
  82. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
  83. */
  84. #define _MD_RESTORE_CONTEXT(_thread) \
  85. {   \
  86.     errno = (_thread)->md.errcode;  \
  87.     _MD_SET_CURRENT_THREAD(_thread);  \
  88.     siglongjmp(CONTEXT(_thread), 1);  \
  89. }
  90.  
  91. /* Machine-dependent (MD) data structures */
  92.  
  93. struct _MDThread {
  94.     PR_CONTEXT_TYPE context;
  95.     int id;
  96.     int errcode;
  97. };
  98.  
  99. struct _MDThreadStack {
  100.     PRInt8 notused;
  101. };
  102.  
  103. struct _MDLock {
  104.     PRInt8 notused;
  105. };
  106.  
  107. struct _MDSemaphore {
  108.     PRInt8 notused;
  109. };
  110.  
  111. struct _MDCVar {
  112.     PRInt8 notused;
  113. };
  114.  
  115. struct _MDSegment {
  116.     PRInt8 notused;
  117. };
  118.  
  119. /*
  120.  * md-specific cpu structure field
  121.  */
  122. #define _PR_MD_MAX_OSFD FD_SETSIZE
  123.  
  124. struct _MDCPU_Unix {
  125.     PRCList ioQ;
  126.     PRUint32 ioq_timeout;
  127.     PRInt32 ioq_max_osfd;
  128.     PRInt32 ioq_osfd_cnt;
  129. #ifndef _PR_USE_POLL
  130.     fd_set fd_read_set, fd_write_set, fd_exception_set;
  131.     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
  132.                 fd_exception_cnt[_PR_MD_MAX_OSFD];
  133. #else
  134.     struct pollfd *ioq_pollfds;
  135.     int ioq_pollfds_size;
  136. #endif    /* _PR_USE_POLL */
  137. };
  138.  
  139. #define _PR_IOQ(_cpu)            ((_cpu)->md.md_unix.ioQ)
  140. #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
  141. #define _PR_FD_READ_SET(_cpu)        ((_cpu)->md.md_unix.fd_read_set)
  142. #define _PR_FD_READ_CNT(_cpu)        ((_cpu)->md.md_unix.fd_read_cnt)
  143. #define _PR_FD_WRITE_SET(_cpu)        ((_cpu)->md.md_unix.fd_write_set)
  144. #define _PR_FD_WRITE_CNT(_cpu)        ((_cpu)->md.md_unix.fd_write_cnt)
  145. #define _PR_FD_EXCEPTION_SET(_cpu)    ((_cpu)->md.md_unix.fd_exception_set)
  146. #define _PR_FD_EXCEPTION_CNT(_cpu)    ((_cpu)->md.md_unix.fd_exception_cnt)
  147. #define _PR_IOQ_TIMEOUT(_cpu)        ((_cpu)->md.md_unix.ioq_timeout)
  148. #define _PR_IOQ_MAX_OSFD(_cpu)        ((_cpu)->md.md_unix.ioq_max_osfd)
  149. #define _PR_IOQ_OSFD_CNT(_cpu)        ((_cpu)->md.md_unix.ioq_osfd_cnt)
  150. #define _PR_IOQ_POLLFDS(_cpu)        ((_cpu)->md.md_unix.ioq_pollfds)
  151. #define _PR_IOQ_POLLFDS_SIZE(_cpu)    ((_cpu)->md.md_unix.ioq_pollfds_size)
  152.  
  153. #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)    32
  154.  
  155. struct _MDCPU {
  156.     struct _MDCPU_Unix md_unix;
  157. };
  158.  
  159. #define _MD_INIT_LOCKS()
  160. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  161. #define _MD_FREE_LOCK(lock)
  162. #define _MD_LOCK(lock)
  163. #define _MD_UNLOCK(lock)
  164. #define _MD_INIT_IO()
  165. #define _MD_IOQ_LOCK()
  166. #define _MD_IOQ_UNLOCK()
  167.  
  168. extern PRStatus _MD_InitializeThread(PRThread *thread);
  169.  
  170. #define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
  171. #define _MD_INIT_THREAD                 _MD_InitializeThread
  172. #define _MD_EXIT_THREAD(thread)
  173. #define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
  174. #define _MD_RESUME_THREAD(thread)       _MD_resume_thread
  175. #define _MD_CLEAN_THREAD(_thread)
  176.  
  177. extern PRStatus _MD_CREATE_THREAD(
  178.     PRThread *thread,
  179.     void (*start) (void *),
  180.     PRThreadPriority priority,
  181.     PRThreadScope scope,
  182.     PRThreadState state,
  183.     PRUint32 stackSize);
  184. extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
  185. extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
  186. extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
  187. extern void _MD_YIELD(void);
  188.  
  189. #endif /* ! _PR_PTHREADS */
  190.  
  191. extern void _MD_EarlyInit(void);
  192. extern PRIntervalTime _PR_UNIX_GetInterval(void);
  193. extern PRIntervalTime _PR_UNIX_TicksPerSecond(void);
  194.  
  195. #define _MD_EARLY_INIT                  _MD_EarlyInit
  196. #define _MD_FINAL_INIT            _PR_UnixInit
  197. #define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
  198. #define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
  199.  
  200. /*
  201.  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
  202.  * unwrapped version.
  203.  */
  204. #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
  205.  
  206. #if defined(_PR_POLL_AVAILABLE)
  207. #define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
  208. #endif
  209.  
  210. /* freebsd has INADDR_LOOPBACK defined, but in /usr/include/rpc/types.h, and I didn't
  211.    want to be including that.. */
  212. #ifndef INADDR_LOOPBACK
  213. #define INADDR_LOOPBACK         (u_long)0x7F000001
  214. #endif
  215.  
  216. /* For writev() */
  217. #include <sys/uio.h>
  218.  
  219. #endif /* nspr_freebsd_defs_h___ */
  220.