Bug 469739 - Add support for displaying Vista UAC shield icon; r=joe sr=vladimir
[wine-gecko.git] / nsprpub / pr / include / md / _irix.h
blobc38bb4bc282a2a6f0185e8f87f6a1bc630dfc66f
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
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/
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.
15 * The Original Code is the Netscape Portable Runtime (NSPR).
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.
22 * Contributor(s):
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.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nspr_irix_defs_h___
39 #define nspr_irix_defs_h___
41 #define _PR_HAVE_ATOMIC_CAS
44 * MipsPro assembler defines _LANGUAGE_ASSEMBLY
46 #ifndef _LANGUAGE_ASSEMBLY
48 #include "prclist.h"
49 #include "prthread.h"
50 #include <sys/ucontext.h>
53 * Internal configuration macros
56 #define PR_LINKER_ARCH "irix"
57 #define _PR_SI_SYSNAME "IRIX"
58 #define _PR_SI_ARCHITECTURE "mips"
59 #define PR_DLL_SUFFIX ".so"
61 #define _PR_VMBASE 0x30000000
62 #define _PR_STACK_VMBASE 0x50000000
63 #define _PR_NUM_GCREGS 9
64 #define _MD_MMAP_FLAGS MAP_PRIVATE
66 #define _MD_DEFAULT_STACK_SIZE 65536L
67 #define _MD_MIN_STACK_SIZE 16384L
69 #undef HAVE_STACK_GROWING_UP
70 #define HAVE_WEAK_IO_SYMBOLS
71 #define HAVE_WEAK_MALLOC_SYMBOLS
72 #define HAVE_DLL
73 #define USE_DLFCN
74 #define _PR_HAVE_ATOMIC_OPS
75 #define _PR_POLL_AVAILABLE
76 #define _PR_USE_POLL
77 #define _PR_STAT_HAS_ST_ATIM
78 #define _PR_HAVE_OFF64_T
79 #define HAVE_POINTER_LOCALTIME_R
80 #define _PR_HAVE_POSIX_SEMAPHORES
81 #define PR_HAVE_POSIX_NAMED_SHARED_MEMORY
82 #define _PR_ACCEPT_INHERIT_NONBLOCK
84 #ifdef _PR_INET6
85 #define _PR_HAVE_INET_NTOP
86 #define _PR_HAVE_GETIPNODEBYNAME
87 #define _PR_HAVE_GETIPNODEBYADDR
88 #define _PR_HAVE_GETADDRINFO
89 #endif
91 /* Initialization entry points */
92 NSPR_API(void) _MD_EarlyInit(void);
93 #define _MD_EARLY_INIT _MD_EarlyInit
95 NSPR_API(void) _MD_IrixInit(void);
96 #define _MD_FINAL_INIT _MD_IrixInit
98 #define _MD_INIT_IO()
100 /* Timer operations */
101 NSPR_API(PRIntervalTime) _MD_IrixGetInterval(void);
102 #define _MD_GET_INTERVAL _MD_IrixGetInterval
104 NSPR_API(PRIntervalTime) _MD_IrixIntervalPerSec(void);
105 #define _MD_INTERVAL_PER_SEC _MD_IrixIntervalPerSec
107 /* GC operations */
108 NSPR_API(void *) _MD_GetSP(PRThread *thread);
109 #define _MD_GET_SP _MD_GetSP
111 /* The atomic operations */
112 #include <mutex.h>
113 #define _MD_INIT_ATOMIC()
114 #define _MD_ATOMIC_INCREMENT(val) add_then_test((unsigned long*)val, 1)
115 #define _MD_ATOMIC_ADD(ptr, val) add_then_test((unsigned long*)ptr, (unsigned long)val)
116 #define _MD_ATOMIC_DECREMENT(val) add_then_test((unsigned long*)val, 0xffffffff)
117 #define _MD_ATOMIC_SET(val, newval) test_and_set((unsigned long*)val, newval)
119 #if defined(_PR_PTHREADS)
120 #else /* defined(_PR_PTHREADS) */
122 /************************************************************************/
124 #include <setjmp.h>
125 #include <errno.h>
126 #include <unistd.h>
127 #include <bstring.h>
128 #include <sys/time.h>
129 #include <ulocks.h>
130 #include <sys/prctl.h>
134 * Data region private to each sproc. This region is setup by calling
135 * mmap(...,MAP_LOCAL,...). The private data is mapped at the same
136 * address in every sproc, but every sproc gets a private mapping.
138 * Just make sure that this structure fits in a page, as only one page
139 * is allocated for the private region.
141 struct sproc_private_data {
142 struct PRThread *me;
143 struct _PRCPU *cpu;
144 struct PRThread *last;
145 PRUintn intsOff;
146 int sproc_pid;
149 extern char *_nspr_sproc_private;
151 #define _PR_PRDA() ((struct sproc_private_data *) _nspr_sproc_private)
152 #define _MD_SET_CURRENT_THREAD(_thread) _PR_PRDA()->me = (_thread)
153 #define _MD_THIS_THREAD() (_PR_PRDA()->me)
154 #define _MD_LAST_THREAD() (_PR_PRDA()->last)
155 #define _MD_SET_LAST_THREAD(_thread) _PR_PRDA()->last = (_thread)
156 #define _MD_CURRENT_CPU() (_PR_PRDA()->cpu)
157 #define _MD_SET_CURRENT_CPU(_cpu) _PR_PRDA()->cpu = (_cpu)
158 #define _MD_SET_INTSOFF(_val) (_PR_PRDA()->intsOff = _val)
159 #define _MD_GET_INTSOFF() (_PR_PRDA()->intsOff)
161 #define _MD_SET_SPROC_PID(_val) (_PR_PRDA()->sproc_pid = _val)
162 #define _MD_GET_SPROC_PID() (_PR_PRDA()->sproc_pid)
164 NSPR_API(struct PRThread*) _MD_get_attached_thread(void);
165 NSPR_API(struct PRThread*) _MD_get_current_thread(void);
166 #define _MD_GET_ATTACHED_THREAD() _MD_get_attached_thread()
167 #define _MD_CURRENT_THREAD() _MD_get_current_thread()
169 #define _MD_CHECK_FOR_EXIT() { \
170 if (_pr_irix_exit_now) { \
171 _PR_POST_SEM(_pr_irix_exit_sem); \
172 _MD_Wakeup_CPUs(); \
173 _exit(0); \
177 #define _MD_ATTACH_THREAD(threadp)
179 #define _MD_SAVE_ERRNO(_thread) (_thread)->md.errcode = errno;
180 #define _MD_RESTORE_ERRNO(_thread) errno = (_thread)->md.errcode;
182 extern struct _PRCPU *_pr_primordialCPU;
183 extern usema_t *_pr_irix_exit_sem;
184 extern PRInt32 _pr_irix_exit_now;
185 extern int _pr_irix_primoridal_cpu_fd[];
186 extern PRInt32 _pr_irix_process_exit;
187 extern PRInt32 _pr_irix_process_exit_code;
189 /* Thread operations */
190 #define _PR_LOCK_HEAP() { \
191 PRIntn _is; \
192 if (_pr_primordialCPU) { \
193 if (_MD_GET_ATTACHED_THREAD() && \
194 !_PR_IS_NATIVE_THREAD( \
195 _MD_GET_ATTACHED_THREAD())) \
196 _PR_INTSOFF(_is); \
197 _PR_LOCK(_pr_heapLock); \
200 #define _PR_UNLOCK_HEAP() if (_pr_primordialCPU) { \
201 _PR_UNLOCK(_pr_heapLock); \
202 if (_MD_GET_ATTACHED_THREAD() && \
203 !_PR_IS_NATIVE_THREAD( \
204 _MD_GET_ATTACHED_THREAD())) \
205 _PR_INTSON(_is); \
209 #define _PR_OPEN_POLL_SEM(_sem) usopenpollsema(_sem, 0666)
210 #define _PR_WAIT_SEM(_sem) uspsema(_sem)
211 #define _PR_POST_SEM(_sem) usvsema(_sem)
213 #define _MD_CVAR_POST_SEM(threadp) usvsema((threadp)->md.cvar_pollsem)
215 #define _MD_IOQ_LOCK()
216 #define _MD_IOQ_UNLOCK()
218 struct _MDLock {
219 ulock_t lock;
220 usptr_t *arena;
224 * disable pre-emption for the LOCAL threads when calling the arena lock
225 * routines
228 #define _PR_LOCK(lock) { \
229 PRIntn _is; \
230 PRThread *me = _MD_GET_ATTACHED_THREAD(); \
231 if (me && !_PR_IS_NATIVE_THREAD(me)) \
232 _PR_INTSOFF(_is); \
233 ussetlock(lock); \
234 if (me && !_PR_IS_NATIVE_THREAD(me)) \
235 _PR_FAST_INTSON(_is); \
238 #define _PR_UNLOCK(lock) { \
239 PRIntn _is; \
240 PRThread *me = _MD_GET_ATTACHED_THREAD(); \
241 if (me && !_PR_IS_NATIVE_THREAD(me)) \
242 _PR_INTSOFF(_is); \
243 usunsetlock(lock); \
244 if (me && !_PR_IS_NATIVE_THREAD(me)) \
245 _PR_FAST_INTSON(_is); \
248 NSPR_API(PRStatus) _MD_NEW_LOCK(struct _MDLock *md);
249 NSPR_API(void) _MD_FREE_LOCK(struct _MDLock *lockp);
251 #define _MD_LOCK(_lockp) _PR_LOCK((_lockp)->lock)
252 #define _MD_UNLOCK(_lockp) _PR_UNLOCK((_lockp)->lock)
253 #define _MD_TEST_AND_LOCK(_lockp) (uscsetlock((_lockp)->lock, 1) == 0)
255 extern ulock_t _pr_heapLock;
257 struct _MDThread {
258 jmp_buf jb;
259 usptr_t *pollsem_arena;
260 usema_t *cvar_pollsem;
261 PRInt32 cvar_pollsemfd;
262 PRInt32 cvar_pollsem_select; /* acquire sem by calling select */
263 PRInt32 cvar_wait; /* if 1, thread is waiting on cvar Q */
264 PRInt32 id;
265 PRInt32 suspending_id;
266 int errcode;
269 struct _MDThreadStack {
270 PRInt8 notused;
273 struct _MDSemaphore {
274 usema_t *sem;
277 struct _MDCVar {
278 ulock_t mdcvar_lock;
281 struct _MDSegment {
282 PRInt8 notused;
286 * md-specific cpu structure field
288 #define _PR_MD_MAX_OSFD FD_SETSIZE
290 struct _MDCPU_Unix {
291 PRCList ioQ;
292 PRUint32 ioq_timeout;
293 PRInt32 ioq_max_osfd;
294 PRInt32 ioq_osfd_cnt;
295 #ifndef _PR_USE_POLL
296 fd_set fd_read_set, fd_write_set, fd_exception_set;
297 PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
298 fd_exception_cnt[_PR_MD_MAX_OSFD];
299 #else
300 struct pollfd *ioq_pollfds;
301 int ioq_pollfds_size;
302 #endif /* _PR_USE_POLL */
305 #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
306 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
307 #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
308 #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
309 #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
310 #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
311 #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
312 #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
313 #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
314 #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
315 #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
316 #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
317 #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
319 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
322 struct _MDCPU {
323 PRInt32 id;
324 PRInt32 suspending_id;
325 struct _MDCPU_Unix md_unix;
329 ** Initialize the thread context preparing it to execute _main.
331 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
332 PR_BEGIN_MACRO \
333 int *jb = (_thread)->md.jb; \
334 *status = PR_TRUE; \
335 (void) setjmp(jb); \
336 (_thread)->md.jb[JB_SP] = (int) ((_sp) - 64); \
337 (_thread)->md.jb[JB_PC] = (int) _main; \
338 _thread->no_sched = 0; \
339 PR_END_MACRO
342 ** Switch away from the current thread context by saving its state and
343 ** calling the thread scheduler. Reload cpu when we come back from the
344 ** context switch because it might have changed.
346 * XXX RUNQ lock needed before clearing _PR_NO_SCHED flag, because the
347 * thread may be unr RUNQ?
349 #define _MD_SWITCH_CONTEXT(_thread) \
350 PR_BEGIN_MACRO \
351 PR_ASSERT(_thread->no_sched); \
352 if (!setjmp(_thread->md.jb)) { \
353 _MD_SAVE_ERRNO(_thread) \
354 _MD_SET_LAST_THREAD(_thread); \
355 _PR_Schedule(); \
356 } else { \
357 PR_ASSERT(_MD_LAST_THREAD() !=_MD_CURRENT_THREAD()); \
358 _MD_LAST_THREAD()->no_sched = 0; \
360 PR_END_MACRO
363 ** Restore a thread context that was saved by _MD_SWITCH_CONTEXT or
364 ** initialized by _MD_INIT_CONTEXT.
366 #define _MD_RESTORE_CONTEXT(_newThread) \
367 PR_BEGIN_MACRO \
368 int *jb = (_newThread)->md.jb; \
369 _MD_RESTORE_ERRNO(_newThread) \
370 _MD_SET_CURRENT_THREAD(_newThread); \
371 _newThread->no_sched = 1; \
372 longjmp(jb, 1); \
373 PR_END_MACRO
375 NSPR_API(PRStatus) _MD_InitThread(struct PRThread *thread,
376 PRBool wakeup_parent);
377 NSPR_API(PRStatus) _MD_InitAttachedThread(struct PRThread *thread,
378 PRBool wakeup_parent);
379 #define _MD_INIT_THREAD(thread) _MD_InitThread(thread, PR_TRUE)
380 #define _MD_INIT_ATTACHED_THREAD(thread) \
381 _MD_InitAttachedThread(thread, PR_FALSE)
383 NSPR_API(void) _MD_ExitThread(struct PRThread *thread);
384 #define _MD_EXIT_THREAD _MD_ExitThread
386 NSPR_API(void) _MD_SuspendThread(struct PRThread *thread);
387 #define _MD_SUSPEND_THREAD _MD_SuspendThread
389 NSPR_API(void) _MD_ResumeThread(struct PRThread *thread);
390 #define _MD_RESUME_THREAD _MD_ResumeThread
392 NSPR_API(void) _MD_SuspendCPU(struct _PRCPU *thread);
393 #define _MD_SUSPEND_CPU _MD_SuspendCPU
395 NSPR_API(void) _MD_ResumeCPU(struct _PRCPU *thread);
396 #define _MD_RESUME_CPU _MD_ResumeCPU
398 #define _MD_BEGIN_SUSPEND_ALL()
399 #define _MD_END_SUSPEND_ALL()
400 #define _MD_BEGIN_RESUME_ALL()
401 #define _MD_END_RESUME_ALL()
403 NSPR_API(void) _MD_InitLocks(void);
404 #define _MD_INIT_LOCKS _MD_InitLocks
406 NSPR_API(void) _MD_CleanThread(struct PRThread *thread);
407 #define _MD_CLEAN_THREAD _MD_CleanThread
409 #define _MD_YIELD() sginap(0)
411 /* The _PR_MD_WAIT_LOCK and _PR_MD_WAKEUP_WAITER functions put to sleep and
412 * awaken a thread which is waiting on a lock or cvar.
414 NSPR_API(PRStatus) _MD_wait(struct PRThread *, PRIntervalTime timeout);
415 #define _MD_WAIT _MD_wait
417 NSPR_API(void) _PR_MD_primordial_cpu();
418 NSPR_API(void) _PR_MD_WAKEUP_PRIMORDIAL_CPU();
420 NSPR_API(PRStatus) _MD_WakeupWaiter(struct PRThread *);
421 #define _MD_WAKEUP_WAITER _MD_WakeupWaiter
423 NSPR_API(void ) _MD_exit(PRIntn status);
424 #define _MD_EXIT _MD_exit
426 #include "prthread.h"
428 NSPR_API(void) _MD_SetPriority(struct _MDThread *thread,
429 PRThreadPriority newPri);
430 #define _MD_SET_PRIORITY _MD_SetPriority
432 NSPR_API(PRStatus) _MD_CreateThread(
433 struct PRThread *thread,
434 void (*start) (void *),
435 PRThreadPriority priority,
436 PRThreadScope scope,
437 PRThreadState state,
438 PRUint32 stackSize);
439 #define _MD_CREATE_THREAD _MD_CreateThread
441 extern void _MD_CleanupBeforeExit(void);
442 #define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit
444 NSPR_API(void) _PR_MD_PRE_CLEANUP(PRThread *me);
447 /* The following defines the unwrapped versions of select() and poll(). */
448 extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
449 fd_set *exceptfds, struct timeval *timeout);
450 #define _MD_SELECT _select
452 #include <stropts.h>
453 #include <poll.h>
454 #define _MD_POLL _poll
455 extern int _poll(struct pollfd *fds, unsigned long nfds, int timeout);
458 #define HAVE_THREAD_AFFINITY 1
460 NSPR_API(PRInt32) _MD_GetThreadAffinityMask(PRThread *unused, PRUint32 *mask);
461 #define _MD_GETTHREADAFFINITYMASK _MD_GetThreadAffinityMask
463 NSPR_API(void) _MD_InitRunningCPU(struct _PRCPU *cpu);
464 #define _MD_INIT_RUNNING_CPU _MD_InitRunningCPU
466 #endif /* defined(_PR_PTHREADS) */
468 #endif /* _LANGUAGE_ASSEMBLY */
470 #endif /* nspr_irix_defs_h___ */