michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef prunixos_h___ michael@0: #define prunixos_h___ michael@0: michael@0: /* michael@0: * If FD_SETSIZE is not defined on the command line, set the default value michael@0: * before include select.h michael@0: */ michael@0: /* michael@0: * Linux: FD_SETSIZE is defined in /usr/include/sys/select.h and should michael@0: * not be redefined. michael@0: */ michael@0: #if !defined(LINUX) && !defined(__GNU__) && !defined(__GLIBC__) \ michael@0: && !defined(DARWIN) michael@0: #ifndef FD_SETSIZE michael@0: #define FD_SETSIZE 4096 michael@0: #endif michael@0: #endif michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "prio.h" michael@0: #include "prmem.h" michael@0: #include "prclist.h" michael@0: michael@0: /* michael@0: * For select(), fd_set, and struct timeval. michael@0: * michael@0: * In The Single UNIX(R) Specification, Version 2, michael@0: * the header file for select() is . michael@0: * In Version 3, the header file for select() is michael@0: * changed to . michael@0: * michael@0: * fd_set is defined in . Usually michael@0: * includes , but on some michael@0: * older systems does not include michael@0: * , so we include it explicitly. michael@0: */ michael@0: #include michael@0: #include michael@0: #if defined(AIX) || defined(SYMBIAN) michael@0: #include michael@0: #endif michael@0: michael@0: #ifndef SYMBIAN michael@0: #define HAVE_NETINET_TCP_H michael@0: #endif michael@0: michael@0: #define _PR_HAVE_O_APPEND michael@0: michael@0: #define PR_DIRECTORY_SEPARATOR '/' michael@0: #define PR_DIRECTORY_SEPARATOR_STR "/" michael@0: #define PR_PATH_SEPARATOR ':' michael@0: #define PR_PATH_SEPARATOR_STR ":" michael@0: typedef int (*FARPROC)(); michael@0: michael@0: /* michael@0: * intervals at which GLOBAL threads wakeup to check for pending interrupt michael@0: */ michael@0: #define _PR_INTERRUPT_CHECK_INTERVAL_SECS 5 michael@0: extern PRIntervalTime intr_timeout_ticks; michael@0: michael@0: /* michael@0: * The bit flags for the in_flags and out_flags fields michael@0: * of _PR_UnixPollDesc michael@0: */ michael@0: #ifdef _PR_USE_POLL michael@0: #define _PR_UNIX_POLL_READ POLLIN michael@0: #define _PR_UNIX_POLL_WRITE POLLOUT michael@0: #define _PR_UNIX_POLL_EXCEPT POLLPRI michael@0: #define _PR_UNIX_POLL_ERR POLLERR michael@0: #define _PR_UNIX_POLL_NVAL POLLNVAL michael@0: #define _PR_UNIX_POLL_HUP POLLHUP michael@0: #else /* _PR_USE_POLL */ michael@0: #define _PR_UNIX_POLL_READ 0x1 michael@0: #define _PR_UNIX_POLL_WRITE 0x2 michael@0: #define _PR_UNIX_POLL_EXCEPT 0x4 michael@0: #define _PR_UNIX_POLL_ERR 0x8 michael@0: #define _PR_UNIX_POLL_NVAL 0x10 michael@0: #define _PR_UNIX_POLL_HUP 0x20 michael@0: #endif /* _PR_USE_POLL */ michael@0: michael@0: typedef struct _PRUnixPollDesc { michael@0: PRInt32 osfd; michael@0: PRInt16 in_flags; michael@0: PRInt16 out_flags; michael@0: } _PRUnixPollDesc; michael@0: michael@0: typedef struct PRPollQueue { michael@0: PRCList links; /* for linking PRPollQueue's together */ michael@0: _PRUnixPollDesc *pds; /* array of poll descriptors */ michael@0: PRUintn npds; /* length of the array */ michael@0: PRPackedBool on_ioq; /* is this on the async i/o work q? */ michael@0: PRIntervalTime timeout; /* timeout, in ticks */ michael@0: struct PRThread *thr; michael@0: } PRPollQueue; michael@0: michael@0: #define _PR_POLLQUEUE_PTR(_qp) \ michael@0: ((PRPollQueue*) ((char*) (_qp) - offsetof(PRPollQueue,links))) michael@0: michael@0: michael@0: extern PRInt32 _PR_WaitForMultipleFDs( michael@0: _PRUnixPollDesc *unixpds, michael@0: PRInt32 pdcnt, michael@0: PRIntervalTime timeout); michael@0: extern void _PR_Unblock_IO_Wait(struct PRThread *thr); michael@0: michael@0: #if defined(_PR_LOCAL_THREADS_ONLY) || defined(_PR_GLOBAL_THREADS_ONLY) michael@0: #define _MD_CHECK_FOR_EXIT() michael@0: #endif michael@0: michael@0: extern fd_set _pr_md_read_set, _pr_md_write_set, _pr_md_exception_set; michael@0: extern PRInt16 _pr_md_read_cnt[], _pr_md_write_cnt[], _pr_md_exception_cnt[]; michael@0: extern PRInt32 _pr_md_ioq_max_osfd; michael@0: extern PRUint32 _pr_md_ioq_timeout; michael@0: michael@0: struct _MDFileDesc { michael@0: int osfd; michael@0: #if defined(LINUX) && defined(_PR_PTHREADS) michael@0: int tcp_nodelay; /* used by pt_LinuxSendFile */ michael@0: #endif michael@0: }; michael@0: michael@0: struct _MDDir { michael@0: DIR *d; michael@0: }; michael@0: michael@0: struct _PRCPU; michael@0: extern void _MD_unix_init_running_cpu(struct _PRCPU *cpu); michael@0: michael@0: /* michael@0: ** Make a redzone at both ends of the stack segment. Disallow access michael@0: ** to those pages of memory. It's ok if the mprotect call's don't michael@0: ** work - it just means that we don't really have a functional michael@0: ** redzone. michael@0: */ michael@0: #include michael@0: #ifndef PROT_NONE michael@0: #define PROT_NONE 0x0 michael@0: #endif michael@0: michael@0: #if defined(DEBUG) && !defined(DARWIN) michael@0: #if !defined(SOLARIS) michael@0: #include /* for memset() */ michael@0: #define _MD_INIT_STACK(ts,REDZONE) \ michael@0: PR_BEGIN_MACRO \ michael@0: (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE); \ michael@0: (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\ michael@0: REDZONE, PROT_NONE); \ michael@0: /* \ michael@0: ** Fill stack memory with something that turns into an illegal \ michael@0: ** pointer value. This will sometimes find runtime references to \ michael@0: ** uninitialized pointers. We don't do this for solaris because we \ michael@0: ** can use purify instead. \ michael@0: */ \ michael@0: if (_pr_debugStacks) { \ michael@0: memset(ts->allocBase + REDZONE, 0xf7, ts->stackSize); \ michael@0: } \ michael@0: PR_END_MACRO michael@0: #else /* !SOLARIS */ michael@0: #define _MD_INIT_STACK(ts,REDZONE) \ michael@0: PR_BEGIN_MACRO \ michael@0: (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE); \ michael@0: (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\ michael@0: REDZONE, PROT_NONE); \ michael@0: PR_END_MACRO michael@0: #endif /* !SOLARIS */ michael@0: michael@0: /* michael@0: * _MD_CLEAR_STACK michael@0: * Allow access to the redzone pages; the access was turned off in michael@0: * _MD_INIT_STACK. michael@0: */ michael@0: #define _MD_CLEAR_STACK(ts) \ michael@0: PR_BEGIN_MACRO \ michael@0: (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_READ|PROT_WRITE);\ michael@0: (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\ michael@0: REDZONE, PROT_READ|PROT_WRITE); \ michael@0: PR_END_MACRO michael@0: michael@0: #else /* DEBUG */ michael@0: michael@0: #define _MD_INIT_STACK(ts,REDZONE) michael@0: #define _MD_CLEAR_STACK(ts) michael@0: michael@0: #endif /* DEBUG */ michael@0: michael@0: #if !defined(SOLARIS) michael@0: michael@0: #define PR_SET_INTSOFF(newval) michael@0: michael@0: #endif michael@0: michael@0: /************************************************************************/ michael@0: michael@0: extern void _PR_UnixInit(void); michael@0: michael@0: extern void _PR_UnixCleanup(void); michael@0: #define _MD_EARLY_CLEANUP _PR_UnixCleanup michael@0: michael@0: /************************************************************************/ michael@0: michael@0: struct _MDProcess { michael@0: pid_t pid; michael@0: }; michael@0: michael@0: struct PRProcess; michael@0: struct PRProcessAttr; michael@0: michael@0: /* Create a new process (fork() + exec()) */ michael@0: #define _MD_CREATE_PROCESS _MD_CreateUnixProcess michael@0: extern struct PRProcess * _MD_CreateUnixProcess( michael@0: const char *path, michael@0: char *const *argv, michael@0: char *const *envp, michael@0: const struct PRProcessAttr *attr michael@0: ); michael@0: michael@0: #define _MD_DETACH_PROCESS _MD_DetachUnixProcess michael@0: extern PRStatus _MD_DetachUnixProcess(struct PRProcess *process); michael@0: michael@0: /* Wait for a child process to terminate */ michael@0: #define _MD_WAIT_PROCESS _MD_WaitUnixProcess michael@0: extern PRStatus _MD_WaitUnixProcess(struct PRProcess *process, michael@0: PRInt32 *exitCode); michael@0: michael@0: #define _MD_KILL_PROCESS _MD_KillUnixProcess michael@0: extern PRStatus _MD_KillUnixProcess(struct PRProcess *process); michael@0: michael@0: /************************************************************************/ michael@0: michael@0: extern void _MD_EnableClockInterrupts(void); michael@0: extern void _MD_DisableClockInterrupts(void); michael@0: michael@0: #define _MD_START_INTERRUPTS _MD_StartInterrupts michael@0: #define _MD_STOP_INTERRUPTS _MD_StopInterrupts michael@0: #define _MD_DISABLE_CLOCK_INTERRUPTS _MD_DisableClockInterrupts michael@0: #define _MD_ENABLE_CLOCK_INTERRUPTS _MD_EnableClockInterrupts michael@0: #define _MD_BLOCK_CLOCK_INTERRUPTS _MD_BlockClockInterrupts michael@0: #define _MD_UNBLOCK_CLOCK_INTERRUPTS _MD_UnblockClockInterrupts michael@0: michael@0: /************************************************************************/ michael@0: michael@0: extern void _MD_InitCPUS(void); michael@0: #define _MD_INIT_CPUS _MD_InitCPUS michael@0: michael@0: extern void _MD_Wakeup_CPUs(void); michael@0: #define _MD_WAKEUP_CPUS _MD_Wakeup_CPUs michael@0: michael@0: #define _MD_PAUSE_CPU _MD_PauseCPU michael@0: michael@0: #if defined(_PR_LOCAL_THREADS_ONLY) || defined(_PR_GLOBAL_THREADS_ONLY) michael@0: #define _MD_CLEANUP_BEFORE_EXIT() michael@0: #endif michael@0: michael@0: #ifndef IRIX michael@0: #define _MD_EXIT(status) _exit(status) michael@0: #endif michael@0: michael@0: /************************************************************************/ michael@0: michael@0: #define _MD_GET_ENV getenv michael@0: #define _MD_PUT_ENV putenv michael@0: michael@0: /************************************************************************/ michael@0: michael@0: #define _MD_INIT_FILEDESC(fd) michael@0: michael@0: extern void _MD_MakeNonblock(PRFileDesc *fd); michael@0: #define _MD_MAKE_NONBLOCK _MD_MakeNonblock michael@0: michael@0: /************************************************************************/ michael@0: michael@0: #if !defined(_PR_PTHREADS) michael@0: michael@0: extern void _MD_InitSegs(void); michael@0: extern PRStatus _MD_AllocSegment(PRSegment *seg, PRUint32 size, michael@0: void *vaddr); michael@0: extern void _MD_FreeSegment(PRSegment *seg); michael@0: michael@0: #define _MD_INIT_SEGS _MD_InitSegs michael@0: #define _MD_ALLOC_SEGMENT _MD_AllocSegment michael@0: #define _MD_FREE_SEGMENT _MD_FreeSegment michael@0: michael@0: #endif /* !defined(_PR_PTHREADS) */ michael@0: michael@0: /************************************************************************/ michael@0: michael@0: #ifdef _MD_INTERVAL_USE_GTOD michael@0: extern PRIntervalTime _PR_UNIX_GetInterval(void); michael@0: extern PRIntervalTime _PR_UNIX_TicksPerSecond(void); michael@0: #define _MD_INTERVAL_INIT() michael@0: #define _MD_GET_INTERVAL _PR_UNIX_GetInterval michael@0: #define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond michael@0: #endif michael@0: michael@0: #ifdef HAVE_CLOCK_MONOTONIC michael@0: extern PRIntervalTime _PR_UNIX_GetInterval2(void); michael@0: extern PRIntervalTime _PR_UNIX_TicksPerSecond2(void); michael@0: #define _MD_INTERVAL_INIT() michael@0: #define _MD_GET_INTERVAL _PR_UNIX_GetInterval2 michael@0: #define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond2 michael@0: #endif michael@0: michael@0: #define _MD_INTERVAL_PER_MILLISEC() (_PR_MD_INTERVAL_PER_SEC() / 1000) michael@0: #define _MD_INTERVAL_PER_MICROSEC() (_PR_MD_INTERVAL_PER_SEC() / 1000000) michael@0: michael@0: /************************************************************************/ michael@0: michael@0: #define _MD_ERRNO() (errno) michael@0: #define _MD_GET_SOCKET_ERROR() (errno) michael@0: michael@0: /************************************************************************/ michael@0: michael@0: extern PRInt32 _MD_AvailableSocket(PRInt32 osfd); michael@0: michael@0: extern void _MD_StartInterrupts(void); michael@0: extern void _MD_StopInterrupts(void); michael@0: extern void _MD_DisableClockInterrupts(void); michael@0: extern void _MD_BlockClockInterrupts(void); michael@0: extern void _MD_UnblockClockInterrupts(void); michael@0: extern void _MD_PauseCPU(PRIntervalTime timeout); michael@0: michael@0: extern PRStatus _MD_open_dir(struct _MDDir *, const char *); michael@0: extern PRInt32 _MD_close_dir(struct _MDDir *); michael@0: extern char * _MD_read_dir(struct _MDDir *, PRIntn); michael@0: extern PRInt32 _MD_open(const char *name, PRIntn osflags, PRIntn mode); michael@0: extern PRInt32 _MD_delete(const char *name); michael@0: extern PRInt32 _MD_getfileinfo(const char *fn, PRFileInfo *info); michael@0: extern PRInt32 _MD_getfileinfo64(const char *fn, PRFileInfo64 *info); michael@0: extern PRInt32 _MD_getopenfileinfo(const PRFileDesc *fd, PRFileInfo *info); michael@0: extern PRInt32 _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info); michael@0: extern PRInt32 _MD_rename(const char *from, const char *to); michael@0: extern PRInt32 _MD_access(const char *name, PRAccessHow how); michael@0: extern PRInt32 _MD_mkdir(const char *name, PRIntn mode); michael@0: extern PRInt32 _MD_rmdir(const char *name); michael@0: extern PRInt32 _MD_accept_read(PRInt32 sock, PRInt32 *newSock, michael@0: PRNetAddr **raddr, void *buf, PRInt32 amount); michael@0: extern PRInt32 _PR_UnixSendFile(PRFileDesc *sd, PRSendFileData *sfd, michael@0: PRTransmitFileFlags flags, PRIntervalTime timeout); michael@0: michael@0: extern PRStatus _MD_LockFile(PRInt32 osfd); michael@0: extern PRStatus _MD_TLockFile(PRInt32 osfd); michael@0: extern PRStatus _MD_UnlockFile(PRInt32 osfd); michael@0: michael@0: #define _MD_OPEN_DIR(dir, name) _MD_open_dir(dir, name) michael@0: #define _MD_CLOSE_DIR(dir) _MD_close_dir(dir) michael@0: #define _MD_READ_DIR(dir, flags) _MD_read_dir(dir, flags) michael@0: #define _MD_OPEN(name, osflags, mode) _MD_open(name, osflags, mode) michael@0: #define _MD_OPEN_FILE(name, osflags, mode) _MD_open(name, osflags, mode) michael@0: extern PRInt32 _MD_read(PRFileDesc *fd, void *buf, PRInt32 amount); michael@0: #define _MD_READ(fd,buf,amount) _MD_read(fd,buf,amount) michael@0: extern PRInt32 _MD_write(PRFileDesc *fd, const void *buf, PRInt32 amount); michael@0: #define _MD_WRITE(fd,buf,amount) _MD_write(fd,buf,amount) michael@0: #define _MD_DELETE(name) _MD_delete(name) michael@0: #define _MD_GETFILEINFO(fn, info) _MD_getfileinfo(fn, info) michael@0: #define _MD_GETFILEINFO64(fn, info) _MD_getfileinfo64(fn, info) michael@0: #define _MD_GETOPENFILEINFO(fd, info) _MD_getopenfileinfo(fd, info) michael@0: #define _MD_GETOPENFILEINFO64(fd, info) _MD_getopenfileinfo64(fd, info) michael@0: #define _MD_RENAME(from, to) _MD_rename(from, to) michael@0: #define _MD_ACCESS(name, how) _MD_access(name, how) michael@0: #define _MD_MKDIR(name, mode) _MD_mkdir(name, mode) michael@0: #define _MD_MAKE_DIR(name, mode) _MD_mkdir(name, mode) michael@0: #define _MD_RMDIR(name) _MD_rmdir(name) michael@0: #define _MD_ACCEPT_READ(sock, newSock, raddr, buf, amount) _MD_accept_read(sock, newSock, raddr, buf, amount) michael@0: michael@0: #define _MD_LOCKFILE _MD_LockFile michael@0: #define _MD_TLOCKFILE _MD_TLockFile michael@0: #define _MD_UNLOCKFILE _MD_UnlockFile michael@0: michael@0: michael@0: extern PRInt32 _MD_socket(int af, int type, int flags); michael@0: #define _MD_SOCKET _MD_socket michael@0: extern PRInt32 _MD_connect(PRFileDesc *fd, const PRNetAddr *addr, michael@0: PRUint32 addrlen, PRIntervalTime timeout); michael@0: #define _MD_CONNECT _MD_connect michael@0: extern PRInt32 _MD_accept(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen, michael@0: PRIntervalTime timeout); michael@0: #define _MD_ACCEPT _MD_accept michael@0: extern PRInt32 _MD_bind(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen); michael@0: #define _MD_BIND _MD_bind michael@0: extern PRInt32 _MD_listen(PRFileDesc *fd, PRIntn backlog); michael@0: #define _MD_LISTEN _MD_listen michael@0: extern PRInt32 _MD_shutdown(PRFileDesc *fd, PRIntn how); michael@0: #define _MD_SHUTDOWN _MD_shutdown michael@0: michael@0: extern PRInt32 _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount, michael@0: PRIntn flags, PRIntervalTime timeout); michael@0: #define _MD_RECV _MD_recv michael@0: extern PRInt32 _MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount, michael@0: PRIntn flags, PRIntervalTime timeout); michael@0: #define _MD_SEND _MD_send michael@0: extern PRInt32 _MD_recvfrom(PRFileDesc *fd, void *buf, PRInt32 amount, michael@0: PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen, michael@0: PRIntervalTime timeout); michael@0: #define _MD_RECVFROM _MD_recvfrom michael@0: extern PRInt32 _MD_sendto(PRFileDesc *fd, const void *buf, PRInt32 amount, michael@0: PRIntn flags, const PRNetAddr *addr, PRUint32 addrlen, michael@0: PRIntervalTime timeout); michael@0: #define _MD_SENDTO _MD_sendto michael@0: extern PRInt32 _MD_writev(PRFileDesc *fd, const struct PRIOVec *iov, michael@0: PRInt32 iov_size, PRIntervalTime timeout); michael@0: #define _MD_WRITEV _MD_writev michael@0: michael@0: extern PRInt32 _MD_socketavailable(PRFileDesc *fd); michael@0: #define _MD_SOCKETAVAILABLE _MD_socketavailable michael@0: extern PRInt64 _MD_socketavailable64(PRFileDesc *fd); michael@0: #define _MD_SOCKETAVAILABLE64 _MD_socketavailable64 michael@0: michael@0: #define _MD_PIPEAVAILABLE _MD_socketavailable michael@0: michael@0: extern PRInt32 _MD_pr_poll(PRPollDesc *pds, PRIntn npds, michael@0: PRIntervalTime timeout); michael@0: #define _MD_PR_POLL _MD_pr_poll michael@0: michael@0: extern PRInt32 _MD_close(PRInt32 osfd); michael@0: #define _MD_CLOSE_FILE _MD_close michael@0: extern PRInt32 _MD_lseek(PRFileDesc*, PRInt32, PRSeekWhence); michael@0: #define _MD_LSEEK _MD_lseek michael@0: extern PRInt64 _MD_lseek64(PRFileDesc*, PRInt64, PRSeekWhence); michael@0: #define _MD_LSEEK64 _MD_lseek64 michael@0: extern PRInt32 _MD_fsync(PRFileDesc *fd); michael@0: #define _MD_FSYNC _MD_fsync michael@0: michael@0: extern PRInt32 _MD_socketpair(int af, int type, int flags, PRInt32 *osfd); michael@0: #define _MD_SOCKETPAIR _MD_socketpair michael@0: michael@0: #define _MD_CLOSE_SOCKET _MD_close michael@0: michael@0: #ifndef NO_NSPR_10_SUPPORT michael@0: #define _MD_STAT stat michael@0: #endif michael@0: michael@0: extern PRStatus _MD_getpeername(PRFileDesc *fd, PRNetAddr *addr, michael@0: PRUint32 *addrlen); michael@0: #define _MD_GETPEERNAME _MD_getpeername michael@0: extern PRStatus _MD_getsockname(PRFileDesc *fd, PRNetAddr *addr, michael@0: PRUint32 *addrlen); michael@0: #define _MD_GETSOCKNAME _MD_getsockname michael@0: michael@0: extern PRStatus _MD_getsockopt(PRFileDesc *fd, PRInt32 level, michael@0: PRInt32 optname, char* optval, PRInt32* optlen); michael@0: #define _MD_GETSOCKOPT _MD_getsockopt michael@0: extern PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level, michael@0: PRInt32 optname, const char* optval, PRInt32 optlen); michael@0: #define _MD_SETSOCKOPT _MD_setsockopt michael@0: michael@0: extern PRStatus _MD_set_fd_inheritable(PRFileDesc *fd, PRBool inheritable); michael@0: #define _MD_SET_FD_INHERITABLE _MD_set_fd_inheritable michael@0: michael@0: extern void _MD_init_fd_inheritable(PRFileDesc *fd, PRBool imported); michael@0: #define _MD_INIT_FD_INHERITABLE _MD_init_fd_inheritable michael@0: michael@0: extern void _MD_query_fd_inheritable(PRFileDesc *fd); michael@0: #define _MD_QUERY_FD_INHERITABLE _MD_query_fd_inheritable michael@0: michael@0: extern PRStatus _MD_gethostname(char *name, PRUint32 namelen); michael@0: #define _MD_GETHOSTNAME _MD_gethostname michael@0: michael@0: extern PRStatus _MD_getsysinfo(PRSysInfo cmd, char *name, PRUint32 namelen); michael@0: #define _MD_GETSYSINFO _MD_getsysinfo michael@0: michael@0: extern int _MD_unix_get_nonblocking_connect_error(int osfd); michael@0: michael@0: /* Memory-mapped files */ michael@0: michael@0: struct _MDFileMap { michael@0: PRIntn prot; michael@0: PRIntn flags; michael@0: PRBool isAnonFM; /* when true, PR_CloseFileMap() must close the related fd */ michael@0: }; michael@0: michael@0: extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size); michael@0: #define _MD_CREATE_FILE_MAP _MD_CreateFileMap michael@0: michael@0: #define _MD_GET_MEM_MAP_ALIGNMENT() PR_GetPageSize() michael@0: michael@0: extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset, michael@0: PRUint32 len); michael@0: #define _MD_MEM_MAP _MD_MemMap michael@0: michael@0: extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size); michael@0: #define _MD_MEM_UNMAP _MD_MemUnmap michael@0: michael@0: extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap); michael@0: #define _MD_CLOSE_FILE_MAP _MD_CloseFileMap michael@0: michael@0: extern PRStatus _MD_SyncMemMap( michael@0: PRFileDesc *fd, michael@0: void *addr, michael@0: PRUint32 len); michael@0: #define _MD_SYNC_MEM_MAP _MD_SyncMemMap michael@0: michael@0: /* michael@0: * The standard (XPG4) gettimeofday() (from BSD) takes two arguments. michael@0: * On some SVR4 derivatives, gettimeofday() takes only one argument. michael@0: * The GETTIMEOFDAY macro is intended to hide this difference. michael@0: */ michael@0: #ifdef HAVE_SVID_GETTOD michael@0: #define GETTIMEOFDAY(tp) gettimeofday(tp) michael@0: #else michael@0: #define GETTIMEOFDAY(tp) gettimeofday((tp), NULL) michael@0: #endif michael@0: michael@0: #if defined(_PR_PTHREADS) && !defined(_PR_POLL_AVAILABLE) michael@0: #define _PR_NEED_FAKE_POLL michael@0: #endif michael@0: michael@0: #if defined(_PR_NEED_FAKE_POLL) michael@0: michael@0: /* michael@0: * Some platforms don't have poll(), but our pthreads code calls poll(). michael@0: * As a temporary measure, I implemented a fake poll() using select(). michael@0: * Here are the struct and macro definitions copied from sys/poll.h michael@0: * on Solaris 2.5. michael@0: */ michael@0: michael@0: struct pollfd { michael@0: int fd; michael@0: short events; michael@0: short revents; michael@0: }; michael@0: michael@0: /* poll events */ michael@0: michael@0: #define POLLIN 0x0001 /* fd is readable */ michael@0: #define POLLPRI 0x0002 /* high priority info at fd */ michael@0: #define POLLOUT 0x0004 /* fd is writeable (won't block) */ michael@0: #define POLLRDNORM 0x0040 /* normal data is readable */ michael@0: #define POLLWRNORM POLLOUT michael@0: #define POLLRDBAND 0x0080 /* out-of-band data is readable */ michael@0: #define POLLWRBAND 0x0100 /* out-of-band data is writeable */ michael@0: michael@0: #define POLLNORM POLLRDNORM michael@0: michael@0: #define POLLERR 0x0008 /* fd has error condition */ michael@0: #define POLLHUP 0x0010 /* fd has been hung up on */ michael@0: #define POLLNVAL 0x0020 /* invalid pollfd entry */ michael@0: michael@0: extern int poll(struct pollfd *, unsigned long, int); michael@0: michael@0: #endif /* _PR_NEED_FAKE_POLL */ michael@0: michael@0: /* michael@0: ** A vector of the UNIX I/O calls we use. These are here to smooth over michael@0: ** the rough edges needed for large files. All of NSPR's implmentaions michael@0: ** go through this vector using syntax of the form michael@0: ** result = _md_iovector.xxx64(args); michael@0: */ michael@0: michael@0: #if defined(SOLARIS2_5) michael@0: /* michael@0: ** Special case: Solaris 2.5.1 michael@0: ** Solaris starts to have 64-bit file I/O in 2.6. We build on Solaris michael@0: ** 2.5.1 so that we can use the same binaries on both Solaris 2.5.1 and michael@0: ** 2.6. At run time, we detect whether 64-bit file I/O is available by michael@0: ** looking up the 64-bit file function symbols in libc. At build time, michael@0: ** we need to define the 64-bit file I/O datatypes that are compatible michael@0: ** with their definitions on Solaris 2.6. michael@0: */ michael@0: typedef PRInt64 off64_t; michael@0: typedef PRUint64 ino64_t; michael@0: typedef PRInt64 blkcnt64_t; michael@0: struct stat64 { michael@0: dev_t st_dev; michael@0: long st_pad1[3]; michael@0: ino64_t st_ino; michael@0: mode_t st_mode; michael@0: nlink_t st_nlink; michael@0: uid_t st_uid; michael@0: gid_t st_gid; michael@0: dev_t st_rdev; michael@0: long t_pad2[2]; michael@0: off64_t st_size; michael@0: timestruc_t st_atim; michael@0: timestruc_t st_mtim; michael@0: timestruc_t st_ctim; michael@0: long st_blksize; michael@0: blkcnt64_t st_blocks; michael@0: char st_fstype[_ST_FSTYPSZ]; michael@0: long st_pad4[8]; michael@0: }; michael@0: typedef struct stat64 _MDStat64; michael@0: typedef off64_t _MDOff64_t; michael@0: michael@0: #elif defined(_PR_HAVE_OFF64_T) michael@0: typedef struct stat64 _MDStat64; michael@0: typedef off64_t _MDOff64_t; michael@0: #elif defined(_PR_HAVE_LARGE_OFF_T) michael@0: typedef struct stat _MDStat64; michael@0: typedef off_t _MDOff64_t; michael@0: #elif defined(_PR_NO_LARGE_FILES) michael@0: typedef struct stat _MDStat64; michael@0: typedef PRInt64 _MDOff64_t; michael@0: #else michael@0: #error "I don't know yet" michael@0: #endif michael@0: michael@0: typedef PRIntn (*_MD_Fstat64)(PRIntn osfd, _MDStat64 *buf); michael@0: typedef PRIntn (*_MD_Open64)(const char *path, int oflag, ...); michael@0: typedef PRIntn (*_MD_Stat64)(const char *path, _MDStat64 *buf); michael@0: typedef _MDOff64_t (*_MD_Lseek64)(PRIntn osfd, _MDOff64_t, PRIntn whence); michael@0: typedef void* (*_MD_Mmap64)( michael@0: void *addr, PRSize len, PRIntn prot, PRIntn flags, michael@0: PRIntn fildes, _MDOff64_t offset); michael@0: struct _MD_IOVector michael@0: { michael@0: _MD_Open64 _open64; michael@0: _MD_Mmap64 _mmap64; michael@0: _MD_Stat64 _stat64; michael@0: _MD_Fstat64 _fstat64; michael@0: _MD_Lseek64 _lseek64; michael@0: }; michael@0: extern struct _MD_IOVector _md_iovector; michael@0: michael@0: #endif /* prunixos_h___ */