1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 * The contents of this file are subject to the Mozilla Public
4 * License Version 1.1 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of
6 * the License at http://www.mozilla.org/MPL/
8 * Software distributed under the License is distributed on an "AS
9 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10 * implied. See the License for the specific language governing
11 * rights and limitations under the License.
13 * The Original Code is the Netscape Portable Runtime (NSPR).
15 * The Initial Developer of the Original Code is Netscape
16 * Communications Corporation. Portions created by Netscape are
17 * Copyright (C) 1998-2000 Netscape Communications Corporation. All
22 * Alternatively, the contents of this file may be used under the
23 * terms of the GNU General Public License Version 2 or later (the
24 * "GPL"), in which case the provisions of the GPL are applicable
25 * instead of those above. If you wish to allow use of your
26 * version of this file only under the terms of the GPL and not to
27 * allow others to use your version of this file under the MPL,
28 * indicate your decision by deleting the provisions above and
29 * replace them with the notice and other provisions required by
30 * the GPL. If you do not delete the provisions above, a recipient
31 * may use your version of this file under either the MPL or the
35 #ifndef nspr_linux_defs_h___
36 #define nspr_linux_defs_h___
41 * Internal configuration macros
44 #define PR_LINKER_ARCH "linux"
45 #define _PR_SI_SYSNAME "LINUX"
47 #define _PR_SI_ARCHITECTURE "ppc"
48 #elif defined(__alpha)
49 #define _PR_SI_ARCHITECTURE "alpha"
50 #elif defined(__ia64__)
51 #define _PR_SI_ARCHITECTURE "ia64"
52 #elif defined(__x86_64__)
53 #define _PR_SI_ARCHITECTURE "x86-64"
54 #elif defined(__mc68000__)
55 #define _PR_SI_ARCHITECTURE "m68k"
56 #elif defined(__sparc__)
57 #define _PR_SI_ARCHITECTURE "sparc"
58 #elif defined(__i386__)
59 #define _PR_SI_ARCHITECTURE "x86"
60 #elif defined(__mips__)
61 #define _PR_SI_ARCHITECTURE "mips"
62 #elif defined(__arm__)
63 #define _PR_SI_ARCHITECTURE "arm"
64 #elif defined(__hppa__)
65 #define _PR_SI_ARCHITECTURE "hppa"
66 #elif defined(__s390__)
67 #define _PR_SI_ARCHITECTURE "s390"
68 #elif defined(__s390x__)
69 #define _PR_SI_ARCHITECTURE "s390x"
71 #error "Unknown CPU architecture"
73 #define PR_DLL_SUFFIX ".so"
75 #define _PR_VMBASE 0x30000000
76 #define _PR_STACK_VMBASE 0x50000000
77 #define _MD_DEFAULT_STACK_SIZE 65536L
78 #define _MD_MMAP_FLAGS MAP_PRIVATE
80 #undef HAVE_STACK_GROWING_UP
83 * Elf linux supports dl* functions
89 #define _PR_HAVE_ATOMIC_OPS
90 #define _MD_INIT_ATOMIC()
91 extern PRInt32
_PR_x86_AtomicIncrement(PRInt32
*val
);
92 #define _MD_ATOMIC_INCREMENT _PR_x86_AtomicIncrement
93 extern PRInt32
_PR_x86_AtomicDecrement(PRInt32
*val
);
94 #define _MD_ATOMIC_DECREMENT _PR_x86_AtomicDecrement
95 extern PRInt32
_PR_x86_AtomicAdd(PRInt32
*ptr
, PRInt32 val
);
96 #define _MD_ATOMIC_ADD _PR_x86_AtomicAdd
97 extern PRInt32
_PR_x86_AtomicSet(PRInt32
*val
, PRInt32 newval
);
98 #define _MD_ATOMIC_SET _PR_x86_AtomicSet
101 #if defined(__ia64__)
102 #define _PR_HAVE_ATOMIC_OPS
103 #define _MD_INIT_ATOMIC()
104 extern PRInt32
_PR_ia64_AtomicIncrement(PRInt32
*val
);
105 #define _MD_ATOMIC_INCREMENT _PR_ia64_AtomicIncrement
106 extern PRInt32
_PR_ia64_AtomicDecrement(PRInt32
*val
);
107 #define _MD_ATOMIC_DECREMENT _PR_ia64_AtomicDecrement
108 extern PRInt32
_PR_ia64_AtomicAdd(PRInt32
*ptr
, PRInt32 val
);
109 #define _MD_ATOMIC_ADD _PR_ia64_AtomicAdd
110 extern PRInt32
_PR_ia64_AtomicSet(PRInt32
*val
, PRInt32 newval
);
111 #define _MD_ATOMIC_SET _PR_ia64_AtomicSet
114 #if defined(__x86_64__)
115 #define _PR_HAVE_ATOMIC_OPS
116 #define _MD_INIT_ATOMIC()
117 extern PRInt32
_PR_x86_64_AtomicIncrement(PRInt32
*val
);
118 #define _MD_ATOMIC_INCREMENT _PR_x86_64_AtomicIncrement
119 extern PRInt32
_PR_x86_64_AtomicDecrement(PRInt32
*val
);
120 #define _MD_ATOMIC_DECREMENT _PR_x86_64_AtomicDecrement
121 extern PRInt32
_PR_x86_64_AtomicAdd(PRInt32
*ptr
, PRInt32 val
);
122 #define _MD_ATOMIC_ADD _PR_x86_64_AtomicAdd
123 extern PRInt32
_PR_x86_64_AtomicSet(PRInt32
*val
, PRInt32 newval
);
124 #define _MD_ATOMIC_SET _PR_x86_64_AtomicSet
128 #if defined(__GLIBC__) && __GLIBC__ >= 2
129 #define _PR_POLL_AVAILABLE
132 #define _PR_STAT_HAS_ONLY_ST_ATIME
133 #if defined(__alpha) || defined(__ia64__)
134 #define _PR_HAVE_LARGE_OFF_T
135 #elif (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
136 #define _PR_HAVE_OFF64_T
138 #define _PR_NO_LARGE_FILES
140 #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
142 #define _PR_HAVE_INET_NTOP
143 #define _PR_HAVE_GETHOSTBYNAME2
144 #define _PR_HAVE_GETADDRINFO
145 #define _PR_INET6_PROBE
147 #define _PR_HAVE_SYSV_SEMAPHORES
148 #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
149 #if (__GLIBC__ >= 2) && defined(_PR_PTHREADS)
150 #define _PR_HAVE_GETHOST_R
151 #define _PR_HAVE_GETHOST_R_INT
156 extern void _MD_CleanupBeforeExit(void);
157 #define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit
159 #else /* ! _PR_PTHREADS */
163 #define PR_CONTEXT_TYPE sigjmp_buf
165 #define CONTEXT(_th) ((_th)->md.context)
169 * PowerPC based MkLinux
171 * On the PowerPC, the new style jmp_buf isn't used until glibc
174 #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
175 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_GPR1]
177 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__misc[0]
178 #endif /* glibc 2.1 or later */
179 #define _MD_SET_FP(_t, val)
180 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
181 #define _MD_GET_FP_PTR(_t) ((void *) 0)
182 /* aix = 64, macos = 70 */
183 #define PR_NUM_GCREGS 64
185 #elif defined(__alpha)
186 /* Alpha based Linux */
188 #if defined(__GLIBC__) && __GLIBC__ >= 2
189 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
190 #define _MD_SET_FP(_t, val)
191 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
192 #define _MD_GET_FP_PTR(_t) ((void *) 0)
193 #define _MD_SP_TYPE long int
195 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
196 #define _MD_SET_FP(_t, val)
197 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
198 #define _MD_GET_FP_PTR(_t) ((void *) 0)
199 #define _MD_SP_TYPE __ptr_t
200 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
202 /* XXX not sure if this is correct, or maybe it should be 17? */
203 #define PR_NUM_GCREGS 9
205 #elif defined(__ia64__)
207 #define _MD_GET_SP(_t) ((long *)((_t)->md.context[0].__jmpbuf)[0])
208 #define _MD_SET_FP(_t, val)
209 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
210 #define _MD_GET_FP_PTR(_t) ((void *) 0)
211 #define _MD_SP_TYPE long int
213 #define PR_NUM_GCREGS _JBLEN
215 #elif defined(__mc68000__)
216 /* m68k based Linux */
219 * On the m68k, glibc still uses the old style sigjmp_buf, even
222 #if defined(__GLIBC__) && __GLIBC__ >= 2
223 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
224 #define _MD_SET_FP(_t, val)
225 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
226 #define _MD_GET_FP_PTR(_t) ((void *) 0)
227 #define _MD_SP_TYPE int
229 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
230 #define _MD_SET_FP(_t, val)
231 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
232 #define _MD_GET_FP_PTR(_t) ((void *) 0)
233 #define _MD_SP_TYPE __ptr_t
234 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
236 /* XXX not sure if this is correct, or maybe it should be 17? */
237 #define PR_NUM_GCREGS 9
239 #elif defined(__sparc__)
241 #if defined(__GLIBC__) && __GLIBC__ >= 2
243 * You need glibc2-2.0.7-25 or later. The libraries that came with
244 * Red Hat 5.1 are not new enough, but they are in 5.2.
246 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
247 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[JB_FP] = val)
248 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
249 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[JB_FP])
250 #define _MD_SP_TYPE int
252 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__fp
253 #define _MD_SET_FP(_t, val)
254 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
255 #define _MD_GET_FP_PTR(_t) ((void *) 0)
256 #define _MD_SP_TYPE __ptr_t
257 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
259 #elif defined(__i386__)
260 /* Intel based Linux */
261 #if defined(__GLIBC__) && __GLIBC__ >= 2
262 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
263 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[JB_BP] = val)
264 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
265 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[JB_BP])
266 #define _MD_SP_TYPE int
268 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
269 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__bp = val)
270 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
271 #define _MD_GET_FP_PTR(_t) &((_t)->md.context[0].__jmpbuf[0].__bp)
272 #define _MD_SP_TYPE __ptr_t
273 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
274 #define PR_NUM_GCREGS 6
276 #elif defined(__mips__)
278 #if defined(__GLIBC__) && __GLIBC__ >= 2
279 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
280 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__fp = (val))
281 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
282 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[0].__fp)
283 #define _MD_SP_TYPE __ptr_t
285 #error "Linux/MIPS pre-glibc2 not supported yet"
286 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
288 #elif defined(__arm__)
290 #if defined(__GLIBC__) && __GLIBC__ >= 2
291 #define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[20]
292 #define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[19] = (val))
293 #define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
294 #define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[19])
295 #define _MD_SP_TYPE __ptr_t
297 #error "ARM/Linux pre-glibc2 not supported yet"
298 #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
302 #error "Unknown CPU architecture"
304 #endif /*__powerpc__*/
307 ** Initialize a thread context to run "_main()" when started
311 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
314 if (sigsetjmp(CONTEXT(_thread), 1)) { \
317 _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 128); \
318 _thread->md.sp = _MD_GET_SP_PTR(_thread); \
319 _thread->md.fp = _MD_GET_FP_PTR(_thread); \
320 _MD_SET_FP(_thread, 0); \
323 #elif defined(__mips__)
325 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
328 (void) sigsetjmp(CONTEXT(_thread), 1); \
329 _thread->md.context[0].__jmpbuf[0].__pc = (__ptr_t) _main; \
330 _MD_GET_SP(_thread) = (_MD_SP_TYPE) ((_sp) - 64); \
331 _thread->md.sp = _MD_GET_SP_PTR(_thread); \
332 _thread->md.fp = _MD_GET_FP_PTR(_thread); \
333 _MD_SET_FP(_thread, 0); \
338 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
341 if (sigsetjmp(CONTEXT(_thread), 1)) { \
344 _MD_GET_SP(_thread) = (_MD_SP_TYPE) ((_sp) - 64); \
345 _thread->md.sp = _MD_GET_SP_PTR(_thread); \
346 _thread->md.fp = _MD_GET_FP_PTR(_thread); \
347 _MD_SET_FP(_thread, 0); \
350 #endif /*__powerpc__*/
352 #define _MD_SWITCH_CONTEXT(_thread) \
353 if (!sigsetjmp(CONTEXT(_thread), 1)) { \
354 (_thread)->md.errcode = errno; \
359 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
361 #define _MD_RESTORE_CONTEXT(_thread) \
363 errno = (_thread)->md.errcode; \
364 _MD_SET_CURRENT_THREAD(_thread); \
365 siglongjmp(CONTEXT(_thread), 1); \
368 /* Machine-dependent (MD) data structures */
371 PR_CONTEXT_TYPE context
;
378 struct _MDThreadStack
{
386 struct _MDSemaphore
{
399 * md-specific cpu structure field
401 #include <sys/time.h> /* for FD_SETSIZE */
402 #define _PR_MD_MAX_OSFD FD_SETSIZE
406 PRUint32 ioq_timeout
;
407 PRInt32 ioq_max_osfd
;
408 PRInt32 ioq_osfd_cnt
;
410 fd_set fd_read_set
, fd_write_set
, fd_exception_set
;
411 PRInt16 fd_read_cnt
[_PR_MD_MAX_OSFD
],fd_write_cnt
[_PR_MD_MAX_OSFD
],
412 fd_exception_cnt
[_PR_MD_MAX_OSFD
];
414 struct pollfd
*ioq_pollfds
;
415 int ioq_pollfds_size
;
416 #endif /* _PR_USE_POLL */
419 #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
420 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
421 #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
422 #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
423 #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
424 #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
425 #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
426 #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
427 #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
428 #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
429 #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
430 #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
431 #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
433 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
436 struct _MDCPU_Unix md_unix
;
439 #define _MD_INIT_LOCKS()
440 #define _MD_NEW_LOCK(lock) PR_SUCCESS
441 #define _MD_FREE_LOCK(lock)
442 #define _MD_LOCK(lock)
443 #define _MD_UNLOCK(lock)
444 #define _MD_INIT_IO()
445 #define _MD_IOQ_LOCK()
446 #define _MD_IOQ_UNLOCK()
448 extern PRStatus
_MD_InitializeThread(PRThread
*thread
);
450 #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
451 #define _MD_INIT_THREAD _MD_InitializeThread
452 #define _MD_EXIT_THREAD(thread)
453 #define _MD_SUSPEND_THREAD(thread) _MD_suspend_thread
454 #define _MD_RESUME_THREAD(thread) _MD_resume_thread
455 #define _MD_CLEAN_THREAD(_thread)
457 extern PRStatus
_MD_CREATE_THREAD(
459 void (*start
) (void *),
460 PRThreadPriority priority
,
464 extern void _MD_SET_PRIORITY(struct _MDThread
*thread
, PRUintn newPri
);
465 extern PRStatus
_MD_WAIT(PRThread
*, PRIntervalTime timeout
);
466 extern PRStatus
_MD_WAKEUP_WAITER(PRThread
*);
467 extern void _MD_YIELD(void);
469 #endif /* ! _PR_PTHREADS */
471 extern void _MD_EarlyInit(void);
472 extern PRIntervalTime
_PR_UNIX_GetInterval(void);
473 extern PRIntervalTime
_PR_UNIX_TicksPerSecond(void);
475 #define _MD_EARLY_INIT _MD_EarlyInit
476 #define _MD_FINAL_INIT _PR_UnixInit
477 #define _MD_GET_INTERVAL _PR_UNIX_GetInterval
478 #define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond
481 * We wrapped the select() call. _MD_SELECT refers to the built-in,
484 #define _MD_SELECT __select
486 #ifdef _PR_POLL_AVAILABLE
487 #include <sys/poll.h>
488 extern int __syscall_poll(struct pollfd
*ufds
, unsigned long int nfds
,
490 #define _MD_POLL __syscall_poll
496 extern void _MD_linux_map_sendfile_error(int err
);
498 #endif /* nspr_linux_defs_h___ */