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 | * These flags are used by NSPR temporarily in the poll
|
---|
227 | * descriptor's out_flags field to record the mapping of
|
---|
228 | * NSPR's poll flags to the system poll flags.
|
---|
229 | *
|
---|
230 | * If _PR_POLL_READ_SYS_WRITE bit is set, it means the
|
---|
231 | * PR_POLL_READ flag specified by the topmost layer is
|
---|
232 | * mapped to the WRITE flag at the system layer. Similarly
|
---|
233 | * for the other three _PR_POLL_XXX_SYS_YYY flags. It is
|
---|
234 | * assumed that the PR_POLL_EXCEPT flag doesn't get mapped
|
---|
235 | * to other flags.
|
---|
236 | */
|
---|
237 | #define _PR_POLL_READ_SYS_READ 0x1
|
---|
238 | #define _PR_POLL_READ_SYS_WRITE 0x2
|
---|
239 | #define _PR_POLL_WRITE_SYS_READ 0x4
|
---|
240 | #define _PR_POLL_WRITE_SYS_WRITE 0x8
|
---|
241 |
|
---|
242 | /*
|
---|
243 | ** These methods are coerced into file descriptor methods table
|
---|
244 | ** when the intended service is inappropriate for the particular
|
---|
245 | ** type of file descriptor.
|
---|
246 | */
|
---|
247 | extern PRIntn _PR_InvalidInt(void);
|
---|
248 | extern PRInt16 _PR_InvalidInt16(void);
|
---|
249 | extern PRInt64 _PR_InvalidInt64(void);
|
---|
250 | extern PRStatus _PR_InvalidStatus(void);
|
---|
251 | extern PRFileDesc *_PR_InvalidDesc(void);
|
---|
252 |
|
---|
253 | extern PRIOMethods _pr_faulty_methods;
|
---|
254 |
|
---|
255 | /*
|
---|
256 | ** The PR_NETADDR_SIZE macro can only be called on a PRNetAddr union
|
---|
257 | ** whose 'family' field is set. It returns the size of the union
|
---|
258 | ** member corresponding to the specified address family.
|
---|
259 | */
|
---|
260 |
|
---|
261 | extern PRUintn _PR_NetAddrSize(const PRNetAddr* addr);
|
---|
262 |
|
---|
263 | #if defined(_PR_INET6)
|
---|
264 |
|
---|
265 | #define PR_NETADDR_SIZE(_addr) _PR_NetAddrSize(_addr)
|
---|
266 |
|
---|
267 | #elif defined(_PR_HAVE_MD_SOCKADDR_IN6)
|
---|
268 |
|
---|
269 | /*
|
---|
270 | ** Under the following conditions:
|
---|
271 | ** 1. _PR_INET6 is not defined;
|
---|
272 | ** 2. _PR_INET6_PROBE is defined;
|
---|
273 | ** 3. struct sockaddr_in6 has nonstandard fields at the end
|
---|
274 | ** (e.g., on Solaris 8),
|
---|
275 | ** (_addr)->ipv6 is smaller than struct sockaddr_in6, and
|
---|
276 | ** hence we can't pass sizeof((_addr)->ipv6) to socket
|
---|
277 | ** functions such as connect because they would fail with
|
---|
278 | ** EINVAL.
|
---|
279 | **
|
---|
280 | ** To pass the correct socket address length to socket
|
---|
281 | ** functions, define the macro _PR_HAVE_MD_SOCKADDR_IN6 and
|
---|
282 | ** define struct _md_sockaddr_in6 to be isomorphic to
|
---|
283 | ** struct sockaddr_in6.
|
---|
284 | */
|
---|
285 |
|
---|
286 | #if defined(XP_UNIX) || defined(XP_OS2_EMX)
|
---|
287 | #define PR_NETADDR_SIZE(_addr) \
|
---|
288 | ((_addr)->raw.family == PR_AF_INET \
|
---|
289 | ? sizeof((_addr)->inet) \
|
---|
290 | : ((_addr)->raw.family == PR_AF_INET6 \
|
---|
291 | ? sizeof(struct _md_sockaddr_in6) \
|
---|
292 | : sizeof((_addr)->local)))
|
---|
293 | #else
|
---|
294 | #define PR_NETADDR_SIZE(_addr) \
|
---|
295 | ((_addr)->raw.family == PR_AF_INET \
|
---|
296 | ? sizeof((_addr)->inet) \
|
---|
297 | : sizeof(struct _md_sockaddr_in6)
|
---|
298 | #endif /* defined(XP_UNIX) */
|
---|
299 |
|
---|
300 | #else
|
---|
301 |
|
---|
302 | #if defined(XP_UNIX) || defined(XP_OS2_EMX)
|
---|
303 | #define PR_NETADDR_SIZE(_addr) \
|
---|
304 | ((_addr)->raw.family == PR_AF_INET \
|
---|
305 | ? sizeof((_addr)->inet) \
|
---|
306 | : ((_addr)->raw.family == PR_AF_INET6 \
|
---|
307 | ? sizeof((_addr)->ipv6) \
|
---|
308 | : sizeof((_addr)->local)))
|
---|
309 | #else
|
---|
310 | #define PR_NETADDR_SIZE(_addr) \
|
---|
311 | ((_addr)->raw.family == PR_AF_INET \
|
---|
312 | ? sizeof((_addr)->inet) \
|
---|
313 | : sizeof((_addr)->ipv6))
|
---|
314 | #endif /* defined(XP_UNIX) */
|
---|
315 |
|
---|
316 | #endif /* defined(_PR_INET6) */
|
---|
317 |
|
---|
318 | extern PRStatus _PR_MapOptionName(
|
---|
319 | PRSockOption optname, PRInt32 *level, PRInt32 *name);
|
---|
320 | extern void _PR_InitThreads(
|
---|
321 | PRThreadType type, PRThreadPriority priority, PRUintn maxPTDs);
|
---|
322 |
|
---|
323 | struct PRLock {
|
---|
324 | pthread_mutex_t mutex; /* the underlying lock */
|
---|
325 | _PT_Notified notified; /* array of conditions notified */
|
---|
326 | PRBool locked; /* whether the mutex is locked */
|
---|
327 | pthread_t owner; /* if locked, current lock owner */
|
---|
328 | };
|
---|
329 |
|
---|
330 | extern void _PR_InitLocks(void);
|
---|
331 |
|
---|
332 | struct PRCondVar {
|
---|
333 | PRLock *lock; /* associated lock that protects the condition */
|
---|
334 | pthread_cond_t cv; /* underlying pthreads condition */
|
---|
335 | volatile uint32_t notify_pending; /* CV has destroy pending notification */
|
---|
336 | };
|
---|
337 |
|
---|
338 | /************************************************************************/
|
---|
339 |
|
---|
340 | struct PRMonitor {
|
---|
341 | const char* name; /* monitor name for debugging */
|
---|
342 | PRLock lock; /* the lock structure */
|
---|
343 | pthread_t owner; /* the owner of the lock or invalid */
|
---|
344 | PRCondVar *cvar; /* condition variable queue */
|
---|
345 | PRUint32 entryCount; /* # of times re-entered */
|
---|
346 | };
|
---|
347 |
|
---|
348 | /************************************************************************/
|
---|
349 |
|
---|
350 | struct PRSemaphore {
|
---|
351 | PRCondVar *cvar; /* associated lock and condition variable queue */
|
---|
352 | PRUintn count; /* the value of the counting semaphore */
|
---|
353 | PRUint32 waiters; /* threads waiting on the semaphore */
|
---|
354 | };
|
---|
355 |
|
---|
356 | NSPR_API(void) _PR_InitSem(void);
|
---|
357 |
|
---|
358 | /*************************************************************************/
|
---|
359 |
|
---|
360 | struct PRSem {
|
---|
361 | #ifdef _PR_HAVE_POSIX_SEMAPHORES
|
---|
362 | sem_t *sem;
|
---|
363 | #elif defined(_PR_HAVE_SYSV_SEMAPHORES)
|
---|
364 | int semid;
|
---|
365 | #elif defined(WIN32)
|
---|
366 | HANDLE sem;
|
---|
367 | #else
|
---|
368 | PRInt8 notused;
|
---|
369 | #endif
|
---|
370 | };
|
---|
371 |
|
---|
372 | /************************************************************************/
|
---|
373 |
|
---|
374 | typedef void (PR_CALLBACK *_PRStartFn)(void *);
|
---|
375 |
|
---|
376 | struct PRThread {
|
---|
377 | PRUint32 state; /* thread's creation state */
|
---|
378 | PRThreadPriority priority; /* apparent priority, loosly defined */
|
---|
379 |
|
---|
380 | void *arg; /* argument to the client's entry point */
|
---|
381 | _PRStartFn startFunc; /* the root of the client's thread */
|
---|
382 |
|
---|
383 | void *environment; /* pointer to execution environment */
|
---|
384 |
|
---|
385 | /*
|
---|
386 | ** Per thread private data
|
---|
387 | */
|
---|
388 | PRUint32 tpdLength; /* thread's current vector length */
|
---|
389 | void **privateData; /* private data vector or NULL */
|
---|
390 | PRErrorCode errorCode; /* current NSPR error code | zero */
|
---|
391 | PRInt32 osErrorCode; /* mapping of errorCode | zero */
|
---|
392 | PRIntn errorStringLength; /* textLength from last call to PR_SetErrorText() */
|
---|
393 | PRInt32 errorStringSize; /* malloc()'d size of buffer | zero */
|
---|
394 | char *errorString; /* current error string | NULL */
|
---|
395 |
|
---|
396 | pthread_t id; /* pthread identifier for the thread */
|
---|
397 | PRBool okToDelete; /* ok to delete the PRThread struct? */
|
---|
398 | PRCondVar *waiting; /* where the thread is waiting | NULL */
|
---|
399 | void *sp; /* recorded sp for garbage collection */
|
---|
400 | PRThread *next, *prev; /* simple linked list of all threads */
|
---|
401 | PRUint32 suspend; /* used to store suspend and resume flags */
|
---|
402 | #ifdef PT_NO_SIGTIMEDWAIT
|
---|
403 | pthread_mutex_t suspendResumeMutex;
|
---|
404 | pthread_cond_t suspendResumeCV;
|
---|
405 | #endif
|
---|
406 | PRUint32 interrupt_blocked; /* interrupt blocked */
|
---|
407 | struct pollfd *syspoll_list; /* Unix polling list used by PR_Poll */
|
---|
408 | PRUint32 syspoll_count; /* number of elements in syspoll_list */
|
---|
409 | };
|
---|
410 |
|
---|
411 | struct PRProcessAttr {
|
---|
412 | PRFileDesc *stdinFd;
|
---|
413 | PRFileDesc *stdoutFd;
|
---|
414 | PRFileDesc *stderrFd;
|
---|
415 | char *currentDirectory;
|
---|
416 | char *fdInheritBuffer;
|
---|
417 | PRSize fdInheritBufferSize;
|
---|
418 | PRSize fdInheritBufferUsed;
|
---|
419 | };
|
---|
420 |
|
---|
421 | struct PRProcess {
|
---|
422 | _MDProcess md;
|
---|
423 | };
|
---|
424 |
|
---|
425 | /************************************************************************/
|
---|
426 |
|
---|
427 | /*
|
---|
428 | ** File descriptors of the NSPR layer can be in one of the
|
---|
429 | ** following states (stored in the 'state' field of struct
|
---|
430 | ** PRFilePrivate):
|
---|
431 | ** - _PR_FILEDESC_OPEN: The OS fd is open.
|
---|
432 | ** - _PR_FILEDESC_CLOSED: The OS fd is closed. The PRFileDesc
|
---|
433 | ** is still open but is unusable. The only operation allowed
|
---|
434 | ** on the PRFileDesc is PR_Close().
|
---|
435 | ** - _PR_FILEDESC_FREED: The OS fd is closed and the PRFileDesc
|
---|
436 | ** structure is freed.
|
---|
437 | */
|
---|
438 |
|
---|
439 | #define _PR_FILEDESC_OPEN 0xaaaaaaaa /* 1010101... */
|
---|
440 | #define _PR_FILEDESC_CLOSED 0x55555555 /* 0101010... */
|
---|
441 | #define _PR_FILEDESC_FREED 0x11111111
|
---|
442 |
|
---|
443 | /*
|
---|
444 | ** A boolean type with an additional "unknown" state
|
---|
445 | */
|
---|
446 |
|
---|
447 | typedef enum {
|
---|
448 | _PR_TRI_TRUE = 1,
|
---|
449 | _PR_TRI_FALSE = 0,
|
---|
450 | _PR_TRI_UNKNOWN = -1
|
---|
451 | } _PRTriStateBool;
|
---|
452 |
|
---|
453 | struct PRFilePrivate {
|
---|
454 | PRInt32 state;
|
---|
455 | PRBool nonblocking;
|
---|
456 | _PRTriStateBool inheritable;
|
---|
457 | PRFileDesc *next;
|
---|
458 | PRIntn lockCount; /* 0: not locked
|
---|
459 | * -1: a native lockfile call is in progress
|
---|
460 | * > 0: # times the file is locked */
|
---|
461 | #ifdef _PR_HAVE_PEEK_BUFFER
|
---|
462 | char *peekBuffer;
|
---|
463 | PRInt32 peekBufSize;
|
---|
464 | PRInt32 peekBytes;
|
---|
465 | #endif
|
---|
466 | #if !defined(XP_UNIX) /* BugZilla: 4090 */
|
---|
467 | PRBool appendMode;
|
---|
468 | #endif
|
---|
469 | _MDFileDesc md;
|
---|
470 | #ifdef _PR_STRICT_ADDR_LEN
|
---|
471 | PRUint16 af; /* If the platform requires passing the exact
|
---|
472 | * length of the sockaddr structure for the
|
---|
473 | * address family of the socket to socket
|
---|
474 | * functions like accept(), we need to save
|
---|
475 | * the address family of the socket. */
|
---|
476 | #endif
|
---|
477 | };
|
---|
478 |
|
---|
479 | extern void _PR_InitSegs(void);
|
---|
480 | extern void _PR_InitStacks(void);
|
---|
481 | extern void _PR_InitMem(void);
|
---|
482 | extern void _PR_InitIO(void);
|
---|
483 | extern void _PR_InitLog(void);
|
---|
484 | extern void _PR_InitNet(void);
|
---|
485 | extern void _PR_InitClock(void);
|
---|
486 | extern void _PR_InitCPUs(void);
|
---|
487 | extern void _PR_InitDtoa(void);
|
---|
488 | extern void _PR_InitMW(void);
|
---|
489 | extern void _PR_NotifyCondVar(PRCondVar *cvar, PRThread *me);
|
---|
490 | extern void _PR_CleanupThread(PRThread *thread);
|
---|
491 | extern void _PR_CleanupMW(void);
|
---|
492 | extern void _PR_CleanupDtoa(void);
|
---|
493 | extern void _PR_CleanupIO(void);
|
---|
494 | extern void _PR_CleanupNet(void);
|
---|
495 | extern void _PR_CleanupLayerCache(void);
|
---|
496 | extern void _PR_CleanupStacks(void);
|
---|
497 | #ifdef WINNT
|
---|
498 | extern void _PR_CleanupCPUs(void);
|
---|
499 | #endif
|
---|
500 | extern void _PR_CleanupThreads(void);
|
---|
501 | extern void _PR_CleanupTPD(void);
|
---|
502 | extern void _PR_Cleanup(void);
|
---|
503 | extern void _PR_LogCleanup(void);
|
---|
504 | extern void _PR_InitLayerCache(void);
|
---|
505 |
|
---|
506 | extern PRBool _pr_initialized;
|
---|
507 | extern void _PR_ImplicitInitialization(void);
|
---|
508 |
|
---|
509 | /************************************************************************/
|
---|
510 |
|
---|
511 | struct PRSegment {
|
---|
512 | void *vaddr;
|
---|
513 | PRUint32 size;
|
---|
514 | PRUintn flags;
|
---|
515 | };
|
---|
516 |
|
---|
517 | /* PRSegment.flags */
|
---|
518 | #define _PR_SEG_VM 0x1
|
---|
519 |
|
---|
520 | /************************************************************************/
|
---|
521 |
|
---|
522 | extern PRInt32 _pr_pageSize;
|
---|
523 | extern PRInt32 _pr_pageShift;
|
---|
524 |
|
---|
525 | extern PRLogModuleInfo *_pr_clock_lm;
|
---|
526 | extern PRLogModuleInfo *_pr_cmon_lm;
|
---|
527 | extern PRLogModuleInfo *_pr_io_lm;
|
---|
528 | extern PRLogModuleInfo *_pr_cvar_lm;
|
---|
529 | extern PRLogModuleInfo *_pr_mon_lm;
|
---|
530 | extern PRLogModuleInfo *_pr_linker_lm;
|
---|
531 | extern PRLogModuleInfo *_pr_sched_lm;
|
---|
532 | extern PRLogModuleInfo *_pr_thread_lm;
|
---|
533 | extern PRLogModuleInfo *_pr_gc_lm;
|
---|
534 |
|
---|
535 | extern PRFileDesc *_pr_stdin;
|
---|
536 | extern PRFileDesc *_pr_stdout;
|
---|
537 | extern PRFileDesc *_pr_stderr;
|
---|
538 |
|
---|
539 |
|
---|
540 | /*************************************************************************
|
---|
541 | * External machine-dependent code provided by each OS. * *
|
---|
542 | *************************************************************************/
|
---|
543 |
|
---|
544 | /* Initialization related */
|
---|
545 | extern void _PR_MD_EARLY_INIT(void);
|
---|
546 | #define _PR_MD_EARLY_INIT _MD_EARLY_INIT
|
---|
547 |
|
---|
548 | extern void _PR_MD_INTERVAL_INIT(void);
|
---|
549 | #define _PR_MD_INTERVAL_INIT _MD_INTERVAL_INIT
|
---|
550 |
|
---|
551 | NSPR_API(void) _PR_MD_FINAL_INIT(void);
|
---|
552 | #define _PR_MD_FINAL_INIT _MD_FINAL_INIT
|
---|
553 |
|
---|
554 | /* Process control */
|
---|
555 |
|
---|
556 | #ifdef _MD_CREATE_PROCESS_DETACHED
|
---|
557 | # define _PR_MD_CREATE_PROCESS_DETACHED _MD_CREATE_PROCESS_DETACHED
|
---|
558 | #endif
|
---|
559 |
|
---|
560 | /* Current Time */
|
---|
561 | NSPR_API(PRTime) _PR_MD_NOW(void);
|
---|
562 | #define _PR_MD_NOW _MD_NOW
|
---|
563 |
|
---|
564 | /* Environment related */
|
---|
565 | extern char* _PR_MD_GET_ENV(const char *name);
|
---|
566 | #define _PR_MD_GET_ENV _MD_GET_ENV
|
---|
567 |
|
---|
568 | extern PRIntn _PR_MD_PUT_ENV(const char *name);
|
---|
569 | #define _PR_MD_PUT_ENV _MD_PUT_ENV
|
---|
570 |
|
---|
571 | /* Atomic operations */
|
---|
572 |
|
---|
573 | extern void _PR_MD_INIT_ATOMIC(void);
|
---|
574 | #define _PR_MD_INIT_ATOMIC _MD_INIT_ATOMIC
|
---|
575 |
|
---|
576 | extern PRInt32 _PR_MD_ATOMIC_INCREMENT(PRInt32 *);
|
---|
577 | #define _PR_MD_ATOMIC_INCREMENT _MD_ATOMIC_INCREMENT
|
---|
578 |
|
---|
579 | extern PRInt32 _PR_MD_ATOMIC_ADD(PRInt32 *, PRInt32);
|
---|
580 | #define _PR_MD_ATOMIC_ADD _MD_ATOMIC_ADD
|
---|
581 |
|
---|
582 | extern PRInt32 _PR_MD_ATOMIC_DECREMENT(PRInt32 *);
|
---|
583 | #define _PR_MD_ATOMIC_DECREMENT _MD_ATOMIC_DECREMENT
|
---|
584 |
|
---|
585 | extern PRInt32 _PR_MD_ATOMIC_SET(PRInt32 *, PRInt32);
|
---|
586 | #define _PR_MD_ATOMIC_SET _MD_ATOMIC_SET
|
---|
587 |
|
---|
588 | /* Time intervals */
|
---|
589 |
|
---|
590 | extern PRIntervalTime _PR_MD_GET_INTERVAL(void);
|
---|
591 | #define _PR_MD_GET_INTERVAL _MD_GET_INTERVAL
|
---|
592 |
|
---|
593 | extern PRIntervalTime _PR_MD_INTERVAL_PER_SEC(void);
|
---|
594 | #define _PR_MD_INTERVAL_PER_SEC _MD_INTERVAL_PER_SEC
|
---|
595 |
|
---|
596 | /* Affinity masks */
|
---|
597 |
|
---|
598 | extern PRInt32 _PR_MD_SETTHREADAFFINITYMASK(PRThread *thread, PRUint32 mask );
|
---|
599 | #define _PR_MD_SETTHREADAFFINITYMASK _MD_SETTHREADAFFINITYMASK
|
---|
600 |
|
---|
601 | extern PRInt32 _PR_MD_GETTHREADAFFINITYMASK(PRThread *thread, PRUint32 *mask);
|
---|
602 | #define _PR_MD_GETTHREADAFFINITYMASK _MD_GETTHREADAFFINITYMASK
|
---|
603 |
|
---|
604 | /* File locking */
|
---|
605 |
|
---|
606 | extern PRStatus _PR_MD_LOCKFILE(PRInt32 osfd);
|
---|
607 | #define _PR_MD_LOCKFILE _MD_LOCKFILE
|
---|
608 |
|
---|
609 | extern PRStatus _PR_MD_TLOCKFILE(PRInt32 osfd);
|
---|
610 | #define _PR_MD_TLOCKFILE _MD_TLOCKFILE
|
---|
611 |
|
---|
612 | extern PRStatus _PR_MD_UNLOCKFILE(PRInt32 osfd);
|
---|
613 | #define _PR_MD_UNLOCKFILE _MD_UNLOCKFILE
|
---|
614 |
|
---|
615 | /* Socket call error code */
|
---|
616 |
|
---|
617 | NSPR_API(PRInt32) _PR_MD_GET_SOCKET_ERROR(void);
|
---|
618 | #define _PR_MD_GET_SOCKET_ERROR _MD_GET_SOCKET_ERROR
|
---|
619 |
|
---|
620 | /* Get name of current host */
|
---|
621 | extern PRStatus _PR_MD_GETHOSTNAME(char *name, PRUint32 namelen);
|
---|
622 | #define _PR_MD_GETHOSTNAME _MD_GETHOSTNAME
|
---|
623 |
|
---|
624 | /* File descriptor inheritance */
|
---|
625 |
|
---|
626 | /*
|
---|
627 | * If fd->secret->inheritable is _PR_TRI_UNKNOWN and we need to
|
---|
628 | * know the inheritable attribute of the fd, call this function
|
---|
629 | * to find that out. This typically requires a system call.
|
---|
630 | */
|
---|
631 | extern void _PR_MD_QUERY_FD_INHERITABLE(PRFileDesc *fd);
|
---|
632 | #define _PR_MD_QUERY_FD_INHERITABLE _MD_QUERY_FD_INHERITABLE
|
---|
633 |
|
---|
634 | PR_END_EXTERN_C
|
---|
635 |
|
---|
636 | #endif /* primpl_h___ */
|
---|