_unixos.h 21 KB

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