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