1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2/* 3 * The contents of this file are subject to the Mozilla Public 4 * License Version 1.1 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of 6 * the License at http://www.mozilla.org/MPL/ 7 * 8 * Software distributed under the License is distributed on an "AS 9 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 10 * implied. See the License for the specific language governing 11 * rights and limitations under the License. 12 * 13 * The Original Code is the Netscape Portable Runtime (NSPR). 14 * 15 * The Initial Developer of the Original Code is Netscape 16 * Communications Corporation. Portions created by Netscape are 17 * Copyright (C) 1998-2000 Netscape Communications Corporation. All 18 * Rights Reserved. 19 * 20 * Contributor(s): 21 * 22 * Alternatively, the contents of this file may be used under the 23 * terms of the GNU General Public License Version 2 or later (the 24 * "GPL"), in which case the provisions of the GPL are applicable 25 * instead of those above. If you wish to allow use of your 26 * version of this file only under the terms of the GPL and not to 27 * allow others to use your version of this file under the MPL, 28 * indicate your decision by deleting the provisions above and 29 * replace them with the notice and other provisions required by 30 * the GPL. If you do not delete the provisions above, a recipient 31 * may use your version of this file under either the MPL or the 32 * GPL. 33 */ 34 35#ifndef nspr_nextstep_defs_h___ 36#define nspr_nextstep_defs_h___ 37 38#include "prthread.h" 39 40#include <bsd/libc.h> 41#include <bsd/syscall.h> 42 43/* syscall() is not declared in NEXTSTEP's syscall.h ... 44*/ 45extern int syscall(int number, ...); 46 47/* 48 * Internal configuration macros 49 */ 50 51#define PR_LINKER_ARCH "nextstep" 52#define _PR_SI_SYSNAME "NEXTSTEP" 53#if defined(__sparc__) 54#define _PR_SI_ARCHITECTURE "sparc" 55#elif defined(__m68k__) 56#define _PR_SI_ARCHITECTURE "m68k" 57#elif defined(__i386__) 58#define _PR_SI_ARCHITECTURE "x86" 59#else 60error Unknown NEXTSTEP architecture 61#endif 62#define PR_DLL_SUFFIX ".so" 63 64#define _PR_VMBASE 0x30000000 65#define _PR_STACK_VMBASE 0x50000000 66#define _MD_DEFAULT_STACK_SIZE 65536L 67#define _MD_MMAP_FLAGS MAP_PRIVATE 68 69#undef HAVE_STACK_GROWING_UP 70 71#define HAVE_WEAK_MALLOC_SYMBOLS 72 73#define HAVE_DLL 74#define USE_MACH_DYLD 75#define _PR_STAT_HAS_ONLY_ST_ATIME 76#define _PR_NO_LARGE_FILES 77 78#define USE_SETJMP 79 80#ifndef _PR_PTHREADS 81 82#include <setjmp.h> 83 84#define PR_CONTEXT_TYPE jmp_buf 85 86#define CONTEXT(_th) ((_th)->md.context) 87 88/* balazs.pataki@sztaki.hu: 89** __sparc__ is checked 90** __m68k__ is checked 91** __i386__ is a guess (one of the two defines should work) 92*/ 93#if defined(__sparc__) 94#define _MD_GET_SP(_th) (_th)->md.context[2] 95#elif defined(__m68k__) 96#define _MD_GET_SP(_th) (_th)->md.context[2] 97#elif defined(__i386__) 98/* One of this two must be OK ... try using sc_onstack 99*/ 100#define _MD_GET_SP(_th) (((struct sigcontext *) (_th)->md.context)->sc_onstack) 101//#define _MD_GET_SP(_th) (_th)->md.context[0].sc_esp 102#else 103error Unknown NEXTSTEP architecture 104#endif 105 106#define PR_NUM_GCREGS _JBLEN 107 108/* 109** Initialize a thread context to run "_main()" when started 110*/ 111#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ 112{ \ 113 *status = PR_TRUE; \ 114 if (setjmp(CONTEXT(_thread))) { \ 115 _main(); \ 116 } \ 117 _MD_GET_SP(_thread) = (int) ((_sp) - 64); \ 118} 119 120#define _MD_SWITCH_CONTEXT(_thread) \ 121 if (!setjmp(CONTEXT(_thread))) { \ 122 (_thread)->md.errcode = errno; \ 123 _PR_Schedule(); \ 124 } 125 126/* 127** Restore a thread context, saved by _MD_SWITCH_CONTEXT 128*/ 129#define _MD_RESTORE_CONTEXT(_thread) \ 130{ \ 131 errno = (_thread)->md.errcode; \ 132 _MD_SET_CURRENT_THREAD(_thread); \ 133 longjmp(CONTEXT(_thread), 1); \ 134} 135 136/* Machine-dependent (MD) data structures */ 137 138struct _MDThread { 139 PR_CONTEXT_TYPE context; 140 int id; 141 int errcode; 142}; 143 144struct _MDThreadStack { 145 PRInt8 notused; 146}; 147 148struct _MDLock { 149 PRInt8 notused; 150}; 151 152struct _MDSemaphore { 153 PRInt8 notused; 154}; 155 156struct _MDCVar { 157 PRInt8 notused; 158}; 159 160struct _MDSegment { 161 PRInt8 notused; 162}; 163 164/* 165 * md-specific cpu structure field 166 */ 167#define _PR_MD_MAX_OSFD FD_SETSIZE 168 169struct _MDCPU_Unix { 170 PRCList ioQ; 171 PRUint32 ioq_timeout; 172 PRInt32 ioq_max_osfd; 173 PRInt32 ioq_osfd_cnt; 174#ifndef _PR_USE_POLL 175 fd_set fd_read_set, fd_write_set, fd_exception_set; 176 PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD], 177 fd_exception_cnt[_PR_MD_MAX_OSFD]; 178#else 179 struct pollfd *ioq_pollfds; 180 int ioq_pollfds_size; 181#endif /* _PR_USE_POLL */ 182}; 183 184#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ) 185#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu)) 186#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set) 187#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt) 188#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set) 189#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt) 190#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set) 191#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt) 192#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout) 193#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd) 194#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt) 195#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds) 196#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size) 197 198#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32 199 200struct _MDCPU { 201 struct _MDCPU_Unix md_unix; 202}; 203 204#define _MD_INIT_LOCKS() 205#define _MD_NEW_LOCK(lock) PR_SUCCESS 206#define _MD_FREE_LOCK(lock) 207#define _MD_LOCK(lock) 208#define _MD_UNLOCK(lock) 209#define _MD_INIT_IO() 210#define _MD_IOQ_LOCK() 211#define _MD_IOQ_UNLOCK() 212 213extern PRStatus _MD_InitializeThread(PRThread *thread); 214 215#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu) 216#define _MD_INIT_THREAD _MD_InitializeThread 217#define _MD_EXIT_THREAD(thread) 218#define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread 219#define _MD_RESUME_THREAD(thread) _MD_resume_thread 220#define _MD_CLEAN_THREAD(_thread) 221 222extern PRStatus _MD_CREATE_THREAD( 223 PRThread *thread, 224 void (*start) (void *), 225 PRThreadPriority priority, 226 PRThreadScope scope, 227 PRThreadState state, 228 PRUint32 stackSize); 229extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri); 230extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout); 231extern PRStatus _MD_WAKEUP_WAITER(PRThread *); 232extern void _MD_YIELD(void); 233 234#endif /* ! _PR_PTHREADS */ 235 236extern void _MD_EarlyInit(void); 237extern PRIntervalTime _PR_UNIX_GetInterval(void); 238extern PRIntervalTime _PR_UNIX_TicksPerSecond(void); 239 240#define _MD_EARLY_INIT _MD_EarlyInit 241#define _MD_FINAL_INIT _PR_UnixInit 242#define _MD_GET_INTERVAL _PR_UNIX_GetInterval 243#define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond 244 245/* 246 * We wrapped the select() call. _MD_SELECT refers to the built-in, 247 * unwrapped version. 248 */ 249#define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv) 250 251/* For writev() */ 252#include <sys/uio.h> 253 254/* signal.h */ 255/* balazs.pataki@sztaki.hu: this is stolen from sunos4.h. The things is that 256** NEXTSTEP doesn't support these flags for `struct sigaction's sa_flags, so 257** I have to fake them ... 258*/ 259#define SA_RESTART 0 260 261/* mmap */ 262/* balazs.pataki@sztaki.hu: NEXTSTEP doesn't have mmap, at least not 263** publically. We have sys/mman.h, but it doesn't declare mmap(), and 264** PROT_NONE is also missing. syscall.h has entries for mmap, munmap, and 265** mprotect so I wrap these in nextstep.c as mmap(), munmap() and mprotect() 266** and pray for it to work. 267** 268*/ 269caddr_t mmap(caddr_t addr, size_t len, int prot, int flags, 270 int fildes, off_t off); 271int munmap(caddr_t addr, size_t len); 272int mprotect(caddr_t addr, size_t len, int prot); 273 274/* my_mmap() is implemented in nextstep.c and is based on map_fd() of mach. 275*/ 276caddr_t my_mmap(caddr_t addr, size_t len, int prot, int flags, 277 int fildes, off_t off); 278int my_munmap(caddr_t addr, size_t len); 279 280 281/* string.h 282*/ 283/* balazs.pataki@sztaki.hu: this is missing so implemenetd in nextstep.c ... 284*/ 285char *strdup(const char *s1); 286 287/* unistd.h 288*/ 289/* balazs.pataki@sztaki.hu: these functions are hidden, though correctly 290** implemented in NEXTSTEP. Here I give the declaration for them to be used 291** by prmalloc.c, and I have a wrapped syscall() version of them in nextstep.c 292*/ 293int brk(void *endds); 294void *sbrk(int incr); 295 296#endif /* nspr_nextstep_defs_h___ */ 297