1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/include/md/_unixos.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,624 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef prunixos_h___ 1.10 +#define prunixos_h___ 1.11 + 1.12 +/* 1.13 + * If FD_SETSIZE is not defined on the command line, set the default value 1.14 + * before include select.h 1.15 + */ 1.16 +/* 1.17 + * Linux: FD_SETSIZE is defined in /usr/include/sys/select.h and should 1.18 + * not be redefined. 1.19 + */ 1.20 +#if !defined(LINUX) && !defined(__GNU__) && !defined(__GLIBC__) \ 1.21 + && !defined(DARWIN) 1.22 +#ifndef FD_SETSIZE 1.23 +#define FD_SETSIZE 4096 1.24 +#endif 1.25 +#endif 1.26 + 1.27 +#include <unistd.h> 1.28 +#include <stddef.h> 1.29 +#include <sys/stat.h> 1.30 +#include <dirent.h> 1.31 +#include <errno.h> 1.32 + 1.33 +#include "prio.h" 1.34 +#include "prmem.h" 1.35 +#include "prclist.h" 1.36 + 1.37 +/* 1.38 + * For select(), fd_set, and struct timeval. 1.39 + * 1.40 + * In The Single UNIX(R) Specification, Version 2, 1.41 + * the header file for select() is <sys/time.h>. 1.42 + * In Version 3, the header file for select() is 1.43 + * changed to <sys/select.h>. 1.44 + * 1.45 + * fd_set is defined in <sys/types.h>. Usually 1.46 + * <sys/time.h> includes <sys/types.h>, but on some 1.47 + * older systems <sys/time.h> does not include 1.48 + * <sys/types.h>, so we include it explicitly. 1.49 + */ 1.50 +#include <sys/time.h> 1.51 +#include <sys/types.h> 1.52 +#if defined(AIX) || defined(SYMBIAN) 1.53 +#include <sys/select.h> 1.54 +#endif 1.55 + 1.56 +#ifndef SYMBIAN 1.57 +#define HAVE_NETINET_TCP_H 1.58 +#endif 1.59 + 1.60 +#define _PR_HAVE_O_APPEND 1.61 + 1.62 +#define PR_DIRECTORY_SEPARATOR '/' 1.63 +#define PR_DIRECTORY_SEPARATOR_STR "/" 1.64 +#define PR_PATH_SEPARATOR ':' 1.65 +#define PR_PATH_SEPARATOR_STR ":" 1.66 +typedef int (*FARPROC)(); 1.67 + 1.68 +/* 1.69 + * intervals at which GLOBAL threads wakeup to check for pending interrupt 1.70 + */ 1.71 +#define _PR_INTERRUPT_CHECK_INTERVAL_SECS 5 1.72 +extern PRIntervalTime intr_timeout_ticks; 1.73 + 1.74 +/* 1.75 + * The bit flags for the in_flags and out_flags fields 1.76 + * of _PR_UnixPollDesc 1.77 + */ 1.78 +#ifdef _PR_USE_POLL 1.79 +#define _PR_UNIX_POLL_READ POLLIN 1.80 +#define _PR_UNIX_POLL_WRITE POLLOUT 1.81 +#define _PR_UNIX_POLL_EXCEPT POLLPRI 1.82 +#define _PR_UNIX_POLL_ERR POLLERR 1.83 +#define _PR_UNIX_POLL_NVAL POLLNVAL 1.84 +#define _PR_UNIX_POLL_HUP POLLHUP 1.85 +#else /* _PR_USE_POLL */ 1.86 +#define _PR_UNIX_POLL_READ 0x1 1.87 +#define _PR_UNIX_POLL_WRITE 0x2 1.88 +#define _PR_UNIX_POLL_EXCEPT 0x4 1.89 +#define _PR_UNIX_POLL_ERR 0x8 1.90 +#define _PR_UNIX_POLL_NVAL 0x10 1.91 +#define _PR_UNIX_POLL_HUP 0x20 1.92 +#endif /* _PR_USE_POLL */ 1.93 + 1.94 +typedef struct _PRUnixPollDesc { 1.95 + PRInt32 osfd; 1.96 + PRInt16 in_flags; 1.97 + PRInt16 out_flags; 1.98 +} _PRUnixPollDesc; 1.99 + 1.100 +typedef struct PRPollQueue { 1.101 + PRCList links; /* for linking PRPollQueue's together */ 1.102 + _PRUnixPollDesc *pds; /* array of poll descriptors */ 1.103 + PRUintn npds; /* length of the array */ 1.104 + PRPackedBool on_ioq; /* is this on the async i/o work q? */ 1.105 + PRIntervalTime timeout; /* timeout, in ticks */ 1.106 + struct PRThread *thr; 1.107 +} PRPollQueue; 1.108 + 1.109 +#define _PR_POLLQUEUE_PTR(_qp) \ 1.110 + ((PRPollQueue*) ((char*) (_qp) - offsetof(PRPollQueue,links))) 1.111 + 1.112 + 1.113 +extern PRInt32 _PR_WaitForMultipleFDs( 1.114 + _PRUnixPollDesc *unixpds, 1.115 + PRInt32 pdcnt, 1.116 + PRIntervalTime timeout); 1.117 +extern void _PR_Unblock_IO_Wait(struct PRThread *thr); 1.118 + 1.119 +#if defined(_PR_LOCAL_THREADS_ONLY) || defined(_PR_GLOBAL_THREADS_ONLY) 1.120 +#define _MD_CHECK_FOR_EXIT() 1.121 +#endif 1.122 + 1.123 +extern fd_set _pr_md_read_set, _pr_md_write_set, _pr_md_exception_set; 1.124 +extern PRInt16 _pr_md_read_cnt[], _pr_md_write_cnt[], _pr_md_exception_cnt[]; 1.125 +extern PRInt32 _pr_md_ioq_max_osfd; 1.126 +extern PRUint32 _pr_md_ioq_timeout; 1.127 + 1.128 +struct _MDFileDesc { 1.129 + int osfd; 1.130 +#if defined(LINUX) && defined(_PR_PTHREADS) 1.131 + int tcp_nodelay; /* used by pt_LinuxSendFile */ 1.132 +#endif 1.133 +}; 1.134 + 1.135 +struct _MDDir { 1.136 + DIR *d; 1.137 +}; 1.138 + 1.139 +struct _PRCPU; 1.140 +extern void _MD_unix_init_running_cpu(struct _PRCPU *cpu); 1.141 + 1.142 +/* 1.143 +** Make a redzone at both ends of the stack segment. Disallow access 1.144 +** to those pages of memory. It's ok if the mprotect call's don't 1.145 +** work - it just means that we don't really have a functional 1.146 +** redzone. 1.147 +*/ 1.148 +#include <sys/mman.h> 1.149 +#ifndef PROT_NONE 1.150 +#define PROT_NONE 0x0 1.151 +#endif 1.152 + 1.153 +#if defined(DEBUG) && !defined(DARWIN) 1.154 +#if !defined(SOLARIS) 1.155 +#include <string.h> /* for memset() */ 1.156 +#define _MD_INIT_STACK(ts,REDZONE) \ 1.157 + PR_BEGIN_MACRO \ 1.158 + (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE); \ 1.159 + (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\ 1.160 + REDZONE, PROT_NONE); \ 1.161 + /* \ 1.162 + ** Fill stack memory with something that turns into an illegal \ 1.163 + ** pointer value. This will sometimes find runtime references to \ 1.164 + ** uninitialized pointers. We don't do this for solaris because we \ 1.165 + ** can use purify instead. \ 1.166 + */ \ 1.167 + if (_pr_debugStacks) { \ 1.168 + memset(ts->allocBase + REDZONE, 0xf7, ts->stackSize); \ 1.169 + } \ 1.170 + PR_END_MACRO 1.171 +#else /* !SOLARIS */ 1.172 +#define _MD_INIT_STACK(ts,REDZONE) \ 1.173 + PR_BEGIN_MACRO \ 1.174 + (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE); \ 1.175 + (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\ 1.176 + REDZONE, PROT_NONE); \ 1.177 + PR_END_MACRO 1.178 +#endif /* !SOLARIS */ 1.179 + 1.180 +/* 1.181 + * _MD_CLEAR_STACK 1.182 + * Allow access to the redzone pages; the access was turned off in 1.183 + * _MD_INIT_STACK. 1.184 + */ 1.185 +#define _MD_CLEAR_STACK(ts) \ 1.186 + PR_BEGIN_MACRO \ 1.187 + (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_READ|PROT_WRITE);\ 1.188 + (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\ 1.189 + REDZONE, PROT_READ|PROT_WRITE); \ 1.190 + PR_END_MACRO 1.191 + 1.192 +#else /* DEBUG */ 1.193 + 1.194 +#define _MD_INIT_STACK(ts,REDZONE) 1.195 +#define _MD_CLEAR_STACK(ts) 1.196 + 1.197 +#endif /* DEBUG */ 1.198 + 1.199 +#if !defined(SOLARIS) 1.200 + 1.201 +#define PR_SET_INTSOFF(newval) 1.202 + 1.203 +#endif 1.204 + 1.205 +/************************************************************************/ 1.206 + 1.207 +extern void _PR_UnixInit(void); 1.208 + 1.209 +extern void _PR_UnixCleanup(void); 1.210 +#define _MD_EARLY_CLEANUP _PR_UnixCleanup 1.211 + 1.212 +/************************************************************************/ 1.213 + 1.214 +struct _MDProcess { 1.215 + pid_t pid; 1.216 +}; 1.217 + 1.218 +struct PRProcess; 1.219 +struct PRProcessAttr; 1.220 + 1.221 +/* Create a new process (fork() + exec()) */ 1.222 +#define _MD_CREATE_PROCESS _MD_CreateUnixProcess 1.223 +extern struct PRProcess * _MD_CreateUnixProcess( 1.224 + const char *path, 1.225 + char *const *argv, 1.226 + char *const *envp, 1.227 + const struct PRProcessAttr *attr 1.228 +); 1.229 + 1.230 +#define _MD_DETACH_PROCESS _MD_DetachUnixProcess 1.231 +extern PRStatus _MD_DetachUnixProcess(struct PRProcess *process); 1.232 + 1.233 +/* Wait for a child process to terminate */ 1.234 +#define _MD_WAIT_PROCESS _MD_WaitUnixProcess 1.235 +extern PRStatus _MD_WaitUnixProcess(struct PRProcess *process, 1.236 + PRInt32 *exitCode); 1.237 + 1.238 +#define _MD_KILL_PROCESS _MD_KillUnixProcess 1.239 +extern PRStatus _MD_KillUnixProcess(struct PRProcess *process); 1.240 + 1.241 +/************************************************************************/ 1.242 + 1.243 +extern void _MD_EnableClockInterrupts(void); 1.244 +extern void _MD_DisableClockInterrupts(void); 1.245 + 1.246 +#define _MD_START_INTERRUPTS _MD_StartInterrupts 1.247 +#define _MD_STOP_INTERRUPTS _MD_StopInterrupts 1.248 +#define _MD_DISABLE_CLOCK_INTERRUPTS _MD_DisableClockInterrupts 1.249 +#define _MD_ENABLE_CLOCK_INTERRUPTS _MD_EnableClockInterrupts 1.250 +#define _MD_BLOCK_CLOCK_INTERRUPTS _MD_BlockClockInterrupts 1.251 +#define _MD_UNBLOCK_CLOCK_INTERRUPTS _MD_UnblockClockInterrupts 1.252 + 1.253 +/************************************************************************/ 1.254 + 1.255 +extern void _MD_InitCPUS(void); 1.256 +#define _MD_INIT_CPUS _MD_InitCPUS 1.257 + 1.258 +extern void _MD_Wakeup_CPUs(void); 1.259 +#define _MD_WAKEUP_CPUS _MD_Wakeup_CPUs 1.260 + 1.261 +#define _MD_PAUSE_CPU _MD_PauseCPU 1.262 + 1.263 +#if defined(_PR_LOCAL_THREADS_ONLY) || defined(_PR_GLOBAL_THREADS_ONLY) 1.264 +#define _MD_CLEANUP_BEFORE_EXIT() 1.265 +#endif 1.266 + 1.267 +#ifndef IRIX 1.268 +#define _MD_EXIT(status) _exit(status) 1.269 +#endif 1.270 + 1.271 +/************************************************************************/ 1.272 + 1.273 +#define _MD_GET_ENV getenv 1.274 +#define _MD_PUT_ENV putenv 1.275 + 1.276 +/************************************************************************/ 1.277 + 1.278 +#define _MD_INIT_FILEDESC(fd) 1.279 + 1.280 +extern void _MD_MakeNonblock(PRFileDesc *fd); 1.281 +#define _MD_MAKE_NONBLOCK _MD_MakeNonblock 1.282 + 1.283 +/************************************************************************/ 1.284 + 1.285 +#if !defined(_PR_PTHREADS) 1.286 + 1.287 +extern void _MD_InitSegs(void); 1.288 +extern PRStatus _MD_AllocSegment(PRSegment *seg, PRUint32 size, 1.289 + void *vaddr); 1.290 +extern void _MD_FreeSegment(PRSegment *seg); 1.291 + 1.292 +#define _MD_INIT_SEGS _MD_InitSegs 1.293 +#define _MD_ALLOC_SEGMENT _MD_AllocSegment 1.294 +#define _MD_FREE_SEGMENT _MD_FreeSegment 1.295 + 1.296 +#endif /* !defined(_PR_PTHREADS) */ 1.297 + 1.298 +/************************************************************************/ 1.299 + 1.300 +#ifdef _MD_INTERVAL_USE_GTOD 1.301 +extern PRIntervalTime _PR_UNIX_GetInterval(void); 1.302 +extern PRIntervalTime _PR_UNIX_TicksPerSecond(void); 1.303 +#define _MD_INTERVAL_INIT() 1.304 +#define _MD_GET_INTERVAL _PR_UNIX_GetInterval 1.305 +#define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond 1.306 +#endif 1.307 + 1.308 +#ifdef HAVE_CLOCK_MONOTONIC 1.309 +extern PRIntervalTime _PR_UNIX_GetInterval2(void); 1.310 +extern PRIntervalTime _PR_UNIX_TicksPerSecond2(void); 1.311 +#define _MD_INTERVAL_INIT() 1.312 +#define _MD_GET_INTERVAL _PR_UNIX_GetInterval2 1.313 +#define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond2 1.314 +#endif 1.315 + 1.316 +#define _MD_INTERVAL_PER_MILLISEC() (_PR_MD_INTERVAL_PER_SEC() / 1000) 1.317 +#define _MD_INTERVAL_PER_MICROSEC() (_PR_MD_INTERVAL_PER_SEC() / 1000000) 1.318 + 1.319 +/************************************************************************/ 1.320 + 1.321 +#define _MD_ERRNO() (errno) 1.322 +#define _MD_GET_SOCKET_ERROR() (errno) 1.323 + 1.324 +/************************************************************************/ 1.325 + 1.326 +extern PRInt32 _MD_AvailableSocket(PRInt32 osfd); 1.327 + 1.328 +extern void _MD_StartInterrupts(void); 1.329 +extern void _MD_StopInterrupts(void); 1.330 +extern void _MD_DisableClockInterrupts(void); 1.331 +extern void _MD_BlockClockInterrupts(void); 1.332 +extern void _MD_UnblockClockInterrupts(void); 1.333 +extern void _MD_PauseCPU(PRIntervalTime timeout); 1.334 + 1.335 +extern PRStatus _MD_open_dir(struct _MDDir *, const char *); 1.336 +extern PRInt32 _MD_close_dir(struct _MDDir *); 1.337 +extern char * _MD_read_dir(struct _MDDir *, PRIntn); 1.338 +extern PRInt32 _MD_open(const char *name, PRIntn osflags, PRIntn mode); 1.339 +extern PRInt32 _MD_delete(const char *name); 1.340 +extern PRInt32 _MD_getfileinfo(const char *fn, PRFileInfo *info); 1.341 +extern PRInt32 _MD_getfileinfo64(const char *fn, PRFileInfo64 *info); 1.342 +extern PRInt32 _MD_getopenfileinfo(const PRFileDesc *fd, PRFileInfo *info); 1.343 +extern PRInt32 _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info); 1.344 +extern PRInt32 _MD_rename(const char *from, const char *to); 1.345 +extern PRInt32 _MD_access(const char *name, PRAccessHow how); 1.346 +extern PRInt32 _MD_mkdir(const char *name, PRIntn mode); 1.347 +extern PRInt32 _MD_rmdir(const char *name); 1.348 +extern PRInt32 _MD_accept_read(PRInt32 sock, PRInt32 *newSock, 1.349 + PRNetAddr **raddr, void *buf, PRInt32 amount); 1.350 +extern PRInt32 _PR_UnixSendFile(PRFileDesc *sd, PRSendFileData *sfd, 1.351 + PRTransmitFileFlags flags, PRIntervalTime timeout); 1.352 + 1.353 +extern PRStatus _MD_LockFile(PRInt32 osfd); 1.354 +extern PRStatus _MD_TLockFile(PRInt32 osfd); 1.355 +extern PRStatus _MD_UnlockFile(PRInt32 osfd); 1.356 + 1.357 +#define _MD_OPEN_DIR(dir, name) _MD_open_dir(dir, name) 1.358 +#define _MD_CLOSE_DIR(dir) _MD_close_dir(dir) 1.359 +#define _MD_READ_DIR(dir, flags) _MD_read_dir(dir, flags) 1.360 +#define _MD_OPEN(name, osflags, mode) _MD_open(name, osflags, mode) 1.361 +#define _MD_OPEN_FILE(name, osflags, mode) _MD_open(name, osflags, mode) 1.362 +extern PRInt32 _MD_read(PRFileDesc *fd, void *buf, PRInt32 amount); 1.363 +#define _MD_READ(fd,buf,amount) _MD_read(fd,buf,amount) 1.364 +extern PRInt32 _MD_write(PRFileDesc *fd, const void *buf, PRInt32 amount); 1.365 +#define _MD_WRITE(fd,buf,amount) _MD_write(fd,buf,amount) 1.366 +#define _MD_DELETE(name) _MD_delete(name) 1.367 +#define _MD_GETFILEINFO(fn, info) _MD_getfileinfo(fn, info) 1.368 +#define _MD_GETFILEINFO64(fn, info) _MD_getfileinfo64(fn, info) 1.369 +#define _MD_GETOPENFILEINFO(fd, info) _MD_getopenfileinfo(fd, info) 1.370 +#define _MD_GETOPENFILEINFO64(fd, info) _MD_getopenfileinfo64(fd, info) 1.371 +#define _MD_RENAME(from, to) _MD_rename(from, to) 1.372 +#define _MD_ACCESS(name, how) _MD_access(name, how) 1.373 +#define _MD_MKDIR(name, mode) _MD_mkdir(name, mode) 1.374 +#define _MD_MAKE_DIR(name, mode) _MD_mkdir(name, mode) 1.375 +#define _MD_RMDIR(name) _MD_rmdir(name) 1.376 +#define _MD_ACCEPT_READ(sock, newSock, raddr, buf, amount) _MD_accept_read(sock, newSock, raddr, buf, amount) 1.377 + 1.378 +#define _MD_LOCKFILE _MD_LockFile 1.379 +#define _MD_TLOCKFILE _MD_TLockFile 1.380 +#define _MD_UNLOCKFILE _MD_UnlockFile 1.381 + 1.382 + 1.383 +extern PRInt32 _MD_socket(int af, int type, int flags); 1.384 +#define _MD_SOCKET _MD_socket 1.385 +extern PRInt32 _MD_connect(PRFileDesc *fd, const PRNetAddr *addr, 1.386 + PRUint32 addrlen, PRIntervalTime timeout); 1.387 +#define _MD_CONNECT _MD_connect 1.388 +extern PRInt32 _MD_accept(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen, 1.389 + PRIntervalTime timeout); 1.390 +#define _MD_ACCEPT _MD_accept 1.391 +extern PRInt32 _MD_bind(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen); 1.392 +#define _MD_BIND _MD_bind 1.393 +extern PRInt32 _MD_listen(PRFileDesc *fd, PRIntn backlog); 1.394 +#define _MD_LISTEN _MD_listen 1.395 +extern PRInt32 _MD_shutdown(PRFileDesc *fd, PRIntn how); 1.396 +#define _MD_SHUTDOWN _MD_shutdown 1.397 + 1.398 +extern PRInt32 _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount, 1.399 + PRIntn flags, PRIntervalTime timeout); 1.400 +#define _MD_RECV _MD_recv 1.401 +extern PRInt32 _MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount, 1.402 + PRIntn flags, PRIntervalTime timeout); 1.403 +#define _MD_SEND _MD_send 1.404 +extern PRInt32 _MD_recvfrom(PRFileDesc *fd, void *buf, PRInt32 amount, 1.405 + PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen, 1.406 + PRIntervalTime timeout); 1.407 +#define _MD_RECVFROM _MD_recvfrom 1.408 +extern PRInt32 _MD_sendto(PRFileDesc *fd, const void *buf, PRInt32 amount, 1.409 + PRIntn flags, const PRNetAddr *addr, PRUint32 addrlen, 1.410 + PRIntervalTime timeout); 1.411 +#define _MD_SENDTO _MD_sendto 1.412 +extern PRInt32 _MD_writev(PRFileDesc *fd, const struct PRIOVec *iov, 1.413 + PRInt32 iov_size, PRIntervalTime timeout); 1.414 +#define _MD_WRITEV _MD_writev 1.415 + 1.416 +extern PRInt32 _MD_socketavailable(PRFileDesc *fd); 1.417 +#define _MD_SOCKETAVAILABLE _MD_socketavailable 1.418 +extern PRInt64 _MD_socketavailable64(PRFileDesc *fd); 1.419 +#define _MD_SOCKETAVAILABLE64 _MD_socketavailable64 1.420 + 1.421 +#define _MD_PIPEAVAILABLE _MD_socketavailable 1.422 + 1.423 +extern PRInt32 _MD_pr_poll(PRPollDesc *pds, PRIntn npds, 1.424 + PRIntervalTime timeout); 1.425 +#define _MD_PR_POLL _MD_pr_poll 1.426 + 1.427 +extern PRInt32 _MD_close(PRInt32 osfd); 1.428 +#define _MD_CLOSE_FILE _MD_close 1.429 +extern PRInt32 _MD_lseek(PRFileDesc*, PRInt32, PRSeekWhence); 1.430 +#define _MD_LSEEK _MD_lseek 1.431 +extern PRInt64 _MD_lseek64(PRFileDesc*, PRInt64, PRSeekWhence); 1.432 +#define _MD_LSEEK64 _MD_lseek64 1.433 +extern PRInt32 _MD_fsync(PRFileDesc *fd); 1.434 +#define _MD_FSYNC _MD_fsync 1.435 + 1.436 +extern PRInt32 _MD_socketpair(int af, int type, int flags, PRInt32 *osfd); 1.437 +#define _MD_SOCKETPAIR _MD_socketpair 1.438 + 1.439 +#define _MD_CLOSE_SOCKET _MD_close 1.440 + 1.441 +#ifndef NO_NSPR_10_SUPPORT 1.442 +#define _MD_STAT stat 1.443 +#endif 1.444 + 1.445 +extern PRStatus _MD_getpeername(PRFileDesc *fd, PRNetAddr *addr, 1.446 + PRUint32 *addrlen); 1.447 +#define _MD_GETPEERNAME _MD_getpeername 1.448 +extern PRStatus _MD_getsockname(PRFileDesc *fd, PRNetAddr *addr, 1.449 + PRUint32 *addrlen); 1.450 +#define _MD_GETSOCKNAME _MD_getsockname 1.451 + 1.452 +extern PRStatus _MD_getsockopt(PRFileDesc *fd, PRInt32 level, 1.453 + PRInt32 optname, char* optval, PRInt32* optlen); 1.454 +#define _MD_GETSOCKOPT _MD_getsockopt 1.455 +extern PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level, 1.456 + PRInt32 optname, const char* optval, PRInt32 optlen); 1.457 +#define _MD_SETSOCKOPT _MD_setsockopt 1.458 + 1.459 +extern PRStatus _MD_set_fd_inheritable(PRFileDesc *fd, PRBool inheritable); 1.460 +#define _MD_SET_FD_INHERITABLE _MD_set_fd_inheritable 1.461 + 1.462 +extern void _MD_init_fd_inheritable(PRFileDesc *fd, PRBool imported); 1.463 +#define _MD_INIT_FD_INHERITABLE _MD_init_fd_inheritable 1.464 + 1.465 +extern void _MD_query_fd_inheritable(PRFileDesc *fd); 1.466 +#define _MD_QUERY_FD_INHERITABLE _MD_query_fd_inheritable 1.467 + 1.468 +extern PRStatus _MD_gethostname(char *name, PRUint32 namelen); 1.469 +#define _MD_GETHOSTNAME _MD_gethostname 1.470 + 1.471 +extern PRStatus _MD_getsysinfo(PRSysInfo cmd, char *name, PRUint32 namelen); 1.472 +#define _MD_GETSYSINFO _MD_getsysinfo 1.473 + 1.474 +extern int _MD_unix_get_nonblocking_connect_error(int osfd); 1.475 + 1.476 +/* Memory-mapped files */ 1.477 + 1.478 +struct _MDFileMap { 1.479 + PRIntn prot; 1.480 + PRIntn flags; 1.481 + PRBool isAnonFM; /* when true, PR_CloseFileMap() must close the related fd */ 1.482 +}; 1.483 + 1.484 +extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size); 1.485 +#define _MD_CREATE_FILE_MAP _MD_CreateFileMap 1.486 + 1.487 +#define _MD_GET_MEM_MAP_ALIGNMENT() PR_GetPageSize() 1.488 + 1.489 +extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset, 1.490 + PRUint32 len); 1.491 +#define _MD_MEM_MAP _MD_MemMap 1.492 + 1.493 +extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size); 1.494 +#define _MD_MEM_UNMAP _MD_MemUnmap 1.495 + 1.496 +extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap); 1.497 +#define _MD_CLOSE_FILE_MAP _MD_CloseFileMap 1.498 + 1.499 +extern PRStatus _MD_SyncMemMap( 1.500 + PRFileDesc *fd, 1.501 + void *addr, 1.502 + PRUint32 len); 1.503 +#define _MD_SYNC_MEM_MAP _MD_SyncMemMap 1.504 + 1.505 +/* 1.506 + * The standard (XPG4) gettimeofday() (from BSD) takes two arguments. 1.507 + * On some SVR4 derivatives, gettimeofday() takes only one argument. 1.508 + * The GETTIMEOFDAY macro is intended to hide this difference. 1.509 + */ 1.510 +#ifdef HAVE_SVID_GETTOD 1.511 +#define GETTIMEOFDAY(tp) gettimeofday(tp) 1.512 +#else 1.513 +#define GETTIMEOFDAY(tp) gettimeofday((tp), NULL) 1.514 +#endif 1.515 + 1.516 +#if defined(_PR_PTHREADS) && !defined(_PR_POLL_AVAILABLE) 1.517 +#define _PR_NEED_FAKE_POLL 1.518 +#endif 1.519 + 1.520 +#if defined(_PR_NEED_FAKE_POLL) 1.521 + 1.522 +/* 1.523 + * Some platforms don't have poll(), but our pthreads code calls poll(). 1.524 + * As a temporary measure, I implemented a fake poll() using select(). 1.525 + * Here are the struct and macro definitions copied from sys/poll.h 1.526 + * on Solaris 2.5. 1.527 + */ 1.528 + 1.529 +struct pollfd { 1.530 + int fd; 1.531 + short events; 1.532 + short revents; 1.533 +}; 1.534 + 1.535 +/* poll events */ 1.536 + 1.537 +#define POLLIN 0x0001 /* fd is readable */ 1.538 +#define POLLPRI 0x0002 /* high priority info at fd */ 1.539 +#define POLLOUT 0x0004 /* fd is writeable (won't block) */ 1.540 +#define POLLRDNORM 0x0040 /* normal data is readable */ 1.541 +#define POLLWRNORM POLLOUT 1.542 +#define POLLRDBAND 0x0080 /* out-of-band data is readable */ 1.543 +#define POLLWRBAND 0x0100 /* out-of-band data is writeable */ 1.544 + 1.545 +#define POLLNORM POLLRDNORM 1.546 + 1.547 +#define POLLERR 0x0008 /* fd has error condition */ 1.548 +#define POLLHUP 0x0010 /* fd has been hung up on */ 1.549 +#define POLLNVAL 0x0020 /* invalid pollfd entry */ 1.550 + 1.551 +extern int poll(struct pollfd *, unsigned long, int); 1.552 + 1.553 +#endif /* _PR_NEED_FAKE_POLL */ 1.554 + 1.555 +/* 1.556 +** A vector of the UNIX I/O calls we use. These are here to smooth over 1.557 +** the rough edges needed for large files. All of NSPR's implmentaions 1.558 +** go through this vector using syntax of the form 1.559 +** result = _md_iovector.xxx64(args); 1.560 +*/ 1.561 + 1.562 +#if defined(SOLARIS2_5) 1.563 +/* 1.564 +** Special case: Solaris 2.5.1 1.565 +** Solaris starts to have 64-bit file I/O in 2.6. We build on Solaris 1.566 +** 2.5.1 so that we can use the same binaries on both Solaris 2.5.1 and 1.567 +** 2.6. At run time, we detect whether 64-bit file I/O is available by 1.568 +** looking up the 64-bit file function symbols in libc. At build time, 1.569 +** we need to define the 64-bit file I/O datatypes that are compatible 1.570 +** with their definitions on Solaris 2.6. 1.571 +*/ 1.572 +typedef PRInt64 off64_t; 1.573 +typedef PRUint64 ino64_t; 1.574 +typedef PRInt64 blkcnt64_t; 1.575 +struct stat64 { 1.576 + dev_t st_dev; 1.577 + long st_pad1[3]; 1.578 + ino64_t st_ino; 1.579 + mode_t st_mode; 1.580 + nlink_t st_nlink; 1.581 + uid_t st_uid; 1.582 + gid_t st_gid; 1.583 + dev_t st_rdev; 1.584 + long t_pad2[2]; 1.585 + off64_t st_size; 1.586 + timestruc_t st_atim; 1.587 + timestruc_t st_mtim; 1.588 + timestruc_t st_ctim; 1.589 + long st_blksize; 1.590 + blkcnt64_t st_blocks; 1.591 + char st_fstype[_ST_FSTYPSZ]; 1.592 + long st_pad4[8]; 1.593 +}; 1.594 +typedef struct stat64 _MDStat64; 1.595 +typedef off64_t _MDOff64_t; 1.596 + 1.597 +#elif defined(_PR_HAVE_OFF64_T) 1.598 +typedef struct stat64 _MDStat64; 1.599 +typedef off64_t _MDOff64_t; 1.600 +#elif defined(_PR_HAVE_LARGE_OFF_T) 1.601 +typedef struct stat _MDStat64; 1.602 +typedef off_t _MDOff64_t; 1.603 +#elif defined(_PR_NO_LARGE_FILES) 1.604 +typedef struct stat _MDStat64; 1.605 +typedef PRInt64 _MDOff64_t; 1.606 +#else 1.607 +#error "I don't know yet" 1.608 +#endif 1.609 + 1.610 +typedef PRIntn (*_MD_Fstat64)(PRIntn osfd, _MDStat64 *buf); 1.611 +typedef PRIntn (*_MD_Open64)(const char *path, int oflag, ...); 1.612 +typedef PRIntn (*_MD_Stat64)(const char *path, _MDStat64 *buf); 1.613 +typedef _MDOff64_t (*_MD_Lseek64)(PRIntn osfd, _MDOff64_t, PRIntn whence); 1.614 +typedef void* (*_MD_Mmap64)( 1.615 + void *addr, PRSize len, PRIntn prot, PRIntn flags, 1.616 + PRIntn fildes, _MDOff64_t offset); 1.617 +struct _MD_IOVector 1.618 +{ 1.619 + _MD_Open64 _open64; 1.620 + _MD_Mmap64 _mmap64; 1.621 + _MD_Stat64 _stat64; 1.622 + _MD_Fstat64 _fstat64; 1.623 + _MD_Lseek64 _lseek64; 1.624 +}; 1.625 +extern struct _MD_IOVector _md_iovector; 1.626 + 1.627 +#endif /* prunixos_h___ */