Back to index

lightning-sunbird  0.9+nobinonly
_unixos.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef prunixos_h___
00039 #define prunixos_h___
00040 
00041 /*
00042  * If FD_SETSIZE is not defined on the command line, set the default value
00043  * before include select.h
00044  */
00045 /*
00046  * Linux: FD_SETSIZE is defined in /usr/include/sys/select.h and should
00047  * not be redefined.
00048  */
00049 #if !defined(LINUX) && !defined(DARWIN) && !defined(NEXTSTEP)
00050 #ifndef FD_SETSIZE
00051 #define FD_SETSIZE  4096
00052 #endif
00053 #endif
00054 
00055 #include <unistd.h>
00056 #include <stddef.h>
00057 #include <sys/stat.h>
00058 #include <dirent.h>
00059 #include <errno.h>
00060 
00061 #include "prio.h"
00062 #include "prmem.h"
00063 #include "prclist.h"
00064 
00065 /*
00066  * For select(), fd_set, and struct timeval.
00067  *
00068  * In The Single UNIX(R) Specification, Version 2,
00069  * the header file for select() is <sys/time.h>.
00070  *
00071  * fd_set is defined in <sys/types.h>.  Usually
00072  * <sys/time.h> includes <sys/types.h>, but on some
00073  * older systems <sys/time.h> does not include
00074  * <sys/types.h>, so we include it explicitly.
00075  */
00076 #include <sys/time.h>
00077 #include <sys/types.h>
00078 #if defined(AIX)  /* Only pre-4.2 AIX needs it, but for simplicity... */
00079 #include <sys/select.h>
00080 #endif
00081 
00082 #define _PR_HAVE_O_APPEND
00083 
00084 #define PR_DIRECTORY_SEPARATOR            '/'
00085 #define PR_DIRECTORY_SEPARATOR_STR "/"
00086 #define PR_PATH_SEPARATOR          ':'
00087 #define PR_PATH_SEPARATOR_STR             ":"
00088 #define GCPTR
00089 typedef int (*FARPROC)();
00090 
00091 /*
00092  * intervals at which GLOBAL threads wakeup to check for pending interrupt
00093  */
00094 #define _PR_INTERRUPT_CHECK_INTERVAL_SECS 5
00095 extern PRIntervalTime intr_timeout_ticks;
00096 
00097 /*
00098  * The bit flags for the in_flags and out_flags fields
00099  * of _PR_UnixPollDesc
00100  */
00101 #ifdef _PR_USE_POLL
00102 #define _PR_UNIX_POLL_READ    POLLIN
00103 #define _PR_UNIX_POLL_WRITE   POLLOUT
00104 #define _PR_UNIX_POLL_EXCEPT  POLLPRI
00105 #define _PR_UNIX_POLL_ERR     POLLERR
00106 #define _PR_UNIX_POLL_NVAL    POLLNVAL
00107 #define _PR_UNIX_POLL_HUP     POLLHUP
00108 #else /* _PR_USE_POLL */
00109 #define _PR_UNIX_POLL_READ    0x1
00110 #define _PR_UNIX_POLL_WRITE   0x2
00111 #define _PR_UNIX_POLL_EXCEPT  0x4
00112 #define _PR_UNIX_POLL_ERR     0x8
00113 #define _PR_UNIX_POLL_NVAL    0x10
00114 #define _PR_UNIX_POLL_HUP     0x20
00115 #endif /* _PR_USE_POLL */
00116 
00117 typedef struct _PRUnixPollDesc {
00118        PRInt32 osfd;
00119        PRInt16 in_flags;
00120        PRInt16 out_flags;
00121 } _PRUnixPollDesc;
00122 
00123 typedef struct PRPollQueue {
00124     PRCList links;        /* for linking PRPollQueue's together */
00125     _PRUnixPollDesc *pds;        /* array of poll descriptors */
00126     PRUintn npds;            /* length of the array */
00127     PRPackedBool on_ioq;    /* is this on the async i/o work q? */
00128     PRIntervalTime timeout;        /* timeout, in ticks */
00129     struct PRThread *thr;
00130 } PRPollQueue;
00131 
00132 #define _PR_POLLQUEUE_PTR(_qp) \
00133     ((PRPollQueue*) ((char*) (_qp) - offsetof(PRPollQueue,links)))
00134 
00135 
00136 extern PRInt32 _PR_WaitForMultipleFDs(
00137     _PRUnixPollDesc *unixpds,
00138     PRInt32 pdcnt,
00139     PRIntervalTime timeout);
00140 extern void _PR_Unblock_IO_Wait(struct PRThread *thr);
00141 
00142 #if defined(_PR_LOCAL_THREADS_ONLY) || defined(_PR_GLOBAL_THREADS_ONLY)
00143 #define _MD_CHECK_FOR_EXIT()
00144 #endif
00145 
00146 extern fd_set _pr_md_read_set, _pr_md_write_set, _pr_md_exception_set;
00147 extern PRInt16 _pr_md_read_cnt[], _pr_md_write_cnt[], _pr_md_exception_cnt[];
00148 extern PRInt32 _pr_md_ioq_max_osfd;
00149 extern PRUint32 _pr_md_ioq_timeout;
00150 
00151 struct _MDFileDesc {
00152     int osfd;
00153 #if defined(LINUX) && defined(_PR_PTHREADS)
00154     int tcp_nodelay;  /* used by pt_LinuxSendFile */
00155 #endif
00156 };
00157 
00158 struct _MDDir {
00159        DIR *d;
00160 };
00161 
00162 struct _PRCPU;
00163 extern void _MD_unix_init_running_cpu(struct _PRCPU *cpu);
00164 
00165 /*
00166 ** Make a redzone at both ends of the stack segment. Disallow access
00167 ** to those pages of memory. It's ok if the mprotect call's don't
00168 ** work - it just means that we don't really have a functional
00169 ** redzone.
00170 */
00171 #include <sys/mman.h>
00172 #ifndef PROT_NONE
00173 #define PROT_NONE 0x0
00174 #endif
00175 
00176 #if defined(DEBUG) && !defined(DARWIN) && !defined(NEXTSTEP)
00177 #if !defined(SOLARIS)       
00178 #include <string.h>  /* for memset() */
00179 #define _MD_INIT_STACK(ts,REDZONE)                             \
00180     PR_BEGIN_MACRO                                                    \
00181        (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE);    \
00182        (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
00183                      REDZONE, PROT_NONE);                      \
00184     /*                                                         \
00185     ** Fill stack memory with something that turns into an illegal    \
00186     ** pointer value. This will sometimes find runtime references to  \
00187     ** uninitialized pointers. We don't do this for solaris because we       \
00188     ** can use purify instead.                                        \
00189     */                                                         \
00190     if (_pr_debugStacks) {                                     \
00191        memset(ts->allocBase + REDZONE, 0xf7, ts->stackSize);          \
00192     }                                                          \
00193     PR_END_MACRO
00194 #else  /* !SOLARIS   */
00195 #define _MD_INIT_STACK(ts,REDZONE)                             \
00196     PR_BEGIN_MACRO                                                    \
00197        (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE);    \
00198        (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
00199                      REDZONE, PROT_NONE);                      \
00200     PR_END_MACRO
00201 #endif /* !SOLARIS   */
00202 
00203 /*
00204  * _MD_CLEAR_STACK
00205  *     Allow access to the redzone pages; the access was turned off in
00206  *     _MD_INIT_STACK.
00207  */
00208 #define _MD_CLEAR_STACK(ts)                                    \
00209     PR_BEGIN_MACRO                                                    \
00210        (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_READ|PROT_WRITE);\
00211        (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
00212                      REDZONE, PROT_READ|PROT_WRITE);                  \
00213     PR_END_MACRO
00214 
00215 #else  /* DEBUG */
00216 
00217 #define _MD_INIT_STACK(ts,REDZONE)
00218 #define _MD_CLEAR_STACK(ts)
00219 
00220 #endif /* DEBUG */
00221 
00222 #if !defined(SOLARIS) 
00223 
00224 #define PR_SET_INTSOFF(newval)
00225 
00226 #endif
00227 
00228 /************************************************************************/
00229 
00230 extern void _PR_UnixInit(void);
00231 
00232 /************************************************************************/
00233 
00234 struct _MDProcess {
00235     pid_t pid;
00236 };
00237 
00238 struct PRProcess;
00239 struct PRProcessAttr;
00240 
00241 /* Create a new process (fork() + exec()) */
00242 #define _MD_CREATE_PROCESS _MD_CreateUnixProcess
00243 extern struct PRProcess * _MD_CreateUnixProcess(
00244     const char *path,
00245     char *const *argv,
00246     char *const *envp,
00247     const struct PRProcessAttr *attr
00248 );
00249 
00250 #define _MD_DETACH_PROCESS _MD_DetachUnixProcess
00251 extern PRStatus _MD_DetachUnixProcess(struct PRProcess *process);
00252 
00253 /* Wait for a child process to terminate */
00254 #define _MD_WAIT_PROCESS _MD_WaitUnixProcess
00255 extern PRStatus _MD_WaitUnixProcess(struct PRProcess *process,
00256     PRInt32 *exitCode);
00257 
00258 #define _MD_KILL_PROCESS _MD_KillUnixProcess
00259 extern PRStatus _MD_KillUnixProcess(struct PRProcess *process);
00260 
00261 /************************************************************************/
00262 
00263 extern void _MD_EnableClockInterrupts(void);
00264 extern void _MD_DisableClockInterrupts(void);
00265 
00266 #define _MD_START_INTERRUPTS                     _MD_StartInterrupts
00267 #define _MD_STOP_INTERRUPTS                      _MD_StopInterrupts
00268 #define _MD_DISABLE_CLOCK_INTERRUPTS      _MD_DisableClockInterrupts
00269 #define _MD_ENABLE_CLOCK_INTERRUPTS              _MD_EnableClockInterrupts
00270 #define _MD_BLOCK_CLOCK_INTERRUPTS        _MD_BlockClockInterrupts
00271 #define _MD_UNBLOCK_CLOCK_INTERRUPTS      _MD_UnblockClockInterrupts
00272 
00273 /************************************************************************/
00274 
00275 extern void          _MD_InitCPUS(void);
00276 #define _MD_INIT_CPUS           _MD_InitCPUS
00277 
00278 extern void          _MD_Wakeup_CPUs(void);
00279 #define _MD_WAKEUP_CPUS _MD_Wakeup_CPUs
00280 
00281 #define _MD_PAUSE_CPU                     _MD_PauseCPU
00282 
00283 #if defined(_PR_LOCAL_THREADS_ONLY) || defined(_PR_GLOBAL_THREADS_ONLY)
00284 #define _MD_CLEANUP_BEFORE_EXIT()
00285 #endif
00286 
00287 #ifndef IRIX
00288 #define _MD_EXIT(status)           _exit(status)
00289 #endif
00290 
00291 /************************************************************************/
00292 
00293 #define _MD_GET_ENV                       getenv
00294 #define _MD_PUT_ENV                       putenv
00295 
00296 /************************************************************************/
00297 
00298 #define _MD_INIT_FILEDESC(fd)
00299 
00300 extern void          _MD_MakeNonblock(PRFileDesc *fd);
00301 #define _MD_MAKE_NONBLOCK                 _MD_MakeNonblock            
00302 
00303 /************************************************************************/
00304 
00305 #if !defined(_PR_PTHREADS)
00306 
00307 extern void          _MD_InitSegs(void);
00308 extern PRStatus      _MD_AllocSegment(PRSegment *seg, PRUint32 size,
00309                             void *vaddr);
00310 extern void          _MD_FreeSegment(PRSegment *seg);
00311 
00312 #define _MD_INIT_SEGS                     _MD_InitSegs
00313 #define _MD_ALLOC_SEGMENT          _MD_AllocSegment
00314 #define _MD_FREE_SEGMENT           _MD_FreeSegment
00315 
00316 #endif /* !defined(_PR_PTHREADS) */
00317 
00318 /************************************************************************/
00319 
00320 #if !defined(HPUX_LW_TIMER)
00321 #define _MD_INTERVAL_INIT()
00322 #endif
00323 #define _MD_INTERVAL_PER_MILLISEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000)
00324 #define _MD_INTERVAL_PER_MICROSEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000000)
00325 
00326 /************************************************************************/
00327 
00328 #define _MD_ERRNO()                (errno)
00329 #define _MD_GET_SOCKET_ERROR()            (errno)
00330 
00331 /************************************************************************/
00332 
00333 extern PRInt32 _MD_AvailableSocket(PRInt32 osfd);
00334 
00335 extern void _MD_StartInterrupts(void);
00336 extern void _MD_StopInterrupts(void);
00337 extern void _MD_DisableClockInterrupts(void);
00338 extern void _MD_BlockClockInterrupts(void);
00339 extern void _MD_UnblockClockInterrupts(void);
00340 extern void _MD_PauseCPU(PRIntervalTime timeout);
00341 
00342 extern PRStatus _MD_open_dir(struct _MDDir *, const char *);
00343 extern PRInt32  _MD_close_dir(struct _MDDir *);
00344 extern char *   _MD_read_dir(struct _MDDir *, PRIntn);
00345 extern PRInt32  _MD_open(const char *name, PRIntn osflags, PRIntn mode);
00346 extern PRInt32       _MD_delete(const char *name);
00347 extern PRInt32       _MD_getfileinfo(const char *fn, PRFileInfo *info);
00348 extern PRInt32  _MD_getfileinfo64(const char *fn, PRFileInfo64 *info);
00349 extern PRInt32  _MD_getopenfileinfo(const PRFileDesc *fd, PRFileInfo *info);
00350 extern PRInt32  _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info);
00351 extern PRInt32       _MD_rename(const char *from, const char *to);
00352 extern PRInt32       _MD_access(const char *name, PRAccessHow how);
00353 extern PRInt32       _MD_mkdir(const char *name, PRIntn mode);
00354 extern PRInt32       _MD_rmdir(const char *name);
00355 extern PRInt32       _MD_accept_read(PRInt32 sock, PRInt32 *newSock,
00356                             PRNetAddr **raddr, void *buf, PRInt32 amount);
00357 extern PRInt32       _PR_UnixSendFile(PRFileDesc *sd, PRSendFileData *sfd,
00358                      PRTransmitFileFlags flags, PRIntervalTime timeout);
00359 
00360 extern PRStatus _MD_LockFile(PRInt32 osfd);
00361 extern PRStatus _MD_TLockFile(PRInt32 osfd);
00362 extern PRStatus _MD_UnlockFile(PRInt32 osfd);
00363 
00364 #define _MD_OPEN_DIR(dir, name)               _MD_open_dir(dir, name)
00365 #define _MD_CLOSE_DIR(dir)                 _MD_close_dir(dir)
00366 #define _MD_READ_DIR(dir, flags)       _MD_read_dir(dir, flags)
00367 #define _MD_OPEN(name, osflags, mode)     _MD_open(name, osflags, mode)
00368 #define _MD_OPEN_FILE(name, osflags, mode)       _MD_open(name, osflags, mode)
00369 extern PRInt32 _MD_read(PRFileDesc *fd, void *buf, PRInt32 amount);
00370 #define _MD_READ(fd,buf,amount)               _MD_read(fd,buf,amount)
00371 extern PRInt32 _MD_write(PRFileDesc *fd, const void *buf, PRInt32 amount);
00372 #define _MD_WRITE(fd,buf,amount)       _MD_write(fd,buf,amount)
00373 #define _MD_DELETE(name)                   _MD_delete(name)
00374 #define _MD_GETFILEINFO(fn, info)      _MD_getfileinfo(fn, info)
00375 #define _MD_GETFILEINFO64(fn, info)           _MD_getfileinfo64(fn, info)
00376 #define _MD_GETOPENFILEINFO(fd, info)     _MD_getopenfileinfo(fd, info)
00377 #define _MD_GETOPENFILEINFO64(fd, info)   _MD_getopenfileinfo64(fd, info)
00378 #define _MD_RENAME(from, to)                  _MD_rename(from, to)
00379 #define _MD_ACCESS(name, how)                 _MD_access(name, how)
00380 #define _MD_MKDIR(name, mode)                 _MD_mkdir(name, mode)
00381 #define _MD_MAKE_DIR(name, mode)          _MD_mkdir(name, mode)
00382 #define _MD_RMDIR(name)                           _MD_rmdir(name)
00383 #define _MD_ACCEPT_READ(sock, newSock, raddr, buf, amount)     _MD_accept_read(sock, newSock, raddr, buf, amount)
00384 
00385 #define _MD_LOCKFILE _MD_LockFile
00386 #define _MD_TLOCKFILE _MD_TLockFile
00387 #define _MD_UNLOCKFILE _MD_UnlockFile
00388 
00389 
00390 extern PRInt32              _MD_socket(int af, int type, int flags);
00391 #define _MD_SOCKET   _MD_socket
00392 extern PRInt32              _MD_connect(PRFileDesc *fd, const PRNetAddr *addr,
00393                                                         PRUint32 addrlen, PRIntervalTime timeout);
00394 #define _MD_CONNECT  _MD_connect
00395 extern PRInt32              _MD_accept(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen,
00396                                                                                            PRIntervalTime timeout);
00397 #define _MD_ACCEPT   _MD_accept
00398 extern PRInt32              _MD_bind(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen);
00399 #define _MD_BIND     _MD_bind
00400 extern PRInt32              _MD_listen(PRFileDesc *fd, PRIntn backlog);
00401 #define _MD_LISTEN   _MD_listen
00402 extern PRInt32              _MD_shutdown(PRFileDesc *fd, PRIntn how);
00403 #define _MD_SHUTDOWN _MD_shutdown
00404 
00405 extern PRInt32              _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount, 
00406                                PRIntn flags, PRIntervalTime timeout);
00407 #define _MD_RECV     _MD_recv
00408 extern PRInt32              _MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount,
00409                                                                PRIntn flags, PRIntervalTime timeout);
00410 #define _MD_SEND     _MD_send
00411 extern PRInt32              _MD_recvfrom(PRFileDesc *fd, void *buf, PRInt32 amount,
00412                                           PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen,
00413                                                                              PRIntervalTime timeout);
00414 #define _MD_RECVFROM _MD_recvfrom
00415 extern PRInt32 _MD_sendto(PRFileDesc *fd, const void *buf, PRInt32 amount,
00416                                                  PRIntn flags, const PRNetAddr *addr, PRUint32 addrlen,
00417                                                                                     PRIntervalTime timeout);
00418 #define _MD_SENDTO   _MD_sendto
00419 extern PRInt32              _MD_writev(PRFileDesc *fd, const struct PRIOVec *iov,
00420                                                         PRInt32 iov_size, PRIntervalTime timeout);
00421 #define _MD_WRITEV   _MD_writev
00422 
00423 extern PRInt32              _MD_socketavailable(PRFileDesc *fd);
00424 #define       _MD_SOCKETAVAILABLE         _MD_socketavailable
00425 extern PRInt64              _MD_socketavailable64(PRFileDesc *fd);
00426 #define       _MD_SOCKETAVAILABLE64              _MD_socketavailable64
00427 
00428 #define       _MD_PIPEAVAILABLE           _MD_socketavailable
00429 
00430 extern PRInt32 _MD_pr_poll(PRPollDesc *pds, PRIntn npds,
00431                                                                                     PRIntervalTime timeout);
00432 #define _MD_PR_POLL         _MD_pr_poll
00433 
00434 extern PRInt32              _MD_close(PRInt32 osfd);
00435 #define _MD_CLOSE_FILE      _MD_close
00436 extern PRInt32              _MD_lseek(PRFileDesc*, PRInt32, PRSeekWhence);
00437 #define _MD_LSEEK    _MD_lseek
00438 extern PRInt64              _MD_lseek64(PRFileDesc*, PRInt64, PRSeekWhence);
00439 #define _MD_LSEEK64  _MD_lseek64
00440 extern PRInt32              _MD_fsync(PRFileDesc *fd);
00441 #define _MD_FSYNC    _MD_fsync
00442 
00443 extern PRInt32 _MD_socketpair(int af, int type, int flags, PRInt32 *osfd);
00444 #define _MD_SOCKETPAIR             _MD_socketpair
00445 
00446 #define _MD_CLOSE_SOCKET    _MD_close
00447 
00448 #ifndef NO_NSPR_10_SUPPORT
00449 #define _MD_STAT     stat
00450 #endif
00451 
00452 extern PRStatus _MD_getpeername(PRFileDesc *fd, PRNetAddr *addr,
00453                                                                              PRUint32 *addrlen);
00454 #define _MD_GETPEERNAME _MD_getpeername
00455 extern PRStatus _MD_getsockname(PRFileDesc *fd, PRNetAddr *addr,
00456                                                                              PRUint32 *addrlen);
00457 #define _MD_GETSOCKNAME _MD_getsockname
00458 
00459 extern PRStatus _MD_getsockopt(PRFileDesc *fd, PRInt32 level,
00460                                           PRInt32 optname, char* optval, PRInt32* optlen);
00461 #define _MD_GETSOCKOPT             _MD_getsockopt
00462 extern PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level,
00463                                    PRInt32 optname, const char* optval, PRInt32 optlen);
00464 #define _MD_SETSOCKOPT             _MD_setsockopt
00465 
00466 extern PRStatus _MD_set_fd_inheritable(PRFileDesc *fd, PRBool inheritable);
00467 #define _MD_SET_FD_INHERITABLE _MD_set_fd_inheritable
00468 
00469 extern void _MD_init_fd_inheritable(PRFileDesc *fd, PRBool imported);
00470 #define _MD_INIT_FD_INHERITABLE _MD_init_fd_inheritable
00471 
00472 extern void _MD_query_fd_inheritable(PRFileDesc *fd);
00473 #define _MD_QUERY_FD_INHERITABLE _MD_query_fd_inheritable
00474 
00475 extern PRStatus _MD_gethostname(char *name, PRUint32 namelen);
00476 #define _MD_GETHOSTNAME            _MD_gethostname
00477 
00478 extern PRStatus _MD_getsysinfo(PRSysInfo cmd, char *name, PRUint32 namelen);
00479 #define _MD_GETSYSINFO             _MD_getsysinfo
00480 
00481 extern int _MD_unix_get_nonblocking_connect_error(int osfd);
00482 
00483 /* Memory-mapped files */
00484 
00485 struct _MDFileMap {
00486     PRIntn prot;
00487     PRIntn flags;
00488     PRBool isAnonFM; /* when true, PR_CloseFileMap() must close the related fd */
00489 };
00490 
00491 extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
00492 #define _MD_CREATE_FILE_MAP _MD_CreateFileMap
00493 
00494 #define _MD_GET_MEM_MAP_ALIGNMENT() PR_GetPageSize()
00495 
00496 extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
00497         PRUint32 len);
00498 #define _MD_MEM_MAP _MD_MemMap
00499 
00500 extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
00501 #define _MD_MEM_UNMAP _MD_MemUnmap
00502 
00503 extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
00504 #define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
00505 
00506 /*
00507  * The standard (XPG4) gettimeofday() (from BSD) takes two arguments.
00508  * On some SVR4 derivatives, gettimeofday() takes only one argument.
00509  * The GETTIMEOFDAY macro is intended to hide this difference.
00510  */
00511 #ifdef HAVE_SVID_GETTOD
00512 #define GETTIMEOFDAY(tp) gettimeofday(tp)
00513 #else
00514 #define GETTIMEOFDAY(tp) gettimeofday((tp), NULL)
00515 #endif
00516 
00517 #if defined(_PR_PTHREADS) && !defined(_PR_POLL_AVAILABLE)
00518 #define _PR_NEED_FAKE_POLL
00519 #endif
00520 
00521 #if defined(_PR_NEED_FAKE_POLL)
00522 
00523 /*
00524  * Some platforms don't have poll(), but our pthreads code calls poll().
00525  * As a temporary measure, I implemented a fake poll() using select().
00526  * Here are the struct and macro definitions copied from sys/poll.h
00527  * on Solaris 2.5.
00528  */
00529 
00530 struct pollfd {
00531     int fd;
00532     short events;
00533     short revents;
00534 };
00535 
00536 /* poll events */
00537 
00538 #define       POLLIN        0x0001        /* fd is readable */
00539 #define       POLLPRI              0x0002        /* high priority info at fd */
00540 #define       POLLOUT              0x0004        /* fd is writeable (won't block) */
00541 #define       POLLRDNORM    0x0040        /* normal data is readable */
00542 #define       POLLWRNORM    POLLOUT
00543 #define       POLLRDBAND    0x0080        /* out-of-band data is readable */
00544 #define       POLLWRBAND    0x0100        /* out-of-band data is writeable */
00545 
00546 #define       POLLNORM      POLLRDNORM
00547 
00548 #define       POLLERR              0x0008        /* fd has error condition */
00549 #define       POLLHUP              0x0010        /* fd has been hung up on */
00550 #define       POLLNVAL      0x0020        /* invalid pollfd entry */
00551 
00552 extern int poll(struct pollfd *, unsigned long, int);
00553 
00554 #endif /* _PR_NEED_FAKE_POLL */
00555 
00556 /*
00557 ** A vector of the UNIX I/O calls we use. These are here to smooth over
00558 ** the rough edges needed for large files. All of NSPR's implmentaions
00559 ** go through this vector using syntax of the form
00560 **      result = _md_iovector.xxx64(args);
00561 */
00562 
00563 #if defined(SOLARIS2_5)
00564 /*
00565 ** Special case: Solaris 2.5.1
00566 ** Solaris starts to have 64-bit file I/O in 2.6.  We build on Solaris
00567 ** 2.5.1 so that we can use the same binaries on both Solaris 2.5.1 and
00568 ** 2.6.  At run time, we detect whether 64-bit file I/O is available by
00569 ** looking up the 64-bit file function symbols in libc.  At build time,
00570 ** we need to define the 64-bit file I/O datatypes that are compatible
00571 ** with their definitions on Solaris 2.6.
00572 */
00573 typedef PRInt64 off64_t;
00574 typedef PRUint64 ino64_t;
00575 typedef PRInt64 blkcnt64_t;
00576 struct stat64 {
00577     dev_t st_dev;
00578     long st_pad1[3];
00579     ino64_t st_ino;
00580     mode_t st_mode;
00581     nlink_t st_nlink;
00582     uid_t st_uid;
00583     gid_t st_gid;
00584     dev_t st_rdev;
00585     long t_pad2[2];
00586     off64_t st_size;
00587     timestruc_t st_atim;
00588     timestruc_t st_mtim;
00589     timestruc_t st_ctim;
00590     long st_blksize;
00591     blkcnt64_t st_blocks;
00592     char st_fstype[_ST_FSTYPSZ];
00593     long st_pad4[8];
00594 };
00595 typedef struct stat64 _MDStat64;
00596 typedef off64_t _MDOff64_t;
00597 
00598 #elif defined(_PR_HAVE_OFF64_T)
00599 typedef struct stat64 _MDStat64;
00600 typedef off64_t _MDOff64_t;
00601 #elif defined(_PR_HAVE_LARGE_OFF_T)
00602 typedef struct stat _MDStat64;
00603 typedef off_t _MDOff64_t;
00604 #elif defined(_PR_NO_LARGE_FILES)
00605 typedef struct stat _MDStat64;
00606 typedef PRInt64 _MDOff64_t;
00607 #else
00608 #error "I don't know yet"
00609 #endif
00610 
00611 typedef PRIntn (*_MD_Fstat64)(PRIntn osfd, _MDStat64 *buf);
00612 typedef PRIntn (*_MD_Open64)(const char *path, int oflag, ...);
00613 #if defined(VMS)
00614 typedef PRIntn (*_MD_Stat64)(const char *path, _MDStat64 *buf, ...);
00615 #else
00616 typedef PRIntn (*_MD_Stat64)(const char *path, _MDStat64 *buf);
00617 #endif
00618 typedef _MDOff64_t (*_MD_Lseek64)(PRIntn osfd, _MDOff64_t, PRIntn whence);
00619 typedef void* (*_MD_Mmap64)(
00620     void *addr, PRSize len, PRIntn prot, PRIntn flags,
00621     PRIntn fildes, _MDOff64_t offset);
00622 struct _MD_IOVector
00623 {
00624     _MD_Open64 _open64;
00625     _MD_Mmap64 _mmap64;
00626     _MD_Stat64 _stat64;
00627     _MD_Fstat64 _fstat64;
00628     _MD_Lseek64 _lseek64;
00629 };
00630 extern struct _MD_IOVector _md_iovector;
00631 
00632 #endif /* prunixos_h___ */