VirtualBox

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

Last change on this file since 3149 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 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#else
57#error "Unknown CPU architecture"
58#endif
59#if defined(__ELF__)
60#define PR_DLL_SUFFIX ".so"
61#else
62#define PR_DLL_SUFFIX ".so.1.0"
63#endif
64
65#define _PR_VMBASE 0x30000000
66#define _PR_STACK_VMBASE 0x50000000
67#define _MD_DEFAULT_STACK_SIZE 65536L
68#define _MD_MMAP_FLAGS MAP_PRIVATE
69
70#undef HAVE_STACK_GROWING_UP
71#define HAVE_DLL
72#define USE_DLFCN
73#define _PR_HAVE_SOCKADDR_LEN
74#define _PR_STAT_HAS_ST_ATIMESPEC
75#define _PR_NO_LARGE_FILES
76
77#if defined(_PR_PTHREADS)
78#if __FreeBSD_version >= 400008
79/*
80 * libc_r before this version of FreeBSD doesn't have poll().
81 * Although libc has poll(), it is not thread-safe so we can't
82 * use it in the pthreads version.
83 */
84#define _PR_POLL_AVAILABLE
85#endif
86#else
87#if __FreeBSD_version >= 300000
88#define _PR_POLL_AVAILABLE
89#define _PR_USE_POLL
90#endif
91#endif
92
93#define _PR_HAVE_SYSV_SEMAPHORES
94#define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
95
96#if __FreeBSD_version >= 400014
97#define _PR_INET6
98#define _PR_HAVE_INET_NTOP
99#define _PR_HAVE_GETHOSTBYNAME2
100#define _PR_HAVE_GETADDRINFO
101#define _PR_INET6_PROBE
102#endif
103
104#define USE_SETJMP
105
106#ifndef _PR_PTHREADS
107#include <setjmp.h>
108
109#define PR_CONTEXT_TYPE sigjmp_buf
110
111#define CONTEXT(_th) ((_th)->md.context)
112
113#define _MD_GET_SP(_th) (_th)->md.context[0]._sjb[2]
114#define PR_NUM_GCREGS _JBLEN
115
116/*
117** Initialize a thread context to run "_main()" when started
118*/
119#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
120{ \
121 *status = PR_TRUE; \
122 if (sigsetjmp(CONTEXT(_thread), 1)) { \
123 _main(); \
124 } \
125 _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
126}
127
128#define _MD_SWITCH_CONTEXT(_thread) \
129 if (!sigsetjmp(CONTEXT(_thread), 1)) { \
130 (_thread)->md.errcode = errno; \
131 _PR_Schedule(); \
132 }
133
134/*
135** Restore a thread context, saved by _MD_SWITCH_CONTEXT
136*/
137#define _MD_RESTORE_CONTEXT(_thread) \
138{ \
139 errno = (_thread)->md.errcode; \
140 _MD_SET_CURRENT_THREAD(_thread); \
141 siglongjmp(CONTEXT(_thread), 1); \
142}
143
144/* Machine-dependent (MD) data structures */
145
146struct _MDThread {
147 PR_CONTEXT_TYPE context;
148 int id;
149 int errcode;
150};
151
152struct _MDThreadStack {
153 PRInt8 notused;
154};
155
156struct _MDLock {
157 PRInt8 notused;
158};
159
160struct _MDSemaphore {
161 PRInt8 notused;
162};
163
164struct _MDCVar {
165 PRInt8 notused;
166};
167
168struct _MDSegment {
169 PRInt8 notused;
170};
171
172/*
173 * md-specific cpu structure field
174 */
175#define _PR_MD_MAX_OSFD FD_SETSIZE
176
177struct _MDCPU_Unix {
178 PRCList ioQ;
179 PRUint32 ioq_timeout;
180 PRInt32 ioq_max_osfd;
181 PRInt32 ioq_osfd_cnt;
182#ifndef _PR_USE_POLL
183 fd_set fd_read_set, fd_write_set, fd_exception_set;
184 PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
185 fd_exception_cnt[_PR_MD_MAX_OSFD];
186#else
187 struct pollfd *ioq_pollfds;
188 int ioq_pollfds_size;
189#endif /* _PR_USE_POLL */
190};
191
192#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
193#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
194#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
195#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
196#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
197#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
198#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
199#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
200#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
201#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
202#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
203#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
204#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
205
206#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
207
208struct _MDCPU {
209 struct _MDCPU_Unix md_unix;
210};
211
212#define _MD_INIT_LOCKS()
213#define _MD_NEW_LOCK(lock) PR_SUCCESS
214#define _MD_FREE_LOCK(lock)
215#define _MD_LOCK(lock)
216#define _MD_UNLOCK(lock)
217#define _MD_INIT_IO()
218#define _MD_IOQ_LOCK()
219#define _MD_IOQ_UNLOCK()
220
221extern PRStatus _MD_InitializeThread(PRThread *thread);
222
223#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
224#define _MD_INIT_THREAD _MD_InitializeThread
225#define _MD_EXIT_THREAD(thread)
226#define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread
227#define _MD_RESUME_THREAD(thread) _MD_resume_thread
228#define _MD_CLEAN_THREAD(_thread)
229
230extern PRStatus _MD_CREATE_THREAD(
231 PRThread *thread,
232 void (*start) (void *),
233 PRThreadPriority priority,
234 PRThreadScope scope,
235 PRThreadState state,
236 PRUint32 stackSize);
237extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
238extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
239extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
240extern void _MD_YIELD(void);
241
242#endif /* ! _PR_PTHREADS */
243
244extern void _MD_EarlyInit(void);
245extern PRIntervalTime _PR_UNIX_GetInterval(void);
246extern PRIntervalTime _PR_UNIX_TicksPerSecond(void);
247
248#define _MD_EARLY_INIT _MD_EarlyInit
249#define _MD_FINAL_INIT _PR_UnixInit
250#define _MD_GET_INTERVAL _PR_UNIX_GetInterval
251#define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond
252
253/*
254 * We wrapped the select() call. _MD_SELECT refers to the built-in,
255 * unwrapped version.
256 */
257#define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
258
259#if defined(_PR_POLL_AVAILABLE)
260#include <poll.h>
261#define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
262#endif
263
264/* freebsd has INADDR_LOOPBACK defined, but in /usr/include/rpc/types.h, and I didn't
265 want to be including that.. */
266#ifndef INADDR_LOOPBACK
267#define INADDR_LOOPBACK (u_long)0x7F000001
268#endif
269
270/* For writev() */
271#include <sys/uio.h>
272
273#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