Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: gecko-sdk/include/md/_solaris.h

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

Powered by Google App Engine
This is Rietveld 408576698