_unixos.h 21 KB

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