| OLD | NEW |
| (Empty) |
| 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_netbsd_defs_h___ | |
| 36 #define nspr_netbsd_defs_h___ | |
| 37 | |
| 38 #include <sys/syscall.h> | |
| 39 #include <sys/param.h> /* for __NetBSD_Version__ */ | |
| 40 | |
| 41 #define PR_LINKER_ARCH "netbsd" | |
| 42 #define _PR_SI_SYSNAME "NetBSD" | |
| 43 #if defined(__i386__) | |
| 44 #define _PR_SI_ARCHITECTURE "x86" | |
| 45 #elif defined(__alpha__) | |
| 46 #define _PR_SI_ARCHITECTURE "alpha" | |
| 47 #elif defined(__m68k__) | |
| 48 #define _PR_SI_ARCHITECTURE "m68k" | |
| 49 #elif defined(__powerpc__) | |
| 50 #define _PR_SI_ARCHITECTURE "powerpc" | |
| 51 #elif defined(__sparc__) | |
| 52 #define _PR_SI_ARCHITECTURE "sparc" | |
| 53 #elif defined(__mips__) | |
| 54 #define _PR_SI_ARCHITECTURE "mips" | |
| 55 #elif defined(__arm32__) | |
| 56 #define _PR_SI_ARCHITECTURE "arm32" | |
| 57 #endif | |
| 58 | |
| 59 #if defined(__ELF__) | |
| 60 #define PR_DLL_SUFFIX ".so" | |
| 61 #else | |
| 62 #define PR_DLL_SUFFIX ".so.1.0" | |
| 63 #endif | |
| 64 | |
| 65 #define _PR_VMBASE 0x30000000 | |
| 66 #define _PR_STACK_VMBASE 0x50000000 | |
| 67 #define _MD_DEFAULT_STACK_SIZE 65536L | |
| 68 #define _MD_MMAP_FLAGS MAP_PRIVATE | |
| 69 | |
| 70 #undef HAVE_STACK_GROWING_UP | |
| 71 #define HAVE_DLL | |
| 72 #define USE_DLFCN | |
| 73 #define _PR_HAVE_SOCKADDR_LEN | |
| 74 #define _PR_NO_LARGE_FILES | |
| 75 #define _PR_STAT_HAS_ST_ATIMESPEC | |
| 76 #define _PR_POLL_AVAILABLE | |
| 77 #define _PR_USE_POLL | |
| 78 #define _PR_HAVE_SYSV_SEMAPHORES | |
| 79 #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY | |
| 80 | |
| 81 #if __NetBSD_Version__ >= 105000000 | |
| 82 #define _PR_INET6 | |
| 83 #define _PR_HAVE_INET_NTOP | |
| 84 #define _PR_HAVE_GETHOSTBYNAME2 | |
| 85 #define _PR_HAVE_GETADDRINFO | |
| 86 #define _PR_INET6_PROBE | |
| 87 #endif | |
| 88 | |
| 89 #define USE_SETJMP | |
| 90 | |
| 91 #ifndef _PR_PTHREADS | |
| 92 #include <setjmp.h> | |
| 93 | |
| 94 #define PR_CONTEXT_TYPE sigjmp_buf | |
| 95 | |
| 96 #define CONTEXT(_th) ((_th)->md.context) | |
| 97 | |
| 98 /* | |
| 99 ** Initialize a thread context to run "_main()" when started | |
| 100 */ | |
| 101 #ifdef __i386__ | |
| 102 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ | |
| 103 { \ | |
| 104 sigsetjmp(CONTEXT(_thread), 1); \ | |
| 105 CONTEXT(_thread)[2] = (unsigned char*) ((_sp) - 128); \ | |
| 106 CONTEXT(_thread)[0] = (int) _main; \ | |
| 107 *status = PR_TRUE; \ | |
| 108 } | |
| 109 #define _MD_GET_SP(_thread) CONTEXT(_thread)[2] | |
| 110 #endif | |
| 111 #ifdef __sparc__ | |
| 112 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ | |
| 113 { \ | |
| 114 sigsetjmp(CONTEXT(_thread), 1); \ | |
| 115 CONTEXT(_thread)[2] = (unsigned char*) ((_sp) - 128); \ | |
| 116 CONTEXT(_thread)[3] = (int) _main; \ | |
| 117 CONTEXT(_thread)[4] = (int) _main + 4; \ | |
| 118 *status = PR_TRUE; \ | |
| 119 } | |
| 120 #define _MD_GET_SP(_thread) CONTEXT(_thread)[2] | |
| 121 #endif | |
| 122 #ifdef __powerpc__ | |
| 123 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ | |
| 124 { \ | |
| 125 sigsetjmp(CONTEXT(_thread), 1); \ | |
| 126 CONTEXT(_thread)[3] = (unsigned char*) ((_sp) - 128); \ | |
| 127 CONTEXT(_thread)[4] = (int) _main; \ | |
| 128 *status = PR_TRUE; \ | |
| 129 } | |
| 130 #define _MD_GET_SP(_thread) CONTEXT(_thread)[3] | |
| 131 #endif | |
| 132 #ifdef __m68k__ | |
| 133 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ | |
| 134 { \ | |
| 135 sigsetjmp(CONTEXT(_thread), 1); \ | |
| 136 CONTEXT(_thread)[2] = (unsigned char*) ((_sp) - 128); \ | |
| 137 CONTEXT(_thread)[5] = (int) _main; \ | |
| 138 *status = PR_TRUE; \ | |
| 139 } | |
| 140 #define _MD_GET_SP(_thread) CONTEXT(_thread)[2] | |
| 141 #endif | |
| 142 #ifdef __mips__ | |
| 143 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ | |
| 144 { \ | |
| 145 sigsetjmp(CONTEXT(_thread), 1); \ | |
| 146 CONTEXT(_thread)[32] = (unsigned char*) ((_sp) - 128); \ | |
| 147 CONTEXT(_thread)[2] = (int) _main; \ | |
| 148 CONTEXT(_thread)[28] = (int) _main; \ | |
| 149 *status = PR_TRUE; \ | |
| 150 } | |
| 151 #define _MD_GET_SP(_thread) CONTEXT(_thread)[32] | |
| 152 #endif | |
| 153 #ifdef __arm32__ | |
| 154 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ | |
| 155 { \ | |
| 156 sigsetjmp(CONTEXT(_thread), 1); \ | |
| 157 CONTEXT(_thread)[23] = (unsigned char*) ((_sp) - 128); \ | |
| 158 CONTEXT(_thread)[24] = (int) _main; \ | |
| 159 *status = PR_TRUE; \ | |
| 160 } | |
| 161 #define _MD_GET_SP(_thread) CONTEXT(_thread)[23] | |
| 162 #endif | |
| 163 #ifdef __alpha__ | |
| 164 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ | |
| 165 { \ | |
| 166 sigsetjmp(CONTEXT(_thread), 1); \ | |
| 167 CONTEXT(_thread)[34] = (unsigned char*) ((_sp) - 128); \ | |
| 168 CONTEXT(_thread)[2] = (long) _main; \ | |
| 169 CONTEXT(_thread)[30] = (long) _main; \ | |
| 170 CONTEXT(_thread)[31] = (long) _main; \ | |
| 171 *status = PR_TRUE; \ | |
| 172 } | |
| 173 #define _MD_GET_SP(_thread) CONTEXT(_thread)[34] | |
| 174 #endif | |
| 175 #ifndef _MD_INIT_CONTEXT | |
| 176 #error "Need to define _MD_INIT_CONTEXT for this platform" | |
| 177 #endif | |
| 178 | |
| 179 #define PR_NUM_GCREGS _JBLEN | |
| 180 | |
| 181 #define _MD_SWITCH_CONTEXT(_thread) \ | |
| 182 if (!sigsetjmp(CONTEXT(_thread), 1)) { \ | |
| 183 (_thread)->md.errcode = errno; \ | |
| 184 _PR_Schedule(); \ | |
| 185 } | |
| 186 | |
| 187 /* | |
| 188 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT | |
| 189 */ | |
| 190 #define _MD_RESTORE_CONTEXT(_thread) \ | |
| 191 { \ | |
| 192 errno = (_thread)->md.errcode; \ | |
| 193 _MD_SET_CURRENT_THREAD(_thread); \ | |
| 194 siglongjmp(CONTEXT(_thread), 1); \ | |
| 195 } | |
| 196 | |
| 197 /* Machine-dependent (MD) data structures */ | |
| 198 | |
| 199 struct _MDThread { | |
| 200 PR_CONTEXT_TYPE context; | |
| 201 int id; | |
| 202 int errcode; | |
| 203 }; | |
| 204 | |
| 205 struct _MDThreadStack { | |
| 206 PRInt8 notused; | |
| 207 }; | |
| 208 | |
| 209 struct _MDLock { | |
| 210 PRInt8 notused; | |
| 211 }; | |
| 212 | |
| 213 struct _MDSemaphore { | |
| 214 PRInt8 notused; | |
| 215 }; | |
| 216 | |
| 217 struct _MDCVar { | |
| 218 PRInt8 notused; | |
| 219 }; | |
| 220 | |
| 221 struct _MDSegment { | |
| 222 PRInt8 notused; | |
| 223 }; | |
| 224 | |
| 225 /* | |
| 226 * md-specific cpu structure field | |
| 227 */ | |
| 228 #define _PR_MD_MAX_OSFD FD_SETSIZE | |
| 229 | |
| 230 struct _MDCPU_Unix { | |
| 231 PRCList ioQ; | |
| 232 PRUint32 ioq_timeout; | |
| 233 PRInt32 ioq_max_osfd; | |
| 234 PRInt32 ioq_osfd_cnt; | |
| 235 #ifndef _PR_USE_POLL | |
| 236 fd_set fd_read_set, fd_write_set, fd_exception_set; | |
| 237 PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD], | |
| 238 fd_exception_cnt[_PR_MD_MAX_OSFD]; | |
| 239 #else | |
| 240 struct pollfd *ioq_pollfds; | |
| 241 int ioq_pollfds_size; | |
| 242 #endif /* _PR_USE_POLL */ | |
| 243 }; | |
| 244 | |
| 245 #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ) | |
| 246 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu)) | |
| 247 #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set) | |
| 248 #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt) | |
| 249 #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set) | |
| 250 #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt) | |
| 251 #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set) | |
| 252 #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt) | |
| 253 #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout) | |
| 254 #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd) | |
| 255 #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt) | |
| 256 #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds) | |
| 257 #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size) | |
| 258 | |
| 259 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32 | |
| 260 | |
| 261 struct _MDCPU { | |
| 262 struct _MDCPU_Unix md_unix; | |
| 263 }; | |
| 264 | |
| 265 #define _MD_INIT_LOCKS() | |
| 266 #define _MD_NEW_LOCK(lock) PR_SUCCESS | |
| 267 #define _MD_FREE_LOCK(lock) | |
| 268 #define _MD_LOCK(lock) | |
| 269 #define _MD_UNLOCK(lock) | |
| 270 #define _MD_INIT_IO() | |
| 271 #define _MD_IOQ_LOCK() | |
| 272 #define _MD_IOQ_UNLOCK() | |
| 273 | |
| 274 #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu) | |
| 275 #define _MD_INIT_THREAD _MD_InitializeThread | |
| 276 #define _MD_EXIT_THREAD(thread) | |
| 277 #define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread | |
| 278 #define _MD_RESUME_THREAD(thread) _MD_resume_thread | |
| 279 #define _MD_CLEAN_THREAD(_thread) | |
| 280 | |
| 281 #endif /* ! _PR_PTHREADS */ | |
| 282 | |
| 283 #define _MD_EARLY_INIT _MD_EarlyInit | |
| 284 #define _MD_FINAL_INIT _PR_UnixInit | |
| 285 #define _MD_GET_INTERVAL _PR_UNIX_GetInterval | |
| 286 #define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond | |
| 287 | |
| 288 /* | |
| 289 * We wrapped the select() call. _MD_SELECT refers to the built-in, | |
| 290 * unwrapped version. | |
| 291 */ | |
| 292 #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv) | |
| 293 #if defined(_PR_POLL_AVAILABLE) | |
| 294 #include <poll.h> | |
| 295 #define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout) | |
| 296 #endif | |
| 297 | |
| 298 #if NetBSD1_3 == 1L | |
| 299 typedef unsigned int nfds_t; | |
| 300 #endif | |
| 301 | |
| 302 #endif /* nspr_netbsd_defs_h___ */ | |
| OLD | NEW |