VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/include/md/_freebsd.h@ 65823

Last change on this file since 65823 was 4885, checked in by vboxsync, 17 years ago

Freebsd patches.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#ifndef nspr_freebsd_defs_h___
39#define nspr_freebsd_defs_h___
40
41#include "prthread.h"
42
43#if __FreeBSD__ >= 2
44#include <osreldate.h> /* for __FreeBSD_version */
45#endif
46#include <sys/syscall.h>
47
48#define PR_LINKER_ARCH "freebsd"
49#define _PR_SI_SYSNAME "FREEBSD"
50#if defined(__i386__)
51#define _PR_SI_ARCHITECTURE "x86"
52#elif defined(__alpha__)
53#define _PR_SI_ARCHITECTURE "alpha"
54#elif defined(__sparc__)
55#define _PR_SI_ARCHITECTURE "sparc"
56#elif defined(__ia64__)
57#define _PR_SI_ARCHITECTURE "ia64"
58#elif defined(__amd64__)
59#define _PR_SI_ARCHITECTURE "amd64"
60#else
61#error "Unknown CPU architecture"
62#endif
63#if defined(__ELF__)
64#define PR_DLL_SUFFIX ".so"
65#else
66#define PR_DLL_SUFFIX ".so.1.0"
67#endif
68
69#define _PR_VMBASE 0x30000000
70#define _PR_STACK_VMBASE 0x50000000
71#define _MD_DEFAULT_STACK_SIZE 65536L
72#define _MD_MMAP_FLAGS MAP_PRIVATE
73
74#undef HAVE_STACK_GROWING_UP
75#define HAVE_DLL
76#define USE_DLFCN
77#define _PR_HAVE_SOCKADDR_LEN
78#define _PR_STAT_HAS_ST_ATIMESPEC
79#define _PR_NO_LARGE_FILES
80
81#if defined(_PR_PTHREADS)
82#if __FreeBSD_version >= 400008
83/*
84 * libc_r before this version of FreeBSD doesn't have poll().
85 * Although libc has poll(), it is not thread-safe so we can't
86 * use it in the pthreads version.
87 */
88#define _PR_POLL_AVAILABLE
89#endif
90#else
91#if __FreeBSD_version >= 300000
92#define _PR_POLL_AVAILABLE
93#define _PR_USE_POLL
94#endif
95#endif
96
97#define _PR_HAVE_SYSV_SEMAPHORES
98#define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
99
100#if __FreeBSD_version >= 400014
101#define _PR_INET6
102#define _PR_HAVE_INET_NTOP
103#define _PR_HAVE_GETHOSTBYNAME2
104#define _PR_HAVE_GETADDRINFO
105#define _PR_INET6_PROBE
106#define _PR_IPV6_V6ONLY_PROBE
107#endif
108
109/* VBOX - START (expect somthing similar to arrive in the mozilla tree) */
110#if (__FreeBSD_version >= 700016) || (__FreeBSD_version < 700000 && __FreeBSD_version >= 601103)
111#if defined(_PR_PTHREADS)
112#define _PR_HAVE_GETPROTO_R
113#define _PR_HAVE_5_ARG_GETPROTO_R
114#define _PR_HAVE_GETHOST_R
115#define _PR_HAVE_GETHOST_R_INT
116#define _PR_HAVE_THREADSAFE_GETHOST
117#endif
118#endif
119/* VBOX - END */
120
121#define USE_SETJMP
122
123#ifndef _PR_PTHREADS
124#include <setjmp.h>
125
126#define PR_CONTEXT_TYPE sigjmp_buf
127
128#define CONTEXT(_th) ((_th)->md.context)
129
130#define _MD_GET_SP(_th) (_th)->md.context[0]._sjb[2]
131#define PR_NUM_GCREGS _JBLEN
132
133/*
134** Initialize a thread context to run "_main()" when started
135*/
136#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
137{ \
138 *status = PR_TRUE; \
139 if (sigsetjmp(CONTEXT(_thread), 1)) { \
140 _main(); \
141 } \
142 _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
143}
144
145#define _MD_SWITCH_CONTEXT(_thread) \
146 if (!sigsetjmp(CONTEXT(_thread), 1)) { \
147 (_thread)->md.errcode = errno; \
148 _PR_Schedule(); \
149 }
150
151/*
152** Restore a thread context, saved by _MD_SWITCH_CONTEXT
153*/
154#define _MD_RESTORE_CONTEXT(_thread) \
155{ \
156 errno = (_thread)->md.errcode; \
157 _MD_SET_CURRENT_THREAD(_thread); \
158 siglongjmp(CONTEXT(_thread), 1); \
159}
160
161/* Machine-dependent (MD) data structures */
162
163struct _MDThread {
164 PR_CONTEXT_TYPE context;
165 int id;
166 int errcode;
167};
168
169struct _MDThreadStack {
170 PRInt8 notused;
171};
172
173struct _MDLock {
174 PRInt8 notused;
175};
176
177struct _MDSemaphore {
178 PRInt8 notused;
179};
180
181struct _MDCVar {
182 PRInt8 notused;
183};
184
185struct _MDSegment {
186 PRInt8 notused;
187};
188
189/*
190 * md-specific cpu structure field
191 */
192#define _PR_MD_MAX_OSFD FD_SETSIZE
193
194struct _MDCPU_Unix {
195 PRCList ioQ;
196 PRUint32 ioq_timeout;
197 PRInt32 ioq_max_osfd;
198 PRInt32 ioq_osfd_cnt;
199#ifndef _PR_USE_POLL
200 fd_set fd_read_set, fd_write_set, fd_exception_set;
201 PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
202 fd_exception_cnt[_PR_MD_MAX_OSFD];
203#else
204 struct pollfd *ioq_pollfds;
205 int ioq_pollfds_size;
206#endif /* _PR_USE_POLL */
207};
208
209#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
210#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
211#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
212#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
213#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
214#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
215#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
216#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
217#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
218#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
219#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
220#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
221#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
222
223#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
224
225struct _MDCPU {
226 struct _MDCPU_Unix md_unix;
227};
228
229#define _MD_INIT_LOCKS()
230#define _MD_NEW_LOCK(lock) PR_SUCCESS
231#define _MD_FREE_LOCK(lock)
232#define _MD_LOCK(lock)
233#define _MD_UNLOCK(lock)
234#define _MD_INIT_IO()
235#define _MD_IOQ_LOCK()
236#define _MD_IOQ_UNLOCK()
237
238extern PRStatus _MD_InitializeThread(PRThread *thread);
239
240#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
241#define _MD_INIT_THREAD _MD_InitializeThread
242#define _MD_EXIT_THREAD(thread)
243#define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread
244#define _MD_RESUME_THREAD(thread) _MD_resume_thread
245#define _MD_CLEAN_THREAD(_thread)
246
247extern PRStatus _MD_CREATE_THREAD(
248 PRThread *thread,
249 void (*start) (void *),
250 PRThreadPriority priority,
251 PRThreadScope scope,
252 PRThreadState state,
253 PRUint32 stackSize);
254extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
255extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
256extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
257extern void _MD_YIELD(void);
258
259#endif /* ! _PR_PTHREADS */
260
261extern void _MD_EarlyInit(void);
262extern PRIntervalTime _PR_UNIX_GetInterval(void);
263extern PRIntervalTime _PR_UNIX_TicksPerSecond(void);
264
265#define _MD_EARLY_INIT _MD_EarlyInit
266#define _MD_FINAL_INIT _PR_UnixInit
267#define _MD_GET_INTERVAL _PR_UNIX_GetInterval
268#define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond
269
270/*
271 * We wrapped the select() call. _MD_SELECT refers to the built-in,
272 * unwrapped version.
273 */
274#define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
275
276#if defined(_PR_POLL_AVAILABLE)
277#include <poll.h>
278#define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
279#endif
280
281/* freebsd has INADDR_LOOPBACK defined, but in /usr/include/rpc/types.h, and I didn't
282 want to be including that.. */
283#ifndef INADDR_LOOPBACK
284#define INADDR_LOOPBACK (u_long)0x7F000001
285#endif
286
287/* For writev() */
288#include <sys/uio.h>
289
290#endif /* nspr_freebsd_defs_h___ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette