Changeset 102198 in vbox
- Timestamp:
- Nov 21, 2023 12:58:34 PM (17 months ago)
- svn:sync-xref-src-repo-rev:
- 160323
- Location:
- trunk/src/libs/xpcom18a4
- Files:
-
- 4 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/Makefile.kmk
r102194 r102198 171 171 nsprpub/pr/include/prerr.h \ 172 172 nsprpub/pr/include/prerror.h \ 173 nsprpub/pr/include/prinet.h \174 173 nsprpub/pr/include/prinit.h \ 175 174 nsprpub/pr/include/prinrval.h \ 176 nsprpub/pr/include/prio.h \177 175 nsprpub/pr/include/prlock.h \ 178 176 nsprpub/pr/include/prlong.h \ … … 193 191 nsprpub/pr/include/md/_openbsd.h \ 194 192 nsprpub/pr/include/md/_solaris.h \ 195 nsprpub/pr/include/md/_unix_errors.h \196 193 nsprpub/pr/include/md/_unixos.h \ 197 194 nsprpub/pr/include/md/_pth.h \ … … 468 465 469 466 VBox-xpcom-nspr_SOURCES = \ 470 nsprpub/pr/src/io/priometh.c \471 467 nsprpub/pr/src/io/prprf.c \ 472 468 nsprpub/pr/src/misc/prerr.c \ … … 488 484 nsprpub/pr/src/md/unix/unix.c \ 489 485 nsprpub/pr/src/md/unix/unix_errors.c \ 490 nsprpub/pr/src/pthreads/ptio.c \491 486 nsprpub/pr/src/pthreads/ptsynch.c \ 492 487 nsprpub/pr/src/pthreads/ptthread.c -
trunk/src/libs/xpcom18a4/nsprpub/pr/include/nspr.h
r102049 r102198 46 46 #include "prinit.h" 47 47 #include "prinrval.h" 48 #include "prio.h"49 48 #include "prlock.h" 50 49 #include "prlong.h" -
trunk/src/libs/xpcom18a4/nsprpub/pr/src/md/unix/unix.c
r102000 r102198 35 35 #include "primpl.h" 36 36 37 #include <string.h>38 37 #include <signal.h> 39 38 #include <unistd.h> 40 #include <fcntl.h>41 39 #include <sys/types.h> 42 #include <sys/socket.h>43 40 #include <sys/time.h> 44 #include <sys/ioctl.h>45 #include <sys/mman.h>46 #include <unistd.h>47 41 #include <sys/utsname.h> 48 49 #ifdef _PR_POLL_AVAILABLE50 #include <poll.h>51 #endif52 53 /* To get FIONREAD */54 #if defined(NCR) || defined(UNIXWARE) || defined(NEC) || defined(SNI) \55 || defined(SONY)56 #include <sys/filio.h>57 #endif58 59 #if defined(NTO)60 #include <sys/statvfs.h>61 #endif62 63 #if defined(FREEBSD)64 # include <signal.h>65 #endif66 42 67 43 #ifdef VBOX … … 70 46 #endif 71 47 72 /*73 * Make sure _PRSockLen_t is 32-bit, because we will cast a PRUint32* or74 * PRInt32* pointer to a _PRSockLen_t* pointer.75 */76 #if defined(HAVE_SOCKLEN_T) \77 || (defined(LINUX) && defined(__GLIBC__) && __GLIBC__ >= 2)78 #define _PRSockLen_t socklen_t79 #elif defined(IRIX) || defined(HPUX) || defined(OSF1) || defined(SOLARIS) \80 || defined(AIX4_1) || defined(LINUX) || defined(SONY) \81 || defined(BSDI) || defined(SCO) || defined(NEC) || defined(SNI) \82 || defined(SUNOS4) || defined(NCR) || defined(DARWIN) \83 || defined(NEXTSTEP) || defined(QNX)84 #define _PRSockLen_t int85 #elif (defined(AIX) && !defined(AIX4_1)) || defined(FREEBSD) \86 || defined(NETBSD) || defined(OPENBSD) || defined(UNIXWARE) \87 || defined(DGUX) || defined(VMS) || defined(NTO)88 #define _PRSockLen_t size_t89 #else90 #error "Cannot determine architecture"91 #endif92 93 static PRInt64 minus_one;94 95 48 sigset_t timer_set; 96 97 void _MD_query_fd_inheritable(PRFileDesc *fd)98 {99 int flags;100 101 Assert(_PR_TRI_UNKNOWN == fd->secret->inheritable);102 flags = fcntl(fd->secret->md.osfd, F_GETFD, 0);103 Assert(-1 != flags);104 fd->secret->inheritable = (flags & FD_CLOEXEC) ?105 _PR_TRI_FALSE : _PR_TRI_TRUE;106 }107 108 PROffset32 _MD_lseek(PRFileDesc *fd, PROffset32 offset, PRSeekWhence whence)109 {110 PROffset32 rv, where;111 112 switch (whence) {113 case PR_SEEK_SET:114 where = SEEK_SET;115 break;116 case PR_SEEK_CUR:117 where = SEEK_CUR;118 break;119 case PR_SEEK_END:120 where = SEEK_END;121 break;122 default:123 PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);124 rv = -1;125 goto done;126 }127 rv = lseek(fd->secret->md.osfd,offset,where);128 if (rv == -1)129 {130 PRInt32 syserr = _MD_ERRNO();131 _PR_MD_MAP_LSEEK_ERROR(syserr);132 }133 done:134 return(rv);135 }136 137 PROffset64 _MD_lseek64(PRFileDesc *fd, PROffset64 offset, PRSeekWhence whence)138 {139 PRInt32 where;140 PROffset64 rv;141 142 switch (whence)143 {144 case PR_SEEK_SET:145 where = SEEK_SET;146 break;147 case PR_SEEK_CUR:148 where = SEEK_CUR;149 break;150 case PR_SEEK_END:151 where = SEEK_END;152 break;153 default:154 PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);155 rv = minus_one;156 goto done;157 }158 rv = _md_iovector._lseek64(fd->secret->md.osfd, offset, where);159 if (LL_EQ(rv, minus_one))160 {161 PRInt32 syserr = _MD_ERRNO();162 _PR_MD_MAP_LSEEK_ERROR(syserr);163 }164 done:165 return rv;166 } /* _MD_lseek64 */167 168 /*169 ** _MD_set_fileinfo_times --170 ** Set the modifyTime and creationTime of the PRFileInfo171 ** structure using the values in struct stat.172 **173 ** _MD_set_fileinfo64_times --174 ** Set the modifyTime and creationTime of the PRFileInfo64175 ** structure using the values in _MDStat64.176 */177 178 #if defined(_PR_STAT_HAS_ST_ATIM)179 /*180 ** struct stat has st_atim, st_mtim, and st_ctim fields of181 ** type timestruc_t.182 */183 static void _MD_set_fileinfo_times(184 const struct stat *sb,185 PRFileInfo *info)186 {187 PRInt64 us, s2us;188 189 LL_I2L(s2us, PR_USEC_PER_SEC);190 LL_I2L(info->modifyTime, sb->st_mtim.tv_sec);191 LL_MUL(info->modifyTime, info->modifyTime, s2us);192 LL_I2L(us, sb->st_mtim.tv_nsec / 1000);193 LL_ADD(info->modifyTime, info->modifyTime, us);194 LL_I2L(info->creationTime, sb->st_ctim.tv_sec);195 LL_MUL(info->creationTime, info->creationTime, s2us);196 LL_I2L(us, sb->st_ctim.tv_nsec / 1000);197 LL_ADD(info->creationTime, info->creationTime, us);198 }199 200 static void _MD_set_fileinfo64_times(201 const _MDStat64 *sb,202 PRFileInfo64 *info)203 {204 PRInt64 us, s2us;205 206 LL_I2L(s2us, PR_USEC_PER_SEC);207 LL_I2L(info->modifyTime, sb->st_mtim.tv_sec);208 LL_MUL(info->modifyTime, info->modifyTime, s2us);209 LL_I2L(us, sb->st_mtim.tv_nsec / 1000);210 LL_ADD(info->modifyTime, info->modifyTime, us);211 LL_I2L(info->creationTime, sb->st_ctim.tv_sec);212 LL_MUL(info->creationTime, info->creationTime, s2us);213 LL_I2L(us, sb->st_ctim.tv_nsec / 1000);214 LL_ADD(info->creationTime, info->creationTime, us);215 }216 #elif defined(_PR_STAT_HAS_ST_ATIM_UNION)217 /*218 ** The st_atim, st_mtim, and st_ctim fields in struct stat are219 ** unions with a st__tim union member of type timestruc_t.220 */221 static void _MD_set_fileinfo_times(222 const struct stat *sb,223 PRFileInfo *info)224 {225 PRInt64 us, s2us;226 227 LL_I2L(s2us, PR_USEC_PER_SEC);228 LL_I2L(info->modifyTime, sb->st_mtim.st__tim.tv_sec);229 LL_MUL(info->modifyTime, info->modifyTime, s2us);230 LL_I2L(us, sb->st_mtim.st__tim.tv_nsec / 1000);231 LL_ADD(info->modifyTime, info->modifyTime, us);232 LL_I2L(info->creationTime, sb->st_ctim.st__tim.tv_sec);233 LL_MUL(info->creationTime, info->creationTime, s2us);234 LL_I2L(us, sb->st_ctim.st__tim.tv_nsec / 1000);235 LL_ADD(info->creationTime, info->creationTime, us);236 }237 238 static void _MD_set_fileinfo64_times(239 const _MDStat64 *sb,240 PRFileInfo64 *info)241 {242 PRInt64 us, s2us;243 244 LL_I2L(s2us, PR_USEC_PER_SEC);245 LL_I2L(info->modifyTime, sb->st_mtim.st__tim.tv_sec);246 LL_MUL(info->modifyTime, info->modifyTime, s2us);247 LL_I2L(us, sb->st_mtim.st__tim.tv_nsec / 1000);248 LL_ADD(info->modifyTime, info->modifyTime, us);249 LL_I2L(info->creationTime, sb->st_ctim.st__tim.tv_sec);250 LL_MUL(info->creationTime, info->creationTime, s2us);251 LL_I2L(us, sb->st_ctim.st__tim.tv_nsec / 1000);252 LL_ADD(info->creationTime, info->creationTime, us);253 }254 #elif defined(_PR_STAT_HAS_ST_ATIMESPEC)255 /*256 ** struct stat has st_atimespec, st_mtimespec, and st_ctimespec257 ** fields of type struct timespec.258 */259 #if defined(_PR_TIMESPEC_HAS_TS_SEC)260 static void _MD_set_fileinfo_times(261 const struct stat *sb,262 PRFileInfo *info)263 {264 PRInt64 us, s2us;265 266 LL_I2L(s2us, PR_USEC_PER_SEC);267 LL_I2L(info->modifyTime, sb->st_mtimespec.ts_sec);268 LL_MUL(info->modifyTime, info->modifyTime, s2us);269 LL_I2L(us, sb->st_mtimespec.ts_nsec / 1000);270 LL_ADD(info->modifyTime, info->modifyTime, us);271 LL_I2L(info->creationTime, sb->st_ctimespec.ts_sec);272 LL_MUL(info->creationTime, info->creationTime, s2us);273 LL_I2L(us, sb->st_ctimespec.ts_nsec / 1000);274 LL_ADD(info->creationTime, info->creationTime, us);275 }276 277 static void _MD_set_fileinfo64_times(278 const _MDStat64 *sb,279 PRFileInfo64 *info)280 {281 PRInt64 us, s2us;282 283 LL_I2L(s2us, PR_USEC_PER_SEC);284 LL_I2L(info->modifyTime, sb->st_mtimespec.ts_sec);285 LL_MUL(info->modifyTime, info->modifyTime, s2us);286 LL_I2L(us, sb->st_mtimespec.ts_nsec / 1000);287 LL_ADD(info->modifyTime, info->modifyTime, us);288 LL_I2L(info->creationTime, sb->st_ctimespec.ts_sec);289 LL_MUL(info->creationTime, info->creationTime, s2us);290 LL_I2L(us, sb->st_ctimespec.ts_nsec / 1000);291 LL_ADD(info->creationTime, info->creationTime, us);292 }293 #else /* _PR_TIMESPEC_HAS_TS_SEC */294 /*295 ** The POSIX timespec structure has tv_sec and tv_nsec.296 */297 static void _MD_set_fileinfo_times(298 const struct stat *sb,299 PRFileInfo *info)300 {301 PRInt64 us, s2us;302 303 LL_I2L(s2us, PR_USEC_PER_SEC);304 LL_I2L(info->modifyTime, sb->st_mtimespec.tv_sec);305 LL_MUL(info->modifyTime, info->modifyTime, s2us);306 LL_I2L(us, sb->st_mtimespec.tv_nsec / 1000);307 LL_ADD(info->modifyTime, info->modifyTime, us);308 LL_I2L(info->creationTime, sb->st_ctimespec.tv_sec);309 LL_MUL(info->creationTime, info->creationTime, s2us);310 LL_I2L(us, sb->st_ctimespec.tv_nsec / 1000);311 LL_ADD(info->creationTime, info->creationTime, us);312 }313 314 static void _MD_set_fileinfo64_times(315 const _MDStat64 *sb,316 PRFileInfo64 *info)317 {318 PRInt64 us, s2us;319 320 LL_I2L(s2us, PR_USEC_PER_SEC);321 LL_I2L(info->modifyTime, sb->st_mtimespec.tv_sec);322 LL_MUL(info->modifyTime, info->modifyTime, s2us);323 LL_I2L(us, sb->st_mtimespec.tv_nsec / 1000);324 LL_ADD(info->modifyTime, info->modifyTime, us);325 LL_I2L(info->creationTime, sb->st_ctimespec.tv_sec);326 LL_MUL(info->creationTime, info->creationTime, s2us);327 LL_I2L(us, sb->st_ctimespec.tv_nsec / 1000);328 LL_ADD(info->creationTime, info->creationTime, us);329 }330 #endif /* _PR_TIMESPEC_HAS_TS_SEC */331 #elif defined(_PR_STAT_HAS_ONLY_ST_ATIME)332 /*333 ** struct stat only has st_atime, st_mtime, and st_ctime fields334 ** of type time_t.335 */336 static void _MD_set_fileinfo_times(337 const struct stat *sb,338 PRFileInfo *info)339 {340 PRInt64 s, s2us;341 LL_I2L(s2us, PR_USEC_PER_SEC);342 LL_I2L(s, sb->st_mtime);343 LL_MUL(s, s, s2us);344 info->modifyTime = s;345 LL_I2L(s, sb->st_ctime);346 LL_MUL(s, s, s2us);347 info->creationTime = s;348 }349 350 static void _MD_set_fileinfo64_times(351 const _MDStat64 *sb,352 PRFileInfo64 *info)353 {354 PRInt64 s, s2us;355 LL_I2L(s2us, PR_USEC_PER_SEC);356 LL_I2L(s, sb->st_mtime);357 LL_MUL(s, s, s2us);358 info->modifyTime = s;359 LL_I2L(s, sb->st_ctime);360 LL_MUL(s, s, s2us);361 info->creationTime = s;362 }363 #else364 #error "I don't know yet"365 #endif366 367 static int _MD_convert_stat_to_fileinfo(368 const struct stat *sb,369 PRFileInfo *info)370 {371 if (S_IFREG & sb->st_mode)372 info->type = PR_FILE_FILE;373 else if (S_IFDIR & sb->st_mode)374 info->type = PR_FILE_DIRECTORY;375 else376 info->type = PR_FILE_OTHER;377 378 #if defined(_PR_HAVE_LARGE_OFF_T)379 if (0x7fffffffL < sb->st_size)380 {381 PR_SetError(PR_FILE_TOO_BIG_ERROR, 0);382 return -1;383 }384 #endif /* defined(_PR_HAVE_LARGE_OFF_T) */385 info->size = sb->st_size;386 387 _MD_set_fileinfo_times(sb, info);388 return 0;389 } /* _MD_convert_stat_to_fileinfo */390 391 static int _MD_convert_stat64_to_fileinfo64(392 const _MDStat64 *sb,393 PRFileInfo64 *info)394 {395 if (S_IFREG & sb->st_mode)396 info->type = PR_FILE_FILE;397 else if (S_IFDIR & sb->st_mode)398 info->type = PR_FILE_DIRECTORY;399 else400 info->type = PR_FILE_OTHER;401 402 LL_I2L(info->size, sb->st_size);403 404 _MD_set_fileinfo64_times(sb, info);405 return 0;406 } /* _MD_convert_stat64_to_fileinfo64 */407 408 PRInt32 _MD_getfileinfo(const char *fn, PRFileInfo *info)409 {410 PRInt32 rv;411 struct stat sb;412 413 rv = stat(fn, &sb);414 if (rv < 0)415 _PR_MD_MAP_STAT_ERROR(_MD_ERRNO());416 else if (NULL != info)417 rv = _MD_convert_stat_to_fileinfo(&sb, info);418 return rv;419 }420 421 PRInt32 _MD_getfileinfo64(const char *fn, PRFileInfo64 *info)422 {423 _MDStat64 sb;424 PRInt32 rv = _md_iovector._stat64(fn, &sb);425 if (rv < 0)426 _PR_MD_MAP_STAT_ERROR(_MD_ERRNO());427 else if (NULL != info)428 rv = _MD_convert_stat64_to_fileinfo64(&sb, info);429 return rv;430 }431 432 PRInt32 _MD_getopenfileinfo(const PRFileDesc *fd, PRFileInfo *info)433 {434 struct stat sb;435 PRInt32 rv = fstat(fd->secret->md.osfd, &sb);436 if (rv < 0)437 _PR_MD_MAP_FSTAT_ERROR(_MD_ERRNO());438 else if (NULL != info)439 rv = _MD_convert_stat_to_fileinfo(&sb, info);440 return rv;441 }442 443 PRInt32 _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info)444 {445 _MDStat64 sb;446 PRInt32 rv = _md_iovector._fstat64(fd->secret->md.osfd, &sb);447 if (rv < 0)448 _PR_MD_MAP_FSTAT_ERROR(_MD_ERRNO());449 else if (NULL != info)450 rv = _MD_convert_stat64_to_fileinfo64(&sb, info);451 return rv;452 }453 454 struct _MD_IOVector _md_iovector = { open };455 456 /*457 ** These implementations are to emulate large file routines on systems that458 ** don't have them. Their goal is to check in case overflow occurs. Otherwise459 ** they will just operate as normal using 32-bit file routines.460 **461 ** The checking might be pre- or post-op, depending on the semantics.462 */463 464 #if defined(_PR_NO_LARGE_FILES)465 466 static PROffset64 _MD_Unix_lseek64(PRIntn osfd, PROffset64 offset, PRIntn whence)467 {468 PRUint64 maxoff;469 PROffset64 rv = minus_one;470 LL_I2L(maxoff, 0x7fffffff);471 if (LL_CMP(offset, <=, maxoff))472 {473 off_t off;474 LL_L2I(off, offset);475 LL_I2L(rv, lseek(osfd, off, whence));476 }477 else errno = EFBIG; /* we can't go there */478 return rv;479 } /* _MD_Unix_lseek64 */480 481 static void* _MD_Unix_mmap64(482 void *addr, PRSize len, PRIntn prot, PRIntn flags,483 PRIntn fildes, PRInt64 offset)484 {485 PR_SetError(PR_FILE_TOO_BIG_ERROR, 0);486 return NULL;487 } /* _MD_Unix_mmap64 */488 #endif /* defined(_PR_NO_LARGE_FILES) */489 490 static void _PR_InitIOV(void)491 {492 #if defined(_PR_NO_LARGE_FILES)493 _md_iovector._open64 = open;494 _md_iovector._mmap64 = _MD_Unix_mmap64;495 _md_iovector._fstat64 = fstat;496 _md_iovector._stat64 = stat;497 _md_iovector._lseek64 = _MD_Unix_lseek64;498 #elif defined(_PR_HAVE_OFF64_T)499 _md_iovector._open64 = open64;500 _md_iovector._mmap64 = mmap64;501 _md_iovector._fstat64 = fstat64;502 _md_iovector._stat64 = stat64;503 _md_iovector._lseek64 = lseek64;504 #elif defined(_PR_HAVE_LARGE_OFF_T)505 _md_iovector._open64 = open;506 _md_iovector._mmap64 = mmap;507 _md_iovector._fstat64 = fstat;508 _md_iovector._stat64 = stat;509 _md_iovector._lseek64 = lseek;510 #else511 #error "I don't know yet"512 #endif513 LL_I2L(minus_one, -1);514 } /* _PR_InitIOV */515 49 516 50 void _PR_UnixInit(void) … … 526 60 rv = sigaction(SIGPIPE, &sigact, 0); 527 61 Assert(0 == rv); 528 529 _PR_InitIOV(); /* one last hack */530 62 } 531 63 … … 575 107 } 576 108 577 /*578 * When a nonblocking connect has completed, determine whether it579 * succeeded or failed, and if it failed, what the error code is.580 *581 * The function returns the error code. An error code of 0 means582 * that the nonblocking connect succeeded.583 */584 585 int _MD_unix_get_nonblocking_connect_error(int osfd)586 {587 int err;588 _PRSockLen_t optlen = sizeof(err);589 if (getsockopt(osfd, SOL_SOCKET, SO_ERROR, (char *) &err, &optlen) == -1) {590 return errno;591 } else {592 return err;593 }594 }595 596 109 /************************************************************************/ 597 598 PR_IMPLEMENT(PRStatus) _MD_gethostname(char *name, PRUint32 namelen)599 {600 PRIntn rv;601 602 rv = gethostname(name, namelen);603 if (0 == rv) {604 return PR_SUCCESS;605 }606 _PR_MD_MAP_GETHOSTNAME_ERROR(_MD_ERRNO());607 return PR_FAILURE;608 }609 610 #if defined(_PR_NEED_FAKE_POLL)611 612 /*613 * Some platforms don't have poll(). For easier porting of code614 * that calls poll(), we emulate poll() using select().615 */616 617 int poll(struct pollfd *filedes, unsigned long nfds, int timeout)618 {619 int i;620 int rv;621 int maxfd;622 fd_set rd, wr, ex;623 struct timeval tv, *tvp;624 625 if (timeout < 0 && timeout != -1) {626 errno = EINVAL;627 return -1;628 }629 630 if (timeout == -1) {631 tvp = NULL;632 } else {633 tv.tv_sec = timeout / 1000;634 tv.tv_usec = (timeout % 1000) * 1000;635 tvp = &tv;636 }637 638 maxfd = -1;639 FD_ZERO(&rd);640 FD_ZERO(&wr);641 FD_ZERO(&ex);642 643 for (i = 0; i < nfds; i++) {644 int osfd = filedes[i].fd;645 int events = filedes[i].events;646 PRBool fdHasEvent = PR_FALSE;647 648 if (osfd < 0) {649 continue; /* Skip this osfd. */650 }651 652 /*653 * Map the poll events to the select fd_sets.654 * POLLIN, POLLRDNORM ===> readable655 * POLLOUT, POLLWRNORM ===> writable656 * POLLPRI, POLLRDBAND ===> exception657 * POLLNORM, POLLWRBAND (and POLLMSG on some platforms)658 * are ignored.659 *660 * The output events POLLERR and POLLHUP are never turned on.661 * POLLNVAL may be turned on.662 */663 664 if (events & (POLLIN | POLLRDNORM)) {665 FD_SET(osfd, &rd);666 fdHasEvent = PR_TRUE;667 }668 if (events & (POLLOUT | POLLWRNORM)) {669 FD_SET(osfd, &wr);670 fdHasEvent = PR_TRUE;671 }672 if (events & (POLLPRI | POLLRDBAND)) {673 FD_SET(osfd, &ex);674 fdHasEvent = PR_TRUE;675 }676 if (fdHasEvent && osfd > maxfd) {677 maxfd = osfd;678 }679 }680 681 rv = select(maxfd + 1, &rd, &wr, &ex, tvp);682 683 /* Compute poll results */684 if (rv > 0) {685 rv = 0;686 for (i = 0; i < nfds; i++) {687 PRBool fdHasEvent = PR_FALSE;688 689 filedes[i].revents = 0;690 if (filedes[i].fd < 0) {691 continue;692 }693 if (FD_ISSET(filedes[i].fd, &rd)) {694 if (filedes[i].events & POLLIN) {695 filedes[i].revents |= POLLIN;696 }697 if (filedes[i].events & POLLRDNORM) {698 filedes[i].revents |= POLLRDNORM;699 }700 fdHasEvent = PR_TRUE;701 }702 if (FD_ISSET(filedes[i].fd, &wr)) {703 if (filedes[i].events & POLLOUT) {704 filedes[i].revents |= POLLOUT;705 }706 if (filedes[i].events & POLLWRNORM) {707 filedes[i].revents |= POLLWRNORM;708 }709 fdHasEvent = PR_TRUE;710 }711 if (FD_ISSET(filedes[i].fd, &ex)) {712 if (filedes[i].events & POLLPRI) {713 filedes[i].revents |= POLLPRI;714 }715 if (filedes[i].events & POLLRDBAND) {716 filedes[i].revents |= POLLRDBAND;717 }718 fdHasEvent = PR_TRUE;719 }720 if (fdHasEvent) {721 rv++;722 }723 }724 Assert(rv > 0);725 } else if (rv == -1 && errno == EBADF) {726 rv = 0;727 for (i = 0; i < nfds; i++) {728 filedes[i].revents = 0;729 if (filedes[i].fd < 0) {730 continue;731 }732 if (fcntl(filedes[i].fd, F_GETFL, 0) == -1) {733 filedes[i].revents = POLLNVAL;734 rv++;735 }736 }737 Assert(rv > 0);738 }739 Assert(-1 != timeout || rv != 0);740 741 return rv;742 }743 #endif /* _PR_NEED_FAKE_POLL */744 110 745 111 void _MD_EarlyInit(void) -
trunk/src/libs/xpcom18a4/nsprpub/pr/src/md/unix/unix_errors.c
r1 r102198 37 37 38 38 #include "primpl.h" 39 #if defined(_PR_POLL_AVAILABLE)40 #include <poll.h>41 #endif42 39 #include <errno.h> 43 40 … … 258 255 PR_SetError(prError, err); 259 256 } 260 261 void _MD_unix_map_opendir_error(int err)262 {263 _MD_unix_map_default_error(err);264 }265 266 void _MD_unix_map_closedir_error(int err)267 {268 PRErrorCode prError;269 270 switch (err) {271 case EINVAL:272 prError = PR_BAD_DESCRIPTOR_ERROR;273 break;274 default:275 _MD_unix_map_default_error(err);276 return;277 }278 PR_SetError(prError, err);279 }280 281 void _MD_unix_readdir_error(int err)282 {283 PRErrorCode prError;284 285 switch (err) {286 case ENOENT:287 prError = PR_NO_MORE_FILES_ERROR;288 break;289 #ifdef EOVERFLOW290 case EOVERFLOW:291 prError = PR_IO_ERROR;292 break;293 #endif294 case EINVAL:295 prError = PR_IO_ERROR;296 break;297 case ENXIO:298 prError = PR_IO_ERROR;299 break;300 default:301 _MD_unix_map_default_error(err);302 return;303 }304 PR_SetError(prError, err);305 }306 307 void _MD_unix_map_unlink_error(int err)308 {309 PRErrorCode prError;310 311 switch (err) {312 case EPERM:313 prError = PR_IS_DIRECTORY_ERROR;314 break;315 default:316 _MD_unix_map_default_error(err);317 return;318 }319 PR_SetError(prError, err);320 }321 322 void _MD_unix_map_stat_error(int err)323 {324 PRErrorCode prError;325 326 switch (err) {327 case ETIMEDOUT:328 prError = PR_REMOTE_FILE_ERROR;329 break;330 default:331 _MD_unix_map_default_error(err);332 return;333 }334 PR_SetError(prError, err);335 }336 337 void _MD_unix_map_fstat_error(int err)338 {339 PRErrorCode prError;340 341 switch (err) {342 case ETIMEDOUT:343 prError = PR_REMOTE_FILE_ERROR;344 break;345 default:346 _MD_unix_map_default_error(err);347 return;348 }349 PR_SetError(prError, err);350 }351 352 void _MD_unix_map_rename_error(int err)353 {354 PRErrorCode prError;355 356 switch (err) {357 case EEXIST:358 prError = PR_DIRECTORY_NOT_EMPTY_ERROR;359 break;360 default:361 _MD_unix_map_default_error(err);362 return;363 }364 PR_SetError(prError, err);365 }366 367 void _MD_unix_map_access_error(int err)368 {369 PRErrorCode prError;370 371 switch (err) {372 case ETIMEDOUT:373 prError = PR_REMOTE_FILE_ERROR;374 break;375 default:376 _MD_unix_map_default_error(err);377 return;378 }379 PR_SetError(prError, err);380 }381 382 void _MD_unix_map_mkdir_error(int err)383 {384 _MD_unix_map_default_error(err);385 }386 387 void _MD_unix_map_rmdir_error(int err)388 {389 PRErrorCode prError;390 391 switch (err) {392 /*393 * On AIX 4.3, ENOTEMPTY is defined as EEXIST.394 */395 #if ENOTEMPTY != EEXIST396 case ENOTEMPTY:397 prError = PR_DIRECTORY_NOT_EMPTY_ERROR;398 break;399 #endif400 case EEXIST:401 prError = PR_DIRECTORY_NOT_EMPTY_ERROR;402 break;403 case EINVAL:404 prError = PR_DIRECTORY_NOT_EMPTY_ERROR;405 break;406 case ETIMEDOUT:407 prError = PR_REMOTE_FILE_ERROR;408 break;409 default:410 _MD_unix_map_default_error(err);411 return;412 }413 PR_SetError(prError, err);414 }415 416 void _MD_unix_map_read_error(int err)417 {418 PRErrorCode prError;419 420 switch (err) {421 case EINVAL:422 prError = PR_INVALID_METHOD_ERROR;423 break;424 case ENXIO:425 prError = PR_INVALID_ARGUMENT_ERROR;426 break;427 default:428 _MD_unix_map_default_error(err);429 return;430 }431 PR_SetError(prError, err);432 }433 434 void _MD_unix_map_write_error(int err)435 {436 PRErrorCode prError;437 438 switch (err) {439 case EINVAL:440 prError = PR_INVALID_METHOD_ERROR;441 break;442 case ENXIO:443 prError = PR_INVALID_METHOD_ERROR;444 break;445 case ETIMEDOUT:446 prError = PR_REMOTE_FILE_ERROR;447 break;448 default:449 _MD_unix_map_default_error(err);450 return;451 }452 PR_SetError(prError, err);453 }454 455 void _MD_unix_map_lseek_error(int err)456 {457 _MD_unix_map_default_error(err);458 }459 460 void _MD_unix_map_fsync_error(int err)461 {462 PRErrorCode prError;463 464 switch (err) {465 case ETIMEDOUT:466 prError = PR_REMOTE_FILE_ERROR;467 break;468 case EINVAL:469 prError = PR_INVALID_METHOD_ERROR;470 break;471 default:472 _MD_unix_map_default_error(err);473 return;474 }475 PR_SetError(prError, err);476 }477 478 void _MD_unix_map_close_error(int err)479 {480 PRErrorCode prError;481 482 switch (err) {483 case ETIMEDOUT:484 prError = PR_REMOTE_FILE_ERROR;485 break;486 default:487 _MD_unix_map_default_error(err);488 return;489 }490 PR_SetError(prError, err);491 }492 493 void _MD_unix_map_socket_error(int err)494 {495 PRErrorCode prError;496 497 switch (err) {498 case ENOMEM:499 prError = PR_INSUFFICIENT_RESOURCES_ERROR;500 break;501 default:502 _MD_unix_map_default_error(err);503 return;504 }505 PR_SetError(prError, err);506 }507 508 void _MD_unix_map_socketavailable_error(int err)509 {510 PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);511 }512 513 void _MD_unix_map_recv_error(int err)514 {515 _MD_unix_map_default_error(err);516 }517 518 void _MD_unix_map_recvfrom_error(int err)519 {520 _MD_unix_map_default_error(err);521 }522 523 void _MD_unix_map_send_error(int err)524 {525 _MD_unix_map_default_error(err);526 }527 528 void _MD_unix_map_sendto_error(int err)529 {530 _MD_unix_map_default_error(err);531 }532 533 void _MD_unix_map_writev_error(int err)534 {535 _MD_unix_map_default_error(err);536 }537 538 void _MD_unix_map_accept_error(int err)539 {540 PRErrorCode prError;541 542 switch (err) {543 case ENODEV:544 prError = PR_NOT_TCP_SOCKET_ERROR;545 break;546 default:547 _MD_unix_map_default_error(err);548 return;549 }550 PR_SetError(prError, err);551 }552 553 void _MD_unix_map_connect_error(int err)554 {555 PRErrorCode prError;556 557 switch (err) {558 case EACCES:559 prError = PR_ADDRESS_NOT_SUPPORTED_ERROR;560 break;561 #if defined(UNIXWARE) || defined(SNI) || defined(NEC)562 /*563 * On some platforms, if we connect to a port on the local host564 * (the loopback address) that no process is listening on, we get565 * EIO instead of ECONNREFUSED.566 */567 case EIO:568 prError = PR_CONNECT_REFUSED_ERROR;569 break;570 #endif571 case ELOOP:572 prError = PR_ADDRESS_NOT_SUPPORTED_ERROR;573 break;574 case ENOENT:575 prError = PR_ADDRESS_NOT_SUPPORTED_ERROR;576 break;577 case ENXIO:578 prError = PR_IO_ERROR;579 break;580 default:581 _MD_unix_map_default_error(err);582 return;583 }584 PR_SetError(prError, err);585 }586 587 void _MD_unix_map_bind_error(int err)588 {589 PRErrorCode prError;590 591 switch (err) {592 case EINVAL:593 prError = PR_SOCKET_ADDRESS_IS_BOUND_ERROR;594 break;595 /*596 * UNIX domain sockets are not supported in NSPR597 */598 case EIO:599 case EISDIR:600 case ELOOP:601 case ENOENT:602 case ENOTDIR:603 case EROFS:604 prError = PR_ADDRESS_NOT_SUPPORTED_ERROR;605 break;606 default:607 _MD_unix_map_default_error(err);608 return;609 }610 PR_SetError(prError, err);611 }612 613 void _MD_unix_map_listen_error(int err)614 {615 _MD_unix_map_default_error(err);616 }617 618 void _MD_unix_map_shutdown_error(int err)619 {620 _MD_unix_map_default_error(err);621 }622 623 void _MD_unix_map_socketpair_error(int err)624 {625 PRErrorCode prError;626 627 switch (err) {628 case ENOMEM:629 prError = PR_INSUFFICIENT_RESOURCES_ERROR;630 break;631 default:632 _MD_unix_map_default_error(err);633 return;634 }635 PR_SetError(prError, err);636 }637 638 void _MD_unix_map_getsockname_error(int err)639 {640 PRErrorCode prError;641 642 switch (err) {643 case ENOMEM:644 prError = PR_INSUFFICIENT_RESOURCES_ERROR;645 break;646 default:647 _MD_unix_map_default_error(err);648 return;649 }650 PR_SetError(prError, err);651 }652 653 void _MD_unix_map_getpeername_error(int err)654 {655 PRErrorCode prError;656 657 switch (err) {658 case ENOMEM:659 prError = PR_INSUFFICIENT_RESOURCES_ERROR;660 break;661 default:662 _MD_unix_map_default_error(err);663 return;664 }665 PR_SetError(prError, err);666 }667 668 void _MD_unix_map_getsockopt_error(int err)669 {670 PRErrorCode prError;671 672 switch (err) {673 case EINVAL:674 prError = PR_BUFFER_OVERFLOW_ERROR;675 break;676 case ENOMEM:677 prError = PR_INSUFFICIENT_RESOURCES_ERROR;678 break;679 default:680 _MD_unix_map_default_error(err);681 return;682 }683 PR_SetError(prError, err);684 }685 686 void _MD_unix_map_setsockopt_error(int err)687 {688 PRErrorCode prError;689 690 switch (err) {691 case EINVAL:692 prError = PR_BUFFER_OVERFLOW_ERROR;693 break;694 case ENOMEM:695 prError = PR_INSUFFICIENT_RESOURCES_ERROR;696 break;697 default:698 _MD_unix_map_default_error(err);699 return;700 }701 PR_SetError(prError, err);702 }703 704 void _MD_unix_map_open_error(int err)705 {706 PRErrorCode prError;707 708 switch (err) {709 case EAGAIN:710 prError = PR_INSUFFICIENT_RESOURCES_ERROR;711 break;712 case EBUSY:713 prError = PR_IO_ERROR;714 break;715 case ENODEV:716 prError = PR_FILE_NOT_FOUND_ERROR;717 break;718 case ENOMEM:719 prError = PR_INSUFFICIENT_RESOURCES_ERROR;720 break;721 #ifdef EOVERFLOW722 case EOVERFLOW:723 prError = PR_FILE_TOO_BIG_ERROR;724 break;725 #endif726 case ETIMEDOUT:727 prError = PR_REMOTE_FILE_ERROR;728 break;729 default:730 _MD_unix_map_default_error(err);731 return;732 }733 PR_SetError(prError, err);734 }735 736 void _MD_unix_map_mmap_error(int err)737 {738 PRErrorCode prError;739 740 switch (err) {741 case EAGAIN:742 prError = PR_INSUFFICIENT_RESOURCES_ERROR;743 break;744 case EMFILE:745 prError = PR_INSUFFICIENT_RESOURCES_ERROR;746 break;747 case ENODEV:748 prError = PR_OPERATION_NOT_SUPPORTED_ERROR;749 break;750 case ENXIO:751 prError = PR_INVALID_ARGUMENT_ERROR;752 break;753 default:754 _MD_unix_map_default_error(err);755 return;756 }757 PR_SetError(prError, err);758 }759 760 void _MD_unix_map_gethostname_error(int err)761 {762 _MD_unix_map_default_error(err);763 }764 765 void _MD_unix_map_select_error(int err)766 {767 _MD_unix_map_default_error(err);768 }769 770 #if defined(_PR_POLL_AVAILABLE) || defined(_PR_NEED_FAKE_POLL)771 void _MD_unix_map_poll_error(int err)772 {773 PRErrorCode prError;774 775 switch (err) {776 case EAGAIN:777 prError = PR_INSUFFICIENT_RESOURCES_ERROR;778 break;779 default:780 _MD_unix_map_default_error(err);781 return;782 }783 PR_SetError(prError, err);784 }785 786 void _MD_unix_map_poll_revents_error(int err)787 {788 if (err & POLLNVAL)789 PR_SetError(PR_BAD_DESCRIPTOR_ERROR, EBADF);790 else if (err & POLLHUP)791 PR_SetError(PR_CONNECT_RESET_ERROR, EPIPE);792 else if (err & POLLERR)793 PR_SetError(PR_IO_ERROR, EIO);794 else795 PR_SetError(PR_UNKNOWN_ERROR, err);796 }797 #endif /* _PR_POLL_AVAILABLE || _PR_NEED_FAKE_POLL */798 799 800 void _MD_unix_map_flock_error(int err)801 {802 PRErrorCode prError;803 804 switch (err) {805 case EINVAL:806 prError = PR_BAD_DESCRIPTOR_ERROR;807 break;808 case EWOULDBLOCK:809 prError = PR_FILE_IS_LOCKED_ERROR;810 break;811 default:812 _MD_unix_map_default_error(err);813 return;814 }815 PR_SetError(prError, err);816 }817 818 void _MD_unix_map_lockf_error(int err)819 {820 PRErrorCode prError;821 822 switch (err) {823 case EACCES:824 prError = PR_FILE_IS_LOCKED_ERROR;825 break;826 case EDEADLK:827 prError = PR_INSUFFICIENT_RESOURCES_ERROR;828 break;829 default:830 _MD_unix_map_default_error(err);831 return;832 }833 PR_SetError(prError, err);834 }835 836 #ifdef AIX837 void _MD_aix_map_sendfile_error(int err)838 {839 _MD_unix_map_default_error(err);840 }841 #endif /* AIX */842 843 #ifdef HPUX11844 void _MD_hpux_map_sendfile_error(int err)845 {846 _MD_unix_map_default_error(err);847 }848 #endif /* HPUX11 */849 850 #ifdef SOLARIS851 void _MD_solaris_map_sendfile_error(int err)852 {853 _MD_unix_map_default_error(err) ;854 }855 #endif /* SOLARIS */856 857 #ifdef LINUX858 void _MD_linux_map_sendfile_error(int err)859 {860 _MD_unix_map_default_error(err) ;861 }862 #endif /* LINUX */ -
trunk/src/libs/xpcom18a4/nsprpub/pr/src/misc/prinit.c
r102049 r102198 82 82 _PR_InitThreads(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); 83 83 84 _PR_InitIO();85 86 84 nspr_InitializePRErrorTable(); 87 85 -
trunk/src/libs/xpcom18a4/nsprpub/pr/src/pthreads/ptthread.c
r102007 r102198 622 622 PR_Unlock(pt_book.ml); 623 623 624 /* Close all the fd's before calling _PR_CleanupIO */625 _PR_CleanupIO();626 627 624 /* 628 625 * I am not sure if it's safe to delete the cv and lock here,
Note:
See TracChangeset
for help on using the changeset viewer.