1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/include/md/_freebsd.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,243 @@ 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_freebsd_defs_h___ 1.10 +#define nspr_freebsd_defs_h___ 1.11 + 1.12 +#include "prthread.h" 1.13 + 1.14 +#if __FreeBSD__ >= 2 1.15 +#include <osreldate.h> /* for __FreeBSD_version */ 1.16 +#endif 1.17 +#include <sys/syscall.h> 1.18 + 1.19 +#define PR_LINKER_ARCH "freebsd" 1.20 +#define _PR_SI_SYSNAME "FREEBSD" 1.21 +#if defined(__i386__) 1.22 +#define _PR_SI_ARCHITECTURE "x86" 1.23 +#elif defined(__alpha__) 1.24 +#define _PR_SI_ARCHITECTURE "alpha" 1.25 +#elif defined(__sparc__) 1.26 +#define _PR_SI_ARCHITECTURE "sparc" 1.27 +#elif defined(__ia64__) 1.28 +#define _PR_SI_ARCHITECTURE "ia64" 1.29 +#elif defined(__amd64__) 1.30 +#define _PR_SI_ARCHITECTURE "amd64" 1.31 +#else 1.32 +#error "Unknown CPU architecture" 1.33 +#endif 1.34 +#if defined(__ELF__) 1.35 +#define PR_DLL_SUFFIX ".so" 1.36 +#else 1.37 +#define PR_DLL_SUFFIX ".so.1.0" 1.38 +#endif 1.39 + 1.40 +#define _PR_VMBASE 0x30000000 1.41 +#define _PR_STACK_VMBASE 0x50000000 1.42 +#define _MD_DEFAULT_STACK_SIZE 65536L 1.43 +#define _MD_MMAP_FLAGS MAP_PRIVATE 1.44 + 1.45 +#undef HAVE_STACK_GROWING_UP 1.46 +#define HAVE_DLL 1.47 +#define USE_DLFCN 1.48 +#define _PR_HAVE_SOCKADDR_LEN 1.49 +#define _PR_STAT_HAS_ST_ATIMESPEC 1.50 +#define _PR_HAVE_LARGE_OFF_T 1.51 + 1.52 +#if defined(_PR_PTHREADS) 1.53 +#if __FreeBSD_version >= 400008 1.54 +/* 1.55 + * libc_r before this version of FreeBSD doesn't have poll(). 1.56 + * Although libc has poll(), it is not thread-safe so we can't 1.57 + * use it in the pthreads version. 1.58 + */ 1.59 +#define _PR_POLL_AVAILABLE 1.60 +#endif 1.61 +#else 1.62 +#if __FreeBSD_version >= 300000 1.63 +#define _PR_POLL_AVAILABLE 1.64 +#define _PR_USE_POLL 1.65 +#endif 1.66 +#endif 1.67 + 1.68 +#define _PR_HAVE_SYSV_SEMAPHORES 1.69 +#define PR_HAVE_SYSV_NAMED_SHARED_MEMORY 1.70 + 1.71 +#if __FreeBSD_version >= 400014 1.72 +#define _PR_INET6 1.73 +#define _PR_HAVE_INET_NTOP 1.74 +#define _PR_HAVE_GETHOSTBYNAME2 1.75 +#define _PR_HAVE_GETADDRINFO 1.76 +#define _PR_INET6_PROBE 1.77 +#define _PR_IPV6_V6ONLY_PROBE 1.78 +#endif 1.79 + 1.80 +#define USE_SETJMP 1.81 + 1.82 +#ifndef _PR_PTHREADS 1.83 +#include <setjmp.h> 1.84 + 1.85 +#define PR_CONTEXT_TYPE sigjmp_buf 1.86 + 1.87 +#define CONTEXT(_th) ((_th)->md.context) 1.88 + 1.89 +#define _MD_GET_SP(_th) (_th)->md.context[0]._sjb[2] 1.90 +#define PR_NUM_GCREGS _JBLEN 1.91 + 1.92 +/* 1.93 +** Initialize a thread context to run "_main()" when started 1.94 +*/ 1.95 +#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \ 1.96 +{ \ 1.97 + *status = PR_TRUE; \ 1.98 + if (sigsetjmp(CONTEXT(_thread), 1)) { \ 1.99 + _main(); \ 1.100 + } \ 1.101 + _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \ 1.102 +} 1.103 + 1.104 +#define _MD_SWITCH_CONTEXT(_thread) \ 1.105 + if (!sigsetjmp(CONTEXT(_thread), 1)) { \ 1.106 + (_thread)->md.errcode = errno; \ 1.107 + _PR_Schedule(); \ 1.108 + } 1.109 + 1.110 +/* 1.111 +** Restore a thread context, saved by _MD_SWITCH_CONTEXT 1.112 +*/ 1.113 +#define _MD_RESTORE_CONTEXT(_thread) \ 1.114 +{ \ 1.115 + errno = (_thread)->md.errcode; \ 1.116 + _MD_SET_CURRENT_THREAD(_thread); \ 1.117 + siglongjmp(CONTEXT(_thread), 1); \ 1.118 +} 1.119 + 1.120 +/* Machine-dependent (MD) data structures */ 1.121 + 1.122 +struct _MDThread { 1.123 + PR_CONTEXT_TYPE context; 1.124 + int id; 1.125 + int errcode; 1.126 +}; 1.127 + 1.128 +struct _MDThreadStack { 1.129 + PRInt8 notused; 1.130 +}; 1.131 + 1.132 +struct _MDLock { 1.133 + PRInt8 notused; 1.134 +}; 1.135 + 1.136 +struct _MDSemaphore { 1.137 + PRInt8 notused; 1.138 +}; 1.139 + 1.140 +struct _MDCVar { 1.141 + PRInt8 notused; 1.142 +}; 1.143 + 1.144 +struct _MDSegment { 1.145 + PRInt8 notused; 1.146 +}; 1.147 + 1.148 +/* 1.149 + * md-specific cpu structure field 1.150 + */ 1.151 +#define _PR_MD_MAX_OSFD FD_SETSIZE 1.152 + 1.153 +struct _MDCPU_Unix { 1.154 + PRCList ioQ; 1.155 + PRUint32 ioq_timeout; 1.156 + PRInt32 ioq_max_osfd; 1.157 + PRInt32 ioq_osfd_cnt; 1.158 +#ifndef _PR_USE_POLL 1.159 + fd_set fd_read_set, fd_write_set, fd_exception_set; 1.160 + PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD], 1.161 + fd_exception_cnt[_PR_MD_MAX_OSFD]; 1.162 +#else 1.163 + struct pollfd *ioq_pollfds; 1.164 + int ioq_pollfds_size; 1.165 +#endif /* _PR_USE_POLL */ 1.166 +}; 1.167 + 1.168 +#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ) 1.169 +#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu)) 1.170 +#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set) 1.171 +#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt) 1.172 +#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set) 1.173 +#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt) 1.174 +#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set) 1.175 +#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt) 1.176 +#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout) 1.177 +#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd) 1.178 +#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt) 1.179 +#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds) 1.180 +#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size) 1.181 + 1.182 +#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32 1.183 + 1.184 +struct _MDCPU { 1.185 + struct _MDCPU_Unix md_unix; 1.186 +}; 1.187 + 1.188 +#define _MD_INIT_LOCKS() 1.189 +#define _MD_NEW_LOCK(lock) PR_SUCCESS 1.190 +#define _MD_FREE_LOCK(lock) 1.191 +#define _MD_LOCK(lock) 1.192 +#define _MD_UNLOCK(lock) 1.193 +#define _MD_INIT_IO() 1.194 +#define _MD_IOQ_LOCK() 1.195 +#define _MD_IOQ_UNLOCK() 1.196 + 1.197 +extern PRStatus _MD_InitializeThread(PRThread *thread); 1.198 + 1.199 +#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu) 1.200 +#define _MD_INIT_THREAD _MD_InitializeThread 1.201 +#define _MD_EXIT_THREAD(thread) 1.202 +#define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread 1.203 +#define _MD_RESUME_THREAD(thread) _MD_resume_thread 1.204 +#define _MD_CLEAN_THREAD(_thread) 1.205 + 1.206 +extern PRStatus _MD_CREATE_THREAD( 1.207 + PRThread *thread, 1.208 + void (*start) (void *), 1.209 + PRThreadPriority priority, 1.210 + PRThreadScope scope, 1.211 + PRThreadState state, 1.212 + PRUint32 stackSize); 1.213 +extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri); 1.214 +extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout); 1.215 +extern PRStatus _MD_WAKEUP_WAITER(PRThread *); 1.216 +extern void _MD_YIELD(void); 1.217 + 1.218 +#endif /* ! _PR_PTHREADS */ 1.219 + 1.220 +extern void _MD_EarlyInit(void); 1.221 + 1.222 +#define _MD_EARLY_INIT _MD_EarlyInit 1.223 +#define _MD_FINAL_INIT _PR_UnixInit 1.224 +#define _MD_INTERVAL_USE_GTOD 1.225 + 1.226 +/* 1.227 + * We wrapped the select() call. _MD_SELECT refers to the built-in, 1.228 + * unwrapped version. 1.229 + */ 1.230 +#define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv) 1.231 + 1.232 +#if defined(_PR_POLL_AVAILABLE) 1.233 +#include <poll.h> 1.234 +#define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout) 1.235 +#endif 1.236 + 1.237 +/* freebsd has INADDR_LOOPBACK defined, but in /usr/include/rpc/types.h, and I didn't 1.238 + want to be including that.. */ 1.239 +#ifndef INADDR_LOOPBACK 1.240 +#define INADDR_LOOPBACK (u_long)0x7F000001 1.241 +#endif 1.242 + 1.243 +/* For writev() */ 1.244 +#include <sys/uio.h> 1.245 + 1.246 +#endif /* nspr_freebsd_defs_h___ */