Back to index

lightning-sunbird  0.9+nobinonly
_freebsd.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nspr_freebsd_defs_h___
00039 #define nspr_freebsd_defs_h___
00040 
00041 #include "prthread.h"
00042 
00043 #if __FreeBSD__ >= 2
00044 #include <osreldate.h>  /* for __FreeBSD_version */
00045 #endif
00046 #include <sys/syscall.h>
00047 
00048 #define PR_LINKER_ARCH      "freebsd"
00049 #define _PR_SI_SYSNAME  "FREEBSD"
00050 #if defined(__i386__)
00051 #define _PR_SI_ARCHITECTURE "x86"
00052 #elif defined(__alpha__)
00053 #define _PR_SI_ARCHITECTURE "alpha"
00054 #elif defined(__sparc__)
00055 #define _PR_SI_ARCHITECTURE "sparc"
00056 #elif defined(__ia64__)
00057 #define _PR_SI_ARCHITECTURE "ia64"
00058 #elif defined(__amd64__)
00059 #define _PR_SI_ARCHITECTURE "amd64"
00060 #else
00061 #error "Unknown CPU architecture"
00062 #endif
00063 #if defined(__ELF__)
00064 #define PR_DLL_SUFFIX          ".so"
00065 #else
00066 #define PR_DLL_SUFFIX          ".so.1.0"
00067 #endif
00068 
00069 #define _PR_VMBASE              0x30000000
00070 #define _PR_STACK_VMBASE    0x50000000
00071 #define _MD_DEFAULT_STACK_SIZE     65536L
00072 #define _MD_MMAP_FLAGS          MAP_PRIVATE
00073 
00074 #undef  HAVE_STACK_GROWING_UP
00075 #define HAVE_DLL
00076 #define USE_DLFCN
00077 #define _PR_HAVE_SOCKADDR_LEN
00078 #define _PR_STAT_HAS_ST_ATIMESPEC
00079 #define _PR_NO_LARGE_FILES
00080 
00081 #if defined(_PR_PTHREADS)
00082 #if __FreeBSD_version >= 400008
00083 /*
00084  * libc_r before this version of FreeBSD doesn't have poll().
00085  * Although libc has poll(), it is not thread-safe so we can't
00086  * use it in the pthreads version.
00087  */
00088 #define _PR_POLL_AVAILABLE
00089 #endif
00090 #else
00091 #if __FreeBSD_version >= 300000
00092 #define _PR_POLL_AVAILABLE
00093 #define _PR_USE_POLL
00094 #endif
00095 #endif
00096 
00097 #define _PR_HAVE_SYSV_SEMAPHORES
00098 #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
00099 
00100 #if __FreeBSD_version >= 400014
00101 #define _PR_INET6
00102 #define _PR_HAVE_INET_NTOP
00103 #define _PR_HAVE_GETHOSTBYNAME2
00104 #define _PR_HAVE_GETADDRINFO
00105 #define _PR_INET6_PROBE
00106 #define _PR_IPV6_V6ONLY_PROBE
00107 #endif
00108 
00109 #define USE_SETJMP
00110 
00111 #ifndef _PR_PTHREADS
00112 #include <setjmp.h>
00113 
00114 #define PR_CONTEXT_TYPE     sigjmp_buf
00115 
00116 #define CONTEXT(_th) ((_th)->md.context)
00117 
00118 #define _MD_GET_SP(_th)    (_th)->md.context[0]._sjb[2]
00119 #define PR_NUM_GCREGS       _JBLEN
00120 
00121 /*
00122 ** Initialize a thread context to run "_main()" when started
00123 */
00124 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
00125 {  \
00126     *status = PR_TRUE;  \
00127     if (sigsetjmp(CONTEXT(_thread), 1)) {  \
00128         _main();  \
00129     }  \
00130     _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
00131 }
00132 
00133 #define _MD_SWITCH_CONTEXT(_thread)  \
00134     if (!sigsetjmp(CONTEXT(_thread), 1)) {  \
00135        (_thread)->md.errcode = errno;  \
00136        _PR_Schedule();  \
00137     }
00138 
00139 /*
00140 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
00141 */
00142 #define _MD_RESTORE_CONTEXT(_thread) \
00143 {   \
00144     errno = (_thread)->md.errcode;  \
00145     _MD_SET_CURRENT_THREAD(_thread);  \
00146     siglongjmp(CONTEXT(_thread), 1);  \
00147 }
00148 
00149 /* Machine-dependent (MD) data structures */
00150 
00151 struct _MDThread {
00152     PR_CONTEXT_TYPE context;
00153     int id;
00154     int errcode;
00155 };
00156 
00157 struct _MDThreadStack {
00158     PRInt8 notused;
00159 };
00160 
00161 struct _MDLock {
00162     PRInt8 notused;
00163 };
00164 
00165 struct _MDSemaphore {
00166     PRInt8 notused;
00167 };
00168 
00169 struct _MDCVar {
00170     PRInt8 notused;
00171 };
00172 
00173 struct _MDSegment {
00174     PRInt8 notused;
00175 };
00176 
00177 /*
00178  * md-specific cpu structure field
00179  */
00180 #define _PR_MD_MAX_OSFD FD_SETSIZE
00181 
00182 struct _MDCPU_Unix {
00183     PRCList ioQ;
00184     PRUint32 ioq_timeout;
00185     PRInt32 ioq_max_osfd;
00186     PRInt32 ioq_osfd_cnt;
00187 #ifndef _PR_USE_POLL
00188     fd_set fd_read_set, fd_write_set, fd_exception_set;
00189     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
00190                             fd_exception_cnt[_PR_MD_MAX_OSFD];
00191 #else
00192        struct pollfd *ioq_pollfds;
00193        int ioq_pollfds_size;
00194 #endif /* _PR_USE_POLL */
00195 };
00196 
00197 #define _PR_IOQ(_cpu)                     ((_cpu)->md.md_unix.ioQ)
00198 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
00199 #define _PR_FD_READ_SET(_cpu)             ((_cpu)->md.md_unix.fd_read_set)
00200 #define _PR_FD_READ_CNT(_cpu)             ((_cpu)->md.md_unix.fd_read_cnt)
00201 #define _PR_FD_WRITE_SET(_cpu)            ((_cpu)->md.md_unix.fd_write_set)
00202 #define _PR_FD_WRITE_CNT(_cpu)            ((_cpu)->md.md_unix.fd_write_cnt)
00203 #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
00204 #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
00205 #define _PR_IOQ_TIMEOUT(_cpu)             ((_cpu)->md.md_unix.ioq_timeout)
00206 #define _PR_IOQ_MAX_OSFD(_cpu)            ((_cpu)->md.md_unix.ioq_max_osfd)
00207 #define _PR_IOQ_OSFD_CNT(_cpu)            ((_cpu)->md.md_unix.ioq_osfd_cnt)
00208 #define _PR_IOQ_POLLFDS(_cpu)             ((_cpu)->md.md_unix.ioq_pollfds)
00209 #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
00210 
00211 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)    32
00212 
00213 struct _MDCPU {
00214        struct _MDCPU_Unix md_unix;
00215 };
00216 
00217 #define _MD_INIT_LOCKS()
00218 #define _MD_NEW_LOCK(lock) PR_SUCCESS
00219 #define _MD_FREE_LOCK(lock)
00220 #define _MD_LOCK(lock)
00221 #define _MD_UNLOCK(lock)
00222 #define _MD_INIT_IO()
00223 #define _MD_IOQ_LOCK()
00224 #define _MD_IOQ_UNLOCK()
00225 
00226 extern PRStatus _MD_InitializeThread(PRThread *thread);
00227 
00228 #define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
00229 #define _MD_INIT_THREAD                 _MD_InitializeThread
00230 #define _MD_EXIT_THREAD(thread)
00231 #define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
00232 #define _MD_RESUME_THREAD(thread)       _MD_resume_thread
00233 #define _MD_CLEAN_THREAD(_thread)
00234 
00235 extern PRStatus _MD_CREATE_THREAD(
00236     PRThread *thread,
00237     void (*start) (void *),
00238     PRThreadPriority priority,
00239     PRThreadScope scope,
00240     PRThreadState state,
00241     PRUint32 stackSize);
00242 extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
00243 extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
00244 extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
00245 extern void _MD_YIELD(void);
00246 
00247 #endif /* ! _PR_PTHREADS */
00248 
00249 extern void _MD_EarlyInit(void);
00250 extern PRIntervalTime _PR_UNIX_GetInterval(void);
00251 extern PRIntervalTime _PR_UNIX_TicksPerSecond(void);
00252 
00253 #define _MD_EARLY_INIT                  _MD_EarlyInit
00254 #define _MD_FINAL_INIT                    _PR_UnixInit
00255 #define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
00256 #define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
00257 
00258 /*
00259  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
00260  * unwrapped version.
00261  */
00262 #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
00263 
00264 #if defined(_PR_POLL_AVAILABLE)
00265 #include <poll.h>
00266 #define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
00267 #endif
00268 
00269 /* freebsd has INADDR_LOOPBACK defined, but in /usr/include/rpc/types.h, and I didn't
00270    want to be including that.. */
00271 #ifndef INADDR_LOOPBACK
00272 #define INADDR_LOOPBACK         (u_long)0x7F000001
00273 #endif
00274 
00275 /* For writev() */
00276 #include <sys/uio.h>
00277 
00278 #endif /* nspr_freebsd_defs_h___ */