nsprpub/pr/include/md/_freebsd.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef nspr_freebsd_defs_h___
     7 #define nspr_freebsd_defs_h___
     9 #include "prthread.h"
    11 #if __FreeBSD__ >= 2
    12 #include <osreldate.h>  /* for __FreeBSD_version */
    13 #endif
    14 #include <sys/syscall.h>
    16 #define PR_LINKER_ARCH	"freebsd"
    17 #define _PR_SI_SYSNAME  "FREEBSD"
    18 #if defined(__i386__)
    19 #define _PR_SI_ARCHITECTURE "x86"
    20 #elif defined(__alpha__)
    21 #define _PR_SI_ARCHITECTURE "alpha"
    22 #elif defined(__sparc__)
    23 #define _PR_SI_ARCHITECTURE "sparc"
    24 #elif defined(__ia64__)
    25 #define _PR_SI_ARCHITECTURE "ia64"
    26 #elif defined(__amd64__)
    27 #define _PR_SI_ARCHITECTURE "amd64"
    28 #else
    29 #error "Unknown CPU architecture"
    30 #endif
    31 #if defined(__ELF__)
    32 #define PR_DLL_SUFFIX          ".so"
    33 #else
    34 #define PR_DLL_SUFFIX          ".so.1.0"
    35 #endif
    37 #define _PR_VMBASE              0x30000000
    38 #define _PR_STACK_VMBASE	0x50000000
    39 #define _MD_DEFAULT_STACK_SIZE	65536L
    40 #define _MD_MMAP_FLAGS          MAP_PRIVATE
    42 #undef  HAVE_STACK_GROWING_UP
    43 #define HAVE_DLL
    44 #define USE_DLFCN
    45 #define _PR_HAVE_SOCKADDR_LEN
    46 #define _PR_STAT_HAS_ST_ATIMESPEC
    47 #define _PR_HAVE_LARGE_OFF_T
    49 #if defined(_PR_PTHREADS)
    50 #if __FreeBSD_version >= 400008
    51 /*
    52  * libc_r before this version of FreeBSD doesn't have poll().
    53  * Although libc has poll(), it is not thread-safe so we can't
    54  * use it in the pthreads version.
    55  */
    56 #define _PR_POLL_AVAILABLE
    57 #endif
    58 #else
    59 #if __FreeBSD_version >= 300000
    60 #define _PR_POLL_AVAILABLE
    61 #define _PR_USE_POLL
    62 #endif
    63 #endif
    65 #define _PR_HAVE_SYSV_SEMAPHORES
    66 #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
    68 #if __FreeBSD_version >= 400014
    69 #define _PR_INET6
    70 #define _PR_HAVE_INET_NTOP
    71 #define _PR_HAVE_GETHOSTBYNAME2
    72 #define _PR_HAVE_GETADDRINFO
    73 #define _PR_INET6_PROBE
    74 #define _PR_IPV6_V6ONLY_PROBE
    75 #endif
    77 #define USE_SETJMP
    79 #ifndef _PR_PTHREADS
    80 #include <setjmp.h>
    82 #define PR_CONTEXT_TYPE	sigjmp_buf
    84 #define CONTEXT(_th) ((_th)->md.context)
    86 #define _MD_GET_SP(_th)    (_th)->md.context[0]._sjb[2]
    87 #define PR_NUM_GCREGS	_JBLEN
    89 /*
    90 ** Initialize a thread context to run "_main()" when started
    91 */
    92 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
    93 {  \
    94     *status = PR_TRUE;  \
    95     if (sigsetjmp(CONTEXT(_thread), 1)) {  \
    96         _main();  \
    97     }  \
    98     _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
    99 }
   101 #define _MD_SWITCH_CONTEXT(_thread)  \
   102     if (!sigsetjmp(CONTEXT(_thread), 1)) {  \
   103 	(_thread)->md.errcode = errno;  \
   104 	_PR_Schedule();  \
   105     }
   107 /*
   108 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
   109 */
   110 #define _MD_RESTORE_CONTEXT(_thread) \
   111 {   \
   112     errno = (_thread)->md.errcode;  \
   113     _MD_SET_CURRENT_THREAD(_thread);  \
   114     siglongjmp(CONTEXT(_thread), 1);  \
   115 }
   117 /* Machine-dependent (MD) data structures */
   119 struct _MDThread {
   120     PR_CONTEXT_TYPE context;
   121     int id;
   122     int errcode;
   123 };
   125 struct _MDThreadStack {
   126     PRInt8 notused;
   127 };
   129 struct _MDLock {
   130     PRInt8 notused;
   131 };
   133 struct _MDSemaphore {
   134     PRInt8 notused;
   135 };
   137 struct _MDCVar {
   138     PRInt8 notused;
   139 };
   141 struct _MDSegment {
   142     PRInt8 notused;
   143 };
   145 /*
   146  * md-specific cpu structure field
   147  */
   148 #define _PR_MD_MAX_OSFD FD_SETSIZE
   150 struct _MDCPU_Unix {
   151     PRCList ioQ;
   152     PRUint32 ioq_timeout;
   153     PRInt32 ioq_max_osfd;
   154     PRInt32 ioq_osfd_cnt;
   155 #ifndef _PR_USE_POLL
   156     fd_set fd_read_set, fd_write_set, fd_exception_set;
   157     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
   158 				fd_exception_cnt[_PR_MD_MAX_OSFD];
   159 #else
   160 	struct pollfd *ioq_pollfds;
   161 	int ioq_pollfds_size;
   162 #endif	/* _PR_USE_POLL */
   163 };
   165 #define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
   166 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
   167 #define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
   168 #define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
   169 #define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
   170 #define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
   171 #define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
   172 #define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
   173 #define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
   174 #define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
   175 #define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
   176 #define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
   177 #define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
   179 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
   181 struct _MDCPU {
   182 	struct _MDCPU_Unix md_unix;
   183 };
   185 #define _MD_INIT_LOCKS()
   186 #define _MD_NEW_LOCK(lock) PR_SUCCESS
   187 #define _MD_FREE_LOCK(lock)
   188 #define _MD_LOCK(lock)
   189 #define _MD_UNLOCK(lock)
   190 #define _MD_INIT_IO()
   191 #define _MD_IOQ_LOCK()
   192 #define _MD_IOQ_UNLOCK()
   194 extern PRStatus _MD_InitializeThread(PRThread *thread);
   196 #define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
   197 #define _MD_INIT_THREAD                 _MD_InitializeThread
   198 #define _MD_EXIT_THREAD(thread)
   199 #define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
   200 #define _MD_RESUME_THREAD(thread)       _MD_resume_thread
   201 #define _MD_CLEAN_THREAD(_thread)
   203 extern PRStatus _MD_CREATE_THREAD(
   204     PRThread *thread,
   205     void (*start) (void *),
   206     PRThreadPriority priority,
   207     PRThreadScope scope,
   208     PRThreadState state,
   209     PRUint32 stackSize);
   210 extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
   211 extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
   212 extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
   213 extern void _MD_YIELD(void);
   215 #endif /* ! _PR_PTHREADS */
   217 extern void _MD_EarlyInit(void);
   219 #define _MD_EARLY_INIT                  _MD_EarlyInit
   220 #define _MD_FINAL_INIT			_PR_UnixInit
   221 #define _MD_INTERVAL_USE_GTOD
   223 /*
   224  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
   225  * unwrapped version.
   226  */
   227 #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
   229 #if defined(_PR_POLL_AVAILABLE)
   230 #include <poll.h>
   231 #define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
   232 #endif
   234 /* freebsd has INADDR_LOOPBACK defined, but in /usr/include/rpc/types.h, and I didn't
   235    want to be including that.. */
   236 #ifndef INADDR_LOOPBACK
   237 #define INADDR_LOOPBACK         (u_long)0x7F000001
   238 #endif
   240 /* For writev() */
   241 #include <sys/uio.h>
   243 #endif /* nspr_freebsd_defs_h___ */

mercurial