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