Back to index

lightning-sunbird  0.9+nobinonly
_darwin.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_darwin_defs_h___
00039 #define nspr_darwin_defs_h___
00040 
00041 #include "prthread.h"
00042 
00043 #include <sys/syscall.h>
00044 
00045 #ifdef XP_MACOSX
00046 #include <AvailabilityMacros.h>
00047 #endif
00048 
00049 #define PR_LINKER_ARCH      "darwin"
00050 #define _PR_SI_SYSNAME  "DARWIN"
00051 #ifdef __i386__
00052 #define _PR_SI_ARCHITECTURE "x86"
00053 #elif defined(__ppc__)
00054 #define _PR_SI_ARCHITECTURE "ppc"
00055 #endif
00056 #define PR_DLL_SUFFIX              ".dylib"
00057 
00058 #define _PR_VMBASE              0x30000000
00059 #define _PR_STACK_VMBASE    0x50000000
00060 #define _MD_DEFAULT_STACK_SIZE     65536L
00061 #define _MD_MMAP_FLAGS          MAP_PRIVATE
00062 
00063 #undef  HAVE_STACK_GROWING_UP
00064 #define HAVE_DLL
00065 #define USE_MACH_DYLD
00066 #define _PR_HAVE_SOCKADDR_LEN  
00067 #define _PR_STAT_HAS_ST_ATIMESPEC
00068 #define _PR_HAVE_LARGE_OFF_T
00069 #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
00070 
00071 #define _PR_INET6
00072 /*
00073  * I'd prefer to use getipnodebyname and getipnodebyaddr but the
00074  * getipnodebyname(3) man page on Mac OS X 10.2 says they are not
00075  * thread-safe.  AI_V4MAPPED|AI_ADDRCONFIG doesn't work either.
00076  */
00077 #define _PR_HAVE_GETHOSTBYNAME2
00078 #define _PR_HAVE_GETADDRINFO
00079 /*
00080  * On Mac OS X 10.2, gethostbyaddr fails with h_errno=NO_RECOVERY
00081  * if you pass an IPv4-mapped IPv6 address to it.
00082  */
00083 #define _PR_GHBA_DISALLOW_V4MAPPED
00084 #ifdef XP_MACOSX
00085 #if !defined(MAC_OS_X_VERSION_10_3) || \
00086     MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_3
00087 /*
00088  * socket(AF_INET6) fails with EPROTONOSUPPORT on Mac OS X 10.1.
00089  * IPv6 under OS X 10.2 and below is not complete (see bug 222031).
00090  */
00091 #define _PR_INET6_PROBE
00092 #endif /* DT < 10.3 */
00093 #if defined(MAC_OS_X_VERSION_10_2) && \
00094     MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_2
00095 /* Mac OS X 10.2 has inet_ntop and inet_pton. */
00096 #define _PR_HAVE_INET_NTOP
00097 #endif /* DT >= 10.2 */
00098 #endif /* XP_MACOSX */
00099 #define _PR_IPV6_V6ONLY_PROBE
00100 /* The IPV6_V6ONLY socket option is not defined on Mac OS X 10.1. */
00101 #ifndef IPV6_V6ONLY
00102 #define IPV6_V6ONLY 27
00103 #endif
00104 
00105 #if defined(__ppc__)
00106 #define _PR_HAVE_ATOMIC_OPS
00107 #define _MD_INIT_ATOMIC()
00108 extern PRInt32 _PR_DarwinPPC_AtomicIncrement(PRInt32 *val);
00109 #define _MD_ATOMIC_INCREMENT(val)   _PR_DarwinPPC_AtomicIncrement(val)
00110 extern PRInt32 _PR_DarwinPPC_AtomicDecrement(PRInt32 *val);
00111 #define _MD_ATOMIC_DECREMENT(val)   _PR_DarwinPPC_AtomicDecrement(val)
00112 extern PRInt32 _PR_DarwinPPC_AtomicSet(PRInt32 *val, PRInt32 newval);
00113 #define _MD_ATOMIC_SET(val, newval) _PR_DarwinPPC_AtomicSet(val, newval)
00114 extern PRInt32 _PR_DarwinPPC_AtomicAdd(PRInt32 *ptr, PRInt32 val);
00115 #define _MD_ATOMIC_ADD(ptr, val)    _PR_DarwinPPC_AtomicAdd(ptr, val)
00116 #elif defined(__i386__)
00117 #define _PR_HAVE_ATOMIC_OPS
00118 #define _MD_INIT_ATOMIC()
00119 extern PRInt32 _PR_Darwin_x86_AtomicIncrement(PRInt32 *val);
00120 #define _MD_ATOMIC_INCREMENT(val)   _PR_Darwin_x86_AtomicIncrement(val)
00121 extern PRInt32 _PR_Darwin_x86_AtomicDecrement(PRInt32 *val);
00122 #define _MD_ATOMIC_DECREMENT(val)   _PR_Darwin_x86_AtomicDecrement(val)
00123 extern PRInt32 _PR_Darwin_x86_AtomicSet(PRInt32 *val, PRInt32 newval);
00124 #define _MD_ATOMIC_SET(val, newval) _PR_Darwin_x86_AtomicSet(val, newval)
00125 extern PRInt32 _PR_Darwin_x86_AtomicAdd(PRInt32 *ptr, PRInt32 val);
00126 #define _MD_ATOMIC_ADD(ptr, val)    _PR_Darwin_x86_AtomicAdd(ptr, val)
00127 #endif /* __i386__ */
00128 
00129 #define USE_SETJMP
00130 
00131 #if !defined(_PR_PTHREADS)
00132 
00133 #include <setjmp.h>
00134 
00135 #define PR_CONTEXT_TYPE     jmp_buf
00136 
00137 #define CONTEXT(_th)       ((_th)->md.context)
00138 #define _MD_GET_SP(_th)    (((struct sigcontext *) (_th)->md.context)->sc_onstack)
00139 #define PR_NUM_GCREGS           _JBLEN
00140 
00141 /*
00142 ** Initialize a thread context to run "_main()" when started
00143 */
00144 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
00145 {  \
00146     *status = PR_TRUE;  \
00147     if (setjmp(CONTEXT(_thread))) {  \
00148         _main();  \
00149     }  \
00150     _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
00151 }
00152 
00153 #define _MD_SWITCH_CONTEXT(_thread)  \
00154     if (!setjmp(CONTEXT(_thread))) {  \
00155        (_thread)->md.errcode = errno;  \
00156        _PR_Schedule();  \
00157     }
00158 
00159 /*
00160 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
00161 */
00162 #define _MD_RESTORE_CONTEXT(_thread) \
00163 {   \
00164     errno = (_thread)->md.errcode;  \
00165     _MD_SET_CURRENT_THREAD(_thread);  \
00166     longjmp(CONTEXT(_thread), 1);  \
00167 }
00168 
00169 /* Machine-dependent (MD) data structures */
00170 
00171 struct _MDThread {
00172     PR_CONTEXT_TYPE context;
00173     int id;
00174     int errcode;
00175 };
00176 
00177 struct _MDThreadStack {
00178     PRInt8 notused;
00179 };
00180 
00181 struct _MDLock {
00182     PRInt8 notused;
00183 };
00184 
00185 struct _MDSemaphore {
00186     PRInt8 notused;
00187 };
00188 
00189 struct _MDCVar {
00190     PRInt8 notused;
00191 };
00192 
00193 struct _MDSegment {
00194     PRInt8 notused;
00195 };
00196 
00197 /*
00198  * md-specific cpu structure field
00199  */
00200 #define _PR_MD_MAX_OSFD FD_SETSIZE
00201 
00202 struct _MDCPU_Unix {
00203     PRCList ioQ;
00204     PRUint32 ioq_timeout;
00205     PRInt32 ioq_max_osfd;
00206     PRInt32 ioq_osfd_cnt;
00207 #ifndef _PR_USE_POLL
00208     fd_set fd_read_set, fd_write_set, fd_exception_set;
00209     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
00210                             fd_exception_cnt[_PR_MD_MAX_OSFD];
00211 #else
00212        struct pollfd *ioq_pollfds;
00213        int ioq_pollfds_size;
00214 #endif /* _PR_USE_POLL */
00215 };
00216 
00217 #define _PR_IOQ(_cpu)                     ((_cpu)->md.md_unix.ioQ)
00218 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
00219 #define _PR_FD_READ_SET(_cpu)             ((_cpu)->md.md_unix.fd_read_set)
00220 #define _PR_FD_READ_CNT(_cpu)             ((_cpu)->md.md_unix.fd_read_cnt)
00221 #define _PR_FD_WRITE_SET(_cpu)            ((_cpu)->md.md_unix.fd_write_set)
00222 #define _PR_FD_WRITE_CNT(_cpu)            ((_cpu)->md.md_unix.fd_write_cnt)
00223 #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
00224 #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
00225 #define _PR_IOQ_TIMEOUT(_cpu)             ((_cpu)->md.md_unix.ioq_timeout)
00226 #define _PR_IOQ_MAX_OSFD(_cpu)            ((_cpu)->md.md_unix.ioq_max_osfd)
00227 #define _PR_IOQ_OSFD_CNT(_cpu)            ((_cpu)->md.md_unix.ioq_osfd_cnt)
00228 #define _PR_IOQ_POLLFDS(_cpu)             ((_cpu)->md.md_unix.ioq_pollfds)
00229 #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
00230 
00231 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)    32
00232 
00233 struct _MDCPU {
00234        struct _MDCPU_Unix md_unix;
00235 };
00236 
00237 #define _MD_INIT_LOCKS()
00238 #define _MD_NEW_LOCK(lock) PR_SUCCESS
00239 #define _MD_FREE_LOCK(lock)
00240 #define _MD_LOCK(lock)
00241 #define _MD_UNLOCK(lock)
00242 #define _MD_INIT_IO()
00243 #define _MD_IOQ_LOCK()
00244 #define _MD_IOQ_UNLOCK()
00245 
00246 extern PRStatus _MD_InitializeThread(PRThread *thread);
00247 
00248 #define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
00249 #define _MD_INIT_THREAD                 _MD_InitializeThread
00250 #define _MD_EXIT_THREAD(thread)
00251 #define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
00252 #define _MD_RESUME_THREAD(thread)       _MD_resume_thread
00253 #define _MD_CLEAN_THREAD(_thread)
00254 
00255 extern PRStatus _MD_CREATE_THREAD(
00256     PRThread *thread,
00257     void (*start) (void *),
00258     PRThreadPriority priority,
00259     PRThreadScope scope,
00260     PRThreadState state,
00261     PRUint32 stackSize);
00262 extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
00263 extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
00264 extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
00265 extern void _MD_YIELD(void);
00266 
00267 #endif /* ! _PR_PTHREADS */
00268 
00269 #define _MD_EARLY_INIT          _MD_EarlyInit
00270 #define _MD_FINAL_INIT                    _PR_UnixInit
00271 #define _MD_GET_INTERVAL        _PR_UNIX_GetInterval
00272 #define _MD_INTERVAL_PER_SEC    _PR_UNIX_TicksPerSecond
00273 
00274 extern void             _MD_EarlyInit(void);
00275 extern PRIntervalTime   _PR_UNIX_GetInterval(void);
00276 extern PRIntervalTime   _PR_UNIX_TicksPerSecond(void);
00277 
00278 /*
00279  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
00280  * unwrapped version.
00281  */
00282 #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
00283 
00284 /* For writev() */
00285 #include <sys/uio.h>
00286 
00287 #endif /* nspr_darwin_defs_h___ */