Back to index

lightning-sunbird  0.9+nobinonly
_sunos4.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_sunos_defs_h___
00039 #define nspr_sunos_defs_h___
00040 
00041 #include "md/sunos4.h"
00042 
00043 /* On SunOS 4, memset is declared in memory.h */
00044 #include <memory.h>
00045 #include <errno.h>
00046 #include <sys/syscall.h>
00047 
00048 /*
00049  * Internal configuration macros
00050  */
00051 
00052 #define PR_LINKER_ARCH      "sunos"
00053 #define _PR_SI_SYSNAME      "SUNOS"
00054 #define _PR_SI_ARCHITECTURE "sparc"
00055 #define PR_DLL_SUFFIX              ".so.1.0"
00056 
00057 /*
00058 ** For sunos type machines, don't specify an address because the
00059 ** NetBSD/SPARC O.S. does the wrong thing.
00060 */
00061 #define _PR_VMBASE          0x30000000
00062 #define _PR_STACK_VMBASE    0x50000000
00063 #define _MD_DEFAULT_STACK_SIZE     65536L
00064 #define _MD_MMAP_FLAGS          MAP_PRIVATE
00065 
00066 #undef  HAVE_STACK_GROWING_UP
00067 #undef HAVE_WEAK_IO_SYMBOLS
00068 #undef HAVE_WEAK_MALLOC_SYMBOLS
00069 #define       HAVE_DLL
00070 #define       USE_DLFCN
00071 #define NEED_STRFTIME_LOCK
00072 #define NEED_TIME_R
00073 #define HAVE_BSD_FLOCK
00074 #define _PR_NO_LARGE_FILES
00075 #define _PR_STAT_HAS_ONLY_ST_ATIME
00076 
00077 #define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
00078 #define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
00079 
00080 #define USE_SETJMP
00081 
00082 #include <setjmp.h>
00083 
00084 #define _MD_GET_SP(_t)    (_t)->md.context[2]
00085 
00086 #define PR_NUM_GCREGS       _JBLEN
00087 
00088 #define CONTEXT(_th) ((_th)->md.context)
00089 
00090 /*
00091 ** Initialize the thread context preparing it to execute _main.
00092 */
00093 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)         \
00094     PR_BEGIN_MACRO                              \
00095        int *context = (_thread)->md.context;           \
00096         *status = PR_TRUE;              \
00097        asm("ta 3");                              \
00098        (void) setjmp(context);                         \
00099        (_thread)->md.context[2] = (int) ((_sp) - 64); \
00100        (_thread)->md.context[2] &= ~7;           \
00101        (_thread)->md.context[3] = (int) _main;  \
00102        (_thread)->md.context[4] = (int) _main + 4;  \
00103     PR_END_MACRO
00104 
00105 #define _MD_SWITCH_CONTEXT(_thread)  \
00106     asm("ta 3");                   \
00107     if (!setjmp(CONTEXT(_thread))) { \
00108        (_thread)->md.errcode = errno;  \
00109        _PR_Schedule();                  \
00110     }
00111 
00112 /*
00113 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
00114 */
00115 #define _MD_RESTORE_CONTEXT(_thread) \
00116 {                                \
00117     errno = (_thread)->md.errcode;      \
00118     _MD_SET_CURRENT_THREAD(_thread);       \
00119     longjmp(CONTEXT(_thread), 1);    \
00120 }
00121 
00122 #pragma unknown_control_flow(longjmp)
00123 #pragma unknown_control_flow(setjmp)
00124 #pragma unknown_control_flow(_PR_Schedule)
00125 
00126 /*
00127 ** Missing function prototypes
00128 */
00129 
00130 extern int socket (int domain, int type, int protocol);
00131 extern int getsockname (int s, struct sockaddr *name, int *namelen);
00132 extern int getpeername (int s, struct sockaddr *name, int *namelen);
00133 extern int getsockopt (int s, int level, int optname, char* optval, int* optlen);
00134 extern int setsockopt (int s, int level, int optname, const char* optval, int optlen);
00135 extern int accept (int s, struct sockaddr *addr, int *addrlen);
00136 extern int listen (int s, int backlog);
00137 extern int brk(void *);
00138 extern void *sbrk(int);
00139 
00140 
00141 /* Machine-dependent (MD) data structures.  SunOS 4 has no native threads. */
00142 
00143 struct _MDThread {
00144     jmp_buf context;
00145     int id;
00146     int errcode;
00147 };
00148 
00149 struct _MDThreadStack {
00150     PRInt8 notused;
00151 };
00152 
00153 struct _MDLock {
00154     PRInt8 notused;
00155 };
00156 
00157 struct _MDSemaphore {
00158     PRInt8 notused;
00159 };
00160 
00161 struct _MDCVar {
00162     PRInt8 notused;
00163 };
00164 
00165 struct _MDSegment {
00166     PRInt8 notused;
00167 };
00168 
00169 /*
00170  * md-specific cpu structure field
00171  */
00172 #define _PR_MD_MAX_OSFD FD_SETSIZE
00173 
00174 struct _MDCPU_Unix {
00175     PRCList ioQ;
00176     PRUint32 ioq_timeout;
00177     PRInt32 ioq_max_osfd;
00178     PRInt32 ioq_osfd_cnt;
00179 #ifndef _PR_USE_POLL
00180     fd_set fd_read_set, fd_write_set, fd_exception_set;
00181     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
00182                             fd_exception_cnt[_PR_MD_MAX_OSFD];
00183 #else
00184        struct pollfd *ioq_pollfds;
00185        int ioq_pollfds_size;
00186 #endif /* _PR_USE_POLL */
00187 };
00188 
00189 #define _PR_IOQ(_cpu)                     ((_cpu)->md.md_unix.ioQ)
00190 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
00191 #define _PR_FD_READ_SET(_cpu)             ((_cpu)->md.md_unix.fd_read_set)
00192 #define _PR_FD_READ_CNT(_cpu)             ((_cpu)->md.md_unix.fd_read_cnt)
00193 #define _PR_FD_WRITE_SET(_cpu)            ((_cpu)->md.md_unix.fd_write_set)
00194 #define _PR_FD_WRITE_CNT(_cpu)            ((_cpu)->md.md_unix.fd_write_cnt)
00195 #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
00196 #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
00197 #define _PR_IOQ_TIMEOUT(_cpu)             ((_cpu)->md.md_unix.ioq_timeout)
00198 #define _PR_IOQ_MAX_OSFD(_cpu)            ((_cpu)->md.md_unix.ioq_max_osfd)
00199 #define _PR_IOQ_OSFD_CNT(_cpu)            ((_cpu)->md.md_unix.ioq_osfd_cnt)
00200 #define _PR_IOQ_POLLFDS(_cpu)             ((_cpu)->md.md_unix.ioq_pollfds)
00201 #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
00202 
00203 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)    32
00204 
00205 struct _MDCPU {
00206        struct _MDCPU_Unix md_unix;
00207 };
00208 
00209 #define _MD_INIT_LOCKS()
00210 #define _MD_NEW_LOCK(lock) PR_SUCCESS
00211 #define _MD_FREE_LOCK(lock)
00212 #define _MD_LOCK(lock)
00213 #define _MD_UNLOCK(lock)
00214 #define _MD_INIT_IO()
00215 #define _MD_IOQ_LOCK()
00216 #define _MD_IOQ_UNLOCK()
00217 
00218 /* These are copied from _solaris.h */
00219 
00220 #define _MD_EARLY_INIT          _MD_EarlyInit
00221 #define _MD_FINAL_INIT                    _PR_UnixInit
00222 #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
00223 #define _MD_INIT_THREAD         _MD_InitializeThread
00224 #define _MD_EXIT_THREAD(thread)
00225 #define       _MD_SUSPEND_THREAD(thread)
00226 #define       _MD_RESUME_THREAD(thread)
00227 #define _MD_CLEAN_THREAD(_thread)
00228 
00229 /*
00230  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
00231  * unwrapped version.
00232  */
00233 #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
00234 #define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
00235 
00236 #endif /* nspr_sparc_defs_h___ */