VirtualBox

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

Last change on this file since 4885 was 4837, checked in by vboxsync, 18 years ago

Solaris

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

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