Fri, 16 Jan 2015 04:50:19 +0100
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_netbsd_defs_h___
7 #define nspr_netbsd_defs_h___
9 #include <sys/syscall.h>
10 #include <sys/param.h> /* for __NetBSD_Version__ */
12 #define PR_LINKER_ARCH "netbsd"
13 #define _PR_SI_SYSNAME "NetBSD"
14 #if defined(__i386__)
15 #define _PR_SI_ARCHITECTURE "x86"
16 #elif defined(__alpha__)
17 #define _PR_SI_ARCHITECTURE "alpha"
18 #elif defined(__amd64__)
19 #define _PR_SI_ARCHITECTURE "amd64"
20 #elif defined(__m68k__)
21 #define _PR_SI_ARCHITECTURE "m68k"
22 #elif defined(__powerpc__)
23 #define _PR_SI_ARCHITECTURE "powerpc"
24 #elif defined(__sparc_v9__)
25 #define _PR_SI_ARCHITECTURE "sparc64"
26 #elif defined(__sparc__)
27 #define _PR_SI_ARCHITECTURE "sparc"
28 #elif defined(__mips__)
29 #define _PR_SI_ARCHITECTURE "mips"
30 #elif defined(__arm32__) || defined(__arm__) || defined(__armel__) \
31 || defined(__armeb__)
32 #define _PR_SI_ARCHITECTURE "arm"
33 #endif
35 #if defined(__ELF__)
36 #define PR_DLL_SUFFIX ".so"
37 #else
38 #define PR_DLL_SUFFIX ".so.1.0"
39 #endif
41 #define _PR_VMBASE 0x30000000
42 #define _PR_STACK_VMBASE 0x50000000
43 #define _MD_DEFAULT_STACK_SIZE 65536L
44 #define _MD_MMAP_FLAGS MAP_PRIVATE
46 #undef HAVE_STACK_GROWING_UP
47 #define HAVE_DLL
48 #define USE_DLFCN
49 #define _PR_HAVE_SOCKADDR_LEN
50 #define _PR_NO_LARGE_FILES
51 #define _PR_STAT_HAS_ST_ATIMESPEC
52 #define _PR_POLL_AVAILABLE
53 #define _PR_USE_POLL
54 #define _PR_HAVE_SYSV_SEMAPHORES
55 #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
57 #if __NetBSD_Version__ >= 105000000
58 #define _PR_INET6
59 #define _PR_HAVE_INET_NTOP
60 #define _PR_HAVE_GETHOSTBYNAME2
61 #define _PR_HAVE_GETADDRINFO
62 #define _PR_INET6_PROBE
63 #endif
65 #define USE_SETJMP
67 #ifndef _PR_PTHREADS
68 #include <setjmp.h>
70 #define PR_CONTEXT_TYPE sigjmp_buf
72 #define CONTEXT(_th) ((_th)->md.context)
74 #if defined(__i386__) || defined(__sparc__) || defined(__m68k__) || defined(__powerpc__)
75 #define JB_SP_INDEX 2
76 #elif defined(__mips__)
77 #define JB_SP_INDEX 4
78 #elif defined(__alpha__)
79 #define JB_SP_INDEX 34
80 #elif defined(__arm32__)
81 /*
82 * On the arm32, the jmpbuf regs underwent a name change after NetBSD 1.3.
83 */
84 #ifdef JMPBUF_REG_R13
85 #define JB_SP_INDEX JMPBUF_REG_R13
86 #else
87 #define JB_SP_INDEX _JB_REG_R13
88 #endif
89 #else
90 #error "Need to define SP index in jmp_buf here"
91 #endif
92 #define _MD_GET_SP(_th) (_th)->md.context[JB_SP_INDEX]
94 #define PR_NUM_GCREGS _JBLEN
96 /*
97 ** Initialize a thread context to run "_main()" when started
98 */
99 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
100 { \
101 *status = PR_TRUE; \
102 if (sigsetjmp(CONTEXT(_thread), 1)) { \
103 _main(); \
104 } \
105 _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
106 }
108 #define _MD_SWITCH_CONTEXT(_thread) \
109 if (!sigsetjmp(CONTEXT(_thread), 1)) { \
110 (_thread)->md.errcode = errno; \
111 _PR_Schedule(); \
112 }
114 /*
115 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
116 */
117 #define _MD_RESTORE_CONTEXT(_thread) \
118 { \
119 errno = (_thread)->md.errcode; \
120 _MD_SET_CURRENT_THREAD(_thread); \
121 siglongjmp(CONTEXT(_thread), 1); \
122 }
124 /* Machine-dependent (MD) data structures */
126 struct _MDThread {
127 PR_CONTEXT_TYPE context;
128 int id;
129 int errcode;
130 };
132 struct _MDThreadStack {
133 PRInt8 notused;
134 };
136 struct _MDLock {
137 PRInt8 notused;
138 };
140 struct _MDSemaphore {
141 PRInt8 notused;
142 };
144 struct _MDCVar {
145 PRInt8 notused;
146 };
148 struct _MDSegment {
149 PRInt8 notused;
150 };
152 /*
153 * md-specific cpu structure field
154 */
155 #define _PR_MD_MAX_OSFD FD_SETSIZE
157 struct _MDCPU_Unix {
158 PRCList ioQ;
159 PRUint32 ioq_timeout;
160 PRInt32 ioq_max_osfd;
161 PRInt32 ioq_osfd_cnt;
162 #ifndef _PR_USE_POLL
163 fd_set fd_read_set, fd_write_set, fd_exception_set;
164 PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
165 fd_exception_cnt[_PR_MD_MAX_OSFD];
166 #else
167 struct pollfd *ioq_pollfds;
168 int ioq_pollfds_size;
169 #endif /* _PR_USE_POLL */
170 };
172 #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
173 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
174 #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
175 #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
176 #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
177 #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
178 #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
179 #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
180 #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
181 #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
182 #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
183 #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
184 #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
186 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
188 struct _MDCPU {
189 struct _MDCPU_Unix md_unix;
190 };
192 #define _MD_INIT_LOCKS()
193 #define _MD_NEW_LOCK(lock) PR_SUCCESS
194 #define _MD_FREE_LOCK(lock)
195 #define _MD_LOCK(lock)
196 #define _MD_UNLOCK(lock)
197 #define _MD_INIT_IO()
198 #define _MD_IOQ_LOCK()
199 #define _MD_IOQ_UNLOCK()
201 #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
202 #define _MD_INIT_THREAD _MD_InitializeThread
203 #define _MD_EXIT_THREAD(thread)
204 #define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread
205 #define _MD_RESUME_THREAD(thread) _MD_resume_thread
206 #define _MD_CLEAN_THREAD(_thread)
208 #endif /* ! _PR_PTHREADS */
210 extern void _MD_EarlyInit(void);
212 #define _MD_EARLY_INIT _MD_EarlyInit
213 #define _MD_FINAL_INIT _PR_UnixInit
214 #define _MD_INTERVAL_USE_GTOD
216 /*
217 * We wrapped the select() call. _MD_SELECT refers to the built-in,
218 * unwrapped version.
219 */
220 #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
221 #if defined(_PR_POLL_AVAILABLE)
222 #include <poll.h>
223 #define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
224 #endif
226 #if NetBSD1_3 == 1L
227 typedef unsigned int nfds_t;
228 #endif
230 #endif /* nspr_netbsd_defs_h___ */