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