Back to index

lightning-sunbird  0.9+nobinonly
_reliantunix.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 /*
00039  * reliantunix.h
00040  * 5/18/96 Taken from nec.h -- chrisk@netscape.com
00041  * 3/14/97 Modified for nspr20 -- chrisk@netscape.com
00042  */
00043 #ifndef nspr_reliantunix_defs_h___
00044 #define nspr_reliantunix_defs_h___
00045 
00046 /*
00047  * Internal configuration macros
00048  */
00049 
00050 #define PR_LINKER_ARCH      "sinix"
00051 #define _PR_SI_SYSNAME      "SINIX"
00052 #define _PR_SI_ARCHITECTURE "mips"
00053 #define PR_DLL_SUFFIX ".so"
00054 
00055 #define _PR_VMBASE          0x30000000
00056 #define _PR_STACK_VMBASE    0x50000000
00057 #define _MD_DEFAULT_STACK_SIZE     (2*65536L)
00058 #define _MD_MMAP_FLAGS             MAP_PRIVATE|MAP_FIXED
00059 
00060 #undef  HAVE_STACK_GROWING_UP
00061 #define HAVE_DLL
00062 #define USE_DLFCN
00063 #define NEED_STRFTIME_LOCK
00064 #define NEED_TIME_R
00065 #define HAVE_NETCONFIG
00066 #define HAVE_WEAK_IO_SYMBOLS
00067 #define HAVE_WEAK_MALLOC_SYMBOLS
00068 #define _PR_RECV_BROKEN /* recv doesn't work on Unix Domain Sockets */
00069 #define _PR_POLL_AVAILABLE
00070 #define _PR_USE_POLL
00071 #define _PR_STAT_HAS_ST_ATIM
00072 #define _PR_NO_LARGE_FILES
00073 
00074 /*
00075  * Mike Patnode indicated that it is possibly safe now to use context-switching
00076  * calls that do not change the signal mask, like setjmp vs. sigsetjmp.
00077  * So we'll use our homegrown, getcontext/setcontext-compatible stuff which 
00078  * will save us the getcontext/setcontext system calls at each context switch.
00079  * It already works in FastTrack 2.01, so it should do it here :-)
00080  *  - chrisk 040497
00081  */
00082 #define USE_SETCXT /* temporarily disabled... */
00083 
00084 #include <ucontext.h>
00085  
00086 #ifdef USE_SETCXT
00087 /* use non-syscall machine language replacement */
00088 #define _GETCONTEXT         getcxt
00089 #define _SETCONTEXT         setcxt
00090 /* defined in os_ReliantUNIX.s */
00091 extern int getcxt(ucontext_t *);
00092 extern int setcxt(ucontext_t *);
00093 #else
00094 #define _GETCONTEXT         getcontext
00095 #define _SETCONTEXT         setcontext
00096 #endif
00097 
00098 #define _MD_GET_SP(_t)             (_t)->md.context.uc_mcontext.gpregs[CXT_SP]
00099 #define _PR_CONTEXT_TYPE    ucontext_t
00100 #define _PR_NUM_GCREGS             NGREG
00101  
00102 #define CONTEXT(_thread) (&(_thread)->md.context)
00103 
00104 #define _PR_IS_NATIVE_THREAD_SUPPORTED() 0
00105  
00106 /*
00107 ** Machine-dependent (MD) data structures.
00108 */
00109 struct _MDThread {
00110     _PR_CONTEXT_TYPE context;
00111     int id;
00112     int errcode;
00113 };
00114 
00115 struct _MDThreadStack {
00116     PRInt8 notused;
00117 };
00118 
00119 struct _MDLock {
00120     PRInt8 notused;
00121 };
00122 
00123 struct _MDSemaphore {
00124     PRInt8 notused;
00125 };
00126 
00127 struct _MDCVar {
00128     PRInt8 notused;
00129 };
00130 
00131 struct _MDSegment {
00132     PRInt8 notused;
00133 };
00134 
00135 /*
00136  * md-specific cpu structure field
00137  */
00138 #define _PR_MD_MAX_OSFD FD_SETSIZE
00139 
00140 struct _MDCPU_Unix {
00141     PRCList ioQ;
00142     PRUint32 ioq_timeout;
00143     PRInt32 ioq_max_osfd;
00144     PRInt32 ioq_osfd_cnt;
00145 #ifndef _PR_USE_POLL
00146     fd_set fd_read_set, fd_write_set, fd_exception_set;
00147     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
00148                             fd_exception_cnt[_PR_MD_MAX_OSFD];
00149 #else
00150        struct pollfd *ioq_pollfds;
00151        int ioq_pollfds_size;
00152 #endif /* _PR_USE_POLL */
00153 };
00154 
00155 #define _PR_IOQ(_cpu)                     ((_cpu)->md.md_unix.ioQ)
00156 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
00157 #define _PR_FD_READ_SET(_cpu)             ((_cpu)->md.md_unix.fd_read_set)
00158 #define _PR_FD_READ_CNT(_cpu)             ((_cpu)->md.md_unix.fd_read_cnt)
00159 #define _PR_FD_WRITE_SET(_cpu)            ((_cpu)->md.md_unix.fd_write_set)
00160 #define _PR_FD_WRITE_CNT(_cpu)            ((_cpu)->md.md_unix.fd_write_cnt)
00161 #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
00162 #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
00163 #define _PR_IOQ_TIMEOUT(_cpu)             ((_cpu)->md.md_unix.ioq_timeout)
00164 #define _PR_IOQ_MAX_OSFD(_cpu)            ((_cpu)->md.md_unix.ioq_max_osfd)
00165 #define _PR_IOQ_OSFD_CNT(_cpu)            ((_cpu)->md.md_unix.ioq_osfd_cnt)
00166 #define _PR_IOQ_POLLFDS(_cpu)             ((_cpu)->md.md_unix.ioq_pollfds)
00167 #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
00168 
00169 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)    32
00170 
00171 struct _MDCPU {
00172        struct _MDCPU_Unix md_unix;
00173 };
00174 
00175 #define _MD_INIT_LOCKS()
00176 #define _MD_NEW_LOCK(lock) PR_SUCCESS
00177 #define _MD_FREE_LOCK(lock)
00178 #define _MD_LOCK(lock)
00179 #define _MD_UNLOCK(lock)
00180 #define _MD_INIT_IO()
00181 #define _MD_IOQ_LOCK()
00182 #define _MD_IOQ_UNLOCK()
00183 
00184 /*
00185 ** Initialize the thread context preparing it to execute "_main()"
00186 ** - get a nice, fresh context
00187 ** - set its SP to the stack we allcoated for it
00188 ** - set it to start things at "e"
00189 */
00190 #define _MD_INIT_CONTEXT(thread, _sp, _main, status)                \
00191     PR_BEGIN_MACRO                                                  \
00192     *status = PR_TRUE;                                              \
00193     _GETCONTEXT(CONTEXT(thread));                                   \
00194     /* this is supposed to point to the stack BASE, not to SP */    \
00195     CONTEXT(thread)->uc_stack.ss_sp = thread->stack->stackBottom;   \
00196     CONTEXT(thread)->uc_stack.ss_size = thread->stack->stackSize;   \
00197     CONTEXT(thread)->uc_mcontext.gpregs[CXT_SP] = ((unsigned long)_sp - 128) & 0xfffffff8; \
00198     CONTEXT(thread)->uc_mcontext.gpregs[CXT_T9] = _main;            \
00199     CONTEXT(thread)->uc_mcontext.gpregs[CXT_EPC] = _main;           \
00200     CONTEXT(thread)->uc_mcontext.gpregs[CXT_RA] = 0;                \
00201     thread->no_sched = 0;                                           \
00202     PR_END_MACRO
00203  
00204 /*
00205 ** Save current context as it is scheduled away
00206 */
00207 #define _MD_SWITCH_CONTEXT(_thread)       \
00208     PR_BEGIN_MACRO                        \
00209     if (!_GETCONTEXT(CONTEXT(_thread))) { \
00210        _MD_SAVE_ERRNO(_thread);          \
00211        _MD_SET_LAST_THREAD(_thread);     \
00212         _PR_Schedule();                   \
00213     }                                     \
00214     PR_END_MACRO
00215  
00216 /*
00217 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT or set up
00218 **  by _MD_INIT_CONTEXT
00219 **  CXT_V0 is the register that holds the return value.
00220 **   We must set it to 1 so that we can see if the return from
00221 **   getcontext() is the result of calling getcontext() or
00222 **   setcontext()...
00223 **   setting a context got with getcontext() appears to
00224 **   return from getcontext(), too!
00225 **  CXT_A3 is the register that holds status when returning
00226 **   from a syscall. It is set to 0 to indicate success,
00227 **   because we want getcontext() on the other side of the magic
00228 **   door to be ok.
00229 */
00230 #define _MD_RESTORE_CONTEXT(_thread)   \
00231     PR_BEGIN_MACRO                     \
00232     ucontext_t *uc = CONTEXT(_thread); \
00233     uc->uc_mcontext.gpregs[CXT_V0] = 1;\
00234     uc->uc_mcontext.gpregs[CXT_A3] = 0;\
00235     _MD_RESTORE_ERRNO(_thread);        \
00236     _MD_SET_CURRENT_THREAD(_thread);   \
00237     _SETCONTEXT(uc);                   \
00238     PR_END_MACRO
00239 
00240 #define _MD_SAVE_ERRNO(t)    (t)->md.errcode = errno;
00241 #define _MD_RESTORE_ERRNO(t)        errno = (t)->md.errcode;
00242 
00243 #define _MD_GET_INTERVAL    _PR_UNIX_GetInterval
00244 #define _MD_INTERVAL_PER_SEC       _PR_UNIX_TicksPerSecond
00245 
00246 #define _MD_EARLY_INIT             _MD_EarlyInit
00247 #define _MD_FINAL_INIT             _PR_UnixInit
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)
00252 #define _MD_RESUME_THREAD(thread)
00253 #define _MD_CLEAN_THREAD(_thread)
00254 
00255 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
00256 #define S_ISSOCK(mode)   ((mode&0xF000) == 0xC000)
00257 #endif
00258 #if !defined(S_ISLNK) && defined(S_IFLNK)
00259 #define S_ISLNK(mode)   ((mode&0xA000) == 0xC000)
00260 #endif
00261 
00262 #include <sys/time.h>
00263 #include <sys/types.h>
00264 #include <sys/select.h>
00265 extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
00266        fd_set *execptfds, struct timeval *timeout);
00267 #define _MD_SELECT(nfds,r,w,e,tv) _select(nfds,r,w,e,tv)
00268 #define _MD_POLL _poll
00269 
00270 #endif /* nspr_reliantunix_defs_h___ */