home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / md / _unixos.h < prev    next >
C/C++ Source or Header  |  1998-11-21  |  20KB  |  572 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef prunixos_h___
  20. #define prunixos_h___
  21.  
  22. /*
  23.  * If FD_SETSIZE is not defined on the command line, set the default value
  24.  * before include select.h
  25.  */
  26. /*
  27.  * Linux: FD_SETSIZE is defined in /usr/include/sys/select.h and should
  28.  * not be redefined.
  29.  */
  30. #if !defined(LINUX) && !defined(RHAPSODY) && !defined(NEXTSTEP)
  31. #ifndef FD_SETSIZE
  32. #define FD_SETSIZE  4096
  33. #endif
  34. #endif
  35.  
  36. #include <unistd.h>
  37. #include <stddef.h>
  38. #include <sys/stat.h>
  39. #include <dirent.h>
  40. #include <errno.h>
  41.  
  42. #include "prio.h"
  43. #include "prmem.h"
  44. #include "prclist.h"
  45.  
  46. /*
  47.  * For select(), fd_set, and struct timeval.
  48.  *
  49.  * In The Single UNIX(R) Specification, Version 2,
  50.  * the header file for select() is <sys/time.h>.
  51.  *
  52.  * fd_set is defined in <sys/types.h>.  Usually
  53.  * <sys/time.h> includes <sys/types.h>, but on some
  54.  * older systems <sys/time.h> does not include
  55.  * <sys/types.h>, so we include it explicitly.
  56.  */
  57. #include <sys/time.h>
  58. #include <sys/types.h>
  59. #if defined(AIX)  /* Only pre-4.2 AIX needs it, but for simplicity... */
  60. #include <sys/select.h>
  61. #endif
  62.  
  63. #define PR_DIRECTORY_SEPARATOR        '/'
  64. #define PR_DIRECTORY_SEPARATOR_STR    "/"
  65. #define PR_PATH_SEPARATOR        ':'
  66. #define PR_PATH_SEPARATOR_STR        ":"
  67. #define GCPTR
  68. typedef int (*FARPROC)();
  69.  
  70. /*
  71.  * intervals at which GLOBAL threads wakeup to check for pending interrupt
  72.  */
  73. #define _PR_INTERRUPT_CHECK_INTERVAL_SECS 5
  74. extern PRIntervalTime intr_timeout_ticks;
  75.  
  76. /*
  77.  * The bit flags for the in_flags and out_flags fields
  78.  * of _PR_UnixPollDesc
  79.  */
  80. #ifdef _PR_USE_POLL
  81. #define _PR_UNIX_POLL_READ    POLLIN
  82. #define _PR_UNIX_POLL_WRITE   POLLOUT
  83. #define _PR_UNIX_POLL_EXCEPT  POLLPRI
  84. #define _PR_UNIX_POLL_ERR     POLLERR
  85. #define _PR_UNIX_POLL_NVAL    POLLNVAL
  86. #define _PR_UNIX_POLL_HUP     POLLHUP
  87. #else /* _PR_USE_POLL */
  88. #define _PR_UNIX_POLL_READ    0x1
  89. #define _PR_UNIX_POLL_WRITE   0x2
  90. #define _PR_UNIX_POLL_EXCEPT  0x4
  91. #define _PR_UNIX_POLL_ERR     0x8
  92. #define _PR_UNIX_POLL_NVAL    0x10
  93. #define _PR_UNIX_POLL_HUP     0x20
  94. #endif /* _PR_USE_POLL */
  95.  
  96. typedef struct _PRUnixPollDesc {
  97.     PRInt32 osfd;
  98.     PRInt16 in_flags;
  99.     PRInt16 out_flags;
  100. } _PRUnixPollDesc;
  101.  
  102. typedef struct PRPollQueue {
  103.     PRCList links;        /* for linking PRPollQueue's together */
  104.     _PRUnixPollDesc *pds;        /* array of poll descriptors */
  105.     PRUintn npds;            /* length of the array */
  106.     PRPackedBool on_ioq;    /* is this on the async i/o work q? */
  107.     PRIntervalTime timeout;        /* timeout, in ticks */
  108.     struct PRThread *thr;
  109. } PRPollQueue;
  110.  
  111. #define _PR_POLLQUEUE_PTR(_qp) \
  112.     ((PRPollQueue*) ((char*) (_qp) - offsetof(PRPollQueue,links)))
  113.  
  114.  
  115. extern PRInt32 _PR_WaitForMultipleFDs(
  116.     _PRUnixPollDesc *unixpds,
  117.     PRInt32 pdcnt,
  118.     PRIntervalTime timeout);
  119. extern void _PR_Unblock_IO_Wait(struct PRThread *thr);
  120.  
  121. #if defined(_PR_LOCAL_THREADS_ONLY) || defined(_PR_GLOBAL_THREADS_ONLY)
  122. #define _MD_CHECK_FOR_EXIT()
  123. #endif
  124.  
  125. extern fd_set _pr_md_read_set, _pr_md_write_set, _pr_md_exception_set;
  126. extern PRInt16 _pr_md_read_cnt[], _pr_md_write_cnt[], _pr_md_exception_cnt[];
  127. extern PRInt32 _pr_md_ioq_max_osfd;
  128. extern PRUint32 _pr_md_ioq_timeout;
  129.  
  130. struct _MDFileDesc {
  131.     int osfd;
  132. };
  133.  
  134. struct _MDDir {
  135.     DIR *d;
  136. };
  137.  
  138. struct _PRCPU;
  139. extern void _MD_unix_init_running_cpu(struct _PRCPU *cpu);
  140.  
  141. /*
  142. ** Make a redzone at both ends of the stack segment. Disallow access
  143. ** to those pages of memory. It's ok if the mprotect call's don't
  144. ** work - it just means that we don't really have a functional
  145. ** redzone.
  146. */
  147. #if defined(DEBUG) && !defined(RHAPSODY) && !defined(NEXTSTEP)
  148. #if !defined(SOLARIS)    
  149. #include <string.h>  /* for memset() */
  150. #define _MD_INIT_STACK(ts,REDZONE)                    \
  151.     PR_BEGIN_MACRO                                     \
  152.     (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE);    \
  153.     (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
  154.             REDZONE, PROT_NONE);                \
  155.     /*                                    \
  156.     ** Fill stack memory with something that turns into an illegal    \
  157.     ** pointer value. This will sometimes find runtime references to    \
  158.     ** uninitialized pointers. We don't do this for solaris because we    \
  159.     ** can use purify instead.                        \
  160.     */                                    \
  161.     if (_pr_debugStacks) {                        \
  162.     memset(ts->allocBase + REDZONE, 0xf7, ts->stackSize);        \
  163.     }                                    \
  164.     PR_END_MACRO
  165. #else    /* !SOLARIS    */
  166. #define _MD_INIT_STACK(ts,REDZONE)                    \
  167.     PR_BEGIN_MACRO                                     \
  168.     (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE);    \
  169.     (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
  170.             REDZONE, PROT_NONE);                \
  171.     PR_END_MACRO
  172. #endif    /* !SOLARIS    */
  173.  
  174. /*
  175.  * _MD_CLEAR_STACK
  176.  *    Allow access to the redzone pages; the access was turned off in
  177.  *    _MD_INIT_STACK.
  178.  */
  179. #define _MD_CLEAR_STACK(ts)                        \
  180.     PR_BEGIN_MACRO                                     \
  181.     (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_READ|PROT_WRITE);\
  182.     (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
  183.             REDZONE, PROT_READ|PROT_WRITE);            \
  184.     PR_END_MACRO
  185.  
  186. #else    /* DEBUG */
  187.  
  188. #define _MD_INIT_STACK(ts,REDZONE)
  189. #define _MD_CLEAR_STACK(ts)
  190.  
  191. #endif    /* DEBUG */
  192.  
  193. #if !defined(SOLARIS) 
  194.  
  195. #define PR_SET_INTSOFF(newval)
  196.  
  197. #endif
  198.  
  199. /************************************************************************/
  200.  
  201. extern void _PR_UnixInit(void);
  202.  
  203. /************************************************************************/
  204.  
  205. struct _MDProcess {
  206.     pid_t pid;
  207. };
  208.  
  209. struct PRProcess;
  210. struct PRProcessAttr;
  211.  
  212. /* Create a new process (fork() + exec()) */
  213. #define _MD_CREATE_PROCESS _MD_CreateUnixProcess
  214. extern struct PRProcess * _MD_CreateUnixProcess(
  215.     const char *path,
  216.     char *const *argv,
  217.     char *const *envp,
  218.     const struct PRProcessAttr *attr
  219. );
  220.  
  221. #define _MD_DETACH_PROCESS _MD_DetachUnixProcess
  222. extern PRStatus _MD_DetachUnixProcess(struct PRProcess *process);
  223.  
  224. /* Wait for a child process to terminate */
  225. #define _MD_WAIT_PROCESS _MD_WaitUnixProcess
  226. extern PRStatus _MD_WaitUnixProcess(struct PRProcess *process,
  227.     PRInt32 *exitCode);
  228.  
  229. #define _MD_KILL_PROCESS _MD_KillUnixProcess
  230. extern PRStatus _MD_KillUnixProcess(struct PRProcess *process);
  231.  
  232. /************************************************************************/
  233.  
  234. #define _MD_START_INTERRUPTS            _MD_StartInterrupts
  235. #define _MD_STOP_INTERRUPTS                _MD_StopInterrupts
  236. #define _MD_DISABLE_CLOCK_INTERRUPTS    _MD_DisableClockInterrupts
  237. #define _MD_ENABLE_CLOCK_INTERRUPTS        _MD_EnableClockInterrupts
  238. #define _MD_BLOCK_CLOCK_INTERRUPTS        _MD_BlockClockInterrupts
  239. #define _MD_UNBLOCK_CLOCK_INTERRUPTS    _MD_UnblockClockInterrupts
  240.  
  241. /************************************************************************/
  242.  
  243. extern void        _MD_InitCPUS(void);
  244. #define _MD_INIT_CPUS           _MD_InitCPUS
  245.  
  246. extern void        _MD_Wakeup_CPUs(void);
  247. #define _MD_WAKEUP_CPUS _MD_Wakeup_CPUs
  248.  
  249. #define _MD_PAUSE_CPU            _MD_PauseCPU
  250.  
  251. #if defined(_PR_LOCAL_THREADS_ONLY) || defined(_PR_GLOBAL_THREADS_ONLY)
  252. #define _MD_CLEANUP_BEFORE_EXIT()
  253. #endif
  254.  
  255. #ifndef IRIX
  256. #define _MD_EXIT(status)        _exit(status)
  257. #endif
  258.  
  259. /************************************************************************/
  260.  
  261. #define _MD_GET_ENV                getenv
  262. #define _MD_PUT_ENV                putenv
  263.  
  264. /************************************************************************/
  265.  
  266. extern void        _MD_MakeNonblock(PRFileDesc *fd);
  267. #define _MD_MAKE_NONBLOCK            _MD_MakeNonblock        
  268.  
  269. /************************************************************************/
  270.  
  271. extern PRStatus    _MD_AllocSegment(PRSegment *seg, PRUint32 size,
  272.                 void *vaddr);
  273. extern void        _MD_FreeSegment(PRSegment *seg);
  274.  
  275. #define _MD_INIT_SEGS            _MD_InitSegs
  276. #define _MD_ALLOC_SEGMENT        _MD_AllocSegment
  277. #define _MD_FREE_SEGMENT        _MD_FreeSegment
  278.  
  279. /************************************************************************/
  280.  
  281. #if !defined(HPUX_LW_TIMER)
  282. #define _MD_INTERVAL_INIT()
  283. #endif
  284. #define _MD_INTERVAL_PER_MILLISEC()    (_PR_MD_INTERVAL_PER_SEC() / 1000)
  285. #define _MD_INTERVAL_PER_MICROSEC()    (_PR_MD_INTERVAL_PER_SEC() / 1000000)
  286.  
  287. /************************************************************************/
  288.  
  289. #define _MD_ERRNO()                 (errno)
  290. #define _MD_GET_SOCKET_ERROR()        (errno)
  291.  
  292. /************************************************************************/
  293.  
  294. extern PRInt32 _MD_AvailableSocket(PRInt32 osfd);
  295.  
  296. extern void _MD_InitSegs(void);
  297. extern void _MD_StartInterrupts(void);
  298. extern void _MD_StopInterrupts(void);
  299. extern void _MD_DisableClockInterrupts(void);
  300. extern void _MD_BlockClockInterrupts(void);
  301. extern void _MD_UnblockClockInterrupts(void);
  302. extern void _MD_PauseCPU(PRIntervalTime timeout);
  303.  
  304. extern PRStatus _MD_open_dir(struct _MDDir *, const char *);
  305. extern PRInt32  _MD_close_dir(struct _MDDir *);
  306. extern char *   _MD_read_dir(struct _MDDir *, PRIntn);
  307. extern PRInt32  _MD_open(const char *name, PRIntn osflags, PRIntn mode);
  308. extern PRInt32    _MD_delete(const char *name);
  309. extern PRInt32    _MD_getfileinfo(const char *fn, PRFileInfo *info);
  310. extern PRInt32  _MD_getfileinfo64(const char *fn, PRFileInfo64 *info);
  311. extern PRInt32  _MD_getopenfileinfo(const PRFileDesc *fd, PRFileInfo *info);
  312. extern PRInt32  _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info);
  313. extern PRInt32    _MD_rename(const char *from, const char *to);
  314. extern PRInt32    _MD_access(const char *name, PRAccessHow how);
  315. extern PRInt32    _MD_mkdir(const char *name, PRIntn mode);
  316. extern PRInt32    _MD_rmdir(const char *name);
  317. extern PRInt32    _MD_accept_read(PRInt32 sock, PRInt32 *newSock,
  318.                 PRNetAddr **raddr, void *buf, PRInt32 amount);
  319. extern PRInt32     _PR_UnixTransmitFile(PRFileDesc *sd, PRFileDesc *fd,
  320.             const void *headers, PRInt32 hlen,
  321.             PRTransmitFileFlags flags, PRIntervalTime timeout);
  322.  
  323. extern PRStatus _MD_LockFile(PRInt32 osfd);
  324. extern PRStatus _MD_TLockFile(PRInt32 osfd);
  325. extern PRStatus _MD_UnlockFile(PRInt32 osfd);
  326.  
  327. #define _MD_OPEN_DIR(dir, name)            _MD_open_dir(dir, name)
  328. #define _MD_CLOSE_DIR(dir)                _MD_close_dir(dir)
  329. #define _MD_READ_DIR(dir, flags)        _MD_read_dir(dir, flags)
  330. #define _MD_OPEN(name, osflags, mode    )    _MD_open(name, osflags, mode)
  331. extern PRInt32 _MD_read(PRFileDesc *fd, void *buf, PRInt32 amount);
  332. #define _MD_READ(fd,buf,amount)            _MD_read(fd,buf,amount)
  333. extern PRInt32 _MD_write(PRFileDesc *fd, const void *buf, PRInt32 amount);
  334. #define _MD_WRITE(fd,buf,amount)        _MD_write(fd,buf,amount)
  335. #define _MD_DELETE(name)                _MD_delete(name)
  336. #define _MD_GETFILEINFO(fn, info)        _MD_getfileinfo(fn, info)
  337. #define _MD_GETFILEINFO64(fn, info)        _MD_getfileinfo64(fn, info)
  338. #define _MD_GETOPENFILEINFO(fd, info)    _MD_getopenfileinfo(fd, info)
  339. #define _MD_GETOPENFILEINFO64(fd, info)    _MD_getopenfileinfo64(fd, info)
  340. #define _MD_RENAME(from, to)            _MD_rename(from, to)
  341. #define _MD_ACCESS(name, how)            _MD_access(name, how)
  342. #define _MD_MKDIR(name, mode)            _MD_mkdir(name, mode)
  343. #define _MD_RMDIR(name)                    _MD_rmdir(name)
  344. #define _MD_ACCEPT_READ(sock, newSock, raddr, buf, amount)    _MD_accept_read(sock, newSock, raddr, buf, amount)
  345.  
  346. #define _MD_LOCKFILE _MD_LockFile
  347. #define _MD_TLOCKFILE _MD_TLockFile
  348. #define _MD_UNLOCKFILE _MD_UnlockFile
  349.  
  350.  
  351. extern PRInt32        _MD_socket(int af, int type, int flags);
  352. #define _MD_SOCKET    _MD_socket
  353. extern PRInt32        _MD_connect(PRFileDesc *fd, const PRNetAddr *addr,
  354.                                 PRUint32 addrlen, PRIntervalTime timeout);
  355. #define _MD_CONNECT    _MD_connect
  356. extern PRInt32        _MD_accept(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen,
  357.                                                     PRIntervalTime timeout);
  358. #define _MD_ACCEPT    _MD_accept
  359. extern PRInt32        _MD_bind(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen);
  360. #define _MD_BIND    _MD_bind
  361. extern PRInt32        _MD_listen(PRFileDesc *fd, PRIntn backlog);
  362. #define _MD_LISTEN    _MD_listen
  363. extern PRInt32        _MD_shutdown(PRFileDesc *fd, PRIntn how);
  364. #define _MD_SHUTDOWN    _MD_shutdown
  365.  
  366. extern PRInt32        _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount, 
  367.                                PRIntn flags, PRIntervalTime timeout);
  368. #define _MD_RECV    _MD_recv
  369. extern PRInt32        _MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount,
  370.                                     PRIntn flags, PRIntervalTime timeout);
  371. #define _MD_SEND    _MD_send
  372. extern PRInt32        _MD_recvfrom(PRFileDesc *fd, void *buf, PRInt32 amount,
  373.                         PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen,
  374.                                             PRIntervalTime timeout);
  375. #define _MD_RECVFROM    _MD_recvfrom
  376. extern PRInt32 _MD_sendto(PRFileDesc *fd, const void *buf, PRInt32 amount,
  377.                             PRIntn flags, const PRNetAddr *addr, PRUint32 addrlen,
  378.                                                 PRIntervalTime timeout);
  379. #define _MD_SENDTO    _MD_sendto
  380. extern PRInt32        _MD_writev(PRFileDesc *fd, struct PRIOVec *iov,
  381.                                 PRInt32 iov_size, PRIntervalTime timeout);
  382. #define _MD_WRITEV    _MD_writev
  383.  
  384. extern PRInt32        _MD_socketavailable(PRFileDesc *fd);
  385. #define    _MD_SOCKETAVAILABLE        _MD_socketavailable
  386. extern PRInt64        _MD_socketavailable64(PRFileDesc *fd);
  387. #define    _MD_SOCKETAVAILABLE64        _MD_socketavailable64
  388.  
  389. extern PRInt32 _MD_pr_poll(PRPollDesc *pds, PRIntn npds,
  390.                                                 PRIntervalTime timeout);
  391. #define _MD_PR_POLL        _MD_pr_poll
  392.  
  393. extern PRInt32        _MD_close(PRInt32 osfd);
  394. #define _MD_CLOSE_FILE    _MD_close
  395. extern PRInt32        _MD_lseek(PRFileDesc*, PRInt32, PRSeekWhence);
  396. #define _MD_LSEEK    _MD_lseek
  397. extern PRInt64        _MD_lseek64(PRFileDesc*, PRInt64, PRSeekWhence);
  398. #define _MD_LSEEK64    _MD_lseek64
  399. extern PRInt32        _MD_fsync(PRFileDesc *fd);
  400. #define _MD_FSYNC    _MD_fsync
  401.  
  402. extern PRInt32 _MD_socketpair(int af, int type, int flags, PRInt32 *osfd);
  403. #define _MD_SOCKETPAIR        _MD_socketpair
  404.  
  405. #define _MD_CLOSE_SOCKET    _MD_close
  406.  
  407. #ifndef NO_NSPR_10_SUPPORT
  408. #define _MD_STAT    stat
  409. #endif
  410.  
  411. extern PRStatus _MD_getpeername(PRFileDesc *fd, PRNetAddr *addr,
  412.                                             PRUint32 *addrlen);
  413. #define _MD_GETPEERNAME _MD_getpeername
  414. extern PRStatus _MD_getsockname(PRFileDesc *fd, PRNetAddr *addr,
  415.                                             PRUint32 *addrlen);
  416. #define _MD_GETSOCKNAME _MD_getsockname
  417.  
  418. extern PRStatus _MD_getsockopt(PRFileDesc *fd, PRInt32 level,
  419.                         PRInt32 optname, char* optval, PRInt32* optlen);
  420. #define _MD_GETSOCKOPT        _MD_getsockopt
  421. extern PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level,
  422.                     PRInt32 optname, const char* optval, PRInt32 optlen);
  423. #define _MD_SETSOCKOPT        _MD_setsockopt
  424.  
  425. extern PRStatus _MD_gethostname(char *name, PRUint32 namelen);
  426. #define _MD_GETHOSTNAME        _MD_gethostname
  427.  
  428. extern int _MD_unix_get_nonblocking_connect_error(int osfd);
  429.  
  430. #define HAVE_SOCKET_REUSEADDR
  431. #define HAVE_SOCKET_KEEPALIVE
  432.  
  433. /* Memory-mapped files */
  434.  
  435. struct _MDFileMap {
  436.     PRIntn prot;
  437.     PRIntn flags;
  438. };
  439.  
  440. extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
  441. #define _MD_CREATE_FILE_MAP _MD_CreateFileMap
  442.  
  443. extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
  444.         PRUint32 len);
  445. #define _MD_MEM_MAP _MD_MemMap
  446.  
  447. extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
  448. #define _MD_MEM_UNMAP _MD_MemUnmap
  449.  
  450. extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
  451. #define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
  452.  
  453. /*
  454.  * The standard (XPG4) gettimeofday() (from BSD) takes two arguments.
  455.  * On some SVR4 derivatives, gettimeofday() takes only one argument.
  456.  * The GETTIMEOFDAY macro is intended to hide this difference.
  457.  */
  458. #ifdef HAVE_SVID_GETTOD
  459. #define GETTIMEOFDAY(tp) gettimeofday(tp)
  460. #else
  461. #define GETTIMEOFDAY(tp) gettimeofday((tp), NULL)
  462. #endif
  463.  
  464. #if defined(_PR_PTHREADS) && !defined(_PR_POLL_AVAILABLE)
  465. #define _PR_NEED_FAKE_POLL
  466. #endif
  467.  
  468. #if defined(_PR_NEED_FAKE_POLL)
  469.  
  470. /*
  471.  * Some platforms don't have poll(), but our pthreads code calls poll().
  472.  * As a temporary measure, I implemented a fake poll() using select().
  473.  * Here are the struct and macro definitions copied from sys/poll.h
  474.  * on Solaris 2.5.
  475.  */
  476.  
  477. struct pollfd {
  478.     int fd;
  479.     short events;
  480.     short revents;
  481. };
  482.  
  483. /* poll events */
  484.  
  485. #define    POLLIN        0x0001        /* fd is readable */
  486. #define    POLLPRI        0x0002        /* high priority info at fd */
  487. #define    POLLOUT        0x0004        /* fd is writeable (won't block) */
  488. #define    POLLRDNORM    0x0040        /* normal data is readable */
  489. #define    POLLWRNORM    POLLOUT
  490. #define    POLLRDBAND    0x0080        /* out-of-band data is readable */
  491. #define    POLLWRBAND    0x0100        /* out-of-band data is writeable */
  492.  
  493. #define    POLLNORM    POLLRDNORM
  494.  
  495. #define    POLLERR        0x0008        /* fd has error condition */
  496. #define    POLLHUP        0x0010        /* fd has been hung up on */
  497. #define    POLLNVAL    0x0020        /* invalid pollfd entry */
  498.  
  499. extern int poll(struct pollfd *, unsigned long, int);
  500.  
  501. #endif /* _PR_NEED_FAKE_POLL */
  502.  
  503. /*
  504. ** A vector of the UNIX I/O calls we use. These are here to smooth over
  505. ** the rough edges needed for large files. All of NSPR's implmentaions
  506. ** go through this vector using syntax of the form
  507. **      result = _md_iovector.xxx64(args);
  508. */
  509.  
  510. #if defined(SOLARIS2_5)
  511. /*
  512. ** Special case: Solaris 2.5.1
  513. ** Solaris starts to have 64-bit file I/O in 2.6.  We build on Solaris
  514. ** 2.5.1 so that we can use the same binaries on both Solaris 2.5.1 and
  515. ** 2.6.  At run time, we detect whether 64-bit file I/O is available by
  516. ** looking up the 64-bit file function symbols in libc.  At build time,
  517. ** we need to define the 64-bit file I/O datatypes that are compatible
  518. ** with their definitions on Solaris 2.6.
  519. */
  520. typedef PRInt64 off64_t;
  521. typedef PRUint64 ino64_t;
  522. typedef PRUint64 blkcnt64_t;
  523. struct stat64 {
  524.     dev_t st_dev;
  525.     long st_pad1[3];
  526.     ino64_t st_ino;
  527.     mode_t st_mode;
  528.     nlink_t st_nlink;
  529.     uid_t st_uid;
  530.     gid_t st_gid;
  531.     dev_t st_rdev;
  532.     long t_pad2[2];
  533.     off64_t st_size;
  534.     timestruc_t st_atim;
  535.     timestruc_t st_mtim;
  536.     timestruc_t st_ctim;
  537.     long st_blksize;
  538.     blkcnt64_t st_blocks;
  539.     char st_fstype[_ST_FSTYPSZ];
  540.     long st_pad4[8];
  541. };
  542. typedef struct stat64 _MDStat64;
  543.  
  544. #elif defined(_PR_HAVE_OFF64_T)
  545. typedef struct stat64 _MDStat64;
  546. #elif defined(_PR_HAVE_LARGE_OFF_T) || defined(_PR_NO_LARGE_FILES)
  547. typedef struct stat _MDStat64;
  548. #else
  549. #error "I don't know yet"
  550. #endif
  551.  
  552. typedef PRIntn (*_MD_Fstat64)(PRIntn osfd, _MDStat64 *buf);
  553. typedef PRIntn (*_MD_Open64)(const char *path, int oflag, ...);
  554. typedef PRIntn (*_MD_Stat64)(const char *path, _MDStat64 *buf);
  555. typedef PRInt64 (*_MD_Lseek64)(PRIntn osfd, PRInt64, PRIntn whence);
  556. typedef PRIntn (*_MD_Lockf64)(PRIntn osfd, PRIntn function, PRInt64 size);
  557. typedef void* (*_MD_Mmap64)(
  558.     void *addr, PRSize len, PRIntn prot, PRIntn flags,
  559.     PRIntn fildes, PRInt64 offset);
  560. struct _MD_IOVector
  561. {
  562.     _MD_Open64 _open64;
  563.     _MD_Mmap64 _mmap64;
  564.     _MD_Stat64 _stat64;
  565.     _MD_Fstat64 _fstat64;
  566.     _MD_Lockf64 _lockf64;
  567.     _MD_Lseek64 _lseek64;
  568. };
  569. extern struct _MD_IOVector _md_iovector;
  570.  
  571. #endif /* prunixos_h___ */
  572.