1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is the Netscape Portable Runtime (NSPR).
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998-2000
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | #ifndef primpl_h___
|
---|
39 | #define primpl_h___
|
---|
40 |
|
---|
41 | /*
|
---|
42 | * HP-UX 10.10's pthread.h (DCE threads) includes dce/cma.h, which
|
---|
43 | * has:
|
---|
44 | * #define sigaction _sigaction_sys
|
---|
45 | * This macro causes chaos if signal.h gets included before pthread.h.
|
---|
46 | * To be safe, we include pthread.h first.
|
---|
47 | */
|
---|
48 |
|
---|
49 | #include <pthread.h>
|
---|
50 |
|
---|
51 | #include "nspr.h"
|
---|
52 | #include "prpriv.h"
|
---|
53 |
|
---|
54 | typedef struct PRSegment PRSegment;
|
---|
55 |
|
---|
56 | #ifdef XP_MAC
|
---|
57 | #include "prosdep.h"
|
---|
58 | #include "probslet.h"
|
---|
59 | #else
|
---|
60 | #include "md/prosdep.h"
|
---|
61 | #include "obsolete/probslet.h"
|
---|
62 | #endif /* XP_MAC */
|
---|
63 |
|
---|
64 | #ifdef _PR_HAVE_POSIX_SEMAPHORES
|
---|
65 | #include <semaphore.h>
|
---|
66 | #elif defined(_PR_HAVE_SYSV_SEMAPHORES)
|
---|
67 | #include <sys/sem.h>
|
---|
68 | #endif
|
---|
69 |
|
---|
70 | /*************************************************************************
|
---|
71 | ***** A Word about Model Dependent Function Naming Convention ***********
|
---|
72 | *************************************************************************/
|
---|
73 |
|
---|
74 | /*
|
---|
75 | NSPR 2.0 must implement its function across a range of platforms
|
---|
76 | including: MAC, Windows/16, Windows/95, Windows/NT, and several
|
---|
77 | variants of Unix. Each implementation shares common code as well
|
---|
78 | as having platform dependent portions. This standard describes how
|
---|
79 | the model dependent portions are to be implemented.
|
---|
80 |
|
---|
81 | In header file pr/include/primpl.h, each publicly declared
|
---|
82 | platform dependent function is declared as:
|
---|
83 |
|
---|
84 | NSPR_API void _PR_MD_FUNCTION( long arg1, long arg2 );
|
---|
85 | #define _PR_MD_FUNCTION _MD_FUNCTION
|
---|
86 |
|
---|
87 | In header file pr/include/md/<platform>/_<platform>.h,
|
---|
88 | each #define'd macro is redefined as one of:
|
---|
89 |
|
---|
90 | #define _MD_FUNCTION <blanks>
|
---|
91 | #define _MD_FUNCTION <expanded macro>
|
---|
92 | #define _MD_FUNCTION <osFunction>
|
---|
93 | #define _MD_FUNCTION <_MD_Function>
|
---|
94 |
|
---|
95 | Where:
|
---|
96 |
|
---|
97 | <blanks> is no definition at all. In this case, the function is not implemented
|
---|
98 | and is never called for this platform.
|
---|
99 | For example:
|
---|
100 | #define _MD_INIT_CPUS()
|
---|
101 |
|
---|
102 | <expanded macro> is a C language macro expansion.
|
---|
103 | For example:
|
---|
104 | #define _MD_CLEAN_THREAD(_thread) \
|
---|
105 | PR_BEGIN_MACRO \
|
---|
106 | PR_DestroyCondVar(_thread->md.asyncIOCVar); \
|
---|
107 | PR_DestroyLock(_thread->md.asyncIOLock); \
|
---|
108 | PR_END_MACRO
|
---|
109 |
|
---|
110 | <osFunction> is some function implemented by the host operating system.
|
---|
111 | For example:
|
---|
112 | #define _MD_EXIT exit
|
---|
113 |
|
---|
114 | <_MD_function> is the name of a function implemented for this platform in
|
---|
115 | pr/src/md/<platform>/<soruce>.c file.
|
---|
116 | For example:
|
---|
117 | #define _MD_GETFILEINFO _MD_GetFileInfo
|
---|
118 |
|
---|
119 | In <source>.c, the implementation is:
|
---|
120 | PR_IMPLEMENT(PRInt32) _MD_GetFileInfo(const char *fn, PRFileInfo *info);
|
---|
121 | */
|
---|
122 |
|
---|
123 | #ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
|
---|
124 | #define PT_FPrintStats VBoxNsprPT_FPrintStats
|
---|
125 | #endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
|
---|
126 |
|
---|
127 | PR_BEGIN_EXTERN_C
|
---|
128 |
|
---|
129 | typedef struct _MDLock _MDLock;
|
---|
130 | typedef struct _MDCVar _MDCVar;
|
---|
131 | typedef struct _MDSegment _MDSegment;
|
---|
132 | typedef struct _MDThread _MDThread;
|
---|
133 | typedef struct _MDThreadStack _MDThreadStack;
|
---|
134 | typedef struct _MDSemaphore _MDSemaphore;
|
---|
135 | typedef struct _MDDir _MDDir;
|
---|
136 | typedef struct _MDFileDesc _MDFileDesc;
|
---|
137 | typedef struct _MDProcess _MDProcess;
|
---|
138 | typedef struct _MDFileMap _MDFileMap;
|
---|
139 |
|
---|
140 | /*
|
---|
141 | ** The following definitions are unique to implementing NSPR using pthreads.
|
---|
142 | ** Since pthreads defines most of the thread and thread synchronization
|
---|
143 | ** stuff, this is a pretty small set.
|
---|
144 | */
|
---|
145 |
|
---|
146 | #define PT_CV_NOTIFIED_LENGTH 6
|
---|
147 | typedef struct _PT_Notified _PT_Notified;
|
---|
148 | struct _PT_Notified
|
---|
149 | {
|
---|
150 | PRIntn length; /* # of used entries in this structure */
|
---|
151 | struct
|
---|
152 | {
|
---|
153 | PRCondVar *cv; /* the condition variable notified */
|
---|
154 | PRIntn times; /* and the number of times notified */
|
---|
155 | } cv[PT_CV_NOTIFIED_LENGTH];
|
---|
156 | _PT_Notified *link; /* link to another of these | NULL */
|
---|
157 | };
|
---|
158 |
|
---|
159 | /*
|
---|
160 | * bits defined for pthreads 'state' field
|
---|
161 | */
|
---|
162 | #define PT_THREAD_DETACHED 0x01 /* thread can't be joined */
|
---|
163 | #define PT_THREAD_GLOBAL 0x02 /* a global thread (unlikely) */
|
---|
164 | #define PT_THREAD_SYSTEM 0x04 /* system (not user) thread */
|
---|
165 | #define PT_THREAD_PRIMORD 0x08 /* this is the primordial thread */
|
---|
166 | #define PT_THREAD_ABORTED 0x10 /* thread has been interrupted */
|
---|
167 | #define PT_THREAD_GCABLE 0x20 /* thread is garbage collectible */
|
---|
168 | #define PT_THREAD_SUSPENDED 0x40 /* thread has been suspended */
|
---|
169 | #define PT_THREAD_FOREIGN 0x80 /* thread is not one of ours */
|
---|
170 | #define PT_THREAD_BOUND 0x100 /* a bound-global thread */
|
---|
171 |
|
---|
172 | #define _PT_THREAD_INTERRUPTED(thr) \
|
---|
173 | (!(thr->interrupt_blocked) && (thr->state & PT_THREAD_ABORTED))
|
---|
174 | #define _PT_THREAD_BLOCK_INTERRUPT(thr) \
|
---|
175 | (thr->interrupt_blocked = 1)
|
---|
176 | #define _PT_THREAD_UNBLOCK_INTERRUPT(thr) \
|
---|
177 | (thr->interrupt_blocked = 0)
|
---|
178 |
|
---|
179 | #define _PT_IS_GCABLE_THREAD(thr) ((thr)->state & PT_THREAD_GCABLE)
|
---|
180 |
|
---|
181 | /*
|
---|
182 | ** Possible values for thread's suspend field
|
---|
183 | ** Note that the first two can be the same as they are really mutually exclusive,
|
---|
184 | ** i.e. both cannot be happening at the same time. We have two symbolic names
|
---|
185 | ** just as a mnemonic.
|
---|
186 | **/
|
---|
187 | #define PT_THREAD_RESUMED 0x80 /* thread has been resumed */
|
---|
188 | #define PT_THREAD_SETGCABLE 0x100 /* set the GCAble flag */
|
---|
189 |
|
---|
190 | #if defined(DEBUG)
|
---|
191 |
|
---|
192 | typedef struct PTDebug
|
---|
193 | {
|
---|
194 | PRTime timeStarted;
|
---|
195 | PRUintn locks_created, locks_destroyed;
|
---|
196 | PRUintn locks_acquired, locks_released;
|
---|
197 | PRUintn cvars_created, cvars_destroyed;
|
---|
198 | PRUintn cvars_notified, delayed_cv_deletes;
|
---|
199 | } PTDebug;
|
---|
200 |
|
---|
201 | #endif /* defined(DEBUG) */
|
---|
202 |
|
---|
203 | NSPR_API(void) PT_FPrintStats(PRFileDesc *fd, const char *msg);
|
---|
204 |
|
---|
205 | /************************************************************************/
|
---|
206 | /*************************************************************************
|
---|
207 | ** The remainder of the definitions are shared by pthreads and the classic
|
---|
208 | ** NSPR code. These too may be conditionalized.
|
---|
209 | *************************************************************************/
|
---|
210 | /************************************************************************/
|
---|
211 |
|
---|
212 | extern PROffset32 _PR_MD_LSEEK(PRFileDesc *fd, PROffset32 offset, PRSeekWhence whence);
|
---|
213 | #define _PR_MD_LSEEK _MD_LSEEK
|
---|
214 |
|
---|
215 | extern PROffset64 _PR_MD_LSEEK64(PRFileDesc *fd, PROffset64 offset, PRSeekWhence whence);
|
---|
216 | #define _PR_MD_LSEEK64 _MD_LSEEK64
|
---|
217 |
|
---|
218 | extern PRInt32 _PR_MD_GETFILEINFO(const char *fn, PRFileInfo *info);
|
---|
219 | #define _PR_MD_GETFILEINFO _MD_GETFILEINFO
|
---|
220 |
|
---|
221 | extern PRInt32 _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info);
|
---|
222 | #define _PR_MD_GETFILEINFO64 _MD_GETFILEINFO64
|
---|
223 |
|
---|
224 | extern PRInt32 _PR_MD_GETOPENFILEINFO(const PRFileDesc *fd, PRFileInfo *info);
|
---|
225 | #define _PR_MD_GETOPENFILEINFO _MD_GETOPENFILEINFO
|
---|
226 |
|
---|
227 | extern PRInt32 _PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info);
|
---|
228 | #define _PR_MD_GETOPENFILEINFO64 _MD_GETOPENFILEINFO64
|
---|
229 |
|
---|
230 |
|
---|
231 | /*****************************************************************************/
|
---|
232 | /************************** File descriptor caching **************************/
|
---|
233 | /*****************************************************************************/
|
---|
234 | extern void _PR_InitFdCache(void);
|
---|
235 | extern void _PR_CleanupFdCache(void);
|
---|
236 | extern PRFileDesc *_PR_Getfd(void);
|
---|
237 | extern void _PR_Putfd(PRFileDesc *fd);
|
---|
238 |
|
---|
239 | /*
|
---|
240 | * These flags are used by NSPR temporarily in the poll
|
---|
241 | * descriptor's out_flags field to record the mapping of
|
---|
242 | * NSPR's poll flags to the system poll flags.
|
---|
243 | *
|
---|
244 | * If _PR_POLL_READ_SYS_WRITE bit is set, it means the
|
---|
245 | * PR_POLL_READ flag specified by the topmost layer is
|
---|
246 | * mapped to the WRITE flag at the system layer. Similarly
|
---|
247 | * for the other three _PR_POLL_XXX_SYS_YYY flags. It is
|
---|
248 | * assumed that the PR_POLL_EXCEPT flag doesn't get mapped
|
---|
249 | * to other flags.
|
---|
250 | */
|
---|
251 | #define _PR_POLL_READ_SYS_READ 0x1
|
---|
252 | #define _PR_POLL_READ_SYS_WRITE 0x2
|
---|
253 | #define _PR_POLL_WRITE_SYS_READ 0x4
|
---|
254 | #define _PR_POLL_WRITE_SYS_WRITE 0x8
|
---|
255 |
|
---|
256 | /*
|
---|
257 | ** These methods are coerced into file descriptor methods table
|
---|
258 | ** when the intended service is inappropriate for the particular
|
---|
259 | ** type of file descriptor.
|
---|
260 | */
|
---|
261 | extern PRIntn _PR_InvalidInt(void);
|
---|
262 | extern PRInt16 _PR_InvalidInt16(void);
|
---|
263 | extern PRInt64 _PR_InvalidInt64(void);
|
---|
264 | extern PRStatus _PR_InvalidStatus(void);
|
---|
265 | extern PRFileDesc *_PR_InvalidDesc(void);
|
---|
266 |
|
---|
267 | extern PRIOMethods _pr_faulty_methods;
|
---|
268 |
|
---|
269 | /*
|
---|
270 | ** The PR_NETADDR_SIZE macro can only be called on a PRNetAddr union
|
---|
271 | ** whose 'family' field is set. It returns the size of the union
|
---|
272 | ** member corresponding to the specified address family.
|
---|
273 | */
|
---|
274 |
|
---|
275 | extern PRUintn _PR_NetAddrSize(const PRNetAddr* addr);
|
---|
276 |
|
---|
277 | #if defined(_PR_INET6)
|
---|
278 |
|
---|
279 | #define PR_NETADDR_SIZE(_addr) _PR_NetAddrSize(_addr)
|
---|
280 |
|
---|
281 | #elif defined(_PR_HAVE_MD_SOCKADDR_IN6)
|
---|
282 |
|
---|
283 | /*
|
---|
284 | ** Under the following conditions:
|
---|
285 | ** 1. _PR_INET6 is not defined;
|
---|
286 | ** 2. _PR_INET6_PROBE is defined;
|
---|
287 | ** 3. struct sockaddr_in6 has nonstandard fields at the end
|
---|
288 | ** (e.g., on Solaris 8),
|
---|
289 | ** (_addr)->ipv6 is smaller than struct sockaddr_in6, and
|
---|
290 | ** hence we can't pass sizeof((_addr)->ipv6) to socket
|
---|
291 | ** functions such as connect because they would fail with
|
---|
292 | ** EINVAL.
|
---|
293 | **
|
---|
294 | ** To pass the correct socket address length to socket
|
---|
295 | ** functions, define the macro _PR_HAVE_MD_SOCKADDR_IN6 and
|
---|
296 | ** define struct _md_sockaddr_in6 to be isomorphic to
|
---|
297 | ** struct sockaddr_in6.
|
---|
298 | */
|
---|
299 |
|
---|
300 | #if defined(XP_UNIX) || defined(XP_OS2_EMX)
|
---|
301 | #define PR_NETADDR_SIZE(_addr) \
|
---|
302 | ((_addr)->raw.family == PR_AF_INET \
|
---|
303 | ? sizeof((_addr)->inet) \
|
---|
304 | : ((_addr)->raw.family == PR_AF_INET6 \
|
---|
305 | ? sizeof(struct _md_sockaddr_in6) \
|
---|
306 | : sizeof((_addr)->local)))
|
---|
307 | #else
|
---|
308 | #define PR_NETADDR_SIZE(_addr) \
|
---|
309 | ((_addr)->raw.family == PR_AF_INET \
|
---|
310 | ? sizeof((_addr)->inet) \
|
---|
311 | : sizeof(struct _md_sockaddr_in6)
|
---|
312 | #endif /* defined(XP_UNIX) */
|
---|
313 |
|
---|
314 | #else
|
---|
315 |
|
---|
316 | #if defined(XP_UNIX) || defined(XP_OS2_EMX)
|
---|
317 | #define PR_NETADDR_SIZE(_addr) \
|
---|
318 | ((_addr)->raw.family == PR_AF_INET \
|
---|
319 | ? sizeof((_addr)->inet) \
|
---|
320 | : ((_addr)->raw.family == PR_AF_INET6 \
|
---|
321 | ? sizeof((_addr)->ipv6) \
|
---|
322 | : sizeof((_addr)->local)))
|
---|
323 | #else
|
---|
324 | #define PR_NETADDR_SIZE(_addr) \
|
---|
325 | ((_addr)->raw.family == PR_AF_INET \
|
---|
326 | ? sizeof((_addr)->inet) \
|
---|
327 | : sizeof((_addr)->ipv6))
|
---|
328 | #endif /* defined(XP_UNIX) */
|
---|
329 |
|
---|
330 | #endif /* defined(_PR_INET6) */
|
---|
331 |
|
---|
332 | extern PRStatus _PR_MapOptionName(
|
---|
333 | PRSockOption optname, PRInt32 *level, PRInt32 *name);
|
---|
334 | extern void _PR_InitThreads(
|
---|
335 | PRThreadType type, PRThreadPriority priority, PRUintn maxPTDs);
|
---|
336 |
|
---|
337 | struct PRLock {
|
---|
338 | pthread_mutex_t mutex; /* the underlying lock */
|
---|
339 | _PT_Notified notified; /* array of conditions notified */
|
---|
340 | PRBool locked; /* whether the mutex is locked */
|
---|
341 | pthread_t owner; /* if locked, current lock owner */
|
---|
342 | };
|
---|
343 |
|
---|
344 | extern void _PR_InitLocks(void);
|
---|
345 |
|
---|
346 | struct PRCondVar {
|
---|
347 | PRLock *lock; /* associated lock that protects the condition */
|
---|
348 | pthread_cond_t cv; /* underlying pthreads condition */
|
---|
349 | PRInt32 notify_pending; /* CV has destroy pending notification */
|
---|
350 | };
|
---|
351 |
|
---|
352 | /************************************************************************/
|
---|
353 |
|
---|
354 | struct PRMonitor {
|
---|
355 | const char* name; /* monitor name for debugging */
|
---|
356 | PRLock lock; /* the lock structure */
|
---|
357 | pthread_t owner; /* the owner of the lock or invalid */
|
---|
358 | PRCondVar *cvar; /* condition variable queue */
|
---|
359 | PRUint32 entryCount; /* # of times re-entered */
|
---|
360 | };
|
---|
361 |
|
---|
362 | /************************************************************************/
|
---|
363 |
|
---|
364 | struct PRSemaphore {
|
---|
365 | PRCondVar *cvar; /* associated lock and condition variable queue */
|
---|
366 | PRUintn count; /* the value of the counting semaphore */
|
---|
367 | PRUint32 waiters; /* threads waiting on the semaphore */
|
---|
368 | };
|
---|
369 |
|
---|
370 | NSPR_API(void) _PR_InitSem(void);
|
---|
371 |
|
---|
372 | /*************************************************************************/
|
---|
373 |
|
---|
374 | struct PRSem {
|
---|
375 | #ifdef _PR_HAVE_POSIX_SEMAPHORES
|
---|
376 | sem_t *sem;
|
---|
377 | #elif defined(_PR_HAVE_SYSV_SEMAPHORES)
|
---|
378 | int semid;
|
---|
379 | #elif defined(WIN32)
|
---|
380 | HANDLE sem;
|
---|
381 | #else
|
---|
382 | PRInt8 notused;
|
---|
383 | #endif
|
---|
384 | };
|
---|
385 |
|
---|
386 | /*************************************************************************/
|
---|
387 |
|
---|
388 | struct PRStackStr {
|
---|
389 | /* head MUST be at offset 0; assembly language code relies on this */
|
---|
390 | #if defined(AIX)
|
---|
391 | volatile PRStackElem prstk_head;
|
---|
392 | #else
|
---|
393 | PRStackElem prstk_head;
|
---|
394 | #endif
|
---|
395 |
|
---|
396 | PRLock *prstk_lock;
|
---|
397 | char *prstk_name;
|
---|
398 | };
|
---|
399 |
|
---|
400 | /************************************************************************/
|
---|
401 |
|
---|
402 | /* XXX this needs to be exported (sigh) */
|
---|
403 | struct PRThreadStack {
|
---|
404 | PRCList links;
|
---|
405 | PRUintn flags;
|
---|
406 |
|
---|
407 | char *allocBase; /* base of stack's allocated memory */
|
---|
408 | PRUint32 allocSize; /* size of stack's allocated memory */
|
---|
409 | char *stackBottom; /* bottom of stack from C's point of view */
|
---|
410 | char *stackTop; /* top of stack from C's point of view */
|
---|
411 | PRUint32 stackSize; /* size of usable portion of the stack */
|
---|
412 |
|
---|
413 | PRSegment *seg;
|
---|
414 | PRThread* thr; /* back pointer to thread owning this stack */
|
---|
415 | };
|
---|
416 |
|
---|
417 | extern void _PR_DestroyThreadPrivate(PRThread*);
|
---|
418 |
|
---|
419 | typedef void (PR_CALLBACK *_PRStartFn)(void *);
|
---|
420 |
|
---|
421 | struct PRThread {
|
---|
422 | PRUint32 state; /* thread's creation state */
|
---|
423 | PRThreadPriority priority; /* apparent priority, loosly defined */
|
---|
424 |
|
---|
425 | void *arg; /* argument to the client's entry point */
|
---|
426 | _PRStartFn startFunc; /* the root of the client's thread */
|
---|
427 |
|
---|
428 | PRThreadStack *stack; /* info about thread's stack (for GC) */
|
---|
429 | void *environment; /* pointer to execution environment */
|
---|
430 |
|
---|
431 | PRThreadDumpProc dump; /* dump thread info out */
|
---|
432 | void *dumpArg; /* argument for the dump function */
|
---|
433 |
|
---|
434 | /*
|
---|
435 | ** Per thread private data
|
---|
436 | */
|
---|
437 | PRUint32 tpdLength; /* thread's current vector length */
|
---|
438 | void **privateData; /* private data vector or NULL */
|
---|
439 | PRErrorCode errorCode; /* current NSPR error code | zero */
|
---|
440 | PRInt32 osErrorCode; /* mapping of errorCode | zero */
|
---|
441 | PRIntn errorStringLength; /* textLength from last call to PR_SetErrorText() */
|
---|
442 | PRInt32 errorStringSize; /* malloc()'d size of buffer | zero */
|
---|
443 | char *errorString; /* current error string | NULL */
|
---|
444 |
|
---|
445 | pthread_t id; /* pthread identifier for the thread */
|
---|
446 | PRBool okToDelete; /* ok to delete the PRThread struct? */
|
---|
447 | PRCondVar *waiting; /* where the thread is waiting | NULL */
|
---|
448 | void *sp; /* recorded sp for garbage collection */
|
---|
449 | PRThread *next, *prev; /* simple linked list of all threads */
|
---|
450 | PRUint32 suspend; /* used to store suspend and resume flags */
|
---|
451 | #ifdef PT_NO_SIGTIMEDWAIT
|
---|
452 | pthread_mutex_t suspendResumeMutex;
|
---|
453 | pthread_cond_t suspendResumeCV;
|
---|
454 | #endif
|
---|
455 | PRUint32 interrupt_blocked; /* interrupt blocked */
|
---|
456 | struct pollfd *syspoll_list; /* Unix polling list used by PR_Poll */
|
---|
457 | PRUint32 syspoll_count; /* number of elements in syspoll_list */
|
---|
458 | };
|
---|
459 |
|
---|
460 | struct PRProcessAttr {
|
---|
461 | PRFileDesc *stdinFd;
|
---|
462 | PRFileDesc *stdoutFd;
|
---|
463 | PRFileDesc *stderrFd;
|
---|
464 | char *currentDirectory;
|
---|
465 | char *fdInheritBuffer;
|
---|
466 | PRSize fdInheritBufferSize;
|
---|
467 | PRSize fdInheritBufferUsed;
|
---|
468 | };
|
---|
469 |
|
---|
470 | struct PRProcess {
|
---|
471 | _MDProcess md;
|
---|
472 | };
|
---|
473 |
|
---|
474 | struct PRFileMap {
|
---|
475 | PRFileDesc *fd;
|
---|
476 | PRFileMapProtect prot;
|
---|
477 | _MDFileMap md;
|
---|
478 | };
|
---|
479 |
|
---|
480 | /************************************************************************/
|
---|
481 |
|
---|
482 | /*
|
---|
483 | ** File descriptors of the NSPR layer can be in one of the
|
---|
484 | ** following states (stored in the 'state' field of struct
|
---|
485 | ** PRFilePrivate):
|
---|
486 | ** - _PR_FILEDESC_OPEN: The OS fd is open.
|
---|
487 | ** - _PR_FILEDESC_CLOSED: The OS fd is closed. The PRFileDesc
|
---|
488 | ** is still open but is unusable. The only operation allowed
|
---|
489 | ** on the PRFileDesc is PR_Close().
|
---|
490 | ** - _PR_FILEDESC_FREED: The OS fd is closed and the PRFileDesc
|
---|
491 | ** structure is freed.
|
---|
492 | */
|
---|
493 |
|
---|
494 | #define _PR_FILEDESC_OPEN 0xaaaaaaaa /* 1010101... */
|
---|
495 | #define _PR_FILEDESC_CLOSED 0x55555555 /* 0101010... */
|
---|
496 | #define _PR_FILEDESC_FREED 0x11111111
|
---|
497 |
|
---|
498 | /*
|
---|
499 | ** A boolean type with an additional "unknown" state
|
---|
500 | */
|
---|
501 |
|
---|
502 | typedef enum {
|
---|
503 | _PR_TRI_TRUE = 1,
|
---|
504 | _PR_TRI_FALSE = 0,
|
---|
505 | _PR_TRI_UNKNOWN = -1
|
---|
506 | } _PRTriStateBool;
|
---|
507 |
|
---|
508 | struct PRFilePrivate {
|
---|
509 | PRInt32 state;
|
---|
510 | PRBool nonblocking;
|
---|
511 | _PRTriStateBool inheritable;
|
---|
512 | PRFileDesc *next;
|
---|
513 | PRIntn lockCount; /* 0: not locked
|
---|
514 | * -1: a native lockfile call is in progress
|
---|
515 | * > 0: # times the file is locked */
|
---|
516 | #ifdef _PR_HAVE_PEEK_BUFFER
|
---|
517 | char *peekBuffer;
|
---|
518 | PRInt32 peekBufSize;
|
---|
519 | PRInt32 peekBytes;
|
---|
520 | #endif
|
---|
521 | #if !defined(XP_UNIX) /* BugZilla: 4090 */
|
---|
522 | PRBool appendMode;
|
---|
523 | #endif
|
---|
524 | _MDFileDesc md;
|
---|
525 | #ifdef _PR_STRICT_ADDR_LEN
|
---|
526 | PRUint16 af; /* If the platform requires passing the exact
|
---|
527 | * length of the sockaddr structure for the
|
---|
528 | * address family of the socket to socket
|
---|
529 | * functions like accept(), we need to save
|
---|
530 | * the address family of the socket. */
|
---|
531 | #endif
|
---|
532 | };
|
---|
533 |
|
---|
534 | struct PRDir {
|
---|
535 | PRDirEntry d;
|
---|
536 | _MDDir md;
|
---|
537 | };
|
---|
538 |
|
---|
539 | extern void _PR_InitSegs(void);
|
---|
540 | extern void _PR_InitStacks(void);
|
---|
541 | extern void _PR_InitTPD(void);
|
---|
542 | extern void _PR_InitMem(void);
|
---|
543 | extern void _PR_InitEnv(void);
|
---|
544 | extern void _PR_InitCMon(void);
|
---|
545 | extern void _PR_InitIO(void);
|
---|
546 | extern void _PR_InitLog(void);
|
---|
547 | extern void _PR_InitNet(void);
|
---|
548 | extern void _PR_InitClock(void);
|
---|
549 | extern void _PR_InitLinker(void);
|
---|
550 | extern void _PR_InitAtomic(void);
|
---|
551 | extern void _PR_InitCPUs(void);
|
---|
552 | extern void _PR_InitDtoa(void);
|
---|
553 | extern void _PR_InitMW(void);
|
---|
554 | extern void _PR_NotifyCondVar(PRCondVar *cvar, PRThread *me);
|
---|
555 | extern void _PR_CleanupThread(PRThread *thread);
|
---|
556 | extern void _PR_CleanupCallOnce(void);
|
---|
557 | extern void _PR_CleanupMW(void);
|
---|
558 | extern void _PR_CleanupDtoa(void);
|
---|
559 | extern void _PR_ShutdownLinker(void);
|
---|
560 | extern void _PR_CleanupEnv(void);
|
---|
561 | extern void _PR_CleanupIO(void);
|
---|
562 | extern void _PR_CleanupNet(void);
|
---|
563 | extern void _PR_CleanupLayerCache(void);
|
---|
564 | extern void _PR_CleanupStacks(void);
|
---|
565 | #ifdef WINNT
|
---|
566 | extern void _PR_CleanupCPUs(void);
|
---|
567 | #endif
|
---|
568 | extern void _PR_CleanupThreads(void);
|
---|
569 | extern void _PR_CleanupTPD(void);
|
---|
570 | extern void _PR_Cleanup(void);
|
---|
571 | extern void _PR_LogCleanup(void);
|
---|
572 | extern void _PR_InitLayerCache(void);
|
---|
573 |
|
---|
574 | extern PRBool _pr_initialized;
|
---|
575 | extern void _PR_ImplicitInitialization(void);
|
---|
576 | extern PRBool _PR_Obsolete(const char *obsolete, const char *preferred);
|
---|
577 |
|
---|
578 | /************************************************************************/
|
---|
579 |
|
---|
580 | struct PRSegment {
|
---|
581 | void *vaddr;
|
---|
582 | PRUint32 size;
|
---|
583 | PRUintn flags;
|
---|
584 | };
|
---|
585 |
|
---|
586 | /* PRSegment.flags */
|
---|
587 | #define _PR_SEG_VM 0x1
|
---|
588 |
|
---|
589 | /************************************************************************/
|
---|
590 |
|
---|
591 | extern PRInt32 _pr_pageSize;
|
---|
592 | extern PRInt32 _pr_pageShift;
|
---|
593 |
|
---|
594 | extern PRLogModuleInfo *_pr_clock_lm;
|
---|
595 | extern PRLogModuleInfo *_pr_cmon_lm;
|
---|
596 | extern PRLogModuleInfo *_pr_io_lm;
|
---|
597 | extern PRLogModuleInfo *_pr_cvar_lm;
|
---|
598 | extern PRLogModuleInfo *_pr_mon_lm;
|
---|
599 | extern PRLogModuleInfo *_pr_linker_lm;
|
---|
600 | extern PRLogModuleInfo *_pr_sched_lm;
|
---|
601 | extern PRLogModuleInfo *_pr_thread_lm;
|
---|
602 | extern PRLogModuleInfo *_pr_gc_lm;
|
---|
603 |
|
---|
604 | extern PRFileDesc *_pr_stdin;
|
---|
605 | extern PRFileDesc *_pr_stdout;
|
---|
606 | extern PRFileDesc *_pr_stderr;
|
---|
607 |
|
---|
608 |
|
---|
609 | /*************************************************************************
|
---|
610 | * External machine-dependent code provided by each OS. * *
|
---|
611 | *************************************************************************/
|
---|
612 |
|
---|
613 | /* Initialization related */
|
---|
614 | extern void _PR_MD_EARLY_INIT(void);
|
---|
615 | #define _PR_MD_EARLY_INIT _MD_EARLY_INIT
|
---|
616 |
|
---|
617 | extern void _PR_MD_INTERVAL_INIT(void);
|
---|
618 | #define _PR_MD_INTERVAL_INIT _MD_INTERVAL_INIT
|
---|
619 |
|
---|
620 | NSPR_API(void) _PR_MD_FINAL_INIT(void);
|
---|
621 | #define _PR_MD_FINAL_INIT _MD_FINAL_INIT
|
---|
622 |
|
---|
623 | /* Process control */
|
---|
624 |
|
---|
625 | #ifdef _MD_CREATE_PROCESS_DETACHED
|
---|
626 | # define _PR_MD_CREATE_PROCESS_DETACHED _MD_CREATE_PROCESS_DETACHED
|
---|
627 | #endif
|
---|
628 |
|
---|
629 | /* Current Time */
|
---|
630 | NSPR_API(PRTime) _PR_MD_NOW(void);
|
---|
631 | #define _PR_MD_NOW _MD_NOW
|
---|
632 |
|
---|
633 | /* Environment related */
|
---|
634 | extern char* _PR_MD_GET_ENV(const char *name);
|
---|
635 | #define _PR_MD_GET_ENV _MD_GET_ENV
|
---|
636 |
|
---|
637 | extern PRIntn _PR_MD_PUT_ENV(const char *name);
|
---|
638 | #define _PR_MD_PUT_ENV _MD_PUT_ENV
|
---|
639 |
|
---|
640 | /* Atomic operations */
|
---|
641 |
|
---|
642 | extern void _PR_MD_INIT_ATOMIC(void);
|
---|
643 | #define _PR_MD_INIT_ATOMIC _MD_INIT_ATOMIC
|
---|
644 |
|
---|
645 | extern PRInt32 _PR_MD_ATOMIC_INCREMENT(PRInt32 *);
|
---|
646 | #define _PR_MD_ATOMIC_INCREMENT _MD_ATOMIC_INCREMENT
|
---|
647 |
|
---|
648 | extern PRInt32 _PR_MD_ATOMIC_ADD(PRInt32 *, PRInt32);
|
---|
649 | #define _PR_MD_ATOMIC_ADD _MD_ATOMIC_ADD
|
---|
650 |
|
---|
651 | extern PRInt32 _PR_MD_ATOMIC_DECREMENT(PRInt32 *);
|
---|
652 | #define _PR_MD_ATOMIC_DECREMENT _MD_ATOMIC_DECREMENT
|
---|
653 |
|
---|
654 | extern PRInt32 _PR_MD_ATOMIC_SET(PRInt32 *, PRInt32);
|
---|
655 | #define _PR_MD_ATOMIC_SET _MD_ATOMIC_SET
|
---|
656 |
|
---|
657 | /* Time intervals */
|
---|
658 |
|
---|
659 | extern PRIntervalTime _PR_MD_GET_INTERVAL(void);
|
---|
660 | #define _PR_MD_GET_INTERVAL _MD_GET_INTERVAL
|
---|
661 |
|
---|
662 | extern PRIntervalTime _PR_MD_INTERVAL_PER_SEC(void);
|
---|
663 | #define _PR_MD_INTERVAL_PER_SEC _MD_INTERVAL_PER_SEC
|
---|
664 |
|
---|
665 | /* Affinity masks */
|
---|
666 |
|
---|
667 | extern PRInt32 _PR_MD_SETTHREADAFFINITYMASK(PRThread *thread, PRUint32 mask );
|
---|
668 | #define _PR_MD_SETTHREADAFFINITYMASK _MD_SETTHREADAFFINITYMASK
|
---|
669 |
|
---|
670 | extern PRInt32 _PR_MD_GETTHREADAFFINITYMASK(PRThread *thread, PRUint32 *mask);
|
---|
671 | #define _PR_MD_GETTHREADAFFINITYMASK _MD_GETTHREADAFFINITYMASK
|
---|
672 |
|
---|
673 | /* File locking */
|
---|
674 |
|
---|
675 | extern PRStatus _PR_MD_LOCKFILE(PRInt32 osfd);
|
---|
676 | #define _PR_MD_LOCKFILE _MD_LOCKFILE
|
---|
677 |
|
---|
678 | extern PRStatus _PR_MD_TLOCKFILE(PRInt32 osfd);
|
---|
679 | #define _PR_MD_TLOCKFILE _MD_TLOCKFILE
|
---|
680 |
|
---|
681 | extern PRStatus _PR_MD_UNLOCKFILE(PRInt32 osfd);
|
---|
682 | #define _PR_MD_UNLOCKFILE _MD_UNLOCKFILE
|
---|
683 |
|
---|
684 | /* Memory-mapped files */
|
---|
685 |
|
---|
686 | extern PRStatus _PR_MD_CREATE_FILE_MAP(PRFileMap *fmap, PRInt64 size);
|
---|
687 | #define _PR_MD_CREATE_FILE_MAP _MD_CREATE_FILE_MAP
|
---|
688 |
|
---|
689 | extern PRInt32 _PR_MD_GET_MEM_MAP_ALIGNMENT(void);
|
---|
690 | #define _PR_MD_GET_MEM_MAP_ALIGNMENT _MD_GET_MEM_MAP_ALIGNMENT
|
---|
691 |
|
---|
692 | extern void * _PR_MD_MEM_MAP(
|
---|
693 | PRFileMap *fmap,
|
---|
694 | PROffset64 offset,
|
---|
695 | PRUint32 len);
|
---|
696 | #define _PR_MD_MEM_MAP _MD_MEM_MAP
|
---|
697 |
|
---|
698 | extern PRStatus _PR_MD_MEM_UNMAP(void *addr, PRUint32 size);
|
---|
699 | #define _PR_MD_MEM_UNMAP _MD_MEM_UNMAP
|
---|
700 |
|
---|
701 | extern PRStatus _PR_MD_CLOSE_FILE_MAP(PRFileMap *fmap);
|
---|
702 | #define _PR_MD_CLOSE_FILE_MAP _MD_CLOSE_FILE_MAP
|
---|
703 |
|
---|
704 |
|
---|
705 | /* Interprocess communications (IPC) */
|
---|
706 |
|
---|
707 | /*
|
---|
708 | * The maximum length of an NSPR IPC name, including the
|
---|
709 | * terminating null byte.
|
---|
710 | */
|
---|
711 | #define PR_IPC_NAME_SIZE 1024
|
---|
712 |
|
---|
713 | /*
|
---|
714 | * Types of NSPR IPC objects
|
---|
715 | */
|
---|
716 | typedef enum {
|
---|
717 | _PRIPCSem, /* semaphores */
|
---|
718 | _PRIPCShm /* shared memory segments */
|
---|
719 | } _PRIPCType;
|
---|
720 |
|
---|
721 | /*
|
---|
722 | * Make a native IPC name from an NSPR IPC name.
|
---|
723 | */
|
---|
724 | extern PRStatus _PR_MakeNativeIPCName(
|
---|
725 | const char *name, /* NSPR IPC name */
|
---|
726 | char *result, /* result buffer */
|
---|
727 | PRIntn size, /* size of result buffer */
|
---|
728 | _PRIPCType type /* type of IPC object */
|
---|
729 | );
|
---|
730 |
|
---|
731 | /* Socket call error code */
|
---|
732 |
|
---|
733 | NSPR_API(PRInt32) _PR_MD_GET_SOCKET_ERROR(void);
|
---|
734 | #define _PR_MD_GET_SOCKET_ERROR _MD_GET_SOCKET_ERROR
|
---|
735 |
|
---|
736 | /* Get name of current host */
|
---|
737 | extern PRStatus _PR_MD_GETHOSTNAME(char *name, PRUint32 namelen);
|
---|
738 | #define _PR_MD_GETHOSTNAME _MD_GETHOSTNAME
|
---|
739 |
|
---|
740 | /* File descriptor inheritance */
|
---|
741 |
|
---|
742 | /*
|
---|
743 | * If fd->secret->inheritable is _PR_TRI_UNKNOWN and we need to
|
---|
744 | * know the inheritable attribute of the fd, call this function
|
---|
745 | * to find that out. This typically requires a system call.
|
---|
746 | */
|
---|
747 | extern void _PR_MD_QUERY_FD_INHERITABLE(PRFileDesc *fd);
|
---|
748 | #define _PR_MD_QUERY_FD_INHERITABLE _MD_QUERY_FD_INHERITABLE
|
---|
749 |
|
---|
750 | #ifdef XP_BEOS
|
---|
751 |
|
---|
752 | extern PRLock *_connectLock;
|
---|
753 |
|
---|
754 | typedef struct _ConnectListNode {
|
---|
755 | PRInt32 osfd;
|
---|
756 | PRNetAddr addr;
|
---|
757 | PRUint32 addrlen;
|
---|
758 | PRIntervalTime timeout;
|
---|
759 | } ConnectListNode;
|
---|
760 |
|
---|
761 | extern ConnectListNode connectList[64];
|
---|
762 |
|
---|
763 | extern PRUint32 connectCount;
|
---|
764 |
|
---|
765 | #endif /* XP_BEOS */
|
---|
766 |
|
---|
767 | PR_END_EXTERN_C
|
---|
768 |
|
---|
769 | #endif /* primpl_h___ */
|
---|