Back to index

lightning-sunbird  0.9+nobinonly
_rhapsody.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_rhapsody_defs_h___
00039 #define nspr_rhapsody_defs_h___
00040 
00041 #include "prthread.h"
00042 
00043 #include <sys/syscall.h>
00044 
00045 #define PR_LINKER_ARCH      "rhapsody"
00046 #define _PR_SI_SYSNAME  "RHAPSODY"
00047 #ifdef i386
00048 #define _PR_SI_ARCHITECTURE "x86"
00049 #else
00050 #define _PR_SI_ARCHITECTURE "ppc"
00051 #endif
00052 #define PR_DLL_SUFFIX              ".dylib"
00053 
00054 #define _PR_VMBASE              0x30000000
00055 #define _PR_STACK_VMBASE    0x50000000
00056 #define _MD_DEFAULT_STACK_SIZE     65536L
00057 #define _MD_MMAP_FLAGS          MAP_PRIVATE
00058 
00059 #undef  HAVE_STACK_GROWING_UP
00060 #define HAVE_DLL
00061 #define USE_MACH_DYLD
00062 #define _PR_HAVE_SOCKADDR_LEN  
00063 #define _PR_STAT_HAS_ST_ATIMESPEC
00064 #define _PR_NO_LARGE_FILES
00065 #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
00066 
00067 #define USE_SETJMP
00068 
00069 #if !defined(_PR_PTHREADS)
00070 
00071 #include <setjmp.h>
00072 
00073 #define PR_CONTEXT_TYPE     jmp_buf
00074 
00075 #define CONTEXT(_th)       ((_th)->md.context)
00076 #define _MD_GET_SP(_th)    (((struct sigcontext *) (_th)->md.context)->sc_onstack)
00077 #define PR_NUM_GCREGS           _JBLEN
00078 
00079 /*
00080 ** Initialize a thread context to run "_main()" when started
00081 */
00082 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
00083 {  \
00084     *status = PR_TRUE;  \
00085     if (setjmp(CONTEXT(_thread))) {  \
00086         _main();  \
00087     }  \
00088     _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
00089 }
00090 
00091 #define _MD_SWITCH_CONTEXT(_thread)  \
00092     if (!setjmp(CONTEXT(_thread))) {  \
00093        (_thread)->md.errcode = errno;  \
00094        _PR_Schedule();  \
00095     }
00096 
00097 /*
00098 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
00099 */
00100 #define _MD_RESTORE_CONTEXT(_thread) \
00101 {   \
00102     errno = (_thread)->md.errcode;  \
00103     _MD_SET_CURRENT_THREAD(_thread);  \
00104     longjmp(CONTEXT(_thread), 1);  \
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 extern PRStatus _MD_InitializeThread(PRThread *thread);
00185 
00186 #define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
00187 #define _MD_INIT_THREAD                 _MD_InitializeThread
00188 #define _MD_EXIT_THREAD(thread)
00189 #define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
00190 #define _MD_RESUME_THREAD(thread)       _MD_resume_thread
00191 #define _MD_CLEAN_THREAD(_thread)
00192 
00193 extern PRStatus _MD_CREATE_THREAD(
00194     PRThread *thread,
00195     void (*start) (void *),
00196     PRThreadPriority priority,
00197     PRThreadScope scope,
00198     PRThreadState state,
00199     PRUint32 stackSize);
00200 extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
00201 extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
00202 extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
00203 extern void _MD_YIELD(void);
00204 
00205 #endif /* ! _PR_PTHREADS */
00206 
00207 #define _MD_EARLY_INIT          _MD_EarlyInit
00208 #define _MD_FINAL_INIT                    _PR_UnixInit
00209 #define _MD_GET_INTERVAL        _PR_UNIX_GetInterval
00210 #define _MD_INTERVAL_PER_SEC    _PR_UNIX_TicksPerSecond
00211 
00212 extern void             _MD_EarlyInit(void);
00213 extern PRIntervalTime   _PR_UNIX_GetInterval(void);
00214 extern PRIntervalTime   _PR_UNIX_TicksPerSecond(void);
00215 
00216 /*
00217  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
00218  * unwrapped version.
00219  */
00220 #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
00221 
00222 /* For writev() */
00223 #include <sys/uio.h>
00224 
00225 #endif /* nspr_rhapsody_defs_h___ */