VirtualBox

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

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