Back to index

lightning-sunbird  0.9+nobinonly
_netbsd.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_netbsd_defs_h___
00039 #define nspr_netbsd_defs_h___
00040 
00041 #include <sys/syscall.h>
00042 #include <sys/param.h>  /* for __NetBSD_Version__ */
00043 
00044 #define PR_LINKER_ARCH      "netbsd"
00045 #define _PR_SI_SYSNAME  "NetBSD"
00046 #if defined(__i386__)
00047 #define _PR_SI_ARCHITECTURE "x86"
00048 #elif defined(__alpha__)
00049 #define _PR_SI_ARCHITECTURE "alpha"
00050 #elif defined(__m68k__)
00051 #define _PR_SI_ARCHITECTURE "m68k"
00052 #elif defined(__powerpc__)
00053 #define _PR_SI_ARCHITECTURE "powerpc"
00054 #elif defined(__sparc_v9__)
00055 #define _PR_SI_ARCHITECTURE "sparc64"
00056 #elif defined(__sparc__)
00057 #define _PR_SI_ARCHITECTURE "sparc"
00058 #elif defined(__mips__)
00059 #define _PR_SI_ARCHITECTURE "mips"
00060 #elif defined(__arm32__) || defined(__arm__) || defined(__armel__) \
00061     || defined(__armeb__)
00062 #define _PR_SI_ARCHITECTURE "arm"
00063 #endif
00064 
00065 #if defined(__ELF__)
00066 #define PR_DLL_SUFFIX              ".so"
00067 #else
00068 #define PR_DLL_SUFFIX              ".so.1.0"
00069 #endif
00070 
00071 #define _PR_VMBASE              0x30000000
00072 #define _PR_STACK_VMBASE    0x50000000
00073 #define _MD_DEFAULT_STACK_SIZE     65536L
00074 #define _MD_MMAP_FLAGS          MAP_PRIVATE
00075 
00076 #undef  HAVE_STACK_GROWING_UP
00077 #define HAVE_DLL
00078 #define USE_DLFCN
00079 #define _PR_HAVE_SOCKADDR_LEN
00080 #define _PR_NO_LARGE_FILES
00081 #define _PR_STAT_HAS_ST_ATIMESPEC
00082 #define _PR_POLL_AVAILABLE
00083 #define _PR_USE_POLL
00084 #define _PR_HAVE_SYSV_SEMAPHORES
00085 #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
00086 
00087 #if __NetBSD_Version__ >= 105000000
00088 #define _PR_INET6
00089 #define _PR_HAVE_INET_NTOP
00090 #define _PR_HAVE_GETHOSTBYNAME2
00091 #define _PR_HAVE_GETADDRINFO
00092 #define _PR_INET6_PROBE
00093 #endif
00094 
00095 #if __NetBSD_Version__ >= 106370000
00096 /* NetBSD 1.6ZK */
00097 #define _PR_HAVE_GETPROTO_R
00098 #define _PR_HAVE_GETPROTO_R_INT
00099 #endif
00100 
00101 #define USE_SETJMP
00102 
00103 #ifndef _PR_PTHREADS
00104 #include <setjmp.h>
00105 
00106 #define PR_CONTEXT_TYPE     sigjmp_buf
00107 
00108 #define CONTEXT(_th) ((_th)->md.context)
00109 
00110 #if defined(__i386__) || defined(__sparc__) || defined(__m68k__) || defined(__powerpc__)
00111 #define JB_SP_INDEX 2
00112 #elif defined(__mips__)
00113 #define JB_SP_INDEX 4
00114 #elif defined(__alpha__)
00115 #define JB_SP_INDEX 34
00116 #elif defined(__arm32__)
00117 /*
00118  * On the arm32, the jmpbuf regs underwent a name change after NetBSD 1.3.
00119  */
00120 #ifdef JMPBUF_REG_R13
00121 #define JB_SP_INDEX JMPBUF_REG_R13
00122 #else
00123 #define JB_SP_INDEX _JB_REG_R13
00124 #endif
00125 #else
00126 #error "Need to define SP index in jmp_buf here"
00127 #endif
00128 #define _MD_GET_SP(_th)    (_th)->md.context[JB_SP_INDEX]
00129 
00130 #define PR_NUM_GCREGS       _JBLEN
00131 
00132 /*
00133 ** Initialize a thread context to run "_main()" when started
00134 */
00135 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
00136 {  \
00137     *status = PR_TRUE;  \
00138     if (sigsetjmp(CONTEXT(_thread), 1)) {  \
00139         _main();  \
00140     }  \
00141     _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
00142 }
00143 
00144 #define _MD_SWITCH_CONTEXT(_thread)  \
00145     if (!sigsetjmp(CONTEXT(_thread), 1)) {  \
00146         (_thread)->md.errcode = errno;  \
00147         _PR_Schedule();  \
00148     }
00149 
00150 /*
00151 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
00152 */
00153 #define _MD_RESTORE_CONTEXT(_thread) \
00154 {   \
00155     errno = (_thread)->md.errcode;  \
00156     _MD_SET_CURRENT_THREAD(_thread);  \
00157     siglongjmp(CONTEXT(_thread), 1);  \
00158 }
00159 
00160 /* Machine-dependent (MD) data structures */
00161 
00162 struct _MDThread {
00163     PR_CONTEXT_TYPE context;
00164     int id;
00165     int errcode;
00166 };
00167 
00168 struct _MDThreadStack {
00169     PRInt8 notused;
00170 };
00171 
00172 struct _MDLock {
00173     PRInt8 notused;
00174 };
00175 
00176 struct _MDSemaphore {
00177     PRInt8 notused;
00178 };
00179 
00180 struct _MDCVar {
00181     PRInt8 notused;
00182 };
00183 
00184 struct _MDSegment {
00185     PRInt8 notused;
00186 };
00187 
00188 /*
00189  * md-specific cpu structure field
00190  */
00191 #define _PR_MD_MAX_OSFD FD_SETSIZE
00192 
00193 struct _MDCPU_Unix {
00194     PRCList ioQ;
00195     PRUint32 ioq_timeout;
00196     PRInt32 ioq_max_osfd;
00197     PRInt32 ioq_osfd_cnt;
00198 #ifndef _PR_USE_POLL
00199     fd_set fd_read_set, fd_write_set, fd_exception_set;
00200     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
00201                             fd_exception_cnt[_PR_MD_MAX_OSFD];
00202 #else
00203        struct pollfd *ioq_pollfds;
00204        int ioq_pollfds_size;
00205 #endif /* _PR_USE_POLL */
00206 };
00207 
00208 #define _PR_IOQ(_cpu)                     ((_cpu)->md.md_unix.ioQ)
00209 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
00210 #define _PR_FD_READ_SET(_cpu)             ((_cpu)->md.md_unix.fd_read_set)
00211 #define _PR_FD_READ_CNT(_cpu)             ((_cpu)->md.md_unix.fd_read_cnt)
00212 #define _PR_FD_WRITE_SET(_cpu)            ((_cpu)->md.md_unix.fd_write_set)
00213 #define _PR_FD_WRITE_CNT(_cpu)            ((_cpu)->md.md_unix.fd_write_cnt)
00214 #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
00215 #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
00216 #define _PR_IOQ_TIMEOUT(_cpu)             ((_cpu)->md.md_unix.ioq_timeout)
00217 #define _PR_IOQ_MAX_OSFD(_cpu)            ((_cpu)->md.md_unix.ioq_max_osfd)
00218 #define _PR_IOQ_OSFD_CNT(_cpu)            ((_cpu)->md.md_unix.ioq_osfd_cnt)
00219 #define _PR_IOQ_POLLFDS(_cpu)             ((_cpu)->md.md_unix.ioq_pollfds)
00220 #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
00221 
00222 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)    32
00223 
00224 struct _MDCPU {
00225     struct _MDCPU_Unix md_unix;
00226 };
00227 
00228 #define _MD_INIT_LOCKS()
00229 #define _MD_NEW_LOCK(lock) PR_SUCCESS
00230 #define _MD_FREE_LOCK(lock)
00231 #define _MD_LOCK(lock)
00232 #define _MD_UNLOCK(lock)
00233 #define _MD_INIT_IO()
00234 #define _MD_IOQ_LOCK()
00235 #define _MD_IOQ_UNLOCK()
00236 
00237 #define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
00238 #define _MD_INIT_THREAD                 _MD_InitializeThread
00239 #define _MD_EXIT_THREAD(thread)
00240 #define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
00241 #define _MD_RESUME_THREAD(thread)       _MD_resume_thread
00242 #define _MD_CLEAN_THREAD(_thread)
00243 
00244 #endif /* ! _PR_PTHREADS */
00245 
00246 #define _MD_EARLY_INIT                  _MD_EarlyInit
00247 #define _MD_FINAL_INIT                    _PR_UnixInit
00248 #define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
00249 #define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
00250 
00251 /*
00252  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
00253  * unwrapped version.
00254  */
00255 #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
00256 #if defined(_PR_POLL_AVAILABLE)
00257 #include <poll.h>
00258 #define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
00259 #endif
00260 
00261 #if NetBSD1_3 == 1L
00262 typedef unsigned int nfds_t;
00263 #endif
00264 
00265 #endif /* nspr_netbsd_defs_h___ */