nsprpub/pr/include/md/_netbsd.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/include/md/_netbsd.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,230 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nspr_netbsd_defs_h___
    1.10 +#define nspr_netbsd_defs_h___
    1.11 +
    1.12 +#include <sys/syscall.h>
    1.13 +#include <sys/param.h>  /* for __NetBSD_Version__ */
    1.14 +
    1.15 +#define PR_LINKER_ARCH	"netbsd"
    1.16 +#define _PR_SI_SYSNAME  "NetBSD"
    1.17 +#if defined(__i386__)
    1.18 +#define _PR_SI_ARCHITECTURE "x86"
    1.19 +#elif defined(__alpha__)
    1.20 +#define _PR_SI_ARCHITECTURE "alpha"
    1.21 +#elif defined(__amd64__)
    1.22 +#define _PR_SI_ARCHITECTURE "amd64"
    1.23 +#elif defined(__m68k__)
    1.24 +#define _PR_SI_ARCHITECTURE "m68k"
    1.25 +#elif defined(__powerpc__)
    1.26 +#define _PR_SI_ARCHITECTURE "powerpc"
    1.27 +#elif defined(__sparc_v9__)
    1.28 +#define _PR_SI_ARCHITECTURE "sparc64"
    1.29 +#elif defined(__sparc__)
    1.30 +#define _PR_SI_ARCHITECTURE "sparc"
    1.31 +#elif defined(__mips__)
    1.32 +#define _PR_SI_ARCHITECTURE "mips"
    1.33 +#elif defined(__arm32__) || defined(__arm__) || defined(__armel__) \
    1.34 +    || defined(__armeb__)
    1.35 +#define _PR_SI_ARCHITECTURE "arm"
    1.36 +#endif
    1.37 +
    1.38 +#if defined(__ELF__)
    1.39 +#define PR_DLL_SUFFIX		".so"
    1.40 +#else
    1.41 +#define PR_DLL_SUFFIX		".so.1.0"
    1.42 +#endif
    1.43 +
    1.44 +#define _PR_VMBASE              0x30000000
    1.45 +#define _PR_STACK_VMBASE	0x50000000
    1.46 +#define _MD_DEFAULT_STACK_SIZE	65536L
    1.47 +#define _MD_MMAP_FLAGS          MAP_PRIVATE
    1.48 +
    1.49 +#undef  HAVE_STACK_GROWING_UP
    1.50 +#define HAVE_DLL
    1.51 +#define USE_DLFCN
    1.52 +#define _PR_HAVE_SOCKADDR_LEN
    1.53 +#define _PR_NO_LARGE_FILES
    1.54 +#define _PR_STAT_HAS_ST_ATIMESPEC
    1.55 +#define _PR_POLL_AVAILABLE
    1.56 +#define _PR_USE_POLL
    1.57 +#define _PR_HAVE_SYSV_SEMAPHORES
    1.58 +#define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
    1.59 +
    1.60 +#if __NetBSD_Version__ >= 105000000
    1.61 +#define _PR_INET6
    1.62 +#define _PR_HAVE_INET_NTOP
    1.63 +#define _PR_HAVE_GETHOSTBYNAME2
    1.64 +#define _PR_HAVE_GETADDRINFO
    1.65 +#define _PR_INET6_PROBE
    1.66 +#endif
    1.67 +
    1.68 +#define USE_SETJMP
    1.69 +
    1.70 +#ifndef _PR_PTHREADS
    1.71 +#include <setjmp.h>
    1.72 +
    1.73 +#define PR_CONTEXT_TYPE	sigjmp_buf
    1.74 +
    1.75 +#define CONTEXT(_th) ((_th)->md.context)
    1.76 +
    1.77 +#if defined(__i386__) || defined(__sparc__) || defined(__m68k__) || defined(__powerpc__)
    1.78 +#define JB_SP_INDEX 2
    1.79 +#elif defined(__mips__)
    1.80 +#define JB_SP_INDEX 4
    1.81 +#elif defined(__alpha__)
    1.82 +#define JB_SP_INDEX 34
    1.83 +#elif defined(__arm32__)
    1.84 +/*
    1.85 + * On the arm32, the jmpbuf regs underwent a name change after NetBSD 1.3.
    1.86 + */
    1.87 +#ifdef JMPBUF_REG_R13
    1.88 +#define JB_SP_INDEX JMPBUF_REG_R13
    1.89 +#else
    1.90 +#define JB_SP_INDEX _JB_REG_R13
    1.91 +#endif
    1.92 +#else
    1.93 +#error "Need to define SP index in jmp_buf here"
    1.94 +#endif
    1.95 +#define _MD_GET_SP(_th)    (_th)->md.context[JB_SP_INDEX]
    1.96 +
    1.97 +#define PR_NUM_GCREGS	_JBLEN
    1.98 +
    1.99 +/*
   1.100 +** Initialize a thread context to run "_main()" when started
   1.101 +*/
   1.102 +#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
   1.103 +{  \
   1.104 +    *status = PR_TRUE;  \
   1.105 +    if (sigsetjmp(CONTEXT(_thread), 1)) {  \
   1.106 +        _main();  \
   1.107 +    }  \
   1.108 +    _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
   1.109 +}
   1.110 +
   1.111 +#define _MD_SWITCH_CONTEXT(_thread)  \
   1.112 +    if (!sigsetjmp(CONTEXT(_thread), 1)) {  \
   1.113 +        (_thread)->md.errcode = errno;  \
   1.114 +        _PR_Schedule();  \
   1.115 +    }
   1.116 +
   1.117 +/*
   1.118 +** Restore a thread context, saved by _MD_SWITCH_CONTEXT
   1.119 +*/
   1.120 +#define _MD_RESTORE_CONTEXT(_thread) \
   1.121 +{   \
   1.122 +    errno = (_thread)->md.errcode;  \
   1.123 +    _MD_SET_CURRENT_THREAD(_thread);  \
   1.124 +    siglongjmp(CONTEXT(_thread), 1);  \
   1.125 +}
   1.126 +
   1.127 +/* Machine-dependent (MD) data structures */
   1.128 +
   1.129 +struct _MDThread {
   1.130 +    PR_CONTEXT_TYPE context;
   1.131 +    int id;
   1.132 +    int errcode;
   1.133 +};
   1.134 +
   1.135 +struct _MDThreadStack {
   1.136 +    PRInt8 notused;
   1.137 +};
   1.138 +
   1.139 +struct _MDLock {
   1.140 +    PRInt8 notused;
   1.141 +};
   1.142 +
   1.143 +struct _MDSemaphore {
   1.144 +    PRInt8 notused;
   1.145 +};
   1.146 +
   1.147 +struct _MDCVar {
   1.148 +    PRInt8 notused;
   1.149 +};
   1.150 +
   1.151 +struct _MDSegment {
   1.152 +    PRInt8 notused;
   1.153 +};
   1.154 +
   1.155 +/*
   1.156 + * md-specific cpu structure field
   1.157 + */
   1.158 +#define _PR_MD_MAX_OSFD FD_SETSIZE
   1.159 +
   1.160 +struct _MDCPU_Unix {
   1.161 +    PRCList ioQ;
   1.162 +    PRUint32 ioq_timeout;
   1.163 +    PRInt32 ioq_max_osfd;
   1.164 +    PRInt32 ioq_osfd_cnt;
   1.165 +#ifndef _PR_USE_POLL
   1.166 +    fd_set fd_read_set, fd_write_set, fd_exception_set;
   1.167 +    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
   1.168 +				fd_exception_cnt[_PR_MD_MAX_OSFD];
   1.169 +#else
   1.170 +	struct pollfd *ioq_pollfds;
   1.171 +	int ioq_pollfds_size;
   1.172 +#endif	/* _PR_USE_POLL */
   1.173 +};
   1.174 +
   1.175 +#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
   1.176 +#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
   1.177 +#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
   1.178 +#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
   1.179 +#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
   1.180 +#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
   1.181 +#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
   1.182 +#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
   1.183 +#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
   1.184 +#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
   1.185 +#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
   1.186 +#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
   1.187 +#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
   1.188 +
   1.189 +#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
   1.190 +
   1.191 +struct _MDCPU {
   1.192 +    struct _MDCPU_Unix md_unix;
   1.193 +};
   1.194 +
   1.195 +#define _MD_INIT_LOCKS()
   1.196 +#define _MD_NEW_LOCK(lock) PR_SUCCESS
   1.197 +#define _MD_FREE_LOCK(lock)
   1.198 +#define _MD_LOCK(lock)
   1.199 +#define _MD_UNLOCK(lock)
   1.200 +#define _MD_INIT_IO()
   1.201 +#define _MD_IOQ_LOCK()
   1.202 +#define _MD_IOQ_UNLOCK()
   1.203 +
   1.204 +#define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
   1.205 +#define _MD_INIT_THREAD                 _MD_InitializeThread
   1.206 +#define _MD_EXIT_THREAD(thread)
   1.207 +#define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
   1.208 +#define _MD_RESUME_THREAD(thread)       _MD_resume_thread
   1.209 +#define _MD_CLEAN_THREAD(_thread)
   1.210 +
   1.211 +#endif /* ! _PR_PTHREADS */
   1.212 +
   1.213 +extern void _MD_EarlyInit(void);
   1.214 +
   1.215 +#define _MD_EARLY_INIT                  _MD_EarlyInit
   1.216 +#define _MD_FINAL_INIT			_PR_UnixInit
   1.217 +#define _MD_INTERVAL_USE_GTOD
   1.218 +
   1.219 +/*
   1.220 + * We wrapped the select() call.  _MD_SELECT refers to the built-in,
   1.221 + * unwrapped version.
   1.222 + */
   1.223 +#define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
   1.224 +#if defined(_PR_POLL_AVAILABLE)
   1.225 +#include <poll.h>
   1.226 +#define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
   1.227 +#endif
   1.228 +
   1.229 +#if NetBSD1_3 == 1L
   1.230 +typedef unsigned int nfds_t;
   1.231 +#endif
   1.232 +
   1.233 +#endif /* nspr_netbsd_defs_h___ */

mercurial