Back to index

lightning-sunbird  0.9+nobinonly
_nextstep.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_nextstep_defs_h___
00039 #define nspr_nextstep_defs_h___
00040 
00041 #include "prthread.h"
00042 
00043 #include <bsd/libc.h>
00044 #include <bsd/syscall.h>
00045 
00046 /*     syscall() is not declared in NEXTSTEP's syscall.h ...
00047 */
00048 extern int syscall(int number, ...);
00049 
00050 /*
00051  * Internal configuration macros
00052  */
00053 
00054 #define PR_LINKER_ARCH      "nextstep"
00055 #define _PR_SI_SYSNAME  "NEXTSTEP"
00056 #if defined(__sparc__)
00057 #define _PR_SI_ARCHITECTURE "sparc"
00058 #elif defined(__m68k__)
00059 #define _PR_SI_ARCHITECTURE "m68k"
00060 #elif defined(__i386__)
00061 #define _PR_SI_ARCHITECTURE "x86"
00062 #else
00063 error Unknown NEXTSTEP architecture
00064 #endif
00065 #define PR_DLL_SUFFIX              ".so"
00066 
00067 #define _PR_VMBASE              0x30000000
00068 #define _PR_STACK_VMBASE    0x50000000
00069 #define _MD_DEFAULT_STACK_SIZE     65536L
00070 #define _MD_MMAP_FLAGS          MAP_PRIVATE
00071 
00072 #undef  HAVE_STACK_GROWING_UP
00073 
00074 #define HAVE_WEAK_MALLOC_SYMBOLS
00075 
00076 #define HAVE_DLL
00077 #define USE_MACH_DYLD
00078 #define _PR_STAT_HAS_ONLY_ST_ATIME
00079 #define _PR_NO_LARGE_FILES
00080 
00081 #define USE_SETJMP
00082 
00083 #ifndef _PR_PTHREADS
00084 
00085 #include <setjmp.h>
00086 
00087 #define PR_CONTEXT_TYPE     jmp_buf
00088 
00089 #define CONTEXT(_th) ((_th)->md.context)
00090 
00091 /* balazs.pataki@sztaki.hu:
00092 ** __sparc__ is checked
00093 ** __m68k__ is checked
00094 ** __i386__ is a guess (one of the two defines should work)
00095 */
00096 #if defined(__sparc__)
00097 #define _MD_GET_SP(_th)            (_th)->md.context[2]
00098 #elif defined(__m68k__)
00099 #define _MD_GET_SP(_th)            (_th)->md.context[2]
00100 #elif defined(__i386__)
00101 /* One of this two must be OK ... try using sc_onstack
00102 */
00103 #define _MD_GET_SP(_th)    (((struct sigcontext *) (_th)->md.context)->sc_onstack)
00104 //#define _MD_GET_SP(_th)          (_th)->md.context[0].sc_esp
00105 #else
00106 error Unknown NEXTSTEP architecture
00107 #endif
00108 
00109 #define PR_NUM_GCREGS       _JBLEN
00110 
00111 /*
00112 ** Initialize a thread context to run "_main()" when started
00113 */
00114 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
00115 {  \
00116     *status = PR_TRUE;  \
00117     if (setjmp(CONTEXT(_thread))) {  \
00118         _main();  \
00119     }  \
00120     _MD_GET_SP(_thread) = (int) ((_sp) - 64); \
00121 }
00122 
00123 #define _MD_SWITCH_CONTEXT(_thread)  \
00124     if (!setjmp(CONTEXT(_thread))) {  \
00125        (_thread)->md.errcode = errno;  \
00126        _PR_Schedule();  \
00127     }
00128 
00129 /*
00130 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
00131 */
00132 #define _MD_RESTORE_CONTEXT(_thread) \
00133 {   \
00134     errno = (_thread)->md.errcode;  \
00135     _MD_SET_CURRENT_THREAD(_thread);  \
00136     longjmp(CONTEXT(_thread), 1);  \
00137 }
00138 
00139 /* Machine-dependent (MD) data structures */
00140 
00141 struct _MDThread {
00142     PR_CONTEXT_TYPE context;
00143     int id;
00144     int errcode;
00145 };
00146 
00147 struct _MDThreadStack {
00148     PRInt8 notused;
00149 };
00150 
00151 struct _MDLock {
00152     PRInt8 notused;
00153 };
00154 
00155 struct _MDSemaphore {
00156     PRInt8 notused;
00157 };
00158 
00159 struct _MDCVar {
00160     PRInt8 notused;
00161 };
00162 
00163 struct _MDSegment {
00164     PRInt8 notused;
00165 };
00166 
00167 /*
00168  * md-specific cpu structure field
00169  */
00170 #define _PR_MD_MAX_OSFD FD_SETSIZE
00171 
00172 struct _MDCPU_Unix {
00173     PRCList ioQ;
00174     PRUint32 ioq_timeout;
00175     PRInt32 ioq_max_osfd;
00176     PRInt32 ioq_osfd_cnt;
00177 #ifndef _PR_USE_POLL
00178     fd_set fd_read_set, fd_write_set, fd_exception_set;
00179     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
00180                             fd_exception_cnt[_PR_MD_MAX_OSFD];
00181 #else
00182        struct pollfd *ioq_pollfds;
00183        int ioq_pollfds_size;
00184 #endif /* _PR_USE_POLL */
00185 };
00186 
00187 #define _PR_IOQ(_cpu)                     ((_cpu)->md.md_unix.ioQ)
00188 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
00189 #define _PR_FD_READ_SET(_cpu)             ((_cpu)->md.md_unix.fd_read_set)
00190 #define _PR_FD_READ_CNT(_cpu)             ((_cpu)->md.md_unix.fd_read_cnt)
00191 #define _PR_FD_WRITE_SET(_cpu)            ((_cpu)->md.md_unix.fd_write_set)
00192 #define _PR_FD_WRITE_CNT(_cpu)            ((_cpu)->md.md_unix.fd_write_cnt)
00193 #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
00194 #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
00195 #define _PR_IOQ_TIMEOUT(_cpu)             ((_cpu)->md.md_unix.ioq_timeout)
00196 #define _PR_IOQ_MAX_OSFD(_cpu)            ((_cpu)->md.md_unix.ioq_max_osfd)
00197 #define _PR_IOQ_OSFD_CNT(_cpu)            ((_cpu)->md.md_unix.ioq_osfd_cnt)
00198 #define _PR_IOQ_POLLFDS(_cpu)             ((_cpu)->md.md_unix.ioq_pollfds)
00199 #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
00200 
00201 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)    32
00202 
00203 struct _MDCPU {
00204        struct _MDCPU_Unix md_unix;
00205 };
00206 
00207 #define _MD_INIT_LOCKS()
00208 #define _MD_NEW_LOCK(lock) PR_SUCCESS
00209 #define _MD_FREE_LOCK(lock)
00210 #define _MD_LOCK(lock)
00211 #define _MD_UNLOCK(lock)
00212 #define _MD_INIT_IO()
00213 #define _MD_IOQ_LOCK()
00214 #define _MD_IOQ_UNLOCK()
00215 
00216 extern PRStatus _MD_InitializeThread(PRThread *thread);
00217 
00218 #define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
00219 #define _MD_INIT_THREAD                 _MD_InitializeThread
00220 #define _MD_EXIT_THREAD(thread)
00221 #define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
00222 #define _MD_RESUME_THREAD(thread)       _MD_resume_thread
00223 #define _MD_CLEAN_THREAD(_thread)
00224 
00225 extern PRStatus _MD_CREATE_THREAD(
00226     PRThread *thread,
00227     void (*start) (void *),
00228     PRThreadPriority priority,
00229     PRThreadScope scope,
00230     PRThreadState state,
00231     PRUint32 stackSize);
00232 extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
00233 extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
00234 extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
00235 extern void _MD_YIELD(void);
00236 
00237 #endif /* ! _PR_PTHREADS */
00238 
00239 extern void _MD_EarlyInit(void);
00240 extern PRIntervalTime _PR_UNIX_GetInterval(void);
00241 extern PRIntervalTime _PR_UNIX_TicksPerSecond(void);
00242 
00243 #define _MD_EARLY_INIT                  _MD_EarlyInit
00244 #define _MD_FINAL_INIT                    _PR_UnixInit
00245 #define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
00246 #define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
00247 
00248 /*
00249  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
00250  * unwrapped version.
00251  */
00252 #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
00253 
00254 /* For writev() */
00255 #include <sys/uio.h>
00256 
00257 /* signal.h */
00258 /*     balazs.pataki@sztaki.hu: this is stolen from sunos4.h. The things is that
00259 **     NEXTSTEP doesn't support these flags for `struct sigaction's sa_flags, so
00260 **     I have to fake them ...
00261 */
00262 #define SA_RESTART 0
00263 
00264 /* mmap */
00265 /*     balazs.pataki@sztaki.hu: NEXTSTEP doesn't have mmap, at least not 
00266 **     publically. We have sys/mman.h, but it doesn't declare mmap(), and
00267 **     PROT_NONE is also missing. syscall.h has entries for mmap, munmap, and 
00268 **     mprotect so I wrap these in nextstep.c as  mmap(), munmap() and mprotect()
00269 **     and pray for it to work.
00270 **     
00271 */
00272 caddr_t mmap(caddr_t addr, size_t len, int prot, int flags,
00273           int fildes, off_t off);
00274 int munmap(caddr_t addr, size_t len);
00275 int mprotect(caddr_t addr, size_t len, int prot);
00276 
00277 /*     my_mmap() is implemented in nextstep.c and is based on map_fd() of mach.
00278 */
00279 caddr_t my_mmap(caddr_t addr, size_t len, int prot, int flags,
00280           int fildes, off_t off);
00281 int my_munmap(caddr_t addr, size_t len);
00282 
00283 
00284 /*     string.h
00285 */
00286 /* balazs.pataki@sztaki.hu: this is missing so implemenetd in nextstep.c ...
00287 */
00288 char *strdup(const char *s1);
00289 
00290 /* unistd.h
00291 */
00292 /*     balazs.pataki@sztaki.hu: these functions are hidden, though correctly 
00293 **     implemented in NEXTSTEP. Here I give the declaration for them to be used
00294 **     by prmalloc.c, and I have a wrapped syscall() version of them in nextstep.c
00295 */
00296 int brk(void *endds);
00297 void *sbrk(int incr);
00298 
00299 #endif /* nspr_nextstep_defs_h___ */