michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef primpl_h___ michael@0: #define primpl_h___ michael@0: michael@0: /* michael@0: * HP-UX 10.10's pthread.h (DCE threads) includes dce/cma.h, which michael@0: * has: michael@0: * #define sigaction _sigaction_sys michael@0: * This macro causes chaos if signal.h gets included before pthread.h. michael@0: * To be safe, we include pthread.h first. michael@0: */ michael@0: michael@0: #if defined(_PR_PTHREADS) michael@0: #include michael@0: #endif michael@0: michael@0: #if defined(_PR_BTHREADS) michael@0: #include michael@0: #endif michael@0: michael@0: #ifdef WIN32 michael@0: /* michael@0: * Allow use of functions and symbols first defined in Win2k. michael@0: */ michael@0: #if !defined(WINVER) || (WINVER < 0x0500) michael@0: #undef WINVER michael@0: #define WINVER 0x0500 michael@0: #endif michael@0: #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500) michael@0: #undef _WIN32_WINNT michael@0: #define _WIN32_WINNT 0x0500 michael@0: #endif michael@0: #endif /* WIN32 */ michael@0: michael@0: #include "nspr.h" michael@0: #include "prpriv.h" michael@0: michael@0: typedef struct PRSegment PRSegment; michael@0: michael@0: #include "md/prosdep.h" michael@0: #include "obsolete/probslet.h" michael@0: michael@0: #ifdef _PR_HAVE_POSIX_SEMAPHORES michael@0: #include michael@0: #elif defined(_PR_HAVE_SYSV_SEMAPHORES) michael@0: #include michael@0: #endif michael@0: michael@0: #ifdef HAVE_SYSCALL michael@0: #include michael@0: #endif michael@0: michael@0: /************************************************************************* michael@0: ***** A Word about Model Dependent Function Naming Convention *********** michael@0: *************************************************************************/ michael@0: michael@0: /* michael@0: NSPR 2.0 must implement its function across a range of platforms michael@0: including: MAC, Windows/16, Windows/95, Windows/NT, and several michael@0: variants of Unix. Each implementation shares common code as well michael@0: as having platform dependent portions. This standard describes how michael@0: the model dependent portions are to be implemented. michael@0: michael@0: In header file pr/include/primpl.h, each publicly declared michael@0: platform dependent function is declared as: michael@0: michael@0: NSPR_API void _PR_MD_FUNCTION( long arg1, long arg2 ); michael@0: #define _PR_MD_FUNCTION _MD_FUNCTION michael@0: michael@0: In header file pr/include/md//_.h, michael@0: each #define'd macro is redefined as one of: michael@0: michael@0: #define _MD_FUNCTION michael@0: #define _MD_FUNCTION michael@0: #define _MD_FUNCTION michael@0: #define _MD_FUNCTION <_MD_Function> michael@0: michael@0: Where: michael@0: michael@0: is no definition at all. In this case, the function is not implemented michael@0: and is never called for this platform. michael@0: For example: michael@0: #define _MD_INIT_CPUS() michael@0: michael@0: is a C language macro expansion. michael@0: For example: michael@0: #define _MD_CLEAN_THREAD(_thread) \ michael@0: PR_BEGIN_MACRO \ michael@0: PR_DestroyCondVar(_thread->md.asyncIOCVar); \ michael@0: PR_DestroyLock(_thread->md.asyncIOLock); \ michael@0: PR_END_MACRO michael@0: michael@0: is some function implemented by the host operating system. michael@0: For example: michael@0: #define _MD_EXIT exit michael@0: michael@0: <_MD_function> is the name of a function implemented for this platform in michael@0: pr/src/md//.c file. michael@0: For example: michael@0: #define _MD_GETFILEINFO _MD_GetFileInfo michael@0: michael@0: In .c, the implementation is: michael@0: PR_IMPLEMENT(PRInt32) _MD_GetFileInfo(const char *fn, PRFileInfo *info); michael@0: */ michael@0: michael@0: PR_BEGIN_EXTERN_C michael@0: michael@0: typedef struct _MDLock _MDLock; michael@0: typedef struct _MDCVar _MDCVar; michael@0: typedef struct _MDSegment _MDSegment; michael@0: typedef struct _MDThread _MDThread; michael@0: typedef struct _MDThreadStack _MDThreadStack; michael@0: typedef struct _MDSemaphore _MDSemaphore; michael@0: typedef struct _MDDir _MDDir; michael@0: #ifdef MOZ_UNICODE michael@0: typedef struct _MDDirUTF16 _MDDirUTF16; michael@0: #endif /* MOZ_UNICODE */ michael@0: typedef struct _MDFileDesc _MDFileDesc; michael@0: typedef struct _MDProcess _MDProcess; michael@0: typedef struct _MDFileMap _MDFileMap; michael@0: michael@0: #if defined(_PR_PTHREADS) michael@0: michael@0: /* michael@0: ** The following definitions are unique to implementing NSPR using pthreads. michael@0: ** Since pthreads defines most of the thread and thread synchronization michael@0: ** stuff, this is a pretty small set. michael@0: */ michael@0: michael@0: #define PT_CV_NOTIFIED_LENGTH 6 michael@0: typedef struct _PT_Notified _PT_Notified; michael@0: struct _PT_Notified michael@0: { michael@0: PRIntn length; /* # of used entries in this structure */ michael@0: struct michael@0: { michael@0: PRCondVar *cv; /* the condition variable notified */ michael@0: PRIntn times; /* and the number of times notified */ michael@0: } cv[PT_CV_NOTIFIED_LENGTH]; michael@0: _PT_Notified *link; /* link to another of these | NULL */ michael@0: }; michael@0: michael@0: /* michael@0: * bits defined for pthreads 'state' field michael@0: */ michael@0: #define PT_THREAD_DETACHED 0x01 /* thread can't be joined */ michael@0: #define PT_THREAD_GLOBAL 0x02 /* a global thread (unlikely) */ michael@0: #define PT_THREAD_SYSTEM 0x04 /* system (not user) thread */ michael@0: #define PT_THREAD_PRIMORD 0x08 /* this is the primordial thread */ michael@0: #define PT_THREAD_ABORTED 0x10 /* thread has been interrupted */ michael@0: #define PT_THREAD_GCABLE 0x20 /* thread is garbage collectible */ michael@0: #define PT_THREAD_SUSPENDED 0x40 /* thread has been suspended */ michael@0: #define PT_THREAD_FOREIGN 0x80 /* thread is not one of ours */ michael@0: #define PT_THREAD_BOUND 0x100 /* a bound-global thread */ michael@0: michael@0: #define _PT_THREAD_INTERRUPTED(thr) \ michael@0: (!(thr->interrupt_blocked) && (thr->state & PT_THREAD_ABORTED)) michael@0: #define _PT_THREAD_BLOCK_INTERRUPT(thr) \ michael@0: (thr->interrupt_blocked = 1) michael@0: #define _PT_THREAD_UNBLOCK_INTERRUPT(thr) \ michael@0: (thr->interrupt_blocked = 0) michael@0: michael@0: #define _PT_IS_GCABLE_THREAD(thr) ((thr)->state & PT_THREAD_GCABLE) michael@0: michael@0: /* michael@0: ** Possible values for thread's suspend field michael@0: ** Note that the first two can be the same as they are really mutually exclusive, michael@0: ** i.e. both cannot be happening at the same time. We have two symbolic names michael@0: ** just as a mnemonic. michael@0: **/ michael@0: #define PT_THREAD_RESUMED 0x80 /* thread has been resumed */ michael@0: #define PT_THREAD_SETGCABLE 0x100 /* set the GCAble flag */ michael@0: michael@0: #if defined(DEBUG) michael@0: michael@0: typedef struct PTDebug michael@0: { michael@0: PRTime timeStarted; michael@0: PRUintn locks_created, locks_destroyed; michael@0: PRUintn locks_acquired, locks_released; michael@0: PRUintn cvars_created, cvars_destroyed; michael@0: PRUintn cvars_notified, delayed_cv_deletes; michael@0: } PTDebug; michael@0: michael@0: #endif /* defined(DEBUG) */ michael@0: michael@0: NSPR_API(void) PT_FPrintStats(PRFileDesc *fd, const char *msg); michael@0: michael@0: /* michael@0: * On Linux and its derivatives POSIX priority scheduling works only for michael@0: * real-time threads. On those platforms we set thread's nice values michael@0: * instead which requires us to track kernel thread IDs for each POSIX michael@0: * thread we create. michael@0: */ michael@0: #if defined(LINUX) && defined(HAVE_SETPRIORITY) && \ michael@0: ((defined(HAVE_SYSCALL) && defined(SYS_gettid)) || defined(HAVE_GETTID)) michael@0: #define _PR_NICE_PRIORITY_SCHEDULING michael@0: #endif michael@0: michael@0: #else /* defined(_PR_PTHREADS) */ michael@0: michael@0: NSPR_API(void) PT_FPrintStats(PRFileDesc *fd, const char *msg); michael@0: michael@0: /* michael@0: ** This section is contains those parts needed to implement NSPR on michael@0: ** platforms in general. One would assume that the pthreads implementation michael@0: ** included lots of the same types, at least conceptually. michael@0: */ michael@0: michael@0: /* michael@0: * Local threads only. No multiple CPU support and hence all the michael@0: * following routines are no-op. michael@0: */ michael@0: #ifdef _PR_LOCAL_THREADS_ONLY michael@0: michael@0: #define _PR_MD_SUSPEND_THREAD(thread) michael@0: #define _PR_MD_RESUME_THREAD(thread) michael@0: #define _PR_MD_SUSPEND_CPU(cpu) michael@0: #define _PR_MD_RESUME_CPU(cpu) michael@0: #define _PR_MD_BEGIN_SUSPEND_ALL() michael@0: #define _PR_MD_END_SUSPEND_ALL() michael@0: #define _PR_MD_BEGIN_RESUME_ALL() michael@0: #define _PR_MD_END_RESUME_ALL() michael@0: #define _PR_MD_INIT_ATTACHED_THREAD(thread) PR_FAILURE michael@0: michael@0: #endif michael@0: michael@0: typedef struct _PRCPUQueue _PRCPUQueue; michael@0: typedef struct _PRCPU _PRCPU; michael@0: typedef struct _MDCPU _MDCPU; michael@0: michael@0: struct _PRCPUQueue { michael@0: _MDLock runQLock; /* lock for the run + wait queues */ michael@0: _MDLock sleepQLock; /* lock for the run + wait queues */ michael@0: _MDLock miscQLock; /* lock for the run + wait queues */ michael@0: michael@0: PRCList runQ[PR_PRIORITY_LAST + 1]; /* run queue for this CPU */ michael@0: PRUint32 runQReadyMask; michael@0: PRCList sleepQ; michael@0: PRIntervalTime sleepQmax; michael@0: PRCList pauseQ; michael@0: PRCList suspendQ; michael@0: PRCList waitingToJoinQ; michael@0: michael@0: PRUintn numCPUs; /* number of CPUs using this Q */ michael@0: }; michael@0: michael@0: struct _PRCPU { michael@0: PRCList links; /* link list of CPUs */ michael@0: PRUint32 id; /* id for this CPU */ michael@0: michael@0: union { michael@0: PRInt32 bits; michael@0: PRUint8 missed[4]; michael@0: } u; michael@0: PRIntn where; /* index into u.missed */ michael@0: PRPackedBool paused; /* cpu is paused */ michael@0: PRPackedBool exit; /* cpu should exit */ michael@0: michael@0: PRThread *thread; /* native thread for this CPUThread */ michael@0: PRThread *idle_thread; /* user-level idle thread for this CPUThread */ michael@0: michael@0: PRIntervalTime last_clock; /* the last time we went into michael@0: * _PR_ClockInterrupt() on this CPU michael@0: */ michael@0: michael@0: _PRCPUQueue *queue; michael@0: michael@0: _MDCPU md; michael@0: }; michael@0: michael@0: typedef struct _PRInterruptTable { michael@0: const char *name; michael@0: PRUintn missed_bit; michael@0: void (*handler)(void); michael@0: } _PRInterruptTable; michael@0: michael@0: #define _PR_CPU_PTR(_qp) \ michael@0: ((_PRCPU*) ((char*) (_qp) - offsetof(_PRCPU,links))) michael@0: michael@0: #if !defined(IRIX) && !defined(WIN32) && !defined(XP_OS2) \ michael@0: && !(defined(SOLARIS) && defined(_PR_GLOBAL_THREADS_ONLY)) michael@0: #define _MD_GET_ATTACHED_THREAD() (_PR_MD_CURRENT_THREAD()) michael@0: #endif michael@0: michael@0: #ifdef _PR_LOCAL_THREADS_ONLY michael@0: michael@0: NSPR_API(struct _PRCPU *) _pr_currentCPU; michael@0: NSPR_API(PRThread *) _pr_currentThread; michael@0: NSPR_API(PRThread *) _pr_lastThread; michael@0: NSPR_API(PRInt32) _pr_intsOff; michael@0: michael@0: #define _MD_CURRENT_CPU() (_pr_currentCPU) michael@0: #define _MD_SET_CURRENT_CPU(_cpu) (_pr_currentCPU = (_cpu)) michael@0: #define _MD_CURRENT_THREAD() (_pr_currentThread) michael@0: #define _MD_SET_CURRENT_THREAD(_thread) (_pr_currentThread = (_thread)) michael@0: #define _MD_LAST_THREAD() (_pr_lastThread) michael@0: #define _MD_SET_LAST_THREAD(t) (_pr_lastThread = t) michael@0: michael@0: #define _MD_GET_INTSOFF() (_pr_intsOff) michael@0: #define _MD_SET_INTSOFF(_val) (_pr_intsOff = _val) michael@0: michael@0: michael@0: /* The unbalanced curly braces in these two macros are intentional */ michael@0: #define _PR_LOCK_HEAP() { PRIntn _is; if (_pr_currentCPU) _PR_INTSOFF(_is); michael@0: #define _PR_UNLOCK_HEAP() if (_pr_currentCPU) _PR_INTSON(_is); } michael@0: michael@0: #endif /* _PR_LOCAL_THREADS_ONLY */ michael@0: michael@0: extern PRInt32 _native_threads_only; michael@0: michael@0: #if defined(_PR_GLOBAL_THREADS_ONLY) michael@0: michael@0: #define _MD_GET_INTSOFF() 0 michael@0: #define _MD_SET_INTSOFF(_val) michael@0: #define _PR_INTSOFF(_is) michael@0: #define _PR_FAST_INTSON(_is) michael@0: #define _PR_INTSON(_is) michael@0: #define _PR_THREAD_LOCK(_thread) michael@0: #define _PR_THREAD_UNLOCK(_thread) michael@0: #define _PR_RUNQ_LOCK(cpu) michael@0: #define _PR_RUNQ_UNLOCK(cpu) michael@0: #define _PR_SLEEPQ_LOCK(thread) michael@0: #define _PR_SLEEPQ_UNLOCK(thread) michael@0: #define _PR_MISCQ_LOCK(thread) michael@0: #define _PR_MISCQ_UNLOCK(thread) michael@0: #define _PR_CPU_LIST_LOCK() michael@0: #define _PR_CPU_LIST_UNLOCK() michael@0: michael@0: #define _PR_ADD_RUNQ(_thread, _cpu, _pri) michael@0: #define _PR_DEL_RUNQ(_thread) michael@0: #define _PR_ADD_SLEEPQ(_thread, _timeout) michael@0: #define _PR_DEL_SLEEPQ(_thread, _propogate) michael@0: #define _PR_ADD_JOINQ(_thread, _cpu) michael@0: #define _PR_DEL_JOINQ(_thread) michael@0: #define _PR_ADD_SUSPENDQ(_thread, _cpu) michael@0: #define _PR_DEL_SUSPENDQ(_thread) michael@0: michael@0: #define _PR_THREAD_SWITCH_CPU(_thread, _newCPU) michael@0: michael@0: #define _PR_IS_NATIVE_THREAD(thread) 1 michael@0: #define _PR_IS_NATIVE_THREAD_SUPPORTED() 1 michael@0: michael@0: #else michael@0: michael@0: #define _PR_INTSOFF(_is) \ michael@0: PR_BEGIN_MACRO \ michael@0: (_is) = _PR_MD_GET_INTSOFF(); \ michael@0: _PR_MD_SET_INTSOFF(1); \ michael@0: PR_END_MACRO michael@0: michael@0: #define _PR_FAST_INTSON(_is) \ michael@0: PR_BEGIN_MACRO \ michael@0: _PR_MD_SET_INTSOFF(_is); \ michael@0: PR_END_MACRO michael@0: michael@0: #define _PR_INTSON(_is) \ michael@0: PR_BEGIN_MACRO \ michael@0: if ((_is == 0) && (_PR_MD_CURRENT_CPU())->u.bits) \ michael@0: _PR_IntsOn((_PR_MD_CURRENT_CPU())); \ michael@0: _PR_MD_SET_INTSOFF(_is); \ michael@0: PR_END_MACRO michael@0: michael@0: #ifdef _PR_LOCAL_THREADS_ONLY michael@0: michael@0: #define _PR_IS_NATIVE_THREAD(thread) 0 michael@0: #define _PR_THREAD_LOCK(_thread) michael@0: #define _PR_THREAD_UNLOCK(_thread) michael@0: #define _PR_RUNQ_LOCK(cpu) michael@0: #define _PR_RUNQ_UNLOCK(cpu) michael@0: #define _PR_SLEEPQ_LOCK(thread) michael@0: #define _PR_SLEEPQ_UNLOCK(thread) michael@0: #define _PR_MISCQ_LOCK(thread) michael@0: #define _PR_MISCQ_UNLOCK(thread) michael@0: #define _PR_CPU_LIST_LOCK() michael@0: #define _PR_CPU_LIST_UNLOCK() michael@0: michael@0: #define _PR_ADD_RUNQ(_thread, _cpu, _pri) \ michael@0: PR_BEGIN_MACRO \ michael@0: PR_APPEND_LINK(&(_thread)->links, &_PR_RUNQ(_cpu)[_pri]); \ michael@0: _PR_RUNQREADYMASK(_cpu) |= (1L << _pri); \ michael@0: PR_END_MACRO michael@0: michael@0: #define _PR_DEL_RUNQ(_thread) \ michael@0: PR_BEGIN_MACRO \ michael@0: _PRCPU *_cpu = _thread->cpu; \ michael@0: PRInt32 _pri = _thread->priority; \ michael@0: PR_REMOVE_LINK(&(_thread)->links); \ michael@0: if (PR_CLIST_IS_EMPTY(&_PR_RUNQ(_cpu)[_pri])) \ michael@0: _PR_RUNQREADYMASK(_cpu) &= ~(1L << _pri); \ michael@0: PR_END_MACRO michael@0: michael@0: #define _PR_ADD_SLEEPQ(_thread, _timeout) \ michael@0: _PR_AddSleepQ(_thread, _timeout); michael@0: michael@0: #define _PR_DEL_SLEEPQ(_thread, _propogate) \ michael@0: _PR_DelSleepQ(_thread, _propogate); michael@0: michael@0: #define _PR_ADD_JOINQ(_thread, _cpu) \ michael@0: PR_APPEND_LINK(&(_thread)->links, &_PR_WAITINGTOJOINQ(_cpu)); michael@0: michael@0: #define _PR_DEL_JOINQ(_thread) \ michael@0: PR_REMOVE_LINK(&(_thread)->links); michael@0: michael@0: #define _PR_ADD_SUSPENDQ(_thread, _cpu) \ michael@0: PR_APPEND_LINK(&(_thread)->links, &_PR_SUSPENDQ(_cpu)); michael@0: michael@0: #define _PR_DEL_SUSPENDQ(_thread) \ michael@0: PR_REMOVE_LINK(&(_thread)->links); michael@0: michael@0: #define _PR_THREAD_SWITCH_CPU(_thread, _newCPU) michael@0: michael@0: #define _PR_IS_NATIVE_THREAD_SUPPORTED() 0 michael@0: michael@0: #else /* _PR_LOCAL_THREADS_ONLY */ michael@0: michael@0: /* These are for the "combined" thread model */ michael@0: michael@0: #define _PR_THREAD_LOCK(_thread) \ michael@0: _PR_MD_LOCK(&(_thread)->threadLock); michael@0: michael@0: #define _PR_THREAD_UNLOCK(_thread) \ michael@0: _PR_MD_UNLOCK(&(_thread)->threadLock); michael@0: michael@0: #define _PR_RUNQ_LOCK(_cpu) \ michael@0: PR_BEGIN_MACRO \ michael@0: _PR_MD_LOCK(&(_cpu)->queue->runQLock );\ michael@0: PR_END_MACRO michael@0: michael@0: #define _PR_RUNQ_UNLOCK(_cpu) \ michael@0: PR_BEGIN_MACRO \ michael@0: _PR_MD_UNLOCK(&(_cpu)->queue->runQLock );\ michael@0: PR_END_MACRO michael@0: michael@0: #define _PR_SLEEPQ_LOCK(_cpu) \ michael@0: _PR_MD_LOCK(&(_cpu)->queue->sleepQLock ); michael@0: michael@0: #define _PR_SLEEPQ_UNLOCK(_cpu) \ michael@0: _PR_MD_UNLOCK(&(_cpu)->queue->sleepQLock ); michael@0: michael@0: #define _PR_MISCQ_LOCK(_cpu) \ michael@0: _PR_MD_LOCK(&(_cpu)->queue->miscQLock ); michael@0: michael@0: #define _PR_MISCQ_UNLOCK(_cpu) \ michael@0: _PR_MD_UNLOCK(&(_cpu)->queue->miscQLock ); michael@0: michael@0: #define _PR_CPU_LIST_LOCK() _PR_MD_LOCK(&_pr_cpuLock) michael@0: #define _PR_CPU_LIST_UNLOCK() _PR_MD_UNLOCK(&_pr_cpuLock) michael@0: michael@0: #define QUEUE_RUN 0x1 michael@0: #define QUEUE_SLEEP 0x2 michael@0: #define QUEUE_JOIN 0x4 michael@0: #define QUEUE_SUSPEND 0x8 michael@0: #define QUEUE_LOCK 0x10 michael@0: michael@0: #define _PR_ADD_RUNQ(_thread, _cpu, _pri) \ michael@0: PR_BEGIN_MACRO \ michael@0: PR_APPEND_LINK(&(_thread)->links, &_PR_RUNQ(_cpu)[_pri]); \ michael@0: _PR_RUNQREADYMASK(_cpu) |= (1L << _pri); \ michael@0: PR_ASSERT((_thread)->queueCount == 0); \ michael@0: (_thread)->queueCount = QUEUE_RUN; \ michael@0: PR_END_MACRO michael@0: michael@0: #define _PR_DEL_RUNQ(_thread) \ michael@0: PR_BEGIN_MACRO \ michael@0: _PRCPU *_cpu = _thread->cpu; \ michael@0: PRInt32 _pri = _thread->priority; \ michael@0: PR_REMOVE_LINK(&(_thread)->links); \ michael@0: if (PR_CLIST_IS_EMPTY(&_PR_RUNQ(_cpu)[_pri])) \ michael@0: _PR_RUNQREADYMASK(_cpu) &= ~(1L << _pri); \ michael@0: PR_ASSERT((_thread)->queueCount == QUEUE_RUN);\ michael@0: (_thread)->queueCount = 0; \ michael@0: PR_END_MACRO michael@0: michael@0: #define _PR_ADD_SLEEPQ(_thread, _timeout) \ michael@0: PR_ASSERT((_thread)->queueCount == 0); \ michael@0: (_thread)->queueCount = QUEUE_SLEEP; \ michael@0: _PR_AddSleepQ(_thread, _timeout); michael@0: michael@0: #define _PR_DEL_SLEEPQ(_thread, _propogate) \ michael@0: PR_ASSERT((_thread)->queueCount == QUEUE_SLEEP);\ michael@0: (_thread)->queueCount = 0; \ michael@0: _PR_DelSleepQ(_thread, _propogate); michael@0: michael@0: #define _PR_ADD_JOINQ(_thread, _cpu) \ michael@0: PR_ASSERT((_thread)->queueCount == 0); \ michael@0: (_thread)->queueCount = QUEUE_JOIN; \ michael@0: PR_APPEND_LINK(&(_thread)->links, &_PR_WAITINGTOJOINQ(_cpu)); michael@0: michael@0: #define _PR_DEL_JOINQ(_thread) \ michael@0: PR_ASSERT((_thread)->queueCount == QUEUE_JOIN);\ michael@0: (_thread)->queueCount = 0; \ michael@0: PR_REMOVE_LINK(&(_thread)->links); michael@0: michael@0: #define _PR_ADD_SUSPENDQ(_thread, _cpu) \ michael@0: PR_ASSERT((_thread)->queueCount == 0); \ michael@0: (_thread)->queueCount = QUEUE_SUSPEND; \ michael@0: PR_APPEND_LINK(&(_thread)->links, &_PR_SUSPENDQ(_cpu)); michael@0: michael@0: #define _PR_DEL_SUSPENDQ(_thread) \ michael@0: PR_ASSERT((_thread)->queueCount == QUEUE_SUSPEND);\ michael@0: (_thread)->queueCount = 0; \ michael@0: PR_REMOVE_LINK(&(_thread)->links); michael@0: michael@0: #define _PR_THREAD_SWITCH_CPU(_thread, _newCPU) \ michael@0: (_thread)->cpu = (_newCPU); michael@0: michael@0: #define _PR_IS_NATIVE_THREAD(thread) (thread->flags & _PR_GLOBAL_SCOPE) michael@0: #define _PR_IS_NATIVE_THREAD_SUPPORTED() 1 michael@0: michael@0: #endif /* _PR_LOCAL_THREADS_ONLY */ michael@0: michael@0: #endif /* _PR_GLOBAL_THREADS_ONLY */ michael@0: michael@0: #define _PR_SET_RESCHED_FLAG() _PR_MD_CURRENT_CPU()->u.missed[3] = 1 michael@0: #define _PR_CLEAR_RESCHED_FLAG() _PR_MD_CURRENT_CPU()->u.missed[3] = 0 michael@0: michael@0: extern _PRInterruptTable _pr_interruptTable[]; michael@0: michael@0: /* Bits for _pr_interruptState.u.missed[0,1] */ michael@0: #define _PR_MISSED_CLOCK 0x1 michael@0: #define _PR_MISSED_IO 0x2 michael@0: #define _PR_MISSED_CHILD 0x4 michael@0: michael@0: extern void _PR_IntsOn(_PRCPU *cpu); michael@0: michael@0: NSPR_API(void) _PR_WakeupCPU(void); michael@0: NSPR_API(void) _PR_PauseCPU(void); michael@0: michael@0: /************************************************************************/ michael@0: michael@0: #define _PR_LOCK_LOCK(_lock) \ michael@0: _PR_MD_LOCK(&(_lock)->ilock); michael@0: #define _PR_LOCK_UNLOCK(_lock) \ michael@0: _PR_MD_UNLOCK(&(_lock)->ilock); michael@0: michael@0: extern void _PR_UnblockLockWaiter(PRLock *lock); michael@0: extern PRStatus _PR_InitLock(PRLock *lock); michael@0: extern void _PR_FreeLock(PRLock *lock); michael@0: michael@0: #define _PR_LOCK_PTR(_qp) \ michael@0: ((PRLock*) ((char*) (_qp) - offsetof(PRLock,links))) michael@0: michael@0: /************************************************************************/ michael@0: michael@0: #define _PR_CVAR_LOCK(_cvar) \ michael@0: _PR_MD_LOCK(&(_cvar)->ilock); michael@0: #define _PR_CVAR_UNLOCK(_cvar) \ michael@0: _PR_MD_UNLOCK(&(_cvar)->ilock); michael@0: michael@0: extern PRStatus _PR_InitCondVar(PRCondVar *cvar, PRLock *lock); michael@0: extern void _PR_FreeCondVar(PRCondVar *cvar); michael@0: extern PRStatus _PR_WaitCondVar( michael@0: PRThread *thread, PRCondVar *cvar, PRLock *lock, PRIntervalTime timeout); michael@0: extern void _PR_NotifyCondVar(PRCondVar *cvar, PRThread *me); michael@0: extern PRUint32 _PR_CondVarToString(PRCondVar *cvar, char *buf, PRUint32 buflen); michael@0: michael@0: NSPR_API(void) _PR_Notify(PRMonitor *mon, PRBool all, PRBool sticky); michael@0: michael@0: /* PRThread.flags */ michael@0: #define _PR_SYSTEM 0x01 michael@0: #define _PR_INTERRUPT 0x02 michael@0: #define _PR_ATTACHED 0x04 /* created via PR_AttachThread */ michael@0: #define _PR_PRIMORDIAL 0x08 /* the thread that called PR_Init */ michael@0: #define _PR_ON_SLEEPQ 0x10 /* thread is on the sleepQ */ michael@0: #define _PR_ON_PAUSEQ 0x20 /* thread is on the pauseQ */ michael@0: #define _PR_SUSPENDING 0x40 /* thread wants to suspend */ michael@0: #define _PR_GLOBAL_SCOPE 0x80 /* thread is global scope */ michael@0: #define _PR_IDLE_THREAD 0x200 /* this is an idle thread */ michael@0: #define _PR_GCABLE_THREAD 0x400 /* this is a collectable thread */ michael@0: #define _PR_BOUND_THREAD 0x800 /* a bound thread */ michael@0: #define _PR_INTERRUPT_BLOCKED 0x1000 /* interrupts blocked */ michael@0: michael@0: /* PRThread.state */ michael@0: #define _PR_UNBORN 0 michael@0: #define _PR_RUNNABLE 1 michael@0: #define _PR_RUNNING 2 michael@0: #define _PR_LOCK_WAIT 3 michael@0: #define _PR_COND_WAIT 4 michael@0: #define _PR_JOIN_WAIT 5 michael@0: #define _PR_IO_WAIT 6 michael@0: #define _PR_SUSPENDED 7 michael@0: #define _PR_DEAD_STATE 8 /* for debugging */ michael@0: michael@0: /* PRThreadStack.flags */ michael@0: #define _PR_STACK_VM 0x1 /* using vm instead of malloc */ michael@0: #define _PR_STACK_MAPPED 0x2 /* vm is mapped */ michael@0: #define _PR_STACK_PRIMORDIAL 0x4 /* stack for primordial thread */ michael@0: michael@0: /* michael@0: ** If the default stcksize from the client is zero, we need to pick a machine michael@0: ** dependent value. This is only for standard user threads. For custom threads, michael@0: ** 0 has a special meaning. michael@0: ** Adjust stackSize. Round up to a page boundary. michael@0: */ michael@0: michael@0: #ifndef _MD_MINIMUM_STACK_SIZE michael@0: #define _MD_MINIMUM_STACK_SIZE 0 michael@0: #endif michael@0: michael@0: #if (!defined(HAVE_CUSTOM_USER_THREADS)) michael@0: #define _PR_ADJUST_STACKSIZE(stackSize) \ michael@0: PR_BEGIN_MACRO \ michael@0: if (stackSize == 0) \ michael@0: stackSize = _MD_DEFAULT_STACK_SIZE; \ michael@0: if (stackSize < _MD_MINIMUM_STACK_SIZE) \ michael@0: stackSize = _MD_MINIMUM_STACK_SIZE; \ michael@0: stackSize = (stackSize + (1 << _pr_pageShift) - 1) >> _pr_pageShift; \ michael@0: stackSize <<= _pr_pageShift; \ michael@0: PR_END_MACRO michael@0: #else michael@0: #define _PR_ADJUST_STACKSIZE(stackSize) michael@0: #endif michael@0: michael@0: #define _PR_IS_GCABLE_THREAD(thr) ((thr)->flags & _PR_GCABLE_THREAD) michael@0: michael@0: #define _PR_PENDING_INTERRUPT(thr) \ michael@0: (!((thr)->flags & _PR_INTERRUPT_BLOCKED) && ((thr)->flags & _PR_INTERRUPT)) michael@0: #define _PR_THREAD_BLOCK_INTERRUPT(thr) \ michael@0: (thr->flags |= _PR_INTERRUPT_BLOCKED) michael@0: #define _PR_THREAD_UNBLOCK_INTERRUPT(thr) \ michael@0: (thr->flags &= ~_PR_INTERRUPT_BLOCKED) michael@0: michael@0: #define _PR_THREAD_PTR(_qp) \ michael@0: ((PRThread*) ((char*) (_qp) - offsetof(PRThread,links))) michael@0: michael@0: #define _PR_ACTIVE_THREAD_PTR(_qp) \ michael@0: ((PRThread*) ((char*) (_qp) - offsetof(PRThread,active))) michael@0: michael@0: #define _PR_THREAD_CONDQ_PTR(_qp) \ michael@0: ((PRThread*) ((char*) (_qp) - offsetof(PRThread,waitQLinks))) michael@0: michael@0: #define _PR_THREAD_MD_TO_PTR(_md) \ michael@0: ((PRThread*) ((char*) (_md) - offsetof(PRThread,md))) michael@0: michael@0: #define _PR_THREAD_STACK_TO_PTR(_stack) \ michael@0: ((PRThread*) (_stack->thr)) michael@0: michael@0: extern PRCList _pr_active_local_threadQ; michael@0: extern PRCList _pr_active_global_threadQ; michael@0: extern PRCList _pr_cpuQ; michael@0: extern _MDLock _pr_cpuLock; michael@0: extern PRInt32 _pr_md_idle_cpus; michael@0: michael@0: #define _PR_ACTIVE_LOCAL_THREADQ() _pr_active_local_threadQ michael@0: #define _PR_ACTIVE_GLOBAL_THREADQ() _pr_active_global_threadQ michael@0: #define _PR_CPUQ() _pr_cpuQ michael@0: #define _PR_RUNQ(_cpu) ((_cpu)->queue->runQ) michael@0: #define _PR_RUNQREADYMASK(_cpu) ((_cpu)->queue->runQReadyMask) michael@0: #define _PR_SLEEPQ(_cpu) ((_cpu)->queue->sleepQ) michael@0: #define _PR_SLEEPQMAX(_cpu) ((_cpu)->queue->sleepQmax) michael@0: #define _PR_PAUSEQ(_cpu) ((_cpu)->queue->pauseQ) michael@0: #define _PR_SUSPENDQ(_cpu) ((_cpu)->queue->suspendQ) michael@0: #define _PR_WAITINGTOJOINQ(_cpu) ((_cpu)->queue->waitingToJoinQ) michael@0: michael@0: extern PRUint32 _pr_recycleThreads; /* Flag for behavior on thread cleanup */ michael@0: extern PRLock *_pr_deadQLock; michael@0: extern PRUint32 _pr_numNativeDead; michael@0: extern PRUint32 _pr_numUserDead; michael@0: extern PRCList _pr_deadNativeQ; michael@0: extern PRCList _pr_deadUserQ; michael@0: #define _PR_DEADNATIVEQ _pr_deadNativeQ michael@0: #define _PR_DEADUSERQ _pr_deadUserQ michael@0: #define _PR_DEADQ_LOCK PR_Lock(_pr_deadQLock); michael@0: #define _PR_DEADQ_UNLOCK PR_Unlock(_pr_deadQLock); michael@0: #define _PR_INC_DEADNATIVE (_pr_numNativeDead++) michael@0: #define _PR_DEC_DEADNATIVE (_pr_numNativeDead--) michael@0: #define _PR_NUM_DEADNATIVE (_pr_numNativeDead) michael@0: #define _PR_INC_DEADUSER (_pr_numUserDead++) michael@0: #define _PR_DEC_DEADUSER (_pr_numUserDead--) michael@0: #define _PR_NUM_DEADUSER (_pr_numUserDead) michael@0: michael@0: extern PRUint32 _pr_utid; michael@0: michael@0: extern struct _PRCPU *_pr_primordialCPU; michael@0: michael@0: extern PRLock *_pr_activeLock; /* lock for userActive and systemActive */ michael@0: extern PRInt32 _pr_userActive; /* number of active user threads */ michael@0: extern PRInt32 _pr_systemActive; /* number of active system threads */ michael@0: extern PRInt32 _pr_primordialExitCount; /* number of user threads left michael@0: * before the primordial thread michael@0: * can exit. */ michael@0: extern PRCondVar *_pr_primordialExitCVar; /* the condition variable for michael@0: * notifying the primordial thread michael@0: * when all other user threads michael@0: * have terminated. */ michael@0: michael@0: extern PRUintn _pr_maxPTDs; michael@0: michael@0: extern PRLock *_pr_terminationCVLock; michael@0: michael@0: /************************************************************************* michael@0: * Internal routines either called by PR itself or from machine-dependent * michael@0: * code. * michael@0: *************************************************************************/ michael@0: michael@0: extern void _PR_ClockInterrupt(void); michael@0: michael@0: extern void _PR_Schedule(void); michael@0: extern void _PR_SetThreadPriority( michael@0: PRThread* thread, PRThreadPriority priority); michael@0: michael@0: /*********************************************************************** michael@0: ** FUNCTION: _PR_NewSegment() michael@0: ** DESCRIPTION: michael@0: ** Allocate a memory segment. The "size" value is rounded up to the michael@0: ** native system page size and a page aligned portion of memory is michael@0: ** returned. This memory is not part of the malloc heap. If "vaddr" is michael@0: ** not NULL then PR tries to allocate the segment at the desired virtual michael@0: ** address. michael@0: ** INPUTS: size: size of the desired memory segment michael@0: ** vaddr: address at which the newly aquired segment is to be michael@0: ** mapped into memory. michael@0: ** OUTPUTS: a memory segment is allocated, a PRSegment is allocated michael@0: ** RETURN: pointer to PRSegment michael@0: ***********************************************************************/ michael@0: extern PRSegment* _PR_NewSegment(PRUint32 size, void *vaddr); michael@0: michael@0: /*********************************************************************** michael@0: ** FUNCTION: _PR_DestroySegment() michael@0: ** DESCRIPTION: michael@0: ** The memory segment and the PRSegment are freed michael@0: ** INPUTS: seg: pointer to PRSegment to be freed michael@0: ** OUTPUTS: the the PRSegment and its associated memory segment are freed michael@0: ** RETURN: void michael@0: ***********************************************************************/ michael@0: extern void _PR_DestroySegment(PRSegment *seg); michael@0: michael@0: extern PRThreadStack * _PR_NewStack(PRUint32 stackSize); michael@0: extern void _PR_FreeStack(PRThreadStack *stack); michael@0: extern PRBool _PR_NotifyThread (PRThread *thread, PRThread *me); michael@0: extern void _PR_NotifyLockedThread (PRThread *thread); michael@0: michael@0: NSPR_API(void) _PR_AddSleepQ(PRThread *thread, PRIntervalTime timeout); michael@0: NSPR_API(void) _PR_DelSleepQ(PRThread *thread, PRBool propogate_time); michael@0: michael@0: extern void _PR_AddThreadToRunQ(PRThread *me, PRThread *thread); michael@0: michael@0: NSPR_API(PRThread*) _PR_CreateThread(PRThreadType type, michael@0: void (*start)(void *arg), michael@0: void *arg, michael@0: PRThreadPriority priority, michael@0: PRThreadScope scope, michael@0: PRThreadState state, michael@0: PRUint32 stackSize, michael@0: PRUint32 flags); michael@0: michael@0: extern void _PR_NativeDestroyThread(PRThread *thread); michael@0: extern void _PR_UserDestroyThread(PRThread *thread); michael@0: michael@0: extern PRThread* _PRI_AttachThread( michael@0: PRThreadType type, PRThreadPriority priority, michael@0: PRThreadStack *stack, PRUint32 flags); michael@0: michael@0: extern void _PRI_DetachThread(void); michael@0: michael@0: michael@0: #define _PR_IO_PENDING(_thread) ((_thread)->io_pending) michael@0: michael@0: NSPR_API(void) _PR_MD_INIT_CPUS(); michael@0: #define _PR_MD_INIT_CPUS _MD_INIT_CPUS michael@0: michael@0: NSPR_API(void) _PR_MD_WAKEUP_CPUS(); michael@0: #define _PR_MD_WAKEUP_CPUS _MD_WAKEUP_CPUS michael@0: michael@0: /* Interrupts related */ michael@0: michael@0: NSPR_API(void) _PR_MD_START_INTERRUPTS(void); michael@0: #define _PR_MD_START_INTERRUPTS _MD_START_INTERRUPTS michael@0: michael@0: NSPR_API(void) _PR_MD_STOP_INTERRUPTS(void); michael@0: #define _PR_MD_STOP_INTERRUPTS _MD_STOP_INTERRUPTS michael@0: michael@0: NSPR_API(void) _PR_MD_ENABLE_CLOCK_INTERRUPTS(void); michael@0: #define _PR_MD_ENABLE_CLOCK_INTERRUPTS _MD_ENABLE_CLOCK_INTERRUPTS michael@0: michael@0: NSPR_API(void) _PR_MD_DISABLE_CLOCK_INTERRUPTS(void); michael@0: #define _PR_MD_DISABLE_CLOCK_INTERRUPTS _MD_DISABLE_CLOCK_INTERRUPTS michael@0: michael@0: NSPR_API(void) _PR_MD_BLOCK_CLOCK_INTERRUPTS(void); michael@0: #define _PR_MD_BLOCK_CLOCK_INTERRUPTS _MD_BLOCK_CLOCK_INTERRUPTS michael@0: michael@0: NSPR_API(void) _PR_MD_UNBLOCK_CLOCK_INTERRUPTS(void); michael@0: #define _PR_MD_UNBLOCK_CLOCK_INTERRUPTS _MD_UNBLOCK_CLOCK_INTERRUPTS michael@0: michael@0: /* The _PR_MD_WAIT_LOCK and _PR_MD_WAKEUP_WAITER functions put to sleep and michael@0: * awaken a thread which is waiting on a lock or cvar. michael@0: */ michael@0: extern PRStatus _PR_MD_WAIT(PRThread *, PRIntervalTime timeout); michael@0: #define _PR_MD_WAIT _MD_WAIT michael@0: michael@0: extern PRStatus _PR_MD_WAKEUP_WAITER(PRThread *); michael@0: #define _PR_MD_WAKEUP_WAITER _MD_WAKEUP_WAITER michael@0: michael@0: #ifndef _PR_LOCAL_THREADS_ONLY /* not if only local threads supported */ michael@0: NSPR_API(void) _PR_MD_CLOCK_INTERRUPT(void); michael@0: #define _PR_MD_CLOCK_INTERRUPT _MD_CLOCK_INTERRUPT michael@0: #endif michael@0: michael@0: /* Stack debugging */ michael@0: NSPR_API(void) _PR_MD_INIT_STACK(PRThreadStack *ts, PRIntn redzone); michael@0: #define _PR_MD_INIT_STACK _MD_INIT_STACK michael@0: michael@0: NSPR_API(void) _PR_MD_CLEAR_STACK(PRThreadStack* ts); michael@0: #define _PR_MD_CLEAR_STACK _MD_CLEAR_STACK michael@0: michael@0: /* CPU related */ michael@0: NSPR_API(PRInt32) _PR_MD_GET_INTSOFF(void); michael@0: #define _PR_MD_GET_INTSOFF _MD_GET_INTSOFF michael@0: michael@0: NSPR_API(void) _PR_MD_SET_INTSOFF(PRInt32 _val); michael@0: #define _PR_MD_SET_INTSOFF _MD_SET_INTSOFF michael@0: michael@0: NSPR_API(_PRCPU*) _PR_MD_CURRENT_CPU(void); michael@0: #define _PR_MD_CURRENT_CPU _MD_CURRENT_CPU michael@0: michael@0: NSPR_API(void) _PR_MD_SET_CURRENT_CPU(_PRCPU *cpu); michael@0: #define _PR_MD_SET_CURRENT_CPU _MD_SET_CURRENT_CPU michael@0: michael@0: NSPR_API(void) _PR_MD_INIT_RUNNING_CPU(_PRCPU *cpu); michael@0: #define _PR_MD_INIT_RUNNING_CPU _MD_INIT_RUNNING_CPU michael@0: michael@0: /* michael@0: * Returns the number of threads awoken or 0 if a timeout occurred; michael@0: */ michael@0: extern PRInt32 _PR_MD_PAUSE_CPU(PRIntervalTime timeout); michael@0: #define _PR_MD_PAUSE_CPU _MD_PAUSE_CPU michael@0: michael@0: extern void _PR_MD_CLEANUP_BEFORE_EXIT(void); michael@0: #define _PR_MD_CLEANUP_BEFORE_EXIT _MD_CLEANUP_BEFORE_EXIT michael@0: michael@0: extern void _PR_MD_EXIT(PRIntn status); michael@0: #define _PR_MD_EXIT _MD_EXIT michael@0: michael@0: /* Locks related */ michael@0: michael@0: NSPR_API(void) _PR_MD_INIT_LOCKS(void); michael@0: #define _PR_MD_INIT_LOCKS _MD_INIT_LOCKS michael@0: michael@0: NSPR_API(PRStatus) _PR_MD_NEW_LOCK(_MDLock *md); michael@0: #define _PR_MD_NEW_LOCK _MD_NEW_LOCK michael@0: michael@0: NSPR_API(void) _PR_MD_FREE_LOCK(_MDLock *md); michael@0: #define _PR_MD_FREE_LOCK _MD_FREE_LOCK michael@0: michael@0: NSPR_API(void) _PR_MD_LOCK(_MDLock *md); michael@0: #define _PR_MD_LOCK _MD_LOCK michael@0: michael@0: /* Return 0 on success, a nonzero value on failure. */ michael@0: NSPR_API(PRIntn) _PR_MD_TEST_AND_LOCK(_MDLock *md); michael@0: #define _PR_MD_TEST_AND_LOCK _MD_TEST_AND_LOCK michael@0: michael@0: NSPR_API(void) _PR_MD_UNLOCK(_MDLock *md); michael@0: #define _PR_MD_UNLOCK _MD_UNLOCK michael@0: michael@0: NSPR_API(void) _PR_MD_IOQ_LOCK(void); michael@0: #define _PR_MD_IOQ_LOCK _MD_IOQ_LOCK michael@0: michael@0: NSPR_API(void) _PR_MD_IOQ_UNLOCK(void); michael@0: #define _PR_MD_IOQ_UNLOCK _MD_IOQ_UNLOCK michael@0: michael@0: #ifndef _PR_LOCAL_THREADS_ONLY /* not if only local threads supported */ michael@0: /* Semaphore related -- only for native threads */ michael@0: #ifdef HAVE_CVAR_BUILT_ON_SEM michael@0: NSPR_API(void) _PR_MD_NEW_SEM(_MDSemaphore *md, PRUintn value); michael@0: #define _PR_MD_NEW_SEM _MD_NEW_SEM michael@0: michael@0: NSPR_API(void) _PR_MD_DESTROY_SEM(_MDSemaphore *md); michael@0: #define _PR_MD_DESTROY_SEM _MD_DESTROY_SEM michael@0: michael@0: NSPR_API(PRStatus) _PR_MD_TIMED_WAIT_SEM( michael@0: _MDSemaphore *md, PRIntervalTime timeout); michael@0: #define _PR_MD_TIMED_WAIT_SEM _MD_TIMED_WAIT_SEM michael@0: michael@0: NSPR_API(PRStatus) _PR_MD_WAIT_SEM(_MDSemaphore *md); michael@0: #define _PR_MD_WAIT_SEM _MD_WAIT_SEM michael@0: michael@0: NSPR_API(void) _PR_MD_POST_SEM(_MDSemaphore *md); michael@0: #define _PR_MD_POST_SEM _MD_POST_SEM michael@0: #endif /* HAVE_CVAR_BUILT_ON_SEM */ michael@0: michael@0: #endif michael@0: michael@0: /* Condition Variables related -- only for native threads */ michael@0: michael@0: #ifndef _PR_LOCAL_THREADS_ONLY /* not if only local threads supported */ michael@0: NSPR_API(PRInt32) _PR_MD_NEW_CV(_MDCVar *md); michael@0: #define _PR_MD_NEW_CV _MD_NEW_CV michael@0: michael@0: NSPR_API(void) _PR_MD_FREE_CV(_MDCVar *md); michael@0: #define _PR_MD_FREE_CV _MD_FREE_CV michael@0: michael@0: NSPR_API(void) _PR_MD_WAIT_CV( michael@0: _MDCVar *mdCVar,_MDLock *mdLock,PRIntervalTime timeout); michael@0: #define _PR_MD_WAIT_CV _MD_WAIT_CV michael@0: michael@0: NSPR_API(void) _PR_MD_NOTIFY_CV(_MDCVar *md, _MDLock *lock); michael@0: #define _PR_MD_NOTIFY_CV _MD_NOTIFY_CV michael@0: michael@0: NSPR_API(void) _PR_MD_NOTIFYALL_CV(_MDCVar *md, _MDLock *lock); michael@0: #define _PR_MD_NOTIFYALL_CV _MD_NOTIFYALL_CV michael@0: #endif /* _PR_LOCAL_THREADS_ONLY */ michael@0: michael@0: /* Threads related */ michael@0: NSPR_API(PRThread*) _PR_MD_CURRENT_THREAD(void); michael@0: #define _PR_MD_CURRENT_THREAD _MD_CURRENT_THREAD michael@0: michael@0: NSPR_API(PRThread*) _PR_MD_GET_ATTACHED_THREAD(void); michael@0: #define _PR_MD_GET_ATTACHED_THREAD _MD_GET_ATTACHED_THREAD michael@0: michael@0: NSPR_API(PRThread*) _PR_MD_LAST_THREAD(void); michael@0: #define _PR_MD_LAST_THREAD _MD_LAST_THREAD michael@0: michael@0: NSPR_API(void) _PR_MD_SET_CURRENT_THREAD(PRThread *thread); michael@0: #define _PR_MD_SET_CURRENT_THREAD _MD_SET_CURRENT_THREAD michael@0: michael@0: NSPR_API(void) _PR_MD_SET_LAST_THREAD(PRThread *thread); michael@0: #define _PR_MD_SET_LAST_THREAD _MD_SET_LAST_THREAD michael@0: michael@0: extern PRStatus _PR_MD_INIT_THREAD(PRThread *thread); michael@0: #define _PR_MD_INIT_THREAD _MD_INIT_THREAD michael@0: michael@0: extern void _PR_MD_EXIT_THREAD(PRThread *thread); michael@0: #define _PR_MD_EXIT_THREAD _MD_EXIT_THREAD michael@0: michael@0: #ifndef _PR_LOCAL_THREADS_ONLY /* not if only local threads supported */ michael@0: michael@0: NSPR_API(PRStatus) _PR_MD_INIT_ATTACHED_THREAD(PRThread *thread); michael@0: #define _PR_MD_INIT_ATTACHED_THREAD _MD_INIT_ATTACHED_THREAD michael@0: michael@0: extern void _PR_MD_SUSPEND_THREAD(PRThread *thread); michael@0: #define _PR_MD_SUSPEND_THREAD _MD_SUSPEND_THREAD michael@0: michael@0: extern void _PR_MD_RESUME_THREAD(PRThread *thread); michael@0: #define _PR_MD_RESUME_THREAD _MD_RESUME_THREAD michael@0: michael@0: extern void _PR_MD_SUSPEND_CPU(_PRCPU *cpu); michael@0: #define _PR_MD_SUSPEND_CPU _MD_SUSPEND_CPU michael@0: michael@0: extern void _PR_MD_RESUME_CPU(_PRCPU *cpu); michael@0: #define _PR_MD_RESUME_CPU _MD_RESUME_CPU michael@0: michael@0: extern void _PR_MD_BEGIN_SUSPEND_ALL(void); michael@0: #define _PR_MD_BEGIN_SUSPEND_ALL _MD_BEGIN_SUSPEND_ALL michael@0: michael@0: extern void _PR_MD_END_SUSPEND_ALL(void); michael@0: #define _PR_MD_END_SUSPEND_ALL _MD_END_SUSPEND_ALL michael@0: michael@0: extern void _PR_MD_BEGIN_RESUME_ALL(void); michael@0: #define _PR_MD_BEGIN_RESUME_ALL _MD_BEGIN_RESUME_ALL michael@0: michael@0: extern void _PR_MD_END_RESUME_ALL(void); michael@0: #define _PR_MD_END_RESUME_ALL _MD_END_RESUME_ALL michael@0: michael@0: #if defined(IRIX) michael@0: NSPR_API(void) _PR_IRIX_CHILD_PROCESS(void); michael@0: #endif /* IRIX */ michael@0: michael@0: #endif /* !_PR_LOCAL_THREADS_ONLY */ michael@0: michael@0: extern void _PR_MD_CLEAN_THREAD(PRThread *thread); michael@0: #define _PR_MD_CLEAN_THREAD _MD_CLEAN_THREAD michael@0: michael@0: #ifdef HAVE_CUSTOM_USER_THREADS michael@0: extern void _PR_MD_CREATE_PRIMORDIAL_USER_THREAD(PRThread *); michael@0: #define _PR_MD_CREATE_PRIMORDIAL_USER_THREAD _MD_CREATE_PRIMORDIAL_USER_THREAD michael@0: michael@0: extern PRThread* _PR_MD_CREATE_USER_THREAD( michael@0: PRUint32 stacksize, michael@0: void (*start)(void *), michael@0: void *arg); michael@0: #define _PR_MD_CREATE_USER_THREAD _MD_CREATE_USER_THREAD michael@0: #endif michael@0: michael@0: extern PRStatus _PR_MD_CREATE_THREAD( michael@0: PRThread *thread, michael@0: void (*start) (void *), michael@0: PRThreadPriority priority, michael@0: PRThreadScope scope, michael@0: PRThreadState state, michael@0: PRUint32 stackSize); michael@0: #define _PR_MD_CREATE_THREAD _MD_CREATE_THREAD michael@0: michael@0: extern void _PR_MD_JOIN_THREAD(_MDThread *md); michael@0: #define _PR_MD_JOIN_THREAD _MD_JOIN_THREAD michael@0: michael@0: extern void _PR_MD_END_THREAD(void); michael@0: #define _PR_MD_END_THREAD _MD_END_THREAD michael@0: michael@0: extern void _PR_MD_YIELD(void); michael@0: #define _PR_MD_YIELD _MD_YIELD michael@0: michael@0: extern void _PR_MD_SET_PRIORITY(_MDThread *md, PRThreadPriority newPri); michael@0: #define _PR_MD_SET_PRIORITY _MD_SET_PRIORITY michael@0: michael@0: extern void _PR_MD_SET_CURRENT_THREAD_NAME(const char *name); michael@0: #define _PR_MD_SET_CURRENT_THREAD_NAME _MD_SET_CURRENT_THREAD_NAME michael@0: michael@0: NSPR_API(void) _PR_MD_SUSPENDALL(void); michael@0: #define _PR_MD_SUSPENDALL _MD_SUSPENDALL michael@0: michael@0: NSPR_API(void) _PR_MD_RESUMEALL(void); michael@0: #define _PR_MD_RESUMEALL _MD_RESUMEALL michael@0: michael@0: extern void _PR_MD_INIT_CONTEXT( michael@0: PRThread *thread, char *top, void (*start) (void), PRBool *status); michael@0: #define _PR_MD_INIT_CONTEXT _MD_INIT_CONTEXT michael@0: michael@0: extern void _PR_MD_SWITCH_CONTEXT(PRThread *thread); michael@0: #define _PR_MD_SWITCH_CONTEXT _MD_SWITCH_CONTEXT michael@0: michael@0: extern void _PR_MD_RESTORE_CONTEXT(PRThread *thread); michael@0: #define _PR_MD_RESTORE_CONTEXT _MD_RESTORE_CONTEXT michael@0: michael@0: /* Segment related */ michael@0: extern void _PR_MD_INIT_SEGS(void); michael@0: #define _PR_MD_INIT_SEGS _MD_INIT_SEGS michael@0: michael@0: extern PRStatus _PR_MD_ALLOC_SEGMENT(PRSegment *seg, PRUint32 size, void *vaddr); michael@0: #define _PR_MD_ALLOC_SEGMENT _MD_ALLOC_SEGMENT michael@0: michael@0: extern void _PR_MD_FREE_SEGMENT(PRSegment *seg); michael@0: #define _PR_MD_FREE_SEGMENT _MD_FREE_SEGMENT michael@0: michael@0: /* Directory enumeration related */ michael@0: extern PRStatus _PR_MD_OPEN_DIR(_MDDir *md,const char *name); michael@0: #define _PR_MD_OPEN_DIR _MD_OPEN_DIR michael@0: michael@0: extern char * _PR_MD_READ_DIR(_MDDir *md, PRIntn flags); michael@0: #define _PR_MD_READ_DIR _MD_READ_DIR michael@0: michael@0: extern PRInt32 _PR_MD_CLOSE_DIR(_MDDir *md); michael@0: #define _PR_MD_CLOSE_DIR _MD_CLOSE_DIR michael@0: michael@0: /* Named semaphores related */ michael@0: extern PRSem * _PR_MD_OPEN_SEMAPHORE( michael@0: const char *osname, PRIntn flags, PRIntn mode, PRUintn value); michael@0: #define _PR_MD_OPEN_SEMAPHORE _MD_OPEN_SEMAPHORE michael@0: michael@0: extern PRStatus _PR_MD_WAIT_SEMAPHORE(PRSem *sem); michael@0: #define _PR_MD_WAIT_SEMAPHORE _MD_WAIT_SEMAPHORE michael@0: michael@0: extern PRStatus _PR_MD_POST_SEMAPHORE(PRSem *sem); michael@0: #define _PR_MD_POST_SEMAPHORE _MD_POST_SEMAPHORE michael@0: michael@0: extern PRStatus _PR_MD_CLOSE_SEMAPHORE(PRSem *sem); michael@0: #define _PR_MD_CLOSE_SEMAPHORE _MD_CLOSE_SEMAPHORE michael@0: michael@0: extern PRStatus _PR_MD_DELETE_SEMAPHORE(const char *osname); michael@0: #define _PR_MD_DELETE_SEMAPHORE _MD_DELETE_SEMAPHORE michael@0: michael@0: /* I/O related */ michael@0: extern void _PR_MD_INIT_FILEDESC(PRFileDesc *fd); michael@0: #define _PR_MD_INIT_FILEDESC _MD_INIT_FILEDESC michael@0: michael@0: extern void _PR_MD_MAKE_NONBLOCK(PRFileDesc *fd); michael@0: #define _PR_MD_MAKE_NONBLOCK _MD_MAKE_NONBLOCK michael@0: michael@0: /* File I/O related */ michael@0: extern PROsfd _PR_MD_OPEN(const char *name, PRIntn osflags, PRIntn mode); michael@0: #define _PR_MD_OPEN _MD_OPEN michael@0: michael@0: extern PROsfd _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, PRIntn mode); michael@0: #define _PR_MD_OPEN_FILE _MD_OPEN_FILE michael@0: michael@0: extern PRInt32 _PR_MD_CLOSE_FILE(PROsfd osfd); michael@0: #define _PR_MD_CLOSE_FILE _MD_CLOSE_FILE michael@0: michael@0: extern PRInt32 _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 amount); michael@0: #define _PR_MD_READ _MD_READ michael@0: michael@0: extern PRInt32 _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 amount); michael@0: #define _PR_MD_WRITE _MD_WRITE michael@0: michael@0: extern PRInt32 _PR_MD_WRITEV( michael@0: PRFileDesc *fd, const struct PRIOVec *iov, michael@0: PRInt32 iov_size, PRIntervalTime timeout); michael@0: #define _PR_MD_WRITEV _MD_WRITEV michael@0: michael@0: extern PRInt32 _PR_MD_FSYNC(PRFileDesc *fd); michael@0: #define _PR_MD_FSYNC _MD_FSYNC michael@0: michael@0: extern PRInt32 _PR_MD_DELETE(const char *name); michael@0: #define _PR_MD_DELETE _MD_DELETE michael@0: michael@0: extern PRInt32 _PR_MD_RENAME(const char *from, const char *to); michael@0: #define _PR_MD_RENAME _MD_RENAME michael@0: michael@0: extern PRInt32 _PR_MD_ACCESS(const char *name, PRAccessHow how); michael@0: #define _PR_MD_ACCESS _MD_ACCESS michael@0: michael@0: extern PRInt32 _PR_MD_STAT(const char *name, struct stat *buf); michael@0: #define _PR_MD_STAT _MD_STAT michael@0: michael@0: extern PRInt32 _PR_MD_MKDIR(const char *name, PRIntn mode); michael@0: #define _PR_MD_MKDIR _MD_MKDIR michael@0: michael@0: extern PRInt32 _PR_MD_MAKE_DIR(const char *name, PRIntn mode); michael@0: #define _PR_MD_MAKE_DIR _MD_MAKE_DIR michael@0: michael@0: extern PRInt32 _PR_MD_RMDIR(const char *name); michael@0: #define _PR_MD_RMDIR _MD_RMDIR michael@0: michael@0: #ifdef MOZ_UNICODE michael@0: /* UTF16 File I/O related */ michael@0: extern PRStatus _PR_MD_OPEN_DIR_UTF16(_MDDirUTF16 *md, const PRUnichar *name); michael@0: #define _PR_MD_OPEN_DIR_UTF16 _MD_OPEN_DIR_UTF16 michael@0: michael@0: extern PROsfd _PR_MD_OPEN_FILE_UTF16(const PRUnichar *name, PRIntn osflags, PRIntn mode); michael@0: #define _PR_MD_OPEN_FILE_UTF16 _MD_OPEN_FILE_UTF16 michael@0: michael@0: extern PRUnichar * _PR_MD_READ_DIR_UTF16(_MDDirUTF16 *md, PRIntn flags); michael@0: #define _PR_MD_READ_DIR_UTF16 _MD_READ_DIR_UTF16 michael@0: michael@0: extern PRInt32 _PR_MD_CLOSE_DIR_UTF16(_MDDirUTF16 *md); michael@0: #define _PR_MD_CLOSE_DIR_UTF16 _MD_CLOSE_DIR_UTF16 michael@0: michael@0: extern PRInt32 _PR_MD_GETFILEINFO64_UTF16(const PRUnichar *fn, PRFileInfo64 *info); michael@0: #define _PR_MD_GETFILEINFO64_UTF16 _MD_GETFILEINFO64_UTF16 michael@0: #endif /* MOZ_UNICODE */ michael@0: michael@0: /* Socket I/O related */ michael@0: extern void _PR_MD_INIT_IO(void); michael@0: #define _PR_MD_INIT_IO _MD_INIT_IO michael@0: michael@0: extern PRInt32 _PR_MD_CLOSE_SOCKET(PROsfd osfd); michael@0: #define _PR_MD_CLOSE_SOCKET _MD_CLOSE_SOCKET michael@0: michael@0: extern PRInt32 _PR_MD_CONNECT( michael@0: PRFileDesc *fd, const PRNetAddr *addr, michael@0: PRUint32 addrlen, PRIntervalTime timeout); michael@0: #define _PR_MD_CONNECT _MD_CONNECT michael@0: michael@0: extern PROsfd _PR_MD_ACCEPT( michael@0: PRFileDesc *fd, PRNetAddr *addr, michael@0: PRUint32 *addrlen, PRIntervalTime timeout); michael@0: #define _PR_MD_ACCEPT _MD_ACCEPT michael@0: michael@0: extern PRInt32 _PR_MD_BIND(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen); michael@0: #define _PR_MD_BIND _MD_BIND michael@0: michael@0: extern PRInt32 _PR_MD_LISTEN(PRFileDesc *fd, PRIntn backlog); michael@0: #define _PR_MD_LISTEN _MD_LISTEN michael@0: michael@0: extern PRInt32 _PR_MD_SHUTDOWN(PRFileDesc *fd, PRIntn how); michael@0: #define _PR_MD_SHUTDOWN _MD_SHUTDOWN michael@0: michael@0: extern PRInt32 _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, michael@0: PRIntn flags, PRIntervalTime timeout); michael@0: #define _PR_MD_RECV _MD_RECV michael@0: michael@0: extern PRInt32 _PR_MD_SEND( michael@0: PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, michael@0: PRIntervalTime timeout); michael@0: #define _PR_MD_SEND _MD_SEND michael@0: michael@0: extern PRInt32 _PR_MD_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, michael@0: PRNetAddr **raddr, void *buf, PRInt32 amount, michael@0: PRIntervalTime timeout); michael@0: #define _PR_MD_ACCEPT_READ _MD_ACCEPT_READ michael@0: michael@0: #ifdef WIN32 michael@0: extern PROsfd _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *addr, michael@0: PRUint32 *addrlen, PRIntervalTime timeout, michael@0: PRBool fast, michael@0: _PR_AcceptTimeoutCallback callback, michael@0: void *callbackArg); michael@0: michael@0: extern PRInt32 _PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, michael@0: PRNetAddr **raddr, void *buf, PRInt32 amount, michael@0: PRIntervalTime timeout, PRBool fast, michael@0: _PR_AcceptTimeoutCallback callback, michael@0: void *callbackArg); michael@0: michael@0: extern void _PR_MD_UPDATE_ACCEPT_CONTEXT(PROsfd s, PROsfd ls); michael@0: #define _PR_MD_UPDATE_ACCEPT_CONTEXT _MD_UPDATE_ACCEPT_CONTEXT michael@0: /* michael@0: * The NSPR epoch (00:00:00 1 Jan 1970 UTC) in FILETIME. michael@0: * We store the value in a PRTime variable for convenience. michael@0: * This constant is used by _PR_FileTimeToPRTime(). michael@0: * This is defined in ntmisc.c michael@0: */ michael@0: extern const PRTime _pr_filetime_offset; michael@0: #endif /* WIN32 */ michael@0: michael@0: extern PRInt32 _PR_MD_SENDFILE( michael@0: PRFileDesc *sock, PRSendFileData *sfd, michael@0: PRInt32 flags, PRIntervalTime timeout); michael@0: #define _PR_MD_SENDFILE _MD_SENDFILE michael@0: michael@0: extern PRStatus _PR_MD_GETSOCKNAME( michael@0: PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen); michael@0: #define _PR_MD_GETSOCKNAME _MD_GETSOCKNAME michael@0: michael@0: extern PRStatus _PR_MD_GETPEERNAME( michael@0: PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen); michael@0: #define _PR_MD_GETPEERNAME _MD_GETPEERNAME michael@0: michael@0: extern PRStatus _PR_MD_GETSOCKOPT( michael@0: PRFileDesc *fd, PRInt32 level, PRInt32 optname, char* optval, PRInt32* optlen); michael@0: #define _PR_MD_GETSOCKOPT _MD_GETSOCKOPT michael@0: michael@0: extern PRStatus _PR_MD_SETSOCKOPT( michael@0: PRFileDesc *fd, PRInt32 level, PRInt32 optname, michael@0: const char* optval, PRInt32 optlen); michael@0: #define _PR_MD_SETSOCKOPT _MD_SETSOCKOPT michael@0: michael@0: extern PRStatus PR_CALLBACK _PR_SocketGetSocketOption( michael@0: PRFileDesc *fd, PRSocketOptionData *data); michael@0: michael@0: extern PRStatus PR_CALLBACK _PR_SocketSetSocketOption( michael@0: PRFileDesc *fd, const PRSocketOptionData *data); michael@0: michael@0: extern PRInt32 _PR_MD_RECVFROM( michael@0: PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, michael@0: PRNetAddr *addr, PRUint32 *addrlen, PRIntervalTime timeout); michael@0: #define _PR_MD_RECVFROM _MD_RECVFROM michael@0: michael@0: extern PRInt32 _PR_MD_SENDTO( michael@0: PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, michael@0: const PRNetAddr *addr, PRUint32 addrlen, PRIntervalTime timeout); michael@0: #define _PR_MD_SENDTO _MD_SENDTO michael@0: michael@0: extern PRInt32 _PR_MD_SOCKETPAIR(int af, int type, int flags, PROsfd *osfd); michael@0: #define _PR_MD_SOCKETPAIR _MD_SOCKETPAIR michael@0: michael@0: extern PROsfd _PR_MD_SOCKET(int af, int type, int flags); michael@0: #define _PR_MD_SOCKET _MD_SOCKET michael@0: michael@0: extern PRInt32 _PR_MD_SOCKETAVAILABLE(PRFileDesc *fd); michael@0: #define _PR_MD_SOCKETAVAILABLE _MD_SOCKETAVAILABLE michael@0: michael@0: extern PRInt32 _PR_MD_PIPEAVAILABLE(PRFileDesc *fd); michael@0: #define _PR_MD_PIPEAVAILABLE _MD_PIPEAVAILABLE michael@0: michael@0: extern PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, michael@0: PRIntervalTime timeout); michael@0: #define _PR_MD_PR_POLL _MD_PR_POLL michael@0: michael@0: /* michael@0: * Initialize fd->secret->inheritable for a newly created fd. michael@0: * If 'imported' is false, the osfd (i.e., fd->secret->md.osfd) michael@0: * was created by NSPR and hence has the OS-dependent default michael@0: * inheritable attribute. If 'imported' is true, the osfd was michael@0: * not created by NSPR and hence a system call is required to michael@0: * query its inheritable attribute. Since we may never need to michael@0: * know the inheritable attribute of a fd, a platform may choose michael@0: * to initialize fd->secret->inheritable of an imported fd to michael@0: * _PR_TRI_UNKNOWN and only pay the cost of the system call michael@0: * (in _PR_MD_QUERY_FD_INHERITABLE) when necessary. michael@0: */ michael@0: extern void _PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported); michael@0: #define _PR_MD_INIT_FD_INHERITABLE _MD_INIT_FD_INHERITABLE michael@0: michael@0: extern PRStatus _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable); michael@0: #define _PR_MD_SET_FD_INHERITABLE _MD_SET_FD_INHERITABLE michael@0: michael@0: michael@0: #define _PR_PROCESS_TIMEOUT_INTERRUPT_ERRORS(me) \ michael@0: if (_PR_PENDING_INTERRUPT(me)) { \ michael@0: me->flags &= ~_PR_INTERRUPT; \ michael@0: PR_SetError( PR_PENDING_INTERRUPT_ERROR, 0); \ michael@0: } else { \ michael@0: PR_SetError(PR_IO_TIMEOUT_ERROR, 0); \ michael@0: } michael@0: michael@0: extern void *_PR_MD_GET_SP(PRThread *thread); michael@0: #define _PR_MD_GET_SP _MD_GET_SP michael@0: michael@0: #endif /* defined(_PR_PTHREADS) */ michael@0: michael@0: /************************************************************************/ michael@0: /************************************************************************* michael@0: ** The remainder of the definitions are shared by pthreads and the classic michael@0: ** NSPR code. These too may be conditionalized. michael@0: *************************************************************************/ michael@0: /************************************************************************/ michael@0: michael@0: extern PROffset32 _PR_MD_LSEEK(PRFileDesc *fd, PROffset32 offset, PRSeekWhence whence); michael@0: #define _PR_MD_LSEEK _MD_LSEEK michael@0: michael@0: extern PROffset64 _PR_MD_LSEEK64(PRFileDesc *fd, PROffset64 offset, PRSeekWhence whence); michael@0: #define _PR_MD_LSEEK64 _MD_LSEEK64 michael@0: michael@0: extern PRInt32 _PR_MD_GETFILEINFO(const char *fn, PRFileInfo *info); michael@0: #define _PR_MD_GETFILEINFO _MD_GETFILEINFO michael@0: michael@0: extern PRInt32 _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info); michael@0: #define _PR_MD_GETFILEINFO64 _MD_GETFILEINFO64 michael@0: michael@0: extern PRInt32 _PR_MD_GETOPENFILEINFO(const PRFileDesc *fd, PRFileInfo *info); michael@0: #define _PR_MD_GETOPENFILEINFO _MD_GETOPENFILEINFO michael@0: michael@0: extern PRInt32 _PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info); michael@0: #define _PR_MD_GETOPENFILEINFO64 _MD_GETOPENFILEINFO64 michael@0: michael@0: michael@0: /*****************************************************************************/ michael@0: /************************** File descriptor caching **************************/ michael@0: /*****************************************************************************/ michael@0: extern void _PR_InitFdCache(void); michael@0: extern void _PR_CleanupFdCache(void); michael@0: extern PRFileDesc *_PR_Getfd(void); michael@0: extern void _PR_Putfd(PRFileDesc *fd); michael@0: michael@0: /* michael@0: * These flags are used by NSPR temporarily in the poll michael@0: * descriptor's out_flags field to record the mapping of michael@0: * NSPR's poll flags to the system poll flags. michael@0: * michael@0: * If _PR_POLL_READ_SYS_WRITE bit is set, it means the michael@0: * PR_POLL_READ flag specified by the topmost layer is michael@0: * mapped to the WRITE flag at the system layer. Similarly michael@0: * for the other three _PR_POLL_XXX_SYS_YYY flags. It is michael@0: * assumed that the PR_POLL_EXCEPT flag doesn't get mapped michael@0: * to other flags. michael@0: */ michael@0: #define _PR_POLL_READ_SYS_READ 0x1 michael@0: #define _PR_POLL_READ_SYS_WRITE 0x2 michael@0: #define _PR_POLL_WRITE_SYS_READ 0x4 michael@0: #define _PR_POLL_WRITE_SYS_WRITE 0x8 michael@0: michael@0: /* michael@0: ** These methods are coerced into file descriptor methods table michael@0: ** when the intended service is inappropriate for the particular michael@0: ** type of file descriptor. michael@0: */ michael@0: extern PRIntn _PR_InvalidInt(void); michael@0: extern PRInt16 _PR_InvalidInt16(void); michael@0: extern PRInt64 _PR_InvalidInt64(void); michael@0: extern PRStatus _PR_InvalidStatus(void); michael@0: extern PRFileDesc *_PR_InvalidDesc(void); michael@0: michael@0: extern PRIOMethods _pr_faulty_methods; michael@0: michael@0: /* michael@0: ** The PR_NETADDR_SIZE macro can only be called on a PRNetAddr union michael@0: ** whose 'family' field is set. It returns the size of the union michael@0: ** member corresponding to the specified address family. michael@0: */ michael@0: michael@0: extern PRUintn _PR_NetAddrSize(const PRNetAddr* addr); michael@0: michael@0: #if defined(_PR_INET6) michael@0: michael@0: #define PR_NETADDR_SIZE(_addr) _PR_NetAddrSize(_addr) michael@0: michael@0: #elif defined(_PR_HAVE_MD_SOCKADDR_IN6) michael@0: michael@0: /* michael@0: ** Under the following conditions: michael@0: ** 1. _PR_INET6 is not defined; michael@0: ** 2. _PR_INET6_PROBE is defined; michael@0: ** 3. struct sockaddr_in6 has nonstandard fields at the end michael@0: ** (e.g., on Solaris 8), michael@0: ** (_addr)->ipv6 is smaller than struct sockaddr_in6, and michael@0: ** hence we can't pass sizeof((_addr)->ipv6) to socket michael@0: ** functions such as connect because they would fail with michael@0: ** EINVAL. michael@0: ** michael@0: ** To pass the correct socket address length to socket michael@0: ** functions, define the macro _PR_HAVE_MD_SOCKADDR_IN6 and michael@0: ** define struct _md_sockaddr_in6 to be isomorphic to michael@0: ** struct sockaddr_in6. michael@0: */ michael@0: michael@0: #if defined(XP_UNIX) || defined(XP_OS2) michael@0: #define PR_NETADDR_SIZE(_addr) \ michael@0: ((_addr)->raw.family == PR_AF_INET \ michael@0: ? sizeof((_addr)->inet) \ michael@0: : ((_addr)->raw.family == PR_AF_INET6 \ michael@0: ? sizeof(struct _md_sockaddr_in6) \ michael@0: : sizeof((_addr)->local))) michael@0: #else michael@0: #define PR_NETADDR_SIZE(_addr) \ michael@0: ((_addr)->raw.family == PR_AF_INET \ michael@0: ? sizeof((_addr)->inet) \ michael@0: : sizeof(struct _md_sockaddr_in6)) michael@0: #endif /* defined(XP_UNIX) */ michael@0: michael@0: #else michael@0: michael@0: #if defined(XP_UNIX) || defined(XP_OS2) michael@0: #define PR_NETADDR_SIZE(_addr) \ michael@0: ((_addr)->raw.family == PR_AF_INET \ michael@0: ? sizeof((_addr)->inet) \ michael@0: : ((_addr)->raw.family == PR_AF_INET6 \ michael@0: ? sizeof((_addr)->ipv6) \ michael@0: : sizeof((_addr)->local))) michael@0: #else michael@0: #define PR_NETADDR_SIZE(_addr) \ michael@0: ((_addr)->raw.family == PR_AF_INET \ michael@0: ? sizeof((_addr)->inet) \ michael@0: : sizeof((_addr)->ipv6)) michael@0: #endif /* defined(XP_UNIX) */ michael@0: michael@0: #endif /* defined(_PR_INET6) */ michael@0: michael@0: extern PRStatus _PR_MapOptionName( michael@0: PRSockOption optname, PRInt32 *level, PRInt32 *name); michael@0: extern void _PR_InitThreads( michael@0: PRThreadType type, PRThreadPriority priority, PRUintn maxPTDs); michael@0: michael@0: struct PRLock { michael@0: #if defined(_PR_PTHREADS) michael@0: pthread_mutex_t mutex; /* the underlying lock */ michael@0: _PT_Notified notified; /* array of conditions notified */ michael@0: PRBool locked; /* whether the mutex is locked */ michael@0: pthread_t owner; /* if locked, current lock owner */ michael@0: #elif defined(_PR_BTHREADS) michael@0: sem_id semaphoreID; /* the underlying lock */ michael@0: int32 benaphoreCount; /* number of people in lock */ michael@0: thread_id owner; /* current lock owner */ michael@0: #else /* not pthreads or Be threads */ michael@0: PRCList links; /* linkage for PRThread.lockList */ michael@0: struct PRThread *owner; /* current lock owner */ michael@0: PRCList waitQ; /* list of threads waiting for lock */ michael@0: PRThreadPriority priority; /* priority of lock */ michael@0: PRThreadPriority boostPriority; /* boosted priority of lock owner */ michael@0: _MDLock ilock; /* Internal Lock to protect user-level fields */ michael@0: #endif michael@0: }; michael@0: michael@0: struct PRCondVar { michael@0: PRLock *lock; /* associated lock that protects the condition */ michael@0: #if defined(_PR_PTHREADS) michael@0: pthread_cond_t cv; /* underlying pthreads condition */ michael@0: PRInt32 notify_pending; /* CV has destroy pending notification */ michael@0: #elif defined(_PR_BTHREADS) michael@0: sem_id sem; /* the underlying lock */ michael@0: sem_id handshakeSem; /* the lock for 'notify'-threads waiting for confirmation */ michael@0: sem_id signalSem; /* the lock for threads waiting for someone to notify */ michael@0: volatile int32 nw; /* the number waiting */ michael@0: volatile int32 ns; /* the number signalling */ michael@0: long signalBenCount; /* the number waiting on the underlying sem */ michael@0: #else /* not pthreads or Be threads */ michael@0: PRCList condQ; /* Condition variable wait Q */ michael@0: _MDLock ilock; /* Internal Lock to protect condQ */ michael@0: _MDCVar md; michael@0: #endif michael@0: }; michael@0: michael@0: /************************************************************************/ michael@0: michael@0: struct PRMonitor { michael@0: const char* name; /* monitor name for debugging */ michael@0: #if defined(_PR_PTHREADS) michael@0: pthread_mutex_t lock; /* lock is only held when accessing fields michael@0: * of the PRMonitor, instead of being held michael@0: * while the monitor is entered. The only michael@0: * exception is notifyTimes, which is michael@0: * protected by the monitor. */ michael@0: pthread_t owner; /* the owner of the monitor or invalid */ michael@0: pthread_cond_t entryCV; /* for threads waiting to enter the monitor */ michael@0: michael@0: pthread_cond_t waitCV; /* for threads waiting on the monitor */ michael@0: PRInt32 refCount; /* reference count, an atomic variable. michael@0: * PR_NewMonitor adds a reference to the michael@0: * newly created PRMonitor, and michael@0: * PR_DestroyMonitor releases that reference. michael@0: * PR_ExitMonitor adds a reference before michael@0: * unlocking the internal lock if it needs to michael@0: * signal entryCV, and releases the reference michael@0: * after signaling entryCV. */ michael@0: #else /* defined(_PR_PTHREADS) */ michael@0: PRLock lock; /* lock is only held when accessing fields michael@0: * of the PRMonitor, instead of being held michael@0: * while the monitor is entered. The only michael@0: * exception is notifyTimes, which is michael@0: * protected by the monitor. */ michael@0: PRThread *owner; /* the owner of the monitor or invalid */ michael@0: PRCondVar entryCV; /* for threads waiting to enter the monitor */ michael@0: michael@0: PRCondVar waitCV; /* for threads waiting on the monitor */ michael@0: #endif /* defined(_PR_PTHREADS) */ michael@0: PRUint32 entryCount; /* # of times re-entered */ michael@0: PRIntn notifyTimes; /* number of pending notifies for waitCV. michael@0: * The special value -1 means a broadcast michael@0: * (PR_NotifyAll). */ michael@0: }; michael@0: michael@0: /************************************************************************/ michael@0: michael@0: struct PRSemaphore { michael@0: #if defined(_PR_BTHREADS) michael@0: sem_id sem; michael@0: int32 benaphoreCount; michael@0: #else michael@0: PRCondVar *cvar; /* associated lock and condition variable queue */ michael@0: PRUintn count; /* the value of the counting semaphore */ michael@0: PRUint32 waiters; /* threads waiting on the semaphore */ michael@0: #if defined(_PR_PTHREADS) michael@0: #else /* defined(_PR_PTHREADS) */ michael@0: _MDSemaphore md; michael@0: #endif /* defined(_PR_PTHREADS) */ michael@0: #endif /* defined(_PR_BTHREADS) */ michael@0: }; michael@0: michael@0: /*************************************************************************/ michael@0: michael@0: struct PRSem { michael@0: #ifdef _PR_HAVE_POSIX_SEMAPHORES michael@0: sem_t *sem; michael@0: #elif defined(_PR_HAVE_SYSV_SEMAPHORES) michael@0: int semid; michael@0: #elif defined(WIN32) michael@0: HANDLE sem; michael@0: #else michael@0: PRInt8 notused; michael@0: #endif michael@0: }; michael@0: michael@0: /*************************************************************************/ michael@0: michael@0: struct PRStackStr { michael@0: /* head MUST be at offset 0; assembly language code relies on this */ michael@0: #if defined(AIX) michael@0: volatile PRStackElem prstk_head; michael@0: #else michael@0: PRStackElem prstk_head; michael@0: #endif michael@0: michael@0: PRLock *prstk_lock; michael@0: char *prstk_name; michael@0: }; michael@0: michael@0: /************************************************************************/ michael@0: michael@0: /* XXX this needs to be exported (sigh) */ michael@0: struct PRThreadStack { michael@0: PRCList links; michael@0: PRUintn flags; michael@0: michael@0: char *allocBase; /* base of stack's allocated memory */ michael@0: PRUint32 allocSize; /* size of stack's allocated memory */ michael@0: char *stackBottom; /* bottom of stack from C's point of view */ michael@0: char *stackTop; /* top of stack from C's point of view */ michael@0: PRUint32 stackSize; /* size of usable portion of the stack */ michael@0: michael@0: PRSegment *seg; michael@0: PRThread* thr; /* back pointer to thread owning this stack */ michael@0: michael@0: #if defined(_PR_PTHREADS) michael@0: #else /* defined(_PR_PTHREADS) */ michael@0: _MDThreadStack md; michael@0: #endif /* defined(_PR_PTHREADS) */ michael@0: }; michael@0: michael@0: extern void _PR_DestroyThreadPrivate(PRThread*); michael@0: michael@0: typedef void (PR_CALLBACK *_PRStartFn)(void *); michael@0: michael@0: struct PRThread { michael@0: PRUint32 state; /* thread's creation state */ michael@0: PRThreadPriority priority; /* apparent priority, loosly defined */ michael@0: michael@0: void *arg; /* argument to the client's entry point */ michael@0: _PRStartFn startFunc; /* the root of the client's thread */ michael@0: michael@0: PRThreadStack *stack; /* info about thread's stack (for GC) */ michael@0: void *environment; /* pointer to execution environment */ michael@0: michael@0: PRThreadDumpProc dump; /* dump thread info out */ michael@0: void *dumpArg; /* argument for the dump function */ michael@0: michael@0: /* michael@0: ** Per thread private data michael@0: */ michael@0: PRUint32 tpdLength; /* thread's current vector length */ michael@0: void **privateData; /* private data vector or NULL */ michael@0: PRErrorCode errorCode; /* current NSPR error code | zero */ michael@0: PRInt32 osErrorCode; /* mapping of errorCode | zero */ michael@0: PRIntn errorStringLength; /* textLength from last call to PR_SetErrorText() */ michael@0: PRInt32 errorStringSize; /* malloc()'d size of buffer | zero */ michael@0: char *errorString; /* current error string | NULL */ michael@0: char *name; /* thread's name */ michael@0: michael@0: #if defined(_PR_PTHREADS) michael@0: pthread_t id; /* pthread identifier for the thread */ michael@0: PRBool idSet; /* whether 'id' has been set. Protected by michael@0: * pt_book.ml. */ michael@0: #ifdef _PR_NICE_PRIORITY_SCHEDULING michael@0: pid_t tid; /* Linux-specific kernel thread ID */ michael@0: #endif michael@0: PRBool okToDelete; /* ok to delete the PRThread struct? */ michael@0: PRCondVar *waiting; /* where the thread is waiting | NULL */ michael@0: void *sp; /* recorded sp for garbage collection */ michael@0: PRThread *next, *prev; /* simple linked list of all threads */ michael@0: PRUint32 suspend; /* used to store suspend and resume flags */ michael@0: #ifdef PT_NO_SIGTIMEDWAIT michael@0: pthread_mutex_t suspendResumeMutex; michael@0: pthread_cond_t suspendResumeCV; michael@0: #endif michael@0: PRUint32 interrupt_blocked; /* interrupt blocked */ michael@0: struct pollfd *syspoll_list; /* Unix polling list used by PR_Poll */ michael@0: PRUint32 syspoll_count; /* number of elements in syspoll_list */ michael@0: #if defined(_PR_POLL_WITH_SELECT) michael@0: int *selectfd_list; /* Unix fd's that PR_Poll selects on */ michael@0: PRUint32 selectfd_count; /* number of elements in selectfd_list */ michael@0: #endif michael@0: #elif defined(_PR_BTHREADS) michael@0: PRUint32 flags; michael@0: _MDThread md; michael@0: PRBool io_pending; michael@0: PRInt32 io_fd; michael@0: PRBool io_suspended; michael@0: #else /* not pthreads or Be threads */ michael@0: _MDLock threadLock; /* Lock to protect thread state variables. michael@0: * Protects the following fields: michael@0: * state michael@0: * priority michael@0: * links michael@0: * wait michael@0: * cpu michael@0: */ michael@0: PRUint32 queueCount; michael@0: PRUint32 waitCount; michael@0: michael@0: PRCList active; /* on list of all active threads */ michael@0: PRCList links; michael@0: PRCList waitQLinks; /* when thread is PR_Wait'ing */ michael@0: PRCList lockList; /* list of locks currently holding */ michael@0: PRIntervalTime sleep; /* sleep time when thread is sleeping */ michael@0: struct _wait { michael@0: struct PRLock *lock; michael@0: struct PRCondVar *cvar; michael@0: } wait; michael@0: michael@0: PRUint32 id; michael@0: PRUint32 flags; michael@0: PRUint32 no_sched; /* Don't schedule the thread to run. michael@0: * This flag has relevance only when michael@0: * multiple NSPR CPUs are created. michael@0: * When a thread is de-scheduled, there michael@0: * is a narrow window of time in which michael@0: * the thread is put on the run queue michael@0: * but the scheduler is actually using michael@0: * the stack of this thread. It is safe michael@0: * to run this thread on a different CPU michael@0: * only when its stack is not in use on michael@0: * any other CPU. The no_sched flag is michael@0: * set during this interval to prevent michael@0: * the thread from being scheduled on a michael@0: * different CPU. michael@0: */ michael@0: michael@0: /* thread termination condition variable for join */ michael@0: PRCondVar *term; michael@0: michael@0: _PRCPU *cpu; /* cpu to which this thread is bound */ michael@0: PRUint32 threadAllocatedOnStack;/* boolean */ michael@0: michael@0: /* When an async IO is in progress and a second async IO cannot be michael@0: * initiated, the io_pending flag is set to true. Some platforms will michael@0: * not use the io_pending flag. If the io_pending flag is true, then michael@0: * io_fd is the OS-file descriptor on which IO is pending. michael@0: */ michael@0: PRBool io_pending; michael@0: PRInt32 io_fd; michael@0: michael@0: /* If a timeout occurs or if an outstanding IO is interrupted and the michael@0: * OS doesn't support a real cancellation (NT or MAC), then the michael@0: * io_suspended flag will be set to true. The thread will be resumed michael@0: * but may run into trouble issuing additional IOs until the io_pending michael@0: * flag can be cleared michael@0: */ michael@0: PRBool io_suspended; michael@0: michael@0: _MDThread md; michael@0: #endif michael@0: }; michael@0: michael@0: struct PRProcessAttr { michael@0: PRFileDesc *stdinFd; michael@0: PRFileDesc *stdoutFd; michael@0: PRFileDesc *stderrFd; michael@0: char *currentDirectory; michael@0: char *fdInheritBuffer; michael@0: PRSize fdInheritBufferSize; michael@0: PRSize fdInheritBufferUsed; michael@0: }; michael@0: michael@0: struct PRProcess { michael@0: _MDProcess md; michael@0: }; michael@0: michael@0: struct PRFileMap { michael@0: PRFileDesc *fd; michael@0: PRFileMapProtect prot; michael@0: _MDFileMap md; michael@0: }; michael@0: michael@0: /************************************************************************/ michael@0: michael@0: /* michael@0: ** File descriptors of the NSPR layer can be in one of the michael@0: ** following states (stored in the 'state' field of struct michael@0: ** PRFilePrivate): michael@0: ** - _PR_FILEDESC_OPEN: The OS fd is open. michael@0: ** - _PR_FILEDESC_CLOSED: The OS fd is closed. The PRFileDesc michael@0: ** is still open but is unusable. The only operation allowed michael@0: ** on the PRFileDesc is PR_Close(). michael@0: ** - _PR_FILEDESC_FREED: The OS fd is closed and the PRFileDesc michael@0: ** structure is freed. michael@0: */ michael@0: michael@0: #define _PR_FILEDESC_OPEN 0xaaaaaaaa /* 1010101... */ michael@0: #define _PR_FILEDESC_CLOSED 0x55555555 /* 0101010... */ michael@0: #define _PR_FILEDESC_FREED 0x11111111 michael@0: michael@0: /* michael@0: ** A boolean type with an additional "unknown" state michael@0: */ michael@0: michael@0: typedef enum { michael@0: _PR_TRI_TRUE = 1, michael@0: _PR_TRI_FALSE = 0, michael@0: _PR_TRI_UNKNOWN = -1 michael@0: } _PRTriStateBool; michael@0: michael@0: struct PRFilePrivate { michael@0: PRInt32 state; michael@0: PRBool nonblocking; michael@0: _PRTriStateBool inheritable; michael@0: PRFileDesc *next; michael@0: PRIntn lockCount; /* 0: not locked michael@0: * -1: a native lockfile call is in progress michael@0: * > 0: # times the file is locked */ michael@0: #ifdef _PR_HAVE_PEEK_BUFFER michael@0: char *peekBuffer; michael@0: PRInt32 peekBufSize; michael@0: PRInt32 peekBytes; michael@0: #endif michael@0: #if !defined(_PR_HAVE_O_APPEND) michael@0: PRBool appendMode; /* Some platforms don't have O_APPEND or its michael@0: * equivalent, so they have to seek to end of michael@0: * file on write if the file was opened in michael@0: * append mode. See Bugzilla 4090, 276330. */ michael@0: #endif michael@0: _MDFileDesc md; michael@0: #ifdef _PR_NEED_SECRET_AF michael@0: PRUint16 af; /* If the platform's implementation of accept() michael@0: * requires knowing the address family of the michael@0: * socket, we save the address family here. */ michael@0: #endif michael@0: }; michael@0: michael@0: #ifdef _WIN64 michael@0: #define PR_PRIdOSFD "lld" /* for printing PROsfd */ michael@0: #define PR_PRIxOSFD "llx" michael@0: #define PR_SCNdOSFD "lld" /* for scanning PROsfd */ michael@0: #define PR_SCNxOSFD "llx" michael@0: #else michael@0: #define PR_PRIdOSFD "ld" /* for printing PROsfd */ michael@0: #define PR_PRIxOSFD "lx" michael@0: #define PR_SCNdOSFD "ld" /* for scanning PROsfd */ michael@0: #define PR_SCNxOSFD "lx" michael@0: #endif michael@0: michael@0: struct PRDir { michael@0: PRDirEntry d; michael@0: _MDDir md; michael@0: }; michael@0: michael@0: #ifdef MOZ_UNICODE michael@0: struct PRDirUTF16 { michael@0: PRDirEntry d; michael@0: _MDDirUTF16 md; michael@0: }; michael@0: #endif /* MOZ_UNICODE */ michael@0: michael@0: extern void _PR_InitLocks(void); michael@0: extern void _PR_InitSegs(void); michael@0: extern void _PR_InitStacks(void); michael@0: extern void _PR_InitTPD(void); michael@0: extern void _PR_InitMem(void); michael@0: extern void _PR_InitEnv(void); michael@0: extern void _PR_InitCMon(void); michael@0: extern void _PR_InitIO(void); michael@0: extern void _PR_InitLog(void); michael@0: extern void _PR_InitNet(void); michael@0: extern void _PR_InitClock(void); michael@0: extern void _PR_InitLinker(void); michael@0: extern void _PR_InitAtomic(void); michael@0: extern void _PR_InitCPUs(void); michael@0: extern void _PR_InitDtoa(void); michael@0: extern void _PR_InitTime(void); michael@0: extern void _PR_InitMW(void); michael@0: extern void _PR_InitRWLocks(void); michael@0: extern void _PR_CleanupThread(PRThread *thread); michael@0: extern void _PR_CleanupCallOnce(void); michael@0: extern void _PR_CleanupMW(void); michael@0: extern void _PR_CleanupTime(void); michael@0: extern void _PR_CleanupDtoa(void); michael@0: extern void _PR_ShutdownLinker(void); michael@0: extern void _PR_CleanupEnv(void); michael@0: extern void _PR_CleanupIO(void); michael@0: extern void _PR_CleanupCMon(void); michael@0: extern void _PR_CleanupNet(void); michael@0: extern void _PR_CleanupLayerCache(void); michael@0: extern void _PR_CleanupStacks(void); michael@0: #ifdef WINNT michael@0: extern void _PR_CleanupCPUs(void); michael@0: #endif michael@0: extern void _PR_CleanupThreads(void); michael@0: extern void _PR_CleanupTPD(void); michael@0: extern void _PR_Cleanup(void); michael@0: extern void _PR_LogCleanup(void); michael@0: extern void _PR_InitLayerCache(void); michael@0: michael@0: extern PRBool _pr_initialized; michael@0: extern void _PR_ImplicitInitialization(void); michael@0: extern PRBool _PR_Obsolete(const char *obsolete, const char *preferred); michael@0: michael@0: /************************************************************************/ michael@0: michael@0: struct PRSegment { michael@0: void *vaddr; michael@0: PRUint32 size; michael@0: PRUintn flags; michael@0: #if defined(_PR_PTHREADS) michael@0: #else /* defined(_PR_PTHREADS) */ michael@0: _MDSegment md; michael@0: #endif /* defined(_PR_PTHREADS) */ michael@0: }; michael@0: michael@0: /* PRSegment.flags */ michael@0: #define _PR_SEG_VM 0x1 michael@0: michael@0: /************************************************************************/ michael@0: michael@0: extern PRInt32 _pr_pageSize; michael@0: extern PRInt32 _pr_pageShift; michael@0: michael@0: extern PRLogModuleInfo *_pr_clock_lm; michael@0: extern PRLogModuleInfo *_pr_cmon_lm; michael@0: extern PRLogModuleInfo *_pr_io_lm; michael@0: extern PRLogModuleInfo *_pr_cvar_lm; michael@0: extern PRLogModuleInfo *_pr_mon_lm; michael@0: extern PRLogModuleInfo *_pr_linker_lm; michael@0: extern PRLogModuleInfo *_pr_sched_lm; michael@0: extern PRLogModuleInfo *_pr_thread_lm; michael@0: extern PRLogModuleInfo *_pr_gc_lm; michael@0: michael@0: extern PRFileDesc *_pr_stdin; michael@0: extern PRFileDesc *_pr_stdout; michael@0: extern PRFileDesc *_pr_stderr; michael@0: michael@0: /* Zone allocator */ michael@0: /* michael@0: ** The zone allocator code has hardcoded pthread types and michael@0: ** functions, so it can only be used in the pthreads version. michael@0: ** This can be fixed by replacing the hardcoded pthread types michael@0: ** and functions with macros that expand to the native thread michael@0: ** types and functions on each platform. michael@0: */ michael@0: #if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) michael@0: #define _PR_ZONE_ALLOCATOR michael@0: #endif michael@0: michael@0: #ifdef _PR_ZONE_ALLOCATOR michael@0: extern void _PR_InitZones(void); michael@0: extern void _PR_DestroyZones(void); michael@0: #endif michael@0: michael@0: /* Overriding malloc, free, etc. */ michael@0: #if !defined(_PR_NO_PREEMPT) && defined(XP_UNIX) \ michael@0: && !defined(_PR_PTHREADS) && !defined(_PR_GLOBAL_THREADS_ONLY) \ michael@0: && !defined(PURIFY) \ michael@0: && !defined(DARWIN) \ michael@0: && !defined(QNX) \ michael@0: && !(defined (UNIXWARE) && defined (USE_SVR4_THREADS)) michael@0: #define _PR_OVERRIDE_MALLOC michael@0: #endif michael@0: michael@0: /************************************************************************* michael@0: * External machine-dependent code provided by each OS. * * michael@0: *************************************************************************/ michael@0: michael@0: /* Initialization related */ michael@0: extern void _PR_MD_EARLY_INIT(void); michael@0: #define _PR_MD_EARLY_INIT _MD_EARLY_INIT michael@0: michael@0: extern void _PR_MD_INTERVAL_INIT(void); michael@0: #define _PR_MD_INTERVAL_INIT _MD_INTERVAL_INIT michael@0: michael@0: NSPR_API(void) _PR_MD_FINAL_INIT(void); michael@0: #define _PR_MD_FINAL_INIT _MD_FINAL_INIT michael@0: michael@0: extern void _PR_MD_EARLY_CLEANUP(void); michael@0: #define _PR_MD_EARLY_CLEANUP _MD_EARLY_CLEANUP michael@0: michael@0: /* Process control */ michael@0: michael@0: extern PRProcess * _PR_MD_CREATE_PROCESS( michael@0: const char *path, michael@0: char *const *argv, michael@0: char *const *envp, michael@0: const PRProcessAttr *attr); michael@0: #define _PR_MD_CREATE_PROCESS _MD_CREATE_PROCESS michael@0: michael@0: extern PRStatus _PR_MD_DETACH_PROCESS(PRProcess *process); michael@0: #define _PR_MD_DETACH_PROCESS _MD_DETACH_PROCESS michael@0: michael@0: extern PRStatus _PR_MD_WAIT_PROCESS(PRProcess *process, PRInt32 *exitCode); michael@0: #define _PR_MD_WAIT_PROCESS _MD_WAIT_PROCESS michael@0: michael@0: extern PRStatus _PR_MD_KILL_PROCESS(PRProcess *process); michael@0: #define _PR_MD_KILL_PROCESS _MD_KILL_PROCESS michael@0: michael@0: /* Current Time */ michael@0: NSPR_API(PRTime) _PR_MD_NOW(void); michael@0: #define _PR_MD_NOW _MD_NOW michael@0: michael@0: /* Environment related */ michael@0: extern char* _PR_MD_GET_ENV(const char *name); michael@0: #define _PR_MD_GET_ENV _MD_GET_ENV michael@0: michael@0: extern PRIntn _PR_MD_PUT_ENV(const char *name); michael@0: #define _PR_MD_PUT_ENV _MD_PUT_ENV michael@0: michael@0: /* Atomic operations */ michael@0: michael@0: extern void _PR_MD_INIT_ATOMIC(void); michael@0: #define _PR_MD_INIT_ATOMIC _MD_INIT_ATOMIC michael@0: michael@0: extern PRInt32 _PR_MD_ATOMIC_INCREMENT(PRInt32 *); michael@0: #define _PR_MD_ATOMIC_INCREMENT _MD_ATOMIC_INCREMENT michael@0: michael@0: extern PRInt32 _PR_MD_ATOMIC_ADD(PRInt32 *, PRInt32); michael@0: #define _PR_MD_ATOMIC_ADD _MD_ATOMIC_ADD michael@0: michael@0: extern PRInt32 _PR_MD_ATOMIC_DECREMENT(PRInt32 *); michael@0: #define _PR_MD_ATOMIC_DECREMENT _MD_ATOMIC_DECREMENT michael@0: michael@0: extern PRInt32 _PR_MD_ATOMIC_SET(PRInt32 *, PRInt32); michael@0: #define _PR_MD_ATOMIC_SET _MD_ATOMIC_SET michael@0: michael@0: /* Garbage collection */ michael@0: michael@0: /* michael@0: ** Save the registers that the GC would find interesting into the thread michael@0: ** "t". isCurrent will be non-zero if the thread state that is being michael@0: ** saved is the currently executing thread. Return the address of the michael@0: ** first register to be scanned as well as the number of registers to michael@0: ** scan in "np". michael@0: ** michael@0: ** If "isCurrent" is non-zero then it is allowed for the thread context michael@0: ** area to be used as scratch storage to hold just the registers michael@0: ** necessary for scanning. michael@0: */ michael@0: extern PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np); michael@0: michael@0: /* Time intervals */ michael@0: michael@0: extern PRIntervalTime _PR_MD_GET_INTERVAL(void); michael@0: #define _PR_MD_GET_INTERVAL _MD_GET_INTERVAL michael@0: michael@0: extern PRIntervalTime _PR_MD_INTERVAL_PER_SEC(void); michael@0: #define _PR_MD_INTERVAL_PER_SEC _MD_INTERVAL_PER_SEC michael@0: michael@0: /* Affinity masks */ michael@0: michael@0: extern PRInt32 _PR_MD_SETTHREADAFFINITYMASK(PRThread *thread, PRUint32 mask ); michael@0: #define _PR_MD_SETTHREADAFFINITYMASK _MD_SETTHREADAFFINITYMASK michael@0: michael@0: extern PRInt32 _PR_MD_GETTHREADAFFINITYMASK(PRThread *thread, PRUint32 *mask); michael@0: #define _PR_MD_GETTHREADAFFINITYMASK _MD_GETTHREADAFFINITYMASK michael@0: michael@0: /* File locking */ michael@0: michael@0: extern PRStatus _PR_MD_LOCKFILE(PROsfd osfd); michael@0: #define _PR_MD_LOCKFILE _MD_LOCKFILE michael@0: michael@0: extern PRStatus _PR_MD_TLOCKFILE(PROsfd osfd); michael@0: #define _PR_MD_TLOCKFILE _MD_TLOCKFILE michael@0: michael@0: extern PRStatus _PR_MD_UNLOCKFILE(PROsfd osfd); michael@0: #define _PR_MD_UNLOCKFILE _MD_UNLOCKFILE michael@0: michael@0: /* Memory-mapped files */ michael@0: michael@0: extern PRStatus _PR_MD_CREATE_FILE_MAP(PRFileMap *fmap, PRInt64 size); michael@0: #define _PR_MD_CREATE_FILE_MAP _MD_CREATE_FILE_MAP michael@0: michael@0: extern PRInt32 _PR_MD_GET_MEM_MAP_ALIGNMENT(void); michael@0: #define _PR_MD_GET_MEM_MAP_ALIGNMENT _MD_GET_MEM_MAP_ALIGNMENT michael@0: michael@0: extern void * _PR_MD_MEM_MAP( michael@0: PRFileMap *fmap, michael@0: PROffset64 offset, michael@0: PRUint32 len); michael@0: #define _PR_MD_MEM_MAP _MD_MEM_MAP michael@0: michael@0: extern PRStatus _PR_MD_MEM_UNMAP(void *addr, PRUint32 size); michael@0: #define _PR_MD_MEM_UNMAP _MD_MEM_UNMAP michael@0: michael@0: extern PRStatus _PR_MD_CLOSE_FILE_MAP(PRFileMap *fmap); michael@0: #define _PR_MD_CLOSE_FILE_MAP _MD_CLOSE_FILE_MAP michael@0: michael@0: extern PRStatus _PR_MD_SYNC_MEM_MAP( michael@0: PRFileDesc *fd, michael@0: void *addr, michael@0: PRUint32 len); michael@0: #define _PR_MD_SYNC_MEM_MAP _MD_SYNC_MEM_MAP michael@0: michael@0: /* Named Shared Memory */ michael@0: michael@0: /* michael@0: ** Declare PRSharedMemory. michael@0: */ michael@0: struct PRSharedMemory michael@0: { michael@0: char *ipcname; /* after conversion to native */ michael@0: PRSize size; /* from open */ michael@0: PRIntn mode; /* from open */ michael@0: PRIntn flags; /* from open */ michael@0: #if defined(PR_HAVE_POSIX_NAMED_SHARED_MEMORY) michael@0: int id; michael@0: #elif defined(PR_HAVE_SYSV_NAMED_SHARED_MEMORY) michael@0: int id; michael@0: #elif defined(PR_HAVE_WIN32_NAMED_SHARED_MEMORY) michael@0: HANDLE handle; michael@0: #else michael@0: PRUint32 nothing; /* placeholder, nothing behind here */ michael@0: #endif michael@0: PRUint32 ident; /* guard word at end of struct */ michael@0: #define _PR_SHM_IDENT 0xdeadbad michael@0: }; michael@0: michael@0: extern PRSharedMemory * _MD_OpenSharedMemory( michael@0: const char *name, michael@0: PRSize size, michael@0: PRIntn flags, michael@0: PRIntn mode michael@0: ); michael@0: #define _PR_MD_OPEN_SHARED_MEMORY _MD_OpenSharedMemory michael@0: michael@0: extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags ); michael@0: #define _PR_MD_ATTACH_SHARED_MEMORY _MD_AttachSharedMemory michael@0: michael@0: extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr ); michael@0: #define _PR_MD_DETACH_SHARED_MEMORY _MD_DetachSharedMemory michael@0: michael@0: extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm ); michael@0: #define _PR_MD_CLOSE_SHARED_MEMORY _MD_CloseSharedMemory michael@0: michael@0: extern PRStatus _MD_DeleteSharedMemory( const char *name ); michael@0: #define _PR_MD_DELETE_SHARED_MEMORY _MD_DeleteSharedMemory michael@0: michael@0: extern PRFileMap* _md_OpenAnonFileMap( michael@0: const char *dirName, michael@0: PRSize size, michael@0: PRFileMapProtect prot michael@0: ); michael@0: #define _PR_MD_OPEN_ANON_FILE_MAP _md_OpenAnonFileMap michael@0: michael@0: extern PRStatus _md_ExportFileMapAsString( michael@0: PRFileMap *fm, michael@0: PRSize bufSize, michael@0: char *buf michael@0: ); michael@0: #define _PR_MD_EXPORT_FILE_MAP_AS_STRING _md_ExportFileMapAsString michael@0: michael@0: extern PRFileMap * _md_ImportFileMapFromString( michael@0: const char *fmstring michael@0: ); michael@0: #define _PR_MD_IMPORT_FILE_MAP_FROM_STRING _md_ImportFileMapFromString michael@0: michael@0: michael@0: michael@0: /* Interprocess communications (IPC) */ michael@0: michael@0: /* michael@0: * The maximum length of an NSPR IPC name, including the michael@0: * terminating null byte. michael@0: */ michael@0: #define PR_IPC_NAME_SIZE 1024 michael@0: michael@0: /* michael@0: * Types of NSPR IPC objects michael@0: */ michael@0: typedef enum { michael@0: _PRIPCSem, /* semaphores */ michael@0: _PRIPCShm /* shared memory segments */ michael@0: } _PRIPCType; michael@0: michael@0: /* michael@0: * Make a native IPC name from an NSPR IPC name. michael@0: */ michael@0: extern PRStatus _PR_MakeNativeIPCName( michael@0: const char *name, /* NSPR IPC name */ michael@0: char *result, /* result buffer */ michael@0: PRIntn size, /* size of result buffer */ michael@0: _PRIPCType type /* type of IPC object */ michael@0: ); michael@0: michael@0: /* Socket call error code */ michael@0: michael@0: NSPR_API(PRInt32) _PR_MD_GET_SOCKET_ERROR(void); michael@0: #define _PR_MD_GET_SOCKET_ERROR _MD_GET_SOCKET_ERROR michael@0: michael@0: /* Get name of current host */ michael@0: extern PRStatus _PR_MD_GETHOSTNAME(char *name, PRUint32 namelen); michael@0: #define _PR_MD_GETHOSTNAME _MD_GETHOSTNAME michael@0: michael@0: extern PRStatus _PR_MD_GETSYSINFO(PRSysInfo cmd, char *name, PRUint32 namelen); michael@0: #define _PR_MD_GETSYSINFO _MD_GETSYSINFO michael@0: michael@0: /* File descriptor inheritance */ michael@0: michael@0: /* michael@0: * If fd->secret->inheritable is _PR_TRI_UNKNOWN and we need to michael@0: * know the inheritable attribute of the fd, call this function michael@0: * to find that out. This typically requires a system call. michael@0: */ michael@0: extern void _PR_MD_QUERY_FD_INHERITABLE(PRFileDesc *fd); michael@0: #define _PR_MD_QUERY_FD_INHERITABLE _MD_QUERY_FD_INHERITABLE michael@0: michael@0: /* --- PR_GetRandomNoise() related things --- */ michael@0: michael@0: extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size ); michael@0: #define _PR_MD_GET_RANDOM_NOISE(buf,size) _PR_MD_GetRandomNoise((buf),(size)) michael@0: extern PRSize _pr_CopyLowBits( void *dest, PRSize dstlen, void *src, PRSize srclen ); michael@0: michael@0: /* end PR_GetRandomNoise() related */ michael@0: michael@0: #ifdef XP_BEOS michael@0: michael@0: extern PRLock *_connectLock; michael@0: michael@0: typedef struct _ConnectListNode { michael@0: PRInt32 osfd; michael@0: PRNetAddr addr; michael@0: PRUint32 addrlen; michael@0: PRIntervalTime timeout; michael@0: } ConnectListNode; michael@0: michael@0: extern ConnectListNode connectList[64]; michael@0: michael@0: extern PRUint32 connectCount; michael@0: michael@0: #endif /* XP_BEOS */ michael@0: michael@0: PR_END_EXTERN_C michael@0: michael@0: #endif /* primpl_h___ */