VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/include/md/_solaris.h@ 21017

Last change on this file since 21017 was 5300, checked in by vboxsync, 17 years ago

Appled https://bugzilla.mozilla.org/attachment.cgi?id=161204 from https://bugzilla.mozilla.org/show_bug.cgi?id=259001 (relevant parts only).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.5 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_solaris_defs_h___
39#define nspr_solaris_defs_h___
40
41/*
42 * Internal configuration macros
43 */
44
45#define PR_LINKER_ARCH "solaris"
46#define _PR_SI_SYSNAME "SOLARIS"
47#ifdef sparc
48#define _PR_SI_ARCHITECTURE "sparc"
49#elif defined(i386)
50#define _PR_SI_ARCHITECTURE "x86"
51#elif defined(__x86_64)
52#define _PR_SI_ARCHITECTURE "x86-64"
53#else
54#error unknown processor
55#endif
56#define PR_DLL_SUFFIX ".so"
57
58#define _PR_VMBASE 0x30000000
59#define _PR_STACK_VMBASE 0x50000000
60#define _MD_DEFAULT_STACK_SIZE (2*65536L)
61#define _MD_MMAP_FLAGS MAP_SHARED
62
63#undef HAVE_STACK_GROWING_UP
64
65#ifndef HAVE_WEAK_IO_SYMBOLS
66#define HAVE_WEAK_IO_SYMBOLS
67#endif
68
69#undef HAVE_WEAK_MALLOC_SYMBOLS
70#define HAVE_DLL
71#define USE_DLFCN
72#define NEED_STRFTIME_LOCK
73
74#if defined(_LARGEFILE64_SOURCE) /* vbox */
75#define _PR_HAVE_OFF64_T /* vbox */
76#elif defined(_LP64) || _FILE_OFFSET_BITS == 32 /* vbox */
77#define _PR_HAVE_LARGE_OFF_T /* vbox */
78#else /* vbox */
79#define _PR_NO_LARGE_FILES /* vbox */
80#endif /* vbox */
81
82
83/*
84 * Intel x86 has atomic instructions.
85 *
86 * Sparc v8 does not have instructions to efficiently implement
87 * atomic increment/decrement operations. In the local threads
88 * only and pthreads versions, we use the default atomic routine
89 * implementation in pratom.c. The obsolete global threads only
90 * version uses a global mutex_t to implement the atomic routines
91 * in solaris.c, which is actually equivalent to the default
92 * implementation.
93 *
94 * 64-bit Solaris requires sparc v9, which has atomic instructions.
95 */
96#if defined(i386) || defined(_PR_GLOBAL_THREADS_ONLY) || defined(IS_64)
97#define _PR_HAVE_ATOMIC_OPS
98#endif
99
100#if defined(_PR_GLOBAL_THREADS_ONLY) || defined(_PR_PTHREADS)
101/*
102 * We have assembly language implementation of atomic
103 * stacks for the 32-bit sparc and x86 architectures only.
104 *
105 * Note: We ran into thread starvation problem with the
106 * 32-bit sparc assembly language implementation of atomic
107 * stacks, so we do not use it now. (Bugzilla bug 113740)
108 */
109#if !defined(sparc) && !defined(__x86_64)
110#define _PR_HAVE_ATOMIC_CAS
111#endif
112#endif
113
114#define _PR_POLL_AVAILABLE
115#define _PR_USE_POLL
116#define _PR_STAT_HAS_ST_ATIM
117#ifdef SOLARIS2_5
118#define _PR_HAVE_SYSV_SEMAPHORES
119#define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
120#else
121#define _PR_HAVE_POSIX_SEMAPHORES
122#define PR_HAVE_POSIX_NAMED_SHARED_MEMORY
123#endif
124#define _PR_HAVE_GETIPNODEBYNAME
125#define _PR_HAVE_GETIPNODEBYADDR
126#define _PR_HAVE_GETADDRINFO
127#define _PR_INET6_PROBE
128#define _PR_ACCEPT_INHERIT_NONBLOCK
129#if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) /* vbox */
130#define _PR_INET6 /* vbox */
131#endif /* vbox */
132#ifdef _PR_INET6
133#define _PR_HAVE_INET_NTOP
134#else
135#define AF_INET6 26
136struct addrinfo {
137 int ai_flags;
138 int ai_family;
139 int ai_socktype;
140 int ai_protocol;
141 size_t ai_addrlen;
142 char *ai_canonname;
143 struct sockaddr *ai_addr;
144 struct addrinfo *ai_next;
145};
146#define AI_CANONNAME 0x0010
147#define AI_V4MAPPED 0x0001
148#define AI_ALL 0x0002
149#define AI_ADDRCONFIG 0x0004
150#define _PR_HAVE_MD_SOCKADDR_IN6
151/* isomorphic to struct in6_addr on Solaris 8 */
152struct _md_in6_addr {
153 union {
154 PRUint8 _S6_u8[16];
155 PRUint32 _S6_u32[4];
156 PRUint32 __S6_align;
157 } _S6_un;
158};
159/* isomorphic to struct sockaddr_in6 on Solaris 8 */
160struct _md_sockaddr_in6 {
161 PRUint16 sin6_family;
162 PRUint16 sin6_port;
163 PRUint32 sin6_flowinfo;
164 struct _md_in6_addr sin6_addr;
165 PRUint32 sin6_scope_id;
166 PRUint32 __sin6_src_id;
167};
168#endif
169#if defined(_PR_GLOBAL_THREADS_ONLY) || defined(_PR_PTHREADS)
170#define _PR_HAVE_GETHOST_R
171#define _PR_HAVE_GETHOST_R_POINTER
172#endif
173
174#include "prinrval.h"
175NSPR_API(PRIntervalTime) _MD_Solaris_GetInterval(void);
176#define _MD_GET_INTERVAL _MD_Solaris_GetInterval
177NSPR_API(PRIntervalTime) _MD_Solaris_TicksPerSecond(void);
178#define _MD_INTERVAL_PER_SEC _MD_Solaris_TicksPerSecond
179
180#if defined(_PR_HAVE_ATOMIC_OPS)
181/*
182** Atomic Operations
183*/
184#define _MD_INIT_ATOMIC()
185
186NSPR_API(PRInt32) _MD_AtomicIncrement(PRInt32 *val);
187#define _MD_ATOMIC_INCREMENT _MD_AtomicIncrement
188
189NSPR_API(PRInt32) _MD_AtomicAdd(PRInt32 *ptr, PRInt32 val);
190#define _MD_ATOMIC_ADD _MD_AtomicAdd
191
192NSPR_API(PRInt32) _MD_AtomicDecrement(PRInt32 *val);
193#define _MD_ATOMIC_DECREMENT _MD_AtomicDecrement
194
195NSPR_API(PRInt32) _MD_AtomicSet(PRInt32 *val, PRInt32 newval);
196#define _MD_ATOMIC_SET _MD_AtomicSet
197#endif /* _PR_HAVE_ATOMIC_OPS */
198
199#if defined(_PR_PTHREADS)
200
201NSPR_API(void) _MD_EarlyInit(void);
202
203#define _MD_EARLY_INIT _MD_EarlyInit
204#define _MD_FINAL_INIT _PR_UnixInit
205
206#elif defined(_PR_GLOBAL_THREADS_ONLY)
207
208#include "prthread.h"
209
210#include <ucontext.h>
211
212/*
213** Iinitialization Related definitions
214*/
215
216NSPR_API(void) _MD_EarlyInit(void);
217
218#define _MD_EARLY_INIT _MD_EarlyInit
219#define _MD_FINAL_INIT _PR_UnixInit
220
221#define _MD_GET_SP(threadp) threadp->md.sp
222
223/*
224** Clean-up the thread machine dependent data structure
225*/
226#define _MD_INIT_THREAD _MD_InitializeThread
227#define _MD_INIT_ATTACHED_THREAD _MD_InitializeThread
228
229NSPR_API(PRStatus) _MD_CreateThread(PRThread *thread,
230 void (*start)(void *),
231 PRThreadPriority priority,
232 PRThreadScope scope,
233 PRThreadState state,
234 PRUint32 stackSize);
235#define _MD_CREATE_THREAD _MD_CreateThread
236
237#define _PR_CONTEXT_TYPE ucontext_t
238
239#define CONTEXT(_thread) (&(_thread)->md.context)
240
241#include <thread.h>
242#include <sys/lwp.h>
243#include <synch.h>
244
245extern struct PRLock *_pr_schedLock;
246
247/*
248** Thread Local Storage
249*/
250
251#define THREAD_KEY_T thread_key_t
252
253extern struct PRThread *_pr_attached_thread_tls();
254extern struct PRThread *_pr_current_thread_tls();
255extern struct _PRCPU *_pr_current_cpu_tls();
256extern struct PRThread *_pr_last_thread_tls();
257
258extern THREAD_KEY_T threadid_key;
259extern THREAD_KEY_T cpuid_key;
260extern THREAD_KEY_T last_thread_key;
261
262#define _MD_GET_ATTACHED_THREAD() _pr_attached_thread_tls()
263#define _MD_CURRENT_THREAD() _pr_current_thread_tls()
264#define _MD_CURRENT_CPU() _pr_current_cpu_tls()
265#define _MD_LAST_THREAD() _pr_last_thread_tls()
266
267#define _MD_SET_CURRENT_THREAD(newval) \
268 PR_BEGIN_MACRO \
269 thr_setspecific(threadid_key, (void *)newval); \
270 PR_END_MACRO
271
272#define _MD_SET_CURRENT_CPU(newval) \
273 PR_BEGIN_MACRO \
274 thr_setspecific(cpuid_key, (void *)newval); \
275 PR_END_MACRO
276
277#define _MD_SET_LAST_THREAD(newval) \
278 PR_BEGIN_MACRO \
279 thr_setspecific(last_thread_key, (void *)newval); \
280 PR_END_MACRO
281
282#define _MD_CLEAN_THREAD(_thread) _MD_cleanup_thread(_thread)
283extern void _MD_exit_thread(PRThread *thread);
284#define _MD_EXIT_THREAD(thread) _MD_exit_thread(thread)
285
286#define _MD_SUSPEND_THREAD(thread) _MD_Suspend(thread)
287#define _MD_RESUME_THREAD(thread) thr_continue((thread)->md.handle)
288
289/* XXXX Needs to be defined - Prashant */
290#define _MD_SUSPEND_CPU(cpu)
291#define _MD_RESUME_CPU(cpu)
292
293extern void _MD_Begin_SuspendAll(void);
294extern void _MD_End_SuspendAll(void);
295extern void _MD_End_ResumeAll(void);
296#define _MD_BEGIN_SUSPEND_ALL() _MD_Begin_SuspendAll()
297#define _MD_BEGIN_RESUME_ALL()
298#define _MD_END_SUSPEND_ALL() _MD_End_SuspendAll()
299#define _MD_END_RESUME_ALL() _MD_End_ResumeAll()
300
301#define _MD_INIT_LOCKS()
302#define _MD_NEW_LOCK(md_lockp) (mutex_init(&((md_lockp)->lock),USYNC_THREAD,NULL) ? PR_FAILURE : PR_SUCCESS)
303#define _MD_FREE_LOCK(md_lockp) mutex_destroy(&((md_lockp)->lock))
304#define _MD_UNLOCK(md_lockp) mutex_unlock(&((md_lockp)->lock))
305#define _MD_TEST_AND_LOCK(md_lockp) mutex_trylock(&((md_lockp)->lock))
306struct _MDLock;
307NSPR_API(void) _MD_lock(struct _MDLock *md_lock);
308#undef PROFILE_LOCKS
309#ifndef PROFILE_LOCKS
310#define _MD_LOCK(md_lockp) _MD_lock(md_lockp)
311#else
312#define _MD_LOCK(md_lockp) \
313 PR_BEGIN_MACRO \
314 int rv = _MD_TEST_AND_LOCK(md_lockp); \
315 if (rv == 0) { \
316 (md_lockp)->hitcount++; \
317 } else { \
318 (md_lockp)->misscount++; \
319 _MD_lock(md_lockp); \
320 } \
321 PR_END_MACRO
322#endif
323
324#define _PR_LOCK_HEAP() if (_pr_heapLock) _MD_LOCK(&_pr_heapLock->md)
325#define _PR_UNLOCK_HEAP() if (_pr_heapLock) _MD_UNLOCK(&_pr_heapLock->md)
326
327#define _MD_ATTACH_THREAD(threadp)
328
329
330#define THR_KEYCREATE thr_keycreate
331#define THR_SELF thr_self
332#define _MD_NEW_CV(condp) cond_init(&((condp)->cv), USYNC_THREAD, 0)
333#define COND_WAIT(condp, mutexp) cond_wait(condp, mutexp)
334#define COND_TIMEDWAIT(condp, mutexp, tspec) \
335 cond_timedwait(condp, mutexp, tspec)
336#define _MD_NOTIFY_CV(condp, lockp) cond_signal(&((condp)->cv))
337#define _MD_NOTIFYALL_CV(condp,unused) cond_broadcast(&((condp)->cv))
338#define _MD_FREE_CV(condp) cond_destroy(&((condp)->cv))
339#define _MD_YIELD() thr_yield()
340#include <time.h>
341/*
342 * Because clock_gettime() on Solaris/x86 2.4 always generates a
343 * segmentation fault, we use an emulated version _pr_solx86_clock_gettime(),
344 * which is implemented using gettimeofday().
345 */
346#if defined(i386) && defined(SOLARIS2_4)
347extern int _pr_solx86_clock_gettime(clockid_t clock_id, struct timespec *tp);
348#define GETTIME(tt) _pr_solx86_clock_gettime(CLOCK_REALTIME, (tt))
349#else
350#define GETTIME(tt) clock_gettime(CLOCK_REALTIME, (tt))
351#endif /* i386 && SOLARIS2_4 */
352
353#define MUTEX_T mutex_t
354#define COND_T cond_t
355
356#define _MD_NEW_SEM(md_semp,_val) sema_init(&((md_semp)->sem),_val,USYNC_THREAD,NULL)
357#define _MD_DESTROY_SEM(md_semp) sema_destroy(&((md_semp)->sem))
358#define _MD_WAIT_SEM(md_semp) sema_wait(&((md_semp)->sem))
359#define _MD_POST_SEM(md_semp) sema_post(&((md_semp)->sem))
360
361#define _MD_SAVE_ERRNO(_thread)
362#define _MD_RESTORE_ERRNO(_thread)
363#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
364
365extern struct _MDLock _pr_ioq_lock;
366#define _MD_IOQ_LOCK() _MD_LOCK(&_pr_ioq_lock)
367#define _MD_IOQ_UNLOCK() _MD_UNLOCK(&_pr_ioq_lock)
368
369extern PRStatus _MD_wait(struct PRThread *, PRIntervalTime timeout);
370#define _MD_WAIT _MD_wait
371
372extern PRStatus _MD_WakeupWaiter(struct PRThread *);
373#define _MD_WAKEUP_WAITER _MD_WakeupWaiter
374
375NSPR_API(void) _MD_InitIO(void);
376#define _MD_INIT_IO _MD_InitIO
377
378#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
379 PR_BEGIN_MACRO \
380 *status = PR_TRUE; \
381 PR_END_MACRO
382#define _MD_SWITCH_CONTEXT(_thread)
383#define _MD_RESTORE_CONTEXT(_newThread)
384
385struct _MDLock {
386 MUTEX_T lock;
387#ifdef PROFILE_LOCKS
388 PRInt32 hitcount;
389 PRInt32 misscount;
390#endif
391};
392
393struct _MDCVar {
394 COND_T cv;
395};
396
397struct _MDSemaphore {
398 sema_t sem;
399};
400
401struct _MDThread {
402 _PR_CONTEXT_TYPE context;
403 thread_t handle;
404 lwpid_t lwpid;
405 uint_t sp; /* stack pointer */
406 uint_t threadID; /* ptr to solaris-internal thread id structures */
407 struct _MDSemaphore waiter_sem;
408};
409
410struct _MDThreadStack {
411 PRInt8 notused;
412};
413
414struct _MDSegment {
415 PRInt8 notused;
416};
417
418/*
419 * md-specific cpu structure field, common to all Unix platforms
420 */
421#define _PR_MD_MAX_OSFD FD_SETSIZE
422
423struct _MDCPU_Unix {
424 PRCList ioQ;
425 PRUint32 ioq_timeout;
426 PRInt32 ioq_max_osfd;
427 PRInt32 ioq_osfd_cnt;
428#ifndef _PR_USE_POLL
429 fd_set fd_read_set, fd_write_set, fd_exception_set;
430 PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
431 fd_exception_cnt[_PR_MD_MAX_OSFD];
432#else
433 struct pollfd *ioq_pollfds;
434 int ioq_pollfds_size;
435#endif /* _PR_USE_POLL */
436};
437
438#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
439#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
440#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
441#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
442#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
443#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
444#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
445#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
446#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
447#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
448#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
449#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
450#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
451
452#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
453
454
455struct _MDCPU {
456 struct _MDCPU_Unix md_unix;
457};
458
459/* The following defines the unwrapped versions of select() and poll(). */
460extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
461 fd_set *exceptfds, struct timeval *timeout);
462#define _MD_SELECT _select
463
464#include <poll.h>
465#define _MD_POLL _poll
466extern int _poll(struct pollfd *fds, unsigned long nfds, int timeout);
467
468PR_BEGIN_EXTERN_C
469
470/*
471** Missing function prototypes
472*/
473extern int gethostname (char *name, int namelen);
474
475PR_END_EXTERN_C
476
477#else /* _PR_GLOBAL_THREADS_ONLY */
478
479/*
480 * LOCAL_THREADS_ONLY implementation on Solaris
481 */
482
483#include "prthread.h"
484
485#include <errno.h>
486#include <ucontext.h>
487#include <sys/stack.h>
488#include <synch.h>
489
490/*
491** Iinitialization Related definitions
492*/
493
494NSPR_API(void) _MD_EarlyInit(void);
495NSPR_API(void) _MD_SolarisInit();
496#define _MD_EARLY_INIT _MD_EarlyInit
497#define _MD_FINAL_INIT _MD_SolarisInit
498#define _MD_INIT_THREAD _MD_InitializeThread
499
500#ifdef USE_SETJMP
501
502#include <setjmp.h>
503
504#define _PR_CONTEXT_TYPE jmp_buf
505
506#ifdef sparc
507#define _MD_GET_SP(_t) (_t)->md.context[2]
508#else
509#define _MD_GET_SP(_t) (_t)->md.context[4]
510#endif
511
512#define PR_NUM_GCREGS _JBLEN
513#define CONTEXT(_thread) (_thread)->md.context
514
515#else /* ! USE_SETJMP */
516
517#ifdef sparc
518#define _PR_CONTEXT_TYPE ucontext_t
519#define _MD_GET_SP(_t) (_t)->md.context.uc_mcontext.gregs[REG_SP]
520/*
521** Sparc's use register windows. the _MD_GetRegisters for the sparc's
522** doesn't actually store anything into the argument buffer; instead the
523** register windows are homed to the stack. I assume that the stack
524** always has room for the registers to spill to...
525*/
526#define PR_NUM_GCREGS 0
527#else
528#define _PR_CONTEXT_TYPE unsigned int edi; sigset_t oldMask, blockMask; ucontext_t
529#define _MD_GET_SP(_t) (_t)->md.context.uc_mcontext.gregs[USP]
530#define PR_NUM_GCREGS _JBLEN
531#endif
532
533#define CONTEXT(_thread) (&(_thread)->md.context)
534
535#endif /* ! USE_SETJMP */
536
537#include <time.h>
538/*
539 * Because clock_gettime() on Solaris/x86 always generates a
540 * segmentation fault, we use an emulated version _pr_solx86_clock_gettime(),
541 * which is implemented using gettimeofday().
542 */
543#ifdef i386
544#define GETTIME(tt) _pr_solx86_clock_gettime(CLOCK_REALTIME, (tt))
545#else
546#define GETTIME(tt) clock_gettime(CLOCK_REALTIME, (tt))
547#endif /* i386 */
548
549#define _MD_SAVE_ERRNO(_thread) (_thread)->md.errcode = errno;
550#define _MD_RESTORE_ERRNO(_thread) errno = (_thread)->md.errcode;
551
552#ifdef sparc
553
554#ifdef USE_SETJMP
555#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
556 PR_BEGIN_MACRO \
557 int *context = (_thread)->md.context; \
558 *status = PR_TRUE; \
559 (void) setjmp(context); \
560 (_thread)->md.context[1] = (int) ((_sp) - 64); \
561 (_thread)->md.context[2] = (int) _main; \
562 (_thread)->md.context[3] = (int) _main + 4; \
563 _thread->no_sched = 0; \
564 PR_END_MACRO
565
566#define _MD_SWITCH_CONTEXT(_thread) \
567 if (!setjmp(CONTEXT(_thread))) { \
568 _MD_SAVE_ERRNO(_thread) \
569 _MD_SET_LAST_THREAD(_thread); \
570 _MD_SET_CURRENT_THREAD(_thread); \
571 _PR_Schedule(); \
572 }
573
574#define _MD_RESTORE_CONTEXT(_newThread) \
575{ \
576 _MD_RESTORE_ERRNO(_newThread) \
577 _MD_SET_CURRENT_THREAD(_newThread); \
578 longjmp(CONTEXT(_newThread), 1); \
579}
580
581#else
582/*
583** Initialize the thread context preparing it to execute _main.
584*/
585#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
586 PR_BEGIN_MACRO \
587 ucontext_t *uc = CONTEXT(_thread); \
588 *status = PR_TRUE; \
589 getcontext(uc); \
590 uc->uc_stack.ss_sp = (char *) ((unsigned long)(_sp - WINDOWSIZE - SA(MINFRAME)) & 0xfffffff8); \
591 uc->uc_stack.ss_size = _thread->stack->stackSize; \
592 uc->uc_stack.ss_flags = 0; /* ? */ \
593 uc->uc_mcontext.gregs[REG_SP] = (unsigned int) uc->uc_stack.ss_sp; \
594 uc->uc_mcontext.gregs[REG_PC] = (unsigned int) _main; \
595 uc->uc_mcontext.gregs[REG_nPC] = (unsigned int) ((char*)_main)+4; \
596 uc->uc_flags = UC_ALL; \
597 _thread->no_sched = 0; \
598 PR_END_MACRO
599
600/*
601** Switch away from the current thread context by saving its state and
602** calling the thread scheduler. Reload cpu when we come back from the
603** context switch because it might have changed.
604*/
605#define _MD_SWITCH_CONTEXT(_thread) \
606 PR_BEGIN_MACRO \
607 if (!getcontext(CONTEXT(_thread))) { \
608 _MD_SAVE_ERRNO(_thread); \
609 _MD_SET_LAST_THREAD(_thread); \
610 _PR_Schedule(); \
611 } \
612 PR_END_MACRO
613
614/*
615** Restore a thread context that was saved by _MD_SWITCH_CONTEXT or
616** initialized by _MD_INIT_CONTEXT.
617*/
618#define _MD_RESTORE_CONTEXT(_newThread) \
619 PR_BEGIN_MACRO \
620 ucontext_t *uc = CONTEXT(_newThread); \
621 uc->uc_mcontext.gregs[11] = 1; \
622 _MD_RESTORE_ERRNO(_newThread); \
623 _MD_SET_CURRENT_THREAD(_newThread); \
624 setcontext(uc); \
625 PR_END_MACRO
626#endif
627
628#else /* x86 solaris */
629
630#ifdef USE_SETJMP
631
632#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
633 PR_BEGIN_MACRO \
634 *status = PR_TRUE; \
635 if (setjmp(CONTEXT(_thread))) _main(); \
636 _MD_GET_SP(_thread) = (int) ((_sp) - 64); \
637 PR_END_MACRO
638
639#define _MD_SWITCH_CONTEXT(_thread) \
640 if (!setjmp(CONTEXT(_thread))) { \
641 _MD_SAVE_ERRNO(_thread) \
642 _PR_Schedule(); \
643 }
644
645#define _MD_RESTORE_CONTEXT(_newThread) \
646{ \
647 _MD_RESTORE_ERRNO(_newThread) \
648 _MD_SET_CURRENT_THREAD(_newThread); \
649 longjmp(CONTEXT(_newThread), 1); \
650}
651
652#else /* USE_SETJMP */
653
654#define WINDOWSIZE 0
655
656int getedi(void);
657void setedi(int);
658
659#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
660 PR_BEGIN_MACRO \
661 ucontext_t *uc = CONTEXT(_thread); \
662 *status = PR_TRUE; \
663 getcontext(uc); \
664 /* Force sp to be double aligned! */ \
665 uc->uc_mcontext.gregs[USP] = (int) ((unsigned long)(_sp - WINDOWSIZE - SA(MINFRAME)) & 0xfffffff8); \
666 uc->uc_mcontext.gregs[PC] = (int) _main; \
667 (_thread)->no_sched = 0; \
668 PR_END_MACRO
669
670/* getcontext() may return 1, contrary to what the man page says */
671#define _MD_SWITCH_CONTEXT(_thread) \
672 PR_BEGIN_MACRO \
673 ucontext_t *uc = CONTEXT(_thread); \
674 PR_ASSERT(_thread->no_sched); \
675 sigfillset(&((_thread)->md.blockMask)); \
676 sigprocmask(SIG_BLOCK, &((_thread)->md.blockMask), \
677 &((_thread)->md.oldMask)); \
678 (_thread)->md.edi = getedi(); \
679 if (! getcontext(uc)) { \
680 sigprocmask(SIG_SETMASK, &((_thread)->md.oldMask), NULL); \
681 uc->uc_mcontext.gregs[EDI] = (_thread)->md.edi; \
682 _MD_SAVE_ERRNO(_thread) \
683 _MD_SET_LAST_THREAD(_thread); \
684 _PR_Schedule(); \
685 } else { \
686 sigprocmask(SIG_SETMASK, &((_thread)->md.oldMask), NULL); \
687 setedi((_thread)->md.edi); \
688 PR_ASSERT(_MD_LAST_THREAD() !=_MD_CURRENT_THREAD()); \
689 _MD_LAST_THREAD()->no_sched = 0; \
690 } \
691 PR_END_MACRO
692
693/*
694** Restore a thread context, saved by _PR_SWITCH_CONTEXT
695*/
696#define _MD_RESTORE_CONTEXT(_newthread) \
697 PR_BEGIN_MACRO \
698 ucontext_t *uc = CONTEXT(_newthread); \
699 uc->uc_mcontext.gregs[EAX] = 1; \
700 _MD_RESTORE_ERRNO(_newthread) \
701 _MD_SET_CURRENT_THREAD(_newthread); \
702 (_newthread)->no_sched = 1; \
703 setcontext(uc); \
704 PR_END_MACRO
705#endif /* USE_SETJMP */
706
707#endif /* sparc */
708
709struct _MDLock {
710 PRInt8 notused;
711};
712
713struct _MDCVar {
714 PRInt8 notused;
715};
716
717struct _MDSemaphore {
718 PRInt8 notused;
719};
720
721struct _MDThread {
722 _PR_CONTEXT_TYPE context;
723 int errcode;
724 int id;
725};
726
727struct _MDThreadStack {
728 PRInt8 notused;
729};
730
731struct _MDSegment {
732 PRInt8 notused;
733};
734
735/*
736 * md-specific cpu structure field
737 */
738#define _PR_MD_MAX_OSFD FD_SETSIZE
739
740struct _MDCPU_Unix {
741 PRCList ioQ;
742 PRUint32 ioq_timeout;
743 PRInt32 ioq_max_osfd;
744 PRInt32 ioq_osfd_cnt;
745#ifndef _PR_USE_POLL
746 fd_set fd_read_set, fd_write_set, fd_exception_set;
747 PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
748 fd_exception_cnt[_PR_MD_MAX_OSFD];
749#else
750 struct pollfd *ioq_pollfds;
751 int ioq_pollfds_size;
752#endif /* _PR_USE_POLL */
753};
754
755#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
756#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
757#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
758#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
759#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
760#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
761#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
762#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
763#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
764#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
765#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
766#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
767#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
768
769#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
770
771struct _MDCPU {
772 struct _MDCPU_Unix md_unix;
773};
774
775#ifndef _PR_PTHREADS
776#define _MD_INIT_LOCKS()
777#endif
778#define _MD_NEW_LOCK(lock) PR_SUCCESS
779#define _MD_FREE_LOCK(lock)
780#define _MD_LOCK(lock)
781#define _MD_UNLOCK(lock)
782#define _MD_INIT_IO()
783#define _MD_IOQ_LOCK()
784#define _MD_IOQ_UNLOCK()
785
786#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
787#define _MD_INIT_THREAD _MD_InitializeThread
788#define _MD_EXIT_THREAD(thread)
789#define _MD_SUSPEND_THREAD(thread)
790#define _MD_RESUME_THREAD(thread)
791#define _MD_CLEAN_THREAD(_thread)
792
793extern PRStatus _MD_WAIT(struct PRThread *, PRIntervalTime timeout);
794extern PRStatus _MD_WAKEUP_WAITER(struct PRThread *);
795extern void _MD_YIELD(void);
796extern PRStatus _MD_InitializeThread(PRThread *thread);
797extern void _MD_SET_PRIORITY(struct _MDThread *thread,
798 PRThreadPriority newPri);
799extern PRStatus _MD_CREATE_THREAD(PRThread *thread, void (*start) (void *),
800 PRThreadPriority priority, PRThreadScope scope, PRThreadState state,
801 PRUint32 stackSize);
802
803NSPR_API(PRIntervalTime) _MD_Solaris_GetInterval(void);
804#define _MD_GET_INTERVAL _MD_Solaris_GetInterval
805NSPR_API(PRIntervalTime) _MD_Solaris_TicksPerSecond(void);
806#define _MD_INTERVAL_PER_SEC _MD_Solaris_TicksPerSecond
807
808/* The following defines the unwrapped versions of select() and poll(). */
809extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
810 fd_set *exceptfds, struct timeval *timeout);
811#define _MD_SELECT _select
812
813#include <stropts.h>
814#include <poll.h>
815#define _MD_POLL _poll
816extern int _poll(struct pollfd *fds, unsigned long nfds, int timeout);
817
818PR_BEGIN_EXTERN_C
819
820/*
821** Missing function prototypes
822*/
823extern int gethostname (char *name, int namelen);
824
825PR_END_EXTERN_C
826
827#endif /* _PR_GLOBAL_THREADS_ONLY */
828
829extern void _MD_solaris_map_sendfile_error(int err);
830
831#endif /* nspr_solaris_defs_h___ */
832
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