summaryrefslogtreecommitdiffstats
path: root/nsprpub/pr/src/md
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2020-01-02 21:01:38 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2020-01-02 21:01:38 +0100
commitf7d30133221896638f7bf4f66c504255c4b14f48 (patch)
tree5f3e07a049f388a3a309a615b8884318f6668a98 /nsprpub/pr/src/md
parent26b297510a11758727438df4669357a2a2bc42ce (diff)
downloadUXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.gz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.lz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.xz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.zip
Issue #1338 - Part 1: Update NSPR to 4.24
Diffstat (limited to 'nsprpub/pr/src/md')
-rw-r--r--nsprpub/pr/src/md/beos/.cvsignore1
-rw-r--r--nsprpub/pr/src/md/beos/Makefile.in28
-rw-r--r--nsprpub/pr/src/md/beos/bcpu.c23
-rw-r--r--nsprpub/pr/src/md/beos/beos.c232
-rw-r--r--nsprpub/pr/src/md/beos/beos_errors.c1494
-rw-r--r--nsprpub/pr/src/md/beos/bfile.c873
-rw-r--r--nsprpub/pr/src/md/beos/bmemory.c10
-rw-r--r--nsprpub/pr/src/md/beos/bmisc.c91
-rw-r--r--nsprpub/pr/src/md/beos/bmmap.c41
-rw-r--r--nsprpub/pr/src/md/beos/bnet.c911
-rw-r--r--nsprpub/pr/src/md/beos/bproc.c212
-rw-r--r--nsprpub/pr/src/md/beos/brng.c40
-rw-r--r--nsprpub/pr/src/md/beos/bseg.c22
-rw-r--r--nsprpub/pr/src/md/beos/bsrcs.mk22
-rw-r--r--nsprpub/pr/src/md/beos/btime.c43
-rw-r--r--nsprpub/pr/src/md/beos/objs.mk11
-rw-r--r--nsprpub/pr/src/md/os2/os2_errors.c1684
-rw-r--r--nsprpub/pr/src/md/os2/os2cv.c96
-rw-r--r--nsprpub/pr/src/md/os2/os2gc.c10
-rw-r--r--nsprpub/pr/src/md/os2/os2inrval.c11
-rw-r--r--nsprpub/pr/src/md/os2/os2io.c438
-rw-r--r--nsprpub/pr/src/md/os2/os2misc.c83
-rw-r--r--nsprpub/pr/src/md/os2/os2poll.c85
-rw-r--r--nsprpub/pr/src/md/os2/os2rng.c25
-rw-r--r--nsprpub/pr/src/md/os2/os2sem.c20
-rw-r--r--nsprpub/pr/src/md/os2/os2sock.c145
-rw-r--r--nsprpub/pr/src/md/os2/os2thred.c114
-rw-r--r--nsprpub/pr/src/md/prosdep.c19
-rw-r--r--nsprpub/pr/src/md/unix/aix.c133
-rw-r--r--nsprpub/pr/src/md/unix/aixwrap.c2
-rw-r--r--nsprpub/pr/src/md/unix/bsdi.c8
-rw-r--r--nsprpub/pr/src/md/unix/darwin.c12
-rw-r--r--nsprpub/pr/src/md/unix/freebsd.c12
-rw-r--r--nsprpub/pr/src/md/unix/hpux.c26
-rw-r--r--nsprpub/pr/src/md/unix/irix.c1648
-rw-r--r--nsprpub/pr/src/md/unix/linux.c24
-rw-r--r--nsprpub/pr/src/md/unix/nto.c10
-rw-r--r--nsprpub/pr/src/md/unix/os_Irix.s134
-rw-r--r--nsprpub/pr/src/md/unix/osf1.c75
-rw-r--r--nsprpub/pr/src/md/unix/pthreads_user.c424
-rw-r--r--nsprpub/pr/src/md/unix/qnx.c6
-rw-r--r--nsprpub/pr/src/md/unix/riscos.c24
-rw-r--r--nsprpub/pr/src/md/unix/scoos.c13
-rw-r--r--nsprpub/pr/src/md/unix/solaris.c24
-rw-r--r--nsprpub/pr/src/md/unix/symbian.c16
-rw-r--r--nsprpub/pr/src/md/unix/unix.c963
-rw-r--r--nsprpub/pr/src/md/unix/unix_errors.c36
-rw-r--r--nsprpub/pr/src/md/unix/unixware.c218
-rw-r--r--nsprpub/pr/src/md/unix/uxpoll.c158
-rw-r--r--nsprpub/pr/src/md/unix/uxproces.c336
-rw-r--r--nsprpub/pr/src/md/unix/uxrng.c111
-rw-r--r--nsprpub/pr/src/md/unix/uxshm.c243
-rw-r--r--nsprpub/pr/src/md/unix/uxwrap.c119
-rw-r--r--nsprpub/pr/src/md/windows/ntdllmn.c5
-rw-r--r--nsprpub/pr/src/md/windows/ntgc.c16
-rw-r--r--nsprpub/pr/src/md/windows/ntinrval.c6
-rw-r--r--nsprpub/pr/src/md/windows/ntio.c2066
-rw-r--r--nsprpub/pr/src/md/windows/ntmisc.c645
-rw-r--r--nsprpub/pr/src/md/windows/ntsec.c66
-rw-r--r--nsprpub/pr/src/md/windows/ntsem.c16
-rw-r--r--nsprpub/pr/src/md/windows/ntthread.c185
-rw-r--r--nsprpub/pr/src/md/windows/w32ipcsem.c20
-rw-r--r--nsprpub/pr/src/md/windows/w32poll.c58
-rw-r--r--nsprpub/pr/src/md/windows/w32rng.c15
-rw-r--r--nsprpub/pr/src/md/windows/w32shm.c139
-rw-r--r--nsprpub/pr/src/md/windows/w95cv.c30
-rw-r--r--nsprpub/pr/src/md/windows/w95dllmain.c5
-rw-r--r--nsprpub/pr/src/md/windows/w95io.c363
-rw-r--r--nsprpub/pr/src/md/windows/w95sock.c114
-rw-r--r--nsprpub/pr/src/md/windows/w95thred.c143
-rw-r--r--nsprpub/pr/src/md/windows/win32_errors.c6
71 files changed, 4889 insertions, 10568 deletions
diff --git a/nsprpub/pr/src/md/beos/.cvsignore b/nsprpub/pr/src/md/beos/.cvsignore
deleted file mode 100644
index f3c7a7c5d..000000000
--- a/nsprpub/pr/src/md/beos/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-Makefile
diff --git a/nsprpub/pr/src/md/beos/Makefile.in b/nsprpub/pr/src/md/beos/Makefile.in
deleted file mode 100644
index 340f144a8..000000000
--- a/nsprpub/pr/src/md/beos/Makefile.in
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-
-MOD_DEPTH = ../../../..
-topsrcdir = @top_srcdir@
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-include $(MOD_DEPTH)/config/autoconf.mk
-
-include $(topsrcdir)/config/config.mk
-
-include $(srcdir)/bsrcs.mk
-CSRCS += $(MDCSRCS)
-
-TARGETS = $(OBJS)
-
-INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include -I$(topsrcdir)/pr/include/private
-
-DEFINES += -D_NSPR_BUILD_
-
-include $(topsrcdir)/config/rules.mk
-
-export:: $(TARGETS)
-
diff --git a/nsprpub/pr/src/md/beos/bcpu.c b/nsprpub/pr/src/md/beos/bcpu.c
deleted file mode 100644
index 6c2538654..000000000
--- a/nsprpub/pr/src/md/beos/bcpu.c
+++ /dev/null
@@ -1,23 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-PR_EXTERN(void) _PR_MD_INIT_CPUS();
-PR_EXTERN(void) _PR_MD_WAKEUP_CPUS();
-PR_EXTERN(void) _PR_MD_START_INTERRUPTS(void);
-PR_EXTERN(void) _PR_MD_STOP_INTERRUPTS(void);
-PR_EXTERN(void) _PR_MD_DISABLE_CLOCK_INTERRUPTS(void);
-PR_EXTERN(void) _PR_MD_BLOCK_CLOCK_INTERRUPTS(void);
-PR_EXTERN(void) _PR_MD_UNBLOCK_CLOCK_INTERRUPTS(void);
-PR_EXTERN(void) _PR_MD_CLOCK_INTERRUPT(void);
-PR_EXTERN(void) _PR_MD_INIT_STACK(PRThreadStack *ts, PRIntn redzone);
-PR_EXTERN(void) _PR_MD_CLEAR_STACK(PRThreadStack* ts);
-PR_EXTERN(PRInt32) _PR_MD_GET_INTSOFF(void);
-PR_EXTERN(void) _PR_MD_SET_INTSOFF(PRInt32 _val);
-PR_EXTERN(_PRCPU*) _PR_MD_CURRENT_CPU(void);
-PR_EXTERN(void) _PR_MD_SET_CURRENT_CPU(_PRCPU *cpu);
-PR_EXTERN(void) _PR_MD_INIT_RUNNING_CPU(_PRCPU *cpu);
-PR_EXTERN(PRInt32) _PR_MD_PAUSE_CPU(PRIntervalTime timeout);
diff --git a/nsprpub/pr/src/md/beos/beos.c b/nsprpub/pr/src/md/beos/beos.c
deleted file mode 100644
index a1df7d2f1..000000000
--- a/nsprpub/pr/src/md/beos/beos.c
+++ /dev/null
@@ -1,232 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-#include <signal.h>
-#include <unistd.h>
-#include <memory.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-
-/*
- * Make sure _PRSockLen_t is 32-bit, because we will cast a PRUint32* or
- * PRInt32* pointer to a _PRSockLen_t* pointer.
- */
-#define _PRSockLen_t int
-
-/*
-** Global lock variable used to bracket calls into rusty libraries that
-** aren't thread safe (like libc, libX, etc).
-*/
-static PRLock *_pr_rename_lock = NULL;
-static PRMonitor *_pr_Xfe_mon = NULL;
-
-/*
- * Variables used by the GC code, initialized in _MD_InitSegs().
- * _pr_zero_fd should be a static variable. Unfortunately, there is
- * still some Unix-specific code left in function PR_GrowSegment()
- * in file memory/prseg.c that references it, so it needs
- * to be a global variable for now.
- */
-PRInt32 _pr_zero_fd = -1;
-static PRLock *_pr_md_lock = NULL;
-
-sigset_t timer_set;
-
-void _PR_UnixInit()
-{
- struct sigaction sigact;
- int rv;
-
- sigemptyset(&timer_set);
-
- sigact.sa_handler = SIG_IGN;
- sigemptyset(&sigact.sa_mask);
- sigact.sa_flags = 0;
- rv = sigaction(SIGPIPE, &sigact, 0);
- PR_ASSERT(0 == rv);
-
- _pr_rename_lock = PR_NewLock();
- PR_ASSERT(NULL != _pr_rename_lock);
- _pr_Xfe_mon = PR_NewMonitor();
- PR_ASSERT(NULL != _pr_Xfe_mon);
-}
-
-/*
- *-----------------------------------------------------------------------
- *
- * PR_Now --
- *
- * Returns the current time in microseconds since the epoch.
- * The epoch is midnight January 1, 1970 GMT.
- * The implementation is machine dependent. This is the Unix
- * implementation.
- * Cf. time_t time(time_t *tp)
- *
- *-----------------------------------------------------------------------
- */
-
-PR_IMPLEMENT(PRTime)
-PR_Now(void)
-{
- struct timeval tv;
- PRInt64 s, us, s2us;
-
- GETTIMEOFDAY(&tv);
- LL_I2L(s2us, PR_USEC_PER_SEC);
- LL_I2L(s, tv.tv_sec);
- LL_I2L(us, tv.tv_usec);
- LL_MUL(s, s, s2us);
- LL_ADD(s, s, us);
- return s;
-}
-
-PRIntervalTime
-_PR_UNIX_GetInterval()
-{
- struct timeval time;
- PRIntervalTime ticks;
-
- (void)GETTIMEOFDAY(&time); /* fallicy of course */
- ticks = (PRUint32)time.tv_sec * PR_MSEC_PER_SEC; /* that's in milliseconds */
- ticks += (PRUint32)time.tv_usec / PR_USEC_PER_MSEC; /* so's that */
- return ticks;
-} /* _PR_SUNOS_GetInterval */
-
-PRIntervalTime _PR_UNIX_TicksPerSecond()
-{
- return 1000; /* this needs some work :) */
-}
-
-/************************************************************************/
-
-/*
-** Special hacks for xlib. Xlib/Xt/Xm is not re-entrant nor is it thread
-** safe. Unfortunately, neither is mozilla. To make these programs work
-** in a pre-emptive threaded environment, we need to use a lock.
-*/
-
-void PR_XLock()
-{
- PR_EnterMonitor(_pr_Xfe_mon);
-}
-
-void PR_XUnlock()
-{
- PR_ExitMonitor(_pr_Xfe_mon);
-}
-
-PRBool PR_XIsLocked()
-{
- return (PR_InMonitor(_pr_Xfe_mon)) ? PR_TRUE : PR_FALSE;
-}
-
-void PR_XWait(int ms)
-{
- PR_Wait(_pr_Xfe_mon, PR_MillisecondsToInterval(ms));
-}
-
-void PR_XNotify(void)
-{
- PR_Notify(_pr_Xfe_mon);
-}
-
-void PR_XNotifyAll(void)
-{
- PR_NotifyAll(_pr_Xfe_mon);
-}
-
-#if !defined(BEOS)
-#ifdef HAVE_BSD_FLOCK
-
-#include <sys/file.h>
-
-PR_IMPLEMENT(PRStatus)
-_MD_LOCKFILE (PRInt32 f)
-{
- PRInt32 rv;
- rv = flock(f, LOCK_EX);
- if (rv == 0)
- return PR_SUCCESS;
- _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-
-PR_IMPLEMENT(PRStatus)
-_MD_TLOCKFILE (PRInt32 f)
-{
- PRInt32 rv;
- rv = flock(f, LOCK_EX|LOCK_NB);
- if (rv == 0)
- return PR_SUCCESS;
- _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-
-PR_IMPLEMENT(PRStatus)
-_MD_UNLOCKFILE (PRInt32 f)
-{
- PRInt32 rv;
- rv = flock(f, LOCK_UN);
- if (rv == 0)
- return PR_SUCCESS;
- _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-#else
-
-PR_IMPLEMENT(PRStatus)
-_MD_LOCKFILE (PRInt32 f)
-{
- PRInt32 rv;
- rv = lockf(f, F_LOCK, 0);
- if (rv == 0)
- return PR_SUCCESS;
- _PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-
-PR_IMPLEMENT(PRStatus)
-_MD_TLOCKFILE (PRInt32 f)
-{
- PRInt32 rv;
- rv = lockf(f, F_TLOCK, 0);
- if (rv == 0)
- return PR_SUCCESS;
- _PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-
-PR_IMPLEMENT(PRStatus)
-_MD_UNLOCKFILE (PRInt32 f)
-{
- PRInt32 rv;
- rv = lockf(f, F_ULOCK, 0);
- if (rv == 0)
- return PR_SUCCESS;
- _PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-#endif
-
-PR_IMPLEMENT(PRStatus)
- _MD_GETHOSTNAME (char *name, PRUint32 namelen)
-{
- PRIntn rv;
-
- rv = gethostname(name, namelen);
- if (0 == rv) {
- return PR_SUCCESS;
- }
- _PR_MD_MAP_GETHOSTNAME_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-
-#endif
diff --git a/nsprpub/pr/src/md/beos/beos_errors.c b/nsprpub/pr/src/md/beos/beos_errors.c
deleted file mode 100644
index 687a53519..000000000
--- a/nsprpub/pr/src/md/beos/beos_errors.c
+++ /dev/null
@@ -1,1494 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "prtypes.h"
-#include "md/_unix_errors.h"
-#include "prerror.h"
-#include <errno.h>
-
-void _MD_unix_map_opendir_error(int err)
-{
- switch (err) {
- case ENOTDIR:
- PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
- break;
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EMFILE:
- PR_SetError(PR_PROC_DESC_TABLE_FULL_ERROR, err);
- break;
- case ENFILE:
- PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ELOOP:
- PR_SetError(PR_LOOP_ERROR, err);
- break;
- case ENAMETOOLONG:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ENOENT:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_closedir_error(int err)
-{
- switch (err) {
- case EINVAL:
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_readdir_error(int err)
-{
-
- switch (err) {
- case 0:
- case ENOENT:
- PR_SetError(PR_NO_MORE_FILES_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#ifdef IRIX
-#ifdef IRIX5_3
-#else
- case EDIRCORRUPTED:
- PR_SetError(PR_DIRECTORY_CORRUPTED_ERROR, err);
- break;
-#endif
-#endif
-#ifdef EOVERFLOW
- case EOVERFLOW:
- PR_SetError(PR_IO_ERROR, err);
- break;
-#endif
- case EINVAL:
- PR_SetError(PR_IO_ERROR, err);
- break;
-#ifdef EBADMSG
- case EBADMSG:
- PR_SetError(PR_IO_ERROR, err);
- break;
-#endif
- case EDEADLK:
- PR_SetError(PR_DEADLOCK_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ENOLCK:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
-#ifdef ENOLINK
- case ENOLINK:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
-#endif
- case ENXIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_unlink_error(int err)
-{
- switch (err) {
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EBUSY:
- PR_SetError(PR_FILESYSTEM_MOUNTED_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case ELOOP:
- PR_SetError(PR_LOOP_ERROR, err);
- break;
- case ENAMETOOLONG:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ENOENT:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ENOTDIR:
- PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
- break;
- case EPERM:
- PR_SetError(PR_IS_DIRECTORY_ERROR, err);
- break;
- case EROFS:
- PR_SetError(PR_READ_ONLY_FILESYSTEM_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_stat_error(int err)
-{
- switch (err) {
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case ETIMEDOUT:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
- case ELOOP:
- PR_SetError(PR_LOOP_ERROR, err);
- break;
- case ENAMETOOLONG:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ENOENT:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ENOTDIR:
- PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
- break;
-#ifdef EOVERFLOW
- case EOVERFLOW:
- PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_fstat_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case ETIMEDOUT:
-#ifdef ENOLINK
- case ENOLINK:
-#endif
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
-#ifdef EOVERFLOW
- case EOVERFLOW:
- PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_rename_error(int err)
-{
- switch (err) {
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EBUSY:
- PR_SetError(PR_FILESYSTEM_MOUNTED_ERROR, err);
- break;
-#ifdef EDQUOT
- case EDQUOT:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
-#endif
- case EEXIST:
- PR_SetError(PR_DIRECTORY_NOT_EMPTY_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case EISDIR:
- PR_SetError(PR_IS_DIRECTORY_ERROR, err);
- break;
- case ELOOP:
- PR_SetError(PR_LOOP_ERROR, err);
- break;
- case ENAMETOOLONG:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ENOENT:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ENOSPC:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
- case ENOTDIR:
- PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
- break;
- case EROFS:
- PR_SetError(PR_READ_ONLY_FILESYSTEM_ERROR, err);
- break;
- case EXDEV:
- PR_SetError(PR_NOT_SAME_DEVICE_ERROR, err);
- break;
- case EMLINK:
- PR_SetError(PR_MAX_DIRECTORY_ENTRIES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_access_error(int err)
-{
- switch (err) {
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ELOOP:
- PR_SetError(PR_LOOP_ERROR, err);
- break;
- case ETIMEDOUT:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
- case ENAMETOOLONG:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ENOENT:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ENOTDIR:
- PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
- break;
- case EROFS:
- PR_SetError(PR_READ_ONLY_FILESYSTEM_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_mkdir_error(int err)
-{
- switch (err) {
- case ENOTDIR:
- PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
- break;
- case ENOENT:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ENAMETOOLONG:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EEXIST:
- PR_SetError(PR_FILE_EXISTS_ERROR, err);
- break;
- case EROFS:
- PR_SetError(PR_READ_ONLY_FILESYSTEM_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ELOOP:
- PR_SetError(PR_LOOP_ERROR, err);
- break;
- case EMLINK:
- PR_SetError(PR_MAX_DIRECTORY_ENTRIES_ERROR, err);
- break;
- case ENOSPC:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
-#ifdef EDQUOT
- case EDQUOT:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
-#endif
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_rmdir_error(int err)
-{
-
- switch (err) {
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EBUSY:
- PR_SetError(PR_FILESYSTEM_MOUNTED_ERROR, err);
- break;
- case EEXIST:
- PR_SetError(PR_DIRECTORY_NOT_EMPTY_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_DIRECTORY_NOT_EMPTY_ERROR, err);
- break;
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ELOOP:
- PR_SetError(PR_LOOP_ERROR, err);
- break;
- case ETIMEDOUT:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
- case ENAMETOOLONG:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ENOENT:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ENOTDIR:
- PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
- break;
- case EROFS:
- PR_SetError(PR_READ_ONLY_FILESYSTEM_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_read_error(int err)
-{
- switch (err) {
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#ifdef EBADMSG
- case EBADMSG:
- PR_SetError(PR_IO_ERROR, err);
- break;
-#endif
- case EDEADLK:
- PR_SetError(PR_DEADLOCK_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_METHOD_ERROR, err);
- break;
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ENOLCK:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ENXIO:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case EISDIR:
- PR_SetError(PR_IS_DIRECTORY_ERROR, err);
- break;
- case ECONNRESET:
- case EPIPE:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
-#ifdef ENOLINK
- case ENOLINK:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_write_error(int err)
-{
- switch (err) {
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EDEADLK:
- PR_SetError(PR_DEADLOCK_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EFBIG:
- PR_SetError(PR_FILE_TOO_BIG_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_METHOD_ERROR, err);
- break;
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ENOLCK:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- case ENOSPC:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
- case ENXIO:
- PR_SetError(PR_INVALID_METHOD_ERROR, err);
- break;
- case ERANGE:
- PR_SetError(PR_INVALID_METHOD_ERROR, err);
- break;
- case ETIMEDOUT:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
- case ECONNRESET:
- case EPIPE:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
-#ifdef EDQUOT
- case EDQUOT:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
-#endif
-#ifdef ENOLINK
- case ENOLINK:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_lseek_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ESPIPE:
- PR_SetError(PR_INVALID_METHOD_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_fsync_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#ifdef ENOLINK
- case ENOLINK:
-#endif
- case ETIMEDOUT:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_METHOD_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_close_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
-#ifdef ENOLINK
- case ENOLINK:
-#endif
- case ETIMEDOUT:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_socket_error(int err)
-{
- switch (err) {
- case EPROTONOSUPPORT:
- PR_SetError(PR_PROTOCOL_NOT_SUPPORTED_ERROR, err);
- break;
- case EMFILE:
- PR_SetError(PR_PROC_DESC_TABLE_FULL_ERROR, err);
- break;
- case ENFILE:
- PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
- break;
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
-#if !defined(SCO)
- case ENOBUFS:
-#endif /* !defined(SCO) */
- case ENOMEM:
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_socketavailable_error(int err)
-{
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
-}
-
-void _MD_unix_map_recv_error(int err)
-{
- switch (err) {
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ENOMEM:
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, err);
- break;
- case ECONNRESET:
- case EPIPE:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_recvfrom_error(int err)
-{
- switch (err) {
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ENOMEM:
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- case ECONNRESET:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_send_error(int err)
-{
- switch (err) {
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
-#if !defined(BEOS)
- case EMSGSIZE:
-#endif
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
-#if !defined(SCO)
- case ENOBUFS:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif /* !defined(SCO) */
- case ECONNREFUSED:
- PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
- break;
- case EISCONN:
- PR_SetError(PR_IS_CONNECTED_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case ENOMEM:
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- case ECONNRESET:
- case EPIPE:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_sendto_error(int err)
-{
- switch (err) {
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
-#if !defined(BEOS)
- case EMSGSIZE:
-#endif
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
-#if !defined(SCO)
- case ENOBUFS:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif /* !defined(SCO) */
- case ECONNREFUSED:
- PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
- break;
- case EISCONN:
- PR_SetError(PR_IS_CONNECTED_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case ENOMEM:
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- case ECONNRESET:
- case EPIPE:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_writev_error(int err)
-{
- switch (err) {
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ECONNRESET:
- case EPIPE:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_accept_error(int err)
-{
- switch (err) {
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
-#if !defined(BEOS)
- case EOPNOTSUPP:
-#endif
- case ENODEV:
- PR_SetError(PR_NOT_TCP_SOCKET_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EMFILE:
- PR_SetError(PR_PROC_DESC_TABLE_FULL_ERROR, err);
- break;
- case ENFILE:
- PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case ENOMEM:
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
-#ifdef EPROTO
- case EPROTO:
- PR_SetError(PR_IO_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_connect_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EADDRNOTAVAIL:
- PR_SetError(PR_ADDRESS_NOT_AVAILABLE_ERROR, err);
- break;
- case EINPROGRESS:
- PR_SetError(PR_IN_PROGRESS_ERROR, err);
- break;
- case EALREADY:
- PR_SetError(PR_ALREADY_INITIATED_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case EAFNOSUPPORT:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
- case EISCONN:
- PR_SetError(PR_IS_CONNECTED_ERROR, err);
- break;
- case ETIMEDOUT:
- PR_SetError(PR_IO_TIMEOUT_ERROR, err);
- break;
- case ECONNREFUSED:
- PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
- break;
- case ENETUNREACH:
- PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, err);
- break;
- case EADDRINUSE:
- PR_SetError(PR_ADDRESS_IN_USE_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- /*
- * UNIX domain sockets are not supported in NSPR
- */
- case EACCES:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case EIO:
-#if defined(UNIXWARE)
- /*
- * On some platforms, if we connect to a port on
- * the local host (the loopback address) that no
- * process is listening on, we get EIO instead
- * of ECONNREFUSED.
- */
- PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
-#else
- PR_SetError(PR_IO_ERROR, err);
-#endif
- break;
- case ELOOP:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
- case ENOENT:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- case ENXIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case EPROTOTYPE:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_bind_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EADDRNOTAVAIL:
- PR_SetError(PR_ADDRESS_NOT_AVAILABLE_ERROR, err);
- break;
- case EADDRINUSE:
- PR_SetError(PR_ADDRESS_IN_USE_ERROR, err);
- break;
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_SOCKET_ADDRESS_IS_BOUND_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- /*
- * UNIX domain sockets are not supported in NSPR
- */
- case EIO:
- case EISDIR:
- case ELOOP:
- case ENOENT:
- case ENOTDIR:
- case EROFS:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_listen_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
-#if !defined(BEOS)
- case EOPNOTSUPP:
- PR_SetError(PR_NOT_TCP_SOCKET_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_shutdown_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case ENOTCONN:
- PR_SetError(PR_NOT_CONNECTED_ERROR, err);
- break;
- case ENOMEM:
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_socketpair_error(int err)
-{
- switch (err) {
- case EMFILE:
- PR_SetError(PR_PROC_DESC_TABLE_FULL_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ENOMEM:
-#ifdef ENOSR
- case ENOSR:
-#endif
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case EAFNOSUPPORT:
- case EPROTONOSUPPORT:
-#if !defined(BEOS)
- case EOPNOTSUPP:
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_getsockname_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
-#if !defined(SCO)
- case ENOBUFS:
-#endif /* !defined(SCO) */
- case ENOMEM:
-#ifdef ENOSR
- case ENOSR:
-#endif
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_getpeername_error(int err)
-{
-
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case ENOTCONN:
- PR_SetError(PR_NOT_CONNECTED_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
-#if !defined(SCO)
- case ENOBUFS:
-#endif /* !defined(SCO) */
- case ENOMEM:
-#ifdef ENOSR
- case ENOSR:
-#endif
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_getsockopt_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case ENOPROTOOPT:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
- break;
- case ENOMEM:
-#ifdef ENOSR
- case ENOSR:
-#endif
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_setsockopt_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case ENOPROTOOPT:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
- break;
- case ENOMEM:
-#ifdef ENOSR
- case ENOSR:
-#endif
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_open_error(int err)
-{
- switch (err) {
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EAGAIN:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case EBUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case EEXIST:
- PR_SetError(PR_FILE_EXISTS_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case EISDIR:
- PR_SetError(PR_IS_DIRECTORY_ERROR, err);
- break;
- case ELOOP:
- PR_SetError(PR_LOOP_ERROR, err);
- break;
- case EMFILE:
- PR_SetError(PR_PROC_DESC_TABLE_FULL_ERROR, err);
- break;
- case ENAMETOOLONG:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ENFILE:
- PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
- break;
- case ENODEV:
- case ENOENT:
- case ENXIO:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ENOMEM:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ENOSPC:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
-#endif
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ENOTDIR:
- PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
- break;
- case EPERM:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ETIMEDOUT:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
- case EROFS:
- PR_SetError(PR_READ_ONLY_FILESYSTEM_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_mmap_error(int err)
-{
-
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EAGAIN:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ENOMEM:
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_gethostname_error(int err)
-{
- switch (err) {
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_select_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_poll_error(int err)
-{
- PRErrorCode prerror;
- switch (err) {
- case EAGAIN:
- prerror = PR_INSUFFICIENT_RESOURCES_ERROR;
- break;
- case EINVAL:
- prerror = PR_INVALID_ARGUMENT_ERROR;
- break;
- case EFAULT:
- prerror = PR_ACCESS_FAULT_ERROR;
- break;
- default:
- prerror = PR_UNKNOWN_ERROR;
- break;
- }
- PR_SetError(prerror, err);
-}
-
-void _MD_unix_map_flock_error(int err)
-{
- switch (err) {
- case EBADF:
- case EINVAL:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EWOULDBLOCK:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_lockf_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EACCES:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case EDEADLK:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-#ifdef HPUX11
-void _MD_hpux_map_sendfile_error(int oserror)
-{
- PRErrorCode prerror;
-
- switch (oserror) {
- case ENOTSOCK:
- prerror = PR_NOT_SOCKET_ERROR;
- break;
- case EFAULT:
- prerror = PR_ACCESS_FAULT_ERROR;
- break;
- case ENOBUFS:
- prerror = PR_INSUFFICIENT_RESOURCES_ERROR;
- break;
- case EINVAL:
- prerror = PR_INVALID_ARGUMENT_ERROR;
- break;
- case ENOTCONN:
- prerror = PR_NOT_CONNECTED_ERROR;
- break;
- case EPIPE:
- prerror = PR_CONNECT_RESET_ERROR;
- break;
- case ENOMEM:
- prerror = PR_OUT_OF_MEMORY_ERROR;
- break;
- case EOPNOTSUPP:
- prerror = PR_NOT_TCP_SOCKET_ERROR;
- break;
- default:
- prerror = PR_UNKNOWN_ERROR;
- }
- PR_SetError(prerror, oserror);
-}
-#endif /* HPUX11 */
diff --git a/nsprpub/pr/src/md/beos/bfile.c b/nsprpub/pr/src/md/beos/bfile.c
deleted file mode 100644
index 89fea29a2..000000000
--- a/nsprpub/pr/src/md/beos/bfile.c
+++ /dev/null
@@ -1,873 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; c-basic-offset: 8 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-/*
-** Global lock variable used to bracket calls into rusty libraries that
-** aren't thread safe (like libc, libX, etc).
-*/
-static PRLock *_pr_rename_lock = NULL;
-
-void
-_MD_InitIO (void)
-{
-}
-
-PRStatus
-_MD_open_dir (_MDDir *md,const char *name)
-{
-int err;
-
- md->d = opendir(name);
- if (!md->d) {
- err = _MD_ERRNO();
- _PR_MD_MAP_OPENDIR_ERROR(err);
- return PR_FAILURE;
- }
- return PR_SUCCESS;
-}
-
-char*
-_MD_read_dir (_MDDir *md, PRIntn flags)
-{
-struct dirent *de;
-int err;
-
- for (;;) {
- /*
- * XXX: readdir() is not MT-safe
- */
- _MD_ERRNO() = 0;
- de = readdir(md->d);
-
- if (!de) {
- err = _MD_ERRNO();
- _PR_MD_MAP_READDIR_ERROR(err);
- return 0;
- }
-
- if ((flags & PR_SKIP_DOT) &&
- (de->d_name[0] == '.') && (de->d_name[1] == 0))
- continue;
-
- if ((flags & PR_SKIP_DOT_DOT) &&
- (de->d_name[0] == '.') && (de->d_name[1] == '.') &&
- (de->d_name[2] == 0))
- continue;
-
- if ((flags & PR_SKIP_HIDDEN) && (de->d_name[1] == '.'))
- continue;
-
- break;
- }
- return de->d_name;
-}
-
-
-PRInt32
-_MD_close_dir (_MDDir *md)
-{
-int rv = 0, err;
-
- if (md->d) {
- rv = closedir(md->d);
- if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_CLOSEDIR_ERROR(err);
- }
- }
- return(rv);
-}
-
-void
-_MD_make_nonblock (PRFileDesc *fd)
-{
- int blocking = 1;
- setsockopt(fd->secret->md.osfd, SOL_SOCKET, SO_NONBLOCK, &blocking, sizeof(blocking));
-
-}
-
-PRStatus
-_MD_set_fd_inheritable (PRFileDesc *fd, PRBool inheritable)
-{
- int rv;
-
- rv = fcntl(fd->secret->md.osfd, F_SETFD, inheritable ? 0 : FD_CLOEXEC);
- if (-1 == rv) {
- PR_SetError(PR_UNKNOWN_ERROR, _MD_ERRNO());
- return PR_FAILURE;
- }
- return PR_SUCCESS;
-}
-
-void
-_MD_init_fd_inheritable (PRFileDesc *fd, PRBool imported)
-{
- if (imported) {
- fd->secret->inheritable = _PR_TRI_UNKNOWN;
- } else {
- int flags = fcntl(fd->secret->md.osfd, F_GETFD, 0);
- if (flags == -1) {
- PR_SetError(PR_UNKNOWN_ERROR, _MD_ERRNO());
- return;
- }
- fd->secret->inheritable = (flags & FD_CLOEXEC) ?
- _PR_TRI_TRUE : _PR_TRI_FALSE;
- }
-}
-
-void
-_MD_query_fd_inheritable (PRFileDesc *fd)
-{
- int flags;
-
- PR_ASSERT(_PR_TRI_UNKNOWN == fd->secret->inheritable);
- flags = fcntl(fd->secret->md.osfd, F_GETFD, 0);
- PR_ASSERT(-1 != flags);
- fd->secret->inheritable = (flags & FD_CLOEXEC) ?
- _PR_TRI_FALSE : _PR_TRI_TRUE;
-}
-
-PRInt32
-_MD_open (const char *name, PRIntn flags, PRIntn mode)
-{
- PRInt32 osflags;
- PRInt32 rv, err;
-
- if (flags & PR_RDWR) {
- osflags = O_RDWR;
- } else if (flags & PR_WRONLY) {
- osflags = O_WRONLY;
- } else {
- osflags = O_RDONLY;
- }
-
- if (flags & PR_EXCL)
- osflags |= O_EXCL;
- if (flags & PR_APPEND)
- osflags |= O_APPEND;
- if (flags & PR_TRUNCATE)
- osflags |= O_TRUNC;
- if (flags & PR_SYNC) {
-/* Ummmm. BeOS doesn't appear to
- support sync in any way shape or
- form. */
- return PR_NOT_IMPLEMENTED_ERROR;
- }
-
- /*
- ** On creations we hold the 'create' lock in order to enforce
- ** the semantics of PR_Rename. (see the latter for more details)
- */
- if (flags & PR_CREATE_FILE)
- {
- osflags |= O_CREAT ;
- if (NULL !=_pr_rename_lock)
- PR_Lock(_pr_rename_lock);
- }
-
- rv = open(name, osflags, mode);
-
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_OPEN_ERROR(err);
- }
-
- if ((flags & PR_CREATE_FILE) && (NULL !=_pr_rename_lock))
- PR_Unlock(_pr_rename_lock);
- return rv;
-}
-
-PRInt32
-_MD_close_file (PRInt32 osfd)
-{
-PRInt32 rv, err;
-
- rv = close(osfd);
- if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_CLOSE_ERROR(err);
- }
- return(rv);
-}
-
-PRInt32
-_MD_read (PRFileDesc *fd, void *buf, PRInt32 amount)
-{
- PRInt32 rv, err;
- PRInt32 osfd = fd->secret->md.osfd;
-
- rv = read( osfd, buf, amount );
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_READ_ERROR(err);
- }
- return(rv);
-}
-
-PRInt32
-_MD_write (PRFileDesc *fd, const void *buf, PRInt32 amount)
-{
- PRInt32 rv, err;
- PRInt32 osfd = fd->secret->md.osfd;
-
- rv = write( osfd, buf, amount );
-
- if( rv < 0 ) {
-
- err = _MD_ERRNO();
- _PR_MD_MAP_WRITE_ERROR(err);
- }
- return( rv );
-}
-
-#ifndef BONE_VERSION /* Writev moves to bnet.c with BONE */
-PRInt32
-_MD_writev (PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size,
- PRIntervalTime timeout)
-{
- return PR_NOT_IMPLEMENTED_ERROR;
-}
-#endif
-
-PRInt32
-_MD_lseek (PRFileDesc *fd, PRInt32 offset, int whence)
-{
-PRInt32 rv, err;
-
- rv = lseek (fd->secret->md.osfd, offset, whence);
- if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_LSEEK_ERROR(err);
- }
- return( rv );
-}
-
-PRInt64
-_MD_lseek64 (PRFileDesc *fd, PRInt64 offset, int whence)
-{
-PRInt32 rv, err;
-
-/* According to the BeOS headers, lseek accepts a
- * variable of type off_t for the offset, and off_t
- * is defined to be a 64-bit value. So no special
- * cracking needs to be done on "offset".
- */
-
- rv = lseek (fd->secret->md.osfd, offset, whence);
- if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_LSEEK_ERROR(err);
- }
- return( rv );
-}
-
-PRInt32
-_MD_fsync (PRFileDesc *fd)
-{
-PRInt32 rv, err;
-
- rv = fsync(fd->secret->md.osfd);
- if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_FSYNC_ERROR(err);
- }
- return(rv);
-}
-
-PRInt32
-_MD_delete (const char *name)
-{
-PRInt32 rv, err;
-
- rv = unlink(name);
- if (rv == -1)
- {
- err = _MD_ERRNO();
- _PR_MD_MAP_UNLINK_ERROR(err);
- }
- return (rv);
-}
-
-PRInt32
-_MD_getfileinfo (const char *fn, PRFileInfo *info)
-{
-struct stat sb;
-PRInt32 rv, err;
-PRInt64 s, s2us;
-
- rv = stat(fn, &sb);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_STAT_ERROR(err);
- } else if (info) {
- if (S_IFREG & sb.st_mode)
- info->type = PR_FILE_FILE;
- else if (S_IFDIR & sb.st_mode)
- info->type = PR_FILE_DIRECTORY;
- else
- info->type = PR_FILE_OTHER;
-
- /* Must truncate file size for the 32 bit
- version */
- info->size = (sb.st_size & 0xffffffff);
- LL_I2L(s, sb.st_mtime);
- LL_I2L(s2us, PR_USEC_PER_SEC);
- LL_MUL(s, s, s2us);
- info->modifyTime = s;
- LL_I2L(s, sb.st_ctime);
- LL_MUL(s, s, s2us);
- info->creationTime = s;
- }
- return rv;
-}
-
-PRInt32
-_MD_getfileinfo64 (const char *fn, PRFileInfo64 *info)
-{
-struct stat sb;
-PRInt32 rv, err;
-PRInt64 s, s2us;
-
- rv = stat(fn, &sb);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_STAT_ERROR(err);
- } else if (info) {
- if (S_IFREG & sb.st_mode)
- info->type = PR_FILE_FILE;
- else if (S_IFDIR & sb.st_mode)
- info->type = PR_FILE_DIRECTORY;
- else
- info->type = PR_FILE_OTHER;
-
- /* For the 64 bit version we can use
- * the native st_size without modification
- */
- info->size = sb.st_size;
- LL_I2L(s, sb.st_mtime);
- LL_I2L(s2us, PR_USEC_PER_SEC);
- LL_MUL(s, s, s2us);
- info->modifyTime = s;
- LL_I2L(s, sb.st_ctime);
- LL_MUL(s, s, s2us);
- info->creationTime = s;
- }
- return rv;
-}
-
-PRInt32
-_MD_getopenfileinfo (const PRFileDesc *fd, PRFileInfo *info)
-{
- struct stat sb;
- PRInt64 s, s2us;
- PRInt32 rv, err;
-
- rv = fstat(fd->secret->md.osfd, &sb);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_FSTAT_ERROR(err);
- } else if (info) {
- if (info) {
- if (S_IFREG & sb.st_mode)
- info->type = PR_FILE_FILE ;
- else if (S_IFDIR & sb.st_mode)
- info->type = PR_FILE_DIRECTORY;
- else
- info->type = PR_FILE_OTHER;
- /* Use lower 32 bits of file size */
- info->size = ( sb.st_size & 0xffffffff);
- LL_I2L(s, sb.st_mtime);
- LL_I2L(s2us, PR_USEC_PER_SEC);
- LL_MUL(s, s, s2us);
- info->modifyTime = s;
- LL_I2L(s, sb.st_ctime);
- LL_MUL(s, s, s2us);
- info->creationTime = s;
- }
- }
- return rv;
-}
-
-PRInt32
-_MD_getopenfileinfo64 (const PRFileDesc *fd, PRFileInfo64 *info)
-{
- struct stat sb;
- PRInt64 s, s2us;
- PRInt32 rv, err;
-
- rv = fstat(fd->secret->md.osfd, &sb);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_FSTAT_ERROR(err);
- } else if (info) {
- if (info) {
- if (S_IFREG & sb.st_mode)
- info->type = PR_FILE_FILE ;
- else if (S_IFDIR & sb.st_mode)
- info->type = PR_FILE_DIRECTORY;
- else
- info->type = PR_FILE_OTHER;
- info->size = sb.st_size;
- LL_I2L(s, sb.st_mtime);
- LL_I2L(s2us, PR_USEC_PER_SEC);
- LL_MUL(s, s, s2us);
- info->modifyTime = s;
- LL_I2L(s, sb.st_ctime);
- LL_MUL(s, s, s2us);
- info->creationTime = s;
- }
- }
- return rv;
-}
-
-PRInt32
-_MD_rename (const char *from, const char *to)
-{
- PRInt32 rv = -1, err;
-
- /*
- ** This is trying to enforce the semantics of WINDOZE' rename
- ** operation. That means one is not allowed to rename over top
- ** of an existing file. Holding a lock across these two function
- ** and the open function is known to be a bad idea, but ....
- */
- if (NULL != _pr_rename_lock)
- PR_Lock(_pr_rename_lock);
- if (0 == access(to, F_OK))
- PR_SetError(PR_FILE_EXISTS_ERROR, 0);
- else
- {
- rv = rename(from, to);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_RENAME_ERROR(err);
- }
- }
- if (NULL != _pr_rename_lock)
- PR_Unlock(_pr_rename_lock);
- return rv;
-}
-
-PRInt32
-_MD_access (const char *name, PRIntn how)
-{
-PRInt32 rv, err;
-int checkFlags;
-struct stat buf;
-
- switch (how) {
- case PR_ACCESS_WRITE_OK:
- checkFlags = S_IWUSR | S_IWGRP | S_IWOTH;
- break;
-
- case PR_ACCESS_READ_OK:
- checkFlags = S_IRUSR | S_IRGRP | S_IROTH;
- break;
-
- case PR_ACCESS_EXISTS:
- /* we don't need to examine st_mode. */
- break;
-
- default:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return -1;
- }
-
- rv = stat(name, &buf);
- if (rv == 0 && how != PR_ACCESS_EXISTS && (!(buf.st_mode & checkFlags))) {
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, 0);
- return -1;
- }
-
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_STAT_ERROR(err);
- }
-
- return(rv);
-}
-
-PRInt32
-_MD_stat (const char *name, struct stat *buf)
-{
- return PR_NOT_IMPLEMENTED_ERROR;
-}
-
-PRInt32
-_MD_mkdir (const char *name, PRIntn mode)
-{
- status_t rv;
- int err;
-
- /*
- ** This lock is used to enforce rename semantics as described
- ** in PR_Rename. Look there for more fun details.
- */
- if (NULL !=_pr_rename_lock)
- PR_Lock(_pr_rename_lock);
-
- rv = mkdir(name, mode);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_MKDIR_ERROR(err);
- }
- if (NULL !=_pr_rename_lock)
- PR_Unlock(_pr_rename_lock);
- return rv;
-}
-
-PRInt32
-_MD_rmdir (const char *name)
-{
-int rv, err;
-
- rv = rmdir(name);
- if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_RMDIR_ERROR(err);
- }
- return rv;
-}
-
-PRInt32
-_MD_pr_poll(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
-{
- PRInt32 rv = 0;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- /*
- * This code is almost a duplicate of w32poll.c's _PR_MD_PR_POLL().
- */
- fd_set rd, wt, ex;
- PRFileDesc *bottom;
- PRPollDesc *pd, *epd;
- PRInt32 maxfd = -1, ready, err;
- PRIntervalTime remaining, elapsed, start;
-
- struct timeval tv, *tvp = NULL;
-
- if (_PR_PENDING_INTERRUPT(me))
- {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
-
- if (0 == npds) {
- PR_Sleep(timeout);
- return rv;
- }
-
- FD_ZERO(&rd);
- FD_ZERO(&wt);
- FD_ZERO(&ex);
-
- ready = 0;
- for (pd = pds, epd = pd + npds; pd < epd; pd++)
- {
- PRInt16 in_flags_read = 0, in_flags_write = 0;
- PRInt16 out_flags_read = 0, out_flags_write = 0;
-
- if ((NULL != pd->fd) && (0 != pd->in_flags))
- {
- if (pd->in_flags & PR_POLL_READ)
- {
- in_flags_read = (pd->fd->methods->poll)(pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read);
- }
- if (pd->in_flags & PR_POLL_WRITE)
- {
- in_flags_write = (pd->fd->methods->poll)(pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write);
- }
- if ((0 != (in_flags_read & out_flags_read))
- || (0 != (in_flags_write & out_flags_write)))
- {
- /* this one's ready right now */
- if (0 == ready)
- {
- /*
- * We will have to return without calling the
- * system poll/select function. So zero the
- * out_flags fields of all the poll descriptors
- * before this one.
- */
- PRPollDesc *prev;
- for (prev = pds; prev < pd; prev++)
- {
- prev->out_flags = 0;
- }
- }
- ready += 1;
- pd->out_flags = out_flags_read | out_flags_write;
- }
- else
- {
- pd->out_flags = 0; /* pre-condition */
-
- /* make sure this is an NSPR supported stack */
- bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
- PR_ASSERT(NULL != bottom); /* what to do about that? */
- if ((NULL != bottom)
- && (_PR_FILEDESC_OPEN == bottom->secret->state))
- {
- if (0 == ready)
- {
- PRInt32 osfd = bottom->secret->md.osfd;
- if (osfd > maxfd) maxfd = osfd;
- if (in_flags_read & PR_POLL_READ)
- {
- pd->out_flags |= _PR_POLL_READ_SYS_READ;
- FD_SET(osfd, &rd);
- }
- if (in_flags_read & PR_POLL_WRITE)
- {
- pd->out_flags |= _PR_POLL_READ_SYS_WRITE;
- FD_SET(osfd, &wt);
- }
- if (in_flags_write & PR_POLL_READ)
- {
- pd->out_flags |= _PR_POLL_WRITE_SYS_READ;
- FD_SET(osfd, &rd);
- }
- if (in_flags_write & PR_POLL_WRITE)
- {
- pd->out_flags |= _PR_POLL_WRITE_SYS_WRITE;
- FD_SET(osfd, &wt);
- }
- if (pd->in_flags & PR_POLL_EXCEPT) FD_SET(osfd, &ex);
- }
- }
- else
- {
- if (0 == ready)
- {
- PRPollDesc *prev;
- for (prev = pds; prev < pd; prev++)
- {
- prev->out_flags = 0;
- }
- }
- ready += 1; /* this will cause an abrupt return */
- pd->out_flags = PR_POLL_NVAL; /* bogii */
- }
- }
- }
- else
- {
- pd->out_flags = 0;
- }
- }
-
- if (0 != ready) return ready; /* no need to block */
-
- remaining = timeout;
- start = PR_IntervalNow();
-
- retry:
- if (timeout != PR_INTERVAL_NO_TIMEOUT)
- {
- PRInt32 ticksPerSecond = PR_TicksPerSecond();
- tv.tv_sec = remaining / ticksPerSecond;
- tv.tv_usec = PR_IntervalToMicroseconds( remaining % ticksPerSecond );
- tvp = &tv;
- }
-
- ready = _MD_SELECT(maxfd + 1, &rd, &wt, &ex, tvp);
-
- if (ready == -1 && errno == EINTR)
- {
- if (timeout == PR_INTERVAL_NO_TIMEOUT) goto retry;
- else
- {
- elapsed = (PRIntervalTime) (PR_IntervalNow() - start);
- if (elapsed > timeout) ready = 0; /* timed out */
- else
- {
- remaining = timeout - elapsed;
- goto retry;
- }
- }
- }
-
- /*
- ** Now to unravel the select sets back into the client's poll
- ** descriptor list. Is this possibly an area for pissing away
- ** a few cycles or what?
- */
- if (ready > 0)
- {
- ready = 0;
- for (pd = pds, epd = pd + npds; pd < epd; pd++)
- {
- PRInt16 out_flags = 0;
- if ((NULL != pd->fd) && (0 != pd->in_flags))
- {
- PRInt32 osfd;
- bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
- PR_ASSERT(NULL != bottom);
-
- osfd = bottom->secret->md.osfd;
-
- if (FD_ISSET(osfd, &rd))
- {
- if (pd->out_flags & _PR_POLL_READ_SYS_READ)
- out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_READ)
- out_flags |= PR_POLL_WRITE;
- }
- if (FD_ISSET(osfd, &wt))
- {
- if (pd->out_flags & _PR_POLL_READ_SYS_WRITE)
- out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE)
- out_flags |= PR_POLL_WRITE;
- }
- if (FD_ISSET(osfd, &ex)) out_flags |= PR_POLL_EXCEPT;
-
-/* Workaround for nonblocking connects under net_server */
-#ifndef BONE_VERSION
- if (out_flags)
- {
- /* check if it is a pending connect */
- int i = 0, j = 0;
- PR_Lock( _connectLock );
- for( i = 0; i < connectCount; i++ )
- {
- if(connectList[i].osfd == osfd)
- {
- int connectError;
- int connectResult;
-
- connectResult = connect(connectList[i].osfd,
- &connectList[i].addr,
- connectList[i].addrlen);
- connectError = errno;
-
- if(connectResult < 0 )
- {
- if(connectError == EINTR || connectError == EWOULDBLOCK ||
- connectError == EINPROGRESS || connectError == EALREADY)
- {
- break;
- }
- }
-
- if(i == (connectCount - 1))
- {
- connectList[i].osfd = -1;
- } else {
- for(j = i; j < connectCount; j++ )
- {
- memcpy( &connectList[j], &connectList[j+1],
- sizeof(connectList[j]));
- }
- }
- connectCount--;
-
- bottom->secret->md.connectReturnValue = connectResult;
- bottom->secret->md.connectReturnError = connectError;
- bottom->secret->md.connectValueValid = PR_TRUE;
- break;
- }
- }
- PR_Unlock( _connectLock );
- }
-#endif
- }
- pd->out_flags = out_flags;
- if (out_flags) ready++;
- }
- PR_ASSERT(ready > 0);
- }
- else if (ready < 0)
- {
- err = _MD_ERRNO();
- if (err == EBADF)
- {
- /* Find the bad fds */
- ready = 0;
- for (pd = pds, epd = pd + npds; pd < epd; pd++)
- {
- pd->out_flags = 0;
- if ((NULL != pd->fd) && (0 != pd->in_flags))
- {
- bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
- if (fcntl(bottom->secret->md.osfd, F_GETFL, 0) == -1)
- {
- pd->out_flags = PR_POLL_NVAL;
- ready++;
- }
- }
- }
- PR_ASSERT(ready > 0);
- }
- else _PR_MD_MAP_SELECT_ERROR(err);
- }
-
- return ready;
-} /* _MD_pr_poll */
-
-/*
- * File locking.
- */
-
-PRStatus
-_MD_lockfile (PRInt32 osfd)
-{
- PRInt32 rv;
- struct flock linfo;
-
- linfo.l_type =
- linfo.l_whence = SEEK_SET;
- linfo.l_start = 0;
- linfo.l_len = 0;
-
- rv = fcntl(osfd, F_SETLKW, &linfo);
- if (rv == 0)
- return PR_SUCCESS;
-
- _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-
-PRStatus
-_MD_tlockfile (PRInt32 osfd)
-{
- PRInt32 rv;
- struct flock linfo;
-
- linfo.l_type =
- linfo.l_whence = SEEK_SET;
- linfo.l_start = 0;
- linfo.l_len = 0;
-
- rv = fcntl(osfd, F_SETLK, &linfo);
- if (rv == 0)
- return PR_SUCCESS;
-
- _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-
-PRStatus
-_MD_unlockfile (PRInt32 osfd)
-{
- PRInt32 rv;
- struct flock linfo;
-
- linfo.l_type =
- linfo.l_whence = SEEK_SET;
- linfo.l_start = 0;
- linfo.l_len = 0;
-
- rv = fcntl(osfd, F_UNLCK, &linfo);
-
- if (rv == 0)
- return PR_SUCCESS;
-
- _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-
diff --git a/nsprpub/pr/src/md/beos/bmemory.c b/nsprpub/pr/src/md/beos/bmemory.c
deleted file mode 100644
index fb906f0f9..000000000
--- a/nsprpub/pr/src/md/beos/bmemory.c
+++ /dev/null
@@ -1,10 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-PR_EXTERN(void) _PR_MD_INIT_SEGS(void);
-PR_EXTERN(PRStatus) _PR_MD_ALLOC_SEGMENT(PRSegment *seg, PRUint32 size, void *vaddr);
-PR_EXTERN(void) _PR_MD_FREE_SEGMENT(PRSegment *seg);
diff --git a/nsprpub/pr/src/md/beos/bmisc.c b/nsprpub/pr/src/md/beos/bmisc.c
deleted file mode 100644
index 4bdad411e..000000000
--- a/nsprpub/pr/src/md/beos/bmisc.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-#include <stdlib.h>
-
-PRLock *_connectLock = NULL;
-
-#ifndef BONE_VERSION
-/* Workaround for nonblocking connects under net_server */
-PRUint32 connectCount = 0;
-ConnectListNode connectList[64];
-#endif
-
-void
-_MD_cleanup_before_exit (void)
-{
-}
-
-void
-_MD_exit (PRIntn status)
-{
- exit(status);
-}
-
-void
-_MD_early_init (void)
-{
-}
-
-static PRLock *monitor = NULL;
-
-void
-_MD_final_init (void)
-{
- _connectLock = PR_NewLock();
- PR_ASSERT(NULL != _connectLock);
-#ifndef BONE_VERSION
- /* Workaround for nonblocking connects under net_server */
- connectCount = 0;
-#endif
-}
-
-void
-_MD_AtomicInit (void)
-{
- if (monitor == NULL) {
- monitor = PR_NewLock();
- }
-}
-
-/*
-** This is exceedingly messy. atomic_add returns the last value, NSPR expects the new value.
-** We just add or subtract 1 from the result. The actual memory update is atomic.
-*/
-
-PRInt32
-_MD_AtomicAdd( PRInt32 *ptr, PRInt32 val )
-{
- return( ( atomic_add( (long *)ptr, val ) ) + val );
-}
-
-PRInt32
-_MD_AtomicIncrement( PRInt32 *val )
-{
- return( ( atomic_add( (long *)val, 1 ) ) + 1 );
-}
-
-PRInt32
-_MD_AtomicDecrement( PRInt32 *val )
-{
- return( ( atomic_add( (long *)val, -1 ) ) - 1 );
-}
-
-PRInt32
-_MD_AtomicSet( PRInt32 *val, PRInt32 newval )
-{
- PRInt32 rv;
-
- if (!_pr_initialized) {
- _PR_ImplicitInitialization();
- }
- PR_Lock(monitor);
- rv = *val;
- *val = newval;
- PR_Unlock(monitor);
- return rv;
-}
diff --git a/nsprpub/pr/src/md/beos/bmmap.c b/nsprpub/pr/src/md/beos/bmmap.c
deleted file mode 100644
index a9b3ac589..000000000
--- a/nsprpub/pr/src/md/beos/bmmap.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-PR_EXTERN(PRStatus)
-_PR_MD_CREATE_FILE_MAP(PRFileMap *fmap, PRInt64 size)
-{
- PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
- return PR_FAILURE;
-}
-
-PR_EXTERN(PRInt32)
-_PR_MD_GET_MEM_MAP_ALIGNMENT(void)
-{
- PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
- return -1;
-}
-
-PR_EXTERN(void *)
-_PR_MD_MEM_MAP(PRFileMap *fmap, PRInt64 offset, PRUint32 len)
-{
- PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
- return 0;
-}
-
-PR_EXTERN(PRStatus)
-_PR_MD_MEM_UNMAP(void *addr, PRUint32 size)
-{
- PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
- return PR_FAILURE;
-}
-
-PR_EXTERN(PRStatus)
-_PR_MD_CLOSE_FILE_MAP(PRFileMap *fmap)
-{
- PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
- return PR_FAILURE;
-}
diff --git a/nsprpub/pr/src/md/beos/bnet.c b/nsprpub/pr/src/md/beos/bnet.c
deleted file mode 100644
index 8bfd4aead..000000000
--- a/nsprpub/pr/src/md/beos/bnet.c
+++ /dev/null
@@ -1,911 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-#include <signal.h>
-#include <unistd.h>
-#include <memory.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <sys/ioctl.h>
-
-/*
- * Make sure _PRSockLen_t is 32-bit, because we will cast a PRUint32* or
- * PRInt32* pointer to a _PRSockLen_t* pointer.
- */
-#define _PRSockLen_t int
-
-
-/*
-** Global lock variable used to bracket calls into rusty libraries that
-** aren't thread safe (like libc, libX, etc).
-*/
-static PRLock *_pr_rename_lock = NULL;
-static PRMonitor *_pr_Xfe_mon = NULL;
-
-#define READ_FD 1
-#define WRITE_FD 2
-
-/*
-** This is a support routine to handle "deferred" i/o on sockets.
-** It uses "select", so it is subject to all of the BeOS limitations
-** (only READ notification, only sockets)
-*/
-
-/*
- * socket_io_wait --
- *
- * wait for socket i/o, periodically checking for interrupt
- *
- */
-
-static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
- PRIntervalTime timeout)
-{
- PRInt32 rv = -1;
- struct timeval tv;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- PRIntervalTime epoch, now, elapsed, remaining;
- PRBool wait_for_remaining;
- PRInt32 syserror;
- fd_set rd_wr;
-
- switch (timeout) {
- case PR_INTERVAL_NO_WAIT:
- PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
- break;
- case PR_INTERVAL_NO_TIMEOUT:
- /*
- * This is a special case of the 'default' case below.
- * Please see the comments there.
- */
- tv.tv_sec = _PR_INTERRUPT_CHECK_INTERVAL_SECS;
- tv.tv_usec = 0;
- FD_ZERO(&rd_wr);
- do {
- FD_SET(osfd, &rd_wr);
- if (fd_type == READ_FD)
- rv = _MD_SELECT(osfd + 1, &rd_wr, NULL, NULL, &tv);
- else
- rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, NULL, &tv);
- if (rv == -1 && (syserror = _MD_ERRNO()) != EINTR) {
-#ifdef BONE_VERSION
- _PR_MD_MAP_SELECT_ERROR(syserror);
-#else
- if (syserror == EBADF) {
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, EBADF);
- } else {
- PR_SetError(PR_UNKNOWN_ERROR, syserror);
- }
-#endif
- break;
- }
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- rv = -1;
- break;
- }
- } while (rv == 0 || (rv == -1 && syserror == EINTR));
- break;
- default:
- now = epoch = PR_IntervalNow();
- remaining = timeout;
- FD_ZERO(&rd_wr);
- do {
- /*
- * We block in _MD_SELECT for at most
- * _PR_INTERRUPT_CHECK_INTERVAL_SECS seconds,
- * so that there is an upper limit on the delay
- * before the interrupt bit is checked.
- */
- wait_for_remaining = PR_TRUE;
- tv.tv_sec = PR_IntervalToSeconds(remaining);
- if (tv.tv_sec > _PR_INTERRUPT_CHECK_INTERVAL_SECS) {
- wait_for_remaining = PR_FALSE;
- tv.tv_sec = _PR_INTERRUPT_CHECK_INTERVAL_SECS;
- tv.tv_usec = 0;
- } else {
- tv.tv_usec = PR_IntervalToMicroseconds(
- remaining -
- PR_SecondsToInterval(tv.tv_sec));
- }
- FD_SET(osfd, &rd_wr);
- if (fd_type == READ_FD)
- rv = _MD_SELECT(osfd + 1, &rd_wr, NULL, NULL, &tv);
- else
- rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, NULL, &tv);
- /*
- * we don't consider EINTR a real error
- */
- if (rv == -1 && (syserror = _MD_ERRNO()) != EINTR) {
-#ifdef BONE_VERSION
- _PR_MD_MAP_SELECT_ERROR(syserror);
-#else
- if (syserror == EBADF) {
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, EBADF);
- } else {
- PR_SetError(PR_UNKNOWN_ERROR, syserror);
- }
-#endif
- break;
- }
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- rv = -1;
- break;
- }
- /*
- * We loop again if _MD_SELECT timed out or got interrupted
- * by a signal, and the timeout deadline has not passed yet.
- */
- if (rv == 0 || (rv == -1 && syserror == EINTR)) {
- /*
- * If _MD_SELECT timed out, we know how much time
- * we spent in blocking, so we can avoid a
- * PR_IntervalNow() call.
- */
- if (rv == 0) {
- if (wait_for_remaining) {
- now += remaining;
- } else {
- now += PR_SecondsToInterval(tv.tv_sec)
- + PR_MicrosecondsToInterval(tv.tv_usec);
- }
- } else {
- now = PR_IntervalNow();
- }
- elapsed = (PRIntervalTime) (now - epoch);
- if (elapsed >= timeout) {
- PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
- rv = -1;
- break;
- } else {
- remaining = timeout - elapsed;
- }
- }
- } while (rv == 0 || (rv == -1 && syserror == EINTR));
- break;
- }
- return(rv);
-}
-
-PRInt32
-_MD_recv (PRFileDesc *fd, void *buf, PRInt32 amount, PRInt32 flags,
- PRIntervalTime timeout)
-{
- PRInt32 osfd = fd->secret->md.osfd;
- PRInt32 rv, err;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
-#ifndef BONE_VERSION
- if (fd->secret->md.sock_state & BE_SOCK_SHUTDOWN_READ) {
- _PR_MD_MAP_RECV_ERROR(EPIPE);
- return -1;
- }
-#endif
-
-#ifdef BONE_VERSION
- /*
- ** Gah, stupid hack. If reading a zero amount, instantly return success.
- ** BONE beta 6 returns EINVAL for reads of zero bytes, which parts of
- ** mozilla use to check for socket availability.
- */
-
- if( 0 == amount ) return(0);
-#endif
-
- while ((rv = recv(osfd, buf, amount, flags)) == -1) {
- err = _MD_ERRNO();
-
- if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
- if (fd->secret->nonblocking) {
- break;
- }
- /* If socket was supposed to be blocking,
- wait a while for the condition to be
- satisfied. */
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
- goto done;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
- continue;
-
- } else
- break;
- }
-
- if (rv < 0) {
- _PR_MD_MAP_RECV_ERROR(err);
- }
-
-done:
- return(rv);
-}
-
-PRInt32
-_MD_recvfrom (PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
- PRNetAddr *addr, PRUint32 *addrlen, PRIntervalTime timeout)
-{
- PRInt32 osfd = fd->secret->md.osfd;
- PRInt32 rv, err;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
- while ((*addrlen = PR_NETADDR_SIZE(addr)),
- ((rv = recvfrom(osfd, buf, amount, flags,
- (struct sockaddr *) addr,
- (_PRSockLen_t *)addrlen)) == -1)) {
- err = _MD_ERRNO();
-
- if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
- if (fd->secret->nonblocking) {
- break;
- }
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
- goto done;
-
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
- continue;
- } else {
- break;
- }
- }
-
- if (rv < 0) {
- _PR_MD_MAP_RECVFROM_ERROR(err);
- }
-
-done:
-#ifdef _PR_HAVE_SOCKADDR_LEN
- if (rv != -1) {
- /* ignore the sa_len field of struct sockaddr */
- if (addr) {
- addr->raw.family = ((struct sockaddr *) addr)->sa_family;
- }
- }
-#endif /* _PR_HAVE_SOCKADDR_LEN */
- return(rv);
-}
-
-PRInt32
-_MD_send (PRFileDesc *fd, const void *buf, PRInt32 amount, PRInt32 flags,
- PRIntervalTime timeout)
-{
- PRInt32 osfd = fd->secret->md.osfd;
- PRInt32 rv, err;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
-#ifndef BONE_VERSION
- if (fd->secret->md.sock_state & BE_SOCK_SHUTDOWN_WRITE)
- {
- _PR_MD_MAP_SEND_ERROR(EPIPE);
- return -1;
- }
-#endif
-
- while ((rv = send(osfd, buf, amount, flags)) == -1) {
- err = _MD_ERRNO();
-
- if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
- if (fd->secret->nonblocking) {
- break;
- }
-
-#ifndef BONE_VERSION
- if( _PR_PENDING_INTERRUPT(me)) {
-
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError( PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
-
- /* in UNIX implementations, you could do a socket_io_wait here.
- * but since BeOS doesn't yet support WRITE notification in select,
- * you're spanked.
- */
- snooze( 10000L );
- continue;
-#else /* BONE_VERSION */
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0)
- goto done;
-#endif
-
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
- continue;
-
- } else {
- break;
- }
- }
-
-#ifdef BONE_VERSION
- /*
- * optimization; if bytes sent is less than "amount" call
- * select before returning. This is because it is likely that
- * the next writev() call will return EWOULDBLOCK.
- */
- if ((!fd->secret->nonblocking) && (rv > 0) && (rv < amount)
- && (timeout != PR_INTERVAL_NO_WAIT)) {
- if (socket_io_wait(osfd, WRITE_FD, timeout) < 0) {
- rv = -1;
- goto done;
- }
- }
-#endif /* BONE_VERSION */
-
- if (rv < 0) {
- _PR_MD_MAP_SEND_ERROR(err);
- }
-
-#ifdef BONE_VERSION
-done:
-#endif
- return(rv);
-}
-
-PRInt32
-_MD_sendto (PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
- const PRNetAddr *addr, PRUint32 addrlen, PRIntervalTime timeout)
-{
- PRInt32 osfd = fd->secret->md.osfd;
- PRInt32 rv, err;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-#ifdef _PR_HAVE_SOCKADDR_LEN
- PRNetAddr addrCopy;
-
- addrCopy = *addr;
- ((struct sockaddr *) &addrCopy)->sa_len = addrlen;
- ((struct sockaddr *) &addrCopy)->sa_family = addr->raw.family;
-
- while ((rv = sendto(osfd, buf, amount, flags,
- (struct sockaddr *) &addrCopy, addrlen)) == -1) {
-#else
- while ((rv = sendto(osfd, buf, amount, flags,
- (struct sockaddr *) addr, addrlen)) == -1) {
-#endif
- err = _MD_ERRNO();
-
- if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
- if (fd->secret->nonblocking) {
- break;
- }
-
-#ifdef BONE_VERSION
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0)
- goto done;
-#endif
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
- continue;
-
- } else {
- break;
- }
- }
-
- if (rv < 0) {
- _PR_MD_MAP_SENDTO_ERROR(err);
- }
-
-#ifdef BONE_VERSION
-done:
-#endif
- return(rv);
-}
-
-#ifdef BONE_VERSION
-
-PRInt32 _MD_writev(
- PRFileDesc *fd, const PRIOVec *iov,
- PRInt32 iov_size, PRIntervalTime timeout)
-{
- PRInt32 rv, err;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- PRInt32 index, amount = 0;
- PRInt32 osfd = fd->secret->md.osfd;
- struct iovec osiov[PR_MAX_IOVECTOR_SIZE];
-
- /* Ensured by PR_Writev */
- PR_ASSERT(iov_size <= PR_MAX_IOVECTOR_SIZE);
-
- /*
- * We can't pass iov to writev because PRIOVec and struct iovec
- * may not be binary compatible. Make osiov a copy of iov and
- * pass osiov to writev.
- */
- for (index = 0; index < iov_size; index++) {
- osiov[index].iov_base = iov[index].iov_base;
- osiov[index].iov_len = iov[index].iov_len;
- }
-
- /*
- * Calculate the total number of bytes to be sent; needed for
- * optimization later.
- * We could avoid this if this number was passed in; but it is
- * probably not a big deal because iov_size is usually small (less than
- * 3)
- */
- if (!fd->secret->nonblocking) {
- for (index=0; index<iov_size; index++) {
- amount += iov[index].iov_len;
- }
- }
-
- while ((rv = writev(osfd, osiov, iov_size)) == -1) {
- err = _MD_ERRNO();
- if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
- if (fd->secret->nonblocking) {
- break;
- }
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))<0)
- goto done;
-
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
- continue;
- } else {
- break;
- }
- }
-
- /*
- * optimization; if bytes sent is less than "amount" call
- * select before returning. This is because it is likely that
- * the next writev() call will return EWOULDBLOCK.
- */
- if ((!fd->secret->nonblocking) && (rv > 0) && (rv < amount)
- && (timeout != PR_INTERVAL_NO_WAIT)) {
- if (socket_io_wait(osfd, WRITE_FD, timeout) < 0) {
- rv = -1;
- goto done;
- }
- }
-
-
- if (rv < 0) {
- _PR_MD_MAP_WRITEV_ERROR(err);
- }
-done:
- return(rv);
-}
-
-#endif /* BONE_VERSION */
-
-PRInt32
-_MD_accept (PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen,
- PRIntervalTime timeout)
-{
- PRInt32 osfd = fd->secret->md.osfd;
- PRInt32 rv, err;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
- while ((rv = accept(osfd, (struct sockaddr *) addr,
- (_PRSockLen_t *)addrlen)) == -1) {
- err = _MD_ERRNO();
-
- if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
- if (fd->secret->nonblocking) {
- break;
- }
- /* If it's SUPPOSED to be a blocking thread, wait
- * a while to see if the triggering condition gets
- * satisfied.
- */
- /* Assume that we're always using a native thread */
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
- goto done;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
- continue;
- } else {
- break;
- }
- }
- if (rv < 0) {
- _PR_MD_MAP_ACCEPT_ERROR(err);
- } else if (addr != NULL) {
- /* bug 134099 */
- err = getpeername(rv, (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
- }
-done:
-#ifdef _PR_HAVE_SOCKADDR_LEN
- if (rv != -1) {
- /* Mask off the first byte of struct sockaddr (the length field) */
- if (addr) {
- addr->raw.family = ((struct sockaddr *) addr)->sa_family;
- }
- }
-#endif /* _PR_HAVE_SOCKADDR_LEN */
- return(rv);
-}
-
-PRInt32
-_MD_connect (PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
- PRIntervalTime timeout)
-{
- PRInt32 rv, err;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- PRInt32 osfd = fd->secret->md.osfd;
-
-#ifndef BONE_VERSION
- fd->secret->md.connectValueValid = PR_FALSE;
-#endif
-#ifdef _PR_HAVE_SOCKADDR_LEN
- PRNetAddr addrCopy;
-
- addrCopy = *addr;
- ((struct sockaddr *) &addrCopy)->sa_len = addrlen;
- ((struct sockaddr *) &addrCopy)->sa_family = addr->raw.family;
-#endif
-
- /* (Copied from unix.c)
- * We initiate the connection setup by making a nonblocking connect()
- * call. If the connect() call fails, there are two cases we handle
- * specially:
- * 1. The connect() call was interrupted by a signal. In this case
- * we simply retry connect().
- * 2. The NSPR socket is nonblocking and connect() fails with
- * EINPROGRESS. We first wait until the socket becomes writable.
- * Then we try to find out whether the connection setup succeeded
- * or failed.
- */
-
-retry:
-#ifdef _PR_HAVE_SOCKADDR_LEN
- if ((rv = connect(osfd, (struct sockaddr *)&addrCopy, addrlen)) == -1) {
-#else
- if ((rv = connect(osfd, (struct sockaddr *)addr, addrlen)) == -1) {
-#endif
- err = _MD_ERRNO();
-#ifndef BONE_VERSION
- fd->secret->md.connectReturnValue = rv;
- fd->secret->md.connectReturnError = err;
- fd->secret->md.connectValueValid = PR_TRUE;
-#endif
- if( err == EINTR ) {
-
- if( _PR_PENDING_INTERRUPT(me)) {
-
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError( PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
-#ifndef BONE_VERSION
- snooze( 100000L );
-#endif
- goto retry;
- }
-
-#ifndef BONE_VERSION
- if(!fd->secret->nonblocking && ((err == EINPROGRESS) || (err==EAGAIN) || (err==EALREADY))) {
-
- /*
- ** There's no timeout on this connect, but that's not
- ** a big deal, since the connect times out anyways
- ** after 30 seconds. Just sleep for 1/10th of a second
- ** and retry until we go through or die.
- */
-
- if( _PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError( PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
-
- goto retry;
- }
-
- if( fd->secret->nonblocking && ((err == EAGAIN) || (err == EINPROGRESS))) {
- PR_Lock(_connectLock);
- if (connectCount < sizeof(connectList)/sizeof(connectList[0])) {
- connectList[connectCount].osfd = osfd;
- memcpy(&connectList[connectCount].addr, addr, addrlen);
- connectList[connectCount].addrlen = addrlen;
- connectList[connectCount].timeout = timeout;
- connectCount++;
- PR_Unlock(_connectLock);
- _PR_MD_MAP_CONNECT_ERROR(err);
- } else {
- PR_Unlock(_connectLock);
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
- }
- return rv;
- }
-#else /* BONE_VERSION */
- if(!fd->secret->nonblocking && (err == EINTR)) {
-
- rv = socket_io_wait(osfd, WRITE_FD, timeout);
- if (rv == -1) {
- return -1;
- }
-
- PR_ASSERT(rv == 1);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError( PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
- err = _MD_beos_get_nonblocking_connect_error(osfd);
- if (err != 0) {
- _PR_MD_MAP_CONNECT_ERROR(err);
- return -1;
- }
- return 0;
- }
-#endif
-
- _PR_MD_MAP_CONNECT_ERROR(err);
- }
-
- return rv;
-}
-
-PRInt32
-_MD_bind (PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen)
-{
- PRInt32 rv, err;
-#ifdef _PR_HAVE_SOCKADDR_LEN
- PRNetAddr addrCopy;
-
- addrCopy = *addr;
- ((struct sockaddr *) &addrCopy)->sa_len = addrlen;
- ((struct sockaddr *) &addrCopy)->sa_family = addr->raw.family;
- rv = bind(fd->secret->md.osfd, (struct sockaddr *) &addrCopy, (int )addrlen);
-#else
- rv = bind(fd->secret->md.osfd, (struct sockaddr *) addr, (int )addrlen);
-#endif
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_BIND_ERROR(err);
- }
-
- return(rv);
-}
-
-PRInt32
-_MD_listen (PRFileDesc *fd, PRIntn backlog)
-{
- PRInt32 rv, err;
-
-#ifndef BONE_VERSION
- /* Bug workaround! Setting listen to 0 on Be accepts no connections.
- ** On most UN*Xes this sets the default.
- */
-
- if( backlog == 0 ) backlog = 5;
-#endif
-
- rv = listen(fd->secret->md.osfd, backlog);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_LISTEN_ERROR(err);
- }
-
- return(rv);
-}
-
-PRInt32
-_MD_shutdown (PRFileDesc *fd, PRIntn how)
-{
- PRInt32 rv, err;
-
-#ifndef BONE_VERSION
- if (how == PR_SHUTDOWN_SEND)
- fd->secret->md.sock_state = BE_SOCK_SHUTDOWN_WRITE;
- else if (how == PR_SHUTDOWN_RCV)
- fd->secret->md.sock_state = BE_SOCK_SHUTDOWN_READ;
- else if (how == PR_SHUTDOWN_BOTH) {
- fd->secret->md.sock_state = (BE_SOCK_SHUTDOWN_WRITE | BE_SOCK_SHUTDOWN_READ);
- }
-
- return 0;
-#else /* BONE_VERSION */
- rv = shutdown(fd->secret->md.osfd, how);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_SHUTDOWN_ERROR(err);
- }
- return(rv);
-#endif
-}
-
-PRInt32
-_MD_socketpair (int af, int type, int flags, PRInt32 *osfd)
-{
- return PR_NOT_IMPLEMENTED_ERROR;
-}
-
-PRInt32
-_MD_close_socket (PRInt32 osfd)
-{
-#ifdef BONE_VERSION
- close( osfd );
-#else
- closesocket( osfd );
-#endif
-}
-
-PRStatus
-_MD_getsockname (PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen)
-{
- PRInt32 rv, err;
-
- rv = getsockname(fd->secret->md.osfd,
- (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
-#ifdef _PR_HAVE_SOCKADDR_LEN
- if (rv == 0) {
- /* ignore the sa_len field of struct sockaddr */
- if (addr) {
- addr->raw.family = ((struct sockaddr *) addr)->sa_family;
- }
- }
-#endif /* _PR_HAVE_SOCKADDR_LEN */
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_GETSOCKNAME_ERROR(err);
- }
-
- return rv==0?PR_SUCCESS:PR_FAILURE;
-}
-
-PRStatus
-_MD_getpeername (PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen)
-{
- PRInt32 rv, err;
-
- rv = getpeername(fd->secret->md.osfd,
- (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
-
-#ifdef _PR_HAVE_SOCKADDR_LEN
- if (rv == 0) {
- /* ignore the sa_len field of struct sockaddr */
- if (addr) {
- addr->raw.family = ((struct sockaddr *) addr)->sa_family;
- }
- }
-#endif /* _PR_HAVE_SOCKADDR_LEN */
-
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_GETPEERNAME_ERROR(err);
- }
- return rv==0?PR_SUCCESS:PR_FAILURE;
-}
-
-PRStatus
-_MD_getsockopt (PRFileDesc *fd, PRInt32 level,
- PRInt32 optname, char* optval, PRInt32* optlen)
-{
- PRInt32 rv, err;
-
- rv = getsockopt(fd->secret->md.osfd, level, optname,
- optval, (_PRSockLen_t *)optlen);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_GETSOCKOPT_ERROR(err);
- }
-
- return rv==0?PR_SUCCESS:PR_FAILURE;
-}
-
-PRStatus
-_MD_setsockopt (PRFileDesc *fd, PRInt32 level,
- PRInt32 optname, const char* optval, PRInt32 optlen)
-{
- PRInt32 rv, err;
-
- rv = setsockopt(fd->secret->md.osfd, level, optname, optval, optlen);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_SETSOCKOPT_ERROR(err);
- }
- return rv==0?PR_SUCCESS:PR_FAILURE;
-}
-
-PRInt32
-_MD_accept_read (PRFileDesc *sd, PRInt32 *newSock, PRNetAddr **raddr,
- void *buf, PRInt32 amount, PRIntervalTime timeout)
-{
- return PR_NOT_IMPLEMENTED_ERROR;
-}
-
-#ifndef BONE_VERSION
-PRInt32
-_MD_socket (int af, int type, int flags)
-{
- PRInt32 osfd, err;
-
- osfd = socket( af, type, 0 );
-
- if( -1 == osfd ) {
-
- err = _MD_ERRNO();
- _PR_MD_MAP_SOCKET_ERROR( err );
- }
-
- return( osfd );
-}
-#else
-PRInt32
-_MD_socket(PRInt32 domain, PRInt32 type, PRInt32 proto)
-{
- PRInt32 osfd, err;
-
- osfd = socket(domain, type, proto);
-
- if (osfd == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_SOCKET_ERROR(err);
- }
-
- return(osfd);
-}
-#endif
-
-PRInt32
-_MD_socketavailable (PRFileDesc *fd)
-{
-#ifdef BONE_VERSION
- PRInt32 result;
-
- if (ioctl(fd->secret->md.osfd, FIONREAD, &result) < 0) {
- _PR_MD_MAP_SOCKETAVAILABLE_ERROR(_MD_ERRNO());
- return -1;
- }
- return result;
-#else
- return PR_NOT_IMPLEMENTED_ERROR;
-#endif
-}
-
-PRInt32
-_MD_get_socket_error (void)
-{
- return PR_NOT_IMPLEMENTED_ERROR;
-}
-
-PRStatus
-_MD_gethostname (char *name, PRUint32 namelen)
-{
- PRInt32 rv, err;
-
- rv = gethostname(name, namelen);
- if (rv == 0)
- {
- err = _MD_ERRNO();
- _PR_MD_MAP_GETHOSTNAME_ERROR(err);
- return PR_FAILURE;
- }
- return PR_SUCCESS;
-}
-
-#ifndef BONE_VERSION
-PRInt32
-_MD_beos_get_nonblocking_connect_error(PRFileDesc *fd)
-{
- int rv;
- int flags = 0;
-
- rv = recv(fd->secret->md.osfd, NULL, 0, flags);
- PR_ASSERT(-1 == rv || 0 == rv);
- if (-1 == rv && errno != EAGAIN && errno != EWOULDBLOCK) {
- return errno;
- }
- return 0; /* no error */
-}
-#else
-PRInt32
-_MD_beos_get_nonblocking_connect_error(int osfd)
-{
- return PR_NOT_IMPLEMENTED_ERROR;
- // int err;
- // _PRSockLen_t optlen = sizeof(err);
- // if (getsockopt(osfd, SOL_SOCKET, SO_ERROR, (char *) &err, &optlen) == -1) {
- // return errno;
- // } else {
- // return err;
- // }
-}
-#endif /* BONE_VERSION */
diff --git a/nsprpub/pr/src/md/beos/bproc.c b/nsprpub/pr/src/md/beos/bproc.c
deleted file mode 100644
index 30ac56990..000000000
--- a/nsprpub/pr/src/md/beos/bproc.c
+++ /dev/null
@@ -1,212 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; c-basic-offset: 8 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-#include <stdio.h>
-#include <signal.h>
-
-#define _PR_SIGNALED_EXITSTATUS 256
-
-PRProcess*
-_MD_create_process (const char *path, char *const *argv,
- char *const *envp, const PRProcessAttr *attr)
-{
- PRProcess *process;
- int nEnv, idx;
- char *const *childEnvp;
- char **newEnvp = NULL;
- int flags;
- PRBool found = PR_FALSE;
-
- process = PR_NEW(PRProcess);
- if (!process) {
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- return NULL;
- }
-
- childEnvp = envp;
- if (attr && attr->fdInheritBuffer) {
- if (NULL == childEnvp) {
- childEnvp = environ;
- }
- for (nEnv = 0; childEnvp[nEnv]; nEnv++) {
- }
- newEnvp = (char **) PR_MALLOC((nEnv + 2) * sizeof(char *));
- if (NULL == newEnvp) {
- PR_DELETE(process);
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- return NULL;
- }
- for (idx = 0; idx < nEnv; idx++) {
- newEnvp[idx] = childEnvp[idx];
- if (!found && !strncmp(newEnvp[idx], "NSPR_INHERIT_FDS=", 17)) {
- newEnvp[idx] = attr->fdInheritBuffer;
- found = PR_TRUE;
- }
- }
- if (!found) {
- newEnvp[idx++] = attr->fdInheritBuffer;
- }
- newEnvp[idx] = NULL;
- childEnvp = newEnvp;
- }
-
- process->md.pid = fork();
-
- if ((pid_t) -1 == process->md.pid) {
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, errno);
- PR_DELETE(process);
- if (newEnvp) {
- PR_DELETE(newEnvp);
- }
- return NULL;
- } else if (0 == process->md.pid) { /* the child process */
- /*
- * If the child process needs to exit, it must call _exit().
- * Do not call exit(), because exit() will flush and close
- * the standard I/O file descriptors, and hence corrupt
- * the parent process's standard I/O data structures.
- */
-
- if (attr) {
- /* the osfd's to redirect stdin, stdout, and stderr to */
- int in_osfd = -1, out_osfd = -1, err_osfd = -1;
-
- if (attr->stdinFd
- && attr->stdinFd->secret->md.osfd != 0) {
- in_osfd = attr->stdinFd->secret->md.osfd;
- if (dup2(in_osfd, 0) != 0) {
- _exit(1); /* failed */
- }
- flags = fcntl(0, F_GETFL, 0);
- if (flags & O_NONBLOCK) {
- fcntl(0, F_SETFL, flags & ~O_NONBLOCK);
- }
- }
- if (attr->stdoutFd
- && attr->stdoutFd->secret->md.osfd != 1) {
- out_osfd = attr->stdoutFd->secret->md.osfd;
- if (dup2(out_osfd, 1) != 1) {
- _exit(1); /* failed */
- }
- flags = fcntl(1, F_GETFL, 0);
- if (flags & O_NONBLOCK) {
- fcntl(1, F_SETFL, flags & ~O_NONBLOCK);
- }
- }
- if (attr->stderrFd
- && attr->stderrFd->secret->md.osfd != 2) {
- err_osfd = attr->stderrFd->secret->md.osfd;
- if (dup2(err_osfd, 2) != 2) {
- _exit(1); /* failed */
- }
- flags = fcntl(2, F_GETFL, 0);
- if (flags & O_NONBLOCK) {
- fcntl(2, F_SETFL, flags & ~O_NONBLOCK);
- }
- }
- if (in_osfd != -1) {
- close(in_osfd);
- }
- if (out_osfd != -1 && out_osfd != in_osfd) {
- close(out_osfd);
- }
- if (err_osfd != -1 && err_osfd != in_osfd
- && err_osfd != out_osfd) {
- close(err_osfd);
- }
- if (attr->currentDirectory) {
- if (chdir(attr->currentDirectory) < 0) {
- _exit(1); /* failed */
- }
- }
- }
-
- if (childEnvp) {
- (void)execve(path, argv, childEnvp);
- } else {
- /* Inherit the environment of the parent. */
- (void)execv(path, argv);
- }
- /* Whoops! It returned. That's a bad sign. */
- _exit(1);
- }
-
- if (newEnvp) {
- PR_DELETE(newEnvp);
- }
-
- return process;
-}
-
-PRStatus
-_MD_detach_process (PRProcess *process)
-{
- /* If we kept a process table like unix does,
- * we'd remove the entry here.
- * Since we dont', just delete the process variable
- */
- PR_DELETE(process);
- return PR_SUCCESS;
-}
-
-PRStatus
-_MD_wait_process (PRProcess *process, PRInt32 *exitCode)
-{
- PRStatus retVal = PR_SUCCESS;
- int ret, status;
-
- /* Ignore interruptions */
- do {
- ret = waitpid(process->md.pid, &status, 0);
- } while (ret == -1 && errno == EINTR);
-
- /*
- * waitpid() cannot return 0 because we did not invoke it
- * with the WNOHANG option.
- */
- PR_ASSERT(0 != ret);
-
- if (ret < 0) {
- PR_SetError(PR_UNKNOWN_ERROR, _MD_ERRNO());
- return PR_FAILURE;
- }
-
- /* If child process exited normally, return child exit code */
- if (WIFEXITED(status)) {
- *exitCode = WEXITSTATUS(status);
- } else {
- PR_ASSERT(WIFSIGNALED(status));
- *exitCode = _PR_SIGNALED_EXITSTATUS;
- }
-
- PR_DELETE(process);
- return PR_SUCCESS;
-}
-
-PRStatus
-_MD_kill_process (PRProcess *process)
-{
- PRErrorCode prerror;
- PRInt32 oserror;
-
- if (kill(process->md.pid, SIGKILL) == 0) {
- return PR_SUCCESS;
- }
- oserror = errno;
- switch (oserror) {
- case EPERM:
- prerror = PR_NO_ACCESS_RIGHTS_ERROR;
- break;
- case ESRCH:
- prerror = PR_INVALID_ARGUMENT_ERROR;
- break;
- default:
- prerror = PR_UNKNOWN_ERROR;
- break;
- }
- PR_SetError(prerror, oserror);
- return PR_FAILURE;
-}
diff --git a/nsprpub/pr/src/md/beos/brng.c b/nsprpub/pr/src/md/beos/brng.c
deleted file mode 100644
index 18a3bbf1e..000000000
--- a/nsprpub/pr/src/md/beos/brng.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <assert.h>
-#include <time.h>
-#include "primpl.h"
-
-extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size )
-{
- struct timeval tv;
- int n = 0;
- int s;
-
- GETTIMEOFDAY(&tv);
-
- if ( size > 0 ) {
- s = _pr_CopyLowBits((char*)buf+n, size, &tv.tv_usec, sizeof(tv.tv_usec));
- size -= s;
- n += s;
- }
- if ( size > 0 ) {
- s = _pr_CopyLowBits((char*)buf+n, size, &tv.tv_sec, sizeof(tv.tv_usec));
- size -= s;
- n += s;
- }
-
- return n;
-} /* end _PR_MD_GetRandomNoise() */
diff --git a/nsprpub/pr/src/md/beos/bseg.c b/nsprpub/pr/src/md/beos/bseg.c
deleted file mode 100644
index e7bb9b3d7..000000000
--- a/nsprpub/pr/src/md/beos/bseg.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-PR_IMPLEMENT(void)
- _MD_init_segs (void)
-{
-}
-
-PR_IMPLEMENT(PRStatus)
- _MD_alloc_segment (PRSegment *seg, PRUint32 size, void *vaddr)
-{
- return PR_NOT_IMPLEMENTED_ERROR;
-}
-
-PR_IMPLEMENT(void)
- _MD_free_segment (PRSegment *seg)
-{
-}
diff --git a/nsprpub/pr/src/md/beos/bsrcs.mk b/nsprpub/pr/src/md/beos/bsrcs.mk
deleted file mode 100644
index 94424537f..000000000
--- a/nsprpub/pr/src/md/beos/bsrcs.mk
+++ /dev/null
@@ -1,22 +0,0 @@
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-
-# this file lists the source files to be compiled (used in Makefile) and
-# then enumerated as object files (in objs.mk) for inclusion in the NSPR
-# shared library
-
-MDCSRCS = \
- beos.c \
- beos_errors.c \
- bfile.c \
- bmisc.c \
- bnet.c \
- bproc.c \
- brng.c \
- bseg.c \
- btime.c \
- bmmap.c \
- $(NULL)
diff --git a/nsprpub/pr/src/md/beos/btime.c b/nsprpub/pr/src/md/beos/btime.c
deleted file mode 100644
index b6e02fc7d..000000000
--- a/nsprpub/pr/src/md/beos/btime.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-#include <kernel/OS.h>
-
-static bigtime_t start;
-
-PRTime
-_MD_now (void)
-{
- return (PRTime)real_time_clock_usecs();
-}
-
-void
-_MD_interval_init (void)
-{
- /* grab the base interval time */
- start = real_time_clock_usecs();
-}
-
-PRIntervalTime
-_MD_get_interval (void)
-{
- return( (PRIntervalTime) real_time_clock_usecs() / 10 );
-
-#if 0
- /* return the number of tens of microseconds that have elapsed since
- we were initialized */
- bigtime_t now = real_time_clock_usecs();
- now -= start;
- now /= 10;
- return (PRIntervalTime)now;
-#endif
-}
-
-PRIntervalTime
-_MD_interval_per_sec (void)
-{
- return 100000L;
-}
diff --git a/nsprpub/pr/src/md/beos/objs.mk b/nsprpub/pr/src/md/beos/objs.mk
deleted file mode 100644
index 8727ee0e6..000000000
--- a/nsprpub/pr/src/md/beos/objs.mk
+++ /dev/null
@@ -1,11 +0,0 @@
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-# This makefile appends to the variable OBJS the platform-dependent
-# object modules that will be part of the nspr20 library.
-
-include $(srcdir)/md/beos/bsrcs.mk
-
-OBJS += $(MDCSRCS:%.c=md/beos/$(OBJDIR)/%.$(OBJ_SUFFIX))
diff --git a/nsprpub/pr/src/md/os2/os2_errors.c b/nsprpub/pr/src/md/os2/os2_errors.c
index 98f5cde59..dfcca6108 100644
--- a/nsprpub/pr/src/md/os2/os2_errors.c
+++ b/nsprpub/pr/src/md/os2/os2_errors.c
@@ -8,152 +8,152 @@
void _MD_os2_map_default_error(PRInt32 err)
{
- switch (err) {
- case EWOULDBLOCK:
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case EMSGSIZE:
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ENOBUFS:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ECONNREFUSED:
- PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
- break;
- case EISCONN:
- PR_SetError(PR_IS_CONNECTED_ERROR, err);
- break;
+ switch (err) {
+ case EWOULDBLOCK:
+ PR_SetError(PR_WOULD_BLOCK_ERROR, err);
+ break;
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case EMSGSIZE:
+ case EINVAL:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
+ case ENOBUFS:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ECONNREFUSED:
+ PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
+ break;
+ case EISCONN:
+ PR_SetError(PR_IS_CONNECTED_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case ERROR_NETNAME_DELETED:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case ERROR_NETNAME_DELETED:
+ PR_SetError(PR_CONNECT_RESET_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_opendir_error(PRInt32 err)
{
- switch (err) {
- case ERROR_FILE_NOT_FOUND:
- case ERROR_PATH_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- case ERROR_INVALID_ACCESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_INVALID_NAME:
- case ERROR_INVALID_PARAMETER:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ERROR_TOO_MANY_OPEN_FILES:
- case ERROR_NOT_DOS_DISK:
- case ERROR_NOT_READY:
- case ERROR_OPEN_FAILED:
- case ERROR_PATH_BUSY:
- case ERROR_CANNOT_MAKE:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- case ERROR_DEVICE_IN_USE:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_FILENAME_EXCED_RANGE:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_SHARING_BUFFER_EXCEEDED:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_FILE_NOT_FOUND:
+ case ERROR_PATH_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ case ERROR_INVALID_ACCESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_INVALID_NAME:
+ case ERROR_INVALID_PARAMETER:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
+ case ERROR_TOO_MANY_OPEN_FILES:
+ case ERROR_NOT_DOS_DISK:
+ case ERROR_NOT_READY:
+ case ERROR_OPEN_FAILED:
+ case ERROR_PATH_BUSY:
+ case ERROR_CANNOT_MAKE:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ case ERROR_DEVICE_IN_USE:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_FILENAME_EXCED_RANGE:
+ PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_SHARING_BUFFER_EXCEEDED:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_closedir_error(PRInt32 err)
{
- switch (err) {
- case ERROR_FILE_NOT_FOUND:
- case ERROR_ACCESS_DENIED:
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_FILE_NOT_FOUND:
+ case ERROR_ACCESS_DENIED:
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_readdir_error(PRInt32 err)
{
- switch (err) {
- case ERROR_NO_MORE_FILES:
- PR_SetError(PR_NO_MORE_FILES_ERROR, err);
- break;
- case ERROR_FILE_NOT_FOUND:
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_NOT_DOS_DISK:
- case ERROR_LOCK_VIOLATION:
- case ERROR_BROKEN_PIPE:
- case ERROR_NOT_READY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_NO_MORE_FILES:
+ PR_SetError(PR_NO_MORE_FILES_ERROR, err);
+ break;
+ case ERROR_FILE_NOT_FOUND:
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_NOT_DOS_DISK:
+ case ERROR_LOCK_VIOLATION:
+ case ERROR_BROKEN_PIPE:
+ case ERROR_NOT_READY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_delete_error(PRInt32 err)
{
- switch (err) {
- case ERROR_FILE_NOT_FOUND:
- case ERROR_PATH_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_ACCESS_DENIED:
- case ERROR_WRITE_PROTECT:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- case ERROR_LOCKED:
- case ERROR_SHARING_VIOLATION:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_FILE_NOT_FOUND:
+ case ERROR_PATH_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_ACCESS_DENIED:
+ case ERROR_WRITE_PROTECT:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ case ERROR_LOCKED:
+ case ERROR_SHARING_VIOLATION:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
/* The error code for stat() is in errno. */
@@ -173,72 +173,72 @@ void _MD_os2_map_stat_error(PRInt32 err)
void _MD_os2_map_fstat_error(PRInt32 err)
{
- switch (err) {
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- case ERROR_LOCKED:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ case ERROR_LOCKED:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_rename_error(PRInt32 err)
{
- switch (err) {
- case ERROR_FILE_NOT_FOUND:
- case ERROR_PATH_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_INVALID_NAME:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_FILENAME_EXCED_RANGE:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ERROR_ALREADY_EXISTS:
- case ERROR_FILE_EXISTS:
- PR_SetError(PR_FILE_EXISTS_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_FILE_NOT_FOUND:
+ case ERROR_PATH_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_INVALID_NAME:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_FILENAME_EXCED_RANGE:
+ PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ERROR_ALREADY_EXISTS:
+ case ERROR_FILE_EXISTS:
+ PR_SetError(PR_FILE_EXISTS_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
/* The error code for access() is in errno. */
@@ -258,458 +258,458 @@ void _MD_os2_map_access_error(PRInt32 err)
void _MD_os2_map_mkdir_error(PRInt32 err)
{
- switch (err) {
- case ERROR_ALREADY_EXISTS:
- case ERROR_FILE_EXISTS:
- PR_SetError(PR_FILE_EXISTS_ERROR, err);
- break;
- case ERROR_FILE_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_INVALID_NAME:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_FILENAME_EXCED_RANGE:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ERROR_TOO_MANY_OPEN_FILES:
- PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
- break;
- case ERROR_PATH_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ERROR_DISK_FULL:
- case ERROR_HANDLE_DISK_FULL:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
- case ERROR_WRITE_PROTECT:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_ALREADY_EXISTS:
+ case ERROR_FILE_EXISTS:
+ PR_SetError(PR_FILE_EXISTS_ERROR, err);
+ break;
+ case ERROR_FILE_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_INVALID_NAME:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_FILENAME_EXCED_RANGE:
+ PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
+ break;
+ case ERROR_TOO_MANY_OPEN_FILES:
+ PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
+ break;
+ case ERROR_PATH_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ERROR_DISK_FULL:
+ case ERROR_HANDLE_DISK_FULL:
+ PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
+ break;
+ case ERROR_WRITE_PROTECT:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_rmdir_error(PRInt32 err)
{
- switch (err) {
- case ERROR_FILE_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_INVALID_NAME:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_FILENAME_EXCED_RANGE:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ERROR_TOO_MANY_OPEN_FILES:
- PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
- break;
- case ERROR_PATH_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ERROR_WRITE_PROTECT:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_FILE_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_INVALID_NAME:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_FILENAME_EXCED_RANGE:
+ PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
+ break;
+ case ERROR_TOO_MANY_OPEN_FILES:
+ PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
+ break;
+ case ERROR_PATH_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ERROR_WRITE_PROTECT:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_read_error(PRInt32 err)
{
- switch (err) {
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- case ERROR_LOCKED:
- case ERROR_SHARING_VIOLATION:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_NETNAME_DELETED:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
+ switch (err) {
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ case ERROR_LOCKED:
+ case ERROR_SHARING_VIOLATION:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_NETNAME_DELETED:
+ PR_SetError(PR_CONNECT_RESET_ERROR, err);
+ break;
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_transmitfile_error(PRInt32 err)
{
- switch (err) {
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- case ERROR_LOCKED:
- case ERROR_SHARING_VIOLATION:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_FILENAME_EXCED_RANGE:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ERROR_TOO_MANY_OPEN_FILES:
- PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
- break;
- case ERROR_PATH_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
+ switch (err) {
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ case ERROR_LOCKED:
+ case ERROR_SHARING_VIOLATION:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_FILENAME_EXCED_RANGE:
+ PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
+ break;
+ case ERROR_TOO_MANY_OPEN_FILES:
+ PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
+ break;
+ case ERROR_PATH_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_write_error(PRInt32 err)
{
- switch (err) {
- case ERROR_ACCESS_DENIED:
- case ERROR_WRITE_PROTECT:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- case ERROR_LOCKED:
- case ERROR_SHARING_VIOLATION:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- case ERROR_DISK_FULL:
- case ERROR_HANDLE_DISK_FULL:
- case ENOSPC:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
- case ERROR_NETNAME_DELETED:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case EMSGSIZE:
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ENOBUFS:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ECONNREFUSED:
- PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
- break;
- case EISCONN:
- PR_SetError(PR_IS_CONNECTED_ERROR, err);
- break;
+ switch (err) {
+ case ERROR_ACCESS_DENIED:
+ case ERROR_WRITE_PROTECT:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ case ERROR_LOCKED:
+ case ERROR_SHARING_VIOLATION:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ case ERROR_DISK_FULL:
+ case ERROR_HANDLE_DISK_FULL:
+ case ENOSPC:
+ PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
+ break;
+ case ERROR_NETNAME_DELETED:
+ PR_SetError(PR_CONNECT_RESET_ERROR, err);
+ break;
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case EMSGSIZE:
+ case EINVAL:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
+ case ENOBUFS:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ECONNREFUSED:
+ PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
+ break;
+ case EISCONN:
+ PR_SetError(PR_IS_CONNECTED_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_lseek_error(PRInt32 err)
{
- switch (err) {
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_SEEK_ON_DEVICE:
- PR_SetError(PR_IO_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_SEEK_ON_DEVICE:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_fsync_error(PRInt32 err)
{
- switch (err) {
- case ERROR_ACCESS_DENIED:
- case ERROR_WRITE_PROTECT:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ERROR_DISK_FULL:
- case ERROR_HANDLE_DISK_FULL:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_ACCESS_DENIED:
+ case ERROR_WRITE_PROTECT:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ERROR_DISK_FULL:
+ case ERROR_HANDLE_DISK_FULL:
+ PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_close_error(PRInt32 err)
{
- switch (err) {
- case ERROR_INVALID_HANDLE:
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_INVALID_HANDLE:
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_socket_error(PRInt32 err)
{
- switch (err) {
- case EPROTONOSUPPORT:
- PR_SetError(PR_PROTOCOL_NOT_SUPPORTED_ERROR, err);
- break;
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- case ENOBUFS:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case EPROTONOSUPPORT:
+ PR_SetError(PR_PROTOCOL_NOT_SUPPORTED_ERROR, err);
+ break;
+ case EACCES:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ case ENOBUFS:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_recv_error(PRInt32 err)
{
- switch (err) {
- case EWOULDBLOCK:
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
+ switch (err) {
+ case EWOULDBLOCK:
+ PR_SetError(PR_WOULD_BLOCK_ERROR, err);
+ break;
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case ERROR_NETNAME_DELETED:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case ERROR_NETNAME_DELETED:
+ PR_SetError(PR_CONNECT_RESET_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_recvfrom_error(PRInt32 err)
{
- switch (err) {
- case EWOULDBLOCK:
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
+ switch (err) {
+ case EWOULDBLOCK:
+ PR_SetError(PR_WOULD_BLOCK_ERROR, err);
+ break;
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case ERROR_NETNAME_DELETED:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case ERROR_NETNAME_DELETED:
+ PR_SetError(PR_CONNECT_RESET_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_send_error(PRInt32 err)
{
- switch (err) {
- case EWOULDBLOCK:
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case EMSGSIZE:
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ENOBUFS:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ECONNREFUSED:
- PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
- break;
- case EISCONN:
- PR_SetError(PR_IS_CONNECTED_ERROR, err);
- break;
+ switch (err) {
+ case EWOULDBLOCK:
+ PR_SetError(PR_WOULD_BLOCK_ERROR, err);
+ break;
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case EMSGSIZE:
+ case EINVAL:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
+ case ENOBUFS:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ECONNREFUSED:
+ PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
+ break;
+ case EISCONN:
+ PR_SetError(PR_IS_CONNECTED_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case ERROR_NETNAME_DELETED:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case ERROR_NETNAME_DELETED:
+ PR_SetError(PR_CONNECT_RESET_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_sendto_error(PRInt32 err)
{
- _MD_os2_map_default_error(err);
+ _MD_os2_map_default_error(err);
}
void _MD_os2_map_writev_error(int err)
{
- _MD_os2_map_default_error(err);
+ _MD_os2_map_default_error(err);
}
void _MD_os2_map_accept_error(PRInt32 err)
{
- _MD_os2_map_default_error(err);
+ _MD_os2_map_default_error(err);
}
void _MD_os2_map_acceptex_error(PRInt32 err)
{
- switch (err) {
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
/*
@@ -729,315 +729,315 @@ int _MD_os2_get_nonblocking_connect_error(int osfd)
void _MD_os2_map_connect_error(PRInt32 err)
{
- switch (err) {
- case EWOULDBLOCK:
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
+ switch (err) {
+ case EWOULDBLOCK:
+ PR_SetError(PR_WOULD_BLOCK_ERROR, err);
+ break;
case EINPROGRESS:
- PR_SetError(PR_IN_PROGRESS_ERROR, err);
- break;
- case EALREADY:
- case EINVAL:
- PR_SetError(PR_ALREADY_INITIATED_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EADDRNOTAVAIL:
- PR_SetError(PR_ADDRESS_NOT_AVAILABLE_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case EAFNOSUPPORT:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
- case ETIMEDOUT:
- PR_SetError(PR_IO_TIMEOUT_ERROR, err);
- break;
- case ECONNREFUSED:
- PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
- break;
- case ENETUNREACH:
- PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, err);
- break;
- case EADDRINUSE:
- PR_SetError(PR_ADDRESS_IN_USE_ERROR, err);
- break;
- case EISCONN:
- PR_SetError(PR_IS_CONNECTED_ERROR, err);
- break;
+ PR_SetError(PR_IN_PROGRESS_ERROR, err);
+ break;
+ case EALREADY:
+ case EINVAL:
+ PR_SetError(PR_ALREADY_INITIATED_ERROR, err);
+ break;
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case EADDRNOTAVAIL:
+ PR_SetError(PR_ADDRESS_NOT_AVAILABLE_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case EAFNOSUPPORT:
+ PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
+ break;
+ case ETIMEDOUT:
+ PR_SetError(PR_IO_TIMEOUT_ERROR, err);
+ break;
+ case ECONNREFUSED:
+ PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
+ break;
+ case ENETUNREACH:
+ PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, err);
+ break;
+ case EADDRINUSE:
+ PR_SetError(PR_ADDRESS_IN_USE_ERROR, err);
+ break;
+ case EISCONN:
+ PR_SetError(PR_IS_CONNECTED_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_bind_error(PRInt32 err)
{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
+ switch (err) {
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case EADDRNOTAVAIL:
- PR_SetError(PR_ADDRESS_NOT_AVAILABLE_ERROR, err);
- break;
- case EADDRINUSE:
- PR_SetError(PR_ADDRESS_IN_USE_ERROR, err);
- break;
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_SOCKET_ADDRESS_IS_BOUND_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case EADDRNOTAVAIL:
+ PR_SetError(PR_ADDRESS_NOT_AVAILABLE_ERROR, err);
+ break;
+ case EADDRINUSE:
+ PR_SetError(PR_ADDRESS_IN_USE_ERROR, err);
+ break;
+ case EACCES:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case EINVAL:
+ PR_SetError(PR_SOCKET_ADDRESS_IS_BOUND_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_listen_error(PRInt32 err)
{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case EOPNOTSUPP:
- PR_SetError(PR_NOT_TCP_SOCKET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case EOPNOTSUPP:
+ PR_SetError(PR_NOT_TCP_SOCKET_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_shutdown_error(PRInt32 err)
{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case ENOTCONN:
- PR_SetError(PR_NOT_CONNECTED_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case ENOTCONN:
+ PR_SetError(PR_NOT_CONNECTED_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_socketpair_error(PRInt32 err)
{
- switch (err) {
- case ENOMEM:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case EAFNOSUPPORT:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
- case EPROTONOSUPPORT:
- PR_SetError(PR_PROTOCOL_NOT_SUPPORTED_ERROR, err);
- break;
- case EOPNOTSUPP:
- PR_SetError(PR_NOT_TCP_SOCKET_ERROR, err);
- break;
- case EPROTOTYPE:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
- default:
- _MD_os2_map_default_error(err);
- return;
- }
+ switch (err) {
+ case ENOMEM:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case EAFNOSUPPORT:
+ PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
+ break;
+ case EPROTONOSUPPORT:
+ PR_SetError(PR_PROTOCOL_NOT_SUPPORTED_ERROR, err);
+ break;
+ case EOPNOTSUPP:
+ PR_SetError(PR_NOT_TCP_SOCKET_ERROR, err);
+ break;
+ case EPROTOTYPE:
+ PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
+ break;
+ default:
+ _MD_os2_map_default_error(err);
+ return;
+ }
}
void _MD_os2_map_getsockname_error(PRInt32 err)
{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
+ switch (err) {
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case ENOBUFS:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case ENOBUFS:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_getpeername_error(PRInt32 err)
{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case ENOTCONN:
- PR_SetError(PR_NOT_CONNECTED_ERROR, err);
- break;
+ switch (err) {
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case ENOTCONN:
+ PR_SetError(PR_NOT_CONNECTED_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case ENOBUFS:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case ENOBUFS:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_getsockopt_error(PRInt32 err)
{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case ENOPROTOOPT:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
+ switch (err) {
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case ENOPROTOOPT:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case EINVAL:
- PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case EINVAL:
+ PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_setsockopt_error(PRInt32 err)
{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case ENOPROTOOPT:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
+ switch (err) {
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case ENOPROTOOPT:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case EINVAL:
- PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case EINVAL:
+ PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_open_error(PRInt32 err)
{
- switch (err) {
- case ERROR_ALREADY_EXISTS:
- case ERROR_FILE_EXISTS:
- PR_SetError(PR_FILE_EXISTS_ERROR, err);
- break;
- case ERROR_FILE_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_INVALID_NAME:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_OPEN_FAILED:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_FILENAME_EXCED_RANGE:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ERROR_TOO_MANY_OPEN_FILES:
- PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
- break;
- case ERROR_PATH_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ERROR_DISK_FULL:
- case ERROR_HANDLE_DISK_FULL:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
- case ERROR_WRITE_PROTECT:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_ALREADY_EXISTS:
+ case ERROR_FILE_EXISTS:
+ PR_SetError(PR_FILE_EXISTS_ERROR, err);
+ break;
+ case ERROR_FILE_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_INVALID_NAME:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_OPEN_FAILED:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_FILENAME_EXCED_RANGE:
+ PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
+ break;
+ case ERROR_TOO_MANY_OPEN_FILES:
+ PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
+ break;
+ case ERROR_PATH_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ERROR_DISK_FULL:
+ case ERROR_HANDLE_DISK_FULL:
+ PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
+ break;
+ case ERROR_WRITE_PROTECT:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_gethostname_error(PRInt32 err)
{
switch (err) {
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case ENETDOWN:
- case EINPROGRESS:
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
+ case ENETDOWN:
+ case EINPROGRESS:
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
}
}
@@ -1070,26 +1070,26 @@ void _MD_os2_map_select_error(PRInt32 err)
void _MD_os2_map_lockf_error(PRInt32 err)
{
switch (err) {
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- case ERROR_LOCKED:
- case ERROR_SHARING_VIOLATION:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ case ERROR_LOCKED:
+ case ERROR_SHARING_VIOLATION:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
}
}
diff --git a/nsprpub/pr/src/md/os2/os2cv.c b/nsprpub/pr/src/md/os2/os2cv.c
index 2c424c50b..91e85c0eb 100644
--- a/nsprpub/pr/src/md/os2/os2cv.c
+++ b/nsprpub/pr/src/md/os2/os2cv.c
@@ -16,7 +16,7 @@
* until right after we unlock the lock. This way the awakened threads
* have a better chance to reaquire the lock.
*/
-
+
#include "primpl.h"
/*
@@ -30,7 +30,7 @@ static void
AddThreadToCVWaitQueueInternal(PRThread *thred, struct _MDCVar *cv)
{
PR_ASSERT((cv->waitTail != NULL && cv->waitHead != NULL)
- || (cv->waitTail == NULL && cv->waitHead == NULL));
+ || (cv->waitTail == NULL && cv->waitHead == NULL));
cv->nwait += 1;
thred->md.inCVWaitQueue = PR_TRUE;
thred->md.next = NULL;
@@ -78,7 +78,7 @@ md_UnlockAndPostNotifies(
lock->notified.link = NULL;
#endif
- /*
+ /*
* Figure out how many threads we need to wake up.
*/
notified = &post; /* this is where we start */
@@ -87,7 +87,7 @@ md_UnlockAndPostNotifies(
_MDCVar *cv = notified->cv[index].cv;
PRThread *thred;
int i;
-
+
/* Fast special case: no waiting threads */
if (cv->waitHead == NULL) {
notified->cv[index].notifyHead = NULL;
@@ -155,7 +155,9 @@ md_UnlockAndPostNotifies(
}
prev = notified;
notified = notified->link;
- if (&post != prev) PR_DELETE(prev);
+ if (&post != prev) {
+ PR_DELETE(prev);
+ }
} while (NULL != notified);
}
@@ -165,7 +167,7 @@ md_UnlockAndPostNotifies(
* MP systems don't contend for a lock that they can't have.
*/
static void md_PostNotifyToCvar(_MDCVar *cvar, _MDLock *lock,
- PRBool broadcast)
+ PRBool broadcast)
{
PRIntn index = 0;
_MDNotified *notified = &lock->notified;
@@ -182,7 +184,9 @@ static void md_PostNotifyToCvar(_MDCVar *cvar, _MDLock *lock,
}
}
/* if not full, enter new CV in this array */
- if (notified->length < _MD_CV_NOTIFIED_LENGTH) break;
+ if (notified->length < _MD_CV_NOTIFIED_LENGTH) {
+ break;
+ }
/* if there's no link, create an empty array and link it */
if (NULL == notified->link) {
@@ -215,7 +219,7 @@ _PR_MD_NEW_CV(_MDCVar *cv)
* when the PRCondVar structure is created.
*/
return 0;
-}
+}
void _PR_MD_FREE_CV(_MDCVar *cv)
{
@@ -232,7 +236,7 @@ _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout )
PRThread *thred = _PR_MD_CURRENT_THREAD();
ULONG rv, count;
ULONG msecs = (timeout == PR_INTERVAL_NO_TIMEOUT) ?
- SEM_INDEFINITE_WAIT : PR_IntervalToMilliseconds(timeout);
+ SEM_INDEFINITE_WAIT : PR_IntervalToMilliseconds(timeout);
/*
* If we have pending notifies, post them now.
@@ -241,7 +245,7 @@ _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout )
md_UnlockAndPostNotifies(lock, thred, cv);
} else {
AddThreadToCVWaitQueueInternal(thred, cv);
- DosReleaseMutexSem(lock->mutex);
+ DosReleaseMutexSem(lock->mutex);
}
/* Wait for notification or timeout; don't really care which */
@@ -256,42 +260,42 @@ _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout )
if(rv == ERROR_TIMEOUT)
{
- if (thred->md.inCVWaitQueue) {
- PR_ASSERT((cv->waitTail != NULL && cv->waitHead != NULL)
- || (cv->waitTail == NULL && cv->waitHead == NULL));
- cv->nwait -= 1;
- thred->md.inCVWaitQueue = PR_FALSE;
- if (cv->waitHead == thred) {
- cv->waitHead = thred->md.next;
- if (cv->waitHead == NULL) {
- cv->waitTail = NULL;
- } else {
- cv->waitHead->md.prev = NULL;
- }
- } else {
- PR_ASSERT(thred->md.prev != NULL);
- thred->md.prev->md.next = thred->md.next;
- if (thred->md.next != NULL) {
- thred->md.next->md.prev = thred->md.prev;
- } else {
- PR_ASSERT(cv->waitTail == thred);
- cv->waitTail = thred->md.prev;
- }
- }
- thred->md.next = thred->md.prev = NULL;
- } else {
- /*
- * This thread must have been notified, but the
- * SemRelease call happens after SemRequest
- * times out. Wait on the semaphore again to make it
- * non-signaled. We assume this wait won't take long.
- */
- rv = DosWaitEventSem(thred->md.blocked_sema, SEM_INDEFINITE_WAIT);
- if (rv == NO_ERROR) {
- DosResetEventSem(thred->md.blocked_sema, &count);
- }
- PR_ASSERT(rv == NO_ERROR);
- }
+ if (thred->md.inCVWaitQueue) {
+ PR_ASSERT((cv->waitTail != NULL && cv->waitHead != NULL)
+ || (cv->waitTail == NULL && cv->waitHead == NULL));
+ cv->nwait -= 1;
+ thred->md.inCVWaitQueue = PR_FALSE;
+ if (cv->waitHead == thred) {
+ cv->waitHead = thred->md.next;
+ if (cv->waitHead == NULL) {
+ cv->waitTail = NULL;
+ } else {
+ cv->waitHead->md.prev = NULL;
+ }
+ } else {
+ PR_ASSERT(thred->md.prev != NULL);
+ thred->md.prev->md.next = thred->md.next;
+ if (thred->md.next != NULL) {
+ thred->md.next->md.prev = thred->md.prev;
+ } else {
+ PR_ASSERT(cv->waitTail == thred);
+ cv->waitTail = thred->md.prev;
+ }
+ }
+ thred->md.next = thred->md.prev = NULL;
+ } else {
+ /*
+ * This thread must have been notified, but the
+ * SemRelease call happens after SemRequest
+ * times out. Wait on the semaphore again to make it
+ * non-signaled. We assume this wait won't take long.
+ */
+ rv = DosWaitEventSem(thred->md.blocked_sema, SEM_INDEFINITE_WAIT);
+ if (rv == NO_ERROR) {
+ DosResetEventSem(thred->md.blocked_sema, &count);
+ }
+ PR_ASSERT(rv == NO_ERROR);
+ }
}
PR_ASSERT(thred->md.inCVWaitQueue == PR_FALSE);
return;
diff --git a/nsprpub/pr/src/md/os2/os2gc.c b/nsprpub/pr/src/md/os2/os2gc.c
index 2bcbf7852..79b6de573 100644
--- a/nsprpub/pr/src/md/os2/os2gc.c
+++ b/nsprpub/pr/src/md/os2/os2gc.c
@@ -9,7 +9,7 @@
*/
#include "primpl.h"
-PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
+PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
CONTEXTRECORD context;
context.ContextFlags = CONTEXT_INTEGER;
@@ -34,7 +34,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
}
/* This function is not used right now, but is left as a reference.
- * If you ever need to get the fiberID from the currently running fiber,
+ * If you ever need to get the fiberID from the currently running fiber,
* this is it.
*/
void *
@@ -43,8 +43,8 @@ GetMyFiberID()
void *fiberData = 0;
/* A pointer to our tib entry is found at FS:[18]
- * At offset 10h is the fiberData pointer. The context of the
- * fiber is stored in there.
+ * At offset 10h is the fiberData pointer. The context of the
+ * fiber is stored in there.
*/
#ifdef HAVE_ASM
__asm {
@@ -53,6 +53,6 @@ GetMyFiberID()
mov [fiberData], EAX
}
#endif
-
+
return fiberData;
}
diff --git a/nsprpub/pr/src/md/os2/os2inrval.c b/nsprpub/pr/src/md/os2/os2inrval.c
index aff99e2ec..bd283f06d 100644
--- a/nsprpub/pr/src/md/os2/os2inrval.c
+++ b/nsprpub/pr/src/md/os2/os2inrval.c
@@ -14,7 +14,7 @@ static PRBool useHighResTimer = PR_FALSE;
PRIntervalTime _os2_ticksPerSec = -1;
PRIntn _os2_bitShift = 0;
PRInt32 _os2_highMask = 0;
-
+
void
_PR_MD_INTERVAL_INIT()
{
@@ -23,8 +23,9 @@ _PR_MD_INTERVAL_INIT()
APIRET rc;
if ((envp = getenv("NSPR_OS2_NO_HIRES_TIMER")) != NULL) {
- if (atoi(envp) == 1)
- return;
+ if (atoi(envp) == 1) {
+ return;
+ }
}
timerFreq = 0; /* OS/2 high-resolution timer frequency in Hz */
@@ -59,8 +60,8 @@ _PR_MD_GET_INTERVAL()
*/
top = timestamp.ulHi & _os2_highMask;
top = top << (32 - _os2_bitShift);
- timestamp.ulLo = timestamp.ulLo >> _os2_bitShift;
- timestamp.ulLo = timestamp.ulLo + top;
+ timestamp.ulLo = timestamp.ulLo >> _os2_bitShift;
+ timestamp.ulLo = timestamp.ulLo + top;
return (PRUint32)timestamp.ulLo;
} else {
ULONG msCount = -1;
diff --git a/nsprpub/pr/src/md/os2/os2io.c b/nsprpub/pr/src/md/os2/os2io.c
index 3c81ae346..639a0d388 100644
--- a/nsprpub/pr/src/md/os2/os2io.c
+++ b/nsprpub/pr/src/md/os2/os2io.c
@@ -23,16 +23,16 @@ struct _MDLock _pr_ioq_lock;
static PRBool isWSEB = PR_FALSE; /* whether we are using an OS/2 kernel that supports large files */
typedef APIRET (*DosOpenLType)(PSZ pszFileName, PHFILE pHf, PULONG pulAction,
- LONGLONG cbFile, ULONG ulAttribute,
- ULONG fsOpenFlags, ULONG fsOpenMode,
- PEAOP2 peaop2);
+ LONGLONG cbFile, ULONG ulAttribute,
+ ULONG fsOpenFlags, ULONG fsOpenMode,
+ PEAOP2 peaop2);
typedef APIRET (*DosSetFileLocksLType)(HFILE hFile, PFILELOCKL pflUnlock,
- PFILELOCKL pflLock, ULONG timeout,
- ULONG flags);
+ PFILELOCKL pflLock, ULONG timeout,
+ ULONG flags);
typedef APIRET (*DosSetFilePtrLType)(HFILE hFile, LONGLONG ib, ULONG method,
- PLONGLONG ibActual);
+ PLONGLONG ibActual);
DosOpenLType myDosOpenL;
DosSetFileLocksLType myDosSetFileLocksL;
@@ -45,7 +45,7 @@ _PR_MD_INIT_IO()
HMODULE module;
sock_init();
-
+
rc = DosLoadModule(NULL, 0, "DOSCALL1", &module);
if (rc != NO_ERROR)
{
@@ -76,10 +76,10 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
ULONG count;
PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
- SEM_INDEFINITE_WAIT : PR_IntervalToMilliseconds(ticks);
+ SEM_INDEFINITE_WAIT : PR_IntervalToMilliseconds(ticks);
rv = DosWaitEventSem(thread->md.blocked_sema, msecs);
- DosResetEventSem(thread->md.blocked_sema, &count);
- switch(rv)
+ DosResetEventSem(thread->md.blocked_sema, &count);
+ switch(rv)
{
case NO_ERROR:
return PR_SUCCESS;
@@ -87,7 +87,7 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
case ERROR_TIMEOUT:
_PR_THREAD_LOCK(thread);
if (thread->state == _PR_IO_WAIT) {
- ;
+ ;
} else {
if (thread->wait.cvar != NULL) {
thread->wait.cvar = NULL;
@@ -99,7 +99,7 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
*/
_PR_THREAD_UNLOCK(thread);
rv = DosWaitEventSem(thread->md.blocked_sema, 0);
- DosResetEventSem(thread->md.blocked_sema, &count);
+ DosResetEventSem(thread->md.blocked_sema, &count);
PR_ASSERT(rv == NO_ERROR);
}
}
@@ -113,13 +113,15 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
PRStatus
_PR_MD_WAKEUP_WAITER(PRThread *thread)
{
- if ( _PR_IS_NATIVE_THREAD(thread) )
+ if ( _PR_IS_NATIVE_THREAD(thread) )
{
- if (DosPostEventSem(thread->md.blocked_sema) != NO_ERROR)
+ if (DosPostEventSem(thread->md.blocked_sema) != NO_ERROR) {
return PR_FAILURE;
- else
- return PR_SUCCESS;
- }
+ }
+ else {
+ return PR_SUCCESS;
+ }
+ }
}
@@ -132,7 +134,7 @@ _PR_MD_WAKEUP_WAITER(PRThread *thread)
* The NSPR open flags (osflags) are translated into flags for OS/2
*
* Mode seems to be passed in as a unix style file permissions argument
- * as in 0666, in the case of opening the logFile.
+ * as in 0666, in the case of opening the logFile.
*
*/
PRInt32
@@ -149,7 +151,7 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
* All the pointer arguments (&file, &actionTaken and name) have to be in
* low memory for DosOpen to use them.
* The following moves name to low memory.
- */
+ */
if ((ULONG)name >= 0x20000000)
{
size_t len = strlen(name) + 1;
@@ -159,14 +161,19 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
}
#endif
- if (osflags & PR_SYNC) access |= OPEN_FLAGS_WRITE_THROUGH;
+ if (osflags & PR_SYNC) {
+ access |= OPEN_FLAGS_WRITE_THROUGH;
+ }
- if (osflags & PR_RDONLY)
+ if (osflags & PR_RDONLY) {
access |= OPEN_ACCESS_READONLY;
- else if (osflags & PR_WRONLY)
+ }
+ else if (osflags & PR_WRONLY) {
access |= OPEN_ACCESS_WRITEONLY;
- else if(osflags & PR_RDWR)
+ }
+ else if(osflags & PR_RDWR) {
access |= OPEN_ACCESS_READWRITE;
+ }
if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
{
@@ -174,41 +181,45 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
}
else if (osflags & PR_CREATE_FILE)
{
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS;
- else
+ }
+ else {
flags = OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;
- }
+ }
+ }
else
{
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS;
- else
+ }
+ else {
flags = OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;
+ }
}
do {
if (isWSEB)
{
- rc = myDosOpenL((char*)name,
- &file, /* file handle if successful */
- &actionTaken, /* reason for failure */
- 0, /* initial size of new file */
- FILE_NORMAL, /* file system attributes */
- flags, /* Open flags */
- access, /* Open mode and rights */
- 0); /* OS/2 Extended Attributes */
+ rc = myDosOpenL((char*)name,
+ &file, /* file handle if successful */
+ &actionTaken, /* reason for failure */
+ 0, /* initial size of new file */
+ FILE_NORMAL, /* file system attributes */
+ flags, /* Open flags */
+ access, /* Open mode and rights */
+ 0); /* OS/2 Extended Attributes */
}
else
{
- rc = DosOpen((char*)name,
- &file, /* file handle if successful */
- &actionTaken, /* reason for failure */
- 0, /* initial size of new file */
- FILE_NORMAL, /* file system attributes */
- flags, /* Open flags */
- access, /* Open mode and rights */
- 0); /* OS/2 Extended Attributes */
+ rc = DosOpen((char*)name,
+ &file, /* file handle if successful */
+ &actionTaken, /* reason for failure */
+ 0, /* initial size of new file */
+ FILE_NORMAL, /* file system attributes */
+ flags, /* Open flags */
+ access, /* Open mode and rights */
+ 0); /* OS/2 Extended Attributes */
};
if (rc == ERROR_TOO_MANY_OPEN_FILES) {
ULONG CurMaxFH = 0;
@@ -223,7 +234,7 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
if (rc != NO_ERROR) {
_PR_MD_MAP_OPEN_ERROR(rc);
- return -1;
+ return -1;
}
return (PRInt32)file;
@@ -239,17 +250,18 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
(PVOID)buf,
len,
&bytes);
-
- if (rv != NO_ERROR)
+
+ if (rv != NO_ERROR)
{
/* ERROR_HANDLE_EOF can only be returned by async io */
PR_ASSERT(rv != ERROR_HANDLE_EOF);
- if (rv == ERROR_BROKEN_PIPE)
+ if (rv == ERROR_BROKEN_PIPE) {
return 0;
- else {
- _PR_MD_MAP_READ_ERROR(rv);
- return -1;
- }
+ }
+ else {
+ _PR_MD_MAP_READ_ERROR(rv);
+ return -1;
+ }
}
return (PRInt32)bytes;
}
@@ -258,14 +270,14 @@ PRInt32
_PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
{
PRInt32 bytes;
- int rv;
+ int rv;
rv = DosWrite((HFILE)fd->secret->md.osfd,
(PVOID)buf,
len,
(PULONG)&bytes);
- if (rv != NO_ERROR)
+ if (rv != NO_ERROR)
{
_PR_MD_MAP_WRITE_ERROR(rv);
return -1;
@@ -288,11 +300,12 @@ _PR_MD_LSEEK(PRFileDesc *fd, PRInt32 offset, PRSeekWhence whence)
rv = DosSetFilePtr((HFILE)fd->secret->md.osfd, offset, whence, &newLocation);
- if (rv != NO_ERROR) {
- _PR_MD_MAP_LSEEK_ERROR(rv);
- return -1;
- } else
- return newLocation;
+ if (rv != NO_ERROR) {
+ _PR_MD_MAP_LSEEK_ERROR(rv);
+ return -1;
+ } else {
+ return newLocation;
+ }
}
PRInt64
@@ -306,14 +319,14 @@ _PR_MD_LSEEK64(PRFileDesc *fd, PRInt64 offset, PRSeekWhence whence)
rv = DosSetFilePtr((HFILE)fd->secret->md.osfd, low, whence, &newLocation);
rv = DosSetFilePtr((HFILE)fd->secret->md.osfd, hi, FILE_CURRENT, &newLocation);
- if (rv != NO_ERROR) {
- _PR_MD_MAP_LSEEK_ERROR(rv);
- hi = newLocation = -1;
- }
+ if (rv != NO_ERROR) {
+ _PR_MD_MAP_LSEEK_ERROR(rv);
+ hi = newLocation = -1;
+ }
result.lo = newLocation;
result.hi = hi;
- return result;
+ return result;
#else
PRInt32 where, rc, lo = (PRInt32)offset, hi = (PRInt32)(offset >> 32);
@@ -322,19 +335,19 @@ _PR_MD_LSEEK64(PRFileDesc *fd, PRInt64 offset, PRSeekWhence whence)
PRUint64 newLocationL;
switch (whence)
- {
- case PR_SEEK_SET:
- where = FILE_BEGIN;
- break;
- case PR_SEEK_CUR:
- where = FILE_CURRENT;
- break;
- case PR_SEEK_END:
- where = FILE_END;
- break;
- default:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return -1;
+ {
+ case PR_SEEK_SET:
+ where = FILE_BEGIN;
+ break;
+ case PR_SEEK_CUR:
+ where = FILE_CURRENT;
+ break;
+ case PR_SEEK_END:
+ where = FILE_END;
+ break;
+ default:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return -1;
}
if (isWSEB)
{
@@ -344,12 +357,12 @@ _PR_MD_LSEEK64(PRFileDesc *fd, PRInt64 offset, PRSeekWhence whence)
{
rc = DosSetFilePtr((HFILE)fd->secret->md.osfd, lo, where, (PULONG)&newLocation);
}
-
+
if (rc != NO_ERROR) {
- _PR_MD_MAP_LSEEK_ERROR(rc);
- return -1;
+ _PR_MD_MAP_LSEEK_ERROR(rc);
+ return -1;
}
-
+
if (isWSEB)
{
return newLocationL;
@@ -373,10 +386,10 @@ _PR_MD_FSYNC(PRFileDesc *fd)
PRInt32 rc = DosResetBuffer((HFILE)fd->secret->md.osfd);
if (rc != NO_ERROR) {
- if (rc != ERROR_ACCESS_DENIED) {
- _PR_MD_MAP_FSYNC_ERROR(rc);
- return -1;
- }
+ if (rc != ERROR_ACCESS_DENIED) {
+ _PR_MD_MAP_FSYNC_ERROR(rc);
+ return -1;
+ }
}
return 0;
}
@@ -385,10 +398,11 @@ PRInt32
_MD_CloseFile(PRInt32 osfd)
{
PRInt32 rv;
-
+
rv = DosClose((HFILE)osfd);
- if (rv != NO_ERROR)
- _PR_MD_MAP_CLOSE_ERROR(rv);
+ if (rv != NO_ERROR) {
+ _PR_MD_MAP_CLOSE_ERROR(rv);
+ }
return rv;
}
@@ -400,10 +414,10 @@ _MD_CloseFile(PRInt32 osfd)
void FlipSlashes(char *cp, int len)
{
while (--len >= 0) {
- if (cp[0] == '/') {
- cp[0] = PR_DIRECTORY_SEPARATOR;
- }
- cp++;
+ if (cp[0] == '/') {
+ cp[0] = PR_DIRECTORY_SEPARATOR;
+ }
+ cp++;
}
}
@@ -417,17 +431,17 @@ void FlipSlashes(char *cp, int len)
PRInt32
_PR_MD_CLOSE_DIR(_MDDir *d)
{
- PRInt32 rc;
+ PRInt32 rc;
if ( d ) {
- rc = DosFindClose(d->d_hdl);
- if(rc == NO_ERROR){
- d->magic = (PRUint32)-1;
- return PR_SUCCESS;
- } else {
- _PR_MD_MAP_CLOSEDIR_ERROR(rc);
- return PR_FAILURE;
- }
+ rc = DosFindClose(d->d_hdl);
+ if(rc == NO_ERROR) {
+ d->magic = (PRUint32)-1;
+ return PR_SUCCESS;
+ } else {
+ _PR_MD_MAP_CLOSEDIR_ERROR(rc);
+ return PR_FAILURE;
+ }
}
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return PR_FAILURE;
@@ -469,7 +483,7 @@ _PR_MD_OPEN_DIR(_MDDir *d, const char *name)
FIL_STANDARD);
}
if ( rc != NO_ERROR ) {
- _PR_MD_MAP_OPENDIR_ERROR(rc);
+ _PR_MD_MAP_OPENDIR_ERROR(rc);
return PR_FAILURE;
}
d->firstEntry = PR_TRUE;
@@ -486,42 +500,46 @@ _PR_MD_READ_DIR(_MDDir *d, PRIntn flags)
USHORT fileAttr;
if ( d ) {
- while (1) {
- if (d->firstEntry) {
- d->firstEntry = PR_FALSE;
- rv = NO_ERROR;
- } else {
- rv = DosFindNext(d->d_hdl,
- &(d->d_entry),
- sizeof(d->d_entry),
- &numFiles);
- }
- if (rv != NO_ERROR) {
- break;
- }
- fileName = GetFileFromDIR(d);
- fileAttr = GetFileAttr(d);
- if ( (flags & PR_SKIP_DOT) &&
- (fileName[0] == '.') && (fileName[1] == '\0'))
+ while (1) {
+ if (d->firstEntry) {
+ d->firstEntry = PR_FALSE;
+ rv = NO_ERROR;
+ } else {
+ rv = DosFindNext(d->d_hdl,
+ &(d->d_entry),
+ sizeof(d->d_entry),
+ &numFiles);
+ }
+ if (rv != NO_ERROR) {
+ break;
+ }
+ fileName = GetFileFromDIR(d);
+ fileAttr = GetFileAttr(d);
+ if ( (flags & PR_SKIP_DOT) &&
+ (fileName[0] == '.') && (fileName[1] == '\0')) {
continue;
- if ( (flags & PR_SKIP_DOT_DOT) &&
- (fileName[0] == '.') && (fileName[1] == '.') &&
- (fileName[2] == '\0'))
+ }
+ if ( (flags & PR_SKIP_DOT_DOT) &&
+ (fileName[0] == '.') && (fileName[1] == '.') &&
+ (fileName[2] == '\0')) {
continue;
- /*
- * XXX
- * Is this the correct definition of a hidden file on OS/2?
- */
- if ((flags & PR_SKIP_NONE) && (fileAttr & FILE_HIDDEN))
+ }
+ /*
+ * XXX
+ * Is this the correct definition of a hidden file on OS/2?
+ */
+ if ((flags & PR_SKIP_NONE) && (fileAttr & FILE_HIDDEN)) {
return fileName;
- else if ((flags & PR_SKIP_HIDDEN) && (fileAttr & FILE_HIDDEN))
+ }
+ else if ((flags & PR_SKIP_HIDDEN) && (fileAttr & FILE_HIDDEN)) {
continue;
- return fileName;
+ }
+ return fileName;
}
PR_ASSERT(NO_ERROR != rv);
- _PR_MD_MAP_READDIR_ERROR(rv);
+ _PR_MD_MAP_READDIR_ERROR(rv);
return NULL;
- }
+ }
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return NULL;
}
@@ -533,7 +551,7 @@ _PR_MD_DELETE(const char *name)
if(rc == NO_ERROR) {
return 0;
} else {
- _PR_MD_MAP_DELETE_ERROR(rc);
+ _PR_MD_MAP_DELETE_ERROR(rc);
return -1;
}
}
@@ -558,7 +576,7 @@ _PR_MD_STAT(const char *fn, struct stat *info)
* can be handled by _stat() on NT but not on Win95.
*
* We remove the backslash or slash at the end and
- * try again.
+ * try again.
*
* Not sure if this happens on OS/2 or not,
* but it doesn't hurt to be careful.
@@ -566,7 +584,7 @@ _PR_MD_STAT(const char *fn, struct stat *info)
int len = strlen(fn);
if (len > 0 && len <= _MAX_PATH
- && (fn[len - 1] == '\\' || fn[len - 1] == '/')) {
+ && (fn[len - 1] == '\\' || fn[len - 1] == '/')) {
char newfn[_MAX_PATH + 1];
strcpy(newfn, fn);
@@ -587,15 +605,18 @@ _PR_MD_GETFILEINFO(const char *fn, PRFileInfo *info)
struct stat sb;
PRInt32 rv;
PRInt64 s, s2us;
-
+
if ( (rv = _PR_MD_STAT(fn, &sb)) == 0 ) {
if (info) {
- if (S_IFREG & sb.st_mode)
+ if (S_IFREG & sb.st_mode) {
info->type = PR_FILE_FILE ;
- else if (S_IFDIR & sb.st_mode)
+ }
+ else if (S_IFDIR & sb.st_mode) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_OTHER;
+ }
info->size = sb.st_size;
LL_I2L(s2us, PR_USEC_PER_SEC);
LL_I2L(s, sb.st_mtime);
@@ -622,7 +643,7 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
LL_UI2L(info->size,info32.size);
info->modifyTime = info32.modifyTime;
info->creationTime = info32.creationTime;
-
+
if (isWSEB)
{
APIRET rc ;
@@ -648,33 +669,35 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
PRInt32
_PR_MD_GETOPENFILEINFO(const PRFileDesc *fd, PRFileInfo *info)
{
- /* For once, the VAC compiler/library did a nice thing.
- * The file handle used by the C runtime is the same one
- * returned by the OS when you call DosOpen(). This means
- * that you can take an OS HFILE and use it with C file
- * functions. The only caveat is that you have to call
- * _setmode() first to initialize some junk. This is
- * immensely useful because I did not have a clue how to
- * implement this function otherwise. The windows folks
- * took the source from the Microsoft C library source, but
- * IBM wasn't kind enough to ship the source with VAC.
- * On second thought, the needed function could probably
- * be gotten from the OS/2 GNU library source, but the
- * point is now moot.
- */
- struct stat hinfo;
+ /* For once, the VAC compiler/library did a nice thing.
+ * The file handle used by the C runtime is the same one
+ * returned by the OS when you call DosOpen(). This means
+ * that you can take an OS HFILE and use it with C file
+ * functions. The only caveat is that you have to call
+ * _setmode() first to initialize some junk. This is
+ * immensely useful because I did not have a clue how to
+ * implement this function otherwise. The windows folks
+ * took the source from the Microsoft C library source, but
+ * IBM wasn't kind enough to ship the source with VAC.
+ * On second thought, the needed function could probably
+ * be gotten from the OS/2 GNU library source, but the
+ * point is now moot.
+ */
+ struct stat hinfo;
PRInt64 s, s2us;
_setmode(fd->secret->md.osfd, O_BINARY);
if(fstat((int)fd->secret->md.osfd, &hinfo) != NO_ERROR) {
- _PR_MD_MAP_FSTAT_ERROR(errno);
+ _PR_MD_MAP_FSTAT_ERROR(errno);
return -1;
- }
+ }
- if (hinfo.st_mode & S_IFDIR)
+ if (hinfo.st_mode & S_IFDIR) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_FILE;
+ }
info->size = hinfo.st_size;
LL_I2L(s2us, PR_USEC_PER_SEC);
@@ -695,13 +718,13 @@ _PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info)
PRInt32 rv = _PR_MD_GETOPENFILEINFO(fd, &info32);
if (0 == rv)
{
- info->type = info32.type;
- LL_UI2L(info->size,info32.size);
-
- info->modifyTime = info32.modifyTime;
- info->creationTime = info32.creationTime;
+ info->type = info32.type;
+ LL_UI2L(info->size,info32.size);
+
+ info->modifyTime = info32.modifyTime;
+ info->creationTime = info32.creationTime;
}
-
+
if (isWSEB)
{
APIRET rc ;
@@ -728,12 +751,12 @@ _PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info)
PRInt32
_PR_MD_RENAME(const char *from, const char *to)
{
- PRInt32 rc;
+ PRInt32 rc;
/* Does this work with dot-relative pathnames? */
if ( (rc = DosMove((char *)from, (char *)to)) == NO_ERROR) {
return 0;
} else {
- _PR_MD_MAP_RENAME_ERROR(rc);
+ _PR_MD_MAP_RENAME_ERROR(rc);
return -1;
}
}
@@ -741,35 +764,36 @@ _PR_MD_RENAME(const char *from, const char *to)
PRInt32
_PR_MD_ACCESS(const char *name, PRAccessHow how)
{
- PRInt32 rv;
+ PRInt32 rv;
switch (how) {
- case PR_ACCESS_WRITE_OK:
- rv = access(name, 02);
- break;
- case PR_ACCESS_READ_OK:
- rv = access(name, 04);
- break;
- case PR_ACCESS_EXISTS:
- return access(name, 00);
- break;
- default:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return -1;
- }
- if (rv < 0)
- _PR_MD_MAP_ACCESS_ERROR(errno);
+ case PR_ACCESS_WRITE_OK:
+ rv = access(name, 02);
+ break;
+ case PR_ACCESS_READ_OK:
+ rv = access(name, 04);
+ break;
+ case PR_ACCESS_EXISTS:
+ return access(name, 00);
+ break;
+ default:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return -1;
+ }
+ if (rv < 0) {
+ _PR_MD_MAP_ACCESS_ERROR(errno);
+ }
return rv;
}
PRInt32
_PR_MD_MKDIR(const char *name, PRIntn mode)
{
- PRInt32 rc;
+ PRInt32 rc;
/* XXXMB - how to translate the "mode"??? */
if ((rc = DosCreateDir((char *)name, NULL))== NO_ERROR) {
return 0;
} else {
- _PR_MD_MAP_MKDIR_ERROR(rc);
+ _PR_MD_MAP_MKDIR_ERROR(rc);
return -1;
}
}
@@ -777,11 +801,11 @@ _PR_MD_MKDIR(const char *name, PRIntn mode)
PRInt32
_PR_MD_RMDIR(const char *name)
{
- PRInt32 rc;
+ PRInt32 rc;
if ( (rc = DosDeleteDir((char *)name)) == NO_ERROR) {
return 0;
} else {
- _PR_MD_MAP_RMDIR_ERROR(rc);
+ _PR_MD_MAP_RMDIR_ERROR(rc);
return -1;
}
}
@@ -792,7 +816,7 @@ _PR_MD_LOCKFILE(PRInt32 f)
PRInt32 rv;
FILELOCK lock, unlock;
FILELOCKL lockL, unlockL;
-
+
lock.lOffset = 0;
lockL.lOffset = 0;
lock.lRange = 0xffffffff;
@@ -811,20 +835,20 @@ _PR_MD_LOCKFILE(PRInt32 f)
{
if (isWSEB)
{
- rv = myDosSetFileLocksL( (HFILE) f,
- &unlockL, &lockL,
- 0, 0);
+ rv = myDosSetFileLocksL( (HFILE) f,
+ &unlockL, &lockL,
+ 0, 0);
}
else
{
- rv = DosSetFileLocks( (HFILE) f,
- &unlock, &lock,
- 0, 0);
+ rv = DosSetFileLocks( (HFILE) f,
+ &unlock, &lock,
+ 0, 0);
}
- if ( rv != NO_ERROR )
+ if ( rv != NO_ERROR )
{
DosSleep( 50 ); /* Sleep() a few milisecs and try again. */
- }
+ }
} /* end for() */
return PR_SUCCESS;
} /* end _PR_MD_LOCKFILE() */
@@ -842,7 +866,7 @@ _PR_MD_UNLOCKFILE(PRInt32 f)
PRInt32 rv;
FILELOCK lock, unlock;
FILELOCKL lockL, unlockL;
-
+
lock.lOffset = 0;
lockL.lOffset = 0;
lock.lRange = 0;
@@ -851,20 +875,20 @@ _PR_MD_UNLOCKFILE(PRInt32 f)
unlockL.lOffset = 0;
unlock.lRange = 0xffffffff;
unlockL.lRange = 0xffffffffffffffff;
-
+
if (isWSEB)
{
rv = myDosSetFileLocksL( (HFILE) f,
- &unlockL, &lockL,
- 0, 0);
+ &unlockL, &lockL,
+ 0, 0);
}
else
{
rv = DosSetFileLocks( (HFILE) f,
- &unlock, &lock,
- 0, 0);
+ &unlock, &lock,
+ 0, 0);
}
-
+
if ( rv != NO_ERROR )
{
return PR_SUCCESS;
@@ -890,10 +914,12 @@ _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable)
return PR_FAILURE;
}
- if (inheritable)
- flags &= ~OPEN_FLAGS_NOINHERIT;
- else
- flags |= OPEN_FLAGS_NOINHERIT;
+ if (inheritable) {
+ flags &= ~OPEN_FLAGS_NOINHERIT;
+ }
+ else {
+ flags |= OPEN_FLAGS_NOINHERIT;
+ }
/* Mask off flags DosSetFHState don't want. */
flags &= (OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_CACHE | OPEN_FLAGS_NOINHERIT);
diff --git a/nsprpub/pr/src/md/os2/os2misc.c b/nsprpub/pr/src/md/os2/os2misc.c
index f0e3ceeaf..240f0905c 100644
--- a/nsprpub/pr/src/md/os2/os2misc.c
+++ b/nsprpub/pr/src/md/os2/os2misc.c
@@ -73,7 +73,7 @@ PR_Now(void)
LL_MUL(ms, ms, ms2us);
LL_MUL(s, s, s2us);
LL_ADD(s, s, ms);
- return s;
+ return s;
}
@@ -120,7 +120,7 @@ static int assembleCmdLine(char *const *argv, char **cmdLine)
strcat(*cmdLine, " ");
}
strcat(*cmdLine, *arg);
- }
+ }
return 0;
}
@@ -150,15 +150,16 @@ static int assembleEnvBlock(char **envp, char **envBlock)
return 0;
}
- if(DosGetInfoBlocks(&ptib, &ppib) != NO_ERROR)
- return -1;
+ if(DosGetInfoBlocks(&ptib, &ppib) != NO_ERROR) {
+ return -1;
+ }
curEnv = ppib->pib_pchenv;
cwdStart = curEnv;
while (*cwdStart) {
if (cwdStart[0] == '=' && cwdStart[1] != '\0'
- && cwdStart[2] == ':' && cwdStart[3] == '=') {
+ && cwdStart[2] == ':' && cwdStart[3] == '=') {
break;
}
cwdStart += strlen(cwdStart) + 1;
@@ -168,7 +169,7 @@ static int assembleEnvBlock(char **envp, char **envBlock)
cwdEnd += strlen(cwdEnd) + 1;
while (*cwdEnd) {
if (cwdEnd[0] != '=' || cwdEnd[1] == '\0'
- || cwdEnd[2] != ':' || cwdEnd[3] != '=') {
+ || cwdEnd[2] != ':' || cwdEnd[3] != '=') {
break;
}
cwdEnd += strlen(cwdEnd) + 1;
@@ -221,7 +222,7 @@ PRProcess * _PR_CreateOS2Process(
char *cmdLine = NULL;
char **newEnvp = NULL;
char *envBlock = NULL;
-
+
STARTDATA startData = {0};
APIRET rc;
ULONG ulAppType = 0;
@@ -250,7 +251,7 @@ PRProcess * _PR_CreateOS2Process(
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
goto errorExit;
}
-
+
if (assembleCmdLine(argv, &cmdLine) == -1) {
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
goto errorExit;
@@ -260,7 +261,7 @@ PRProcess * _PR_CreateOS2Process(
/*
* DosQueryAppType() fails if path (the char* in the first argument) is in
* high memory. If that is the case, the following moves it to low memory.
- */
+ */
if ((ULONG)path >= 0x20000000) {
size_t len = strlen(path) + 1;
char *copy = (char *)alloca(len);
@@ -268,7 +269,7 @@ PRProcess * _PR_CreateOS2Process(
path = copy;
}
#endif
-
+
if (envp == NULL) {
newEnvp = NULL;
} else {
@@ -287,27 +288,27 @@ PRProcess * _PR_CreateOS2Process(
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
goto errorExit;
}
-
+
rc = DosQueryAppType(path, &ulAppType);
if (rc != NO_ERROR) {
- char *pszDot = strrchr(path, '.');
- if (pszDot) {
- /* If it is a CMD file, launch the users command processor */
- if (!stricmp(pszDot, ".cmd")) {
- rc = DosScanEnv("COMSPEC", (PSZ *)&pszComSpec);
- if (!rc) {
- strcpy(pszFormatString, "/C %s %s");
- strcpy(pszEXEName, pszComSpec);
- ulAppType = FAPPTYP_WINDOWCOMPAT;
- }
- }
- }
+ char *pszDot = strrchr(path, '.');
+ if (pszDot) {
+ /* If it is a CMD file, launch the users command processor */
+ if (!stricmp(pszDot, ".cmd")) {
+ rc = DosScanEnv("COMSPEC", (PSZ *)&pszComSpec);
+ if (!rc) {
+ strcpy(pszFormatString, "/C %s %s");
+ strcpy(pszEXEName, pszComSpec);
+ ulAppType = FAPPTYP_WINDOWCOMPAT;
+ }
+ }
+ }
}
if (ulAppType == 0) {
- PR_SetError(PR_UNKNOWN_ERROR, 0);
- goto errorExit;
+ PR_SetError(PR_UNKNOWN_ERROR, 0);
+ goto errorExit;
}
-
+
if ((ulAppType & FAPPTYP_WINDOWAPI) == FAPPTYP_WINDOWAPI) {
startData.SessionType = SSF_TYPE_PM;
}
@@ -317,16 +318,16 @@ PRProcess * _PR_CreateOS2Process(
else {
startData.SessionType = SSF_TYPE_DEFAULT;
}
-
+
if (ulAppType & (FAPPTYP_WINDOWSPROT31 | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSREAL))
{
strcpy(pszEXEName, "WINOS2.COM");
startData.SessionType = PROG_31_STDSEAMLESSVDM;
strcpy(pszFormatString, "/3 %s %s");
}
-
+
startData.InheritOpt = SSF_INHERTOPT_SHELL;
-
+
if (pszEXEName[0]) {
pszFormatResult = PR_MALLOC(strlen(pszFormatString)+strlen(path)+strlen(cmdLine));
sprintf(pszFormatResult, pszFormatString, path, cmdLine);
@@ -336,13 +337,13 @@ PRProcess * _PR_CreateOS2Process(
startData.PgmInputs = cmdLine;
}
startData.PgmName = pszEXEName;
-
+
startData.Length = sizeof(startData);
startData.Related = SSF_RELATED_INDEPENDENT;
startData.ObjectBuffer = pszObjectBuffer;
startData.ObjectBuffLen = CCHMAXPATH;
startData.Environment = envBlock;
-
+
if (attr) {
/* On OS/2, there is really no way to pass file handles for stdin,
* stdout, and stderr to a new process. Instead, we can make it
@@ -407,7 +408,7 @@ PRProcess * _PR_CreateOS2Process(
}
proc->md.pid = procInfo.codeTerminate;
- } else {
+ } else {
/*
* If no STDIN/STDOUT redirection is not needed, use DosStartSession
* to create a new, independent session
@@ -418,7 +419,7 @@ PRProcess * _PR_CreateOS2Process(
PR_SetError(PR_UNKNOWN_ERROR, rc);
goto errorExit;
}
-
+
proc->md.pid = pid;
}
@@ -453,7 +454,7 @@ errorExit:
PRStatus _PR_DetachOS2Process(PRProcess *process)
{
- /* On OS/2, a process is either created as a child or not.
+ /* On OS/2, a process is either created as a child or not.
* You can't 'detach' it later on.
*/
PR_DELETE(process);
@@ -464,18 +465,18 @@ PRStatus _PR_DetachOS2Process(PRProcess *process)
* XXX: This will currently only work on a child process.
*/
PRStatus _PR_WaitOS2Process(PRProcess *process,
- PRInt32 *exitCode)
+ PRInt32 *exitCode)
{
ULONG ulRetVal;
RESULTCODES results;
PID pidEnded = 0;
- ulRetVal = DosWaitChild(DCWA_PROCESS, DCWW_WAIT,
+ ulRetVal = DosWaitChild(DCWA_PROCESS, DCWW_WAIT,
&results,
&pidEnded, process->md.pid);
if (ulRetVal != NO_ERROR) {
- printf("\nDosWaitChild rc = %lu\n", ulRetVal);
+ printf("\nDosWaitChild rc = %lu\n", ulRetVal);
PR_SetError(PR_UNKNOWN_ERROR, ulRetVal);
return PR_FAILURE;
}
@@ -485,9 +486,9 @@ PRStatus _PR_WaitOS2Process(PRProcess *process,
PRStatus _PR_KillOS2Process(PRProcess *process)
{
- ULONG ulRetVal;
+ ULONG ulRetVal;
if ((ulRetVal = DosKillProcess(DKP_PROCESS, process->md.pid)) == NO_ERROR) {
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PR_SetError(PR_UNKNOWN_ERROR, ulRetVal);
return PR_FAILURE;
@@ -501,7 +502,7 @@ PRStatus _MD_OS2GetHostName(char *name, PRUint32 namelen)
if (0 == rv) {
return PR_SUCCESS;
}
- _PR_MD_MAP_GETHOSTNAME_ERROR(sock_errno());
+ _PR_MD_MAP_GETHOSTNAME_ERROR(sock_errno());
return PR_FAILURE;
}
@@ -509,7 +510,7 @@ void
_PR_MD_WAKEUP_CPUS( void )
{
return;
-}
+}
/*
**********************************************************************
diff --git a/nsprpub/pr/src/md/os2/os2poll.c b/nsprpub/pr/src/md/os2/os2poll.c
index 9a0a00956..47d971045 100644
--- a/nsprpub/pr/src/md/os2/os2poll.c
+++ b/nsprpub/pr/src/md/os2/os2poll.c
@@ -16,16 +16,17 @@
PRBool IsSocketSet( PRInt32 osfd, int* socks, int start, int count )
{
- int i;
- PRBool isSet = PR_FALSE;
+ int i;
+ PRBool isSet = PR_FALSE;
- for( i = start; i < start+count; i++ )
- {
- if( socks[i] == osfd )
- isSet = PR_TRUE;
- }
-
- return isSet;
+ for( i = start; i < start+count; i++ )
+ {
+ if( socks[i] == osfd ) {
+ isSet = PR_TRUE;
+ }
+ }
+
+ return isSet;
}
#endif
@@ -55,7 +56,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
wt = 0;
ex = 0;
socks = (int) PR_MALLOC( npds * 3 * sizeof(int) );
-
+
if (!socks)
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
@@ -74,12 +75,12 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
if (pd->in_flags & PR_POLL_READ)
{
in_flags_read = (pd->fd->methods->poll)(
- pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read);
+ pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read);
}
if (pd->in_flags & PR_POLL_WRITE)
{
in_flags_write = (pd->fd->methods->poll)(
- pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write);
+ pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write);
}
if ((0 != (in_flags_read & out_flags_read)) ||
(0 != (in_flags_write & out_flags_write)))
@@ -115,8 +116,9 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
if (0 == ready)
{
PRInt32 osfd = bottom->secret->md.osfd;
- if (osfd > maxfd)
+ if (osfd > maxfd) {
maxfd = osfd;
+ }
if (in_flags_read & PR_POLL_READ)
{
pd->out_flags |= _PR_POLL_READ_SYS_READ;
@@ -124,7 +126,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
FD_SET(osfd, &rd);
#else
socks[rd] = osfd;
- rd++;
+ rd++;
#endif
}
if (in_flags_read & PR_POLL_WRITE)
@@ -134,7 +136,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
FD_SET(osfd, &wt);
#else
socks[npds+wt] = osfd;
- wt++;
+ wt++;
#endif
}
if (in_flags_write & PR_POLL_READ)
@@ -144,7 +146,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
FD_SET(osfd, &rd);
#else
socks[rd] = osfd;
- rd++;
+ rd++;
#endif
}
if (in_flags_write & PR_POLL_WRITE)
@@ -154,7 +156,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
FD_SET(osfd, &wt);
#else
socks[npds+wt] = osfd;
- wt++;
+ wt++;
#endif
}
if (pd->in_flags & PR_POLL_EXCEPT)
@@ -224,24 +226,28 @@ retry:
msecs = PR_IntervalToMilliseconds(remaining);
}
- /* compact array */
- for( i = rd, j = npds; j < npds+wt; i++,j++ )
+ /* compact array */
+ for( i = rd, j = npds; j < npds+wt; i++,j++ ) {
socks[i] = socks[j];
- for( i = rd+wt, j = npds*2; j < npds*2+ex; i++,j++ )
+ }
+ for( i = rd+wt, j = npds*2; j < npds*2+ex; i++,j++ ) {
socks[i] = socks[j];
-
+ }
+
ready = os2_select(socks, rd, wt, ex, msecs);
#endif
if (ready == -1 && errno == EINTR)
{
- if (timeout == PR_INTERVAL_NO_TIMEOUT)
+ if (timeout == PR_INTERVAL_NO_TIMEOUT) {
goto retry;
+ }
else
{
elapsed = (PRIntervalTime) (PR_IntervalNow() - start);
- if (elapsed > timeout)
- ready = 0; /* timed out */
+ if (elapsed > timeout) {
+ ready = 0; /* timed out */
+ }
else
{
remaining = timeout - elapsed;
@@ -272,38 +278,44 @@ retry:
#ifdef BSD_SELECT
if (FD_ISSET(osfd, &rd))
#else
- if( IsSocketSet(osfd, socks, 0, rd) )
+ if( IsSocketSet(osfd, socks, 0, rd) )
#endif
{
- if (pd->out_flags & _PR_POLL_READ_SYS_READ)
+ if (pd->out_flags & _PR_POLL_READ_SYS_READ) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_READ)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_READ) {
out_flags |= PR_POLL_WRITE;
- }
+ }
+ }
#ifdef BSD_SELECT
if (FD_ISSET(osfd, &wt))
#else
- if( IsSocketSet(osfd, socks, rd, wt) )
+ if( IsSocketSet(osfd, socks, rd, wt) )
#endif
{
- if (pd->out_flags & _PR_POLL_READ_SYS_WRITE)
+ if (pd->out_flags & _PR_POLL_READ_SYS_WRITE) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE) {
out_flags |= PR_POLL_WRITE;
- }
+ }
+ }
#ifdef BSD_SELECT
if (FD_ISSET(osfd, &ex))
#else
- if( IsSocketSet(osfd, socks, rd+wt, ex) )
+ if( IsSocketSet(osfd, socks, rd+wt, ex) )
#endif
{
out_flags |= PR_POLL_EXCEPT;
}
}
pd->out_flags = out_flags;
- if (out_flags) ready++;
+ if (out_flags) {
+ ready++;
+ }
}
PR_ASSERT(ready > 0);
}
@@ -323,7 +335,7 @@ retry:
{
bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
if (getsockopt(bottom->secret->md.osfd, SOL_SOCKET,
- SO_TYPE, (char *) &optval, &optlen) == -1)
+ SO_TYPE, (char *) &optval, &optlen) == -1)
{
PR_ASSERT(sock_errno() == ENOTSOCK);
if (sock_errno() == ENOTSOCK)
@@ -336,8 +348,9 @@ retry:
}
PR_ASSERT(ready > 0);
}
- else
+ else {
_PR_MD_MAP_SELECT_ERROR(err);
+ }
}
#ifndef BSD_SELECT
diff --git a/nsprpub/pr/src/md/os2/os2rng.c b/nsprpub/pr/src/md/os2/os2rng.c
index 72f7357fa..aaa969381 100644
--- a/nsprpub/pr/src/md/os2/os2rng.c
+++ b/nsprpub/pr/src/md/os2/os2rng.c
@@ -17,8 +17,9 @@ static BOOL clockTickTime(unsigned long *phigh, unsigned long *plow)
QWORD qword = {0,0};
rc = DosTmrQueryTime(&qword);
- if (rc != NO_ERROR)
- return FALSE;
+ if (rc != NO_ERROR) {
+ return FALSE;
+ }
*phigh = qword.ulHi;
*plow = qword.ulLo;
@@ -35,8 +36,9 @@ extern PRSize _PR_MD_GetRandomNoise(void *buf, PRSize size )
int nBytes = 0;
time_t sTime;
- if (size <= 0)
- return 0;
+ if (size <= 0) {
+ return 0;
+ }
clockTickTime(&high, &low);
@@ -46,16 +48,18 @@ extern PRSize _PR_MD_GetRandomNoise(void *buf, PRSize size )
n += nBytes;
size -= nBytes;
- if (size <= 0)
- return n;
+ if (size <= 0) {
+ return n;
+ }
nBytes = sizeof(high) > size ? size : sizeof(high);
memcpy(((char *)buf) + n, &high, nBytes);
n += nBytes;
size -= nBytes;
- if (size <= 0)
- return n;
+ if (size <= 0) {
+ return n;
+ }
/* get the number of milliseconds that have elapsed since application started */
val = clock();
@@ -65,8 +69,9 @@ extern PRSize _PR_MD_GetRandomNoise(void *buf, PRSize size )
n += nBytes;
size -= nBytes;
- if (size <= 0)
- return n;
+ if (size <= 0) {
+ return n;
+ }
/* get the time in seconds since midnight Jan 1, 1970 */
time(&sTime);
diff --git a/nsprpub/pr/src/md/os2/os2sem.c b/nsprpub/pr/src/md/os2/os2sem.c
index b60f35a74..a0dd88e4b 100644
--- a/nsprpub/pr/src/md/os2/os2sem.c
+++ b/nsprpub/pr/src/md/os2/os2sem.c
@@ -14,7 +14,7 @@
void
_PR_MD_NEW_SEM(_MDSemaphore *md, PRUintn value)
{
- int rv;
+ int rv;
/* Our Sems don't support a value > 1 */
PR_ASSERT(value <= 1);
@@ -26,9 +26,9 @@ _PR_MD_NEW_SEM(_MDSemaphore *md, PRUintn value)
void
_PR_MD_DESTROY_SEM(_MDSemaphore *md)
{
- int rv;
- rv = DosCloseEventSem(md->sem);
- PR_ASSERT(rv == NO_ERROR);
+ int rv;
+ rv = DosCloseEventSem(md->sem);
+ PR_ASSERT(rv == NO_ERROR);
}
@@ -38,10 +38,12 @@ _PR_MD_TIMED_WAIT_SEM(_MDSemaphore *md, PRIntervalTime ticks)
int rv;
rv = DosWaitEventSem(md->sem, PR_IntervalToMilliseconds(ticks));
- if (rv == NO_ERROR)
+ if (rv == NO_ERROR) {
return PR_SUCCESS;
- else
+ }
+ else {
return PR_FAILURE;
+ }
}
PRStatus
@@ -53,9 +55,9 @@ _PR_MD_WAIT_SEM(_MDSemaphore *md)
void
_PR_MD_POST_SEM(_MDSemaphore *md)
{
- int rv;
- rv = DosPostEventSem(md->sem);
- PR_ASSERT(rv == NO_ERROR);
+ int rv;
+ rv = DosPostEventSem(md->sem);
+ PR_ASSERT(rv == NO_ERROR);
}
diff --git a/nsprpub/pr/src/md/os2/os2sock.c b/nsprpub/pr/src/md/os2/os2sock.c
index b32794f39..c6b3ea3a5 100644
--- a/nsprpub/pr/src/md/os2/os2sock.c
+++ b/nsprpub/pr/src/md/os2/os2sock.c
@@ -12,7 +12,7 @@
/*There is standard BSD (which is kind of slow) and a new flavor of select() that takes */
/*an integer list of sockets, the number of read sockets, write sockets, except sockets, and */
/*a millisecond count for timeout. In the interest of performance I have choosen the OS/2 */
-/*specific version of select(). See OS/2 TCP/IP Programmer's Toolkit for more info. */
+/*specific version of select(). See OS/2 TCP/IP Programmer's Toolkit for more info. */
#include "primpl.h"
@@ -32,7 +32,7 @@ _PR_MD_SOCKET(int domain, int type, int flags)
osfd = socket(domain, type, flags);
- if (osfd == -1)
+ if (osfd == -1)
{
err = sock_errno();
_PR_MD_MAP_SOCKET_ERROR(err);
@@ -101,19 +101,23 @@ socket_io_wait( PRInt32 osfd, PRInt32 fd_type, PRIntervalTime timeout )
FD_ZERO(&rd_wr);
do {
FD_SET(osfd, &rd_wr);
- if (fd_type == READ_FD)
+ if (fd_type == READ_FD) {
rv = bsdselect(osfd + 1, &rd_wr, NULL, NULL, &tv);
- else
+ }
+ else {
rv = bsdselect(osfd + 1, NULL, &rd_wr, NULL, &tv);
+ }
#else
- lTimeout = _PR_INTERRUPT_CHECK_INTERVAL_SECS * 1000;
+ lTimeout = _PR_INTERRUPT_CHECK_INTERVAL_SECS * 1000;
do {
socks[0] = osfd;
- if (fd_type == READ_FD)
+ if (fd_type == READ_FD) {
rv = os2_select(socks, 1, 0, 0, lTimeout);
- else
+ }
+ else {
rv = os2_select(socks, 0, 1, 0, lTimeout);
-#endif
+ }
+#endif
if (rv == -1 && (syserror = sock_errno()) != EINTR) {
_PR_MD_MAP_SELECT_ERROR(syserror);
break;
@@ -148,14 +152,16 @@ socket_io_wait( PRInt32 osfd, PRInt32 fd_type, PRIntervalTime timeout )
tv.tv_usec = 0;
} else {
tv.tv_usec = PR_IntervalToMicroseconds(
- remaining -
- PR_SecondsToInterval(tv.tv_sec));
+ remaining -
+ PR_SecondsToInterval(tv.tv_sec));
}
FD_SET(osfd, &rd_wr);
- if (fd_type == READ_FD)
+ if (fd_type == READ_FD) {
rv = bsdselect(osfd + 1, &rd_wr, NULL, NULL, &tv);
- else
+ }
+ else {
rv = bsdselect(osfd + 1, NULL, &rd_wr, NULL, &tv);
+ }
#else
wait_for_remaining = PR_TRUE;
lTimeout = PR_IntervalToMilliseconds(remaining);
@@ -164,10 +170,12 @@ socket_io_wait( PRInt32 osfd, PRInt32 fd_type, PRIntervalTime timeout )
lTimeout = _PR_INTERRUPT_CHECK_INTERVAL_SECS * 1000;
}
socks[0] = osfd;
- if (fd_type == READ_FD)
+ if (fd_type == READ_FD) {
rv = os2_select(socks, 1, 0, 0, lTimeout);
- else
+ }
+ else {
rv = os2_select(socks, 0, 1, 0, lTimeout);
+ }
#endif
/*
* we don't consider EINTR a real error
@@ -198,7 +206,7 @@ socket_io_wait( PRInt32 osfd, PRInt32 fd_type, PRIntervalTime timeout )
} else {
#ifdef BSD_SELECT
now += PR_SecondsToInterval(tv.tv_sec)
- + PR_MicrosecondsToInterval(tv.tv_usec);
+ + PR_MicrosecondsToInterval(tv.tv_usec);
#else
now += PR_MillisecondsToInterval(lTimeout);
#endif
@@ -217,7 +225,7 @@ socket_io_wait( PRInt32 osfd, PRInt32 fd_type, PRIntervalTime timeout )
}
} while (rv == 0 || (rv == -1 && syserror == EINTR));
break;
- }
+ }
return(rv);
}
@@ -237,9 +245,10 @@ _MD_Accept(PRFileDesc *fd, PRNetAddr *addr,
if (fd->secret->nonblocking) {
break;
}
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
- goto done;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) {
+ goto done;
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -253,7 +262,7 @@ done:
}
PRInt32
-_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
+_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
PRIntervalTime timeout)
{
PRInt32 rv, err;
@@ -263,17 +272,17 @@ _PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
* modifies the sockaddr structure.
* See Bugzilla bug 100776. */
- /*
- * We initiate the connection setup by making a nonblocking connect()
- * call. If the connect() call fails, there are two cases we handle
- * specially:
- * 1. The connect() call was interrupted by a signal. In this case
- * we simply retry connect().
- * 2. The NSPR socket is nonblocking and connect() fails with
- * EINPROGRESS. We first wait until the socket becomes writable.
- * Then we try to find out whether the connection setup succeeded
- * or failed.
- */
+ /*
+ * We initiate the connection setup by making a nonblocking connect()
+ * call. If the connect() call fails, there are two cases we handle
+ * specially:
+ * 1. The connect() call was interrupted by a signal. In this case
+ * we simply retry connect().
+ * 2. The NSPR socket is nonblocking and connect() fails with
+ * EINPROGRESS. We first wait until the socket becomes writable.
+ * Then we try to find out whether the connection setup succeeded
+ * or failed.
+ */
retry:
if ((rv = connect(osfd, (struct sockaddr *)&addrCopy, addrlen)) == -1)
@@ -313,7 +322,7 @@ retry:
}
return 0;
}
-
+
_PR_MD_MAP_CONNECT_ERROR(err);
}
@@ -347,7 +356,7 @@ _PR_MD_LISTEN(PRFileDesc *fd, PRIntn backlog)
PRInt32
-_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
+_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PRIntervalTime timeout)
{
PRInt32 osfd = fd->secret->md.osfd;
@@ -361,9 +370,10 @@ _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
if (fd->secret->nonblocking) {
break;
}
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) {
goto done;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -391,20 +401,21 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
if (fd->secret->nonblocking) {
break;
}
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, WRITE_FD, timeout)) < 0) {
goto done;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
}
}
- /*
- * optimization; if bytes sent is less than "amount" call
- * select before returning. This is because it is likely that
- * the next send() call will return EWOULDBLOCK.
- */
+ /*
+ * optimization; if bytes sent is less than "amount" call
+ * select before returning. This is because it is likely that
+ * the next send() call will return EWOULDBLOCK.
+ */
if ((!fd->secret->nonblocking) && (rv > 0) && (rv < amount)
&& (timeout != PR_INTERVAL_NO_WAIT))
{
@@ -428,7 +439,7 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
while ((rv = sendto(osfd, buf, amount, flags,
- (struct sockaddr *) addr, addrlen)) == -1)
+ (struct sockaddr *) addr, addrlen)) == -1)
{
err = sock_errno();
if ((err == EWOULDBLOCK))
@@ -436,9 +447,10 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
if (fd->secret->nonblocking) {
break;
}
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, WRITE_FD, timeout)) < 0) {
goto done;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -461,16 +473,17 @@ _PR_MD_RECVFROM(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
while( (*addrlen = PR_NETADDR_SIZE(addr)),
((rv = recvfrom(osfd, buf, amount, flags,
- (struct sockaddr *) addr, (int *)addrlen)) == -1))
+ (struct sockaddr *) addr, (int *)addrlen)) == -1))
{
err = sock_errno();
if ((err == EWOULDBLOCK)) {
if (fd->secret->nonblocking) {
break;
}
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) {
goto done;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -506,13 +519,13 @@ _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size,
osiov[index].iov_len = iov[index].iov_len;
}
- /*
- * Calculate the total number of bytes to be sent; needed for
- * optimization later.
- * We could avoid this if this number was passed in; but it is
- * probably not a big deal because iov_size is usually small (less than
- * 3)
- */
+ /*
+ * Calculate the total number of bytes to be sent; needed for
+ * optimization later.
+ * We could avoid this if this number was passed in; but it is
+ * probably not a big deal because iov_size is usually small (less than
+ * 3)
+ */
if (!fd->secret->nonblocking) {
for (index=0; index<iov_size; index++) {
amount += iov[index].iov_len;
@@ -525,22 +538,23 @@ _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size,
if (fd->secret->nonblocking) {
break;
}
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))<0)
+ if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))<0) {
goto done;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
}
}
- /*
- * optimization; if bytes sent is less than "amount" call
- * select before returning. This is because it is likely that
- * the next writev() call will return EWOULDBLOCK.
- */
+ /*
+ * optimization; if bytes sent is less than "amount" call
+ * select before returning. This is because it is likely that
+ * the next writev() call will return EWOULDBLOCK.
+ */
if ((!fd->secret->nonblocking) && (rv > 0) && (rv < amount)
- && (timeout != PR_INTERVAL_NO_WAIT)) {
+ && (timeout != PR_INTERVAL_NO_WAIT)) {
if (socket_io_wait(osfd, WRITE_FD, timeout) < 0) {
rv = -1;
goto done;
@@ -559,8 +573,9 @@ _PR_MD_SHUTDOWN(PRFileDesc *fd, PRIntn how)
PRInt32 rv;
rv = shutdown(fd->secret->md.osfd, how);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_SHUTDOWN_ERROR(sock_errno());
+ }
return rv;
}
@@ -639,7 +654,7 @@ _MD_MakeNonblock(PRFileDesc *fd)
PRInt32 osfd = fd->secret->md.osfd;
PRInt32 err;
PRUint32 one = 1;
-
+
if (osfd <= 2) {
/* Don't mess around with stdin, stdout or stderr */
return;
diff --git a/nsprpub/pr/src/md/os2/os2thred.c b/nsprpub/pr/src/md/os2/os2thred.c
index edb9f5f0c..aa929a1a2 100644
--- a/nsprpub/pr/src/md/os2/os2thred.c
+++ b/nsprpub/pr/src/md/os2/os2thred.c
@@ -16,37 +16,37 @@ APIRET (* APIENTRY QueryThreadContext)(TID, ULONG, PCONTEXTRECORD);
void
_PR_MD_ENSURE_TLS(void)
{
- if(!pThreadLocalStorage)
- {
- /* Allocate thread local storage (TLS). Note, that only 32 bytes can
- * be allocated at a time.
- */
- int rc = DosAllocThreadLocalMemory(sizeof(_NSPR_TLS) / 4, (PULONG*)&pThreadLocalStorage);
- PR_ASSERT(rc == NO_ERROR);
- memset(pThreadLocalStorage, 0, sizeof(_NSPR_TLS));
- }
+ if(!pThreadLocalStorage)
+ {
+ /* Allocate thread local storage (TLS). Note, that only 32 bytes can
+ * be allocated at a time.
+ */
+ int rc = DosAllocThreadLocalMemory(sizeof(_NSPR_TLS) / 4, (PULONG*)&pThreadLocalStorage);
+ PR_ASSERT(rc == NO_ERROR);
+ memset(pThreadLocalStorage, 0, sizeof(_NSPR_TLS));
+ }
}
void
_PR_MD_EARLY_INIT()
{
- HMODULE hmod;
+ HMODULE hmod;
- if (DosLoadModule(NULL, 0, "DOSCALL1", &hmod) == 0)
- DosQueryProcAddr(hmod, 877, "DOSQUERYTHREADCONTEXT",
- (PFN *)&QueryThreadContext);
+ if (DosLoadModule(NULL, 0, "DOSCALL1", &hmod) == 0)
+ DosQueryProcAddr(hmod, 877, "DOSQUERYTHREADCONTEXT",
+ (PFN *)&QueryThreadContext);
}
static void
_pr_SetThreadMDHandle(PRThread *thread)
{
- PTIB ptib;
- PPIB ppib;
- PRUword rc;
+ PTIB ptib;
+ PPIB ppib;
+ PRUword rc;
- rc = DosGetInfoBlocks(&ptib, &ppib);
+ rc = DosGetInfoBlocks(&ptib, &ppib);
- thread->md.handle = ptib->tib_ptib2->tib2_ultid;
+ thread->md.handle = ptib->tib_ptib2->tib2_ultid;
}
/* On OS/2, some system function calls seem to change the FPU control word,
@@ -134,15 +134,15 @@ PR_OS2_UnsetFloatExcpHandler(EXCEPTIONREGISTRATIONRECORD* excpreg)
PRStatus
_PR_MD_INIT_THREAD(PRThread *thread)
{
- APIRET rv;
+ APIRET rv;
- if (thread->flags & (_PR_PRIMORDIAL | _PR_ATTACHED)) {
- _pr_SetThreadMDHandle(thread);
- }
+ if (thread->flags & (_PR_PRIMORDIAL | _PR_ATTACHED)) {
+ _pr_SetThreadMDHandle(thread);
+ }
- /* Create the blocking IO semaphore */
- rv = DosCreateEventSem(NULL, &(thread->md.blocked_sema), 0, 0);
- return (rv == NO_ERROR) ? PR_SUCCESS : PR_FAILURE;
+ /* Create the blocking IO semaphore */
+ rv = DosCreateEventSem(NULL, &(thread->md.blocked_sema), 0, 0);
+ return (rv == NO_ERROR) ? PR_SUCCESS : PR_FAILURE;
}
typedef struct param_store
@@ -169,20 +169,20 @@ ExcpStartFunc(void* arg)
}
PRStatus
-_PR_MD_CREATE_THREAD(PRThread *thread,
- void (*start)(void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+_PR_MD_CREATE_THREAD(PRThread *thread,
+ void (*start)(void *),
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize)
{
PARAMSTORE* params = PR_Malloc(sizeof(PARAMSTORE));
params->start = start;
params->thread = thread;
thread->md.handle = thread->id = (TID) _beginthread(ExcpStartFunc,
- NULL,
- thread->stack->stackSize,
- params);
+ NULL,
+ thread->stack->stackSize,
+ params);
if(thread->md.handle == -1) {
return PR_FAILURE;
}
@@ -232,7 +232,7 @@ _PR_MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
PR_ASSERT(rv == NO_ERROR);
if (rv != NO_ERROR) {
PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("PR_SetThreadPriority: can't set thread priority\n"));
+ ("PR_SetThreadPriority: can't set thread priority\n"));
}
return;
}
@@ -268,41 +268,41 @@ _PR_MD_EXIT(PRIntn status)
}
#ifdef HAVE_THREAD_AFFINITY
-PR_EXTERN(PRInt32)
+PR_EXTERN(PRInt32)
_PR_MD_SETTHREADAFFINITYMASK(PRThread *thread, PRUint32 mask )
{
- /* Can we do this on OS/2? Only on SMP versions? */
- PR_NOT_REACHED("Not implemented");
- return 0;
+ /* Can we do this on OS/2? Only on SMP versions? */
+ PR_NOT_REACHED("Not implemented");
+ return 0;
- /* This is what windows does:
- int rv;
+ /* This is what windows does:
+ int rv;
- rv = SetThreadAffinityMask(thread->md.handle, mask);
+ rv = SetThreadAffinityMask(thread->md.handle, mask);
- return rv?0:-1;
- */
+ return rv?0:-1;
+ */
}
PR_EXTERN(PRInt32)
_PR_MD_GETTHREADAFFINITYMASK(PRThread *thread, PRUint32 *mask)
{
- /* Can we do this on OS/2? Only on SMP versions? */
- PR_NOT_REACHED("Not implemented");
- return 0;
+ /* Can we do this on OS/2? Only on SMP versions? */
+ PR_NOT_REACHED("Not implemented");
+ return 0;
- /* This is what windows does:
- PRInt32 rv, system_mask;
+ /* This is what windows does:
+ PRInt32 rv, system_mask;
- rv = GetProcessAffinityMask(GetCurrentProcess(), mask, &system_mask);
-
- return rv?0:-1;
- */
+ rv = GetProcessAffinityMask(GetCurrentProcess(), mask, &system_mask);
+
+ return rv?0:-1;
+ */
}
#endif /* HAVE_THREAD_AFFINITY */
void
-_PR_MD_SUSPEND_CPU(_PRCPU *cpu)
+_PR_MD_SUSPEND_CPU(_PRCPU *cpu)
{
_PR_MD_SUSPEND_THREAD(cpu->thread);
}
@@ -317,13 +317,13 @@ void
_PR_MD_SUSPEND_THREAD(PRThread *thread)
{
if (_PR_IS_NATIVE_THREAD(thread)) {
- APIRET rc;
+ APIRET rc;
/* XXXMB - DosSuspendThread() is not a blocking call; how do we
* know when the thread is *REALLY* suspended?
*/
- rc = DosSuspendThread(thread->md.handle);
- PR_ASSERT(rc == NO_ERROR);
+ rc = DosSuspendThread(thread->md.handle);
+ PR_ASSERT(rc == NO_ERROR);
}
}
diff --git a/nsprpub/pr/src/md/prosdep.c b/nsprpub/pr/src/md/prosdep.c
index 137ffaecc..0b1f3e597 100644
--- a/nsprpub/pr/src/md/prosdep.c
+++ b/nsprpub/pr/src/md/prosdep.c
@@ -11,9 +11,6 @@
#endif
#ifdef _WIN32
#include <windows.h>
-#endif
-#ifdef XP_BEOS
-#include <OS.h>
#endif
PRInt32 _pr_pageShift;
@@ -24,14 +21,14 @@ PRInt32 _pr_pageSize;
*/
static void GetPageSize(void)
{
- PRInt32 pageSize;
+ PRInt32 pageSize;
/* Get page size */
#ifdef XP_UNIX
#if defined BSDI || defined AIX \
|| defined LINUX || defined __GNU__ || defined __GLIBC__ \
|| defined FREEBSD || defined NETBSD || defined OPENBSD \
- || defined DARWIN || defined SYMBIAN
+ || defined DARWIN
_pr_pageSize = getpagesize();
#elif defined(HPUX)
/* I have no idea. Don't get me started. --Rob */
@@ -41,10 +38,6 @@ static void GetPageSize(void)
#endif
#endif /* XP_UNIX */
-#ifdef XP_BEOS
- _pr_pageSize = B_PAGE_SIZE;
-#endif
-
#ifdef XP_PC
#ifdef _WIN32
SYSTEM_INFO info;
@@ -55,14 +48,14 @@ static void GetPageSize(void)
#endif
#endif /* XP_PC */
- pageSize = _pr_pageSize;
- PR_CEILING_LOG2(_pr_pageShift, pageSize);
+ pageSize = _pr_pageSize;
+ PR_CEILING_LOG2(_pr_pageShift, pageSize);
}
PR_IMPLEMENT(PRInt32) PR_GetPageShift(void)
{
if (!_pr_pageSize) {
- GetPageSize();
+ GetPageSize();
}
return _pr_pageShift;
}
@@ -70,7 +63,7 @@ PR_IMPLEMENT(PRInt32) PR_GetPageShift(void)
PR_IMPLEMENT(PRInt32) PR_GetPageSize(void)
{
if (!_pr_pageSize) {
- GetPageSize();
+ GetPageSize();
}
return _pr_pageSize;
}
diff --git a/nsprpub/pr/src/md/unix/aix.c b/nsprpub/pr/src/md/unix/aix.c
index 43f0d58de..c632c5790 100644
--- a/nsprpub/pr/src/md/unix/aix.c
+++ b/nsprpub/pr/src/md/unix/aix.c
@@ -73,7 +73,7 @@ int _pr_aix_send_file_use_disabled = 0;
void _MD_EarlyInit(void)
{
void *main_app_handle;
- char *evp;
+ char *evp;
main_app_handle = dlopen(NULL, RTLD_NOW);
PR_ASSERT(NULL != main_app_handle);
@@ -85,10 +85,11 @@ void _MD_EarlyInit(void)
}
dlclose(main_app_handle);
- if (evp = getenv("NSPR_AIX_SEND_FILE_USE_DISABLED")) {
- if (1 == atoi(evp))
- _pr_aix_send_file_use_disabled = 1;
- }
+ if (evp = getenv("NSPR_AIX_SEND_FILE_USE_DISABLED")) {
+ if (1 == atoi(evp)) {
+ _pr_aix_send_file_use_disabled = 1;
+ }
+ }
#if defined(AIX_TIMERS)
_MD_AixIntervalInit();
@@ -110,13 +111,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#ifndef _PR_PTHREADS
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
#else
- *np = 0;
- return NULL;
+ *np = 0;
+ return NULL;
#endif
}
@@ -130,7 +131,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PR_IMPLEMENT(PRStatus)
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PR_IMPLEMENT(PRStatus)
@@ -145,7 +146,7 @@ PR_IMPLEMENT(PRStatus)
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
@@ -193,17 +194,17 @@ int _MD_SELECT(int width, fd_set *r, fd_set *w, fd_set *e, struct timeval *t)
if (!aix_select_fcn) {
void *aix_handle;
- aix_handle = dlopen("/unix", RTLD_NOW);
- if (!aix_handle) {
- PR_SetError(PR_UNKNOWN_ERROR, 0);
- return -1;
- }
- aix_select_fcn = (int(*)())dlsym(aix_handle,"select");
+ aix_handle = dlopen("/unix", RTLD_NOW);
+ if (!aix_handle) {
+ PR_SetError(PR_UNKNOWN_ERROR, 0);
+ return -1;
+ }
+ aix_select_fcn = (int(*)())dlsym(aix_handle,"select");
dlclose(aix_handle);
- if (!aix_select_fcn) {
- PR_SetError(PR_UNKNOWN_ERROR, 0);
- return -1;
- }
+ if (!aix_select_fcn) {
+ PR_SetError(PR_UNKNOWN_ERROR, 0);
+ return -1;
+ }
}
rv = (*aix_select_fcn)(width, r, w, e, t);
return rv;
@@ -216,17 +217,17 @@ int _MD_POLL(void *listptr, unsigned long nfds, long timeout)
if (!aix_poll_fcn) {
void *aix_handle;
- aix_handle = dlopen("/unix", RTLD_NOW);
- if (!aix_handle) {
- PR_SetError(PR_UNKNOWN_ERROR, 0);
- return -1;
- }
- aix_poll_fcn = (int(*)())dlsym(aix_handle,"poll");
+ aix_handle = dlopen("/unix", RTLD_NOW);
+ if (!aix_handle) {
+ PR_SetError(PR_UNKNOWN_ERROR, 0);
+ return -1;
+ }
+ aix_poll_fcn = (int(*)())dlsym(aix_handle,"poll");
dlclose(aix_handle);
- if (!aix_poll_fcn) {
- PR_SetError(PR_UNKNOWN_ERROR, 0);
- return -1;
- }
+ if (!aix_poll_fcn) {
+ PR_SetError(PR_UNKNOWN_ERROR, 0);
+ return -1;
+ }
}
rv = (*aix_poll_fcn)(listptr, nfds, timeout);
return rv;
@@ -251,51 +252,51 @@ void _pr_aix_dummy()
#include "pratom.h"
-#define _PR_AIX_ATOMIC_LOCK -1
+#define _PR_AIX_ATOMIC_LOCK -1
PR_IMPLEMENT(void)
PR_StackPush(PRStack *stack, PRStackElem *stack_elem)
{
-PRStackElem *addr;
-boolean_t locked = TRUE;
-
- /* Is it safe to cast a pointer to an int? */
- PR_ASSERT(sizeof(int) == sizeof(PRStackElem *));
- do {
- while ((addr = stack->prstk_head.prstk_elem_next) ==
- (PRStackElem *)_PR_AIX_ATOMIC_LOCK)
- ;
- locked = _check_lock((atomic_p) &stack->prstk_head.prstk_elem_next,
- (int) addr, _PR_AIX_ATOMIC_LOCK);
- } while (locked == TRUE);
- stack_elem->prstk_elem_next = addr;
- _clear_lock((atomic_p)&stack->prstk_head.prstk_elem_next, (int)stack_elem);
+ PRStackElem *addr;
+ boolean_t locked = TRUE;
+
+ /* Is it safe to cast a pointer to an int? */
+ PR_ASSERT(sizeof(int) == sizeof(PRStackElem *));
+ do {
+ while ((addr = stack->prstk_head.prstk_elem_next) ==
+ (PRStackElem *)_PR_AIX_ATOMIC_LOCK)
+ ;
+ locked = _check_lock((atomic_p) &stack->prstk_head.prstk_elem_next,
+ (int) addr, _PR_AIX_ATOMIC_LOCK);
+ } while (locked == TRUE);
+ stack_elem->prstk_elem_next = addr;
+ _clear_lock((atomic_p)&stack->prstk_head.prstk_elem_next, (int)stack_elem);
return;
}
PR_IMPLEMENT(PRStackElem *)
PR_StackPop(PRStack *stack)
{
-PRStackElem *element;
-boolean_t locked = TRUE;
-
- /* Is it safe to cast a pointer to an int? */
- PR_ASSERT(sizeof(int) == sizeof(PRStackElem *));
- do {
- while ((element = stack->prstk_head.prstk_elem_next) ==
- (PRStackElem *) _PR_AIX_ATOMIC_LOCK)
- ;
- locked = _check_lock((atomic_p) &stack->prstk_head.prstk_elem_next,
- (int)element, _PR_AIX_ATOMIC_LOCK);
- } while (locked == TRUE);
-
- if (element == NULL) {
- _clear_lock((atomic_p) &stack->prstk_head.prstk_elem_next, NULL);
- } else {
- _clear_lock((atomic_p) &stack->prstk_head.prstk_elem_next,
- (int) element->prstk_elem_next);
- }
- return element;
+ PRStackElem *element;
+ boolean_t locked = TRUE;
+
+ /* Is it safe to cast a pointer to an int? */
+ PR_ASSERT(sizeof(int) == sizeof(PRStackElem *));
+ do {
+ while ((element = stack->prstk_head.prstk_elem_next) ==
+ (PRStackElem *) _PR_AIX_ATOMIC_LOCK)
+ ;
+ locked = _check_lock((atomic_p) &stack->prstk_head.prstk_elem_next,
+ (int)element, _PR_AIX_ATOMIC_LOCK);
+ } while (locked == TRUE);
+
+ if (element == NULL) {
+ _clear_lock((atomic_p) &stack->prstk_head.prstk_elem_next, NULL);
+ } else {
+ _clear_lock((atomic_p) &stack->prstk_head.prstk_elem_next,
+ (int) element->prstk_elem_next);
+ }
+ return element;
}
-#endif /* _PR_HAVE_ATOMIC_CAS */
+#endif /* _PR_HAVE_ATOMIC_CAS */
diff --git a/nsprpub/pr/src/md/unix/aixwrap.c b/nsprpub/pr/src/md/unix/aixwrap.c
index cb5b413f1..853825196 100644
--- a/nsprpub/pr/src/md/unix/aixwrap.c
+++ b/nsprpub/pr/src/md/unix/aixwrap.c
@@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
- * File: aixwrap.c
+ * File: aixwrap.c
* Description:
* This file contains a single function, _MD_SELECT(), which simply
* invokes the select() function. This file is used in an ugly
diff --git a/nsprpub/pr/src/md/unix/bsdi.c b/nsprpub/pr/src/md/unix/bsdi.c
index 095547ed5..e625003f7 100644
--- a/nsprpub/pr/src/md/unix/bsdi.c
+++ b/nsprpub/pr/src/md/unix/bsdi.c
@@ -25,7 +25,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#ifndef _PR_PTHREADS
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
@@ -45,7 +45,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PRStatus
@@ -60,7 +60,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
@@ -82,6 +82,6 @@ _MD_CREATE_THREAD(
PRUint32 stackSize)
{
PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for BSDI.");
- return PR_FAILURE;
+ return PR_FAILURE;
}
#endif /* ! _PR_PTHREADS */
diff --git a/nsprpub/pr/src/md/unix/darwin.c b/nsprpub/pr/src/md/unix/darwin.c
index 719fc30f2..6135e082f 100644
--- a/nsprpub/pr/src/md/unix/darwin.c
+++ b/nsprpub/pr/src/md/unix/darwin.c
@@ -48,13 +48,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#if !defined(_PR_PTHREADS)
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
#else
- *np = 0;
- return NULL;
+ *np = 0;
+ return NULL;
#endif
}
@@ -68,7 +68,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PRStatus
@@ -83,7 +83,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
@@ -105,7 +105,7 @@ _MD_CREATE_THREAD(
PRUint32 stackSize)
{
PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for Darwin.");
- return PR_FAILURE;
+ return PR_FAILURE;
}
#endif /* ! _PR_PTHREADS */
diff --git a/nsprpub/pr/src/md/unix/freebsd.c b/nsprpub/pr/src/md/unix/freebsd.c
index a66a81284..19af17a44 100644
--- a/nsprpub/pr/src/md/unix/freebsd.c
+++ b/nsprpub/pr/src/md/unix/freebsd.c
@@ -25,13 +25,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#ifndef _PR_PTHREADS
if (isCurrent) {
- (void) sigsetjmp(CONTEXT(t), 1);
+ (void) sigsetjmp(CONTEXT(t), 1);
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
#else
- *np = 0;
- return NULL;
+ *np = 0;
+ return NULL;
#endif
}
@@ -45,7 +45,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PRStatus
@@ -60,7 +60,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
@@ -82,6 +82,6 @@ _MD_CREATE_THREAD(
PRUint32 stackSize)
{
PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for FreeBSD.");
- return PR_FAILURE;
+ return PR_FAILURE;
}
#endif /* ! _PR_PTHREADS */
diff --git a/nsprpub/pr/src/md/unix/hpux.c b/nsprpub/pr/src/md/unix/hpux.c
index 56fddba29..bf72567fd 100644
--- a/nsprpub/pr/src/md/unix/hpux.c
+++ b/nsprpub/pr/src/md/unix/hpux.c
@@ -84,7 +84,7 @@ void _MD_EarlyInit(void)
if(!setjmp(jb)) {
newstack = (char *) PR_MALLOC(PIDOOMA_STACK_SIZE);
- oldstack = (char *) (*(((int *) jb) + 1) - BACKTRACE_SIZE);
+ oldstack = (char *) (*(((int *) jb) + 1) - BACKTRACE_SIZE);
memcpy(newstack, oldstack, BACKTRACE_SIZE);
*(((int *) jb) + 1) = (int) (newstack + BACKTRACE_SIZE);
longjmp(jb, 1);
@@ -98,13 +98,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#ifndef _PR_PTHREADS
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
#else
- *np = 0;
- return NULL;
+ *np = 0;
+ return NULL;
#endif
}
@@ -118,7 +118,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PRStatus
@@ -133,7 +133,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
@@ -208,7 +208,7 @@ strchr(const char *s, int c)
* A.09.07, and B.10.10) dumps core if called with:
* 1. First operand with address = 1(mod 4).
* 2. Size = 1(mod 4)
- * 3. Last byte of the second operand is the last byte of the page and
+ * 3. Last byte of the second operand is the last byte of the page and
* next page is not accessible(not mapped or protected)
* Thus, using the following naive version (tons of optimizations are
* possible;^)
@@ -217,13 +217,15 @@ strchr(const char *s, int c)
int memcmp(const void *s1, const void *s2, size_t n)
{
register unsigned char *p1 = (unsigned char *) s1,
- *p2 = (unsigned char *) s2;
+ *p2 = (unsigned char *) s2;
while (n-- > 0) {
- register int r = ((int) ((unsigned int) *p1))
- - ((int) ((unsigned int) *p2));
- if (r) return r;
+ register int r = ((int) ((unsigned int) *p1))
+ - ((int) ((unsigned int) *p2));
+ if (r) {
+ return r;
+ }
p1++; p2++;
}
- return 0;
+ return 0;
}
diff --git a/nsprpub/pr/src/md/unix/irix.c b/nsprpub/pr/src/md/unix/irix.c
deleted file mode 100644
index c57a07b33..000000000
--- a/nsprpub/pr/src/md/unix/irix.c
+++ /dev/null
@@ -1,1648 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-#include <signal.h>
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/mman.h>
-#include <sys/syssgi.h>
-#include <sys/time.h>
-#include <sys/immu.h>
-#include <sys/utsname.h>
-#include <sys/sysmp.h>
-#include <sys/pda.h>
-#include <sys/prctl.h>
-#include <sys/wait.h>
-#include <sys/resource.h>
-#include <sys/procfs.h>
-#include <task.h>
-#include <dlfcn.h>
-
-static void _MD_IrixIntervalInit(void);
-
-#if defined(_PR_PTHREADS)
-/*
- * for compatibility with classic nspr
- */
-void _PR_IRIX_CHILD_PROCESS()
-{
-}
-#else /* defined(_PR_PTHREADS) */
-
-static void irix_detach_sproc(void);
-char *_nspr_sproc_private; /* ptr. to private region in every sproc */
-
-extern PRUintn _pr_numCPU;
-
-typedef struct nspr_arena {
- PRCList links;
- usptr_t *usarena;
-} nspr_arena;
-
-#define ARENA_PTR(qp) \
- ((nspr_arena *) ((char*) (qp) - offsetof(nspr_arena , links)))
-
-static usptr_t *alloc_new_arena(void);
-
-PRCList arena_list = PR_INIT_STATIC_CLIST(&arena_list);
-ulock_t arena_list_lock;
-nspr_arena first_arena;
-int _nspr_irix_arena_cnt = 1;
-
-PRCList sproc_list = PR_INIT_STATIC_CLIST(&sproc_list);
-ulock_t sproc_list_lock;
-
-typedef struct sproc_data {
- void (*entry) (void *, size_t);
- unsigned inh;
- void *arg;
- caddr_t sp;
- size_t len;
- int *pid;
- int creator_pid;
-} sproc_data;
-
-typedef struct sproc_params {
- PRCList links;
- sproc_data sd;
-} sproc_params;
-
-#define SPROC_PARAMS_PTR(qp) \
- ((sproc_params *) ((char*) (qp) - offsetof(sproc_params , links)))
-
-long _nspr_irix_lock_cnt = 0;
-long _nspr_irix_sem_cnt = 0;
-long _nspr_irix_pollsem_cnt = 0;
-
-usptr_t *_pr_usArena;
-ulock_t _pr_heapLock;
-
-usema_t *_pr_irix_exit_sem;
-PRInt32 _pr_irix_exit_now = 0;
-PRInt32 _pr_irix_process_exit_code = 0; /* exit code for PR_ProcessExit */
-PRInt32 _pr_irix_process_exit = 0; /* process exiting due to call to
- PR_ProcessExit */
-
-int _pr_irix_primoridal_cpu_fd[2] = { -1, -1 };
-static void (*libc_exit)(int) = NULL;
-static void *libc_handle = NULL;
-
-#define _NSPR_DEF_INITUSERS 100 /* default value of CONF_INITUSERS */
-#define _NSPR_DEF_INITSIZE (4 * 1024 * 1024) /* 4 MB */
-
-int _irix_initusers = _NSPR_DEF_INITUSERS;
-int _irix_initsize = _NSPR_DEF_INITSIZE;
-
-PRIntn _pr_io_in_progress, _pr_clock_in_progress;
-
-PRInt32 _pr_md_irix_sprocs_created, _pr_md_irix_sprocs_failed;
-PRInt32 _pr_md_irix_sprocs = 1;
-PRCList _pr_md_irix_sproc_list =
-PR_INIT_STATIC_CLIST(&_pr_md_irix_sproc_list);
-
-sigset_t ints_off;
-extern sigset_t timer_set;
-
-#if !defined(PR_SETABORTSIG)
-#define PR_SETABORTSIG 18
-#endif
-/*
- * terminate the entire application if any sproc exits abnormally
- */
-PRBool _nspr_terminate_on_error = PR_TRUE;
-
-/*
- * exported interface to set the shared arena parameters
- */
-void _PR_Irix_Set_Arena_Params(PRInt32 initusers, PRInt32 initsize)
-{
- _irix_initusers = initusers;
- _irix_initsize = initsize;
-}
-
-static usptr_t *alloc_new_arena()
-{
- return(usinit("/dev/zero"));
-}
-
-static PRStatus new_poll_sem(struct _MDThread *mdthr, int val)
-{
-PRIntn _is;
-PRStatus rv = PR_SUCCESS;
-usema_t *sem = NULL;
-PRCList *qp;
-nspr_arena *arena;
-usptr_t *irix_arena;
-PRThread *me = _MD_GET_ATTACHED_THREAD();
-
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(_is);
- _PR_LOCK(arena_list_lock);
- for (qp = arena_list.next; qp != &arena_list; qp = qp->next) {
- arena = ARENA_PTR(qp);
- sem = usnewpollsema(arena->usarena, val);
- if (sem != NULL) {
- mdthr->cvar_pollsem = sem;
- mdthr->pollsem_arena = arena->usarena;
- break;
- }
- }
- if (sem == NULL) {
- /*
- * If no space left in the arena allocate a new one.
- */
- if (errno == ENOMEM) {
- arena = PR_NEWZAP(nspr_arena);
- if (arena != NULL) {
- irix_arena = alloc_new_arena();
- if (irix_arena) {
- PR_APPEND_LINK(&arena->links, &arena_list);
- _nspr_irix_arena_cnt++;
- arena->usarena = irix_arena;
- sem = usnewpollsema(arena->usarena, val);
- if (sem != NULL) {
- mdthr->cvar_pollsem = sem;
- mdthr->pollsem_arena = arena->usarena;
- } else
- rv = PR_FAILURE;
- } else {
- PR_DELETE(arena);
- rv = PR_FAILURE;
- }
-
- } else
- rv = PR_FAILURE;
- } else
- rv = PR_FAILURE;
- }
- _PR_UNLOCK(arena_list_lock);
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(_is);
- if (rv == PR_SUCCESS)
- _MD_ATOMIC_INCREMENT(&_nspr_irix_pollsem_cnt);
- return rv;
-}
-
-static void free_poll_sem(struct _MDThread *mdthr)
-{
-PRIntn _is;
-PRThread *me = _MD_GET_ATTACHED_THREAD();
-
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(_is);
- usfreepollsema(mdthr->cvar_pollsem, mdthr->pollsem_arena);
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(_is);
- _MD_ATOMIC_DECREMENT(&_nspr_irix_pollsem_cnt);
-}
-
-static PRStatus new_lock(struct _MDLock *lockp)
-{
-PRIntn _is;
-PRStatus rv = PR_SUCCESS;
-ulock_t lock = NULL;
-PRCList *qp;
-nspr_arena *arena;
-usptr_t *irix_arena;
-PRThread *me = _MD_GET_ATTACHED_THREAD();
-
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(_is);
- _PR_LOCK(arena_list_lock);
- for (qp = arena_list.next; qp != &arena_list; qp = qp->next) {
- arena = ARENA_PTR(qp);
- lock = usnewlock(arena->usarena);
- if (lock != NULL) {
- lockp->lock = lock;
- lockp->arena = arena->usarena;
- break;
- }
- }
- if (lock == NULL) {
- /*
- * If no space left in the arena allocate a new one.
- */
- if (errno == ENOMEM) {
- arena = PR_NEWZAP(nspr_arena);
- if (arena != NULL) {
- irix_arena = alloc_new_arena();
- if (irix_arena) {
- PR_APPEND_LINK(&arena->links, &arena_list);
- _nspr_irix_arena_cnt++;
- arena->usarena = irix_arena;
- lock = usnewlock(irix_arena);
- if (lock != NULL) {
- lockp->lock = lock;
- lockp->arena = arena->usarena;
- } else
- rv = PR_FAILURE;
- } else {
- PR_DELETE(arena);
- rv = PR_FAILURE;
- }
-
- } else
- rv = PR_FAILURE;
- } else
- rv = PR_FAILURE;
- }
- _PR_UNLOCK(arena_list_lock);
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(_is);
- if (rv == PR_SUCCESS)
- _MD_ATOMIC_INCREMENT(&_nspr_irix_lock_cnt);
- return rv;
-}
-
-static void free_lock(struct _MDLock *lockp)
-{
-PRIntn _is;
-PRThread *me = _MD_GET_ATTACHED_THREAD();
-
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(_is);
- usfreelock(lockp->lock, lockp->arena);
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(_is);
- _MD_ATOMIC_DECREMENT(&_nspr_irix_lock_cnt);
-}
-
-void _MD_FREE_LOCK(struct _MDLock *lockp)
-{
- PRIntn _is;
- PRThread *me = _MD_GET_ATTACHED_THREAD();
-
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(_is);
- free_lock(lockp);
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(_is);
-}
-
-/*
- * _MD_get_attached_thread
- * Return the thread pointer of the current thread if it is attached.
- *
- * This function is needed for Irix because the thread-local-storage is
- * implemented by mmapin'g a page with the MAP_LOCAL flag. This causes the
- * sproc-private page to inherit contents of the page of the caller of sproc().
- */
-PRThread *_MD_get_attached_thread(void)
-{
-
- if (_MD_GET_SPROC_PID() == get_pid())
- return _MD_THIS_THREAD();
- else
- return 0;
-}
-
-/*
- * _MD_get_current_thread
- * Return the thread pointer of the current thread (attaching it if
- * necessary)
- */
-PRThread *_MD_get_current_thread(void)
-{
-PRThread *me;
-
- me = _MD_GET_ATTACHED_THREAD();
- if (NULL == me) {
- me = _PRI_AttachThread(
- PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL, 0);
- }
- PR_ASSERT(me != NULL);
- return(me);
-}
-
-/*
- * irix_detach_sproc
- * auto-detach a sproc when it exits
- */
-void irix_detach_sproc(void)
-{
-PRThread *me;
-
- me = _MD_GET_ATTACHED_THREAD();
- if ((me != NULL) && (me->flags & _PR_ATTACHED)) {
- _PRI_DetachThread();
- }
-}
-
-
-PRStatus _MD_NEW_LOCK(struct _MDLock *lockp)
-{
- PRStatus rv;
- PRIntn is;
- PRThread *me = _MD_GET_ATTACHED_THREAD();
-
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
- rv = new_lock(lockp);
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
- return rv;
-}
-
-static void
-sigchld_handler(int sig)
-{
- pid_t pid;
- int status;
-
- /*
- * If an sproc exited abnormally send a SIGKILL signal to all the
- * sprocs in the process to terminate the application
- */
- while ((pid = waitpid(0, &status, WNOHANG)) > 0) {
- if (WIFSIGNALED(status) && ((WTERMSIG(status) == SIGSEGV) ||
- (WTERMSIG(status) == SIGBUS) ||
- (WTERMSIG(status) == SIGABRT) ||
- (WTERMSIG(status) == SIGILL))) {
-
- prctl(PR_SETEXITSIG, SIGKILL);
- _exit(status);
- }
- }
-}
-
-static void save_context_and_block(int sig)
-{
-PRThread *me = _PR_MD_CURRENT_THREAD();
-_PRCPU *cpu = _PR_MD_CURRENT_CPU();
-
- /*
- * save context
- */
- (void) setjmp(me->md.jb);
- /*
- * unblock the suspending thread
- */
- if (me->cpu) {
- /*
- * I am a cpu thread, not a user-created GLOBAL thread
- */
- unblockproc(cpu->md.suspending_id);
- } else {
- unblockproc(me->md.suspending_id);
- }
- /*
- * now, block current thread
- */
- blockproc(getpid());
-}
-
-/*
-** The irix kernel has a bug in it which causes async connect's which are
-** interrupted by a signal to fail terribly (EADDRINUSE is returned).
-** We work around the bug by blocking signals during the async connect
-** attempt.
-*/
-PRInt32 _MD_irix_connect(
- PRInt32 osfd, const PRNetAddr *addr, PRInt32 addrlen, PRIntervalTime timeout)
-{
- PRInt32 rv;
- sigset_t oldset;
-
- sigprocmask(SIG_BLOCK, &ints_off, &oldset);
- rv = connect(osfd, addr, addrlen);
- sigprocmask(SIG_SETMASK, &oldset, 0);
-
- return(rv);
-}
-
-#include "prprf.h"
-
-/********************************************************************/
-/********************************************************************/
-/*************** Various thread like things for IRIX ****************/
-/********************************************************************/
-/********************************************************************/
-
-void *_MD_GetSP(PRThread *t)
-{
- PRThread *me = _PR_MD_CURRENT_THREAD();
- void *sp;
-
- if (me == t)
- (void) setjmp(t->md.jb);
-
- sp = (void *)(t->md.jb[JB_SP]);
- PR_ASSERT((sp >= (void *) t->stack->stackBottom) &&
- (sp <= (void *) (t->stack->stackBottom + t->stack->stackSize)));
- return(sp);
-}
-
-void _MD_InitLocks()
-{
- char buf[200];
- char *init_users, *init_size;
-
- PR_snprintf(buf, sizeof(buf), "/dev/zero");
-
- if (init_users = getenv("_NSPR_IRIX_INITUSERS"))
- _irix_initusers = atoi(init_users);
-
- if (init_size = getenv("_NSPR_IRIX_INITSIZE"))
- _irix_initsize = atoi(init_size);
-
- usconfig(CONF_INITUSERS, _irix_initusers);
- usconfig(CONF_INITSIZE, _irix_initsize);
- usconfig(CONF_AUTOGROW, 1);
- usconfig(CONF_AUTORESV, 1);
- if (usconfig(CONF_ARENATYPE, US_SHAREDONLY) < 0) {
- perror("PR_Init: unable to config mutex arena");
- exit(-1);
- }
-
- _pr_usArena = usinit(buf);
- if (!_pr_usArena) {
- fprintf(stderr,
- "PR_Init: Error - unable to create lock/monitor arena\n");
- exit(-1);
- }
- _pr_heapLock = usnewlock(_pr_usArena);
- _nspr_irix_lock_cnt++;
-
- arena_list_lock = usnewlock(_pr_usArena);
- _nspr_irix_lock_cnt++;
-
- sproc_list_lock = usnewlock(_pr_usArena);
- _nspr_irix_lock_cnt++;
-
- _pr_irix_exit_sem = usnewsema(_pr_usArena, 0);
- _nspr_irix_sem_cnt = 1;
-
- first_arena.usarena = _pr_usArena;
- PR_INIT_CLIST(&first_arena.links);
- PR_APPEND_LINK(&first_arena.links, &arena_list);
-}
-
-/* _PR_IRIX_CHILD_PROCESS is a private API for Server group */
-void _PR_IRIX_CHILD_PROCESS()
-{
-extern PRUint32 _pr_global_threads;
-
- PR_ASSERT(_PR_MD_CURRENT_CPU() == _pr_primordialCPU);
- PR_ASSERT(_pr_numCPU == 1);
- PR_ASSERT(_pr_global_threads == 0);
- /*
- * save the new pid
- */
- _pr_primordialCPU->md.id = getpid();
- _MD_SET_SPROC_PID(getpid());
-}
-
-static PRStatus pr_cvar_wait_sem(PRThread *thread, PRIntervalTime timeout)
-{
- int rv;
-
-#ifdef _PR_USE_POLL
- struct pollfd pfd;
- int msecs;
-
- if (timeout == PR_INTERVAL_NO_TIMEOUT)
- msecs = -1;
- else
- msecs = PR_IntervalToMilliseconds(timeout);
-#else
- struct timeval tv, *tvp;
- fd_set rd;
-
- if(timeout == PR_INTERVAL_NO_TIMEOUT)
- tvp = NULL;
- else {
- tv.tv_sec = PR_IntervalToSeconds(timeout);
- tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
- tvp = &tv;
- }
- FD_ZERO(&rd);
- FD_SET(thread->md.cvar_pollsemfd, &rd);
-#endif
-
- /*
- * call uspsema only if a previous select call on this semaphore
- * did not timeout
- */
- if (!thread->md.cvar_pollsem_select) {
- rv = _PR_WAIT_SEM(thread->md.cvar_pollsem);
- PR_ASSERT(rv >= 0);
- } else
- rv = 0;
-again:
- if(!rv) {
-#ifdef _PR_USE_POLL
- pfd.events = POLLIN;
- pfd.fd = thread->md.cvar_pollsemfd;
- rv = _MD_POLL(&pfd, 1, msecs);
-#else
- rv = _MD_SELECT(thread->md.cvar_pollsemfd + 1, &rd, NULL,NULL,tvp);
-#endif
- if ((rv == -1) && (errno == EINTR)) {
- rv = 0;
- goto again;
- }
- PR_ASSERT(rv >= 0);
- }
-
- if (rv > 0) {
- /*
- * acquired the semaphore, call uspsema next time
- */
- thread->md.cvar_pollsem_select = 0;
- return PR_SUCCESS;
- } else {
- /*
- * select timed out; must call select, not uspsema, when trying
- * to acquire the semaphore the next time
- */
- thread->md.cvar_pollsem_select = 1;
- return PR_FAILURE;
- }
-}
-
-PRStatus _MD_wait(PRThread *thread, PRIntervalTime ticks)
-{
- if ( thread->flags & _PR_GLOBAL_SCOPE ) {
- _MD_CHECK_FOR_EXIT();
- if (pr_cvar_wait_sem(thread, ticks) == PR_FAILURE) {
- _MD_CHECK_FOR_EXIT();
- /*
- * wait timed out
- */
- _PR_THREAD_LOCK(thread);
- if (thread->wait.cvar) {
- /*
- * The thread will remove itself from the waitQ
- * of the cvar in _PR_WaitCondVar
- */
- thread->wait.cvar = NULL;
- thread->state = _PR_RUNNING;
- _PR_THREAD_UNLOCK(thread);
- } else {
- _PR_THREAD_UNLOCK(thread);
- /*
- * This thread was woken up by a notifying thread
- * at the same time as a timeout; so, consume the
- * extra post operation on the semaphore
- */
- _MD_CHECK_FOR_EXIT();
- pr_cvar_wait_sem(thread, PR_INTERVAL_NO_TIMEOUT);
- }
- _MD_CHECK_FOR_EXIT();
- }
- } else {
- _PR_MD_SWITCH_CONTEXT(thread);
- }
- return PR_SUCCESS;
-}
-
-PRStatus _MD_WakeupWaiter(PRThread *thread)
-{
- PRThread *me = _PR_MD_CURRENT_THREAD();
- PRIntn is;
-
- PR_ASSERT(_pr_md_idle_cpus >= 0);
- if (thread == NULL) {
- if (_pr_md_idle_cpus)
- _MD_Wakeup_CPUs();
- } else if (!_PR_IS_NATIVE_THREAD(thread)) {
- if (_pr_md_idle_cpus)
- _MD_Wakeup_CPUs();
- } else {
- PR_ASSERT(_PR_IS_NATIVE_THREAD(thread));
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
- _MD_CVAR_POST_SEM(thread);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
- }
- return PR_SUCCESS;
-}
-
-void create_sproc (void (*entry) (void *, size_t), unsigned inh,
- void *arg, caddr_t sp, size_t len, int *pid)
-{
-sproc_params sparams;
-char data;
-int rv;
-PRThread *me = _PR_MD_CURRENT_THREAD();
-
- if (!_PR_IS_NATIVE_THREAD(me) && (_PR_MD_CURRENT_CPU()->id == 0)) {
- *pid = sprocsp(entry, /* startup func */
- inh, /* attribute flags */
- arg, /* thread param */
- sp, /* stack address */
- len); /* stack size */
- } else {
- sparams.sd.entry = entry;
- sparams.sd.inh = inh;
- sparams.sd.arg = arg;
- sparams.sd.sp = sp;
- sparams.sd.len = len;
- sparams.sd.pid = pid;
- sparams.sd.creator_pid = getpid();
- _PR_LOCK(sproc_list_lock);
- PR_APPEND_LINK(&sparams.links, &sproc_list);
- rv = write(_pr_irix_primoridal_cpu_fd[1], &data, 1);
- PR_ASSERT(rv == 1);
- _PR_UNLOCK(sproc_list_lock);
- blockproc(getpid());
- }
-}
-
-/*
- * _PR_MD_WAKEUP_PRIMORDIAL_CPU
- *
- * wakeup cpu 0
- */
-
-void _PR_MD_WAKEUP_PRIMORDIAL_CPU()
-{
-char data = '0';
-int rv;
-
- rv = write(_pr_irix_primoridal_cpu_fd[1], &data, 1);
- PR_ASSERT(rv == 1);
-}
-
-/*
- * _PR_MD_primordial_cpu
- *
- * process events that need to executed by the primordial cpu on each
- * iteration through the idle loop
- */
-
-void _PR_MD_primordial_cpu()
-{
-PRCList *qp;
-sproc_params *sp;
-int pid;
-
- _PR_LOCK(sproc_list_lock);
- while ((qp = sproc_list.next) != &sproc_list) {
- sp = SPROC_PARAMS_PTR(qp);
- PR_REMOVE_LINK(&sp->links);
- pid = sp->sd.creator_pid;
- (*(sp->sd.pid)) = sprocsp(sp->sd.entry, /* startup func */
- sp->sd.inh, /* attribute flags */
- sp->sd.arg, /* thread param */
- sp->sd.sp, /* stack address */
- sp->sd.len); /* stack size */
- unblockproc(pid);
- }
- _PR_UNLOCK(sproc_list_lock);
-}
-
-PRStatus _MD_CreateThread(PRThread *thread,
-void (*start)(void *),
-PRThreadPriority priority,
-PRThreadScope scope,
-PRThreadState state,
-PRUint32 stackSize)
-{
- typedef void (*SprocEntry) (void *, size_t);
- SprocEntry spentry = (SprocEntry)start;
- PRIntn is;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- PRInt32 pid;
- PRStatus rv;
-
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
- thread->md.cvar_pollsem_select = 0;
- thread->flags |= _PR_GLOBAL_SCOPE;
-
- thread->md.cvar_pollsemfd = -1;
- if (new_poll_sem(&thread->md,0) == PR_FAILURE) {
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
- return PR_FAILURE;
- }
- thread->md.cvar_pollsemfd =
- _PR_OPEN_POLL_SEM(thread->md.cvar_pollsem);
- if ((thread->md.cvar_pollsemfd < 0)) {
- free_poll_sem(&thread->md);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
- return PR_FAILURE;
- }
-
- create_sproc(spentry, /* startup func */
- PR_SALL, /* attribute flags */
- (void *)thread, /* thread param */
- NULL, /* stack address */
- stackSize, &pid); /* stack size */
- if (pid > 0) {
- _MD_ATOMIC_INCREMENT(&_pr_md_irix_sprocs_created);
- _MD_ATOMIC_INCREMENT(&_pr_md_irix_sprocs);
- rv = PR_SUCCESS;
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
- return rv;
- } else {
- close(thread->md.cvar_pollsemfd);
- thread->md.cvar_pollsemfd = -1;
- free_poll_sem(&thread->md);
- thread->md.cvar_pollsem = NULL;
- _MD_ATOMIC_INCREMENT(&_pr_md_irix_sprocs_failed);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
- return PR_FAILURE;
- }
-}
-
-void _MD_CleanThread(PRThread *thread)
-{
- if (thread->flags & _PR_GLOBAL_SCOPE) {
- close(thread->md.cvar_pollsemfd);
- thread->md.cvar_pollsemfd = -1;
- free_poll_sem(&thread->md);
- thread->md.cvar_pollsem = NULL;
- }
-}
-
-void _MD_SetPriority(_MDThread *thread, PRThreadPriority newPri)
-{
- return;
-}
-
-extern void _MD_unix_terminate_waitpid_daemon(void);
-
-void
-_MD_CleanupBeforeExit(void)
-{
- extern PRInt32 _pr_cpus_exit;
-
- _MD_unix_terminate_waitpid_daemon();
-
- _pr_irix_exit_now = 1;
- if (_pr_numCPU > 1) {
- /*
- * Set a global flag, and wakeup all cpus which will notice the flag
- * and exit.
- */
- _pr_cpus_exit = getpid();
- _MD_Wakeup_CPUs();
- while(_pr_numCPU > 1) {
- _PR_WAIT_SEM(_pr_irix_exit_sem);
- _pr_numCPU--;
- }
- }
- /*
- * cause global threads on the recycle list to exit
- */
- _PR_DEADQ_LOCK;
- if (_PR_NUM_DEADNATIVE != 0) {
- PRThread *thread;
- PRCList *ptr;
-
- ptr = _PR_DEADNATIVEQ.next;
- while( ptr != &_PR_DEADNATIVEQ ) {
- thread = _PR_THREAD_PTR(ptr);
- _MD_CVAR_POST_SEM(thread);
- ptr = ptr->next;
- }
- }
- _PR_DEADQ_UNLOCK;
- while(_PR_NUM_DEADNATIVE > 1) {
- _PR_WAIT_SEM(_pr_irix_exit_sem);
- _PR_DEC_DEADNATIVE;
- }
-}
-
-#ifdef _PR_HAVE_SGI_PRDA_PROCMASK
-extern void __sgi_prda_procmask(int);
-#endif
-
-PRStatus
-_MD_InitAttachedThread(PRThread *thread, PRBool wakeup_parent)
-{
- PRStatus rv = PR_SUCCESS;
-
- if (thread->flags & _PR_GLOBAL_SCOPE) {
- if (new_poll_sem(&thread->md,0) == PR_FAILURE) {
- return PR_FAILURE;
- }
- thread->md.cvar_pollsemfd =
- _PR_OPEN_POLL_SEM(thread->md.cvar_pollsem);
- if ((thread->md.cvar_pollsemfd < 0)) {
- free_poll_sem(&thread->md);
- return PR_FAILURE;
- }
- if (_MD_InitThread(thread, PR_FALSE) == PR_FAILURE) {
- close(thread->md.cvar_pollsemfd);
- thread->md.cvar_pollsemfd = -1;
- free_poll_sem(&thread->md);
- thread->md.cvar_pollsem = NULL;
- return PR_FAILURE;
- }
- }
- return rv;
-}
-
-PRStatus
-_MD_InitThread(PRThread *thread, PRBool wakeup_parent)
-{
- struct sigaction sigact;
- PRStatus rv = PR_SUCCESS;
-
- if (thread->flags & _PR_GLOBAL_SCOPE) {
- thread->md.id = getpid();
- setblockproccnt(thread->md.id, 0);
- _MD_SET_SPROC_PID(getpid());
-#ifdef _PR_HAVE_SGI_PRDA_PROCMASK
- /*
- * enable user-level processing of sigprocmask(); this is an
- * undocumented feature available in Irix 6.2, 6.3, 6.4 and 6.5
- */
- __sgi_prda_procmask(USER_LEVEL);
-#endif
- /*
- * set up SIGUSR1 handler; this is used to save state
- */
- sigact.sa_handler = save_context_and_block;
- sigact.sa_flags = SA_RESTART;
- /*
- * Must mask clock interrupts
- */
- sigact.sa_mask = timer_set;
- sigaction(SIGUSR1, &sigact, 0);
-
-
- /*
- * PR_SETABORTSIG is a new command implemented in a patch to
- * Irix 6.2, 6.3 and 6.4. This causes a signal to be sent to all
- * sprocs in the process when one of them terminates abnormally
- *
- */
- if (prctl(PR_SETABORTSIG, SIGKILL) < 0) {
- /*
- * if (errno == EINVAL)
- *
- * PR_SETABORTSIG not supported under this OS.
- * You may want to get a recent kernel rollup patch that
- * supports this feature.
- */
- }
- /*
- * SIGCLD handler for detecting abormally-terminating
- * sprocs and for reaping sprocs
- */
- sigact.sa_handler = sigchld_handler;
- sigact.sa_flags = SA_RESTART;
- sigact.sa_mask = ints_off;
- sigaction(SIGCLD, &sigact, NULL);
- }
- return rv;
-}
-
-/*
- * PR_Cleanup should be executed on the primordial sproc; migrate the thread
- * to the primordial cpu
- */
-
-void _PR_MD_PRE_CLEANUP(PRThread *me)
-{
-PRIntn is;
-_PRCPU *cpu = _pr_primordialCPU;
-
- PR_ASSERT(cpu);
-
- me->flags |= _PR_BOUND_THREAD;
-
- if (me->cpu->id != 0) {
- _PR_INTSOFF(is);
- _PR_RUNQ_LOCK(cpu);
- me->cpu = cpu;
- me->state = _PR_RUNNABLE;
- _PR_ADD_RUNQ(me, cpu, me->priority);
- _PR_RUNQ_UNLOCK(cpu);
- _MD_Wakeup_CPUs();
-
- _PR_MD_SWITCH_CONTEXT(me);
-
- _PR_FAST_INTSON(is);
- PR_ASSERT(me->cpu->id == 0);
- }
-}
-
-/*
- * process exiting
- */
-PR_EXTERN(void ) _MD_exit(PRIntn status)
-{
-PRThread *me = _PR_MD_CURRENT_THREAD();
-
- /*
- * the exit code of the process is the exit code of the primordial
- * sproc
- */
- if (!_PR_IS_NATIVE_THREAD(me) && (_PR_MD_CURRENT_CPU()->id == 0)) {
- /*
- * primordial sproc case: call _exit directly
- * Cause SIGKILL to be sent to other sprocs
- */
- prctl(PR_SETEXITSIG, SIGKILL);
- _exit(status);
- } else {
- int rv;
- char data;
- sigset_t set;
-
- /*
- * non-primordial sproc case: cause the primordial sproc, cpu 0,
- * to wakeup and call _exit
- */
- _pr_irix_process_exit = 1;
- _pr_irix_process_exit_code = status;
- rv = write(_pr_irix_primoridal_cpu_fd[1], &data, 1);
- PR_ASSERT(rv == 1);
- /*
- * block all signals and wait for SIGKILL to terminate this sproc
- */
- sigfillset(&set);
- sigsuspend(&set);
- /*
- * this code doesn't (shouldn't) execute
- */
- prctl(PR_SETEXITSIG, SIGKILL);
- _exit(status);
- }
-}
-
-/*
- * Override the exit() function in libc to cause the process to exit
- * when the primodial/main nspr thread calls exit. Calls to exit by any
- * other thread simply result in a call to the exit function in libc.
- * The exit code of the process is the exit code of the primordial
- * sproc.
- */
-
-void exit(int status)
-{
-PRThread *me, *thr;
-PRCList *qp;
-
- if (!_pr_initialized) {
- if (!libc_exit) {
-
- if (!libc_handle)
- libc_handle = dlopen("libc.so",RTLD_NOW);
- if (libc_handle)
- libc_exit = (void (*)(int)) dlsym(libc_handle, "exit");
- }
- if (libc_exit)
- (*libc_exit)(status);
- else
- _exit(status);
- }
-
- me = _PR_MD_CURRENT_THREAD();
-
- if (me == NULL) /* detached thread */
- (*libc_exit)(status);
-
- PR_ASSERT(_PR_IS_NATIVE_THREAD(me) ||
- (_PR_MD_CURRENT_CPU())->id == me->cpu->id);
-
- if (me->flags & _PR_PRIMORDIAL) {
-
- me->flags |= _PR_BOUND_THREAD;
-
- PR_ASSERT((_PR_MD_CURRENT_CPU())->id == me->cpu->id);
- if (me->cpu->id != 0) {
- _PRCPU *cpu = _pr_primordialCPU;
- PRIntn is;
-
- _PR_INTSOFF(is);
- _PR_RUNQ_LOCK(cpu);
- me->cpu = cpu;
- me->state = _PR_RUNNABLE;
- _PR_ADD_RUNQ(me, cpu, me->priority);
- _PR_RUNQ_UNLOCK(cpu);
- _MD_Wakeup_CPUs();
-
- _PR_MD_SWITCH_CONTEXT(me);
-
- _PR_FAST_INTSON(is);
- }
-
- PR_ASSERT((_PR_MD_CURRENT_CPU())->id == 0);
-
- if (prctl(PR_GETNSHARE) > 1) {
-#define SPROC_EXIT_WAIT_TIME 5
- int sleep_cnt = SPROC_EXIT_WAIT_TIME;
-
- /*
- * sprocs still running; caue cpus and recycled global threads
- * to exit
- */
- _pr_irix_exit_now = 1;
- if (_pr_numCPU > 1) {
- _MD_Wakeup_CPUs();
- }
- _PR_DEADQ_LOCK;
- if (_PR_NUM_DEADNATIVE != 0) {
- PRThread *thread;
- PRCList *ptr;
-
- ptr = _PR_DEADNATIVEQ.next;
- while( ptr != &_PR_DEADNATIVEQ ) {
- thread = _PR_THREAD_PTR(ptr);
- _MD_CVAR_POST_SEM(thread);
- ptr = ptr->next;
- }
- }
-
- while (sleep_cnt-- > 0) {
- if (waitpid(0, NULL, WNOHANG) >= 0)
- sleep(1);
- else
- break;
- }
- prctl(PR_SETEXITSIG, SIGKILL);
- }
- (*libc_exit)(status);
- } else {
- /*
- * non-primordial thread; simply call exit in libc.
- */
- (*libc_exit)(status);
- }
-}
-
-
-void
-_MD_InitRunningCPU(_PRCPU *cpu)
-{
- extern int _pr_md_pipefd[2];
-
- _MD_unix_init_running_cpu(cpu);
- cpu->md.id = getpid();
- _MD_SET_SPROC_PID(getpid());
- if (_pr_md_pipefd[0] >= 0) {
- _PR_IOQ_MAX_OSFD(cpu) = _pr_md_pipefd[0];
-#ifndef _PR_USE_POLL
- FD_SET(_pr_md_pipefd[0], &_PR_FD_READ_SET(cpu));
-#endif
- }
-}
-
-void
-_MD_ExitThread(PRThread *thread)
-{
- if (thread->flags & _PR_GLOBAL_SCOPE) {
- _MD_ATOMIC_DECREMENT(&_pr_md_irix_sprocs);
- _MD_CLEAN_THREAD(thread);
- _MD_SET_CURRENT_THREAD(NULL);
- }
-}
-
-void
-_MD_SuspendCPU(_PRCPU *cpu)
-{
- PRInt32 rv;
-
- cpu->md.suspending_id = getpid();
- rv = kill(cpu->md.id, SIGUSR1);
- PR_ASSERT(rv == 0);
- /*
- * now, block the current thread/cpu until woken up by the suspended
- * thread from it's SIGUSR1 signal handler
- */
- blockproc(getpid());
-
-}
-
-void
-_MD_ResumeCPU(_PRCPU *cpu)
-{
- unblockproc(cpu->md.id);
-}
-
-#if 0
-/*
- * save the register context of a suspended sproc
- */
-void get_context(PRThread *thr)
-{
- int len, fd;
- char pidstr[24];
- char path[24];
-
- /*
- * open the file corresponding to this process in procfs
- */
- sprintf(path,"/proc/%s","00000");
- len = strlen(path);
- sprintf(pidstr,"%d",thr->md.id);
- len -= strlen(pidstr);
- sprintf(path + len,"%s",pidstr);
- fd = open(path,O_RDONLY);
- if (fd >= 0) {
- (void) ioctl(fd, PIOCGREG, thr->md.gregs);
- close(fd);
- }
- return;
-}
-#endif /* 0 */
-
-void
-_MD_SuspendThread(PRThread *thread)
-{
- PRInt32 rv;
-
- PR_ASSERT((thread->flags & _PR_GLOBAL_SCOPE) &&
- _PR_IS_GCABLE_THREAD(thread));
-
- thread->md.suspending_id = getpid();
- rv = kill(thread->md.id, SIGUSR1);
- PR_ASSERT(rv == 0);
- /*
- * now, block the current thread/cpu until woken up by the suspended
- * thread from it's SIGUSR1 signal handler
- */
- blockproc(getpid());
-}
-
-void
-_MD_ResumeThread(PRThread *thread)
-{
- PR_ASSERT((thread->flags & _PR_GLOBAL_SCOPE) &&
- _PR_IS_GCABLE_THREAD(thread));
- (void)unblockproc(thread->md.id);
-}
-
-/*
- * return the set of processors available for scheduling procs in the
- * "mask" argument
- */
-PRInt32 _MD_GetThreadAffinityMask(PRThread *unused, PRUint32 *mask)
-{
- PRInt32 nprocs, rv;
- struct pda_stat *pstat;
-#define MAX_PROCESSORS 32
-
- nprocs = sysmp(MP_NPROCS);
- if (nprocs < 0)
- return(-1);
- pstat = (struct pda_stat*)PR_MALLOC(sizeof(struct pda_stat) * nprocs);
- if (pstat == NULL)
- return(-1);
- rv = sysmp(MP_STAT, pstat);
- if (rv < 0) {
- PR_DELETE(pstat);
- return(-1);
- }
- /*
- * look at the first 32 cpus
- */
- nprocs = (nprocs > MAX_PROCESSORS) ? MAX_PROCESSORS : nprocs;
- *mask = 0;
- while (nprocs) {
- if ((pstat->p_flags & PDAF_ENABLED) &&
- !(pstat->p_flags & PDAF_ISOLATED)) {
- *mask |= (1 << pstat->p_cpuid);
- }
- nprocs--;
- pstat++;
- }
- return 0;
-}
-
-static char *_thr_state[] = {
- "UNBORN",
- "RUNNABLE",
- "RUNNING",
- "LOCK_WAIT",
- "COND_WAIT",
- "JOIN_WAIT",
- "IO_WAIT",
- "SUSPENDED",
- "DEAD"
-};
-
-void _PR_List_Threads()
-{
- PRThread *thr;
- void *handle;
- struct _PRCPU *cpu;
- PRCList *qp;
- int len, fd;
- char pidstr[24];
- char path[24];
- prpsinfo_t pinfo;
-
-
- printf("\n%s %-s\n"," ","LOCAL Threads");
- printf("%s %-s\n"," ","----- -------");
- printf("%s %-14s %-10s %-12s %-3s %-10s %-10s %-12s\n\n"," ",
- "Thread", "State", "Wait-Handle",
- "Cpu","Stk-Base","Stk-Sz","SP");
- for (qp = _PR_ACTIVE_LOCAL_THREADQ().next;
- qp != &_PR_ACTIVE_LOCAL_THREADQ(); qp = qp->next) {
- thr = _PR_ACTIVE_THREAD_PTR(qp);
- printf("%s 0x%-12x %-10s "," ",thr,_thr_state[thr->state]);
- if (thr->state == _PR_LOCK_WAIT)
- handle = thr->wait.lock;
- else if (thr->state == _PR_COND_WAIT)
- handle = thr->wait.cvar;
- else
- handle = NULL;
- if (handle)
- printf("0x%-10x ",handle);
- else
- printf("%-12s "," ");
- printf("%-3d ",thr->cpu->id);
- printf("0x%-8x ",thr->stack->stackBottom);
- printf("0x%-8x ",thr->stack->stackSize);
- printf("0x%-10x\n",thr->md.jb[JB_SP]);
- }
-
- printf("\n%s %-s\n"," ","GLOBAL Threads");
- printf("%s %-s\n"," ","------ -------");
- printf("%s %-14s %-6s %-12s %-12s %-12s %-12s\n\n"," ","Thread",
- "Pid","State","Wait-Handle",
- "Stk-Base","Stk-Sz");
-
- for (qp = _PR_ACTIVE_GLOBAL_THREADQ().next;
- qp != &_PR_ACTIVE_GLOBAL_THREADQ(); qp = qp->next) {
- thr = _PR_ACTIVE_THREAD_PTR(qp);
- if (thr->cpu != NULL)
- continue; /* it is a cpu thread */
- printf("%s 0x%-12x %-6d "," ",thr,thr->md.id);
- /*
- * check if the sproc is still running
- * first call prctl(PR_GETSHMASK,pid) to check if
- * the process is part of the share group (the pid
- * could have been recycled by the OS)
- */
- if (prctl(PR_GETSHMASK,thr->md.id) < 0) {
- printf("%-12s\n","TERMINATED");
- continue;
- }
- /*
- * Now, check if the sproc terminated and is in zombie
- * state
- */
- sprintf(path,"/proc/pinfo/%s","00000");
- len = strlen(path);
- sprintf(pidstr,"%d",thr->md.id);
- len -= strlen(pidstr);
- sprintf(path + len,"%s",pidstr);
- fd = open(path,O_RDONLY);
- if (fd >= 0) {
- if (ioctl(fd, PIOCPSINFO, &pinfo) < 0)
- printf("%-12s ","TERMINATED");
- else if (pinfo.pr_zomb)
- printf("%-12s ","TERMINATED");
- else
- printf("%-12s ",_thr_state[thr->state]);
- close(fd);
- } else {
- printf("%-12s ","TERMINATED");
- }
-
- if (thr->state == _PR_LOCK_WAIT)
- handle = thr->wait.lock;
- else if (thr->state == _PR_COND_WAIT)
- handle = thr->wait.cvar;
- else
- handle = NULL;
- if (handle)
- printf("%-12x ",handle);
- else
- printf("%-12s "," ");
- printf("0x%-10x ",thr->stack->stackBottom);
- printf("0x%-10x\n",thr->stack->stackSize);
- }
-
- printf("\n%s %-s\n"," ","CPUs");
- printf("%s %-s\n"," ","----");
- printf("%s %-14s %-6s %-12s \n\n"," ","Id","Pid","State");
-
-
- for (qp = _PR_CPUQ().next; qp != &_PR_CPUQ(); qp = qp->next) {
- cpu = _PR_CPU_PTR(qp);
- printf("%s %-14d %-6d "," ",cpu->id,cpu->md.id);
- /*
- * check if the sproc is still running
- * first call prctl(PR_GETSHMASK,pid) to check if
- * the process is part of the share group (the pid
- * could have been recycled by the OS)
- */
- if (prctl(PR_GETSHMASK,cpu->md.id) < 0) {
- printf("%-12s\n","TERMINATED");
- continue;
- }
- /*
- * Now, check if the sproc terminated and is in zombie
- * state
- */
- sprintf(path,"/proc/pinfo/%s","00000");
- len = strlen(path);
- sprintf(pidstr,"%d",cpu->md.id);
- len -= strlen(pidstr);
- sprintf(path + len,"%s",pidstr);
- fd = open(path,O_RDONLY);
- if (fd >= 0) {
- if (ioctl(fd, PIOCPSINFO, &pinfo) < 0)
- printf("%-12s\n","TERMINATED");
- else if (pinfo.pr_zomb)
- printf("%-12s\n","TERMINATED");
- else
- printf("%-12s\n","RUNNING");
- close(fd);
- } else {
- printf("%-12s\n","TERMINATED");
- }
-
- }
- fflush(stdout);
-}
-#endif /* defined(_PR_PTHREADS) */
-
-PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
-{
-#if !defined(_PR_PTHREADS)
- if (isCurrent) {
- (void) setjmp(t->md.jb);
- }
- *np = sizeof(t->md.jb) / sizeof(PRWord);
- return (PRWord *) (t->md.jb);
-#else
- *np = 0;
- return NULL;
-#endif
-}
-
-void _MD_EarlyInit(void)
-{
-#if !defined(_PR_PTHREADS)
- char *eval;
- int fd;
- extern int __ateachexit(void (*func)(void));
-
- sigemptyset(&ints_off);
- sigaddset(&ints_off, SIGALRM);
- sigaddset(&ints_off, SIGIO);
- sigaddset(&ints_off, SIGCLD);
-
- if (eval = getenv("_NSPR_TERMINATE_ON_ERROR"))
- _nspr_terminate_on_error = (0 == atoi(eval) == 0) ? PR_FALSE : PR_TRUE;
-
- fd = open("/dev/zero",O_RDWR , 0);
- if (fd < 0) {
- perror("open /dev/zero failed");
- exit(1);
- }
- /*
- * Set up the sproc private data area.
- * This region exists at the same address, _nspr_sproc_private, for
- * every sproc, but each sproc gets a private copy of the region.
- */
- _nspr_sproc_private = (char*)mmap(0, _pr_pageSize, PROT_READ | PROT_WRITE,
- MAP_PRIVATE| MAP_LOCAL, fd, 0);
- if (_nspr_sproc_private == (void*)-1) {
- perror("mmap /dev/zero failed");
- exit(1);
- }
- _MD_SET_SPROC_PID(getpid());
- close(fd);
- __ateachexit(irix_detach_sproc);
-#endif
- _MD_IrixIntervalInit();
-} /* _MD_EarlyInit */
-
-void _MD_IrixInit(void)
-{
-#if !defined(_PR_PTHREADS)
- struct sigaction sigact;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- int rv;
-
-#ifdef _PR_HAVE_SGI_PRDA_PROCMASK
- /*
- * enable user-level processing of sigprocmask(); this is an undocumented
- * feature available in Irix 6.2, 6.3, 6.4 and 6.5
- */
- __sgi_prda_procmask(USER_LEVEL);
-#endif
-
- /*
- * set up SIGUSR1 handler; this is used to save state
- * during PR_SuspendAll
- */
- sigact.sa_handler = save_context_and_block;
- sigact.sa_flags = SA_RESTART;
- sigact.sa_mask = ints_off;
- sigaction(SIGUSR1, &sigact, 0);
-
- /*
- * Change the name of the core file from core to core.pid,
- * This is inherited by the sprocs created by this process
- */
-#ifdef PR_COREPID
- prctl(PR_COREPID, 0, 1);
-#endif
- /*
- * Irix-specific terminate on error processing
- */
- /*
- * PR_SETABORTSIG is a new command implemented in a patch to
- * Irix 6.2, 6.3 and 6.4. This causes a signal to be sent to all
- * sprocs in the process when one of them terminates abnormally
- *
- */
- if (prctl(PR_SETABORTSIG, SIGKILL) < 0) {
- /*
- * if (errno == EINVAL)
- *
- * PR_SETABORTSIG not supported under this OS.
- * You may want to get a recent kernel rollup patch that
- * supports this feature.
- *
- */
- }
- /*
- * PR_SETEXITSIG - send the SIGCLD signal to the parent
- * sproc when any sproc terminates
- *
- * This is used to cause the entire application to
- * terminate when any sproc terminates abnormally by
- * receipt of a SIGSEGV, SIGBUS or SIGABRT signal.
- * If this is not done, the application may seem
- * "hung" to the user because the other sprocs may be
- * waiting for resources held by the
- * abnormally-terminating sproc.
- */
- prctl(PR_SETEXITSIG, 0);
-
- sigact.sa_handler = sigchld_handler;
- sigact.sa_flags = SA_RESTART;
- sigact.sa_mask = ints_off;
- sigaction(SIGCLD, &sigact, NULL);
-
- /*
- * setup stack fields for the primordial thread
- */
- me->stack->stackSize = prctl(PR_GETSTACKSIZE);
- me->stack->stackBottom = me->stack->stackTop - me->stack->stackSize;
-
- rv = pipe(_pr_irix_primoridal_cpu_fd);
- PR_ASSERT(rv == 0);
-#ifndef _PR_USE_POLL
- _PR_IOQ_MAX_OSFD(me->cpu) = _pr_irix_primoridal_cpu_fd[0];
- FD_SET(_pr_irix_primoridal_cpu_fd[0], &_PR_FD_READ_SET(me->cpu));
-#endif
-
- libc_handle = dlopen("libc.so",RTLD_NOW);
- PR_ASSERT(libc_handle != NULL);
- libc_exit = (void (*)(int)) dlsym(libc_handle, "exit");
- PR_ASSERT(libc_exit != NULL);
- /* dlclose(libc_handle); */
-
-#endif /* _PR_PTHREADS */
-
- _PR_UnixInit();
-}
-
-/**************************************************************************/
-/************** code and such for NSPR 2.0's interval times ***************/
-/**************************************************************************/
-
-#define PR_PSEC_PER_SEC 1000000000000ULL /* 10^12 */
-
-#ifndef SGI_CYCLECNTR_SIZE
-#define SGI_CYCLECNTR_SIZE 165 /* Size user needs to use to read CC */
-#endif
-
-static PRIntn mmem_fd = -1;
-static PRIntn clock_width = 0;
-static void *iotimer_addr = NULL;
-static PRUint32 pr_clock_mask = 0;
-static PRUint32 pr_clock_shift = 0;
-static PRIntervalTime pr_ticks = 0;
-static PRUint32 pr_clock_granularity = 1;
-static PRUint32 pr_previous = 0, pr_residual = 0;
-static PRUint32 pr_ticks_per_second = 0;
-
-extern PRIntervalTime _PR_UNIX_GetInterval(void);
-extern PRIntervalTime _PR_UNIX_TicksPerSecond(void);
-
-static void _MD_IrixIntervalInit(void)
-{
- /*
- * As much as I would like, the service available through this
- * interface on R3000's (aka, IP12) just isn't going to make it.
- * The register is only 24 bits wide, and rolls over at a verocious
- * rate.
- */
- PRUint32 one_tick = 0;
- struct utsname utsinfo;
- uname(&utsinfo);
- if ((strncmp("IP12", utsinfo.machine, 4) != 0)
- && ((mmem_fd = open("/dev/mmem", O_RDONLY)) != -1))
- {
- int poffmask = getpagesize() - 1;
- __psunsigned_t phys_addr, raddr, cycleval;
-
- phys_addr = syssgi(SGI_QUERY_CYCLECNTR, &cycleval);
- raddr = phys_addr & ~poffmask;
- iotimer_addr = mmap(
- 0, poffmask, PROT_READ, MAP_PRIVATE, mmem_fd, (__psint_t)raddr);
-
- clock_width = syssgi(SGI_CYCLECNTR_SIZE);
- if (clock_width < 0)
- {
- /*
- * We must be executing on a 6.0 or earlier system, since the
- * SGI_CYCLECNTR_SIZE call is not supported.
- *
- * The only pre-6.1 platforms with 64-bit counters are
- * IP19 and IP21 (Challenge, PowerChallenge, Onyx).
- */
- if (!strncmp(utsinfo.machine, "IP19", 4) ||
- !strncmp(utsinfo.machine, "IP21", 4))
- clock_width = 64;
- else
- clock_width = 32;
- }
-
- /*
- * 'cycleval' is picoseconds / increment of the counter.
- * I'm pushing for a tick to be 100 microseconds, 10^(-4).
- * That leaves 10^(-8) left over, or 10^8 / cycleval.
- * Did I do that right?
- */
-
- one_tick = 100000000UL / cycleval ; /* 100 microseconds */
-
- while (0 != one_tick)
- {
- pr_clock_shift += 1;
- one_tick = one_tick >> 1;
- pr_clock_granularity = pr_clock_granularity << 1;
- }
- pr_clock_mask = pr_clock_granularity - 1; /* to make a mask out of it */
- pr_ticks_per_second = PR_PSEC_PER_SEC
- / ((PRUint64)pr_clock_granularity * (PRUint64)cycleval);
-
- iotimer_addr = (void*)
- ((__psunsigned_t)iotimer_addr + (phys_addr & poffmask));
- }
- else
- {
- pr_ticks_per_second = _PR_UNIX_TicksPerSecond();
- }
-} /* _MD_IrixIntervalInit */
-
-PRIntervalTime _MD_IrixIntervalPerSec(void)
-{
- return pr_ticks_per_second;
-}
-
-PRIntervalTime _MD_IrixGetInterval(void)
-{
- if (mmem_fd != -1)
- {
- if (64 == clock_width)
- {
- PRUint64 temp = *(PRUint64*)iotimer_addr;
- pr_ticks = (PRIntervalTime)(temp >> pr_clock_shift);
- }
- else
- {
- PRIntervalTime ticks = pr_ticks;
- PRUint32 now = *(PRUint32*)iotimer_addr, temp;
- PRUint32 residual = pr_residual, previous = pr_previous;
-
- temp = now - previous + residual;
- residual = temp & pr_clock_mask;
- ticks += temp >> pr_clock_shift;
-
- pr_previous = now;
- pr_residual = residual;
- pr_ticks = ticks;
- }
- }
- else
- {
- /*
- * No fast access. Use the time of day clock. This isn't the
- * right answer since this clock can get set back, tick at odd
- * rates, and it's expensive to acqurie.
- */
- pr_ticks = _PR_UNIX_GetInterval();
- }
- return pr_ticks;
-} /* _MD_IrixGetInterval */
-
diff --git a/nsprpub/pr/src/md/unix/linux.c b/nsprpub/pr/src/md/unix/linux.c
index 1b485a024..6bfc7a802 100644
--- a/nsprpub/pr/src/md/unix/linux.c
+++ b/nsprpub/pr/src/md/unix/linux.c
@@ -13,13 +13,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#ifndef _PR_PTHREADS
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
#else
- *np = 0;
- return NULL;
+ *np = 0;
+ return NULL;
#endif
}
@@ -43,13 +43,13 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- /*
- * set the pointers to the stack-pointer and frame-pointer words in the
- * context structure; this is for debugging use.
- */
- thread->md.sp = _MD_GET_SP_PTR(thread);
- thread->md.fp = _MD_GET_FP_PTR(thread);
- return PR_SUCCESS;
+ /*
+ * set the pointers to the stack-pointer and frame-pointer words in the
+ * context structure; this is for debugging use.
+ */
+ thread->md.sp = _MD_GET_SP_PTR(thread);
+ thread->md.fp = _MD_GET_FP_PTR(thread);
+ return PR_SUCCESS;
}
PRStatus
@@ -64,7 +64,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
@@ -86,6 +86,6 @@ _MD_CREATE_THREAD(
PRUint32 stackSize)
{
PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for Linux.");
- return PR_FAILURE;
+ return PR_FAILURE;
}
#endif /* ! _PR_PTHREADS */
diff --git a/nsprpub/pr/src/md/unix/nto.c b/nsprpub/pr/src/md/unix/nto.c
index e41d665ca..8ab8b1eab 100644
--- a/nsprpub/pr/src/md/unix/nto.c
+++ b/nsprpub/pr/src/md/unix/nto.c
@@ -10,8 +10,8 @@
/* Fake this out */
int socketpair (int foo, int foo2, int foo3, int sv[2])
{
- printf("error in socketpair\n");
- exit (-1);
+ printf("error in socketpair\n");
+ exit (-1);
}
void _MD_EarlyInit(void)
@@ -22,13 +22,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#ifndef _PR_PTHREADS
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
#else
- *np = 0;
- return NULL;
+ *np = 0;
+ return NULL;
#endif
}
diff --git a/nsprpub/pr/src/md/unix/os_Irix.s b/nsprpub/pr/src/md/unix/os_Irix.s
deleted file mode 100644
index ab1cb0b30..000000000
--- a/nsprpub/pr/src/md/unix/os_Irix.s
+++ /dev/null
@@ -1,134 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/*
- * Atomically add a new element to the top of the stack
- *
- * usage : PR_StackPush(listp, elementp);
- * -----------------------
- */
-
-#include "md/_irix.h"
-#ifdef _PR_HAVE_ATOMIC_CAS
-
-#include <sys/asm.h>
-#include <sys/regdef.h>
-
-LEAF(PR_StackPush)
-
-retry_push:
-.set noreorder
- lw v0,0(a0)
- li t1,1
- beq v0,t1,retry_push
- move t0,a1
-
- ll v0,0(a0)
- beq v0,t1,retry_push
- nop
- sc t1,0(a0)
- beq t1,0,retry_push
- nop
- sw v0,0(a1)
- sync
- sw t0,0(a0)
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- jr ra
- nop
-
-END(PR_StackPush)
-
-/*
- *
- * Atomically remove the element at the top of the stack
- *
- * usage : elemep = PR_StackPop(listp);
- *
- */
-
-LEAF(PR_StackPop)
-retry_pop:
-.set noreorder
-
-
- lw v0,0(a0)
- li t1,1
- beq v0,0,done
- nop
- beq v0,t1,retry_pop
- nop
-
- ll v0,0(a0)
- beq v0,0,done
- nop
- beq v0,t1,retry_pop
- nop
- sc t1,0(a0)
- beq t1,0,retry_pop
- nop
- lw t0,0(v0)
- sw t0,0(a0)
-done:
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- jr ra
- nop
-
-END(PR_StackPop)
-
-#endif /* _PR_HAVE_ATOMIC_CAS */
diff --git a/nsprpub/pr/src/md/unix/osf1.c b/nsprpub/pr/src/md/unix/osf1.c
deleted file mode 100644
index a9a1c67d0..000000000
--- a/nsprpub/pr/src/md/unix/osf1.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-void _MD_EarlyInit(void)
-{
-}
-
-PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
-{
-#ifndef _PR_PTHREADS
- if (isCurrent) {
- (void) setjmp(CONTEXT(t));
- }
- *np = sizeof(CONTEXT(t)) / sizeof(PRWord);
- return (PRWord *) CONTEXT(t);
-#else
- *np = 0;
- return NULL;
-#endif
-}
-
-#ifndef _PR_PTHREADS
-void
-_MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
-{
- return;
-}
-
-PRStatus
-_MD_InitializeThread(PRThread *thread)
-{
- return PR_SUCCESS;
-}
-
-PRStatus
-_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
-{
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
- _PR_MD_SWITCH_CONTEXT(thread);
- return PR_SUCCESS;
-}
-
-PRStatus
-_MD_WAKEUP_WAITER(PRThread *thread)
-{
- if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
- }
- return PR_SUCCESS;
-}
-
-/* These functions should not be called for OSF1 */
-void
-_MD_YIELD(void)
-{
- PR_NOT_REACHED("_MD_YIELD should not be called for OSF1.");
-}
-
-PRStatus
-_MD_CREATE_THREAD(
- PRThread *thread,
- void (*start) (void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
-{
- PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for OSF1.");
- return PR_FAILURE;
-}
-#endif /* ! _PR_PTHREADS */
diff --git a/nsprpub/pr/src/md/unix/pthreads_user.c b/nsprpub/pr/src/md/unix/pthreads_user.c
index bb64b9f44..525c1576f 100644
--- a/nsprpub/pr/src/md/unix/pthreads_user.c
+++ b/nsprpub/pr/src/md/unix/pthreads_user.c
@@ -11,7 +11,7 @@
sigset_t ints_off;
-pthread_mutex_t _pr_heapLock;
+pthread_mutex_t _pr_heapLock;
pthread_key_t current_thread_key;
pthread_key_t current_cpu_key;
pthread_key_t last_thread_key;
@@ -23,55 +23,57 @@ PRInt32 _pr_md_pthreads = 1;
void _MD_EarlyInit(void)
{
-extern PRInt32 _nspr_noclock;
-
- if (pthread_key_create(&current_thread_key, NULL) != 0) {
- perror("pthread_key_create failed");
- exit(1);
- }
- if (pthread_key_create(&current_cpu_key, NULL) != 0) {
- perror("pthread_key_create failed");
- exit(1);
- }
- if (pthread_key_create(&last_thread_key, NULL) != 0) {
- perror("pthread_key_create failed");
- exit(1);
- }
- if (pthread_key_create(&intsoff_key, NULL) != 0) {
- perror("pthread_key_create failed");
- exit(1);
- }
-
- sigemptyset(&ints_off);
- sigaddset(&ints_off, SIGALRM);
- sigaddset(&ints_off, SIGIO);
- sigaddset(&ints_off, SIGCLD);
-
- /*
- * disable clock interrupts
- */
- _nspr_noclock = 1;
+ extern PRInt32 _nspr_noclock;
+
+ if (pthread_key_create(&current_thread_key, NULL) != 0) {
+ perror("pthread_key_create failed");
+ exit(1);
+ }
+ if (pthread_key_create(&current_cpu_key, NULL) != 0) {
+ perror("pthread_key_create failed");
+ exit(1);
+ }
+ if (pthread_key_create(&last_thread_key, NULL) != 0) {
+ perror("pthread_key_create failed");
+ exit(1);
+ }
+ if (pthread_key_create(&intsoff_key, NULL) != 0) {
+ perror("pthread_key_create failed");
+ exit(1);
+ }
+
+ sigemptyset(&ints_off);
+ sigaddset(&ints_off, SIGALRM);
+ sigaddset(&ints_off, SIGIO);
+ sigaddset(&ints_off, SIGCLD);
+
+ /*
+ * disable clock interrupts
+ */
+ _nspr_noclock = 1;
}
void _MD_InitLocks()
{
- if (pthread_mutex_init(&_pr_heapLock, NULL) != 0) {
- perror("pthread_mutex_init failed");
- exit(1);
- }
+ if (pthread_mutex_init(&_pr_heapLock, NULL) != 0) {
+ perror("pthread_mutex_init failed");
+ exit(1);
+ }
}
PR_IMPLEMENT(void) _MD_FREE_LOCK(struct _MDLock *lockp)
{
- PRIntn _is;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(_is);
- pthread_mutex_destroy(&lockp->mutex);
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(_is);
+ PRIntn _is;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+
+ if (me && !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(_is);
+ }
+ pthread_mutex_destroy(&lockp->mutex);
+ if (me && !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(_is);
+ }
}
@@ -80,21 +82,23 @@ PR_IMPLEMENT(PRStatus) _MD_NEW_LOCK(struct _MDLock *lockp)
{
PRStatus rv;
PRIntn is;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
- rv = pthread_mutex_init(&lockp->mutex, NULL);
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
- return (rv == 0) ? PR_SUCCESS : PR_FAILURE;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+
+ if (me && !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
+ rv = pthread_mutex_init(&lockp->mutex, NULL);
+ if (me && !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
+ return (rv == 0) ? PR_SUCCESS : PR_FAILURE;
}
PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
@@ -103,9 +107,9 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
PR_IMPLEMENT(void)
_MD_SetPriority(_MDThread *thread, PRThreadPriority newPri)
{
- /*
- * XXX - to be implemented
- */
+ /*
+ * XXX - to be implemented
+ */
return;
}
@@ -116,17 +120,17 @@ PR_IMPLEMENT(PRStatus) _MD_InitThread(struct PRThread *thread)
if (thread->flags & _PR_GLOBAL_SCOPE) {
thread->md.pthread = pthread_self();
#if 0
- /*
- * set up SIGUSR1 handler; this is used to save state
- * during PR_SuspendAll
- */
- sigact.sa_handler = save_context_and_block;
- sigact.sa_flags = SA_RESTART;
- /*
- * Must mask clock interrupts
- */
- sigact.sa_mask = timer_set;
- sigaction(SIGUSR1, &sigact, 0);
+ /*
+ * set up SIGUSR1 handler; this is used to save state
+ * during PR_SuspendAll
+ */
+ sigact.sa_handler = save_context_and_block;
+ sigact.sa_flags = SA_RESTART;
+ /*
+ * Must mask clock interrupts
+ */
+ sigact.sa_mask = timer_set;
+ sigaction(SIGUSR1, &sigact, 0);
#endif
}
@@ -144,8 +148,8 @@ PR_IMPLEMENT(void) _MD_ExitThread(struct PRThread *thread)
PR_IMPLEMENT(void) _MD_CleanThread(struct PRThread *thread)
{
if (thread->flags & _PR_GLOBAL_SCOPE) {
- pthread_mutex_destroy(&thread->md.pthread_mutex);
- pthread_cond_destroy(&thread->md.pthread_cond);
+ pthread_mutex_destroy(&thread->md.pthread_mutex);
+ pthread_cond_destroy(&thread->md.pthread_cond);
}
}
@@ -154,16 +158,16 @@ PR_IMPLEMENT(void) _MD_SuspendThread(struct PRThread *thread)
PRInt32 rv;
PR_ASSERT((thread->flags & _PR_GLOBAL_SCOPE) &&
- _PR_IS_GCABLE_THREAD(thread));
+ _PR_IS_GCABLE_THREAD(thread));
#if 0
- thread->md.suspending_id = getpid();
- rv = kill(thread->md.id, SIGUSR1);
- PR_ASSERT(rv == 0);
- /*
- * now, block the current thread/cpu until woken up by the suspended
- * thread from it's SIGUSR1 signal handler
- */
- blockproc(getpid());
+ thread->md.suspending_id = getpid();
+ rv = kill(thread->md.id, SIGUSR1);
+ PR_ASSERT(rv == 0);
+ /*
+ * now, block the current thread/cpu until woken up by the suspended
+ * thread from it's SIGUSR1 signal handler
+ */
+ blockproc(getpid());
#endif
}
@@ -172,7 +176,7 @@ PR_IMPLEMENT(void) _MD_ResumeThread(struct PRThread *thread)
PRInt32 rv;
PR_ASSERT((thread->flags & _PR_GLOBAL_SCOPE) &&
- _PR_IS_GCABLE_THREAD(thread));
+ _PR_IS_GCABLE_THREAD(thread));
#if 0
rv = unblockproc(thread->md.id);
#endif
@@ -183,21 +187,21 @@ PR_IMPLEMENT(void) _MD_SuspendCPU(struct _PRCPU *thread)
PRInt32 rv;
#if 0
- cpu->md.suspending_id = getpid();
- rv = kill(cpu->md.id, SIGUSR1);
- PR_ASSERT(rv == 0);
- /*
- * now, block the current thread/cpu until woken up by the suspended
- * thread from it's SIGUSR1 signal handler
- */
- blockproc(getpid());
+ cpu->md.suspending_id = getpid();
+ rv = kill(cpu->md.id, SIGUSR1);
+ PR_ASSERT(rv == 0);
+ /*
+ * now, block the current thread/cpu until woken up by the suspended
+ * thread from it's SIGUSR1 signal handler
+ */
+ blockproc(getpid());
#endif
}
PR_IMPLEMENT(void) _MD_ResumeCPU(struct _PRCPU *thread)
{
#if 0
- unblockproc(cpu->md.id);
+ unblockproc(cpu->md.id);
#endif
}
@@ -208,54 +212,55 @@ PR_IMPLEMENT(void) _MD_ResumeCPU(struct _PRCPU *thread)
PR_IMPLEMENT(PRStatus)
_pt_wait(PRThread *thread, PRIntervalTime timeout)
{
-int rv;
-struct timeval now;
-struct timespec tmo;
-PRUint32 ticks = PR_TicksPerSecond();
-
-
- if (timeout != PR_INTERVAL_NO_TIMEOUT) {
- tmo.tv_sec = timeout / ticks;
- tmo.tv_nsec = timeout - (tmo.tv_sec * ticks);
- tmo.tv_nsec = PR_IntervalToMicroseconds(PT_NANOPERMICRO *
- tmo.tv_nsec);
-
- /* pthreads wants this in absolute time, off we go ... */
- (void)GETTIMEOFDAY(&now);
- /* that one's usecs, this one's nsecs - grrrr! */
- tmo.tv_sec += now.tv_sec;
- tmo.tv_nsec += (PT_NANOPERMICRO * now.tv_usec);
- tmo.tv_sec += tmo.tv_nsec / PT_BILLION;
- tmo.tv_nsec %= PT_BILLION;
- }
-
- pthread_mutex_lock(&thread->md.pthread_mutex);
- thread->md.wait--;
- if (thread->md.wait < 0) {
- if (timeout != PR_INTERVAL_NO_TIMEOUT) {
- rv = pthread_cond_timedwait(&thread->md.pthread_cond,
- &thread->md.pthread_mutex, &tmo);
+ int rv;
+ struct timeval now;
+ struct timespec tmo;
+ PRUint32 ticks = PR_TicksPerSecond();
+
+
+ if (timeout != PR_INTERVAL_NO_TIMEOUT) {
+ tmo.tv_sec = timeout / ticks;
+ tmo.tv_nsec = timeout - (tmo.tv_sec * ticks);
+ tmo.tv_nsec = PR_IntervalToMicroseconds(PT_NANOPERMICRO *
+ tmo.tv_nsec);
+
+ /* pthreads wants this in absolute time, off we go ... */
+ (void)GETTIMEOFDAY(&now);
+ /* that one's usecs, this one's nsecs - grrrr! */
+ tmo.tv_sec += now.tv_sec;
+ tmo.tv_nsec += (PT_NANOPERMICRO * now.tv_usec);
+ tmo.tv_sec += tmo.tv_nsec / PT_BILLION;
+ tmo.tv_nsec %= PT_BILLION;
+ }
+
+ pthread_mutex_lock(&thread->md.pthread_mutex);
+ thread->md.wait--;
+ if (thread->md.wait < 0) {
+ if (timeout != PR_INTERVAL_NO_TIMEOUT) {
+ rv = pthread_cond_timedwait(&thread->md.pthread_cond,
+ &thread->md.pthread_mutex, &tmo);
+ }
+ else
+ rv = pthread_cond_wait(&thread->md.pthread_cond,
+ &thread->md.pthread_mutex);
+ if (rv != 0) {
+ thread->md.wait++;
}
- else
- rv = pthread_cond_wait(&thread->md.pthread_cond,
- &thread->md.pthread_mutex);
- if (rv != 0) {
- thread->md.wait++;
- }
- } else
- rv = 0;
- pthread_mutex_unlock(&thread->md.pthread_mutex);
-
- return (rv == 0) ? PR_SUCCESS : PR_FAILURE;
+ } else {
+ rv = 0;
+ }
+ pthread_mutex_unlock(&thread->md.pthread_mutex);
+
+ return (rv == 0) ? PR_SUCCESS : PR_FAILURE;
}
PR_IMPLEMENT(PRStatus)
_MD_wait(PRThread *thread, PRIntervalTime ticks)
{
if ( thread->flags & _PR_GLOBAL_SCOPE ) {
- _MD_CHECK_FOR_EXIT();
+ _MD_CHECK_FOR_EXIT();
if (_pt_wait(thread, ticks) == PR_FAILURE) {
- _MD_CHECK_FOR_EXIT();
+ _MD_CHECK_FOR_EXIT();
/*
* wait timed out
*/
@@ -269,12 +274,12 @@ _MD_wait(PRThread *thread, PRIntervalTime ticks)
thread->state = _PR_RUNNING;
_PR_THREAD_UNLOCK(thread);
} else {
- _pt_wait(thread, PR_INTERVAL_NO_TIMEOUT);
+ _pt_wait(thread, PR_INTERVAL_NO_TIMEOUT);
_PR_THREAD_UNLOCK(thread);
}
}
} else {
- _PR_MD_SWITCH_CONTEXT(thread);
+ _PR_MD_SWITCH_CONTEXT(thread);
}
return PR_SUCCESS;
}
@@ -286,38 +291,43 @@ _MD_WakeupWaiter(PRThread *thread)
PRInt32 pid, rv;
PRIntn is;
- PR_ASSERT(_pr_md_idle_cpus >= 0);
+ PR_ASSERT(_pr_md_idle_cpus >= 0);
if (thread == NULL) {
- if (_pr_md_idle_cpus)
- _MD_Wakeup_CPUs();
+ if (_pr_md_idle_cpus) {
+ _MD_Wakeup_CPUs();
+ }
} else if (!_PR_IS_NATIVE_THREAD(thread)) {
- /*
- * If the thread is on my cpu's runq there is no need to
- * wakeup any cpus
- */
- if (!_PR_IS_NATIVE_THREAD(me)) {
- if (me->cpu != thread->cpu) {
- if (_pr_md_idle_cpus)
- _MD_Wakeup_CPUs();
- }
- } else {
- if (_pr_md_idle_cpus)
- _MD_Wakeup_CPUs();
- }
+ /*
+ * If the thread is on my cpu's runq there is no need to
+ * wakeup any cpus
+ */
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ if (me->cpu != thread->cpu) {
+ if (_pr_md_idle_cpus) {
+ _MD_Wakeup_CPUs();
+ }
+ }
+ } else {
+ if (_pr_md_idle_cpus) {
+ _MD_Wakeup_CPUs();
+ }
+ }
} else {
- PR_ASSERT(_PR_IS_NATIVE_THREAD(thread));
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
-
- pthread_mutex_lock(&thread->md.pthread_mutex);
- thread->md.wait++;
- rv = pthread_cond_signal(&thread->md.pthread_cond);
- PR_ASSERT(rv == 0);
- pthread_mutex_unlock(&thread->md.pthread_mutex);
-
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
- }
+ PR_ASSERT(_PR_IS_NATIVE_THREAD(thread));
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
+
+ pthread_mutex_lock(&thread->md.pthread_mutex);
+ thread->md.wait++;
+ rv = pthread_cond_signal(&thread->md.pthread_cond);
+ PR_ASSERT(rv == 0);
+ pthread_mutex_unlock(&thread->md.pthread_mutex);
+
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
+ }
return PR_SUCCESS;
}
@@ -339,51 +349,57 @@ _MD_CreateThread(
{
PRIntn is;
int rv;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- pthread_attr_t attr;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+ pthread_attr_t attr;
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
- if (pthread_mutex_init(&thread->md.pthread_mutex, NULL) != 0) {
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
+ if (pthread_mutex_init(&thread->md.pthread_mutex, NULL) != 0) {
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
return PR_FAILURE;
- }
+ }
- if (pthread_cond_init(&thread->md.pthread_cond, NULL) != 0) {
- pthread_mutex_destroy(&thread->md.pthread_mutex);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
+ if (pthread_cond_init(&thread->md.pthread_cond, NULL) != 0) {
+ pthread_mutex_destroy(&thread->md.pthread_mutex);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
return PR_FAILURE;
- }
+ }
thread->flags |= _PR_GLOBAL_SCOPE;
- pthread_attr_init(&attr); /* initialize attr with default attributes */
- if (pthread_attr_setstacksize(&attr, (size_t) stackSize) != 0) {
- pthread_mutex_destroy(&thread->md.pthread_mutex);
- pthread_cond_destroy(&thread->md.pthread_cond);
- pthread_attr_destroy(&attr);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
+ pthread_attr_init(&attr); /* initialize attr with default attributes */
+ if (pthread_attr_setstacksize(&attr, (size_t) stackSize) != 0) {
+ pthread_mutex_destroy(&thread->md.pthread_mutex);
+ pthread_cond_destroy(&thread->md.pthread_cond);
+ pthread_attr_destroy(&attr);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
return PR_FAILURE;
- }
+ }
- thread->md.wait = 0;
+ thread->md.wait = 0;
rv = pthread_create(&thread->md.pthread, &attr, start, (void *)thread);
if (0 == rv) {
_MD_ATOMIC_INCREMENT(&_pr_md_pthreads_created);
_MD_ATOMIC_INCREMENT(&_pr_md_pthreads);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
return PR_SUCCESS;
} else {
- pthread_mutex_destroy(&thread->md.pthread_mutex);
- pthread_cond_destroy(&thread->md.pthread_cond);
- pthread_attr_destroy(&attr);
+ pthread_mutex_destroy(&thread->md.pthread_mutex);
+ pthread_cond_destroy(&thread->md.pthread_cond);
+ pthread_attr_destroy(&attr);
_MD_ATOMIC_INCREMENT(&_pr_md_pthreads_failed);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, rv);
return PR_FAILURE;
}
@@ -396,12 +412,12 @@ _MD_InitRunningCPU(struct _PRCPU *cpu)
_MD_unix_init_running_cpu(cpu);
cpu->md.pthread = pthread_self();
- if (_pr_md_pipefd[0] >= 0) {
- _PR_IOQ_MAX_OSFD(cpu) = _pr_md_pipefd[0];
+ if (_pr_md_pipefd[0] >= 0) {
+ _PR_IOQ_MAX_OSFD(cpu) = _pr_md_pipefd[0];
#ifndef _PR_USE_POLL
- FD_SET(_pr_md_pipefd[0], &_PR_FD_READ_SET(cpu));
+ FD_SET(_pr_md_pipefd[0], &_PR_FD_READ_SET(cpu));
#endif
- }
+ }
}
@@ -411,7 +427,7 @@ _MD_CleanupBeforeExit(void)
#if 0
extern PRInt32 _pr_cpus_exit;
- _pr_irix_exit_now = 1;
+ _pr_irix_exit_now = 1;
if (_pr_numCPU > 1) {
/*
* Set a global flag, and wakeup all cpus which will notice the flag
@@ -427,22 +443,22 @@ _MD_CleanupBeforeExit(void)
/*
* cause global threads on the recycle list to exit
*/
- _PR_DEADQ_LOCK;
- if (_PR_NUM_DEADNATIVE != 0) {
- PRThread *thread;
- PRCList *ptr;
+ _PR_DEADQ_LOCK;
+ if (_PR_NUM_DEADNATIVE != 0) {
+ PRThread *thread;
+ PRCList *ptr;
ptr = _PR_DEADNATIVEQ.next;
while( ptr != &_PR_DEADNATIVEQ ) {
- thread = _PR_THREAD_PTR(ptr);
- _MD_CVAR_POST_SEM(thread);
- ptr = ptr->next;
- }
- }
- _PR_DEADQ_UNLOCK;
- while(_PR_NUM_DEADNATIVE > 1) {
- _PR_WAIT_SEM(_pr_irix_exit_sem);
- _PR_DEC_DEADNATIVE;
- }
+ thread = _PR_THREAD_PTR(ptr);
+ _MD_CVAR_POST_SEM(thread);
+ ptr = ptr->next;
+ }
+ }
+ _PR_DEADQ_UNLOCK;
+ while(_PR_NUM_DEADNATIVE > 1) {
+ _PR_WAIT_SEM(_pr_irix_exit_sem);
+ _PR_DEC_DEADNATIVE;
+ }
#endif
}
diff --git a/nsprpub/pr/src/md/unix/qnx.c b/nsprpub/pr/src/md/unix/qnx.c
index 259e29cdc..aef97a25a 100644
--- a/nsprpub/pr/src/md/unix/qnx.c
+++ b/nsprpub/pr/src/md/unix/qnx.c
@@ -14,7 +14,7 @@ void _MD_EarlyInit(void)
PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
@@ -29,7 +29,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PRStatus
@@ -44,7 +44,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
diff --git a/nsprpub/pr/src/md/unix/riscos.c b/nsprpub/pr/src/md/unix/riscos.c
index 318903acb..a04118875 100644
--- a/nsprpub/pr/src/md/unix/riscos.c
+++ b/nsprpub/pr/src/md/unix/riscos.c
@@ -13,13 +13,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#ifndef _PR_PTHREADS
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
#else
- *np = 0;
- return NULL;
+ *np = 0;
+ return NULL;
#endif
}
@@ -40,13 +40,13 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- /*
- * set the pointers to the stack-pointer and frame-pointer words in the
- * context structure; this is for debugging use.
- */
- thread->md.sp = _MD_GET_SP_PTR(thread);
- thread->md.fp = _MD_GET_FP_PTR(thread);
- return PR_SUCCESS;
+ /*
+ * set the pointers to the stack-pointer and frame-pointer words in the
+ * context structure; this is for debugging use.
+ */
+ thread->md.sp = _MD_GET_SP_PTR(thread);
+ thread->md.fp = _MD_GET_FP_PTR(thread);
+ return PR_SUCCESS;
}
PRStatus
@@ -61,7 +61,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
@@ -83,6 +83,6 @@ _MD_CREATE_THREAD(
PRUint32 stackSize)
{
PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for RISC OS.");
- return PR_FAILURE;
+ return PR_FAILURE;
}
#endif /* ! _PR_PTHREADS */
diff --git a/nsprpub/pr/src/md/unix/scoos.c b/nsprpub/pr/src/md/unix/scoos.c
index b727a53ae..43b256d82 100644
--- a/nsprpub/pr/src/md/unix/scoos.c
+++ b/nsprpub/pr/src/md/unix/scoos.c
@@ -17,7 +17,7 @@ void _MD_EarlyInit(void)
PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
@@ -26,7 +26,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
#ifdef ALARMS_BREAK_TCP /* I don't think they do */
PRInt32 _MD_connect(PRInt32 osfd, PRNetAddr *addr, PRInt32 addrlen,
- PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
PRInt32 rv;
@@ -36,7 +36,7 @@ PRInt32 _MD_connect(PRInt32 osfd, PRNetAddr *addr, PRInt32 addrlen,
}
PRInt32 _MD_accept(PRInt32 osfd, PRNetAddr *addr, PRInt32 addrlen,
- PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
PRInt32 rv;
@@ -61,8 +61,9 @@ void
_MD_INIT_ATOMIC(void)
{
/* Sigh. Sure wish SYSV semaphores weren't such a pain to use */
- if ((_uw_semf = tmpfile()) == NULL)
+ if ((_uw_semf = tmpfile()) == NULL) {
PR_ASSERT(0);
+ }
return;
}
@@ -109,7 +110,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PRStatus
@@ -124,7 +125,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
diff --git a/nsprpub/pr/src/md/unix/solaris.c b/nsprpub/pr/src/md/unix/solaris.c
index 4fe2043b1..383f49d04 100644
--- a/nsprpub/pr/src/md/unix/solaris.c
+++ b/nsprpub/pr/src/md/unix/solaris.c
@@ -25,8 +25,8 @@ PRIntervalTime _MD_Solaris_TicksPerSecond(void)
PRIntervalTime _MD_Solaris_GetInterval(void)
{
union {
- hrtime_t hrt; /* hrtime_t is a 64-bit (long long) integer */
- PRInt64 pr64;
+ hrtime_t hrt; /* hrtime_t is a 64-bit (long long) integer */
+ PRInt64 pr64;
} time;
PRInt64 resolution;
PRIntervalTime ticks;
@@ -49,8 +49,8 @@ void _MD_EarlyInit(void)
PRWord *_MD_HomeGCRegisters(PRThread *t, PRIntn isCurrent, PRIntn *np)
{
- *np = 0;
- return NULL;
+ *np = 0;
+ return NULL;
}
#endif /* _PR_PTHREADS */
@@ -74,7 +74,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PRStatus
@@ -88,7 +88,7 @@ _MD_WAIT(PRThread *thread, PRIntervalTime ticks)
PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
- PR_ASSERT((thread == NULL) || (!(thread->flags & _PR_GLOBAL_SCOPE)));
+ PR_ASSERT((thread == NULL) || (!(thread->flags & _PR_GLOBAL_SCOPE)));
return PR_SUCCESS;
}
@@ -109,14 +109,14 @@ _MD_CREATE_THREAD(
PRUint32 stackSize)
{
PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for Solaris");
- return(PR_FAILURE);
+ return(PR_FAILURE);
}
#ifdef USE_SETJMP
PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
@@ -125,7 +125,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
PRWord *_MD_HomeGCRegisters(PRThread *t, PRIntn isCurrent, PRIntn *np)
{
if (isCurrent) {
- (void) getcontext(CONTEXT(t));
+ (void) getcontext(CONTEXT(t));
}
*np = NGREG;
return (PRWord*) &t->md.context.uc_mcontext.gregs[0];
@@ -136,7 +136,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, PRIntn isCurrent, PRIntn *np)
#ifndef _PR_PTHREADS
#if defined(i386) && defined(SOLARIS2_4)
-/*
+/*
* Because clock_gettime() on Solaris/x86 2.4 always generates a
* segmentation fault, we use an emulated version _pr_solx86_clock_gettime(),
* which is implemented using gettimeofday().
@@ -148,8 +148,8 @@ _pr_solx86_clock_gettime(clockid_t clock_id, struct timespec *tp)
struct timeval tv;
if (clock_id != CLOCK_REALTIME) {
- errno = EINVAL;
- return -1;
+ errno = EINVAL;
+ return -1;
}
gettimeofday(&tv, NULL);
diff --git a/nsprpub/pr/src/md/unix/symbian.c b/nsprpub/pr/src/md/unix/symbian.c
deleted file mode 100644
index c797d8687..000000000
--- a/nsprpub/pr/src/md/unix/symbian.c
+++ /dev/null
@@ -1,16 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-void _MD_EarlyInit(void)
-{
-}
-
-PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
-{
- *np = 0;
- return NULL;
-}
diff --git a/nsprpub/pr/src/md/unix/unix.c b/nsprpub/pr/src/md/unix/unix.c
index 7c90b5075..a8862a4ce 100644
--- a/nsprpub/pr/src/md/unix/unix.c
+++ b/nsprpub/pr/src/md/unix/unix.c
@@ -41,7 +41,7 @@
#if defined(HAVE_SOCKLEN_T) \
|| (defined(__GLIBC__) && __GLIBC__ >= 2)
#define _PRSockLen_t socklen_t
-#elif defined(IRIX) || defined(HPUX) || defined(OSF1) || defined(SOLARIS) \
+#elif defined(HPUX) || defined(SOLARIS) \
|| defined(AIX4_1) || defined(LINUX) \
|| defined(BSDI) || defined(SCO) \
|| defined(DARWIN) \
@@ -49,7 +49,7 @@
#define _PRSockLen_t int
#elif (defined(AIX) && !defined(AIX4_1)) || defined(FREEBSD) \
|| defined(NETBSD) || defined(OPENBSD) || defined(UNIXWARE) \
- || defined(DGUX) || defined(NTO) || defined(RISCOS)
+ || defined(NTO) || defined(RISCOS)
#define _PRSockLen_t size_t
#else
#error "Cannot determine architecture"
@@ -59,7 +59,7 @@
** Global lock variable used to bracket calls into rusty libraries that
** aren't thread safe (like libc, libX, etc).
*/
-static PRLock *_pr_rename_lock = NULL;
+static PRLock *_pr_unix_rename_lock = NULL;
static PRMonitor *_pr_Xfe_mon = NULL;
static PRInt64 minus_one;
@@ -84,10 +84,6 @@ static sigset_t empty_set;
*/
int _nspr_noclock = 1;
-#ifdef IRIX
-extern PRInt32 _nspr_terminate_on_error;
-#endif
-
/*
* There is an assertion in this code that NSPR's definition of PRIOVec
* is bit compatible with UNIX' definition of a struct iovec. This is
@@ -98,13 +94,15 @@ extern PRInt32 _nspr_terminate_on_error;
int _pr_md_pipefd[2] = { -1, -1 };
static char _pr_md_pipebuf[PIPE_BUF];
static PRInt32 local_io_wait(PRInt32 osfd, PRInt32 wait_flag,
- PRIntervalTime timeout);
+ PRIntervalTime timeout);
_PRInterruptTable _pr_interruptTable[] = {
- {
- "clock", _PR_MISSED_CLOCK, _PR_ClockInterrupt, },
- {
- 0 }
+ {
+ "clock", _PR_MISSED_CLOCK, _PR_ClockInterrupt,
+ },
+ {
+ 0
+ }
};
void _MD_unix_init_running_cpu(_PRCPU *cpu)
@@ -116,7 +114,7 @@ void _MD_unix_init_running_cpu(_PRCPU *cpu)
PRStatus _MD_open_dir(_MDDir *d, const char *name)
{
-int err;
+ int err;
d->d = opendir(name);
if (!d->d) {
@@ -129,13 +127,13 @@ int err;
PRInt32 _MD_close_dir(_MDDir *d)
{
-int rv = 0, err;
+ int rv = 0, err;
if (d->d) {
rv = closedir(d->d);
if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_CLOSEDIR_ERROR(err);
+ err = _MD_ERRNO();
+ _PR_MD_MAP_CLOSEDIR_ERROR(err);
}
}
return rv;
@@ -143,8 +141,8 @@ int rv = 0, err;
char * _MD_read_dir(_MDDir *d, PRIntn flags)
{
-struct dirent *de;
-int err;
+ struct dirent *de;
+ int err;
for (;;) {
/*
@@ -157,16 +155,19 @@ int err;
err = _MD_ERRNO();
_PR_MD_MAP_READDIR_ERROR(err);
return 0;
- }
+ }
if ((flags & PR_SKIP_DOT) &&
- (de->d_name[0] == '.') && (de->d_name[1] == 0))
+ (de->d_name[0] == '.') && (de->d_name[1] == 0)) {
continue;
+ }
if ((flags & PR_SKIP_DOT_DOT) &&
(de->d_name[0] == '.') && (de->d_name[1] == '.') &&
- (de->d_name[2] == 0))
+ (de->d_name[2] == 0)) {
continue;
- if ((flags & PR_SKIP_HIDDEN) && (de->d_name[0] == '.'))
+ }
+ if ((flags & PR_SKIP_HIDDEN) && (de->d_name[0] == '.')) {
continue;
+ }
break;
}
return de->d_name;
@@ -174,7 +175,7 @@ int err;
PRInt32 _MD_delete(const char *name)
{
-PRInt32 rv, err;
+ PRInt32 rv, err;
#ifdef UNIXWARE
sigset_t set, oset;
#endif
@@ -188,8 +189,8 @@ PRInt32 rv, err;
sigprocmask(SIG_SETMASK, &oset, NULL);
#endif
if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_UNLINK_ERROR(err);
+ err = _MD_ERRNO();
+ _PR_MD_MAP_UNLINK_ERROR(err);
}
return(rv);
}
@@ -204,10 +205,12 @@ PRInt32 _MD_rename(const char *from, const char *to)
** of an existing file. Holding a lock across these two function
** and the open function is known to be a bad idea, but ....
*/
- if (NULL != _pr_rename_lock)
- PR_Lock(_pr_rename_lock);
- if (0 == access(to, F_OK))
+ if (NULL != _pr_unix_rename_lock) {
+ PR_Lock(_pr_unix_rename_lock);
+ }
+ if (0 == access(to, F_OK)) {
PR_SetError(PR_FILE_EXISTS_ERROR, 0);
+ }
else
{
rv = rename(from, to);
@@ -216,15 +219,16 @@ PRInt32 _MD_rename(const char *from, const char *to)
_PR_MD_MAP_RENAME_ERROR(err);
}
}
- if (NULL != _pr_rename_lock)
- PR_Unlock(_pr_rename_lock);
+ if (NULL != _pr_unix_rename_lock) {
+ PR_Unlock(_pr_unix_rename_lock);
+ }
return rv;
}
PRInt32 _MD_access(const char *name, PRAccessHow how)
{
-PRInt32 rv, err;
-int amode;
+ PRInt32 rv, err;
+ int amode;
switch (how) {
case PR_ACCESS_WRITE_OK:
@@ -254,46 +258,48 @@ done:
PRInt32 _MD_mkdir(const char *name, PRIntn mode)
{
-int rv, err;
+ int rv, err;
/*
** This lock is used to enforce rename semantics as described
** in PR_Rename. Look there for more fun details.
*/
- if (NULL !=_pr_rename_lock)
- PR_Lock(_pr_rename_lock);
+ if (NULL !=_pr_unix_rename_lock) {
+ PR_Lock(_pr_unix_rename_lock);
+ }
rv = mkdir(name, mode);
if (rv < 0) {
err = _MD_ERRNO();
_PR_MD_MAP_MKDIR_ERROR(err);
}
- if (NULL !=_pr_rename_lock)
- PR_Unlock(_pr_rename_lock);
+ if (NULL !=_pr_unix_rename_lock) {
+ PR_Unlock(_pr_unix_rename_lock);
+ }
return rv;
}
PRInt32 _MD_rmdir(const char *name)
{
-int rv, err;
+ int rv, err;
rv = rmdir(name);
if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_RMDIR_ERROR(err);
+ err = _MD_ERRNO();
+ _PR_MD_MAP_RMDIR_ERROR(err);
}
return rv;
}
PRInt32 _MD_read(PRFileDesc *fd, void *buf, PRInt32 amount)
{
-PRThread *me = _PR_MD_CURRENT_THREAD();
-PRInt32 rv, err;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+ PRInt32 rv, err;
#ifndef _PR_USE_POLL
-fd_set rd;
+ fd_set rd;
#else
-struct pollfd pfd;
+ struct pollfd pfd;
#endif /* _PR_USE_POLL */
-PRInt32 osfd = fd->secret->md.osfd;
+ PRInt32 osfd = fd->secret->md.osfd;
#ifndef _PR_USE_POLL
FD_ZERO(&rd);
@@ -310,17 +316,18 @@ PRInt32 osfd = fd->secret->md.osfd;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ,
- PR_INTERVAL_NO_TIMEOUT)) < 0)
- goto done;
+ PR_INTERVAL_NO_TIMEOUT)) < 0) {
+ goto done;
+ }
} else {
#ifndef _PR_USE_POLL
while ((rv = _MD_SELECT(osfd + 1, &rd, NULL, NULL, NULL))
- == -1 && (err = _MD_ERRNO()) == EINTR) {
+ == -1 && (err = _MD_ERRNO()) == EINTR) {
/* retry _MD_SELECT() if it is interrupted */
}
#else /* _PR_USE_POLL */
while ((rv = _MD_POLL(&pfd, 1, -1))
- == -1 && (err = _MD_ERRNO()) == EINTR) {
+ == -1 && (err = _MD_ERRNO()) == EINTR) {
/* retry _MD_POLL() if it is interrupted */
}
#endif /* _PR_USE_POLL */
@@ -328,9 +335,10 @@ PRInt32 osfd = fd->secret->md.osfd;
break;
}
}
- if (_PR_PENDING_INTERRUPT(me))
+ if (_PR_PENDING_INTERRUPT(me)) {
break;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -350,14 +358,14 @@ done:
PRInt32 _MD_write(PRFileDesc *fd, const void *buf, PRInt32 amount)
{
-PRThread *me = _PR_MD_CURRENT_THREAD();
-PRInt32 rv, err;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+ PRInt32 rv, err;
#ifndef _PR_USE_POLL
-fd_set wd;
+ fd_set wd;
#else
-struct pollfd pfd;
+ struct pollfd pfd;
#endif /* _PR_USE_POLL */
-PRInt32 osfd = fd->secret->md.osfd;
+ PRInt32 osfd = fd->secret->md.osfd;
#ifndef _PR_USE_POLL
FD_ZERO(&wd);
@@ -374,17 +382,18 @@ PRInt32 osfd = fd->secret->md.osfd;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE,
- PR_INTERVAL_NO_TIMEOUT)) < 0)
+ PR_INTERVAL_NO_TIMEOUT)) < 0) {
goto done;
+ }
} else {
#ifndef _PR_USE_POLL
while ((rv = _MD_SELECT(osfd + 1, NULL, &wd, NULL, NULL))
- == -1 && (err = _MD_ERRNO()) == EINTR) {
+ == -1 && (err = _MD_ERRNO()) == EINTR) {
/* retry _MD_SELECT() if it is interrupted */
}
#else /* _PR_USE_POLL */
while ((rv = _MD_POLL(&pfd, 1, -1))
- == -1 && (err = _MD_ERRNO()) == EINTR) {
+ == -1 && (err = _MD_ERRNO()) == EINTR) {
/* retry _MD_POLL() if it is interrupted */
}
#endif /* _PR_USE_POLL */
@@ -392,9 +401,10 @@ PRInt32 osfd = fd->secret->md.osfd;
break;
}
}
- if (_PR_PENDING_INTERRUPT(me))
+ if (_PR_PENDING_INTERRUPT(me)) {
break;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -414,7 +424,7 @@ done:
PRInt32 _MD_fsync(PRFileDesc *fd)
{
-PRInt32 rv, err;
+ PRInt32 rv, err;
rv = fsync(fd->secret->md.osfd);
if (rv == -1) {
@@ -426,7 +436,7 @@ PRInt32 rv, err;
PRInt32 _MD_close(PRInt32 osfd)
{
-PRInt32 rv, err;
+ PRInt32 rv, err;
rv = close(osfd);
if (rv == -1) {
@@ -484,7 +494,7 @@ PRInt64 _MD_socketavailable64(PRFileDesc *fd)
#ifndef _PR_USE_POLL
static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
- PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
PRInt32 rv = -1;
struct timeval tv;
@@ -508,10 +518,12 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
FD_ZERO(&rd_wr);
do {
FD_SET(osfd, &rd_wr);
- if (fd_type == READ_FD)
+ if (fd_type == READ_FD) {
rv = _MD_SELECT(osfd + 1, &rd_wr, NULL, NULL, &tv);
- else
+ }
+ else {
rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, NULL, &tv);
+ }
if (rv == -1 && (syserror = _MD_ERRNO()) != EINTR) {
_PR_MD_MAP_SELECT_ERROR(syserror);
break;
@@ -543,14 +555,16 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
tv.tv_usec = 0;
} else {
tv.tv_usec = PR_IntervalToMicroseconds(
- remaining -
- PR_SecondsToInterval(tv.tv_sec));
+ remaining -
+ PR_SecondsToInterval(tv.tv_sec));
}
FD_SET(osfd, &rd_wr);
- if (fd_type == READ_FD)
+ if (fd_type == READ_FD) {
rv = _MD_SELECT(osfd + 1, &rd_wr, NULL, NULL, &tv);
- else
+ }
+ else {
rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, NULL, &tv);
+ }
/*
* we don't consider EINTR a real error
*/
@@ -579,7 +593,7 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
now += remaining;
} else {
now += PR_SecondsToInterval(tv.tv_sec)
- + PR_MicrosecondsToInterval(tv.tv_usec);
+ + PR_MicrosecondsToInterval(tv.tv_usec);
}
} else {
now = PR_IntervalNow();
@@ -602,7 +616,7 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
#else /* _PR_USE_POLL */
static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
- PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
PRInt32 rv = -1;
int msecs;
@@ -634,11 +648,11 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
_PR_MD_MAP_POLL_ERROR(syserror);
break;
}
- /*
- * If POLLERR is set, don't process it; retry the operation
- */
+ /*
+ * If POLLERR is set, don't process it; retry the operation
+ */
if ((rv == 1) && (pfd.revents & (POLLHUP | POLLNVAL))) {
- rv = -1;
+ rv = -1;
_PR_MD_MAP_POLL_REVENTS_ERROR(pfd.revents);
break;
}
@@ -686,11 +700,11 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
rv = -1;
break;
}
- /*
- * If POLLERR is set, don't process it; retry the operation
- */
+ /*
+ * If POLLERR is set, don't process it; retry the operation
+ */
if ((rv == 1) && (pfd.revents & (POLLHUP | POLLNVAL))) {
- rv = -1;
+ rv = -1;
_PR_MD_MAP_POLL_REVENTS_ERROR(pfd.revents);
break;
}
@@ -739,11 +753,13 @@ static PRInt32 local_io_wait(
PRInt32 rv;
PR_LOG(_pr_io_lm, PR_LOG_MIN,
- ("waiting to %s on osfd=%d",
- (wait_flag == _PR_UNIX_POLL_READ) ? "read" : "write",
- osfd));
+ ("waiting to %s on osfd=%d",
+ (wait_flag == _PR_UNIX_POLL_READ) ? "read" : "write",
+ osfd));
- if (timeout == PR_INTERVAL_NO_WAIT) return 0;
+ if (timeout == PR_INTERVAL_NO_WAIT) {
+ return 0;
+ }
pd.osfd = osfd;
pd.in_flags = wait_flag;
@@ -760,17 +776,17 @@ static PRInt32 local_io_wait(
PRInt32 _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount,
- PRInt32 flags, PRIntervalTime timeout)
+ PRInt32 flags, PRIntervalTime timeout)
{
PRInt32 osfd = fd->secret->md.osfd;
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
-/*
- * Many OS's (Solaris, Unixware) have a broken recv which won't read
- * from socketpairs. As long as we don't use flags on socketpairs, this
- * is a decent fix. - mikep
- */
+ /*
+ * Many OS's (Solaris, Unixware) have a broken recv which won't read
+ * from socketpairs. As long as we don't use flags on socketpairs, this
+ * is a decent fix. - mikep
+ */
#if defined(UNIXWARE) || defined(SOLARIS)
while ((rv = read(osfd,buf,amount)) == -1) {
#else
@@ -782,13 +798,15 @@ PRInt32 _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount,
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd,_PR_UNIX_POLL_READ,timeout)) < 0)
- goto done;
+ if ((rv = local_io_wait(osfd,_PR_UNIX_POLL_READ,timeout)) < 0) {
+ goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -802,29 +820,31 @@ done:
}
PRInt32 _MD_recvfrom(PRFileDesc *fd, void *buf, PRInt32 amount,
- PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen,
- PRIntervalTime timeout)
+ PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen,
+ PRIntervalTime timeout)
{
PRInt32 osfd = fd->secret->md.osfd;
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
while ((*addrlen = PR_NETADDR_SIZE(addr)),
- ((rv = recvfrom(osfd, buf, amount, flags,
- (struct sockaddr *) addr, (_PRSockLen_t *)addrlen)) == -1)) {
+ ((rv = recvfrom(osfd, buf, amount, flags,
+ (struct sockaddr *) addr, (_PRSockLen_t *)addrlen)) == -1)) {
err = _MD_ERRNO();
if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
if (fd->secret->nonblocking) {
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, timeout)) < 0)
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, timeout)) < 0) {
goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -846,13 +866,13 @@ done:
}
PRInt32 _MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount,
- PRInt32 flags, PRIntervalTime timeout)
+ PRInt32 flags, PRIntervalTime timeout)
{
PRInt32 osfd = fd->secret->md.osfd;
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
#if defined(SOLARIS)
- PRInt32 tmp_amount = amount;
+ PRInt32 tmp_amount = amount;
#endif
/*
@@ -872,48 +892,50 @@ PRInt32 _MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount,
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0)
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) {
goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0)
+ if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
#if defined(SOLARIS)
- /*
- * The write system call has been reported to return the ERANGE
- * error on occasion. Try to write in smaller chunks to workaround
- * this bug.
- */
- if (err == ERANGE) {
- if (tmp_amount > 1) {
- tmp_amount = tmp_amount/2; /* half the bytes */
- continue;
- }
- }
+ /*
+ * The write system call has been reported to return the ERANGE
+ * error on occasion. Try to write in smaller chunks to workaround
+ * this bug.
+ */
+ if (err == ERANGE) {
+ if (tmp_amount > 1) {
+ tmp_amount = tmp_amount/2; /* half the bytes */
+ continue;
+ }
+ }
#endif
break;
}
}
- /*
- * optimization; if bytes sent is less than "amount" call
- * select before returning. This is because it is likely that
- * the next send() call will return EWOULDBLOCK.
- */
+ /*
+ * optimization; if bytes sent is less than "amount" call
+ * select before returning. This is because it is likely that
+ * the next send() call will return EWOULDBLOCK.
+ */
if ((!fd->secret->nonblocking) && (rv > 0) && (rv < amount)
- && (timeout != PR_INTERVAL_NO_WAIT)) {
+ && (timeout != PR_INTERVAL_NO_WAIT)) {
if (_PR_IS_NATIVE_THREAD(me)) {
- if (socket_io_wait(osfd, WRITE_FD, timeout)< 0) {
- rv = -1;
- goto done;
- }
+ if (socket_io_wait(osfd, WRITE_FD, timeout)< 0) {
+ rv = -1;
+ goto done;
+ }
} else {
- if (local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout) < 0) {
- rv = -1;
- goto done;
- }
+ if (local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout) < 0) {
+ rv = -1;
+ goto done;
+ }
}
}
if (rv < 0) {
@@ -938,10 +960,10 @@ PRInt32 _MD_sendto(
((struct sockaddr *) &addrCopy)->sa_family = addr->raw.family;
while ((rv = sendto(osfd, buf, amount, flags,
- (struct sockaddr *) &addrCopy, addrlen)) == -1) {
+ (struct sockaddr *) &addrCopy, addrlen)) == -1) {
#else
while ((rv = sendto(osfd, buf, amount, flags,
- (struct sockaddr *) addr, addrlen)) == -1) {
+ (struct sockaddr *) addr, addrlen)) == -1) {
#endif
err = _MD_ERRNO();
if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
@@ -949,13 +971,15 @@ PRInt32 _MD_sendto(
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0)
- goto done;
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) {
+ goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0)
+ if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -997,13 +1021,15 @@ PRInt32 _MD_writev(
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0)
- goto done;
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) {
+ goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))<0)
+ if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))<0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -1015,17 +1041,17 @@ PRInt32 _MD_writev(
* the next writev() call will return EWOULDBLOCK.
*/
if ((!fd->secret->nonblocking) && (rv > 0) && (rv < amount)
- && (timeout != PR_INTERVAL_NO_WAIT)) {
+ && (timeout != PR_INTERVAL_NO_WAIT)) {
if (_PR_IS_NATIVE_THREAD(me)) {
if (socket_io_wait(osfd, WRITE_FD, timeout) < 0) {
- rv = -1;
+ rv = -1;
goto done;
- }
+ }
} else {
- if (local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout) < 0) {
- rv = -1;
- goto done;
- }
+ if (local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout) < 0) {
+ rv = -1;
+ goto done;
+ }
}
}
if (rv < 0) {
@@ -1036,27 +1062,29 @@ done:
}
PRInt32 _MD_accept(PRFileDesc *fd, PRNetAddr *addr,
- PRUint32 *addrlen, PRIntervalTime timeout)
+ PRUint32 *addrlen, PRIntervalTime timeout)
{
PRInt32 osfd = fd->secret->md.osfd;
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
while ((rv = accept(osfd, (struct sockaddr *) addr,
- (_PRSockLen_t *)addrlen)) == -1) {
+ (_PRSockLen_t *)addrlen)) == -1) {
err = _MD_ERRNO();
if ((err == EAGAIN) || (err == EWOULDBLOCK) || (err == ECONNABORTED)) {
if (fd->secret->nonblocking) {
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, timeout)) < 0)
- goto done;
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, timeout)) < 0) {
+ goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -1084,10 +1112,6 @@ PRInt32 _MD_connect(
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
PRInt32 osfd = fd->secret->md.osfd;
-#ifdef IRIX
-extern PRInt32 _MD_irix_connect(
- PRInt32 osfd, const PRNetAddr *addr, PRInt32 addrlen, PRIntervalTime timeout);
-#endif
#ifdef _PR_HAVE_SOCKADDR_LEN
PRNetAddr addrCopy;
@@ -1109,15 +1133,11 @@ extern PRInt32 _MD_irix_connect(
*/
retry:
-#ifdef IRIX
- if ((rv = _MD_irix_connect(osfd, addr, addrlen, timeout)) == -1) {
-#else
#ifdef _PR_HAVE_SOCKADDR_LEN
if ((rv = connect(osfd, (struct sockaddr *)&addrCopy, addrlen)) == -1) {
#else
if ((rv = connect(osfd, (struct sockaddr *)addr, addrlen)) == -1) {
#endif
-#endif
err = _MD_ERRNO();
if (err == EINTR) {
@@ -1132,8 +1152,9 @@ retry:
if (!fd->secret->nonblocking && (err == EINPROGRESS)) {
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0)
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) {
return -1;
+ }
} else {
/*
* socket_io_wait() may return -1 or 1.
@@ -1210,7 +1231,7 @@ PRInt32 _MD_shutdown(PRFileDesc *fd, PRIntn how)
}
PRInt32 _MD_socketpair(int af, int type, int flags,
- PRInt32 *osfd)
+ PRInt32 *osfd)
{
PRInt32 rv, err;
@@ -1223,12 +1244,12 @@ PRInt32 _MD_socketpair(int af, int type, int flags,
}
PRStatus _MD_getsockname(PRFileDesc *fd, PRNetAddr *addr,
- PRUint32 *addrlen)
+ PRUint32 *addrlen)
{
PRInt32 rv, err;
rv = getsockname(fd->secret->md.osfd,
- (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
+ (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
#ifdef _PR_HAVE_SOCKADDR_LEN
if (rv == 0) {
/* ignore the sa_len field of struct sockaddr */
@@ -1245,12 +1266,12 @@ PRStatus _MD_getsockname(PRFileDesc *fd, PRNetAddr *addr,
}
PRStatus _MD_getpeername(PRFileDesc *fd, PRNetAddr *addr,
- PRUint32 *addrlen)
+ PRUint32 *addrlen)
{
PRInt32 rv, err;
rv = getpeername(fd->secret->md.osfd,
- (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
+ (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
#ifdef _PR_HAVE_SOCKADDR_LEN
if (rv == 0) {
/* ignore the sa_len field of struct sockaddr */
@@ -1279,8 +1300,8 @@ PRStatus _MD_getsockopt(PRFileDesc *fd, PRInt32 level,
return rv==0?PR_SUCCESS:PR_FAILURE;
}
-PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level,
- PRInt32 optname, const char* optval, PRInt32 optlen)
+PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level,
+ PRInt32 optname, const char* optval, PRInt32 optlen)
{
PRInt32 rv, err;
@@ -1354,7 +1375,7 @@ static void FindBadFDs(void)
if (fcntl(osfd, F_GETFL, 0) == -1) {
/* Found a bad descriptor, remove it from the fd_sets. */
PR_LOG(_pr_io_lm, PR_LOG_MAX,
- ("file descriptor %d is bad", osfd));
+ ("file descriptor %d is bad", osfd));
pds->out_flags = _PR_UNIX_POLL_NVAL;
notify = PR_TRUE;
}
@@ -1369,26 +1390,29 @@ static void FindBadFDs(void)
pq->on_ioq = PR_FALSE;
/*
- * Decrement the count of descriptors for each desciptor/event
- * because this I/O request is being removed from the
- * ioq
- */
+ * Decrement the count of descriptors for each desciptor/event
+ * because this I/O request is being removed from the
+ * ioq
+ */
pds = pq->pds;
for (; pds < epds; pds++) {
PRInt32 osfd = pds->osfd;
PRInt16 in_flags = pds->in_flags;
PR_ASSERT(osfd >= 0 || in_flags == 0);
if (in_flags & _PR_UNIX_POLL_READ) {
- if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_READ_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_WRITE) {
- if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_WRITE_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_EXCEPT) {
- if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_EXCEPTION_SET(me->cpu));
+ }
}
}
@@ -1399,36 +1423,39 @@ static void FindBadFDs(void)
_PR_DEL_SLEEPQ(pq->thr, PR_TRUE);
_PR_SLEEPQ_UNLOCK(pq->thr->cpu);
- if (pq->thr->flags & _PR_SUSPENDING) {
- /*
- * set thread state to SUSPENDED;
- * a Resume operation on the thread
- * will move it to the runQ
- */
- pq->thr->state = _PR_SUSPENDED;
- _PR_MISCQ_LOCK(pq->thr->cpu);
- _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
- _PR_MISCQ_UNLOCK(pq->thr->cpu);
- } else {
- pri = pq->thr->priority;
- pq->thr->state = _PR_RUNNABLE;
-
- _PR_RUNQ_LOCK(cpu);
- _PR_ADD_RUNQ(pq->thr, cpu, pri);
- _PR_RUNQ_UNLOCK(cpu);
- }
+ if (pq->thr->flags & _PR_SUSPENDING) {
+ /*
+ * set thread state to SUSPENDED;
+ * a Resume operation on the thread
+ * will move it to the runQ
+ */
+ pq->thr->state = _PR_SUSPENDED;
+ _PR_MISCQ_LOCK(pq->thr->cpu);
+ _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
+ _PR_MISCQ_UNLOCK(pq->thr->cpu);
+ } else {
+ pri = pq->thr->priority;
+ pq->thr->state = _PR_RUNNABLE;
+
+ _PR_RUNQ_LOCK(cpu);
+ _PR_ADD_RUNQ(pq->thr, cpu, pri);
+ _PR_RUNQ_UNLOCK(cpu);
+ }
}
_PR_THREAD_UNLOCK(pq->thr);
} else {
- if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu))
+ if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu)) {
_PR_IOQ_TIMEOUT(me->cpu) = pq->timeout;
- if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd)
+ }
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd) {
_PR_IOQ_MAX_OSFD(me->cpu) = pq_max_osfd;
+ }
}
}
if (_PR_IS_NATIVE_THREAD_SUPPORTED()) {
- if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0])
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0]) {
_PR_IOQ_MAX_OSFD(me->cpu) = _pr_md_pipefd[0];
+ }
}
}
#endif /* !defined(_PR_USE_POLL) */
@@ -1466,9 +1493,6 @@ void _MD_PauseCPU(PRIntervalTime ticks)
PRCList *q;
PRUint32 min_timeout;
sigset_t oldset;
-#ifdef IRIX
-extern sigset_t ints_off;
-#endif
PR_ASSERT(_PR_MD_GET_INTSOFF() != 0);
@@ -1487,24 +1511,15 @@ extern sigset_t ints_off;
*/
if (_PR_IS_NATIVE_THREAD_SUPPORTED()) {
npollfds++;
-#ifdef IRIX
- /*
- * On Irix, a second pipe is used to cause the primordial cpu to
- * wakeup and exit, when the process is exiting because of a call
- * to exit/PR_ProcessExit.
- */
- if (me->cpu->id == 0) {
- npollfds++;
- }
-#endif
- }
+ }
/*
* if the cpu's pollfd array is not big enough, release it and allocate a new one
*/
if (npollfds > _PR_IOQ_POLLFDS_SIZE(me->cpu)) {
- if (_PR_IOQ_POLLFDS(me->cpu) != NULL)
+ if (_PR_IOQ_POLLFDS(me->cpu) != NULL) {
PR_DELETE(_PR_IOQ_POLLFDS(me->cpu));
+ }
pollfds_size = PR_MAX(_PR_IOQ_MIN_POLLFDS_SIZE(me->cpu), npollfds);
pollfds = (struct pollfd *) PR_MALLOC(pollfds_size * sizeof(struct pollfd));
_PR_IOQ_POLLFDS(me->cpu) = pollfds;
@@ -1522,16 +1537,6 @@ extern sigset_t ints_off;
pollfdPtr->fd = _pr_md_pipefd[0];
pollfdPtr->events = POLLIN;
pollfdPtr++;
-#ifdef IRIX
- /*
- * On Irix, the second element is the exit pipe
- */
- if (me->cpu->id == 0) {
- pollfdPtr->fd = _pr_irix_primoridal_cpu_fd[0];
- pollfdPtr->events = POLLIN;
- pollfdPtr++;
- }
-#endif
}
min_timeout = PR_INTERVAL_NO_TIMEOUT;
@@ -1545,9 +1550,9 @@ extern sigset_t ints_off;
}
for (; pds < epds; pds++, pollfdPtr++) {
/*
- * Assert that the pollfdPtr pointer does not go
- * beyond the end of the pollfds array
- */
+ * Assert that the pollfdPtr pointer does not go
+ * beyond the end of the pollfds array
+ */
PR_ASSERT(pollfdPtr < pollfds + npollfds);
pollfdPtr->fd = pds->osfd;
/* direct copy of poll flags */
@@ -1589,17 +1594,19 @@ extern sigset_t ints_off;
}
#ifdef _PR_USE_POLL
- if (min_timeout == PR_INTERVAL_NO_TIMEOUT)
+ if (min_timeout == PR_INTERVAL_NO_TIMEOUT) {
timeout = -1;
- else
+ }
+ else {
timeout = PR_IntervalToMilliseconds(min_timeout);
+ }
#else
if (min_timeout == PR_INTERVAL_NO_TIMEOUT) {
tvp = NULL;
} else {
timeout.tv_sec = PR_IntervalToSeconds(min_timeout);
timeout.tv_usec = PR_IntervalToMicroseconds(min_timeout)
- % PR_USEC_PER_SEC;
+ % PR_USEC_PER_SEC;
tvp = &timeout;
}
#endif /* _PR_USE_POLL */
@@ -1615,22 +1622,10 @@ extern sigset_t ints_off;
* are enabled. Otherwise, when the select/poll calls are interrupted, the
* timer value starts ticking from zero again when the system call is restarted.
*/
-#ifdef IRIX
- /*
- * SIGCHLD signal is used on Irix to detect he termination of an
- * sproc by SIGSEGV, SIGBUS or SIGABRT signals when
- * _nspr_terminate_on_error is set.
- */
- if ((!_nspr_noclock) || (_nspr_terminate_on_error))
-#else
- if (!_nspr_noclock)
-#endif /* IRIX */
-#ifdef IRIX
- sigprocmask(SIG_BLOCK, &ints_off, &oldset);
-#else
- PR_ASSERT(sigismember(&timer_set, SIGALRM));
+ if (!_nspr_noclock) {
+ PR_ASSERT(sigismember(&timer_set, SIGALRM));
+ }
sigprocmask(SIG_BLOCK, &timer_set, &oldset);
-#endif /* IRIX */
#endif /* !_PR_NO_CLOCK_TIMER */
#ifndef _PR_USE_POLL
@@ -1641,19 +1636,14 @@ extern sigset_t ints_off;
#endif /* !_PR_USE_POLL */
#ifndef _PR_NO_CLOCK_TIMER
-#ifdef IRIX
- if ((!_nspr_noclock) || (_nspr_terminate_on_error))
-#else
- if (!_nspr_noclock)
-#endif /* IRIX */
- sigprocmask(SIG_SETMASK, &oldset, 0);
+ if (!_nspr_noclock) {
+ sigprocmask(SIG_SETMASK, &oldset, 0);
+ }
#endif /* !_PR_NO_CLOCK_TIMER */
_MD_CHECK_FOR_EXIT();
-#ifdef IRIX
- _PR_MD_primordial_cpu();
-#endif
+ _PR_MD_primordial_cpu();
_PR_MD_IOQ_LOCK();
/*
@@ -1664,45 +1654,21 @@ extern sigset_t ints_off;
pollfdPtr = pollfds;
if (_PR_IS_NATIVE_THREAD_SUPPORTED()) {
/*
- * Assert that the pipe is the first element in the
- * pollfds array.
- */
+ * Assert that the pipe is the first element in the
+ * pollfds array.
+ */
PR_ASSERT(pollfds[0].fd == _pr_md_pipefd[0]);
if ((pollfds[0].revents & POLLIN) && (nfd == 1)) {
/*
- * woken up by another thread; read all the data
- * in the pipe to empty the pipe
- */
+ * woken up by another thread; read all the data
+ * in the pipe to empty the pipe
+ */
while ((rv = read(_pr_md_pipefd[0], _pr_md_pipebuf,
- PIPE_BUF)) == PIPE_BUF){
+ PIPE_BUF)) == PIPE_BUF) {
}
PR_ASSERT((rv > 0) || ((rv == -1) && (errno == EAGAIN)));
}
pollfdPtr++;
-#ifdef IRIX
- /*
- * On Irix, check to see if the primordial cpu needs to exit
- * to cause the process to terminate
- */
- if (me->cpu->id == 0) {
- PR_ASSERT(pollfds[1].fd == _pr_irix_primoridal_cpu_fd[0]);
- if (pollfdPtr->revents & POLLIN) {
- if (_pr_irix_process_exit) {
- /*
- * process exit due to a call to PR_ProcessExit
- */
- prctl(PR_SETEXITSIG, SIGKILL);
- _exit(_pr_irix_process_exit_code);
- } else {
- while ((rv = read(_pr_irix_primoridal_cpu_fd[0],
- _pr_md_pipebuf, PIPE_BUF)) == PIPE_BUF) {
- }
- PR_ASSERT(rv > 0);
- }
- }
- pollfdPtr++;
- }
-#endif
}
for (q = _PR_IOQ(me->cpu).next; q != &_PR_IOQ(me->cpu); q = q->next) {
PRPollQueue *pq = _PR_POLLQUEUE_PTR(q);
@@ -1744,26 +1710,27 @@ extern sigset_t ints_off;
_PR_DEL_SLEEPQ(pq->thr, PR_TRUE);
_PR_SLEEPQ_UNLOCK(pq->thr->cpu);
- if (pq->thr->flags & _PR_SUSPENDING) {
- /*
- * set thread state to SUSPENDED;
- * a Resume operation on the thread
- * will move it to the runQ
- */
- pq->thr->state = _PR_SUSPENDED;
- _PR_MISCQ_LOCK(pq->thr->cpu);
- _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
- _PR_MISCQ_UNLOCK(pq->thr->cpu);
- } else {
- pri = pq->thr->priority;
- pq->thr->state = _PR_RUNNABLE;
-
- _PR_RUNQ_LOCK(cpu);
- _PR_ADD_RUNQ(pq->thr, cpu, pri);
- _PR_RUNQ_UNLOCK(cpu);
- if (_pr_md_idle_cpus > 1)
- _PR_MD_WAKEUP_WAITER(thred);
- }
+ if (pq->thr->flags & _PR_SUSPENDING) {
+ /*
+ * set thread state to SUSPENDED;
+ * a Resume operation on the thread
+ * will move it to the runQ
+ */
+ pq->thr->state = _PR_SUSPENDED;
+ _PR_MISCQ_LOCK(pq->thr->cpu);
+ _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
+ _PR_MISCQ_UNLOCK(pq->thr->cpu);
+ } else {
+ pri = pq->thr->priority;
+ pq->thr->state = _PR_RUNNABLE;
+
+ _PR_RUNQ_LOCK(cpu);
+ _PR_ADD_RUNQ(pq->thr, cpu, pri);
+ _PR_RUNQ_UNLOCK(cpu);
+ if (_pr_md_idle_cpus > 1) {
+ _PR_MD_WAKEUP_WAITER(thred);
+ }
+ }
}
_PR_THREAD_UNLOCK(thred);
_PR_IOQ_OSFD_CNT(me->cpu) -= pq->npds;
@@ -1827,16 +1794,19 @@ extern sigset_t ints_off;
PRInt16 in_flags = pds->in_flags;
PR_ASSERT(osfd >= 0 || in_flags == 0);
if (in_flags & _PR_UNIX_POLL_READ) {
- if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_READ_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_WRITE) {
- if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_WRITE_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_EXCEPT) {
- if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_EXCEPTION_SET(me->cpu));
+ }
}
}
@@ -1845,7 +1815,7 @@ extern sigset_t ints_off;
* after being added to the run queue, do not dereference
* pq
*/
- thred = pq->thr;
+ thred = pq->thr;
_PR_THREAD_LOCK(thred);
if (pq->thr->flags & (_PR_ON_PAUSEQ|_PR_ON_SLEEPQ)) {
_PRCPU *cpu = thred->cpu;
@@ -1853,79 +1823,62 @@ extern sigset_t ints_off;
_PR_DEL_SLEEPQ(pq->thr, PR_TRUE);
_PR_SLEEPQ_UNLOCK(pq->thr->cpu);
- if (pq->thr->flags & _PR_SUSPENDING) {
- /*
- * set thread state to SUSPENDED;
- * a Resume operation on the thread
- * will move it to the runQ
- */
- pq->thr->state = _PR_SUSPENDED;
- _PR_MISCQ_LOCK(pq->thr->cpu);
- _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
- _PR_MISCQ_UNLOCK(pq->thr->cpu);
- } else {
- pri = pq->thr->priority;
- pq->thr->state = _PR_RUNNABLE;
-
- pq->thr->cpu = cpu;
- _PR_RUNQ_LOCK(cpu);
- _PR_ADD_RUNQ(pq->thr, cpu, pri);
- _PR_RUNQ_UNLOCK(cpu);
- if (_pr_md_idle_cpus > 1)
- _PR_MD_WAKEUP_WAITER(thred);
- }
+ if (pq->thr->flags & _PR_SUSPENDING) {
+ /*
+ * set thread state to SUSPENDED;
+ * a Resume operation on the thread
+ * will move it to the runQ
+ */
+ pq->thr->state = _PR_SUSPENDED;
+ _PR_MISCQ_LOCK(pq->thr->cpu);
+ _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
+ _PR_MISCQ_UNLOCK(pq->thr->cpu);
+ } else {
+ pri = pq->thr->priority;
+ pq->thr->state = _PR_RUNNABLE;
+
+ pq->thr->cpu = cpu;
+ _PR_RUNQ_LOCK(cpu);
+ _PR_ADD_RUNQ(pq->thr, cpu, pri);
+ _PR_RUNQ_UNLOCK(cpu);
+ if (_pr_md_idle_cpus > 1) {
+ _PR_MD_WAKEUP_WAITER(thred);
+ }
+ }
}
_PR_THREAD_UNLOCK(thred);
} else {
- if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu))
+ if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu)) {
_PR_IOQ_TIMEOUT(me->cpu) = pq->timeout;
- if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd)
+ }
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd) {
_PR_IOQ_MAX_OSFD(me->cpu) = pq_max_osfd;
+ }
}
}
if (_PR_IS_NATIVE_THREAD_SUPPORTED()) {
if ((FD_ISSET(_pr_md_pipefd[0], rp)) && (nfd == 1)) {
/*
- * woken up by another thread; read all the data
- * in the pipe to empty the pipe
- */
+ * woken up by another thread; read all the data
+ * in the pipe to empty the pipe
+ */
while ((rv =
- read(_pr_md_pipefd[0], _pr_md_pipebuf, PIPE_BUF))
- == PIPE_BUF){
+ read(_pr_md_pipefd[0], _pr_md_pipebuf, PIPE_BUF))
+ == PIPE_BUF) {
}
PR_ASSERT((rv > 0) ||
- ((rv == -1) && (errno == EAGAIN)));
+ ((rv == -1) && (errno == EAGAIN)));
}
- if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0])
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0]) {
_PR_IOQ_MAX_OSFD(me->cpu) = _pr_md_pipefd[0];
-#ifdef IRIX
- if ((me->cpu->id == 0) &&
- (FD_ISSET(_pr_irix_primoridal_cpu_fd[0], rp))) {
- if (_pr_irix_process_exit) {
- /*
- * process exit due to a call to PR_ProcessExit
- */
- prctl(PR_SETEXITSIG, SIGKILL);
- _exit(_pr_irix_process_exit_code);
- } else {
- while ((rv = read(_pr_irix_primoridal_cpu_fd[0],
- _pr_md_pipebuf, PIPE_BUF)) == PIPE_BUF) {
- }
- PR_ASSERT(rv > 0);
- }
- }
- if (me->cpu->id == 0) {
- if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_irix_primoridal_cpu_fd[0])
- _PR_IOQ_MAX_OSFD(me->cpu) = _pr_irix_primoridal_cpu_fd[0];
- }
-#endif
+ }
}
} else if (nfd < 0) {
if (errno == EBADF) {
FindBadFDs();
} else {
PR_LOG(_pr_io_lm, PR_LOG_MAX, ("select() failed with errno %d",
- errno));
+ errno));
}
} else {
PR_ASSERT(nfd == 0);
@@ -1947,14 +1900,17 @@ extern sigset_t ints_off;
pq_max_osfd = pds->osfd;
}
}
- if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu))
+ if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu)) {
_PR_IOQ_TIMEOUT(me->cpu) = pq->timeout;
- if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd)
+ }
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd) {
_PR_IOQ_MAX_OSFD(me->cpu) = pq_max_osfd;
+ }
}
if (_PR_IS_NATIVE_THREAD_SUPPORTED()) {
- if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0])
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0]) {
_PR_IOQ_MAX_OSFD(me->cpu) = _pr_md_pipefd[0];
+ }
}
}
#endif /* _PR_USE_POLL */
@@ -1973,11 +1929,11 @@ void _MD_Wakeup_CPUs()
* pipe full, read all data in pipe to empty it
*/
while ((rv =
- read(_pr_md_pipefd[0], _pr_md_pipebuf, PIPE_BUF))
- == PIPE_BUF) {
+ read(_pr_md_pipefd[0], _pr_md_pipebuf, PIPE_BUF))
+ == PIPE_BUF) {
}
PR_ASSERT((rv > 0) ||
- ((rv == -1) && (errno == EAGAIN)));
+ ((rv == -1) && (errno == EAGAIN)));
rv = write(_pr_md_pipefd[1], &data, 1);
}
}
@@ -2041,10 +1997,10 @@ static void ClockInterruptHandler()
}
#else /* _PR_NO_PREEMPT */
/*
- ** Re-enable unix interrupts (so that we can use
- ** setjmp/longjmp for context switching without having to
- ** worry about the signal state)
- */
+ ** Re-enable unix interrupts (so that we can use
+ ** setjmp/longjmp for context switching without having to
+ ** worry about the signal state)
+ */
sigprocmask(SIG_SETMASK, &empty_set, 0);
PR_LOG(_pr_sched_lm, PR_LOG_MIN, ("clock caused context switch"));
@@ -2056,8 +2012,9 @@ static void ClockInterruptHandler()
_PR_ADD_RUNQ(me, cpu, pri);
_PR_RUNQ_UNLOCK(cpu);
_PR_THREAD_UNLOCK(me);
- } else
+ } else {
me->state = _PR_RUNNABLE;
+ }
_MD_SWITCH_CONTEXT(me);
PR_LOG(_pr_sched_lm, PR_LOG_MIN, ("clock back from context switch"));
#endif /* _PR_NO_PREEMPT */
@@ -2096,10 +2053,12 @@ void _MD_StartInterrupts()
char *eval;
if ((eval = getenv("NSPR_NOCLOCK")) != NULL) {
- if (atoi(eval) == 0)
+ if (atoi(eval) == 0) {
_nspr_noclock = 0;
- else
+ }
+ else {
_nspr_noclock = 1;
+ }
}
#ifndef _PR_NO_CLOCK_TIMER
@@ -2135,10 +2094,10 @@ void _MD_EnableClockInterrupts()
#endif /* HPUX9 */
PR_ASSERT(_pr_numCPU == 1);
- itval.it_interval.tv_sec = 0;
- itval.it_interval.tv_usec = MSEC_PER_TICK * PR_USEC_PER_MSEC;
- itval.it_value = itval.it_interval;
- setitimer(ITIMER_REAL, &itval, 0);
+ itval.it_interval.tv_sec = 0;
+ itval.it_interval.tv_usec = MSEC_PER_TICK * PR_USEC_PER_MSEC;
+ itval.it_value = itval.it_interval;
+ setitimer(ITIMER_REAL, &itval, 0);
}
void _MD_DisableClockInterrupts()
@@ -2147,10 +2106,10 @@ void _MD_DisableClockInterrupts()
extern PRUintn _pr_numCPU;
PR_ASSERT(_pr_numCPU == 1);
- itval.it_interval.tv_sec = 0;
- itval.it_interval.tv_usec = 0;
- itval.it_value = itval.it_interval;
- setitimer(ITIMER_REAL, &itval, 0);
+ itval.it_interval.tv_sec = 0;
+ itval.it_interval.tv_usec = 0;
+ itval.it_value = itval.it_interval;
+ setitimer(ITIMER_REAL, &itval, 0);
}
void _MD_BlockClockInterrupts()
@@ -2181,7 +2140,7 @@ void _MD_MakeNonblock(PRFileDesc *fd)
*/
fcntl(osfd, F_SETFL, flags | O_NONBLOCK);
- }
+}
PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode)
{
@@ -2196,12 +2155,15 @@ PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode)
osflags = O_RDONLY;
}
- if (flags & PR_EXCL)
+ if (flags & PR_EXCL) {
osflags |= O_EXCL;
- if (flags & PR_APPEND)
+ }
+ if (flags & PR_APPEND) {
osflags |= O_APPEND;
- if (flags & PR_TRUNCATE)
+ }
+ if (flags & PR_TRUNCATE) {
osflags |= O_TRUNC;
+ }
if (flags & PR_SYNC) {
#if defined(O_SYNC)
osflags |= O_SYNC;
@@ -2219,8 +2181,9 @@ PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode)
if (flags & PR_CREATE_FILE)
{
osflags |= O_CREAT;
- if (NULL !=_pr_rename_lock)
- PR_Lock(_pr_rename_lock);
+ if (NULL !=_pr_unix_rename_lock) {
+ PR_Lock(_pr_unix_rename_lock);
+ }
}
#if defined(ANDROID)
@@ -2234,14 +2197,15 @@ PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode)
_PR_MD_MAP_OPEN_ERROR(err);
}
- if ((flags & PR_CREATE_FILE) && (NULL !=_pr_rename_lock))
- PR_Unlock(_pr_rename_lock);
+ if ((flags & PR_CREATE_FILE) && (NULL !=_pr_unix_rename_lock)) {
+ PR_Unlock(_pr_unix_rename_lock);
+ }
return rv;
}
PRIntervalTime intr_timeout_ticks;
-#if defined(SOLARIS) || defined(IRIX)
+#if defined(SOLARIS)
static void sigsegvhandler() {
fprintf(stderr,"Received SIGSEGV\n");
fflush(stderr);
@@ -2259,7 +2223,7 @@ static void sigbushandler() {
fflush(stderr);
pause();
}
-#endif /* SOLARIS, IRIX */
+#endif /* SOLARIS */
#endif /* !defined(_PR_PTHREADS) */
@@ -2271,7 +2235,7 @@ void _MD_query_fd_inheritable(PRFileDesc *fd)
flags = fcntl(fd->secret->md.osfd, F_GETFD, 0);
PR_ASSERT(-1 != flags);
fd->secret->inheritable = (flags & FD_CLOEXEC) ?
- _PR_TRI_FALSE : _PR_TRI_TRUE;
+ _PR_TRI_FALSE : _PR_TRI_TRUE;
}
PROffset32 _MD_lseek(PRFileDesc *fd, PROffset32 offset, PRSeekWhence whence)
@@ -2537,12 +2501,15 @@ static int _MD_convert_stat_to_fileinfo(
const struct stat *sb,
PRFileInfo *info)
{
- if (S_IFREG & sb->st_mode)
+ if (S_IFREG & sb->st_mode) {
info->type = PR_FILE_FILE;
- else if (S_IFDIR & sb->st_mode)
+ }
+ else if (S_IFDIR & sb->st_mode) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_OTHER;
+ }
#if defined(_PR_HAVE_LARGE_OFF_T)
if (0x7fffffffL < sb->st_size)
@@ -2561,12 +2528,15 @@ static int _MD_convert_stat64_to_fileinfo64(
const _MDStat64 *sb,
PRFileInfo64 *info)
{
- if (S_IFREG & sb->st_mode)
+ if (S_IFREG & sb->st_mode) {
info->type = PR_FILE_FILE;
- else if (S_IFDIR & sb->st_mode)
+ }
+ else if (S_IFDIR & sb->st_mode) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_OTHER;
+ }
LL_I2L(info->size, sb->st_size);
@@ -2580,10 +2550,12 @@ PRInt32 _MD_getfileinfo(const char *fn, PRFileInfo *info)
struct stat sb;
rv = stat(fn, &sb);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_STAT_ERROR(_MD_ERRNO());
- else if (NULL != info)
+ }
+ else if (NULL != info) {
rv = _MD_convert_stat_to_fileinfo(&sb, info);
+ }
return rv;
}
@@ -2591,10 +2563,12 @@ PRInt32 _MD_getfileinfo64(const char *fn, PRFileInfo64 *info)
{
_MDStat64 sb;
PRInt32 rv = _md_iovector._stat64(fn, &sb);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_STAT_ERROR(_MD_ERRNO());
- else if (NULL != info)
+ }
+ else if (NULL != info) {
rv = _MD_convert_stat64_to_fileinfo64(&sb, info);
+ }
return rv;
}
@@ -2602,10 +2576,12 @@ PRInt32 _MD_getopenfileinfo(const PRFileDesc *fd, PRFileInfo *info)
{
struct stat sb;
PRInt32 rv = fstat(fd->secret->md.osfd, &sb);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_FSTAT_ERROR(_MD_ERRNO());
- else if (NULL != info)
+ }
+ else if (NULL != info) {
rv = _MD_convert_stat_to_fileinfo(&sb, info);
+ }
return rv;
}
@@ -2613,10 +2589,12 @@ PRInt32 _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info)
{
_MDStat64 sb;
PRInt32 rv = _md_iovector._fstat64(fd->secret->md.osfd, &sb);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_FSTAT_ERROR(_MD_ERRNO());
- else if (NULL != info)
+ }
+ else if (NULL != info) {
rv = _MD_convert_stat64_to_fileinfo64(&sb, info);
+ }
return rv;
}
@@ -2626,11 +2604,7 @@ PRInt32 _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info)
* initialized by _PR_MD_FINAL_INIT. This means the log file cannot be a
* large file on some platforms.
*/
-#ifdef SYMBIAN
-struct _MD_IOVector _md_iovector; /* Will crash if NSPR_LOG_FILE is set. */
-#else
struct _MD_IOVector _md_iovector = { open };
-#endif
/*
** These implementations are to emulate large file routines on systems that
@@ -2700,7 +2674,9 @@ static PROffset64 _MD_Unix_lseek64(PRIntn osfd, PROffset64 offset, PRIntn whence
LL_L2I(off, offset);
LL_I2L(rv, lseek(osfd, off, whence));
}
- else errno = EFBIG; /* we can't go there */
+ else {
+ errno = EFBIG; /* we can't go there */
+ }
return rv;
} /* _MD_Unix_lseek64 */
@@ -2735,28 +2711,6 @@ mmap64(void *addr, size_t len, int prot, int flags, int fd, loff_t offset)
}
#endif
-#if defined(OSF1) && defined(__GNUC__)
-
-/*
- * On OSF1 V5.0A, <sys/stat.h> defines stat and fstat as
- * macros when compiled under gcc, so it is rather tricky to
- * take the addresses of the real functions the macros expend
- * to. A simple solution is to define forwarder functions
- * and take the addresses of the forwarder functions instead.
- */
-
-static int stat_forwarder(const char *path, struct stat *buffer)
-{
- return stat(path, buffer);
-}
-
-static int fstat_forwarder(int filedes, struct stat *buffer)
-{
- return fstat(filedes, buffer);
-}
-
-#endif
-
static void _PR_InitIOV(void)
{
#if defined(SOLARIS2_5)
@@ -2789,7 +2743,7 @@ static void _PR_InitIOV(void)
_md_iovector._stat64 = stat;
_md_iovector._lseek64 = _MD_Unix_lseek64;
#elif defined(_PR_HAVE_OFF64_T)
-#if defined(IRIX5_3) || (defined(ANDROID) && __ANDROID_API__ < 21)
+#if (defined(ANDROID) && __ANDROID_API__ < 21)
/*
* Android < 21 doesn't have open64. We pass the O_LARGEFILE flag to open
* in _MD_open.
@@ -2811,13 +2765,8 @@ static void _PR_InitIOV(void)
#elif defined(_PR_HAVE_LARGE_OFF_T)
_md_iovector._open64 = open;
_md_iovector._mmap64 = mmap;
-#if defined(OSF1) && defined(__GNUC__)
- _md_iovector._fstat64 = fstat_forwarder;
- _md_iovector._stat64 = stat_forwarder;
-#else
_md_iovector._fstat64 = fstat;
_md_iovector._stat64 = stat;
-#endif
_md_iovector._lseek64 = lseek;
#else
#error "I don't know yet"
@@ -2837,9 +2786,9 @@ void _PR_UnixInit(void)
sigaddset(&timer_set, SIGALRM);
sigemptyset(&empty_set);
intr_timeout_ticks =
- PR_SecondsToInterval(_PR_INTERRUPT_CHECK_INTERVAL_SECS);
+ PR_SecondsToInterval(_PR_INTERRUPT_CHECK_INTERVAL_SECS);
-#if defined(SOLARIS) || defined(IRIX)
+#if defined(SOLARIS)
if (getenv("NSPR_SIGSEGV_HANDLE")) {
sigact.sa_handler = sigsegvhandler;
@@ -2871,8 +2820,8 @@ void _PR_UnixInit(void)
rv = sigaction(SIGPIPE, &sigact, 0);
PR_ASSERT(0 == rv);
- _pr_rename_lock = PR_NewLock();
- PR_ASSERT(NULL != _pr_rename_lock);
+ _pr_unix_rename_lock = PR_NewLock();
+ PR_ASSERT(NULL != _pr_unix_rename_lock);
_pr_Xfe_mon = PR_NewMonitor();
PR_ASSERT(NULL != _pr_Xfe_mon);
@@ -2881,9 +2830,9 @@ void _PR_UnixInit(void)
void _PR_UnixCleanup(void)
{
- if (_pr_rename_lock) {
- PR_DestroyLock(_pr_rename_lock);
- _pr_rename_lock = NULL;
+ if (_pr_unix_rename_lock) {
+ PR_DestroyLock(_pr_unix_rename_lock);
+ _pr_unix_rename_lock = NULL;
}
if (_pr_Xfe_mon) {
PR_DestroyMonitor(_pr_Xfe_mon);
@@ -2917,7 +2866,7 @@ void _MD_InitSegs(void)
return;
}
#endif
- _pr_zero_fd = open("/dev/zero",O_RDWR , 0);
+ _pr_zero_fd = open("/dev/zero",O_RDWR, 0);
/* Prevent the fd from being inherited by child processes */
fcntl(_pr_zero_fd, F_SETFD, FD_CLOEXEC);
_pr_md_lock = PR_NewLock();
@@ -2956,8 +2905,8 @@ from_heap:
prot |= PROT_EXEC;
#endif
rv = mmap((vaddr != 0) ? vaddr : lastaddr, size, prot,
- _MD_MMAP_FLAGS,
- _pr_zero_fd, 0);
+ _MD_MMAP_FLAGS,
+ _pr_zero_fd, 0);
if (rv == (void*)-1) {
goto from_heap;
}
@@ -2973,10 +2922,12 @@ exit:
void _MD_FreeSegment(PRSegment *seg)
{
- if (seg->flags & _PR_SEG_VM)
+ if (seg->flags & _PR_SEG_VM) {
(void) munmap(seg->vaddr, seg->size);
- else
+ }
+ else {
PR_DELETE(seg->vaddr);
+ }
}
#endif /* _PR_PTHREADS */
@@ -3123,7 +3074,7 @@ PRInt32 _PR_WaitForMultipleFDs(
}
_PR_IOQ_OSFD_CNT(me->cpu) += pdcnt;
-
+
_PR_SLEEPQ_LOCK(me->cpu);
_PR_ADD_SLEEPQ(me, timeout);
me->state = _PR_IO_WAIT;
@@ -3139,7 +3090,7 @@ PRInt32 _PR_WaitForMultipleFDs(
me->io_suspended = PR_FALSE;
/*
- * This thread should run on the same cpu on which it was blocked; when
+ * This thread should run on the same cpu on which it was blocked; when
* the IO request times out the fd sets and fd counts for the
* cpu are updated below.
*/
@@ -3163,16 +3114,19 @@ PRInt32 _PR_WaitForMultipleFDs(
PRInt16 in_flags = unixpd->in_flags;
if (in_flags & _PR_UNIX_POLL_READ) {
- if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_READ_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_WRITE) {
- if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_WRITE_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_EXCEPT) {
- if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_EXCEPTION_SET(me->cpu));
+ }
}
}
#endif /* _PR_USE_POLL */
@@ -3220,12 +3174,12 @@ void _PR_Unblock_IO_Wait(PRThread *thr)
{
int pri = thr->priority;
_PRCPU *cpu = thr->cpu;
-
+
/*
* GLOBAL threads wakeup periodically to check for interrupt
*/
if (_PR_IS_NATIVE_THREAD(thr)) {
- _PR_THREAD_UNLOCK(thr);
+ _PR_THREAD_UNLOCK(thr);
return;
}
@@ -3267,7 +3221,7 @@ int _MD_unix_get_nonblocking_connect_error(int osfd)
if (strcmp(superblock.f_basetype, "ttcpip") == 0) {
/* Using the Tiny Stack! */
rv = getpeername(osfd, (struct sockaddr *) &addr,
- (_PRSockLen_t *) &addrlen);
+ (_PRSockLen_t *) &addrlen);
if (rv == -1) {
int errno_copy = errno; /* make a copy so I don't
* accidentally reset */
@@ -3306,7 +3260,7 @@ int _MD_unix_get_nonblocking_connect_error(int osfd)
_PRSockLen_t optlen = sizeof(err);
if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,
- (char *) &err, &optlen) == -1) {
+ (char *) &err, &optlen) == -1) {
return errno;
} else {
return err;
@@ -3325,16 +3279,16 @@ int _MD_unix_get_nonblocking_connect_error(int osfd)
rv = getmsg(osfd, NULL, NULL, &flags);
PR_ASSERT(-1 == rv || 0 == rv);
if (-1 == rv && errno != EAGAIN && errno != EWOULDBLOCK) {
- return errno;
+ return errno;
}
return 0; /* no error */
#else
- int err;
- _PRSockLen_t optlen = sizeof(err);
- if (getsockopt(osfd, SOL_SOCKET, SO_ERROR, (char*)&err, &optlen) == -1) {
- return errno;
- }
- return err;
+ int err;
+ _PRSockLen_t optlen = sizeof(err);
+ if (getsockopt(osfd, SOL_SOCKET, SO_ERROR, (char*)&err, &optlen) == -1) {
+ return errno;
+ }
+ return err;
#endif
}
@@ -3390,8 +3344,9 @@ _MD_LockFile(PRInt32 f)
arg.l_start = 0;
arg.l_len = 0; /* until EOF */
rv = fcntl(f, F_SETLKW, &arg);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3407,8 +3362,9 @@ _MD_TLockFile(PRInt32 f)
arg.l_start = 0;
arg.l_len = 0; /* until EOF */
rv = fcntl(f, F_SETLK, &arg);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3424,8 +3380,9 @@ _MD_UnlockFile(PRInt32 f)
arg.l_start = 0;
arg.l_len = 0; /* until EOF */
rv = fcntl(f, F_SETLK, &arg);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3439,8 +3396,9 @@ _MD_LockFile(PRInt32 f)
{
PRInt32 rv;
rv = flock(f, LOCK_EX);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3450,8 +3408,9 @@ _MD_TLockFile(PRInt32 f)
{
PRInt32 rv;
rv = flock(f, LOCK_EX|LOCK_NB);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3461,8 +3420,9 @@ _MD_UnlockFile(PRInt32 f)
{
PRInt32 rv;
rv = flock(f, LOCK_UN);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3473,8 +3433,9 @@ _MD_LockFile(PRInt32 f)
{
PRInt32 rv;
rv = lockf(f, F_LOCK, 0);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3484,8 +3445,9 @@ _MD_TLockFile(PRInt32 f)
{
PRInt32 rv;
rv = lockf(f, F_TLOCK, 0);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3495,8 +3457,9 @@ _MD_UnlockFile(PRInt32 f)
{
PRInt32 rv;
rv = lockf(f, F_ULOCK, 0);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3516,20 +3479,23 @@ PRStatus _MD_gethostname(char *name, PRUint32 namelen)
PRStatus _MD_getsysinfo(PRSysInfo cmd, char *name, PRUint32 namelen)
{
- struct utsname info;
+ struct utsname info;
- PR_ASSERT((cmd == PR_SI_SYSNAME) || (cmd == PR_SI_RELEASE));
+ PR_ASSERT((cmd == PR_SI_SYSNAME) || (cmd == PR_SI_RELEASE));
- if (uname(&info) == -1) {
- _PR_MD_MAP_DEFAULT_ERROR(errno);
- return PR_FAILURE;
- }
- if (PR_SI_SYSNAME == cmd)
- (void)PR_snprintf(name, namelen, info.sysname);
- else if (PR_SI_RELEASE == cmd)
- (void)PR_snprintf(name, namelen, info.release);
- else
- return PR_FAILURE;
+ if (uname(&info) == -1) {
+ _PR_MD_MAP_DEFAULT_ERROR(errno);
+ return PR_FAILURE;
+ }
+ if (PR_SI_SYSNAME == cmd) {
+ (void)PR_snprintf(name, namelen, info.sysname);
+ }
+ else if (PR_SI_RELEASE == cmd) {
+ (void)PR_snprintf(name, namelen, info.release);
+ }
+ else {
+ return PR_FAILURE;
+ }
return PR_SUCCESS;
}
@@ -3569,12 +3535,15 @@ PRStatus _MD_CreateFileMap(PRFileMap *fmap, PRInt64 size)
}
if (fmap->prot == PR_PROT_READONLY) {
fmap->md.prot = PROT_READ;
-#ifdef OSF1V4_MAP_PRIVATE_BUG
+#if defined(DARWIN) || defined(ANDROID)
/*
- * Use MAP_SHARED to work around a bug in OSF1 V4.0D
- * (QAR 70220 in the OSF_QAR database) that results in
- * corrupted data in the memory-mapped region. This
- * bug is fixed in V5.0.
+ * This is needed on OS X because its implementation of
+ * POSIX shared memory returns an error for MAP_PRIVATE, even
+ * when the mapping is read-only.
+ *
+ * And this is needed on Android, because mapping ashmem with
+ * MAP_PRIVATE creates a mapping of zeroed memory instead of
+ * the shm contents.
*/
fmap->md.flags = MAP_SHARED;
#else
@@ -3601,8 +3570,8 @@ void * _MD_MemMap(
LL_L2I(off, offset);
if ((addr = mmap(0, len, fmap->md.prot, fmap->md.flags,
- fmap->fd->secret->md.osfd, off)) == (void *) -1) {
- _PR_MD_MAP_MMAP_ERROR(_MD_ERRNO());
+ fmap->fd->secret->md.osfd, off)) == (void *) -1) {
+ _PR_MD_MAP_MMAP_ERROR(_MD_ERRNO());
addr = NULL;
}
return addr;
@@ -3623,7 +3592,7 @@ PRStatus _MD_CloseFileMap(PRFileMap *fmap)
PRStatus rc = PR_Close( fmap->fd );
if ( PR_FAILURE == rc ) {
PR_LOG( _pr_io_lm, PR_LOG_DEBUG,
- ("_MD_CloseFileMap(): error closing anonymnous file map osfd"));
+ ("_MD_CloseFileMap(): error closing anonymnous file map osfd"));
return PR_FAILURE;
}
}
diff --git a/nsprpub/pr/src/md/unix/unix_errors.c b/nsprpub/pr/src/md/unix/unix_errors.c
index bcea0993f..1d8765969 100644
--- a/nsprpub/pr/src/md/unix/unix_errors.c
+++ b/nsprpub/pr/src/md/unix/unix_errors.c
@@ -29,9 +29,9 @@ void _MD_unix_map_default_error(int err)
case EAGAIN:
prError = PR_WOULD_BLOCK_ERROR;
break;
- /*
- * On QNX and Neutrino, EALREADY is defined as EBUSY.
- */
+ /*
+ * On QNX and Neutrino, EALREADY is defined as EBUSY.
+ */
#if EALREADY != EBUSY
case EALREADY:
prError = PR_ALREADY_INITIATED_ERROR;
@@ -127,9 +127,9 @@ void _MD_unix_map_default_error(int err)
case ENFILE:
prError = PR_SYS_DESC_TABLE_FULL_ERROR;
break;
- /*
- * On SCO OpenServer 5, ENOBUFS is defined as ENOSR.
- */
+ /*
+ * On SCO OpenServer 5, ENOBUFS is defined as ENOSR.
+ */
#if defined(ENOBUFS) && (ENOBUFS != ENOSR)
case ENOBUFS:
prError = PR_INSUFFICIENT_RESOURCES_ERROR;
@@ -144,7 +144,7 @@ void _MD_unix_map_default_error(int err)
case ENOLCK:
prError = PR_FILE_IS_LOCKED_ERROR;
break;
-#ifdef ENOLINK
+#ifdef ENOLINK
case ENOLINK:
prError = PR_REMOTE_FILE_ERROR;
break;
@@ -362,9 +362,9 @@ void _MD_unix_map_rmdir_error(int err)
PRErrorCode prError;
switch (err) {
- /*
- * On AIX 4.3, ENOTEMPTY is defined as EEXIST.
- */
+ /*
+ * On AIX 4.3, ENOTEMPTY is defined as EEXIST.
+ */
#if ENOTEMPTY != EEXIST
case ENOTEMPTY:
prError = PR_DIRECTORY_NOT_EMPTY_ERROR;
@@ -530,8 +530,8 @@ void _MD_unix_map_connect_error(int err)
switch (err) {
#if defined(UNIXWARE)
/*
- * On some platforms, if we connect to a port on the local host
- * (the loopback address) that no process is listening on, we get
+ * On some platforms, if we connect to a port on the local host
+ * (the loopback address) that no process is listening on, we get
* EIO instead of ECONNREFUSED.
*/
case EIO:
@@ -738,14 +738,18 @@ void _MD_unix_map_poll_error(int err)
void _MD_unix_map_poll_revents_error(int err)
{
- if (err & POLLNVAL)
+ if (err & POLLNVAL) {
PR_SetError(PR_BAD_DESCRIPTOR_ERROR, EBADF);
- else if (err & POLLHUP)
+ }
+ else if (err & POLLHUP) {
PR_SetError(PR_CONNECT_RESET_ERROR, EPIPE);
- else if (err & POLLERR)
+ }
+ else if (err & POLLERR) {
PR_SetError(PR_IO_ERROR, EIO);
- else
+ }
+ else {
PR_SetError(PR_UNKNOWN_ERROR, err);
+ }
}
#endif /* _PR_POLL_AVAILABLE || _PR_NEED_FAKE_POLL */
diff --git a/nsprpub/pr/src/md/unix/unixware.c b/nsprpub/pr/src/md/unix/unixware.c
index 638af5f2e..d6958558b 100644
--- a/nsprpub/pr/src/md/unix/unixware.c
+++ b/nsprpub/pr/src/md/unix/unixware.c
@@ -20,7 +20,7 @@ void _MD_EarlyInit(void)
PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
@@ -29,7 +29,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
#ifdef ALARMS_BREAK_TCP /* I don't think they do */
PRInt32 _MD_connect(PRInt32 osfd, const PRNetAddr *addr, PRInt32 addrlen,
- PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
PRInt32 rv;
@@ -39,7 +39,7 @@ PRInt32 _MD_connect(PRInt32 osfd, const PRNetAddr *addr, PRInt32 addrlen,
}
PRInt32 _MD_accept(PRInt32 osfd, PRNetAddr *addr, PRInt32 addrlen,
- PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
PRInt32 rv;
@@ -64,8 +64,9 @@ void
_MD_INIT_ATOMIC(void)
{
/* Sigh. Sure wish SYSV semaphores weren't such a pain to use */
- if ((_uw_semf = tmpfile()) == NULL)
+ if ((_uw_semf = tmpfile()) == NULL) {
PR_ASSERT(0);
+ }
return;
}
@@ -112,7 +113,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PRStatus
@@ -127,7 +128,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
@@ -230,30 +231,31 @@ void _MD_EarlyInit(void)
sigaddset(&set, SIGALRM);
}
-PRStatus _MD_CREATE_THREAD(PRThread *thread,
- void (*start)(void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+PRStatus _MD_CREATE_THREAD(PRThread *thread,
+ void (*start)(void *),
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize)
{
- long flags;
-
+ long flags;
+
/* mask out SIGALRM for native thread creation */
- thr_sigsetmask(SIG_BLOCK, &set, &oldset);
+ thr_sigsetmask(SIG_BLOCK, &set, &oldset);
- flags = (state == PR_JOINABLE_THREAD ? THR_SUSPENDED/*|THR_NEW_LWP*/
- : THR_SUSPENDED|THR_DETACHED/*|THR_NEW_LWP*/);
- if (_PR_IS_GCABLE_THREAD(thread) ||
- (scope == PR_GLOBAL_BOUND_THREAD))
- flags |= THR_BOUND;
+ flags = (state == PR_JOINABLE_THREAD ? THR_SUSPENDED/*|THR_NEW_LWP*/
+ : THR_SUSPENDED|THR_DETACHED/*|THR_NEW_LWP*/);
+ if (_PR_IS_GCABLE_THREAD(thread) ||
+ (scope == PR_GLOBAL_BOUND_THREAD)) {
+ flags |= THR_BOUND;
+ }
if (thr_create(NULL, thread->stack->stackSize,
- (void *(*)(void *)) start, (void *) thread,
- flags,
- &thread->md.handle)) {
- thr_sigsetmask(SIG_SETMASK, &oldset, NULL);
- return PR_FAILURE;
+ (void *(*)(void *)) start, (void *) thread,
+ flags,
+ &thread->md.handle)) {
+ thr_sigsetmask(SIG_SETMASK, &oldset, NULL);
+ return PR_FAILURE;
}
@@ -262,34 +264,34 @@ PRStatus _MD_CREATE_THREAD(PRThread *thread,
* its register state is initialized properly for GC */
thread->md.lwpid = -1;
- thr_sigsetmask(SIG_SETMASK, &oldset, NULL);
+ thr_sigsetmask(SIG_SETMASK, &oldset, NULL);
_MD_NEW_SEM(&thread->md.waiter_sem, 0);
- if ((scope == PR_GLOBAL_THREAD) || (scope == PR_GLOBAL_BOUND_THREAD)) {
- thread->flags |= _PR_GLOBAL_SCOPE;
+ if ((scope == PR_GLOBAL_THREAD) || (scope == PR_GLOBAL_BOUND_THREAD)) {
+ thread->flags |= _PR_GLOBAL_SCOPE;
}
- /*
- ** Set the thread priority. This will also place the thread on
+ /*
+ ** Set the thread priority. This will also place the thread on
** the runQ.
**
** Force PR_SetThreadPriority to set the priority by
** setting thread->priority to 100.
*/
{
- int pri;
- pri = thread->priority;
- thread->priority = 100;
- PR_SetThreadPriority( thread, pri );
-
- PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("(0X%x)[Start]: on to runq at priority %d",
- thread, thread->priority));
+ int pri;
+ pri = thread->priority;
+ thread->priority = 100;
+ PR_SetThreadPriority( thread, pri );
+
+ PR_LOG(_pr_thread_lm, PR_LOG_MIN,
+ ("(0X%x)[Start]: on to runq at priority %d",
+ thread, thread->priority));
}
/* Activate the thread */
if (thr_continue( thread->md.handle ) ) {
- return PR_FAILURE;
+ return PR_FAILURE;
}
return PR_SUCCESS;
}
@@ -301,7 +303,7 @@ void _MD_cleanup_thread(PRThread *thread)
hdl = thread->md.handle;
- /*
+ /*
** First, suspend the thread (unless it's the active one)
** Because we suspend it first, we don't have to use LOCK_SCHEDULER to
** prevent both of us modifying the thread structure at the same time.
@@ -310,17 +312,17 @@ void _MD_cleanup_thread(PRThread *thread)
thr_suspend(hdl);
}
PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("(0X%x)[DestroyThread]\n", thread));
+ ("(0X%x)[DestroyThread]\n", thread));
_MD_DESTROY_SEM(&thread->md.waiter_sem);
}
void _MD_SET_PRIORITY(_MDThread *md_thread, PRUintn newPri)
{
- if(thr_setprio((thread_t)md_thread->handle, newPri)) {
- PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("_PR_SetThreadPriority: can't set thread priority\n"));
- }
+ if(thr_setprio((thread_t)md_thread->handle, newPri)) {
+ PR_LOG(_pr_thread_lm, PR_LOG_MIN,
+ ("_PR_SetThreadPriority: can't set thread priority\n"));
+ }
}
void _MD_WAIT_CV(
@@ -373,18 +375,18 @@ PRThread *_pr_current_thread_tls()
PRStatus
_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
{
- _MD_WAIT_SEM(&thread->md.waiter_sem);
- return PR_SUCCESS;
+ _MD_WAIT_SEM(&thread->md.waiter_sem);
+ return PR_SUCCESS;
}
PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
- if (thread == NULL) {
- return PR_SUCCESS;
- }
- _MD_POST_SEM(&thread->md.waiter_sem);
- return PR_SUCCESS;
+ if (thread == NULL) {
+ return PR_SUCCESS;
+ }
+ _MD_POST_SEM(&thread->md.waiter_sem);
+ return PR_SUCCESS;
}
_PRCPU *_pr_current_cpu_tls()
@@ -412,39 +414,40 @@ void _MD_INIT_IO (void)
PRStatus _MD_InitializeThread(PRThread *thread)
{
- if (!_PR_IS_NATIVE_THREAD(thread))
+ if (!_PR_IS_NATIVE_THREAD(thread)) {
return;
- /* prime the sp; substract 4 so we don't hit the assert that
- * curr sp > base_stack
- */
+ }
+ /* prime the sp; substract 4 so we don't hit the assert that
+ * curr sp > base_stack
+ */
thread->md.sp = (uint_t) thread->stack->allocBase - sizeof(long);
thread->md.lwpid = _lwp_self();
thread->md.handle = THR_SELF();
- /* all threads on Solaris are global threads from NSPR's perspective
- * since all of them are mapped to Solaris threads.
- */
+ /* all threads on Solaris are global threads from NSPR's perspective
+ * since all of them are mapped to Solaris threads.
+ */
thread->flags |= _PR_GLOBAL_SCOPE;
- /* For primordial/attached thread, we don't create an underlying native thread.
- * So, _MD_CREATE_THREAD() does not get called. We need to do initialization
- * like allocating thread's synchronization variables and set the underlying
- * native thread's priority.
- */
- if (thread->flags & (_PR_PRIMORDIAL | _PR_ATTACHED)) {
- _MD_NEW_SEM(&thread->md.waiter_sem, 0);
- _MD_SET_PRIORITY(&(thread->md), thread->priority);
- }
- return PR_SUCCESS;
-}
-
-static sigset_t old_mask; /* store away original gc thread sigmask */
-static int gcprio; /* store away original gc thread priority */
-static lwpid_t *all_lwps=NULL; /* list of lwps that we suspended */
+ /* For primordial/attached thread, we don't create an underlying native thread.
+ * So, _MD_CREATE_THREAD() does not get called. We need to do initialization
+ * like allocating thread's synchronization variables and set the underlying
+ * native thread's priority.
+ */
+ if (thread->flags & (_PR_PRIMORDIAL | _PR_ATTACHED)) {
+ _MD_NEW_SEM(&thread->md.waiter_sem, 0);
+ _MD_SET_PRIORITY(&(thread->md), thread->priority);
+ }
+ return PR_SUCCESS;
+}
+
+static sigset_t old_mask; /* store away original gc thread sigmask */
+static int gcprio; /* store away original gc thread priority */
+static lwpid_t *all_lwps=NULL; /* list of lwps that we suspended */
static int num_lwps ;
static int suspendAllOn = 0;
-#define VALID_SP(sp, bottom, top) \
+#define VALID_SP(sp, bottom, top) \
(((uint_t)(sp)) > ((uint_t)(bottom)) && ((uint_t)(sp)) < ((uint_t)(top)))
void unixware_preempt_off()
@@ -456,7 +459,7 @@ void unixware_preempt_off()
void unixware_preempt_on()
{
- sigprocmask (SIG_SETMASK, &old_mask, NULL);
+ sigprocmask (SIG_SETMASK, &old_mask, NULL);
}
void _MD_Begin_SuspendAll()
@@ -466,7 +469,7 @@ void _MD_Begin_SuspendAll()
PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, ("Begin_SuspendAll\n"));
/* run at highest prio so I cannot be preempted */
thr_getprio(thr_self(), &gcprio);
- thr_setprio(thr_self(), 0x7fffffff);
+ thr_setprio(thr_self(), 0x7fffffff);
suspendAllOn = 1;
}
@@ -484,55 +487,60 @@ void _MD_End_ResumeAll()
void _MD_Suspend(PRThread *thr)
{
- int lwp_fd, result;
- int lwp_main_proc_fd = 0;
+ int lwp_fd, result;
+ int lwp_main_proc_fd = 0;
thr_suspend(thr->md.handle);
- if (!_PR_IS_GCABLE_THREAD(thr))
- return;
+ if (!_PR_IS_GCABLE_THREAD(thr)) {
+ return;
+ }
/* XXX Primordial thread can't be bound to an lwp, hence there is no
* way we can assume that we can get the lwp status for primordial
* thread reliably. Hence we skip this for primordial thread, hoping
- * that the SP is saved during lock and cond. wait.
+ * that the SP is saved during lock and cond. wait.
* XXX - Again this is concern only for java interpreter, not for the
* server, 'cause primordial thread in the server does not do java work
*/
- if (thr->flags & _PR_PRIMORDIAL)
- return;
+ if (thr->flags & _PR_PRIMORDIAL) {
+ return;
+ }
/* if the thread is not started yet then don't do anything */
- if (!suspendAllOn || thr->md.lwpid == -1)
- return;
+ if (!suspendAllOn || thr->md.lwpid == -1) {
+ return;
+ }
}
void _MD_Resume(PRThread *thr)
{
- if (!_PR_IS_GCABLE_THREAD(thr) || !suspendAllOn){
- /*XXX When the suspendAllOn is set, we will be trying to do lwp_suspend
- * during that time we can't call any thread lib or libc calls. Hence
- * make sure that no resume is requested for Non gcable thread
- * during suspendAllOn */
- PR_ASSERT(!suspendAllOn);
- thr_continue(thr->md.handle);
- return;
- }
- if (thr->md.lwpid == -1)
- return;
-
- if ( _lwp_continue(thr->md.lwpid) < 0) {
- PR_ASSERT(0); /* ARGH, we are hosed! */
- }
+ if (!_PR_IS_GCABLE_THREAD(thr) || !suspendAllOn) {
+ /*XXX When the suspendAllOn is set, we will be trying to do lwp_suspend
+ * during that time we can't call any thread lib or libc calls. Hence
+ * make sure that no resume is requested for Non gcable thread
+ * during suspendAllOn */
+ PR_ASSERT(!suspendAllOn);
+ thr_continue(thr->md.handle);
+ return;
+ }
+ if (thr->md.lwpid == -1) {
+ return;
+ }
+
+ if ( _lwp_continue(thr->md.lwpid) < 0) {
+ PR_ASSERT(0); /* ARGH, we are hosed! */
+ }
}
PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
if (isCurrent) {
- (void) getcontext(CONTEXT(t)); /* XXX tune me: set md_IRIX.c */
+ (void) getcontext(CONTEXT(t)); /* XXX tune me: set md_IRIX.c */
}
*np = NGREG;
- if (t->md.lwpid == -1)
- memset(&t->md.context.uc_mcontext.gregs[0], 0, NGREG * sizeof(PRWord));
+ if (t->md.lwpid == -1) {
+ memset(&t->md.context.uc_mcontext.gregs[0], 0, NGREG * sizeof(PRWord));
+ }
return (PRWord*) &t->md.context.uc_mcontext.gregs[0];
}
@@ -540,7 +548,7 @@ int
_pr_unixware_clock_gettime (struct timespec *tp)
{
struct timeval tv;
-
+
gettimeofday(&tv, NULL);
tp->tv_sec = tv.tv_sec;
tp->tv_nsec = tv.tv_usec * 1000;
diff --git a/nsprpub/pr/src/md/unix/uxpoll.c b/nsprpub/pr/src/md/unix/uxpoll.c
index 8a618ed80..d01121cbf 100644
--- a/nsprpub/pr/src/md/unix/uxpoll.c
+++ b/nsprpub/pr/src/md/unix/uxpoll.c
@@ -52,19 +52,19 @@ static PRInt32 NativeThreadPoll(
if (pds[index].in_flags & PR_POLL_READ)
{
in_flags_read = (pds[index].fd->methods->poll)(
- pds[index].fd,
- pds[index].in_flags & ~PR_POLL_WRITE,
- &out_flags_read);
+ pds[index].fd,
+ pds[index].in_flags & ~PR_POLL_WRITE,
+ &out_flags_read);
}
if (pds[index].in_flags & PR_POLL_WRITE)
{
in_flags_write = (pds[index].fd->methods->poll)(
- pds[index].fd,
- pds[index].in_flags & ~PR_POLL_READ,
- &out_flags_write);
+ pds[index].fd,
+ pds[index].in_flags & ~PR_POLL_READ,
+ &out_flags_write);
}
if ((0 != (in_flags_read & out_flags_read))
- || (0 != (in_flags_write & out_flags_write)))
+ || (0 != (in_flags_write & out_flags_write)))
{
/* this one is ready right now */
if (0 == ready)
@@ -91,7 +91,7 @@ static PRInt32 NativeThreadPoll(
bottom = PR_GetIdentitiesLayer(pds[index].fd, PR_NSPR_IO_LAYER);
PR_ASSERT(NULL != bottom); /* what to do about that? */
if ((NULL != bottom)
- && (_PR_FILEDESC_OPEN == bottom->secret->state))
+ && (_PR_FILEDESC_OPEN == bottom->secret->state))
{
if (0 == ready)
{
@@ -121,8 +121,9 @@ static PRInt32 NativeThreadPoll(
_PR_POLL_WRITE_SYS_WRITE;
syspoll[index].events |= POLLOUT;
}
- if (pds[index].in_flags & PR_POLL_EXCEPT)
+ if (pds[index].in_flags & PR_POLL_EXCEPT) {
syspoll[index].events |= POLLPRI;
+ }
}
}
else
@@ -168,12 +169,18 @@ retry:
if (EINTR == oserror)
{
- if (timeout == PR_INTERVAL_NO_TIMEOUT) goto retry;
- else if (timeout == PR_INTERVAL_NO_WAIT) ready = 0;
+ if (timeout == PR_INTERVAL_NO_TIMEOUT) {
+ goto retry;
+ }
+ else if (timeout == PR_INTERVAL_NO_WAIT) {
+ ready = 0;
+ }
else
{
elapsed = (PRIntervalTime)(PR_IntervalNow() - start);
- if (elapsed > timeout) ready = 0; /* timed out */
+ if (elapsed > timeout) {
+ ready = 0; /* timed out */
+ }
else
{
remaining = timeout - elapsed;
@@ -182,7 +189,9 @@ retry:
}
}
}
- else _PR_MD_MAP_POLL_ERROR(oserror);
+ else {
+ _PR_MD_MAP_POLL_ERROR(oserror);
+ }
}
else if (ready > 0)
{
@@ -203,12 +212,12 @@ retry:
if (syspoll[index].revents & POLLIN)
{
if (pds[index].out_flags
- & _PR_POLL_READ_SYS_READ)
+ & _PR_POLL_READ_SYS_READ)
{
out_flags |= PR_POLL_READ;
}
if (pds[index].out_flags
- & _PR_POLL_WRITE_SYS_READ)
+ & _PR_POLL_WRITE_SYS_READ)
{
out_flags |= PR_POLL_WRITE;
}
@@ -216,24 +225,28 @@ retry:
if (syspoll[index].revents & POLLOUT)
{
if (pds[index].out_flags
- & _PR_POLL_READ_SYS_WRITE)
+ & _PR_POLL_READ_SYS_WRITE)
{
out_flags |= PR_POLL_READ;
}
if (pds[index].out_flags
- & _PR_POLL_WRITE_SYS_WRITE)
+ & _PR_POLL_WRITE_SYS_WRITE)
{
out_flags |= PR_POLL_WRITE;
}
}
- if (syspoll[index].revents & POLLPRI)
+ if (syspoll[index].revents & POLLPRI) {
out_flags |= PR_POLL_EXCEPT;
- if (syspoll[index].revents & POLLERR)
+ }
+ if (syspoll[index].revents & POLLERR) {
out_flags |= PR_POLL_ERR;
- if (syspoll[index].revents & POLLNVAL)
+ }
+ if (syspoll[index].revents & POLLNVAL) {
out_flags |= PR_POLL_NVAL;
- if (syspoll[index].revents & POLLHUP)
+ }
+ if (syspoll[index].revents & POLLHUP) {
out_flags |= PR_POLL_HUP;
+ }
}
}
pds[index].out_flags = out_flags;
@@ -277,15 +290,15 @@ static PRInt32 NativeThreadSelect(
if (pd->in_flags & PR_POLL_READ)
{
in_flags_read = (pd->fd->methods->poll)(
- pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read);
+ pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read);
}
if (pd->in_flags & PR_POLL_WRITE)
{
in_flags_write = (pd->fd->methods->poll)(
- pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write);
+ pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write);
}
if ((0 != (in_flags_read & out_flags_read))
- || (0 != (in_flags_write & out_flags_write)))
+ || (0 != (in_flags_write & out_flags_write)))
{
/* this one's ready right now */
if (0 == ready)
@@ -313,12 +326,14 @@ static PRInt32 NativeThreadSelect(
bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
PR_ASSERT(NULL != bottom); /* what to do about that? */
if ((NULL != bottom)
- && (_PR_FILEDESC_OPEN == bottom->secret->state))
+ && (_PR_FILEDESC_OPEN == bottom->secret->state))
{
if (0 == ready)
{
PRInt32 osfd = bottom->secret->md.osfd;
- if (osfd > maxfd) maxfd = osfd;
+ if (osfd > maxfd) {
+ maxfd = osfd;
+ }
if (in_flags_read & PR_POLL_READ)
{
pd->out_flags |= _PR_POLL_READ_SYS_READ;
@@ -339,7 +354,9 @@ static PRInt32 NativeThreadSelect(
pd->out_flags |= _PR_POLL_WRITE_SYS_WRITE;
FD_SET(osfd, &wt);
}
- if (pd->in_flags & PR_POLL_EXCEPT) FD_SET(osfd, &ex);
+ if (pd->in_flags & PR_POLL_EXCEPT) {
+ FD_SET(osfd, &ex);
+ }
}
}
else
@@ -363,7 +380,9 @@ static PRInt32 NativeThreadSelect(
}
}
- if (0 != ready) return ready; /* no need to block */
+ if (0 != ready) {
+ return ready; /* no need to block */
+ }
remaining = timeout;
start = PR_IntervalNow();
@@ -381,11 +400,15 @@ retry:
if (ready == -1 && errno == EINTR)
{
- if (timeout == PR_INTERVAL_NO_TIMEOUT) goto retry;
+ if (timeout == PR_INTERVAL_NO_TIMEOUT) {
+ goto retry;
+ }
else
{
elapsed = (PRIntervalTime) (PR_IntervalNow() - start);
- if (elapsed > timeout) ready = 0; /* timed out */
+ if (elapsed > timeout) {
+ ready = 0; /* timed out */
+ }
else
{
remaining = timeout - elapsed;
@@ -415,22 +438,30 @@ retry:
if (FD_ISSET(osfd, &rd))
{
- if (pd->out_flags & _PR_POLL_READ_SYS_READ)
+ if (pd->out_flags & _PR_POLL_READ_SYS_READ) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_READ)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_READ) {
out_flags |= PR_POLL_WRITE;
- }
+ }
+ }
if (FD_ISSET(osfd, &wt))
{
- if (pd->out_flags & _PR_POLL_READ_SYS_WRITE)
+ if (pd->out_flags & _PR_POLL_READ_SYS_WRITE) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE) {
out_flags |= PR_POLL_WRITE;
- }
- if (FD_ISSET(osfd, &ex)) out_flags |= PR_POLL_EXCEPT;
+ }
+ }
+ if (FD_ISSET(osfd, &ex)) {
+ out_flags |= PR_POLL_EXCEPT;
+ }
}
pd->out_flags = out_flags;
- if (out_flags) ready++;
+ if (out_flags) {
+ ready++;
+ }
}
PR_ASSERT(ready > 0);
}
@@ -456,7 +487,9 @@ retry:
}
PR_ASSERT(ready > 0);
}
- else _PR_MD_MAP_SELECT_ERROR(err);
+ else {
+ _PR_MD_MAP_SELECT_ERROR(err);
+ }
}
return ready;
@@ -484,7 +517,7 @@ static PRInt32 LocalThreads(
*/
unixpd = unixpds = (_PRUnixPollDesc*)
- PR_MALLOC(npds * sizeof(_PRUnixPollDesc));
+ PR_MALLOC(npds * sizeof(_PRUnixPollDesc));
if (NULL == unixpds)
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
@@ -503,15 +536,15 @@ static PRInt32 LocalThreads(
if (pd->in_flags & PR_POLL_READ)
{
in_flags_read = (pd->fd->methods->poll)(
- pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read);
+ pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read);
}
if (pd->in_flags & PR_POLL_WRITE)
{
in_flags_write = (pd->fd->methods->poll)(
- pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write);
+ pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write);
}
if ((0 != (in_flags_read & out_flags_read))
- || (0 != (in_flags_write & out_flags_write)))
+ || (0 != (in_flags_write & out_flags_write)))
{
/* this one's ready right now */
if (0 == ready)
@@ -537,7 +570,7 @@ static PRInt32 LocalThreads(
bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
PR_ASSERT(NULL != bottom); /* what to do about that? */
if ((NULL != bottom)
- && (_PR_FILEDESC_OPEN == bottom->secret->state))
+ && (_PR_FILEDESC_OPEN == bottom->secret->state))
{
if (0 == ready)
{
@@ -614,26 +647,34 @@ static PRInt32 LocalThreads(
{
if (unixpd->out_flags & _PR_UNIX_POLL_READ)
{
- if (pd->out_flags & _PR_POLL_READ_SYS_READ)
+ if (pd->out_flags & _PR_POLL_READ_SYS_READ) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_READ)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_READ) {
out_flags |= PR_POLL_WRITE;
+ }
}
if (unixpd->out_flags & _PR_UNIX_POLL_WRITE)
{
- if (pd->out_flags & _PR_POLL_READ_SYS_WRITE)
+ if (pd->out_flags & _PR_POLL_READ_SYS_WRITE) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE) {
out_flags |= PR_POLL_WRITE;
+ }
}
- if (unixpd->out_flags & _PR_UNIX_POLL_EXCEPT)
+ if (unixpd->out_flags & _PR_UNIX_POLL_EXCEPT) {
out_flags |= PR_POLL_EXCEPT;
- if (unixpd->out_flags & _PR_UNIX_POLL_ERR)
+ }
+ if (unixpd->out_flags & _PR_UNIX_POLL_ERR) {
out_flags |= PR_POLL_ERR;
- if (unixpd->out_flags & _PR_UNIX_POLL_NVAL)
+ }
+ if (unixpd->out_flags & _PR_UNIX_POLL_NVAL) {
out_flags |= PR_POLL_NVAL;
- if (unixpd->out_flags & _PR_UNIX_POLL_HUP)
+ }
+ if (unixpd->out_flags & _PR_UNIX_POLL_HUP) {
out_flags |= PR_POLL_HUP;
+ }
}
unixpd++;
}
@@ -662,15 +703,20 @@ PRInt32 _MD_pr_poll(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
return -1;
}
- if (0 == npds) PR_Sleep(timeout);
- else if (_PR_IS_NATIVE_THREAD(me))
+ if (0 == npds) {
+ PR_Sleep(timeout);
+ }
+ else if (_PR_IS_NATIVE_THREAD(me)) {
rv = NativeThreads(pds, npds, timeout);
- else rv = LocalThreads(pds, npds, timeout);
+ }
+ else {
+ rv = LocalThreads(pds, npds, timeout);
+ }
return rv;
} /* _MD_pr_poll */
-#endif /* defined(_PR_PTHREADS) */
+#endif /* defined(_PR_PTHREADS) */
/* uxpoll.c */
diff --git a/nsprpub/pr/src/md/unix/uxproces.c b/nsprpub/pr/src/md/unix/uxproces.c
index 18f23fde8..4216c0442 100644
--- a/nsprpub/pr/src/md/unix/uxproces.c
+++ b/nsprpub/pr/src/md/unix/uxproces.c
@@ -55,11 +55,10 @@ typedef struct pr_PidRecord {
} pr_PidRecord;
/*
- * Irix sprocs and LinuxThreads are actually a kind of processes
+ * LinuxThreads are actually a kind of processes
* that can share the virtual address space and file descriptors.
*/
-#if (defined(IRIX) && !defined(_PR_PTHREADS)) \
- || ((defined(LINUX) || defined(__GNU__) || defined(__GLIBC__)) \
+#if ((defined(LINUX) || defined(__GNU__) || defined(__GLIBC__)) \
&& defined(_PR_PTHREADS))
#define _PR_SHARE_CLONES
#endif
@@ -74,8 +73,8 @@ typedef struct pr_PidRecord {
*/
#if defined(_PR_GLOBAL_THREADS_ONLY) \
- || (defined(_PR_PTHREADS) \
- && !defined(LINUX) && !defined(__GNU__) && !defined(__GLIBC__))
+ || (defined(_PR_PTHREADS) \
+ && !defined(LINUX) && !defined(__GNU__) && !defined(__GLIBC__))
#define _PR_NATIVE_THREADS
#endif
@@ -192,7 +191,7 @@ ForkAndExec(
#ifdef AIX
process->md.pid = (*pr_wp.forkptr)();
-#elif defined(NTO) || defined(SYMBIAN)
+#elif defined(NTO)
/*
* fork() & exec() does not work in a multithreaded process.
* Use spawn() instead.
@@ -204,38 +203,39 @@ ForkAndExec(
if (attr->stdinFd && attr->stdinFd->secret->md.osfd != 0) {
fd_map[0] = dup(attr->stdinFd->secret->md.osfd);
flags = fcntl(fd_map[0], F_GETFL, 0);
- if (flags & O_NONBLOCK)
+ if (flags & O_NONBLOCK) {
fcntl(fd_map[0], F_SETFL, flags & ~O_NONBLOCK);
+ }
}
if (attr->stdoutFd && attr->stdoutFd->secret->md.osfd != 1) {
fd_map[1] = dup(attr->stdoutFd->secret->md.osfd);
flags = fcntl(fd_map[1], F_GETFL, 0);
- if (flags & O_NONBLOCK)
+ if (flags & O_NONBLOCK) {
fcntl(fd_map[1], F_SETFL, flags & ~O_NONBLOCK);
+ }
}
if (attr->stderrFd && attr->stderrFd->secret->md.osfd != 2) {
fd_map[2] = dup(attr->stderrFd->secret->md.osfd);
flags = fcntl(fd_map[2], F_GETFL, 0);
- if (flags & O_NONBLOCK)
+ if (flags & O_NONBLOCK) {
fcntl(fd_map[2], F_SETFL, flags & ~O_NONBLOCK);
+ }
}
PR_ASSERT(attr->currentDirectory == NULL); /* not implemented */
}
-#ifdef SYMBIAN
- /* In Symbian OS, we use posix_spawn instead of fork() and exec() */
- posix_spawn(&(process->md.pid), path, NULL, NULL, argv, childEnvp);
-#else
process->md.pid = spawn(path, 3, fd_map, NULL, argv, childEnvp);
-#endif
- if (fd_map[0] != 0)
+ if (fd_map[0] != 0) {
close(fd_map[0]);
- if (fd_map[1] != 1)
+ }
+ if (fd_map[1] != 1) {
close(fd_map[1]);
- if (fd_map[2] != 2)
+ }
+ if (fd_map[2] != 2) {
close(fd_map[2]);
+ }
}
#else
process->md.pid = fork();
@@ -249,20 +249,20 @@ ForkAndExec(
return NULL;
}
if (0 == process->md.pid) { /* the child process */
- /*
- * If the child process needs to exit, it must call _exit().
- * Do not call exit(), because exit() will flush and close
- * the standard I/O file descriptors, and hence corrupt
- * the parent process's standard I/O data structures.
- */
-
-#if !defined(NTO) && !defined(SYMBIAN)
+ /*
+ * If the child process needs to exit, it must call _exit().
+ * Do not call exit(), because exit() will flush and close
+ * the standard I/O file descriptors, and hence corrupt
+ * the parent process's standard I/O data structures.
+ */
+
+#if !defined(NTO)
if (attr) {
/* the osfd's to redirect stdin, stdout, and stderr to */
int in_osfd = -1, out_osfd = -1, err_osfd = -1;
if (attr->stdinFd
- && attr->stdinFd->secret->md.osfd != 0) {
+ && attr->stdinFd->secret->md.osfd != 0) {
in_osfd = attr->stdinFd->secret->md.osfd;
if (dup2(in_osfd, 0) != 0) {
_exit(1); /* failed */
@@ -273,7 +273,7 @@ ForkAndExec(
}
}
if (attr->stdoutFd
- && attr->stdoutFd->secret->md.osfd != 1) {
+ && attr->stdoutFd->secret->md.osfd != 1) {
out_osfd = attr->stdoutFd->secret->md.osfd;
if (dup2(out_osfd, 1) != 1) {
_exit(1); /* failed */
@@ -284,7 +284,7 @@ ForkAndExec(
}
}
if (attr->stderrFd
- && attr->stderrFd->secret->md.osfd != 2) {
+ && attr->stderrFd->secret->md.osfd != 2) {
err_osfd = attr->stderrFd->secret->md.osfd;
if (dup2(err_osfd, 2) != 2) {
_exit(1); /* failed */
@@ -301,7 +301,7 @@ ForkAndExec(
close(out_osfd);
}
if (err_osfd != -1 && err_osfd != in_osfd
- && err_osfd != out_osfd) {
+ && err_osfd != out_osfd) {
close(err_osfd);
}
if (attr->currentDirectory) {
@@ -363,13 +363,13 @@ _MD_CreateUnixProcess(
int rv;
if (PR_CallOnce(&pr_wp.once, _MD_InitProcesses) == PR_FAILURE) {
- return NULL;
+ return NULL;
}
op = PR_NEW(struct pr_CreateProcOp);
if (NULL == op) {
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- return NULL;
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ return NULL;
}
op->path = path;
op->argv = argv;
@@ -378,19 +378,19 @@ _MD_CreateUnixProcess(
op->done = PR_FALSE;
op->doneCV = PR_NewCondVar(pr_wp.ml);
if (NULL == op->doneCV) {
- PR_DELETE(op);
- return NULL;
+ PR_DELETE(op);
+ return NULL;
}
PR_Lock(pr_wp.ml);
/* add to the tail of op queue */
op->next = NULL;
if (pr_wp.opTail) {
- pr_wp.opTail->next = op;
- pr_wp.opTail = op;
+ pr_wp.opTail->next = op;
+ pr_wp.opTail = op;
} else {
- PR_ASSERT(NULL == pr_wp.opHead);
- pr_wp.opHead = pr_wp.opTail = op;
+ PR_ASSERT(NULL == pr_wp.opHead);
+ pr_wp.opHead = pr_wp.opTail = op;
}
/* wake up the daemon thread */
@@ -399,13 +399,13 @@ _MD_CreateUnixProcess(
} while (-1 == rv && EINTR == errno);
while (op->done == PR_FALSE) {
- PR_WaitCondVar(op->doneCV, PR_INTERVAL_NO_TIMEOUT);
+ PR_WaitCondVar(op->doneCV, PR_INTERVAL_NO_TIMEOUT);
}
PR_Unlock(pr_wp.ml);
PR_DestroyCondVar(op->doneCV);
proc = op->process;
if (!proc) {
- PR_SetError(op->prerror, op->oserror);
+ PR_SetError(op->prerror, op->oserror);
}
PR_DELETE(op);
return proc;
@@ -421,7 +421,7 @@ _MD_CreateUnixProcess(
const PRProcessAttr *attr)
{
if (PR_CallOnce(&pr_wp.once, _MD_InitProcesses) == PR_FAILURE) {
- return NULL;
+ return NULL;
}
return ForkAndExec(path, argv, envp, attr);
} /* _MD_CreateUnixProcess */
@@ -445,10 +445,10 @@ FindPidTable(pid_t pid)
pRec = pr_wp.pidTable[keyHash];
while (pRec) {
- if (pRec->pid == pid) {
- break;
- }
- pRec = pRec->next;
+ if (pRec->pid == pid) {
+ break;
+ }
+ pRec = pRec->next;
}
return pRec;
}
@@ -468,21 +468,21 @@ DeletePidTable(pr_PidRecord *pRec)
int keyHash = (int) (pRec->pid & PID_HASH_MASK);
if (pr_wp.pidTable[keyHash] == pRec) {
- pr_wp.pidTable[keyHash] = pRec->next;
+ pr_wp.pidTable[keyHash] = pRec->next;
} else {
- pr_PidRecord *pred, *cur; /* predecessor and current */
-
- pred = pr_wp.pidTable[keyHash];
- cur = pred->next;
- while (cur) {
- if (cur == pRec) {
- pred->next = cur->next;
- break;
+ pr_PidRecord *pred, *cur; /* predecessor and current */
+
+ pred = pr_wp.pidTable[keyHash];
+ cur = pred->next;
+ while (cur) {
+ if (cur == pRec) {
+ pred->next = cur->next;
+ break;
}
- pred = cur;
- cur = cur->next;
+ pred = cur;
+ cur = cur->next;
}
- PR_ASSERT(cur != NULL);
+ PR_ASSERT(cur != NULL);
}
}
@@ -498,10 +498,10 @@ ExtractExitStatus(int rawExitStatus)
PR_ASSERT(!WIFCONTINUED(rawExitStatus));
#endif
if (WIFEXITED(rawExitStatus)) {
- return WEXITSTATUS(rawExitStatus);
+ return WEXITSTATUS(rawExitStatus);
}
- PR_ASSERT(WIFSIGNALED(rawExitStatus));
- return _PR_SIGNALED_EXITSTATUS;
+ PR_ASSERT(WIFSIGNALED(rawExitStatus));
+ return _PR_SIGNALED_EXITSTATUS;
}
static void
@@ -553,16 +553,16 @@ static void WaitPidDaemonThread(void *unused)
}
PR_Unlock(pr_wp.ml);
- while (1) {
- do {
- pid = waitpid((pid_t) -1, &status, 0);
- } while ((pid_t) -1 == pid && EINTR == errno);
+ while (1) {
+ do {
+ pid = waitpid((pid_t) -1, &status, 0);
+ } while ((pid_t) -1 == pid && EINTR == errno);
/*
* waitpid() cannot return 0 because we did not invoke it
* with the WNOHANG option.
- */
- PR_ASSERT(0 != pid);
+ */
+ PR_ASSERT(0 != pid);
/*
* The only possible error code is ECHILD. But if we do
@@ -570,18 +570,18 @@ static void WaitPidDaemonThread(void *unused)
* when there is a child process to wait for.
*/
PR_ASSERT((pid_t) -1 != pid);
- if ((pid_t) -1 == pid) {
+ if ((pid_t) -1 == pid) {
break;
}
- PR_Lock(pr_wp.ml);
+ PR_Lock(pr_wp.ml);
ProcessReapedChildInternal(pid, status);
pr_wp.numProcs--;
while (0 == pr_wp.numProcs) {
PR_WaitCondVar(pr_wp.cv, PR_INTERVAL_NO_TIMEOUT);
}
- PR_Unlock(pr_wp.ml);
- }
+ PR_Unlock(pr_wp.ml);
+ }
}
}
@@ -616,48 +616,50 @@ static void WaitPidDaemonThread(void *unused)
if (pr_waitpid_daemon_exit) {
return;
}
- PR_Lock(pr_wp.ml);
+ PR_Lock(pr_wp.ml);
#endif
-
+
do {
rv = read(pr_wp.pipefd[0], buf, sizeof(buf));
} while (sizeof(buf) == rv || (-1 == rv && EINTR == errno));
#ifdef _PR_SHARE_CLONES
- while ((op = pr_wp.opHead) != NULL) {
- PR_Unlock(pr_wp.ml);
- op->process = ForkAndExec(op->path, op->argv,
- op->envp, op->attr);
- if (NULL == op->process) {
- op->prerror = PR_GetError();
- op->oserror = PR_GetOSError();
- }
- PR_Lock(pr_wp.ml);
- pr_wp.opHead = op->next;
- if (NULL == pr_wp.opHead) {
- pr_wp.opTail = NULL;
- }
- op->done = PR_TRUE;
- PR_NotifyCondVar(op->doneCV);
- }
- PR_Unlock(pr_wp.ml);
+ while ((op = pr_wp.opHead) != NULL) {
+ PR_Unlock(pr_wp.ml);
+ op->process = ForkAndExec(op->path, op->argv,
+ op->envp, op->attr);
+ if (NULL == op->process) {
+ op->prerror = PR_GetError();
+ op->oserror = PR_GetOSError();
+ }
+ PR_Lock(pr_wp.ml);
+ pr_wp.opHead = op->next;
+ if (NULL == pr_wp.opHead) {
+ pr_wp.opTail = NULL;
+ }
+ op->done = PR_TRUE;
+ PR_NotifyCondVar(op->doneCV);
+ }
+ PR_Unlock(pr_wp.ml);
#endif
- while (1) {
- do {
- pid = waitpid((pid_t) -1, &status, WNOHANG);
- } while ((pid_t) -1 == pid && EINTR == errno);
- if (0 == pid) break;
- if ((pid_t) -1 == pid) {
- /* must be because we have no child processes */
- PR_ASSERT(ECHILD == errno);
- break;
+ while (1) {
+ do {
+ pid = waitpid((pid_t) -1, &status, WNOHANG);
+ } while ((pid_t) -1 == pid && EINTR == errno);
+ if (0 == pid) {
+ break;
+ }
+ if ((pid_t) -1 == pid) {
+ /* must be because we have no child processes */
+ PR_ASSERT(ECHILD == errno);
+ break;
}
- PR_Lock(pr_wp.ml);
+ PR_Lock(pr_wp.ml);
ProcessReapedChildInternal(pid, status);
- PR_Unlock(pr_wp.ml);
- }
+ PR_Unlock(pr_wp.ml);
+ }
}
}
@@ -740,13 +742,13 @@ static PRStatus _MD_InitProcesses(void)
#endif /* !_PR_NATIVE_THREADS */
pr_wp.thread = PR_CreateThread(PR_SYSTEM_THREAD,
- WaitPidDaemonThread, NULL, PR_PRIORITY_NORMAL,
+ WaitPidDaemonThread, NULL, PR_PRIORITY_NORMAL,
#ifdef _PR_SHARE_CLONES
- PR_GLOBAL_THREAD,
+ PR_GLOBAL_THREAD,
#else
- PR_LOCAL_THREAD,
+ PR_LOCAL_THREAD,
#endif
- PR_JOINABLE_THREAD, 0);
+ PR_JOINABLE_THREAD, 0);
PR_ASSERT(NULL != pr_wp.thread);
pr_wp.pidTable = (pr_PidRecord**)PR_CALLOC(NBUCKETS * sizeof(pr_PidRecord *));
@@ -762,26 +764,26 @@ PRStatus _MD_DetachUnixProcess(PRProcess *process)
PR_Lock(pr_wp.ml);
pRec = FindPidTable(process->md.pid);
if (NULL == pRec) {
- pRec = PR_NEW(pr_PidRecord);
- if (NULL == pRec) {
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- retVal = PR_FAILURE;
- goto done;
- }
- pRec->pid = process->md.pid;
- pRec->state = _PR_PID_DETACHED;
- pRec->reapedCV = NULL;
- InsertPidTable(pRec);
+ pRec = PR_NEW(pr_PidRecord);
+ if (NULL == pRec) {
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ retVal = PR_FAILURE;
+ goto done;
+ }
+ pRec->pid = process->md.pid;
+ pRec->state = _PR_PID_DETACHED;
+ pRec->reapedCV = NULL;
+ InsertPidTable(pRec);
} else {
- PR_ASSERT(_PR_PID_REAPED == pRec->state);
- if (_PR_PID_REAPED != pRec->state) {
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- retVal = PR_FAILURE;
- } else {
- DeletePidTable(pRec);
- PR_ASSERT(NULL == pRec->reapedCV);
- PR_DELETE(pRec);
- }
+ PR_ASSERT(_PR_PID_REAPED == pRec->state);
+ if (_PR_PID_REAPED != pRec->state) {
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ retVal = PR_FAILURE;
+ } else {
+ DeletePidTable(pRec);
+ PR_ASSERT(NULL == pRec->reapedCV);
+ PR_DELETE(pRec);
+ }
}
PR_DELETE(process);
@@ -801,47 +803,47 @@ PRStatus _MD_WaitUnixProcess(
PR_Lock(pr_wp.ml);
pRec = FindPidTable(process->md.pid);
if (NULL == pRec) {
- pRec = PR_NEW(pr_PidRecord);
- if (NULL == pRec) {
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- retVal = PR_FAILURE;
- goto done;
- }
- pRec->pid = process->md.pid;
- pRec->state = _PR_PID_WAITING;
- pRec->reapedCV = PR_NewCondVar(pr_wp.ml);
- if (NULL == pRec->reapedCV) {
- PR_DELETE(pRec);
- retVal = PR_FAILURE;
- goto done;
- }
- InsertPidTable(pRec);
- while (!interrupted && _PR_PID_REAPED != pRec->state) {
- if (PR_WaitCondVar(pRec->reapedCV,
- PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE
- && PR_GetError() == PR_PENDING_INTERRUPT_ERROR) {
- interrupted = PR_TRUE;
+ pRec = PR_NEW(pr_PidRecord);
+ if (NULL == pRec) {
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ retVal = PR_FAILURE;
+ goto done;
+ }
+ pRec->pid = process->md.pid;
+ pRec->state = _PR_PID_WAITING;
+ pRec->reapedCV = PR_NewCondVar(pr_wp.ml);
+ if (NULL == pRec->reapedCV) {
+ PR_DELETE(pRec);
+ retVal = PR_FAILURE;
+ goto done;
+ }
+ InsertPidTable(pRec);
+ while (!interrupted && _PR_PID_REAPED != pRec->state) {
+ if (PR_WaitCondVar(pRec->reapedCV,
+ PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE
+ && PR_GetError() == PR_PENDING_INTERRUPT_ERROR) {
+ interrupted = PR_TRUE;
}
- }
- if (_PR_PID_REAPED == pRec->state) {
+ }
+ if (_PR_PID_REAPED == pRec->state) {
if (exitCode) {
*exitCode = pRec->exitStatus;
}
- } else {
- PR_ASSERT(interrupted);
- retVal = PR_FAILURE;
- }
- DeletePidTable(pRec);
- PR_DestroyCondVar(pRec->reapedCV);
- PR_DELETE(pRec);
+ } else {
+ PR_ASSERT(interrupted);
+ retVal = PR_FAILURE;
+ }
+ DeletePidTable(pRec);
+ PR_DestroyCondVar(pRec->reapedCV);
+ PR_DELETE(pRec);
} else {
- PR_ASSERT(_PR_PID_REAPED == pRec->state);
- PR_ASSERT(NULL == pRec->reapedCV);
- DeletePidTable(pRec);
+ PR_ASSERT(_PR_PID_REAPED == pRec->state);
+ PR_ASSERT(NULL == pRec->reapedCV);
+ DeletePidTable(pRec);
if (exitCode) {
*exitCode = pRec->exitStatus;
}
- PR_DELETE(pRec);
+ PR_DELETE(pRec);
}
PR_DELETE(process);
@@ -855,27 +857,21 @@ PRStatus _MD_KillUnixProcess(PRProcess *process)
PRErrorCode prerror;
PRInt32 oserror;
-#ifdef SYMBIAN
- /* In Symbian OS, we can not kill other process with Open C */
- PR_SetError(PR_OPERATION_NOT_SUPPORTED_ERROR, oserror);
- return PR_FAILURE;
-#else
if (kill(process->md.pid, SIGKILL) == 0) {
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
oserror = errno;
switch (oserror) {
case EPERM:
- prerror = PR_NO_ACCESS_RIGHTS_ERROR;
- break;
+ prerror = PR_NO_ACCESS_RIGHTS_ERROR;
+ break;
case ESRCH:
- prerror = PR_INVALID_ARGUMENT_ERROR;
- break;
+ prerror = PR_INVALID_ARGUMENT_ERROR;
+ break;
default:
- prerror = PR_UNKNOWN_ERROR;
- break;
+ prerror = PR_UNKNOWN_ERROR;
+ break;
}
PR_SetError(prerror, oserror);
return PR_FAILURE;
-#endif
} /* _MD_KillUnixProcess */
diff --git a/nsprpub/pr/src/md/unix/uxrng.c b/nsprpub/pr/src/md/unix/uxrng.c
index da2f7e9fe..479859000 100644
--- a/nsprpub/pr/src/md/unix/uxrng.c
+++ b/nsprpub/pr/src/md/unix/uxrng.c
@@ -20,7 +20,7 @@ GetHighResClock(void *buf, size_t maxbytes)
hrtime_t t;
t = gethrtime();
if (t) {
- return _pr_CopyLowBits(buf, maxbytes, &t, sizeof(t));
+ return _pr_CopyLowBits(buf, maxbytes, &t, sizeof(t));
}
return 0;
}
@@ -54,28 +54,6 @@ GetHighResClock(void *buf, size_t maxbytes)
}
#endif
-#elif defined(OSF1)
-
-#include <c_asm.h>
-
-/*
- * Use the "get the cycle counter" instruction on the alpha.
- * The low 32 bits completely turn over in less than a minute.
- * The high 32 bits are some non-counter gunk that changes sometimes.
- */
-static size_t
-GetHighResClock(void *buf, size_t maxbytes)
-{
- unsigned long t;
-
-#ifdef __GNUC__
- __asm__("rpcc %0" : "=r" (t));
-#else
- t = asm("rpcc %v0");
-#endif
- return _pr_CopyLowBits(buf, maxbytes, &t, sizeof(t));
-}
-
#elif defined(AIX)
static size_t
@@ -86,7 +64,7 @@ GetHighResClock(void *buf, size_t maxbytes)
#elif (defined(LINUX) || defined(FREEBSD) || defined(__FreeBSD_kernel__) \
|| defined(NETBSD) || defined(__NetBSD_kernel__) || defined(OPENBSD) \
- || defined(SYMBIAN) || defined(__GNU__))
+ || defined(__GNU__))
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -122,91 +100,8 @@ static size_t GetDevURandom( void *buf, size_t size )
static size_t
GetHighResClock(void *buf, size_t maxbytes)
-{
- return(GetDevURandom( buf, maxbytes ));
-}
-
-#elif defined(IRIX)
-#include <fcntl.h>
-#undef PRIVATE
-#include <sys/mman.h>
-#include <sys/syssgi.h>
-#include <sys/immu.h>
-#include <sys/systeminfo.h>
-#include <sys/utsname.h>
-
-static size_t GetHighResClock(void *buf, size_t maxbuf)
{
- unsigned phys_addr, raddr, cycleval;
- static volatile unsigned *iotimer_addr = NULL;
- static int tries = 0;
- static int cntr_size;
- int mfd;
- unsigned s0[2];
-
-#ifndef SGI_CYCLECNTR_SIZE
-#define SGI_CYCLECNTR_SIZE 165 /* Size user needs to use to read CC */
-#endif
-
- if (iotimer_addr == NULL) {
- if (tries++ > 1) {
- /* Don't keep trying if it didn't work */
- return 0;
- }
-
- /*
- ** For SGI machines we can use the cycle counter, if it has one,
- ** to generate some truly random numbers
- */
- phys_addr = syssgi(SGI_QUERY_CYCLECNTR, &cycleval);
- if (phys_addr) {
- int pgsz = getpagesize();
- int pgoffmask = pgsz - 1;
-
- raddr = phys_addr & ~pgoffmask;
- mfd = open("/dev/mmem", O_RDONLY);
- if (mfd < 0) {
- return 0;
- }
- iotimer_addr = (unsigned *)
- mmap(0, pgoffmask, PROT_READ, MAP_PRIVATE, mfd, (int)raddr);
- if (iotimer_addr == (unsigned*)-1) {
- close(mfd);
- iotimer_addr = NULL;
- return 0;
- }
- iotimer_addr = (unsigned*)
- ((__psint_t)iotimer_addr | (phys_addr & pgoffmask));
- /*
- * The file 'mfd' is purposefully not closed.
- */
- cntr_size = syssgi(SGI_CYCLECNTR_SIZE);
- if (cntr_size < 0) {
- struct utsname utsinfo;
-
- /*
- * We must be executing on a 6.0 or earlier system, since the
- * SGI_CYCLECNTR_SIZE call is not supported.
- *
- * The only pre-6.1 platforms with 64-bit counters are
- * IP19 and IP21 (Challenge, PowerChallenge, Onyx).
- */
- uname(&utsinfo);
- if (!strncmp(utsinfo.machine, "IP19", 4) ||
- !strncmp(utsinfo.machine, "IP21", 4))
- cntr_size = 64;
- else
- cntr_size = 32;
- }
- cntr_size /= 8; /* Convert from bits to bytes */
- }
- }
-
- s0[0] = *iotimer_addr;
- if (cntr_size > 4)
- s0[1] = *(iotimer_addr + 1);
- memcpy(buf, (char *)&s0[0], cntr_size);
- return _pr_CopyLowBits(buf, maxbuf, &s0, cntr_size);
+ return(GetDevURandom( buf, maxbytes ));
}
#elif defined(SCO) || defined(UNIXWARE) || defined(BSDI) || defined(NTO) \
diff --git a/nsprpub/pr/src/md/unix/uxshm.c b/nsprpub/pr/src/md/unix/uxshm.c
index 54e68191c..29a6030f4 100644
--- a/nsprpub/pr/src/md/unix/uxshm.c
+++ b/nsprpub/pr/src/md/unix/uxshm.c
@@ -14,7 +14,7 @@
#include <prshm.h>
#include <prerr.h>
#include <prmem.h>
-#include "primpl.h"
+#include "primpl.h"
#include <fcntl.h>
extern PRLogModuleInfo *_pr_shm_lm;
@@ -36,7 +36,7 @@ extern PRLogModuleInfo *_pr_shm_lm;
#define _MD_CLOSE_SHARED_MEMORY _MD_CloseSharedMemory
#define _MD_DELETE_SHARED_MEMORY _MD_DeleteSharedMemory
-extern PRSharedMemory * _MD_OpenSharedMemory(
+extern PRSharedMemory * _MD_OpenSharedMemory(
const char *name,
PRSize size,
PRIntn flags,
@@ -52,16 +52,16 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
if ( PR_FAILURE == rc )
{
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
return( NULL );
}
shm = PR_NEWZAP( PRSharedMemory );
- if ( NULL == shm )
+ if ( NULL == shm )
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory"));
return( NULL );
}
@@ -69,7 +69,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
if ( NULL == shm->ipcname )
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory"));
PR_DELETE( shm );
return( NULL );
}
@@ -89,7 +89,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
PR_FREEIF( shm->ipcname );
PR_DELETE( shm );
return( NULL );
- }
+ }
if ( close(osfd) == -1 ) {
_PR_MD_MAP_CLOSE_ERROR( errno );
PR_FREEIF( shm->ipcname );
@@ -104,8 +104,8 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
{
rc = PR_FAILURE;
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): ftok() failed on name: %s", shm->ipcname));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_OpenSharedMemory(): ftok() failed on name: %s", shm->ipcname));
PR_FREEIF( shm->ipcname );
PR_DELETE( shm );
return( NULL );
@@ -119,19 +119,19 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
}
if ((errno == EEXIST) && (flags & PR_SHM_EXCL)) {
PR_SetError( PR_FILE_EXISTS_ERROR, errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): shmget() exclusive failed, errno: %d", errno));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_OpenSharedMemory(): shmget() exclusive failed, errno: %d", errno));
PR_FREEIF(shm->ipcname);
PR_DELETE(shm);
return(NULL);
}
- }
+ }
shm->id = shmget( key, shm->size, shm->mode );
if ( -1 == shm->id ) {
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): shmget() failed, errno: %d", errno));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_OpenSharedMemory(): shmget() failed, errno: %d", errno));
PR_FREEIF(shm->ipcname);
PR_DELETE(shm);
return(NULL);
@@ -153,14 +153,14 @@ extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags )
if ( (void*)-1 == addr )
{
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_AttachSharedMemory(): shmat() failed on name: %s, OsError: %d",
- shm->ipcname, PR_GetOSError() ));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_AttachSharedMemory(): shmat() failed on name: %s, OsError: %d",
+ shm->ipcname, PR_GetOSError() ));
addr = NULL;
}
return addr;
-}
+}
extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr )
{
@@ -174,12 +174,12 @@ extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr )
{
rc = PR_FAILURE;
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DetachSharedMemory(): shmdt() failed on name: %s", shm->ipcname ));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DetachSharedMemory(): shmdt() failed on name: %s", shm->ipcname ));
}
return rc;
-}
+}
extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm )
{
@@ -189,7 +189,7 @@ extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm )
PR_DELETE(shm);
return PR_SUCCESS;
-}
+}
extern PRStatus _MD_DeleteSharedMemory( const char *name )
{
@@ -202,19 +202,19 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name )
rc = _PR_MakeNativeIPCName( name, ipcname, PR_IPC_NAME_SIZE, _PRIPCShm );
if ( PR_FAILURE == rc )
{
- PR_SetError( PR_UNKNOWN_ERROR , errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
+ PR_SetError( PR_UNKNOWN_ERROR, errno );
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DeleteSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
return(PR_FAILURE);
}
- /* create the file first */
+ /* create the file first */
{
int osfd = open( ipcname, (O_RDWR | O_CREAT), 0666 );
if ( -1 == osfd ) {
_PR_MD_MAP_OPEN_ERROR( errno );
return( PR_FAILURE );
- }
+ }
if ( close(osfd) == -1 ) {
_PR_MD_MAP_CLOSE_ERROR( errno );
return( PR_FAILURE );
@@ -227,20 +227,15 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name )
{
rc = PR_FAILURE;
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): ftok() failed on name: %s", ipcname));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DeleteSharedMemory(): ftok() failed on name: %s", ipcname));
}
-#ifdef SYMBIAN
- /* In Symbian OS the system imposed minimum is 1 byte, instead of ZERO */
- id = shmget( key, 1, 0 );
-#else
id = shmget( key, 0, 0 );
-#endif
if ( -1 == id ) {
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): shmget() failed, errno: %d", errno));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DeleteSharedMemory(): shmget() failed, errno: %d", errno));
return(PR_FAILURE);
}
@@ -248,16 +243,16 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name )
if ( -1 == urc )
{
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): shmctl() failed on name: %s", ipcname ));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DeleteSharedMemory(): shmctl() failed on name: %s", ipcname ));
return(PR_FAILURE);
}
urc = unlink( ipcname );
if ( -1 == urc ) {
_PR_MD_MAP_UNLINK_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): unlink() failed: %s", ipcname ));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DeleteSharedMemory(): unlink() failed: %s", ipcname ));
return(PR_FAILURE);
}
@@ -280,7 +275,7 @@ struct _MDSharedMemory {
int handle;
};
-extern PRSharedMemory * _MD_OpenSharedMemory(
+extern PRSharedMemory * _MD_OpenSharedMemory(
const char *name,
PRSize size,
PRIntn flags,
@@ -295,17 +290,17 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
rc = _PR_MakeNativeIPCName( name, ipcname, PR_IPC_NAME_SIZE, _PRIPCShm );
if ( PR_FAILURE == rc )
{
- PR_SetError( PR_UNKNOWN_ERROR , errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
+ PR_SetError( PR_UNKNOWN_ERROR, errno );
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
return( NULL );
}
shm = PR_NEWZAP( PRSharedMemory );
- if ( NULL == shm )
+ if ( NULL == shm )
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory"));
return( NULL );
}
@@ -313,13 +308,13 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
if ( NULL == shm->ipcname )
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory"));
return( NULL );
}
/* copy args to struct */
strcpy( shm->ipcname, ipcname );
- shm->size = size;
+ shm->size = size;
shm->mode = mode;
shm->flags = flags;
shm->ident = _PR_SHM_IDENT;
@@ -329,9 +324,10 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
*/
if ( flags & PR_SHM_CREATE ) {
int oflag = (O_CREAT | O_RDWR);
-
- if ( flags & PR_SHM_EXCL )
+
+ if ( flags & PR_SHM_EXCL ) {
oflag |= O_EXCL;
+ }
shm->id = shm_open( shm->ipcname, oflag, shm->mode );
} else {
shm->id = shm_open( shm->ipcname, O_RDWR, shm->mode );
@@ -339,9 +335,9 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
if ( -1 == shm->id ) {
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): shm_open failed: %s, OSError: %d",
- shm->ipcname, PR_GetOSError()));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_OpenSharedMemory(): shm_open failed: %s, OSError: %d",
+ shm->ipcname, PR_GetOSError()));
PR_DELETE( shm->ipcname );
PR_DELETE( shm );
return(NULL);
@@ -350,8 +346,8 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
end = ftruncate( shm->id, shm->size );
if ( -1 == end ) {
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): ftruncate failed, OSError: %d",
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_OpenSharedMemory(): ftruncate failed, OSError: %d",
PR_GetOSError()));
PR_DELETE( shm->ipcname );
PR_DELETE( shm );
@@ -368,24 +364,25 @@ extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags )
PR_ASSERT( shm->ident == _PR_SHM_IDENT );
- if ( PR_SHM_READONLY == flags)
+ if ( PR_SHM_READONLY == flags) {
prot ^= PROT_WRITE;
+ }
addr = mmap( (void*)0, shm->size, prot, MAP_SHARED, shm->id, 0 );
if ((void*)-1 == addr )
{
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_AttachSharedMemory(): mmap failed: %s, errno: %d",
- shm->ipcname, PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_AttachSharedMemory(): mmap failed: %s, errno: %d",
+ shm->ipcname, PR_GetOSError()));
addr = NULL;
} else {
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_AttachSharedMemory(): name: %s, attached at: %p", shm->ipcname, addr));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_AttachSharedMemory(): name: %s, attached at: %p", shm->ipcname, addr));
}
-
+
return addr;
-}
+}
extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr )
{
@@ -399,30 +396,30 @@ extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr )
{
rc = PR_FAILURE;
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DetachSharedMemory(): munmap failed: %s, errno: %d",
- shm->ipcname, PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DetachSharedMemory(): munmap failed: %s, errno: %d",
+ shm->ipcname, PR_GetOSError()));
}
return rc;
-}
+}
extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm )
{
int urc;
-
+
PR_ASSERT( shm->ident == _PR_SHM_IDENT );
urc = close( shm->id );
if ( -1 == urc ) {
_PR_MD_MAP_CLOSE_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_CloseSharedMemory(): close() failed, error: %d", PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_CloseSharedMemory(): close() failed, error: %d", PR_GetOSError()));
return(PR_FAILURE);
}
PR_DELETE( shm->ipcname );
PR_DELETE( shm );
return PR_SUCCESS;
-}
+}
extern PRStatus _MD_DeleteSharedMemory( const char *name )
{
@@ -433,9 +430,9 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name )
rc = _PR_MakeNativeIPCName( name, ipcname, PR_IPC_NAME_SIZE, _PRIPCShm );
if ( PR_FAILURE == rc )
{
- PR_SetError( PR_UNKNOWN_ERROR , errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
+ PR_SetError( PR_UNKNOWN_ERROR, errno );
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
return rc;
}
@@ -443,12 +440,12 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name )
if ( -1 == urc ) {
rc = PR_FAILURE;
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): shm_unlink failed: %s, errno: %d",
- ipcname, PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DeleteSharedMemory(): shm_unlink failed: %s, errno: %d",
+ ipcname, PR_GetOSError()));
} else {
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): %s, success", ipcname));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DeleteSharedMemory(): %s, success", ipcname));
}
return rc;
@@ -464,7 +461,7 @@ extern PRLogModuleInfo *_pr_shma_lm;
#include <unistd.h>
-extern PRFileMap* _md_OpenAnonFileMap(
+extern PRFileMap* _md_OpenAnonFileMap(
const char *dirName,
PRSize size,
PRFileMapProtect prot
@@ -488,100 +485,90 @@ extern PRFileMap* _md_OpenAnonFileMap(
** make maxTries number of attempts at uniqueness in the filename
*/
for ( incr = 0; incr < maxTries ; incr++ ) {
-#if defined(SYMBIAN)
-#define NSPR_AFM_FILENAME "%s\\NSPR-AFM-%d-%p.%d"
-#else
#define NSPR_AFM_FILENAME "%s/.NSPR-AFM-%d-%p.%d"
-#endif
genName = PR_smprintf( NSPR_AFM_FILENAME,
- dirName, (int) pid, tid, incr );
+ dirName, (int) pid, tid, incr );
if ( NULL == genName ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): PR_snprintf(): failed, generating filename"));
+ ("_md_OpenAnonFileMap(): PR_snprintf(): failed, generating filename"));
goto Finished;
}
/* create the file */
osfd = open(genName, (O_CREAT | O_EXCL | O_RDWR), mode);
if (-1 == osfd) {
- if (EEXIST == errno) {
+ if (EEXIST == errno) {
+ PR_smprintf_free(genName);
+ continue; /* name exists, try again */
+ }
+ _PR_MD_MAP_OPEN_ERROR(errno);
+ PR_LOG(
+ _pr_shma_lm,
+ PR_LOG_DEBUG,
+ ("_md_OpenAnonFileMap(): open(): failed, filename: %s, errno: %d",
+ genName,
+ PR_GetOSError()));
PR_smprintf_free(genName);
- continue; /* name exists, try again */
- }
- _PR_MD_MAP_OPEN_ERROR(errno);
- PR_LOG(
- _pr_shma_lm,
- PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): open(): failed, filename: %s, errno: %d",
- genName,
- PR_GetOSError()));
- PR_smprintf_free(genName);
- goto Finished;
+ goto Finished;
}
break; /* name generation and open successful, break; */
} /* end for() */
if (incr == maxTries) {
- PR_ASSERT(-1 == osfd);
- PR_ASSERT(EEXIST == errno);
- _PR_MD_MAP_OPEN_ERROR(errno);
- goto Finished;
+ PR_ASSERT(-1 == osfd);
+ PR_ASSERT(EEXIST == errno);
+ _PR_MD_MAP_OPEN_ERROR(errno);
+ goto Finished;
}
urc = unlink( genName );
-#if defined(SYMBIAN) && defined(__WINS__)
- /* If it is being used by the system or another process, Symbian OS
- * Emulator(WINS) considers this an error. */
- if ( -1 == urc && EACCES != errno ) {
-#else
if ( -1 == urc ) {
-#endif
_PR_MD_MAP_UNLINK_ERROR( errno );
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): failed on unlink(), errno: %d", errno));
+ ("_md_OpenAnonFileMap(): failed on unlink(), errno: %d", errno));
PR_smprintf_free( genName );
close( osfd );
- goto Finished;
+ goto Finished;
}
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): unlink(): %s", genName ));
+ ("_md_OpenAnonFileMap(): unlink(): %s", genName ));
PR_smprintf_free( genName );
fd = PR_ImportFile( osfd );
if ( NULL == fd ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): PR_ImportFile(): failed"));
- goto Finished;
+ ("_md_OpenAnonFileMap(): PR_ImportFile(): failed"));
+ goto Finished;
}
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): fd: %p", fd ));
+ ("_md_OpenAnonFileMap(): fd: %p", fd ));
urc = ftruncate( fd->secret->md.osfd, size );
if ( -1 == urc ) {
_PR_MD_MAP_DEFAULT_ERROR( errno );
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): failed on ftruncate(), errno: %d", errno));
+ ("_md_OpenAnonFileMap(): failed on ftruncate(), errno: %d", errno));
PR_Close( fd );
- goto Finished;
+ goto Finished;
}
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): ftruncate(): size: %d", size ));
+ ("_md_OpenAnonFileMap(): ftruncate(): size: %d", size ));
LL_UI2L(size64, size); /* PRSize (size_t) is unsigned */
fm = PR_CreateFileMap( fd, size64, prot );
if ( NULL == fm ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("PR_OpenAnonFileMap(): failed"));
+ ("PR_OpenAnonFileMap(): failed"));
PR_Close( fd );
- goto Finished;
+ goto Finished;
}
fm->md.isAnonFM = PR_TRUE; /* set fd close */
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): PR_CreateFileMap(): fm: %p", fm ));
+ ("_md_OpenAnonFileMap(): PR_CreateFileMap(): fm: %p", fm ));
-Finished:
+Finished:
return(fm);
} /* end md_OpenAnonFileMap() */
@@ -598,10 +585,10 @@ extern PRStatus _md_ExportFileMapAsString(
{
PRIntn written;
PRIntn prot = (PRIntn)fm->prot;
-
+
written = PR_snprintf( buf, bufSize, "%ld:%d",
- fm->fd->secret->md.osfd, prot );
-
+ fm->fd->secret->md.osfd, prot );
+
return((written == -1)? PR_FAILURE : PR_SUCCESS);
} /* end _md_ExportFileMapAsString() */
@@ -623,21 +610,21 @@ extern PRFileMap * _md_ImportFileMapFromString(
fd = PR_ImportFile( osfd );
if ( NULL == fd ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_ImportFileMapFromString(): PR_ImportFile() failed"));
+ ("_md_ImportFileMapFromString(): PR_ImportFile() failed"));
goto Finished;
}
rc = PR_GetOpenFileInfo64( fd, &info );
if ( PR_FAILURE == rc ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_ImportFileMapFromString(): PR_GetOpenFileInfo64() failed"));
+ ("_md_ImportFileMapFromString(): PR_GetOpenFileInfo64() failed"));
goto Finished;
}
fm = PR_CreateFileMap( fd, info.size, (PRFileMapProtect)prot );
if ( NULL == fm ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_ImportFileMapFromString(): PR_CreateFileMap() failed"));
+ ("_md_ImportFileMapFromString(): PR_CreateFileMap() failed"));
}
Finished:
diff --git a/nsprpub/pr/src/md/unix/uxwrap.c b/nsprpub/pr/src/md/unix/uxwrap.c
index 3f8e149ef..d6f6d0621 100644
--- a/nsprpub/pr/src/md/unix/uxwrap.c
+++ b/nsprpub/pr/src/md/unix/uxwrap.c
@@ -18,30 +18,25 @@
/* Do not wrap select() and poll(). */
#else /* defined(_PR_PTHREADS) || defined(_PR_GLOBAL_THREADS_ONLY) */
/* The include files for select() */
-#ifdef IRIX
-#include <unistd.h>
-#include <bstring.h>
-#endif
-
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
-#define ZAP_SET(_to, _width) \
- PR_BEGIN_MACRO \
- memset(_to, 0, \
- ((_width + 8*sizeof(int)-1) / (8*sizeof(int))) \
- * sizeof(int) \
- ); \
+#define ZAP_SET(_to, _width) \
+ PR_BEGIN_MACRO \
+ memset(_to, 0, \
+ ((_width + 8*sizeof(int)-1) / (8*sizeof(int))) \
+ * sizeof(int) \
+ ); \
PR_END_MACRO
/* see comments in ns/cmd/xfe/mozilla.c (look for "PR_XGetXtHackFD") */
static int _pr_xt_hack_fd = -1;
-
+
int PR_XGetXtHackFD(void)
{
int fds[2];
-
+
if (_pr_xt_hack_fd == -1) {
if (!pipe(fds)) {
_pr_xt_hack_fd = fds[0];
@@ -54,7 +49,7 @@ static int (*_pr_xt_hack_okayToReleaseXLock)(void) = 0;
void PR_SetXtHackOkayToReleaseXLockFn(int (*fn)(void))
{
- _pr_xt_hack_okayToReleaseXLock = fn;
+ _pr_xt_hack_okayToReleaseXLock = fn;
}
@@ -72,10 +67,10 @@ void PR_SetXtHackOkayToReleaseXLockFn(int (*fn)(void))
int select(size_t width, int *rl, int *wl, int *el, const struct timeval *tv)
#elif defined(AIX_RENAME_SELECT)
int wrap_select(unsigned long width, void *rl, void *wl, void *el,
- struct timeval *tv)
+ struct timeval *tv)
#elif defined(_PR_SELECT_CONST_TIMEVAL)
int select(int width, fd_set *rd, fd_set *wr, fd_set *ex,
- const struct timeval *tv)
+ const struct timeval *tv)
#else
int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv)
#endif
@@ -108,10 +103,10 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv)
if (!_pr_initialized) {
_PR_ImplicitInitialization();
}
-
+
#ifndef _PR_LOCAL_THREADS_ONLY
if (_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) {
- return _MD_SELECT(width, rd, wr, ex, tv);
+ return _MD_SELECT(width, rd, wr, ex, tv);
}
#endif
@@ -127,7 +122,7 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv)
* from the select() man pages.
*/
if (tv->tv_sec < 0 || tv->tv_sec > 100000000
- || tv->tv_usec < 0 || tv->tv_usec >= 1000000) {
+ || tv->tv_usec < 0 || tv->tv_usec >= 1000000) {
errno = EINVAL;
return -1;
}
@@ -187,31 +182,37 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv)
* see comments in mozilla/cmd/xfe/mozilla.c (look for
* "PR_XGetXtHackFD")
*/
- {
- int needToLockXAgain;
-
- needToLockXAgain = 0;
- if (rd && (_pr_xt_hack_fd != -1)
- && FD_ISSET(_pr_xt_hack_fd, rd) && PR_XIsLocked()
- && (!_pr_xt_hack_okayToReleaseXLock
- || _pr_xt_hack_okayToReleaseXLock())) {
- PR_XUnlock();
- needToLockXAgain = 1;
- }
-
- /* This is the potentially blocking step */
- retVal = _PR_WaitForMultipleFDs(unixpds, pdcnt, timeout);
-
- if (needToLockXAgain) {
- PR_XLock();
- }
- }
+ {
+ int needToLockXAgain;
+
+ needToLockXAgain = 0;
+ if (rd && (_pr_xt_hack_fd != -1)
+ && FD_ISSET(_pr_xt_hack_fd, rd) && PR_XIsLocked()
+ && (!_pr_xt_hack_okayToReleaseXLock
+ || _pr_xt_hack_okayToReleaseXLock())) {
+ PR_XUnlock();
+ needToLockXAgain = 1;
+ }
+
+ /* This is the potentially blocking step */
+ retVal = _PR_WaitForMultipleFDs(unixpds, pdcnt, timeout);
+
+ if (needToLockXAgain) {
+ PR_XLock();
+ }
+ }
if (retVal > 0) {
/* Compute select results */
- if (rd) ZAP_SET(rd, width);
- if (wr) ZAP_SET(wr, width);
- if (ex) ZAP_SET(ex, width);
+ if (rd) {
+ ZAP_SET(rd, width);
+ }
+ if (wr) {
+ ZAP_SET(wr, width);
+ }
+ if (ex) {
+ ZAP_SET(ex, width);
+ }
/*
* The return value can be either the number of ready file
@@ -226,7 +227,7 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv)
if (unixpd->out_flags & _PR_UNIX_POLL_NVAL) {
errno = EBADF;
PR_LOG(_pr_io_lm, PR_LOG_ERROR,
- ("select returns EBADF for %d", unixpd->osfd));
+ ("select returns EBADF for %d", unixpd->osfd));
retVal = -1;
break;
}
@@ -238,27 +239,25 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv)
* it has a hangup condition.
*/
if (rd && (unixpd->in_flags & _PR_UNIX_POLL_READ)
- && (unixpd->out_flags & (_PR_UNIX_POLL_READ
- | _PR_UNIX_POLL_ERR | _PR_UNIX_POLL_HUP))) {
+ && (unixpd->out_flags & (_PR_UNIX_POLL_READ
+ | _PR_UNIX_POLL_ERR | _PR_UNIX_POLL_HUP))) {
FD_SET(unixpd->osfd, rd);
nbits++;
}
if (wr && (unixpd->in_flags & _PR_UNIX_POLL_WRITE)
- && (unixpd->out_flags & (_PR_UNIX_POLL_WRITE
- | _PR_UNIX_POLL_ERR))) {
+ && (unixpd->out_flags & (_PR_UNIX_POLL_WRITE
+ | _PR_UNIX_POLL_ERR))) {
FD_SET(unixpd->osfd, wr);
nbits++;
}
if (ex && (unixpd->in_flags & _PR_UNIX_POLL_WRITE)
- && (unixpd->out_flags & PR_POLL_EXCEPT)) {
+ && (unixpd->out_flags & PR_POLL_EXCEPT)) {
FD_SET(unixpd->osfd, ex);
nbits++;
}
PR_ASSERT(nbits > 0);
-#if defined(HPUX) || defined(SOLARIS) || defined(OSF1) || defined(AIX)
+#if defined(HPUX) || defined(SOLARIS) || defined(AIX)
retVal += nbits;
-#else /* IRIX */
- retVal += 1;
#endif
}
}
@@ -288,7 +287,7 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv)
*-----------------------------------------------------------------------
* poll() --
*
- * RETURN VALUES:
+ * RETURN VALUES:
* -1: fails, errno indicates the error.
* 0: timed out, the revents bitmasks are not set.
* positive value: the number of file descriptors for which poll()
@@ -303,7 +302,7 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv)
int wrap_poll(void *listptr, unsigned long nfds, long timeout)
#elif (defined(AIX) && !defined(AIX_RENAME_SELECT))
int poll(void *listptr, unsigned long nfds, long timeout)
-#elif defined(OSF1) || (defined(HPUX) && !defined(HPUX9))
+#elif defined(HPUX) && !defined(HPUX9)
int poll(struct pollfd filedes[], unsigned int nfds, int timeout)
#elif defined(HPUX9)
int poll(struct pollfd filedes[], int nfds, int timeout)
@@ -344,7 +343,7 @@ int poll(struct pollfd *filedes, unsigned long nfds, int timeout)
#ifndef _PR_LOCAL_THREADS_ONLY
if (_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) {
- return _MD_POLL(filedes, nfds, timeout);
+ return _MD_POLL(filedes, nfds, timeout);
}
#endif
@@ -372,7 +371,7 @@ int poll(struct pollfd *filedes, unsigned long nfds, int timeout)
}
unixpds = (_PRUnixPollDesc *)
- PR_MALLOC(nfds * sizeof(_PRUnixPollDesc));
+ PR_MALLOC(nfds * sizeof(_PRUnixPollDesc));
if (NULL == unixpds) {
errno = EAGAIN;
return -1;
@@ -405,23 +404,23 @@ int poll(struct pollfd *filedes, unsigned long nfds, int timeout)
unixpd->in_flags = 0;
if (pfd->events & (POLLIN
#ifdef POLLRDNORM
- | POLLRDNORM
+ | POLLRDNORM
#endif
- )) {
+ )) {
unixpd->in_flags |= _PR_UNIX_POLL_READ;
}
if (pfd->events & (POLLOUT
#ifdef POLLWRNORM
- | POLLWRNORM
+ | POLLWRNORM
#endif
- )) {
+ )) {
unixpd->in_flags |= _PR_UNIX_POLL_WRITE;
}
if (pfd->events & (POLLPRI
#ifdef POLLRDBAND
- | POLLRDBAND
+ | POLLRDBAND
#endif
- )) {
+ )) {
unixpd->in_flags |= PR_POLL_EXCEPT;
}
#endif /* _PR_USE_POLL */
diff --git a/nsprpub/pr/src/md/windows/ntdllmn.c b/nsprpub/pr/src/md/windows/ntdllmn.c
index 7dec0517d..e64b312d0 100644
--- a/nsprpub/pr/src/md/windows/ntdllmn.c
+++ b/nsprpub/pr/src/md/windows/ntdllmn.c
@@ -26,7 +26,7 @@ BOOL WINAPI DllMain(
DWORD fdwReason,
LPVOID lpvReserved)
{
-PRThread *me;
+ PRThread *me;
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
@@ -45,8 +45,9 @@ PRThread *me;
case DLL_THREAD_DETACH:
if (_pr_initialized) {
me = _MD_GET_ATTACHED_THREAD();
- if ((me != NULL) && (me->flags & _PR_ATTACHED))
+ if ((me != NULL) && (me->flags & _PR_ATTACHED)) {
_PRI_DetachThread();
+ }
}
break;
case DLL_PROCESS_DETACH:
diff --git a/nsprpub/pr/src/md/windows/ntgc.c b/nsprpub/pr/src/md/windows/ntgc.c
index 55ac92fb0..20ad8a81e 100644
--- a/nsprpub/pr/src/md/windows/ntgc.c
+++ b/nsprpub/pr/src/md/windows/ntgc.c
@@ -10,7 +10,7 @@
#include <windows.h>
#include "primpl.h"
-PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
+PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#if defined(_X86_)
CONTEXT context;
@@ -34,8 +34,8 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
} else {
/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
- * This code is extremely machine dependant and completely
- * undocumented by MS. Its only known to work experimentally.
+ * This code is extremely machine dependant and completely
+ * undocumented by MS. Its only known to work experimentally.
* Ready for a walk on the wild * side?
*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING */
@@ -47,7 +47,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
* Are your palms sweating yet?
*/
- /*
+ /*
** EAX is on the stack (ESP+0)
** EDX is on the stack (ESP+4)
** ECX is on the stack (ESP+8)
@@ -71,7 +71,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
}
/* This function is not used right now, but is left as a reference.
- * If you ever need to get the fiberID from the currently running fiber,
+ * If you ever need to get the fiberID from the currently running fiber,
* this is it.
*/
void *
@@ -81,15 +81,15 @@ GetMyFiberID()
void *fiberData;
/* A pointer to our tib entry is found at FS:[18]
- * At offset 10h is the fiberData pointer. The context of the
- * fiber is stored in there.
+ * At offset 10h is the fiberData pointer. The context of the
+ * fiber is stored in there.
*/
__asm {
mov EDX, FS:[18h]
mov EAX, DWORD PTR [EDX+10h]
mov [fiberData], EAX
}
-
+
return fiberData;
#else
PR_NOT_REACHED("not implemented");
diff --git a/nsprpub/pr/src/md/windows/ntinrval.c b/nsprpub/pr/src/md/windows/ntinrval.c
index 10aca11ba..a44780455 100644
--- a/nsprpub/pr/src/md/windows/ntinrval.c
+++ b/nsprpub/pr/src/md/windows/ntinrval.c
@@ -26,14 +26,14 @@ _PR_MD_INTERVAL_INIT()
HMODULE mmtimerlib = LoadLibraryW(L"mmtimer.dll"); /* XXX leaked! */
if (mmtimerlib) {
intervalFunc = (IntervalFuncType)GetProcAddress(mmtimerlib,
- "timeGetTime");
+ "timeGetTime");
} else {
intervalFunc = &GetTickCount;
}
#endif
}
-PRIntervalTime
+PRIntervalTime
_PR_MD_GET_INTERVAL()
{
/* milliseconds since system start */
@@ -44,7 +44,7 @@ _PR_MD_GET_INTERVAL()
#endif
}
-PRIntervalTime
+PRIntervalTime
_PR_MD_INTERVAL_PER_SEC()
{
return 1000;
diff --git a/nsprpub/pr/src/md/windows/ntio.c b/nsprpub/pr/src/md/windows/ntio.c
index aba53dc85..040bbd310 100644
--- a/nsprpub/pr/src/md/windows/ntio.c
+++ b/nsprpub/pr/src/md/windows/ntio.c
@@ -9,7 +9,7 @@
* For LOCAL_SCOPE threads, we're using NT fibers. For GLOBAL_SCOPE threads
* we're using NT-native threads.
*
- * When doing IO, we want to use completion ports for optimal performance
+ * When doing IO, we want to use completion ports for optimal performance
* with fibers. But if we use completion ports for all IO, it is difficult
* to project a blocking model with GLOBAL_SCOPE threads. To handle this
* we create an extra thread for completing IO for GLOBAL_SCOPE threads.
@@ -32,9 +32,9 @@ static PRThread *_pr_io_completion_thread;
#define RECYCLE_SIZE 512
static struct _MDLock _pr_recycle_lock;
static PRInt32 _pr_recycle_INET_array[RECYCLE_SIZE];
-static PRInt32 _pr_recycle_INET_tail = 0;
+static PRInt32 _pr_recycle_INET_tail = 0;
static PRInt32 _pr_recycle_INET6_array[RECYCLE_SIZE];
-static PRInt32 _pr_recycle_INET6_tail = 0;
+static PRInt32 _pr_recycle_INET6_tail = 0;
__declspec(thread) PRThread *_pr_io_restarted_io = NULL;
DWORD _pr_io_restartedIOIndex; /* The thread local storage slot for each
@@ -97,14 +97,14 @@ static PRInt32 _nt_nonblock_recvfrom(PRFileDesc *, char *, int, struct sockaddr
* An inheritable fd cannot be associated with an I/O completion port
* because the completion notification of async I/O initiated by the
* child process is still posted to the I/O completion port in the
- * parent process.
+ * parent process.
*/
#define _NT_USE_NB_IO(fd) \
((fd)->secret->nonblocking || (fd)->secret->inheritable == _PR_TRI_TRUE)
/*
* UDP support
- *
+ *
* UDP is supported on NT by the continuation thread mechanism.
* The code is borrowed from ptio.c in pthreads nspr, hence the
* PT and pt prefixes. This mechanism is in fact general and
@@ -134,12 +134,22 @@ struct pt_Continuation
/* The building of the continuation operation */
ContinuationFn function; /* what function to continue */
- union { SOCKET osfd; } arg1; /* #1 - the op's fd */
- union { void* buffer; } arg2; /* #2 - primary transfer buffer */
- union { PRIntn amount; } arg3; /* #3 - size of 'buffer' */
- union { PRIntn flags; } arg4; /* #4 - read/write flags */
- union { PRNetAddr *addr; } arg5; /* #5 - send/recv address */
-
+ union {
+ SOCKET osfd;
+ } arg1; /* #1 - the op's fd */
+ union {
+ void* buffer;
+ } arg2; /* #2 - primary transfer buffer */
+ union {
+ PRIntn amount;
+ } arg3; /* #3 - size of 'buffer' */
+ union {
+ PRIntn flags;
+ } arg4; /* #4 - read/write flags */
+ union {
+ PRNetAddr *addr;
+ } arg5; /* #5 - send/recv address */
+
PRIntervalTime timeout; /* representation of the timeout */
PRIntn event; /* flags for select()'s events */
@@ -149,7 +159,10 @@ struct pt_Continuation
** These function can either return an int return code or a pointer to
** some object.
*/
- union { PRIntn code; void *object; } result;
+ union {
+ PRIntn code;
+ void *object;
+ } result;
PRIntn syserrno; /* in case it failed, why (errno) */
pr_ContuationStatus status; /* the status of the operation */
@@ -184,7 +197,7 @@ static PRInt32 pt_SendTo(
PRInt32 amount, PRInt32 flags, const PRNetAddr *addr,
PRIntn addrlen, PRIntervalTime timeout);
static PRInt32 pt_RecvFrom(SOCKET osfd, void *buf, PRInt32 amount,
- PRInt32 flags, PRNetAddr *addr, PRIntn *addr_len, PRIntervalTime timeout);
+ PRInt32 flags, PRNetAddr *addr, PRIntn *addr_len, PRIntervalTime timeout);
/* The key returned from GetQueuedCompletionStatus() is used to determine what
@@ -215,10 +228,10 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
PR_ASSERT(deadThread->state == _PR_DEAD_STATE);
/* XXXMB - cleanup to do here? */
- if ( !_PR_IS_NATIVE_THREAD(deadThread) ){
+ if ( !_PR_IS_NATIVE_THREAD(deadThread) ) {
/* Spinlock while user thread is still running.
* There is no way to use a condition variable here. The thread
- * is dead, and we have to wait until we switch off the dead
+ * is dead, and we have to wait until we switch off the dead
* thread before we can kill the fiber completely.
*/
while ( deadThread->no_sched)
@@ -227,8 +240,9 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
DeleteFiber(deadThread->md.fiber_id);
}
memset(deadThread, 0xa, sizeof(PRThread)); /* debugging */
- if (!deadThread->threadAllocatedOnStack)
+ if (!deadThread->threadAllocatedOnStack) {
PR_DELETE(deadThread);
+ }
_nt_idleCount--;
}
_MD_UNLOCK(&_nt_idleLock);
@@ -238,18 +252,19 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
#if 0
timeout = INFINITE;
#else
- /*
- * temporary hack to poll the runq every 5 seconds because of bug in
- * native threads creating user threads and not poking the right cpu.
- *
- * A local thread that was interrupted is bound to its current
- * cpu but there is no easy way for the interrupter to poke the
- * right cpu. This is a hack to poll the runq every 5 seconds.
- */
+ /*
+ * temporary hack to poll the runq every 5 seconds because of bug in
+ * native threads creating user threads and not poking the right cpu.
+ *
+ * A local thread that was interrupted is bound to its current
+ * cpu but there is no easy way for the interrupter to poke the
+ * right cpu. This is a hack to poll the runq every 5 seconds.
+ */
timeout = 5000;
#endif
- else
+ else {
timeout = PR_IntervalToMilliseconds(ticks);
+ }
/*
* The idea of looping here is to complete as many IOs as possible before
@@ -257,11 +272,11 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
*/
while(1) {
rv = GetQueuedCompletionStatus(
- _pr_completion_port,
- &bytes,
- &key,
- &olp,
- timeout);
+ _pr_completion_port,
+ &bytes,
+ &key,
+ &olp,
+ timeout);
if (rv == 0 && olp == NULL) {
/* Error in GetQueuedCompetionStatus */
if (GetLastError() != WAIT_TIMEOUT) {
@@ -273,8 +288,9 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
}
}
- if (olp == NULL)
+ if (olp == NULL) {
return 0;
+ }
mdOlp = (_MDOverlapped *)olp;
@@ -288,8 +304,8 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
PR_ASSERT(desc != NULL);
mwstatus = rv ? PR_MW_SUCCESS : PR_MW_FAILURE;
if (InterlockedCompareExchange((PVOID *)&desc->outcome,
- (PVOID)mwstatus, (PVOID)PR_MW_PENDING)
- == (PVOID)PR_MW_PENDING) {
+ (PVOID)mwstatus, (PVOID)PR_MW_PENDING)
+ == (PVOID)PR_MW_PENDING) {
if (mwstatus == PR_MW_SUCCESS) {
desc->bytesRecv = bytes;
} else {
@@ -344,8 +360,9 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
PR_ASSERT(mdOlp->ioModel == _MD_BlockingIO);
completed_io = _PR_THREAD_MD_TO_PTR(mdOlp->data.mdThread);
completed_io->md.blocked_io_status = rv;
- if (rv == 0)
+ if (rv == 0) {
completed_io->md.blocked_io_error = GetLastError();
+ }
completed_io->md.blocked_io_bytes = bytes;
if ( !_PR_IS_NATIVE_THREAD(completed_io) ) {
@@ -354,7 +371,7 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
/* The KEY_CVAR notification only occurs when a native thread
* is notifying a user thread. For user-user notifications
- * the wakeup occurs by having the notifier place the thread
+ * the wakeup occurs by having the notifier place the thread
* on the runq directly; for native-native notifications the
* wakeup occurs by calling ReleaseSemaphore.
*/
@@ -391,16 +408,17 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
_PR_THREAD_UNLOCK(completed_io);
- /*
- * If an I/O operation is suspended, the thread
- * must be running on the same cpu on which the
- * I/O operation was issued.
- */
- PR_ASSERT(!completed_io->md.thr_bound_cpu ||
- (completed_io->cpu == completed_io->md.thr_bound_cpu));
-
- if (!completed_io->md.thr_bound_cpu)
- completed_io->cpu = lockedCPU;
+ /*
+ * If an I/O operation is suspended, the thread
+ * must be running on the same cpu on which the
+ * I/O operation was issued.
+ */
+ PR_ASSERT(!completed_io->md.thr_bound_cpu ||
+ (completed_io->cpu == completed_io->md.thr_bound_cpu));
+
+ if (!completed_io->md.thr_bound_cpu) {
+ completed_io->cpu = lockedCPU;
+ }
completed_io->state = _PR_RUNNABLE;
_PR_RUNQ_LOCK(completed_io->cpu);
_PR_ADD_RUNQ(completed_io, completed_io->cpu, pri);
@@ -423,7 +441,7 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
completed_io->state = _PR_RUNNABLE;
_PR_THREAD_UNLOCK(completed_io);
rv = ReleaseSemaphore(completed_io->md.blocked_sema,
- 1, NULL);
+ 1, NULL);
PR_ASSERT(0 != rv);
} else {
_PR_THREAD_UNLOCK(completed_io);
@@ -443,41 +461,41 @@ static PRStatus
_native_thread_md_wait(PRThread *thread, PRIntervalTime ticks)
{
DWORD rv;
- PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
- INFINITE : PR_IntervalToMilliseconds(ticks);
-
- /*
- * thread waiting for a cvar or a joining thread
- */
- rv = WaitForSingleObject(thread->md.blocked_sema, msecs);
- switch(rv) {
- case WAIT_OBJECT_0:
- return PR_SUCCESS;
- break;
- case WAIT_TIMEOUT:
- _PR_THREAD_LOCK(thread);
- PR_ASSERT (thread->state != _PR_IO_WAIT);
- if (thread->wait.cvar != NULL) {
- PR_ASSERT(thread->state == _PR_COND_WAIT);
- thread->wait.cvar = NULL;
- thread->state = _PR_RUNNING;
- _PR_THREAD_UNLOCK(thread);
- } else {
- /* The CVAR was notified just as the timeout
- * occurred. This left the semaphore in the
- * signaled state. Call WaitForSingleObject()
- * to clear the semaphore.
- */
- _PR_THREAD_UNLOCK(thread);
- rv = WaitForSingleObject(thread->md.blocked_sema, INFINITE);
- PR_ASSERT(rv == WAIT_OBJECT_0);
- }
- return PR_SUCCESS;
- break;
- default:
- return PR_FAILURE;
- break;
- }
+ PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
+ INFINITE : PR_IntervalToMilliseconds(ticks);
+
+ /*
+ * thread waiting for a cvar or a joining thread
+ */
+ rv = WaitForSingleObject(thread->md.blocked_sema, msecs);
+ switch(rv) {
+ case WAIT_OBJECT_0:
+ return PR_SUCCESS;
+ break;
+ case WAIT_TIMEOUT:
+ _PR_THREAD_LOCK(thread);
+ PR_ASSERT (thread->state != _PR_IO_WAIT);
+ if (thread->wait.cvar != NULL) {
+ PR_ASSERT(thread->state == _PR_COND_WAIT);
+ thread->wait.cvar = NULL;
+ thread->state = _PR_RUNNING;
+ _PR_THREAD_UNLOCK(thread);
+ } else {
+ /* The CVAR was notified just as the timeout
+ * occurred. This left the semaphore in the
+ * signaled state. Call WaitForSingleObject()
+ * to clear the semaphore.
+ */
+ _PR_THREAD_UNLOCK(thread);
+ rv = WaitForSingleObject(thread->md.blocked_sema, INFINITE);
+ PR_ASSERT(rv == WAIT_OBJECT_0);
+ }
+ return PR_SUCCESS;
+ break;
+ default:
+ return PR_FAILURE;
+ break;
+ }
return PR_SUCCESS;
}
@@ -487,12 +505,12 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
{
DWORD rv;
- if (_native_threads_only) {
- return(_native_thread_md_wait(thread, ticks));
- }
+ if (_native_threads_only) {
+ return(_native_thread_md_wait(thread, ticks));
+ }
if ( thread->flags & _PR_GLOBAL_SCOPE ) {
PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
- INFINITE : PR_IntervalToMilliseconds(ticks);
+ INFINITE : PR_IntervalToMilliseconds(ticks);
rv = WaitForSingleObject(thread->md.blocked_sema, msecs);
switch(rv) {
case WAIT_OBJECT_0:
@@ -589,96 +607,96 @@ static PRStatus
_native_thread_io_wait(PRThread *thread, PRIntervalTime ticks)
{
DWORD rv, bytes;
-#define _NATIVE_IO_WAIT_HANDLES 2
-#define _NATIVE_WAKEUP_EVENT_INDEX 0
-#define _NATIVE_IO_EVENT_INDEX 1
+#define _NATIVE_IO_WAIT_HANDLES 2
+#define _NATIVE_WAKEUP_EVENT_INDEX 0
+#define _NATIVE_IO_EVENT_INDEX 1
- HANDLE wait_handles[_NATIVE_IO_WAIT_HANDLES];
+ HANDLE wait_handles[_NATIVE_IO_WAIT_HANDLES];
- PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
- INFINITE : PR_IntervalToMilliseconds(ticks);
+ PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
+ INFINITE : PR_IntervalToMilliseconds(ticks);
PR_ASSERT(thread->flags & _PR_GLOBAL_SCOPE);
- wait_handles[0] = thread->md.blocked_sema;
- wait_handles[1] = thread->md.thr_event;
- rv = WaitForMultipleObjects(_NATIVE_IO_WAIT_HANDLES, wait_handles,
- FALSE, msecs);
-
- switch(rv) {
- case WAIT_OBJECT_0 + _NATIVE_IO_EVENT_INDEX:
- /*
- * I/O op completed
- */
- _PR_THREAD_LOCK(thread);
- if (thread->state == _PR_IO_WAIT) {
-
- PR_ASSERT(thread->io_suspended == PR_FALSE);
- PR_ASSERT(thread->io_pending == PR_TRUE);
- thread->state = _PR_RUNNING;
- thread->io_pending = PR_FALSE;
- _PR_THREAD_UNLOCK(thread);
- } else {
- /* The IO completed just at the same time the
- * thread was interrupted. This led to us being
- * notified twice. Call WaitForSingleObject()
- * to clear the semaphore.
- */
- PR_ASSERT(thread->io_suspended == PR_TRUE);
- PR_ASSERT(thread->io_pending == PR_TRUE);
- thread->io_pending = PR_FALSE;
- _PR_THREAD_UNLOCK(thread);
- rv = WaitForSingleObject(thread->md.blocked_sema,
- INFINITE);
- PR_ASSERT(rv == WAIT_OBJECT_0);
- }
-
- rv = GetOverlappedResult((HANDLE) thread->io_fd,
- &thread->md.overlapped.overlapped, &bytes, FALSE);
-
- thread->md.blocked_io_status = rv;
- if (rv != 0) {
- thread->md.blocked_io_bytes = bytes;
- } else {
- thread->md.blocked_io_error = GetLastError();
- PR_ASSERT(ERROR_IO_PENDING != thread->md.blocked_io_error);
- }
- rv = ResetEvent(thread->md.thr_event);
- PR_ASSERT(rv != 0);
- break;
- case WAIT_OBJECT_0 + _NATIVE_WAKEUP_EVENT_INDEX:
- /*
- * I/O interrupted;
- */
+ wait_handles[0] = thread->md.blocked_sema;
+ wait_handles[1] = thread->md.thr_event;
+ rv = WaitForMultipleObjects(_NATIVE_IO_WAIT_HANDLES, wait_handles,
+ FALSE, msecs);
+
+ switch(rv) {
+ case WAIT_OBJECT_0 + _NATIVE_IO_EVENT_INDEX:
+ /*
+ * I/O op completed
+ */
+ _PR_THREAD_LOCK(thread);
+ if (thread->state == _PR_IO_WAIT) {
+
+ PR_ASSERT(thread->io_suspended == PR_FALSE);
+ PR_ASSERT(thread->io_pending == PR_TRUE);
+ thread->state = _PR_RUNNING;
+ thread->io_pending = PR_FALSE;
+ _PR_THREAD_UNLOCK(thread);
+ } else {
+ /* The IO completed just at the same time the
+ * thread was interrupted. This led to us being
+ * notified twice. Call WaitForSingleObject()
+ * to clear the semaphore.
+ */
+ PR_ASSERT(thread->io_suspended == PR_TRUE);
+ PR_ASSERT(thread->io_pending == PR_TRUE);
+ thread->io_pending = PR_FALSE;
+ _PR_THREAD_UNLOCK(thread);
+ rv = WaitForSingleObject(thread->md.blocked_sema,
+ INFINITE);
+ PR_ASSERT(rv == WAIT_OBJECT_0);
+ }
+
+ rv = GetOverlappedResult((HANDLE) thread->io_fd,
+ &thread->md.overlapped.overlapped, &bytes, FALSE);
+
+ thread->md.blocked_io_status = rv;
+ if (rv != 0) {
+ thread->md.blocked_io_bytes = bytes;
+ } else {
+ thread->md.blocked_io_error = GetLastError();
+ PR_ASSERT(ERROR_IO_PENDING != thread->md.blocked_io_error);
+ }
+ rv = ResetEvent(thread->md.thr_event);
+ PR_ASSERT(rv != 0);
+ break;
+ case WAIT_OBJECT_0 + _NATIVE_WAKEUP_EVENT_INDEX:
+ /*
+ * I/O interrupted;
+ */
#ifdef DEBUG
- _PR_THREAD_LOCK(thread);
- PR_ASSERT(thread->io_suspended == PR_TRUE);
- _PR_THREAD_UNLOCK(thread);
+ _PR_THREAD_LOCK(thread);
+ PR_ASSERT(thread->io_suspended == PR_TRUE);
+ _PR_THREAD_UNLOCK(thread);
#endif
- break;
- case WAIT_TIMEOUT:
- _PR_THREAD_LOCK(thread);
- if (thread->state == _PR_IO_WAIT) {
- thread->state = _PR_RUNNING;
- thread->io_suspended = PR_TRUE;
- _PR_THREAD_UNLOCK(thread);
- } else {
- /*
- * The thread was interrupted just as the timeout
- * occurred. This left the semaphore in the signaled
- * state. Call WaitForSingleObject() to clear the
- * semaphore.
- */
- PR_ASSERT(thread->io_suspended == PR_TRUE);
- _PR_THREAD_UNLOCK(thread);
- rv = WaitForSingleObject(thread->md.blocked_sema, INFINITE);
- PR_ASSERT(rv == WAIT_OBJECT_0);
- }
- break;
- default:
- return PR_FAILURE;
- break;
- }
+ break;
+ case WAIT_TIMEOUT:
+ _PR_THREAD_LOCK(thread);
+ if (thread->state == _PR_IO_WAIT) {
+ thread->state = _PR_RUNNING;
+ thread->io_suspended = PR_TRUE;
+ _PR_THREAD_UNLOCK(thread);
+ } else {
+ /*
+ * The thread was interrupted just as the timeout
+ * occurred. This left the semaphore in the signaled
+ * state. Call WaitForSingleObject() to clear the
+ * semaphore.
+ */
+ PR_ASSERT(thread->io_suspended == PR_TRUE);
+ _PR_THREAD_UNLOCK(thread);
+ rv = WaitForSingleObject(thread->md.blocked_sema, INFINITE);
+ PR_ASSERT(rv == WAIT_OBJECT_0);
+ }
+ break;
+ default:
+ return PR_FAILURE;
+ break;
+ }
return PR_SUCCESS;
}
@@ -689,28 +707,31 @@ _NT_IO_WAIT(PRThread *thread, PRIntervalTime timeout)
{
PRBool fWait = PR_TRUE;
- if (_native_threads_only) {
- return(_native_thread_io_wait(thread, timeout));
- }
+ if (_native_threads_only) {
+ return(_native_thread_io_wait(thread, timeout));
+ }
if (!_PR_IS_NATIVE_THREAD(thread)) {
_PR_THREAD_LOCK(thread);
- /* The IO may have already completed; if so, don't add to sleepQ,
+ /* The IO may have already completed; if so, don't add to sleepQ,
* since we are already on the runQ!
*/
if (thread->io_pending == PR_TRUE) {
_PR_SLEEPQ_LOCK(thread->cpu);
_PR_ADD_SLEEPQ(thread, timeout);
_PR_SLEEPQ_UNLOCK(thread->cpu);
- } else
+ } else {
fWait = PR_FALSE;
+ }
_PR_THREAD_UNLOCK(thread);
}
- if (fWait)
+ if (fWait) {
return _PR_MD_WAIT(thread, timeout);
- else
+ }
+ else {
return PR_SUCCESS;
+ }
}
/*
@@ -724,18 +745,18 @@ void _PR_Unblock_IO_Wait(PRThread *thr)
{
PRStatus rv;
_PRCPU *cpu = thr->cpu;
-
+
PR_ASSERT(thr->state == _PR_IO_WAIT);
- /*
- * A thread for which an I/O timed out or was interrupted cannot be
- * in an IO_WAIT state except as a result of calling PR_Close or
- * PR_NT_CancelIo for the FD. For these two cases, _PR_IO_WAIT state
- * is not interruptible
- */
- if (thr->md.interrupt_disabled == PR_TRUE) {
- _PR_THREAD_UNLOCK(thr);
- return;
- }
+ /*
+ * A thread for which an I/O timed out or was interrupted cannot be
+ * in an IO_WAIT state except as a result of calling PR_Close or
+ * PR_NT_CancelIo for the FD. For these two cases, _PR_IO_WAIT state
+ * is not interruptible
+ */
+ if (thr->md.interrupt_disabled == PR_TRUE) {
+ _PR_THREAD_UNLOCK(thr);
+ return;
+ }
thr->io_suspended = PR_TRUE;
thr->state = _PR_RUNNABLE;
@@ -745,11 +766,11 @@ void _PR_Unblock_IO_Wait(PRThread *thr)
_PR_SLEEPQ_LOCK(cpu);
_PR_DEL_SLEEPQ(thr, PR_TRUE);
_PR_SLEEPQ_UNLOCK(cpu);
- /*
- * this thread will continue to run on the same cpu until the
- * I/O is aborted by closing the FD or calling CancelIO
- */
- thr->md.thr_bound_cpu = cpu;
+ /*
+ * this thread will continue to run on the same cpu until the
+ * I/O is aborted by closing the FD or calling CancelIO
+ */
+ thr->md.thr_bound_cpu = cpu;
PR_ASSERT(!(thr->flags & _PR_IDLE_THREAD));
_PR_AddThreadToRunQ(me, thr);
@@ -773,13 +794,14 @@ _NT_ResumeIO(PRThread *thread, PRIntervalTime ticks)
}
} else {
_PR_THREAD_LOCK(thread);
- if (!thread->io_pending)
+ if (!thread->io_pending) {
fWait = PR_FALSE;
+ }
thread->io_suspended = PR_FALSE;
-
+
_PR_THREAD_UNLOCK(thread);
}
- /* We don't put ourselves back on the sleepQ yet; until we
+ /* We don't put ourselves back on the sleepQ yet; until we
* set the suspended bit to false, we can't do that. Just save
* the sleep time here, and then continue. The restarted_io handler
* will add us to the sleepQ if needed.
@@ -787,10 +809,12 @@ _NT_ResumeIO(PRThread *thread, PRIntervalTime ticks)
thread->sleep = ticks;
if (fWait) {
- if (!_PR_IS_NATIVE_THREAD(thread))
+ if (!_PR_IS_NATIVE_THREAD(thread)) {
return _PR_MD_WAIT(thread, ticks);
- else
+ }
+ else {
return _NT_IO_WAIT(thread, ticks);
+ }
}
return PR_SUCCESS;
}
@@ -800,36 +824,40 @@ _PR_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread == NULL) {
/* If thread is NULL, we aren't waking a thread, we're just poking
- * idle thread
+ * idle thread
*/
- if ( PostQueuedCompletionStatus(_pr_completion_port, 0,
- KEY_CVAR, NULL) == FALSE)
+ if ( PostQueuedCompletionStatus(_pr_completion_port, 0,
+ KEY_CVAR, NULL) == FALSE) {
return PR_FAILURE;
+ }
return PR_SUCCESS;
}
if ( _PR_IS_NATIVE_THREAD(thread) ) {
- if (ReleaseSemaphore(thread->md.blocked_sema, 1, NULL) == FALSE)
+ if (ReleaseSemaphore(thread->md.blocked_sema, 1, NULL) == FALSE) {
return PR_FAILURE;
- else
+ }
+ else {
return PR_SUCCESS;
+ }
} else {
PRThread *me = _PR_MD_CURRENT_THREAD();
/* When a Native thread has to awaken a user thread, it has to poke
* the completion port because all user threads might be idle, and
- * thus the CPUs are just waiting for a completion.
+ * thus the CPUs are just waiting for a completion.
*
- * XXXMB - can we know when we are truely idle (and not checking
+ * XXXMB - can we know when we are truely idle (and not checking
* the runq)?
*/
if ((_PR_IS_NATIVE_THREAD(me) || (thread->cpu != me->cpu)) &&
- (!thread->md.thr_bound_cpu)) {
+ (!thread->md.thr_bound_cpu)) {
/* The thread should not be in any queue */
PR_ASSERT(thread->queueCount == 0);
- if ( PostQueuedCompletionStatus(_pr_completion_port, 0,
- KEY_CVAR, &(thread->md.overlapped.overlapped)) == FALSE)
+ if ( PostQueuedCompletionStatus(_pr_completion_port, 0,
+ KEY_CVAR, &(thread->md.overlapped.overlapped)) == FALSE) {
return PR_FAILURE;
+ }
}
return PR_SUCCESS;
}
@@ -845,12 +873,12 @@ _PR_MD_INIT_IO()
err = WSAStartup( WSAVersion, &WSAData );
PR_ASSERT(0 == err);
-
- _pr_completion_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE,
- NULL,
- 0,
- 0);
-
+
+ _pr_completion_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE,
+ NULL,
+ 0,
+ 0);
+
_MD_NEW_LOCK(&_pr_recycle_lock);
_MD_NEW_LOCK(&_pr_ioq_lock);
@@ -860,8 +888,9 @@ _PR_MD_INIT_IO()
if (OSversion.dwMajorVersion >= 4) {
_nt_version_gets_lockfile_completion = PR_TRUE;
}
- } else
+ } else {
PR_ASSERT(0);
+ }
#ifdef _NEED_351_FILE_LOCKING_HACK
IsFileLocalInit();
@@ -882,8 +911,8 @@ _PR_MD_INIT_IO()
#endif
pt_tq.thread = PR_CreateThread(
- PR_SYSTEM_THREAD, ContinuationThread, NULL,
- PR_PRIORITY_URGENT, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_SYSTEM_THREAD, ContinuationThread, NULL,
+ PR_PRIORITY_URGENT, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(NULL != pt_tq.thread);
@@ -892,8 +921,8 @@ _PR_MD_INIT_IO()
{
SYSTEMTIME systime;
union {
- PRTime prt;
- FILETIME ft;
+ PRTime prt;
+ FILETIME ft;
} filetime;
BOOL rv;
@@ -972,7 +1001,7 @@ _md_put_recycled_socket(SOCKET newsock, int af)
_MD_UNLOCK(&_pr_recycle_lock);
closesocket(newsock);
}
-
+
return;
}
@@ -985,17 +1014,17 @@ _md_Associate(HANDLE file)
{
HANDLE port;
- if (!_native_threads_only) {
- port = CreateIoCompletionPort((HANDLE)file,
- _pr_completion_port,
- KEY_IO,
- 0);
-
- /* XXX should map error codes on failures */
- return (port == _pr_completion_port);
- } else {
- return 1;
- }
+ if (!_native_threads_only) {
+ port = CreateIoCompletionPort((HANDLE)file,
+ _pr_completion_port,
+ KEY_IO,
+ 0);
+
+ /* XXX should map error codes on failures */
+ return (port == _pr_completion_port);
+ } else {
+ return 1;
+ }
}
/*
@@ -1026,7 +1055,7 @@ _NT_IO_ABORT(PROsfd sock)
int loop_count;
/* This is a clumsy way to abort the IO, but it is all we can do.
- * It looks a bit racy, but we handle all the cases.
+ * It looks a bit racy, but we handle all the cases.
* case 1: IO completes before calling closesocket
* case 1a: fWait is set to PR_FALSE
* This should e the most likely case. We'll properly
@@ -1139,15 +1168,16 @@ _PR_MD_connect_thread(void *cdata)
cd->status = connect(cd->osfd, cd->addr, cd->addrlen);
- if (cd->status == SOCKET_ERROR)
+ if (cd->status == SOCKET_ERROR) {
cd->error = WSAGetLastError();
+ }
return;
}
PRInt32
-_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
+_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
PRIntervalTime timeout)
{
PROsfd osfd = fd->secret->md.osfd;
@@ -1207,7 +1237,7 @@ _PR_MD_BIND(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen)
#if 0
/* Disable nagle- so far unknown if this is good or not...
*/
- rv = setsockopt(fd->secret->md.osfd,
+ rv = setsockopt(fd->secret->md.osfd,
SOL_SOCKET,
TCP_NODELAY,
(const char *)&one,
@@ -1221,19 +1251,19 @@ _PR_MD_BIND(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen)
void _PR_MD_UPDATE_ACCEPT_CONTEXT(PROsfd accept_sock, PROsfd listen_sock)
{
/* Sockets accept()'d with AcceptEx need to call this setsockopt before
- * calling anything other than ReadFile(), WriteFile(), send(), recv(),
- * Transmitfile(), and closesocket(). In order to call any other
+ * calling anything other than ReadFile(), WriteFile(), send(), recv(),
+ * Transmitfile(), and closesocket(). In order to call any other
* winsock functions, we have to make this setsockopt call.
*
* XXXMB - For the server, we *NEVER* need this in
* the "normal" code path. But now we have to call it. This is a waste
- * of a system call. We'd like to only call it before calling the
+ * of a system call. We'd like to only call it before calling the
* obscure socket calls, but since we don't know at that point what the
* original socket was (or even if it is still alive) we can't do it
- * at that point...
+ * at that point...
*/
- setsockopt((SOCKET)accept_sock,
- SOL_SOCKET,
+ setsockopt((SOCKET)accept_sock,
+ SOL_SOCKET,
SO_UPDATE_ACCEPT_CONTEXT,
(char *)&listen_sock,
sizeof(listen_sock));
@@ -1243,8 +1273,8 @@ void _PR_MD_UPDATE_ACCEPT_CONTEXT(PROsfd accept_sock, PROsfd listen_sock)
#define INET_ADDR_PADDED (sizeof(PRNetAddr) + 16)
PROsfd
_PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
- PRIntervalTime timeout, PRBool fast,
- _PR_AcceptTimeoutCallback callback, void *callbackArg)
+ PRIntervalTime timeout, PRBool fast,
+ _PR_AcceptTimeoutCallback callback, void *callbackArg)
{
PROsfd osfd = fd->secret->md.osfd;
PRThread *me = _PR_MD_CURRENT_THREAD();
@@ -1296,21 +1326,23 @@ _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
}
accept_sock = _md_get_recycled_socket(fd->secret->af);
- if (accept_sock == INVALID_SOCKET)
+ if (accept_sock == INVALID_SOCKET) {
return -1;
+ }
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- closesocket(accept_sock);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ closesocket(accept_sock);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
@@ -1327,19 +1359,19 @@ _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
if ( (rv == 0) && ((err = WSAGetLastError()) != ERROR_IO_PENDING)) {
/* Argh! The IO failed */
- closesocket(accept_sock);
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
-
- _PR_MD_MAP_ACCEPTEX_ERROR(err);
+ closesocket(accept_sock);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ _PR_MD_MAP_ACCEPTEX_ERROR(err);
return -1;
}
@@ -1365,27 +1397,29 @@ _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
}
if (me->md.blocked_io_status == 0) {
- closesocket(accept_sock);
- _PR_MD_MAP_ACCEPTEX_ERROR(me->md.blocked_io_error);
+ closesocket(accept_sock);
+ _PR_MD_MAP_ACCEPTEX_ERROR(me->md.blocked_io_error);
return -1;
}
- if (!fast)
+ if (!fast) {
_PR_MD_UPDATE_ACCEPT_CONTEXT((SOCKET)accept_sock, (SOCKET)osfd);
+ }
/* IO is done */
GetAcceptExSockaddrs(
- me->md.acceptex_buf,
- 0,
- INET_ADDR_PADDED,
- INET_ADDR_PADDED,
- (LPSOCKADDR *)&(Laddr),
- &llen,
- (LPSOCKADDR *)&(Raddr),
- (unsigned int *)rlen);
-
- if (raddr != NULL)
+ me->md.acceptex_buf,
+ 0,
+ INET_ADDR_PADDED,
+ INET_ADDR_PADDED,
+ (LPSOCKADDR *)&(Laddr),
+ &llen,
+ (LPSOCKADDR *)&(Raddr),
+ (unsigned int *)rlen);
+
+ if (raddr != NULL) {
memcpy((char *)raddr, (char *)&Raddr->inet, *rlen);
+ }
PR_ASSERT(me->io_pending == PR_FALSE);
@@ -1393,10 +1427,10 @@ _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
}
PRInt32
-_PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, PRNetAddr **raddr,
- void *buf, PRInt32 amount, PRIntervalTime timeout,
- PRBool fast, _PR_AcceptTimeoutCallback callback,
- void *callbackArg)
+_PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, PRNetAddr **raddr,
+ void *buf, PRInt32 amount, PRIntervalTime timeout,
+ PRBool fast, _PR_AcceptTimeoutCallback callback,
+ void *callbackArg)
{
PROsfd sock = sd->secret->md.osfd;
PRThread *me = _PR_MD_CURRENT_THREAD();
@@ -1419,21 +1453,23 @@ _PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, PRNetAddr **raddr,
}
*newSock = _md_get_recycled_socket(sd->secret->af);
- if (*newSock == INVALID_SOCKET)
+ if (*newSock == INVALID_SOCKET) {
return -1;
+ }
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- closesocket(*newSock);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ closesocket(*newSock);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
@@ -1449,19 +1485,19 @@ _PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, PRNetAddr **raddr,
&(me->md.overlapped.overlapped));
if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING)) {
- closesocket(*newSock);
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
-
- _PR_MD_MAP_ACCEPTEX_ERROR(err);
+ closesocket(*newSock);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ _PR_MD_MAP_ACCEPTEX_ERROR(err);
return -1;
}
@@ -1481,7 +1517,7 @@ retry:
PR_ASSERT(timeout != PR_INTERVAL_NO_TIMEOUT);
- err = getsockopt(*newSock,
+ err = getsockopt(*newSock,
SOL_SOCKET,
SO_CONNECT_TIME,
(char *)&seconds,
@@ -1489,14 +1525,17 @@ retry:
if ( err == NO_ERROR ) {
PRIntervalTime elapsed = PR_SecondsToInterval(seconds);
- if (seconds == 0xffffffff)
+ if (seconds == 0xffffffff) {
isConnected = PR_FALSE;
- else
+ }
+ else {
isConnected = PR_TRUE;
+ }
if (!isConnected) {
- if (madeCallback == PR_FALSE && callback)
+ if (madeCallback == PR_FALSE && callback) {
callback(callbackArg);
+ }
madeCallback = PR_TRUE;
me->state = _PR_IO_WAIT;
if (_NT_ResumeIO(me, timeout) == PR_FAILURE) {
@@ -1527,9 +1566,9 @@ retry:
PR_ASSERT(me->io_pending == PR_FALSE);
PR_ASSERT(me->io_suspended == PR_FALSE);
PR_ASSERT(me->md.thr_bound_cpu == NULL);
- /* If the IO is still suspended, it means we didn't get any
+ /* If the IO is still suspended, it means we didn't get any
* completion from NT_IO_WAIT. This is not disasterous, I hope,
- * but it may mean we still have an IO outstanding... Try to
+ * but it may mean we still have an IO outstanding... Try to
* recover by just allowing ourselves to continue.
*/
me->io_suspended = PR_FALSE;
@@ -1549,31 +1588,32 @@ retry:
PR_ASSERT(me->md.thr_bound_cpu == NULL);
if (me->md.blocked_io_status == 0) {
- _PR_MD_MAP_ACCEPTEX_ERROR(me->md.blocked_io_error);
+ _PR_MD_MAP_ACCEPTEX_ERROR(me->md.blocked_io_error);
closesocket(*newSock);
return -1;
}
- if (!fast)
+ if (!fast) {
_PR_MD_UPDATE_ACCEPT_CONTEXT((SOCKET)*newSock, (SOCKET)sock);
+ }
/* IO is done */
GetAcceptExSockaddrs(
- buf,
- amount,
- INET_ADDR_PADDED,
- INET_ADDR_PADDED,
- (LPSOCKADDR *)&(Laddr),
- &llen,
- (LPSOCKADDR *)(raddr),
- (unsigned int *)&rlen);
+ buf,
+ amount,
+ INET_ADDR_PADDED,
+ INET_ADDR_PADDED,
+ (LPSOCKADDR *)&(Laddr),
+ &llen,
+ (LPSOCKADDR *)(raddr),
+ (unsigned int *)&rlen);
return me->md.blocked_io_bytes;
}
PRInt32
_PR_MD_SENDFILE(PRFileDesc *sock, PRSendFileData *sfd,
- PRInt32 flags, PRIntervalTime timeout)
+ PRInt32 flags, PRIntervalTime timeout)
{
PRThread *me = _PR_MD_CURRENT_THREAD();
PRInt32 tflags;
@@ -1603,20 +1643,22 @@ _PR_MD_SENDFILE(PRFileDesc *sock, PRSendFileData *sfd,
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
me->md.overlapped.overlapped.Offset = sfd->file_offset;
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
tflags = 0;
- if (flags & PR_TRANSMITFILE_CLOSE_SOCKET)
+ if (flags & PR_TRANSMITFILE_CLOSE_SOCKET) {
tflags = TF_DISCONNECT | TF_REUSE_SOCKET;
+ }
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
@@ -1630,18 +1672,18 @@ _PR_MD_SENDFILE(PRFileDesc *sock, PRSendFileData *sfd,
(TRANSMIT_FILE_BUFFERS *)me->md.xmit_bufs,
(DWORD)tflags);
if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING) ) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
-
- _PR_MD_MAP_TRANSMITFILE_ERROR(err);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ _PR_MD_MAP_TRANSMITFILE_ERROR(err);
return -1;
}
@@ -1663,7 +1705,7 @@ _PR_MD_SENDFILE(PRFileDesc *sock, PRSendFileData *sfd,
}
if (me->md.blocked_io_status == 0) {
- _PR_MD_MAP_TRANSMITFILE_ERROR(me->md.blocked_io_error);
+ _PR_MD_MAP_TRANSMITFILE_ERROR(me->md.blocked_io_error);
return -1;
}
@@ -1677,7 +1719,7 @@ _PR_MD_SENDFILE(PRFileDesc *sock, PRSendFileData *sfd,
}
PRInt32
-_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
+_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PRIntervalTime timeout)
{
PROsfd osfd = fd->secret->md.osfd;
@@ -1706,41 +1748,43 @@ _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
}
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
me->io_fd = osfd;
rv = ReadFile((HANDLE)osfd,
- buf,
+ buf,
amount,
&bytes,
&(me->md.overlapped.overlapped));
if ( (rv == 0) && (GetLastError() != ERROR_IO_PENDING) ) {
- _PR_THREAD_LOCK(me);
+ _PR_THREAD_LOCK(me);
me->io_pending = PR_FALSE;
me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
-
- if ((err = GetLastError()) == ERROR_HANDLE_EOF)
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ if ((err = GetLastError()) == ERROR_HANDLE_EOF) {
return 0;
- _PR_MD_MAP_READ_ERROR(err);
+ }
+ _PR_MD_MAP_READ_ERROR(err);
return -1;
}
@@ -1764,9 +1808,10 @@ _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
}
if (me->md.blocked_io_status == 0) {
- if (me->md.blocked_io_error == ERROR_HANDLE_EOF)
+ if (me->md.blocked_io_error == ERROR_HANDLE_EOF) {
return 0;
- _PR_MD_MAP_READ_ERROR(me->md.blocked_io_error);
+ }
+ _PR_MD_MAP_READ_ERROR(me->md.blocked_io_error);
return -1;
}
@@ -1805,39 +1850,40 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
}
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
me->io_fd = osfd;
rv = WriteFile((HANDLE)osfd,
- buf,
+ buf,
amount,
&bytes,
&(me->md.overlapped.overlapped));
if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING) ) {
- _PR_THREAD_LOCK(me);
+ _PR_THREAD_LOCK(me);
me->io_pending = PR_FALSE;
me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
-
- _PR_MD_MAP_WRITE_ERROR(err);
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ _PR_MD_MAP_WRITE_ERROR(err);
return -1;
}
@@ -1861,7 +1907,7 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
}
if (me->md.blocked_io_status == 0) {
- _PR_MD_MAP_WRITE_ERROR(me->md.blocked_io_error);
+ _PR_MD_MAP_WRITE_ERROR(me->md.blocked_io_error);
return -1;
}
@@ -1882,10 +1928,12 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
PR_ASSERT(0 != rv);
fd->secret->md.io_model_committed = PR_TRUE;
}
- if (_NT_USE_NB_IO(fd))
+ if (_NT_USE_NB_IO(fd)) {
return _nt_nonblock_sendto(fd, buf, amount, (struct sockaddr *)addr, addrlen, timeout);
- else
+ }
+ else {
return pt_SendTo(osfd, buf, amount, flags, addr, addrlen, timeout);
+ }
}
PRInt32
@@ -1900,10 +1948,12 @@ _PR_MD_RECVFROM(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PR_ASSERT(0 != rv);
fd->secret->md.io_model_committed = PR_TRUE;
}
- if (_NT_USE_NB_IO(fd))
+ if (_NT_USE_NB_IO(fd)) {
return _nt_nonblock_recvfrom(fd, buf, amount, (struct sockaddr *)addr, addrlen, timeout);
- else
+ }
+ else {
return pt_RecvFrom(osfd, buf, amount, flags, addr, addrlen, timeout);
+ }
}
/* XXXMB - for now this is a sockets call only */
@@ -1926,12 +1976,14 @@ _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size, PRIntervalTi
for (index=0; index<iov_size; index++) {
rv = _PR_MD_SEND(fd, iov[index].iov_base, iov[index].iov_len, 0,
- timeout);
- if (rv > 0)
+ timeout);
+ if (rv > 0) {
sent += rv;
+ }
if ( rv != iov[index].iov_len ) {
- if (sent <= 0)
+ if (sent <= 0) {
return -1;
+ }
return -1;
}
}
@@ -1945,9 +1997,10 @@ _PR_MD_LISTEN(PRFileDesc *fd, PRIntn backlog)
PRInt32 rv;
rv = listen(fd->secret->md.osfd, backlog);
- if (rv < 0)
- _PR_MD_MAP_LISTEN_ERROR(WSAGetLastError());
- return(rv);
+ if (rv < 0) {
+ _PR_MD_MAP_LISTEN_ERROR(WSAGetLastError());
+ }
+ return(rv);
}
PRInt32
@@ -1956,9 +2009,10 @@ _PR_MD_SHUTDOWN(PRFileDesc *fd, PRIntn how)
PRInt32 rv;
rv = shutdown(fd->secret->md.osfd, how);
- if (rv < 0)
- _PR_MD_MAP_SHUTDOWN_ERROR(WSAGetLastError());
- return(rv);
+ if (rv < 0) {
+ _PR_MD_MAP_SHUTDOWN_ERROR(WSAGetLastError());
+ }
+ return(rv);
}
PRStatus
@@ -1967,12 +2021,13 @@ _PR_MD_GETSOCKNAME(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *len)
PRInt32 rv;
rv = getsockname((SOCKET)fd->secret->md.osfd, (struct sockaddr *)addr, len);
- if (rv==0)
- return PR_SUCCESS;
- else {
- _PR_MD_MAP_GETSOCKNAME_ERROR(WSAGetLastError());
- return PR_FAILURE;
- }
+ if (rv==0) {
+ return PR_SUCCESS;
+ }
+ else {
+ _PR_MD_MAP_GETSOCKNAME_ERROR(WSAGetLastError());
+ return PR_FAILURE;
+ }
}
PRStatus
@@ -1996,7 +2051,7 @@ _PR_MD_GETPEERNAME(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *len)
* Determine if the socket is connected.
*/
- rv = getsockopt(fd->secret->md.osfd,
+ rv = getsockopt(fd->secret->md.osfd,
SOL_SOCKET,
SO_CONNECT_TIME,
(char *) &seconds,
@@ -2013,7 +2068,7 @@ _PR_MD_GETPEERNAME(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *len)
_PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
return PR_FAILURE;
}
- } else {
+ } else {
rv = getpeername((SOCKET)fd->secret->md.osfd,
(struct sockaddr *) addr, len);
if (rv == 0) {
@@ -2031,12 +2086,13 @@ _PR_MD_GETSOCKOPT(PRFileDesc *fd, PRInt32 level, PRInt32 optname, char* optval,
PRInt32 rv;
rv = getsockopt((SOCKET)fd->secret->md.osfd, level, optname, optval, optlen);
- if (rv==0)
- return PR_SUCCESS;
- else {
- _PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
- return PR_FAILURE;
- }
+ if (rv==0) {
+ return PR_SUCCESS;
+ }
+ else {
+ _PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
+ return PR_FAILURE;
+ }
}
PRStatus
@@ -2045,12 +2101,13 @@ _PR_MD_SETSOCKOPT(PRFileDesc *fd, PRInt32 level, PRInt32 optname, const char* op
PRInt32 rv;
rv = setsockopt((SOCKET)fd->secret->md.osfd, level, optname, optval, optlen);
- if (rv==0)
- return PR_SUCCESS;
- else {
- _PR_MD_MAP_SETSOCKOPT_ERROR(WSAGetLastError());
- return PR_FAILURE;
- }
+ if (rv==0) {
+ return PR_SUCCESS;
+ }
+ else {
+ _PR_MD_MAP_SETSOCKOPT_ERROR(WSAGetLastError());
+ return PR_FAILURE;
+ }
}
/* --- FILE IO ----------------------------------------------------------- */
@@ -2062,27 +2119,39 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, PRIntn mode)
PRInt32 access = 0;
PRInt32 flags = 0;
PRInt32 flag6 = 0;
-
- if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
-
- if (osflags & PR_RDONLY || osflags & PR_RDWR) access |= GENERIC_READ;
- if (osflags & PR_WRONLY || osflags & PR_RDWR) access |= GENERIC_WRITE;
- if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
+ if (osflags & PR_SYNC) {
+ flag6 = FILE_FLAG_WRITE_THROUGH;
+ }
+
+ if (osflags & PR_RDONLY || osflags & PR_RDWR) {
+ access |= GENERIC_READ;
+ }
+ if (osflags & PR_WRONLY || osflags & PR_RDWR) {
+ access |= GENERIC_WRITE;
+ }
+
+ if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL ) {
flags = CREATE_NEW;
- else if (osflags & PR_CREATE_FILE)
+ }
+ else if (osflags & PR_CREATE_FILE) {
flags = (0 != (osflags & PR_TRUNCATE)) ? CREATE_ALWAYS : OPEN_ALWAYS;
- else if (osflags & PR_TRUNCATE) flags = TRUNCATE_EXISTING;
- else flags = OPEN_EXISTING;
+ }
+ else if (osflags & PR_TRUNCATE) {
+ flags = TRUNCATE_EXISTING;
+ }
+ else {
+ flags = OPEN_EXISTING;
+ }
flag6 |= FILE_FLAG_OVERLAPPED;
- file = CreateFile(name,
- access,
+ file = CreateFile(name,
+ access,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
- flags,
+ flags,
flag6,
NULL);
if (file == INVALID_HANDLE_VALUE) {
@@ -2113,35 +2182,47 @@ _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, PRIntn mode)
PSECURITY_DESCRIPTOR pSD = NULL;
PACL pACL = NULL;
- if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
-
- if (osflags & PR_RDONLY || osflags & PR_RDWR) access |= GENERIC_READ;
- if (osflags & PR_WRONLY || osflags & PR_RDWR) access |= GENERIC_WRITE;
+ if (osflags & PR_SYNC) {
+ flag6 = FILE_FLAG_WRITE_THROUGH;
+ }
+
+ if (osflags & PR_RDONLY || osflags & PR_RDWR) {
+ access |= GENERIC_READ;
+ }
+ if (osflags & PR_WRONLY || osflags & PR_RDWR) {
+ access |= GENERIC_WRITE;
+ }
- if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
+ if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL ) {
flags = CREATE_NEW;
- else if (osflags & PR_CREATE_FILE)
+ }
+ else if (osflags & PR_CREATE_FILE) {
flags = (0 != (osflags & PR_TRUNCATE)) ? CREATE_ALWAYS : OPEN_ALWAYS;
- else if (osflags & PR_TRUNCATE) flags = TRUNCATE_EXISTING;
- else flags = OPEN_EXISTING;
+ }
+ else if (osflags & PR_TRUNCATE) {
+ flags = TRUNCATE_EXISTING;
+ }
+ else {
+ flags = OPEN_EXISTING;
+ }
flag6 |= FILE_FLAG_OVERLAPPED;
if (osflags & PR_CREATE_FILE) {
if (_PR_NT_MakeSecurityDescriptorACL(mode, fileAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
lpSA = &sa;
}
}
- file = CreateFile(name,
- access,
+ file = CreateFile(name,
+ access,
FILE_SHARE_READ|FILE_SHARE_WRITE,
lpSA,
- flags,
+ flags,
flag6,
NULL);
if (lpSA != NULL) {
@@ -2163,7 +2244,7 @@ _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, PRIntn mode)
return (PROsfd)file;
}
-PRInt32
+PRInt32
_PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
{
PROsfd f = fd->secret->md.osfd;
@@ -2186,10 +2267,10 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
PR_ASSERT((me->md.overlapped.overlapped.Offset != 0xffffffff) || (GetLastError() == NO_ERROR));
if (fd->secret->inheritable == _PR_TRI_TRUE) {
- rv = ReadFile((HANDLE)f,
- (LPVOID)buf,
- len,
- &bytes,
+ rv = ReadFile((HANDLE)f,
+ (LPVOID)buf,
+ len,
+ &bytes,
&me->md.overlapped.overlapped);
if (rv != 0) {
loOffset = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);
@@ -2199,7 +2280,7 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
err = GetLastError();
if (err == ERROR_IO_PENDING) {
rv = GetOverlappedResult((HANDLE)f,
- &me->md.overlapped.overlapped, &bytes, TRUE);
+ &me->md.overlapped.overlapped, &bytes, TRUE);
if (rv != 0) {
loOffset = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);
PR_ASSERT((loOffset != 0xffffffff) || (GetLastError() == NO_ERROR));
@@ -2220,37 +2301,38 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
fd->secret->md.io_model_committed = PR_TRUE;
}
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
-
- _PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- me->io_pending = PR_TRUE;
- me->state = _PR_IO_WAIT;
- _PR_THREAD_UNLOCK(me);
- me->io_fd = f;
-
- rv = ReadFile((HANDLE)f,
- (LPVOID)buf,
- len,
- &bytes,
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
+
+ _PR_THREAD_LOCK(me);
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ me->io_pending = PR_TRUE;
+ me->state = _PR_IO_WAIT;
+ _PR_THREAD_UNLOCK(me);
+ me->io_fd = f;
+
+ rv = ReadFile((HANDLE)f,
+ (LPVOID)buf,
+ len,
+ &bytes,
&me->md.overlapped.overlapped);
if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING) ) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
if (err == ERROR_HANDLE_EOF) {
return 0;
@@ -2287,7 +2369,7 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
}
SetFilePointer((HANDLE)f, me->md.blocked_io_bytes, 0, FILE_CURRENT);
-
+
PR_ASSERT(me->io_pending == PR_FALSE);
return me->md.blocked_io_bytes;
@@ -2304,7 +2386,7 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
/* ERROR_HANDLE_EOF can only be returned by async io */
PR_ASSERT(err != ERROR_HANDLE_EOF);
if (err == ERROR_BROKEN_PIPE) {
- /* The write end of the pipe has been closed. */
+ /* The write end of the pipe has been closed. */
return 0;
}
_PR_MD_MAP_READ_ERROR(err);
@@ -2338,11 +2420,11 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
PR_ASSERT((me->md.overlapped.overlapped.Offset != 0xffffffff) || (GetLastError() == NO_ERROR));
if (fd->secret->inheritable == _PR_TRI_TRUE) {
- rv = WriteFile((HANDLE)f,
- (LPVOID)buf,
- len,
- &bytes,
- &me->md.overlapped.overlapped);
+ rv = WriteFile((HANDLE)f,
+ (LPVOID)buf,
+ len,
+ &bytes,
+ &me->md.overlapped.overlapped);
if (rv != 0) {
loOffset = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);
PR_ASSERT((loOffset != 0xffffffff) || (GetLastError() == NO_ERROR));
@@ -2351,7 +2433,7 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
err = GetLastError();
if (err == ERROR_IO_PENDING) {
rv = GetOverlappedResult((HANDLE)f,
- &me->md.overlapped.overlapped, &bytes, TRUE);
+ &me->md.overlapped.overlapped, &bytes, TRUE);
if (rv != 0) {
loOffset = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);
PR_ASSERT((loOffset != 0xffffffff) || (GetLastError() == NO_ERROR));
@@ -2367,37 +2449,38 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
PR_ASSERT(rv != 0);
fd->secret->md.io_model_committed = PR_TRUE;
}
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
-
- _PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- me->io_pending = PR_TRUE;
- me->state = _PR_IO_WAIT;
- _PR_THREAD_UNLOCK(me);
- me->io_fd = f;
-
- rv = WriteFile((HANDLE)f,
- buf,
- len,
- &bytes,
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
+
+ _PR_THREAD_LOCK(me);
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ me->io_pending = PR_TRUE;
+ me->state = _PR_IO_WAIT;
+ _PR_THREAD_UNLOCK(me);
+ me->io_fd = f;
+
+ rv = WriteFile((HANDLE)f,
+ buf,
+ len,
+ &bytes,
&(me->md.overlapped.overlapped));
if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING) ) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
_PR_MD_MAP_WRITE_ERROR(err);
return -1;
@@ -2439,7 +2522,7 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
offset.QuadPart += me->md.blocked_io_bytes;
SetFilePointer((HANDLE)f, offset.LowPart, &offset.HighPart, FILE_BEGIN);
-
+
PR_ASSERT(me->io_pending == PR_FALSE);
return me->md.blocked_io_bytes;
@@ -2464,7 +2547,7 @@ _PR_MD_SOCKETAVAILABLE(PRFileDesc *fd)
PRInt32 result;
if (ioctlsocket(fd->secret->md.osfd, FIONREAD, &result) < 0) {
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, WSAGetLastError());
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, WSAGetLastError());
return -1;
}
return result;
@@ -2473,10 +2556,12 @@ _PR_MD_SOCKETAVAILABLE(PRFileDesc *fd)
PRInt32
_PR_MD_PIPEAVAILABLE(PRFileDesc *fd)
{
- if (NULL == fd)
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
- else
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ if (NULL == fd) {
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
+ }
+ else {
+ PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ }
return -1;
}
@@ -2537,7 +2622,7 @@ _PR_MD_LSEEK64(PRFileDesc *fd, PROffset64 offset, PRSeekWhence whence)
li.QuadPart = offset;
li.LowPart = SetFilePointer((HANDLE)fd->secret->md.osfd,
- li.LowPart, &li.HighPart, moveMethod);
+ li.LowPart, &li.HighPart, moveMethod);
if (0xffffffff == li.LowPart && (err = GetLastError()) != NO_ERROR) {
_PR_MD_MAP_LSEEK_ERROR(err);
@@ -2558,10 +2643,10 @@ _PR_MD_FSYNC(PRFileDesc *fd)
/*
* From the documentation:
*
- * On Windows NT, the function FlushFileBuffers fails if hFile
- * is a handle to console output. That is because console
- * output is not buffered. The function returns FALSE, and
- * GetLastError returns ERROR_INVALID_HANDLE.
+ * On Windows NT, the function FlushFileBuffers fails if hFile
+ * is a handle to console output. That is because console
+ * output is not buffered. The function returns FALSE, and
+ * GetLastError returns ERROR_INVALID_HANDLE.
*
* On the other hand, on Win95, it returns without error. I cannot
* assume that 0, 1, and 2 are console, because if someone closes
@@ -2575,12 +2660,12 @@ _PR_MD_FSYNC(PRFileDesc *fd)
BOOL ok = FlushFileBuffers((HANDLE)fd->secret->md.osfd);
if (!ok) {
- DWORD err = GetLastError();
+ DWORD err = GetLastError();
- if (err != ERROR_ACCESS_DENIED) { /* from winerror.h */
- _PR_MD_MAP_FSYNC_ERROR(err);
- return -1;
- }
+ if (err != ERROR_ACCESS_DENIED) { /* from winerror.h */
+ _PR_MD_MAP_FSYNC_ERROR(err);
+ return -1;
+ }
}
return 0;
}
@@ -2593,12 +2678,14 @@ _PR_MD_CLOSE(PROsfd osfd, PRBool socket)
if (socket) {
rv = closesocket((SOCKET)osfd);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_CLOSE_ERROR(WSAGetLastError());
+ }
} else {
rv = CloseHandle((HANDLE)osfd)?0:-1;
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_CLOSE_ERROR(GetLastError());
+ }
}
if (rv == 0 && me->io_suspended) {
@@ -2608,7 +2695,7 @@ _PR_MD_CLOSE(PROsfd osfd, PRBool socket)
_PR_THREAD_LOCK(me);
me->state = _PR_IO_WAIT;
/* The IO could have completed on another thread just after
- * calling closesocket while the io_suspended flag was true.
+ * calling closesocket while the io_suspended flag was true.
* So we now grab the lock to do a safe check on io_pending to
* see if we need to wait or not.
*/
@@ -2617,8 +2704,9 @@ _PR_MD_CLOSE(PROsfd osfd, PRBool socket)
me->md.interrupt_disabled = PR_TRUE;
_PR_THREAD_UNLOCK(me);
- if (fWait)
+ if (fWait) {
_NT_IO_WAIT(me, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_ASSERT(me->io_suspended == PR_FALSE);
PR_ASSERT(me->io_pending == PR_FALSE);
/*
@@ -2647,15 +2735,15 @@ _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable)
return PR_FAILURE;
}
rv = SetHandleInformation(
- (HANDLE)fd->secret->md.osfd,
- HANDLE_FLAG_INHERIT,
- inheritable ? HANDLE_FLAG_INHERIT : 0);
+ (HANDLE)fd->secret->md.osfd,
+ HANDLE_FLAG_INHERIT,
+ inheritable ? HANDLE_FLAG_INHERIT : 0);
if (0 == rv) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
return PR_FAILURE;
}
return PR_SUCCESS;
-}
+}
void
_PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported)
@@ -2750,7 +2838,7 @@ _PR_MD_OPEN_DIR(_MDDir *d, const char *name)
d->d_hdl = FindFirstFile( filename, &(d->d_entry) );
if ( d->d_hdl == INVALID_HANDLE_VALUE ) {
- _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
+ _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
return PR_FAILURE;
}
d->firstEntry = PR_TRUE;
@@ -2778,21 +2866,24 @@ _PR_MD_READ_DIR(_MDDir *d, PRIntn flags)
}
fileName = GetFileFromDIR(d);
if ( (flags & PR_SKIP_DOT) &&
- (fileName[0] == '.') && (fileName[1] == '\0'))
- continue;
+ (fileName[0] == '.') && (fileName[1] == '\0')) {
+ continue;
+ }
if ( (flags & PR_SKIP_DOT_DOT) &&
(fileName[0] == '.') && (fileName[1] == '.') &&
- (fileName[2] == '\0'))
- continue;
- if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d))
- continue;
+ (fileName[2] == '\0')) {
+ continue;
+ }
+ if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d)) {
+ continue;
+ }
return fileName;
}
- err = GetLastError();
- PR_ASSERT(NO_ERROR != err);
- _PR_MD_MAP_READDIR_ERROR(err);
- return NULL;
- }
+ err = GetLastError();
+ PR_ASSERT(NO_ERROR != err);
+ _PR_MD_MAP_READDIR_ERROR(err);
+ return NULL;
+ }
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return NULL;
}
@@ -2801,11 +2892,11 @@ PRInt32
_PR_MD_DELETE(const char *name)
{
if (DeleteFile(name)) {
- return 0;
- } else {
- _PR_MD_MAP_DELETE_ERROR(GetLastError());
- return -1;
- }
+ return 0;
+ } else {
+ _PR_MD_MAP_DELETE_ERROR(GetLastError());
+ return -1;
+ }
}
void
@@ -2880,7 +2971,7 @@ _PR_MD_STAT(const char *fn, struct stat *info)
int len = strlen(fn);
if (len > 0 && len <= _MAX_PATH
- && IsPrevCharSlash(fn, fn + len)) {
+ && IsPrevCharSlash(fn, fn + len)) {
char newfn[_MAX_PATH + 1];
strcpy(newfn, fn);
@@ -2902,8 +2993,9 @@ IsPrevCharSlash(const char *str, const char *current)
{
const char *prev;
- if (str >= current)
+ if (str >= current) {
return PR_FALSE;
+ }
prev = _mbsdec(str, current);
return (prev == current - 1) && _PR_IS_SLASH(*prev);
}
@@ -2938,7 +3030,7 @@ IsRootDirectory(char *fn, size_t buflen)
}
if (isalpha(fn[0]) && fn[1] == ':' && _PR_IS_SLASH(fn[2])
- && fn[3] == '\0') {
+ && fn[3] == '\0') {
rv = GetDriveType(fn) > 1 ? PR_TRUE : PR_FALSE;
return rv;
}
@@ -3000,7 +3092,7 @@ PRInt32
_PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
{
WIN32_FILE_ATTRIBUTE_DATA findFileData;
-
+
if (NULL == fn || '\0' == *fn) {
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return -1;
@@ -3023,11 +3115,11 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
_PR_FileTimeToPRTime(&findFileData.ftLastWriteTime, &info->modifyTime);
if (0 == findFileData.ftCreationTime.dwLowDateTime &&
- 0 == findFileData.ftCreationTime.dwHighDateTime) {
+ 0 == findFileData.ftCreationTime.dwHighDateTime) {
info->creationTime = info->modifyTime;
} else {
_PR_FileTimeToPRTime(&findFileData.ftCreationTime,
- &info->creationTime);
+ &info->creationTime);
}
return 0;
@@ -3057,14 +3149,16 @@ _PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info)
rv = GetFileInformationByHandle((HANDLE)fd->secret->md.osfd, &hinfo);
if (rv == FALSE) {
- _PR_MD_MAP_FSTAT_ERROR(GetLastError());
+ _PR_MD_MAP_FSTAT_ERROR(GetLastError());
return -1;
- }
+ }
- if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_FILE;
+ }
info->size = hinfo.nFileSizeHigh;
info->size = (info->size << 32) + hinfo.nFileSizeLow;
@@ -3084,14 +3178,16 @@ _PR_MD_GETOPENFILEINFO(const PRFileDesc *fd, PRFileInfo *info)
rv = GetFileInformationByHandle((HANDLE)fd->secret->md.osfd, &hinfo);
if (rv == FALSE) {
- _PR_MD_MAP_FSTAT_ERROR(GetLastError());
+ _PR_MD_MAP_FSTAT_ERROR(GetLastError());
return -1;
- }
+ }
- if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_FILE;
+ }
info->size = hinfo.nFileSizeLow;
@@ -3106,11 +3202,11 @@ _PR_MD_RENAME(const char *from, const char *to)
{
/* Does this work with dot-relative pathnames? */
if (MoveFile(from, to)) {
- return 0;
- } else {
- _PR_MD_MAP_RENAME_ERROR(GetLastError());
- return -1;
- }
+ return 0;
+ } else {
+ _PR_MD_MAP_RENAME_ERROR(GetLastError());
+ return -1;
+ }
}
PRInt32
@@ -3119,21 +3215,21 @@ _PR_MD_ACCESS(const char *name, PRAccessHow how)
PRInt32 rv;
switch (how) {
- case PR_ACCESS_WRITE_OK:
- rv = _access(name, 02);
- break;
- case PR_ACCESS_READ_OK:
- rv = _access(name, 04);
- break;
- case PR_ACCESS_EXISTS:
- rv = _access(name, 00);
- break;
- default:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return -1;
- }
- if (rv < 0) {
- _PR_MD_MAP_ACCESS_ERROR(errno);
+ case PR_ACCESS_WRITE_OK:
+ rv = _access(name, 02);
+ break;
+ case PR_ACCESS_READ_OK:
+ rv = _access(name, 04);
+ break;
+ case PR_ACCESS_EXISTS:
+ rv = _access(name, 00);
+ break;
+ default:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return -1;
+ }
+ if (rv < 0) {
+ _PR_MD_MAP_ACCESS_ERROR(errno);
}
return rv;
}
@@ -3160,7 +3256,7 @@ _PR_MD_MAKE_DIR(const char *name, PRIntn mode)
PACL pACL = NULL;
if (_PR_NT_MakeSecurityDescriptorACL(mode, dirAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
@@ -3203,17 +3299,17 @@ _PR_MD_LOCKFILE(PROsfd f)
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
- rv = LockFileEx((HANDLE)f,
+ rv = LockFileEx((HANDLE)f,
LOCKFILE_EXCLUSIVE_LOCK,
0,
0x7fffffff,
@@ -3221,16 +3317,16 @@ _PR_MD_LOCKFILE(PROsfd f)
&me->md.overlapped.overlapped);
if (_native_threads_only) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
if (rv == FALSE) {
err = GetLastError();
@@ -3249,7 +3345,7 @@ _PR_MD_LOCKFILE(PROsfd f)
*
* If we pretend we won't get a completion, NSPR gets confused later
* when the unexpected completion arrives. If we assume we do get
- * a completion, we hang on 3.51. Worse, Microsoft informs me that the
+ * a completion, we hang on 3.51. Worse, Microsoft informs me that the
* behavior varies on 3.51 depending on if you are using a network
* file system or a local disk!
*
@@ -3257,51 +3353,51 @@ _PR_MD_LOCKFILE(PROsfd f)
* depending on whether or not this system is EITHER
* - running NT 4.0
* - running NT 3.51 with a service pack greater than 5.
- *
+ *
* In the meantime, this code may not work on network file systems.
*
*/
if ( rv == FALSE && ((err = GetLastError()) != ERROR_IO_PENDING)) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
-
- _PR_MD_MAP_LOCKF_ERROR(err);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ _PR_MD_MAP_LOCKF_ERROR(err);
return PR_FAILURE;
}
#ifdef _NEED_351_FILE_LOCKING_HACK
else if (rv) {
- /* If this is NT 3.51 and the file is local, then we won't get a
+ /* If this is NT 3.51 and the file is local, then we won't get a
* completion back from LockFile when it succeeded.
*/
if (_nt_version_gets_lockfile_completion == PR_FALSE) {
if ( IsFileLocal((HANDLE)f) == _PR_LOCAL_FILE) {
me->io_pending = PR_FALSE;
me->state = _PR_RUNNING;
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
}
}
#endif /* _NEED_351_FILE_LOCKING_HACK */
if (_NT_IO_WAIT(me, PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE) {
- _PR_THREAD_LOCK(me);
+ _PR_THREAD_LOCK(me);
me->io_pending = PR_FALSE;
me->state = _PR_RUNNING;
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_UNLOCK(me);
return PR_FAILURE;
}
if (me->md.blocked_io_status == 0) {
- _PR_MD_MAP_LOCKF_ERROR(me->md.blocked_io_error);
+ _PR_MD_MAP_LOCKF_ERROR(me->md.blocked_io_error);
return PR_FAILURE;
}
@@ -3322,33 +3418,33 @@ _PR_MD_TLOCKFILE(PROsfd f)
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
- rv = LockFileEx((HANDLE)f,
+ rv = LockFileEx((HANDLE)f,
LOCKFILE_FAIL_IMMEDIATELY|LOCKFILE_EXCLUSIVE_LOCK,
0,
0x7fffffff,
0,
&me->md.overlapped.overlapped);
if (_native_threads_only) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
if (rv == FALSE) {
err = GetLastError();
@@ -3359,61 +3455,61 @@ _PR_MD_TLOCKFILE(PROsfd f)
return PR_SUCCESS;
}
if ( rv == FALSE && ((err = GetLastError()) != ERROR_IO_PENDING)) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
_PR_MD_MAP_LOCKF_ERROR(err);
return PR_FAILURE;
}
#ifdef _NEED_351_FILE_LOCKING_HACK
else if (rv) {
- /* If this is NT 3.51 and the file is local, then we won't get a
+ /* If this is NT 3.51 and the file is local, then we won't get a
* completion back from LockFile when it succeeded.
*/
if (_nt_version_gets_lockfile_completion == PR_FALSE) {
if ( IsFileLocal((HANDLE)f) == _PR_LOCAL_FILE) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
-
- return PR_SUCCESS;
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ return PR_SUCCESS;
}
}
}
#endif /* _NEED_351_FILE_LOCKING_HACK */
if (_NT_IO_WAIT(me, PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
return PR_FAILURE;
}
if (me->md.blocked_io_status == 0) {
- _PR_MD_MAP_LOCKF_ERROR(me->md.blocked_io_error);
+ _PR_MD_MAP_LOCKF_ERROR(me->md.blocked_io_error);
return PR_FAILURE;
}
@@ -3440,11 +3536,12 @@ _PR_MD_UNLOCKFILE(PROsfd f)
0,
&me->md.overlapped.overlapped);
- if (rv)
+ if (rv) {
return PR_SUCCESS;
+ }
else {
int err = GetLastError();
- _PR_MD_MAP_LOCKF_ERROR(err);
+ _PR_MD_MAP_LOCKF_ERROR(err);
return PR_FAILURE;
}
}
@@ -3465,17 +3562,17 @@ _PR_MD_MAKE_NONBLOCK(PRFileDesc *f)
#ifdef _NEED_351_FILE_LOCKING_HACK
/***************
-**
+**
** Lockfile hacks
**
** The following code is a hack to work around a microsoft bug with lockfile.
** The problem is that on NT 3.51, if LockFileEx() succeeds, you never
** get a completion back for files that are on local disks. So, we need to
-** know if a file is local or remote so we can tell if we should expect
+** know if a file is local or remote so we can tell if we should expect
** a completion.
**
** The only way to check if a file is local or remote based on the handle is
-** to get the serial number for the volume it is mounted on and then to
+** to get the serial number for the volume it is mounted on and then to
** compare that with mounted drives. This code caches the volume numbers of
** fixed disks and does a relatively quick check.
**
@@ -3499,222 +3596,228 @@ DWORD dwRemoveableDrivesToCheck = 0; /* bitmask for removeable drives */
PRBool IsFileLocalInit()
{
- TCHAR lpBuffer[_PR_MAX_DRIVES*5];
- DWORD nBufferLength = _PR_MAX_DRIVES*5;
- DWORD nBufferNeeded = GetLogicalDriveStrings(0, NULL);
- DWORD dwIndex = 0;
- DWORD dwDriveType;
- DWORD dwVolumeSerialNumber;
- DWORD dwDriveIndex = 0;
- DWORD oldmode = (DWORD) -1;
-
- _MD_NEW_LOCK(&cachedVolumeLock);
-
- nBufferNeeded = GetLogicalDriveStrings(nBufferLength, lpBuffer);
- if (nBufferNeeded == 0 || nBufferNeeded > nBufferLength)
- return PR_FALSE;
-
- // Calling GetVolumeInformation on a removeable drive where the
- // disk is currently removed will cause a dialog box to the
- // console. This is not good.
- // Temporarily disable the SEM_FAILCRITICALERRORS to avoid the
- // damn dialog.
-
- dwCachedVolumeSerialNumbers[dwDriveIndex] = 0;
- oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
-
- // now loop through the logical drives
- while(lpBuffer[dwIndex] != TEXT('\0'))
- {
- // skip the floppy drives. This is *SLOW*
- if ((lpBuffer[dwIndex] == TEXT('A')) || (lpBuffer[dwIndex] == TEXT('B')))
- /* Skip over floppies */;
- else
- {
- dwDriveIndex = (lpBuffer[dwIndex] - TEXT('A'));
-
- dwDriveType = GetDriveType(&lpBuffer[dwIndex]);
-
- switch(dwDriveType)
- {
- // Ignore these drive types
- case 0:
- case 1:
- case DRIVE_REMOTE:
- default: // If the drive type is unknown, ignore it.
- break;
-
- // Removable media drives can have different serial numbers
- // at different times, so cache the current serial number
- // but keep track of them so they can be rechecked if necessary.
- case DRIVE_REMOVABLE:
-
- // CDROM is a removable media
- case DRIVE_CDROM:
-
- // no idea if ramdisks can change serial numbers or not
- // but it doesn't hurt to treat them as removable.
-
- case DRIVE_RAMDISK:
-
-
- // Here is where we keep track of removable drives.
- dwRemoveableDrivesToCheck |= 1 << dwDriveIndex;
-
- // removable drives fall through to fixed drives and get cached.
-
- case DRIVE_FIXED:
-
- // cache volume serial numbers.
- if (GetVolumeInformation(
- &lpBuffer[dwIndex],
- NULL, 0,
- &dwVolumeSerialNumber,
- NULL, NULL, NULL, 0)
- )
- {
- if (dwLastCachedDrive < dwDriveIndex)
- dwLastCachedDrive = dwDriveIndex;
- dwCachedVolumeSerialNumbers[dwDriveIndex] = dwVolumeSerialNumber;
- }
-
- break;
- }
- }
-
- dwIndex += lstrlen(&lpBuffer[dwIndex]) +1;
- }
-
- if (oldmode != (DWORD) -1) {
- SetErrorMode(oldmode);
- oldmode = (DWORD) -1;
- }
-
- return PR_TRUE;
+ TCHAR lpBuffer[_PR_MAX_DRIVES*5];
+ DWORD nBufferLength = _PR_MAX_DRIVES*5;
+ DWORD nBufferNeeded = GetLogicalDriveStrings(0, NULL);
+ DWORD dwIndex = 0;
+ DWORD dwDriveType;
+ DWORD dwVolumeSerialNumber;
+ DWORD dwDriveIndex = 0;
+ DWORD oldmode = (DWORD) -1;
+
+ _MD_NEW_LOCK(&cachedVolumeLock);
+
+ nBufferNeeded = GetLogicalDriveStrings(nBufferLength, lpBuffer);
+ if (nBufferNeeded == 0 || nBufferNeeded > nBufferLength) {
+ return PR_FALSE;
+ }
+
+ // Calling GetVolumeInformation on a removeable drive where the
+ // disk is currently removed will cause a dialog box to the
+ // console. This is not good.
+ // Temporarily disable the SEM_FAILCRITICALERRORS to avoid the
+ // damn dialog.
+
+ dwCachedVolumeSerialNumbers[dwDriveIndex] = 0;
+ oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
+
+ // now loop through the logical drives
+ while(lpBuffer[dwIndex] != TEXT('\0'))
+ {
+ // skip the floppy drives. This is *SLOW*
+ if ((lpBuffer[dwIndex] == TEXT('A')) || (lpBuffer[dwIndex] == TEXT('B')))
+ /* Skip over floppies */;
+ else
+ {
+ dwDriveIndex = (lpBuffer[dwIndex] - TEXT('A'));
+
+ dwDriveType = GetDriveType(&lpBuffer[dwIndex]);
+
+ switch(dwDriveType)
+ {
+ // Ignore these drive types
+ case 0:
+ case 1:
+ case DRIVE_REMOTE:
+ default: // If the drive type is unknown, ignore it.
+ break;
+
+ // Removable media drives can have different serial numbers
+ // at different times, so cache the current serial number
+ // but keep track of them so they can be rechecked if necessary.
+ case DRIVE_REMOVABLE:
+
+ // CDROM is a removable media
+ case DRIVE_CDROM:
+
+ // no idea if ramdisks can change serial numbers or not
+ // but it doesn't hurt to treat them as removable.
+
+ case DRIVE_RAMDISK:
+
+
+ // Here is where we keep track of removable drives.
+ dwRemoveableDrivesToCheck |= 1 << dwDriveIndex;
+
+ // removable drives fall through to fixed drives and get cached.
+
+ case DRIVE_FIXED:
+
+ // cache volume serial numbers.
+ if (GetVolumeInformation(
+ &lpBuffer[dwIndex],
+ NULL, 0,
+ &dwVolumeSerialNumber,
+ NULL, NULL, NULL, 0)
+ )
+ {
+ if (dwLastCachedDrive < dwDriveIndex) {
+ dwLastCachedDrive = dwDriveIndex;
+ }
+ dwCachedVolumeSerialNumbers[dwDriveIndex] = dwVolumeSerialNumber;
+ }
+
+ break;
+ }
+ }
+
+ dwIndex += lstrlen(&lpBuffer[dwIndex]) +1;
+ }
+
+ if (oldmode != (DWORD) -1) {
+ SetErrorMode(oldmode);
+ oldmode = (DWORD) -1;
+ }
+
+ return PR_TRUE;
}
PRInt32 IsFileLocal(HANDLE hFile)
{
- DWORD dwIndex = 0, dwMask;
- BY_HANDLE_FILE_INFORMATION Info;
- TCHAR szDrive[4] = TEXT("C:\\");
- DWORD dwVolumeSerialNumber;
- DWORD oldmode = (DWORD) -1;
- int rv = _PR_REMOTE_FILE;
-
- if (!GetFileInformationByHandle(hFile, &Info))
- return -1;
-
- // look to see if the volume serial number has been cached.
- _MD_LOCK(&cachedVolumeLock);
- while(dwIndex <= dwLastCachedDrive)
- if (dwCachedVolumeSerialNumbers[dwIndex++] == Info.dwVolumeSerialNumber)
- {
- _MD_UNLOCK(&cachedVolumeLock);
- return _PR_LOCAL_FILE;
- }
- _MD_UNLOCK(&cachedVolumeLock);
-
- // volume serial number not found in the cache. Check removable files.
- // removable drives are noted as a bitmask. If the bit associated with
- // a specific drive is set, then we should query its volume serial number
- // as its possible it has changed.
- dwMask = dwRemoveableDrivesToCheck;
- dwIndex = 0;
-
- while(dwMask)
- {
- while(!(dwMask & 1))
- {
- dwIndex++;
- dwMask = dwMask >> 1;
- }
-
- szDrive[0] = TEXT('A')+ (TCHAR) dwIndex;
-
- // Calling GetVolumeInformation on a removeable drive where the
- // disk is currently removed will cause a dialog box to the
- // console. This is not good.
- // Temporarily disable the SEM_FAILCRITICALERRORS to avoid the
- // dialog.
-
- oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
-
- if (GetVolumeInformation(
- szDrive,
- NULL, 0,
- &dwVolumeSerialNumber,
- NULL, NULL, NULL, 0)
- )
- {
- if (dwVolumeSerialNumber == Info.dwVolumeSerialNumber)
- {
- _MD_LOCK(&cachedVolumeLock);
- if (dwLastCachedDrive < dwIndex)
- dwLastCachedDrive = dwIndex;
- dwCachedVolumeSerialNumbers[dwIndex] = dwVolumeSerialNumber;
+ DWORD dwIndex = 0, dwMask;
+ BY_HANDLE_FILE_INFORMATION Info;
+ TCHAR szDrive[4] = TEXT("C:\\");
+ DWORD dwVolumeSerialNumber;
+ DWORD oldmode = (DWORD) -1;
+ int rv = _PR_REMOTE_FILE;
+
+ if (!GetFileInformationByHandle(hFile, &Info)) {
+ return -1;
+ }
+
+ // look to see if the volume serial number has been cached.
+ _MD_LOCK(&cachedVolumeLock);
+ while(dwIndex <= dwLastCachedDrive)
+ if (dwCachedVolumeSerialNumbers[dwIndex++] == Info.dwVolumeSerialNumber)
+ {
_MD_UNLOCK(&cachedVolumeLock);
- rv = _PR_LOCAL_FILE;
- }
- }
- if (oldmode != (DWORD) -1) {
- SetErrorMode(oldmode);
- oldmode = (DWORD) -1;
- }
-
- if (rv == _PR_LOCAL_FILE)
- return _PR_LOCAL_FILE;
-
- dwIndex++;
- dwMask = dwMask >> 1;
- }
-
- return _PR_REMOTE_FILE;
+ return _PR_LOCAL_FILE;
+ }
+ _MD_UNLOCK(&cachedVolumeLock);
+
+ // volume serial number not found in the cache. Check removable files.
+ // removable drives are noted as a bitmask. If the bit associated with
+ // a specific drive is set, then we should query its volume serial number
+ // as its possible it has changed.
+ dwMask = dwRemoveableDrivesToCheck;
+ dwIndex = 0;
+
+ while(dwMask)
+ {
+ while(!(dwMask & 1))
+ {
+ dwIndex++;
+ dwMask = dwMask >> 1;
+ }
+
+ szDrive[0] = TEXT('A')+ (TCHAR) dwIndex;
+
+ // Calling GetVolumeInformation on a removeable drive where the
+ // disk is currently removed will cause a dialog box to the
+ // console. This is not good.
+ // Temporarily disable the SEM_FAILCRITICALERRORS to avoid the
+ // dialog.
+
+ oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
+
+ if (GetVolumeInformation(
+ szDrive,
+ NULL, 0,
+ &dwVolumeSerialNumber,
+ NULL, NULL, NULL, 0)
+ )
+ {
+ if (dwVolumeSerialNumber == Info.dwVolumeSerialNumber)
+ {
+ _MD_LOCK(&cachedVolumeLock);
+ if (dwLastCachedDrive < dwIndex) {
+ dwLastCachedDrive = dwIndex;
+ }
+ dwCachedVolumeSerialNumbers[dwIndex] = dwVolumeSerialNumber;
+ _MD_UNLOCK(&cachedVolumeLock);
+ rv = _PR_LOCAL_FILE;
+ }
+ }
+ if (oldmode != (DWORD) -1) {
+ SetErrorMode(oldmode);
+ oldmode = (DWORD) -1;
+ }
+
+ if (rv == _PR_LOCAL_FILE) {
+ return _PR_LOCAL_FILE;
+ }
+
+ dwIndex++;
+ dwMask = dwMask >> 1;
+ }
+
+ return _PR_REMOTE_FILE;
}
#endif /* _NEED_351_FILE_LOCKING_HACK */
PR_IMPLEMENT(PRStatus) PR_NT_CancelIo(PRFileDesc *fd)
{
PRThread *me = _PR_MD_CURRENT_THREAD();
- PRBool fWait;
- PRFileDesc *bottom;
+ PRBool fWait;
+ PRFileDesc *bottom;
- bottom = PR_GetIdentitiesLayer(fd, PR_NSPR_IO_LAYER);
+ bottom = PR_GetIdentitiesLayer(fd, PR_NSPR_IO_LAYER);
if (!me->io_suspended || (NULL == bottom) ||
- (me->io_fd != bottom->secret->md.osfd)) {
+ (me->io_fd != bottom->secret->md.osfd)) {
PR_SetError(PR_INVALID_STATE_ERROR, 0);
return PR_FAILURE;
}
- /*
- * The CancelIO operation has to be issued by the same NT thread that
- * issued the I/O operation
- */
- PR_ASSERT(_PR_IS_NATIVE_THREAD(me) || (me->cpu == me->md.thr_bound_cpu));
- if (me->io_pending) {
- if (!CancelIo((HANDLE)bottom->secret->md.osfd)) {
- PR_SetError(PR_INVALID_STATE_ERROR, GetLastError());
- return PR_FAILURE;
- }
- }
- _PR_THREAD_LOCK(me);
- fWait = me->io_pending;
- me->io_suspended = PR_FALSE;
- me->state = _PR_IO_WAIT;
- me->md.interrupt_disabled = PR_TRUE;
- _PR_THREAD_UNLOCK(me);
- if (fWait)
- _NT_IO_WAIT(me, PR_INTERVAL_NO_TIMEOUT);
- PR_ASSERT(me->io_suspended == PR_FALSE);
- PR_ASSERT(me->io_pending == PR_FALSE);
-
- _PR_THREAD_LOCK(me);
- me->md.interrupt_disabled = PR_FALSE;
- me->md.thr_bound_cpu = NULL;
+ /*
+ * The CancelIO operation has to be issued by the same NT thread that
+ * issued the I/O operation
+ */
+ PR_ASSERT(_PR_IS_NATIVE_THREAD(me) || (me->cpu == me->md.thr_bound_cpu));
+ if (me->io_pending) {
+ if (!CancelIo((HANDLE)bottom->secret->md.osfd)) {
+ PR_SetError(PR_INVALID_STATE_ERROR, GetLastError());
+ return PR_FAILURE;
+ }
+ }
+ _PR_THREAD_LOCK(me);
+ fWait = me->io_pending;
+ me->io_suspended = PR_FALSE;
+ me->state = _PR_IO_WAIT;
+ me->md.interrupt_disabled = PR_TRUE;
+ _PR_THREAD_UNLOCK(me);
+ if (fWait) {
+ _NT_IO_WAIT(me, PR_INTERVAL_NO_TIMEOUT);
+ }
+ PR_ASSERT(me->io_suspended == PR_FALSE);
+ PR_ASSERT(me->io_pending == PR_FALSE);
+
+ _PR_THREAD_LOCK(me);
+ me->md.interrupt_disabled = PR_FALSE;
+ me->md.thr_bound_cpu = NULL;
me->io_suspended = PR_FALSE;
me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- _PR_THREAD_UNLOCK(me);
- return PR_SUCCESS;
+ me->state = _PR_RUNNING;
+ _PR_THREAD_UNLOCK(me);
+ return PR_SUCCESS;
}
static PROsfd _nt_nonblock_accept(PRFileDesc *fd, struct sockaddr *addr, int *addrlen, PRIntervalTime timeout)
@@ -3730,9 +3833,9 @@ static PROsfd _nt_nonblock_accept(PRFileDesc *fd, struct sockaddr *addr, int *ad
if (timeout == PR_INTERVAL_NO_TIMEOUT) {
while ((sock = accept(osfd, addr, addrlen)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
if ((rv = _PR_NTFiberSafeSelect(0, &rd, NULL, NULL,
- NULL)) == -1) {
+ NULL)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
break;
}
@@ -3744,7 +3847,7 @@ static PROsfd _nt_nonblock_accept(PRFileDesc *fd, struct sockaddr *addr, int *ad
} else if (timeout == PR_INTERVAL_NO_WAIT) {
if ((sock = accept(osfd, addr, addrlen)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
} else {
_PR_MD_MAP_ACCEPT_ERROR(err);
@@ -3754,10 +3857,10 @@ static PROsfd _nt_nonblock_accept(PRFileDesc *fd, struct sockaddr *addr, int *ad
retry:
if ((sock = accept(osfd, addr, addrlen)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
rv = _PR_NTFiberSafeSelect(0, &rd, NULL, NULL, tvp);
@@ -3792,7 +3895,7 @@ static PRInt32 _nt_nonblock_connect(PRFileDesc *fd, struct sockaddr *addr, int a
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&wr);
@@ -3800,7 +3903,7 @@ static PRInt32 _nt_nonblock_connect(PRFileDesc *fd, struct sockaddr *addr, int a
FD_SET((SOCKET)osfd, &wr);
FD_SET((SOCKET)osfd, &ex);
if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wr, &ex,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
return rv;
}
@@ -3813,13 +3916,13 @@ static PRInt32 _nt_nonblock_connect(PRFileDesc *fd, struct sockaddr *addr, int a
if (FD_ISSET((SOCKET)osfd, &ex)) {
len = sizeof(err);
if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,
- (char *) &err, &len) == SOCKET_ERROR) {
+ (char *) &err, &len) == SOCKET_ERROR) {
_PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
return -1;
}
_PR_MD_MAP_CONNECT_ERROR(err);
return -1;
- }
+ }
PR_ASSERT(FD_ISSET((SOCKET)osfd, &wr));
rv = 0;
} else {
@@ -3845,7 +3948,7 @@ static PRInt32 _nt_nonblock_recv(PRFileDesc *fd, char *buf, int len, int flags,
}
while ((rv = recv(osfd,buf,len,osflags)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
FD_ZERO(&rd);
FD_SET((SOCKET)osfd, &rd);
if (timeout == PR_INTERVAL_NO_TIMEOUT) {
@@ -3853,11 +3956,11 @@ static PRInt32 _nt_nonblock_recv(PRFileDesc *fd, char *buf, int len, int flags,
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
if ((rv = _PR_NTFiberSafeSelect(0, &rd, NULL, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
break;
} else if (rv == 0) {
@@ -3884,19 +3987,19 @@ static PRInt32 _nt_nonblock_send(PRFileDesc *fd, char *buf, int len, PRIntervalT
while(bytesSent < len) {
while ((rv = send(osfd,buf,len,0)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
if ( timeout == PR_INTERVAL_NO_TIMEOUT ) {
tvp = NULL;
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&wd);
FD_SET((SOCKET)osfd, &wd);
if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wd, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
return -1;
}
@@ -3919,13 +4022,13 @@ static PRInt32 _nt_nonblock_send(PRFileDesc *fd, char *buf, int len, PRIntervalT
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&wd);
FD_SET((SOCKET)osfd, &wd);
if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wd, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
return -1;
}
@@ -3946,13 +4049,14 @@ static PRInt32 _nt_nonblock_writev(PRFileDesc *fd, const PRIOVec *iov, int size,
for (index=0; index<size; index++) {
rv = _nt_nonblock_send(fd, iov[index].iov_base, iov[index].iov_len, timeout);
- if (rv > 0)
+ if (rv > 0) {
sent += rv;
+ }
if ( rv != iov[index].iov_len ) {
if (rv < 0) {
if (fd->secret->nonblocking
- && (PR_GetError() == PR_WOULD_BLOCK_ERROR)
- && (sent > 0)) {
+ && (PR_GetError() == PR_WOULD_BLOCK_ERROR)
+ && (sent > 0)) {
return sent;
} else {
return -1;
@@ -3980,19 +4084,19 @@ static PRInt32 _nt_nonblock_sendto(
while(bytesSent < len) {
while ((rv = sendto(osfd,buf,len,0, addr, addrlen)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
if ( timeout == PR_INTERVAL_NO_TIMEOUT ) {
tvp = NULL;
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&wd);
FD_SET((SOCKET)osfd, &wd);
if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wd, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
return -1;
}
@@ -4015,13 +4119,13 @@ static PRInt32 _nt_nonblock_sendto(
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&wd);
FD_SET((SOCKET)osfd, &wd);
if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wd, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
return -1;
}
@@ -4043,19 +4147,19 @@ static PRInt32 _nt_nonblock_recvfrom(PRFileDesc *fd, char *buf, int len, struct
while ((rv = recvfrom(osfd,buf,len,0,addr, addrlen)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
if (timeout == PR_INTERVAL_NO_TIMEOUT) {
tvp = NULL;
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&rd);
FD_SET((SOCKET)osfd, &rd);
if ((rv = _PR_NTFiberSafeSelect(0, &rd, NULL, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
break;
} else if (rv == 0) {
@@ -4110,7 +4214,7 @@ static void pt_InsertTimedInternal(pt_Continuation *op)
* Subsequently earlier timeouts are computed based on the latter
* knowledge by subracting the timeout deltas that are stored in
* the operation list. There are operation[n]->timeout ticks
- * between the expiration of operation[n-1] and operation[n].e e
+ * between the expiration of operation[n-1] and operation[n].e e
*
* Therefore, the operation[n-1] will expire operation[n]->timeout
* ticks prior to operation[n].
@@ -4145,7 +4249,9 @@ static void pt_InsertTimedInternal(pt_Continuation *op)
qd_tmo -= t_op->timeout; /* previous operaton expiration */
t_op = t_op->prev; /* point to previous operation */
- if (NULL != t_op) qd_tmo += t_op->timeout;
+ if (NULL != t_op) {
+ qd_tmo += t_op->timeout;
+ }
} while (NULL != t_op);
/*
@@ -4170,19 +4276,26 @@ done:
op->prev = NULL;
op->next = pt_tq.head;
pt_tq.head = op;
- if (NULL == pt_tq.tail) pt_tq.tail = op;
- else op->next->prev = op;
+ if (NULL == pt_tq.tail) {
+ pt_tq.tail = op;
+ }
+ else {
+ op->next->prev = op;
+ }
}
else
{
op->prev = t_op;
op->next = t_op->next;
- if (NULL != op->prev)
+ if (NULL != op->prev) {
op->prev->next = op;
- if (NULL != op->next)
+ }
+ if (NULL != op->next) {
op->next->prev = op;
- if (t_op == pt_tq.tail)
+ }
+ if (t_op == pt_tq.tail) {
pt_tq.tail = op;
+ }
}
/*
@@ -4193,7 +4306,7 @@ done:
if (PR_INTERVAL_NO_TIMEOUT != op->timeout)
{
if ((NULL == pt_tq.op) /* we're the one and only */
- || (t_op == pt_tq.op)) /* we're replacing */
+ || (t_op == pt_tq.op)) /* we're replacing */
{
pt_tq.op = op;
pt_tq.epoch = now;
@@ -4217,13 +4330,23 @@ static pt_Continuation *pt_FinishTimedInternal(pt_Continuation *op)
pt_Continuation *next;
/* remove this one from the list */
- if (NULL == op->prev) pt_tq.head = op->next;
- else op->prev->next = op->next;
- if (NULL == op->next) pt_tq.tail = op->prev;
- else op->next->prev = op->prev;
+ if (NULL == op->prev) {
+ pt_tq.head = op->next;
+ }
+ else {
+ op->prev->next = op->next;
+ }
+ if (NULL == op->next) {
+ pt_tq.tail = op->prev;
+ }
+ else {
+ op->next->prev = op->prev;
+ }
/* did we happen to hit the timed op? */
- if (op == pt_tq.op) pt_tq.op = op->prev;
+ if (op == pt_tq.op) {
+ pt_tq.op = op->prev;
+ }
next = op->next;
op->next = op->prev = NULL;
@@ -4264,20 +4387,24 @@ static void ContinuationThread(void *arg)
{
status = PR_WaitCondVar(pt_tq.new_op, PR_INTERVAL_NO_TIMEOUT);
if ((PR_FAILURE == status)
- && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) break;
+ && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) {
+ break;
+ }
}
pollingListNeeded = pt_tq.op_count;
PR_Unlock(pt_tq.ml);
/* Okay. We're history */
if ((PR_FAILURE == status)
- && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) break;
+ && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) {
+ break;
+ }
- /*
- * We are not holding the pt_tq.ml lock now, so more items may
- * get added to pt_tq during this window of time. We hope
- * that 10 more spaces in the polling list should be enough.
- */
+ /*
+ * We are not holding the pt_tq.ml lock now, so more items may
+ * get added to pt_tq during this window of time. We hope
+ * that 10 more spaces in the polling list should be enough.
+ */
FD_ZERO(&readSet);
FD_ZERO(&writeSet);
@@ -4285,15 +4412,18 @@ static void ContinuationThread(void *arg)
pollingListNeeded += 10;
if (pollingListNeeded > pollingSlotsAllocated)
{
- if (NULL != pollingList) PR_DELETE(pollingList);
+ if (NULL != pollingList) {
+ PR_DELETE(pollingList);
+ }
pollingList = PR_MALLOC(pollingListNeeded * sizeof(PRPollDesc));
PR_ASSERT(NULL != pollingList);
pollingSlotsAllocated = pollingListNeeded;
}
#if defined(DEBUG)
- if (pollingListNeeded > pt_debug.pollingListMax)
+ if (pollingListNeeded > pt_debug.pollingListMax) {
pt_debug.pollingListMax = pollingListUsed;
+ }
#endif
/*
@@ -4328,7 +4458,9 @@ static void ContinuationThread(void *arg)
}
pollingList[pollingListUsed] = op->arg1.osfd;
pollingListUsed += 1;
- if (pollingListUsed == pollingSlotsAllocated) break;
+ if (pollingListUsed == pollingSlotsAllocated) {
+ break;
+ }
op = op->next;
}
}
@@ -4351,7 +4483,9 @@ static void ContinuationThread(void *arg)
}
/* there's a chance that all ops got blown away */
- if (NULL == pt_tq.head) continue;
+ if (NULL == pt_tq.head) {
+ continue;
+ }
/* if not, we know this is the shortest timeout */
timeout = pt_tq.head->timeout;
@@ -4362,10 +4496,13 @@ static void ContinuationThread(void *arg)
* should persist forever. But they may be aborted. That's
* what this anxiety is all about.
*/
- if (timeout > mx_select_ticks) timeout = mx_select_ticks;
+ if (timeout > mx_select_ticks) {
+ timeout = mx_select_ticks;
+ }
- if (PR_INTERVAL_NO_TIMEOUT != pt_tq.head->timeout)
+ if (PR_INTERVAL_NO_TIMEOUT != pt_tq.head->timeout) {
pt_tq.head->timeout -= timeout;
+ }
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(timeout) % PR_USEC_PER_SEC;
@@ -4375,7 +4512,7 @@ static void ContinuationThread(void *arg)
{
if (0 == pt_tq.head->timeout)
{
- /*
+ /*
* The leading element of the timed queue has timed
* out. Get rid of it. In any case go around the
* loop again, computing the polling list, checking
@@ -4394,7 +4531,7 @@ static void ContinuationThread(void *arg)
}
if (-1 == rv && (WSAGetLastError() == WSAEINTR
- || WSAGetLastError() == WSAEINPROGRESS))
+ || WSAGetLastError() == WSAEINPROGRESS))
{
continue; /* go around the loop again */
}
@@ -4463,7 +4600,9 @@ static void ContinuationThread(void *arg)
}
}
}
- if (NULL != pollingList) PR_DELETE(pollingList);
+ if (NULL != pollingList) {
+ PR_DELETE(pollingList);
+ }
} /* ContinuationThread */
static int pt_Continue(pt_Continuation *op)
@@ -4493,8 +4632,9 @@ static int pt_Continue(pt_Continuation *op)
* anyhow and should notice the request in there.
*/
if ((PR_FAILURE == rv)
- && (PR_PENDING_INTERRUPT_ERROR == PR_GetError()))
- op->status = pt_continuation_abort; /* our status */
+ && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) {
+ op->status = pt_continuation_abort; /* our status */
+ }
}
PR_Unlock(pt_tq.ml); /* we provide the locking */
@@ -4507,8 +4647,8 @@ static int pt_Continue(pt_Continuation *op)
static PRBool pt_sendto_cont(pt_Continuation *op, PRInt16 revents)
{
PRIntn bytes = sendto(
- op->arg1.osfd, op->arg2.buffer, op->arg3.amount, op->arg4.flags,
- (struct sockaddr*)op->arg5.addr, sizeof(*(op->arg5.addr)));
+ op->arg1.osfd, op->arg2.buffer, op->arg3.amount, op->arg4.flags,
+ (struct sockaddr*)op->arg5.addr, sizeof(*(op->arg5.addr)));
op->syserrno = WSAGetLastError();
if (bytes > 0) /* this is progress */
{
@@ -4520,18 +4660,18 @@ static PRBool pt_sendto_cont(pt_Continuation *op, PRInt16 revents)
return (0 == op->arg3.amount) ? PR_TRUE : PR_FALSE;
}
else return ((-1 == bytes) && (WSAEWOULDBLOCK == op->syserrno)) ?
- PR_FALSE : PR_TRUE;
+ PR_FALSE : PR_TRUE;
} /* pt_sendto_cont */
static PRBool pt_recvfrom_cont(pt_Continuation *op, PRInt16 revents)
{
PRIntn addr_len = sizeof(*(op->arg5.addr));
op->result.code = recvfrom(
- op->arg1.osfd, op->arg2.buffer, op->arg3.amount,
- op->arg4.flags, (struct sockaddr*)op->arg5.addr, &addr_len);
+ op->arg1.osfd, op->arg2.buffer, op->arg3.amount,
+ op->arg4.flags, (struct sockaddr*)op->arg5.addr, &addr_len);
op->syserrno = WSAGetLastError();
return ((-1 == op->result.code) && (WSAEWOULDBLOCK == op->syserrno)) ?
- PR_FALSE : PR_TRUE;
+ PR_FALSE : PR_TRUE;
} /* pt_recvfrom_cont */
static PRInt32 pt_SendTo(
@@ -4543,13 +4683,15 @@ static PRInt32 pt_SendTo(
PRBool fNeedContinue = PR_FALSE;
bytes = sendto(
- osfd, buf, amount, flags,
- (struct sockaddr*)addr, PR_NETADDR_SIZE(addr));
+ osfd, buf, amount, flags,
+ (struct sockaddr*)addr, PR_NETADDR_SIZE(addr));
if (bytes == -1) {
- if ((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- fNeedContinue = PR_TRUE;
- else
- _PR_MD_MAP_SENDTO_ERROR(err);
+ if ((err = WSAGetLastError()) == WSAEWOULDBLOCK) {
+ fNeedContinue = PR_TRUE;
+ }
+ else {
+ _PR_MD_MAP_SENDTO_ERROR(err);
+ }
}
if (fNeedContinue == PR_TRUE)
{
@@ -4566,26 +4708,28 @@ static PRInt32 pt_SendTo(
bytes = pt_Continue(&op);
if (bytes < 0) {
WSASetLastError(op.syserrno);
- _PR_MD_MAP_SENDTO_ERROR(op.syserrno);
+ _PR_MD_MAP_SENDTO_ERROR(op.syserrno);
}
}
return bytes;
} /* pt_SendTo */
static PRInt32 pt_RecvFrom(SOCKET osfd, void *buf, PRInt32 amount,
- PRInt32 flags, PRNetAddr *addr, PRIntn *addr_len, PRIntervalTime timeout)
+ PRInt32 flags, PRNetAddr *addr, PRIntn *addr_len, PRIntervalTime timeout)
{
PRInt32 bytes = -1, err;
PRBool fNeedContinue = PR_FALSE;
bytes = recvfrom(
- osfd, buf, amount, flags,
- (struct sockaddr*)addr, addr_len);
+ osfd, buf, amount, flags,
+ (struct sockaddr*)addr, addr_len);
if (bytes == -1) {
- if ((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- fNeedContinue = PR_TRUE;
- else
- _PR_MD_MAP_RECVFROM_ERROR(err);
+ if ((err = WSAGetLastError()) == WSAEWOULDBLOCK) {
+ fNeedContinue = PR_TRUE;
+ }
+ else {
+ _PR_MD_MAP_RECVFROM_ERROR(err);
+ }
}
if (fNeedContinue == PR_TRUE)
@@ -4602,7 +4746,7 @@ static PRInt32 pt_RecvFrom(SOCKET osfd, void *buf, PRInt32 amount,
bytes = pt_Continue(&op);
if (bytes < 0) {
WSASetLastError(op.syserrno);
- _PR_MD_MAP_RECVFROM_ERROR(op.syserrno);
+ _PR_MD_MAP_RECVFROM_ERROR(op.syserrno);
}
}
return bytes;
diff --git a/nsprpub/pr/src/md/windows/ntmisc.c b/nsprpub/pr/src/md/windows/ntmisc.c
index 12f8c1df7..1ec6c2a5e 100644
--- a/nsprpub/pr/src/md/windows/ntmisc.c
+++ b/nsprpub/pr/src/md/windows/ntmisc.c
@@ -88,43 +88,43 @@ NowCalibrate(void)
LARGE_INTEGER liFreq, now;
if (calibration.freq == 0.0) {
- if(!QueryPerformanceFrequency(&liFreq)) {
- /* High-performance timer is unavailable */
- calibration.freq = -1.0;
- } else {
- calibration.freq = (long double) liFreq.QuadPart;
- }
+ if(!QueryPerformanceFrequency(&liFreq)) {
+ /* High-performance timer is unavailable */
+ calibration.freq = -1.0;
+ } else {
+ calibration.freq = (long double) liFreq.QuadPart;
+ }
}
if (calibration.freq > 0.0) {
- PRInt64 calibrationDelta = 0;
- /*
- * By wrapping a timeBegin/EndPeriod pair of calls around this loop,
- * the loop seems to take much less time (1 ms vs 15ms) on Vista.
- */
- timeBeginPeriod(1);
- LowResTime(&ftStart);
- do {
- LowResTime(&ft);
- } while (memcmp(&ftStart,&ft, sizeof(ft)) == 0);
- timeEndPeriod(1);
-
- calibration.granularity =
- (FILETIME_TO_INT64(ft) - FILETIME_TO_INT64(ftStart))/10;
-
- QueryPerformanceCounter(&now);
-
- calibration.offset = (long double) FILETIME_TO_INT64(ft);
- calibration.timer_offset = (long double) now.QuadPart;
- /*
- * The windows epoch is around 1600. The unix epoch is around 1970.
- * _pr_filetime_offset is the difference (in windows time units which
- * are 10 times more highres than the JS time unit)
- */
- calibration.offset -= _pr_filetime_offset;
- calibration.offset *= 0.1;
- calibration.last = 0;
-
- calibration.calibrated = PR_TRUE;
+ PRInt64 calibrationDelta = 0;
+ /*
+ * By wrapping a timeBegin/EndPeriod pair of calls around this loop,
+ * the loop seems to take much less time (1 ms vs 15ms) on Vista.
+ */
+ timeBeginPeriod(1);
+ LowResTime(&ftStart);
+ do {
+ LowResTime(&ft);
+ } while (memcmp(&ftStart,&ft, sizeof(ft)) == 0);
+ timeEndPeriod(1);
+
+ calibration.granularity =
+ (FILETIME_TO_INT64(ft) - FILETIME_TO_INT64(ftStart))/10;
+
+ QueryPerformanceCounter(&now);
+
+ calibration.offset = (long double) FILETIME_TO_INT64(ft);
+ calibration.timer_offset = (long double) now.QuadPart;
+ /*
+ * The windows epoch is around 1600. The unix epoch is around 1970.
+ * _pr_filetime_offset is the difference (in windows time units which
+ * are 10 times more highres than the JS time unit)
+ */
+ calibration.offset -= _pr_filetime_offset;
+ calibration.offset *= 0.1;
+ calibration.last = 0;
+
+ calibration.calibrated = PR_TRUE;
}
}
@@ -138,7 +138,7 @@ _MD_InitTime(void)
/* try for CE6 GetSystemTimeAsFileTime first */
HANDLE h = GetModuleHandleW(L"coredll.dll");
ce6_GetSystemTimeAsFileTime = (GetSystemTimeAsFileTimeFcn)
- GetProcAddressA(h, "GetSystemTimeAsFileTime");
+ GetProcAddressA(h, "GetSystemTimeAsFileTime");
/* otherwise go the slow route */
if (ce6_GetSystemTimeAsFileTime == NULL) {
@@ -199,113 +199,113 @@ PR_Now(void)
* a constant, and the entire expression is faster to execute.
*/
return currentTime.prt/_pr_filetime_divisor -
- _pr_filetime_offset/_pr_filetime_divisor;
+ _pr_filetime_offset/_pr_filetime_divisor;
}
do {
- if (!calibration.calibrated || needsCalibration) {
- EnterCriticalSection(&calibration.calibration_lock);
- EnterCriticalSection(&calibration.data_lock);
-
- /* Recalibrate only if no one else did before us */
- if (calibration.offset == cachedOffset) {
- /*
- * Since calibration can take a while, make any other
- * threads immediately wait
- */
- MUTEX_SETSPINCOUNT(&calibration.data_lock, 0);
-
- NowCalibrate();
-
- calibrated = PR_TRUE;
-
- /* Restore spin count */
- MUTEX_SETSPINCOUNT(&calibration.data_lock, DATALOCK_SPINCOUNT);
- }
- LeaveCriticalSection(&calibration.data_lock);
- LeaveCriticalSection(&calibration.calibration_lock);
- }
-
- /* Calculate a low resolution time */
- LowResTime(&ft);
- lowresTime =
+ if (!calibration.calibrated || needsCalibration) {
+ EnterCriticalSection(&calibration.calibration_lock);
+ EnterCriticalSection(&calibration.data_lock);
+
+ /* Recalibrate only if no one else did before us */
+ if (calibration.offset == cachedOffset) {
+ /*
+ * Since calibration can take a while, make any other
+ * threads immediately wait
+ */
+ MUTEX_SETSPINCOUNT(&calibration.data_lock, 0);
+
+ NowCalibrate();
+
+ calibrated = PR_TRUE;
+
+ /* Restore spin count */
+ MUTEX_SETSPINCOUNT(&calibration.data_lock, DATALOCK_SPINCOUNT);
+ }
+ LeaveCriticalSection(&calibration.data_lock);
+ LeaveCriticalSection(&calibration.calibration_lock);
+ }
+
+ /* Calculate a low resolution time */
+ LowResTime(&ft);
+ lowresTime =
((long double)(FILETIME_TO_INT64(ft) - _pr_filetime_offset)) * 0.1;
- if (calibration.freq > 0.0) {
- long double highresTime, diff;
- DWORD timeAdjustment, timeIncrement;
- BOOL timeAdjustmentDisabled;
-
- /* Default to 15.625 ms if the syscall fails */
- long double skewThreshold = 15625.25;
-
- /* Grab high resolution time */
- QueryPerformanceCounter(&now);
- highresTimerValue = (long double)now.QuadPart;
-
- EnterCriticalSection(&calibration.data_lock);
- highresTime = calibration.offset + 1000000L *
- (highresTimerValue-calibration.timer_offset)/calibration.freq;
- cachedOffset = calibration.offset;
-
- /*
- * On some dual processor/core systems, we might get an earlier
- * time so we cache the last time that we returned.
- */
- calibration.last = PR_MAX(calibration.last,(PRInt64)highresTime);
- returnedTime = calibration.last;
- LeaveCriticalSection(&calibration.data_lock);
-
- /* Get an estimate of clock ticks per second from our own test */
- skewThreshold = calibration.granularity;
- /* Check for clock skew */
- diff = lowresTime - highresTime;
-
- /*
- * For some reason that I have not determined, the skew can be
- * up to twice a kernel tick. This does not seem to happen by
- * itself, but I have only seen it triggered by another program
- * doing some kind of file I/O. The symptoms are a negative diff
- * followed by an equally large positive diff.
- */
- if (fabs(diff) > 2*skewThreshold) {
- if (calibrated) {
- /*
- * If we already calibrated once this instance, and the
- * clock is still skewed, then either the processor(s) are
- * wildly changing clockspeed or the system is so busy that
- * we get switched out for long periods of time. In either
- * case, it would be infeasible to make use of high
- * resolution results for anything, so let's resort to old
- * behavior for this call. It's possible that in the
- * future, the user will want the high resolution timer, so
- * we don't disable it entirely.
- */
- returnedTime = (PRInt64)lowresTime;
- needsCalibration = PR_FALSE;
- } else {
- /*
- * It is possible that when we recalibrate, we will return
- * a value less than what we have returned before; this is
- * unavoidable. We cannot tell the different between a
- * faulty QueryPerformanceCounter implementation and user
- * changes to the operating system time. Since we must
- * respect user changes to the operating system time, we
- * cannot maintain the invariant that Date.now() never
- * decreases; the old implementation has this behavior as
- * well.
- */
- needsCalibration = PR_TRUE;
- }
- } else {
- /* No detectable clock skew */
- returnedTime = (PRInt64)highresTime;
- needsCalibration = PR_FALSE;
- }
- } else {
- /* No high resolution timer is available, so fall back */
- returnedTime = (PRInt64)lowresTime;
- }
+ if (calibration.freq > 0.0) {
+ long double highresTime, diff;
+ DWORD timeAdjustment, timeIncrement;
+ BOOL timeAdjustmentDisabled;
+
+ /* Default to 15.625 ms if the syscall fails */
+ long double skewThreshold = 15625.25;
+
+ /* Grab high resolution time */
+ QueryPerformanceCounter(&now);
+ highresTimerValue = (long double)now.QuadPart;
+
+ EnterCriticalSection(&calibration.data_lock);
+ highresTime = calibration.offset + 1000000L *
+ (highresTimerValue-calibration.timer_offset)/calibration.freq;
+ cachedOffset = calibration.offset;
+
+ /*
+ * On some dual processor/core systems, we might get an earlier
+ * time so we cache the last time that we returned.
+ */
+ calibration.last = PR_MAX(calibration.last,(PRInt64)highresTime);
+ returnedTime = calibration.last;
+ LeaveCriticalSection(&calibration.data_lock);
+
+ /* Get an estimate of clock ticks per second from our own test */
+ skewThreshold = calibration.granularity;
+ /* Check for clock skew */
+ diff = lowresTime - highresTime;
+
+ /*
+ * For some reason that I have not determined, the skew can be
+ * up to twice a kernel tick. This does not seem to happen by
+ * itself, but I have only seen it triggered by another program
+ * doing some kind of file I/O. The symptoms are a negative diff
+ * followed by an equally large positive diff.
+ */
+ if (fabs(diff) > 2*skewThreshold) {
+ if (calibrated) {
+ /*
+ * If we already calibrated once this instance, and the
+ * clock is still skewed, then either the processor(s) are
+ * wildly changing clockspeed or the system is so busy that
+ * we get switched out for long periods of time. In either
+ * case, it would be infeasible to make use of high
+ * resolution results for anything, so let's resort to old
+ * behavior for this call. It's possible that in the
+ * future, the user will want the high resolution timer, so
+ * we don't disable it entirely.
+ */
+ returnedTime = (PRInt64)lowresTime;
+ needsCalibration = PR_FALSE;
+ } else {
+ /*
+ * It is possible that when we recalibrate, we will return
+ * a value less than what we have returned before; this is
+ * unavoidable. We cannot tell the different between a
+ * faulty QueryPerformanceCounter implementation and user
+ * changes to the operating system time. Since we must
+ * respect user changes to the operating system time, we
+ * cannot maintain the invariant that Date.now() never
+ * decreases; the old implementation has this behavior as
+ * well.
+ */
+ needsCalibration = PR_TRUE;
+ }
+ } else {
+ /* No detectable clock skew */
+ returnedTime = (PRInt64)highresTime;
+ needsCalibration = PR_FALSE;
+ }
+ } else {
+ /* No high resolution timer is available, so fall back */
+ returnedTime = (PRInt64)lowresTime;
+ }
} while (needsCalibration);
return returnedTime;
@@ -323,7 +323,7 @@ PR_Now(void)
GetSystemTime(&st);
SystemTimeToFileTime(&st, &ft);
_PR_FileTimeToPRTime(&ft, &prt);
- return prt;
+ return prt;
}
#endif
@@ -365,8 +365,8 @@ static int assembleCmdLine(char *const *argv, char **cmdLine)
* a null byte at the end of command line.
*/
cmdLineSize += 2 * strlen(*arg) /* \ and " need to be escaped */
- + 2 /* we quote every argument */
- + 1; /* space in between, or final null */
+ + 2 /* we quote every argument */
+ + 1; /* space in between, or final null */
}
p = *cmdLine = PR_MALLOC((PRUint32) cmdLineSize);
if (p == NULL) {
@@ -376,7 +376,7 @@ static int assembleCmdLine(char *const *argv, char **cmdLine)
for (arg = argv; *arg; arg++) {
/* Add a space to separates the arguments */
if (arg != argv) {
- *p++ = ' ';
+ *p++ = ' ';
}
q = *arg;
numBackslashes = 0;
@@ -442,7 +442,7 @@ static int assembleCmdLine(char *const *argv, char **cmdLine)
if (argNeedQuotes) {
*p++ = '"';
}
- }
+ }
*p = '\0';
return 0;
@@ -488,7 +488,7 @@ static int assembleEnvBlock(char **envp, char **envBlock)
cwdStart = curEnv;
while (*cwdStart) {
if (cwdStart[0] == '=' && cwdStart[1] != '\0'
- && cwdStart[2] == ':' && cwdStart[3] == '=') {
+ && cwdStart[2] == ':' && cwdStart[3] == '=') {
break;
}
cwdStart += strlen(cwdStart) + 1;
@@ -498,7 +498,7 @@ static int assembleEnvBlock(char **envp, char **envBlock)
cwdEnd += strlen(cwdEnd) + 1;
while (*cwdEnd) {
if (cwdEnd[0] != '=' || cwdEnd[1] == '\0'
- || cwdEnd[2] != ':' || cwdEnd[3] != '=') {
+ || cwdEnd[2] != ':' || cwdEnd[3] != '=') {
break;
}
cwdEnd += strlen(cwdEnd) + 1;
@@ -609,7 +609,7 @@ PRProcess * _PR_CreateWindowsProcess(
for (idx = 0; idx < numEnv; idx++) {
newEnvp[idx] = envp[idx];
if (hasFdInheritBuffer && !found
- && !strncmp(newEnvp[idx], "NSPR_INHERIT_FDS=", 17)) {
+ && !strncmp(newEnvp[idx], "NSPR_INHERIT_FDS=", 17)) {
newEnvp[idx] = attr->fdInheritBuffer;
found = PR_TRUE;
}
@@ -759,7 +759,7 @@ PRStatus _PR_DetachWindowsProcess(PRProcess *process)
* It can be called by native threads only (not by fibers).
*/
PRStatus _PR_WaitWindowsProcess(PRProcess *process,
- PRInt32 *exitCode)
+ PRInt32 *exitCode)
{
DWORD dwRetVal;
@@ -770,7 +770,7 @@ PRStatus _PR_WaitWindowsProcess(PRProcess *process,
}
PR_ASSERT(dwRetVal == WAIT_OBJECT_0);
if (exitCode != NULL &&
- GetExitCodeProcess(process->md.handle, exitCode) == FALSE) {
+ GetExitCodeProcess(process->md.handle, exitCode) == FALSE) {
PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
return PR_FAILURE;
}
@@ -787,7 +787,7 @@ PRStatus _PR_KillWindowsProcess(PRProcess *process)
* 256 to indicate that the process is killed.
*/
if (TerminateProcess(process->md.handle, 256)) {
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
return PR_FAILURE;
@@ -804,86 +804,92 @@ PRStatus _MD_WindowsGetHostName(char *name, PRUint32 namelen)
}
syserror = WSAGetLastError();
PR_ASSERT(WSANOTINITIALISED != syserror);
- _PR_MD_MAP_GETHOSTNAME_ERROR(syserror);
+ _PR_MD_MAP_GETHOSTNAME_ERROR(syserror);
return PR_FAILURE;
}
PRStatus _MD_WindowsGetSysInfo(PRSysInfo cmd, char *name, PRUint32 namelen)
{
- OSVERSIONINFO osvi;
-
- PR_ASSERT((cmd == PR_SI_SYSNAME) || (cmd == PR_SI_RELEASE));
-
- ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-
- if (! GetVersionEx (&osvi) ) {
- _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
- return PR_FAILURE;
- }
-
- switch (osvi.dwPlatformId) {
- case VER_PLATFORM_WIN32_NT:
- if (PR_SI_SYSNAME == cmd)
- (void)PR_snprintf(name, namelen, "Windows_NT");
- else if (PR_SI_RELEASE == cmd)
- (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
- osvi.dwMinorVersion);
- break;
- case VER_PLATFORM_WIN32_WINDOWS:
- if (PR_SI_SYSNAME == cmd) {
- if ((osvi.dwMajorVersion > 4) ||
- ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion > 0)))
- (void)PR_snprintf(name, namelen, "Windows_98");
- else
- (void)PR_snprintf(name, namelen, "Windows_95");
- } else if (PR_SI_RELEASE == cmd) {
- (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
- osvi.dwMinorVersion);
- }
- break;
+ OSVERSIONINFO osvi;
+
+ PR_ASSERT((cmd == PR_SI_SYSNAME) || (cmd == PR_SI_RELEASE));
+
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ if (! GetVersionEx (&osvi) ) {
+ _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
+ return PR_FAILURE;
+ }
+
+ switch (osvi.dwPlatformId) {
+ case VER_PLATFORM_WIN32_NT:
+ if (PR_SI_SYSNAME == cmd) {
+ (void)PR_snprintf(name, namelen, "Windows_NT");
+ }
+ else if (PR_SI_RELEASE == cmd)
+ (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
+ osvi.dwMinorVersion);
+ break;
+ case VER_PLATFORM_WIN32_WINDOWS:
+ if (PR_SI_SYSNAME == cmd) {
+ if ((osvi.dwMajorVersion > 4) ||
+ ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion > 0))) {
+ (void)PR_snprintf(name, namelen, "Windows_98");
+ }
+ else {
+ (void)PR_snprintf(name, namelen, "Windows_95");
+ }
+ } else if (PR_SI_RELEASE == cmd) {
+ (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
+ osvi.dwMinorVersion);
+ }
+ break;
#ifdef VER_PLATFORM_WIN32_CE
- case VER_PLATFORM_WIN32_CE:
- if (PR_SI_SYSNAME == cmd)
- (void)PR_snprintf(name, namelen, "Windows_CE");
- else if (PR_SI_RELEASE == cmd)
- (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
- osvi.dwMinorVersion);
- break;
+ case VER_PLATFORM_WIN32_CE:
+ if (PR_SI_SYSNAME == cmd) {
+ (void)PR_snprintf(name, namelen, "Windows_CE");
+ }
+ else if (PR_SI_RELEASE == cmd)
+ (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
+ osvi.dwMinorVersion);
+ break;
#endif
- default:
- if (PR_SI_SYSNAME == cmd)
- (void)PR_snprintf(name, namelen, "Windows_Unknown");
- else if (PR_SI_RELEASE == cmd)
- (void)PR_snprintf(name, namelen, "%d.%d",0,0);
- break;
- }
- return PR_SUCCESS;
+ default:
+ if (PR_SI_SYSNAME == cmd) {
+ (void)PR_snprintf(name, namelen, "Windows_Unknown");
+ }
+ else if (PR_SI_RELEASE == cmd) {
+ (void)PR_snprintf(name, namelen, "%d.%d",0,0);
+ }
+ break;
+ }
+ return PR_SUCCESS;
}
PRStatus _MD_WindowsGetReleaseName(char *name, PRUint32 namelen)
{
- OSVERSIONINFO osvi;
-
- ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-
- if (! GetVersionEx (&osvi) ) {
- _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
- return PR_FAILURE;
- }
-
- switch (osvi.dwPlatformId) {
- case VER_PLATFORM_WIN32_NT:
- case VER_PLATFORM_WIN32_WINDOWS:
- (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
- osvi.dwMinorVersion);
- break;
- default:
- (void)PR_snprintf(name, namelen, "%d.%d",0,0);
- break;
- }
- return PR_SUCCESS;
+ OSVERSIONINFO osvi;
+
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ if (! GetVersionEx (&osvi) ) {
+ _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
+ return PR_FAILURE;
+ }
+
+ switch (osvi.dwPlatformId) {
+ case VER_PLATFORM_WIN32_NT:
+ case VER_PLATFORM_WIN32_WINDOWS:
+ (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
+ osvi.dwMinorVersion);
+ break;
+ default:
+ (void)PR_snprintf(name, namelen, "%d.%d",0,0);
+ break;
+ }
+ return PR_SUCCESS;
}
/*
@@ -924,12 +930,12 @@ PRStatus _MD_CreateFileMap(PRFileMap *fmap, PRInt64 size)
}
fmap->md.hFileMap = CreateFileMapping(
- (HANDLE) osfd,
- NULL,
- flProtect,
- dwHi,
- dwLo,
- NULL);
+ (HANDLE) osfd,
+ NULL,
+ flProtect,
+ dwHi,
+ dwLo,
+ NULL);
if (fmap->md.hFileMap == NULL) {
PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
@@ -958,18 +964,18 @@ void * _MD_MemMap(
dwLo = (DWORD) (offset & 0xffffffff);
dwHi = (DWORD) (((PRUint64) offset >> 32) & 0xffffffff);
if ((addr = MapViewOfFile(fmap->md.hFileMap, fmap->md.dwAccess,
- dwHi, dwLo, len)) == NULL) {
+ dwHi, dwLo, len)) == NULL) {
{
- LPVOID lpMsgBuf;
-
- FormatMessage(
+ LPVOID lpMsgBuf;
+
+ FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
- NULL
+ NULL
);
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, ("md_memmap(): %s", lpMsgBuf ));
}
@@ -1035,13 +1041,13 @@ PRStatus _MD_SyncMemMap(
#pragma warning(disable: 4035)
PRInt32 _PR_MD_ATOMIC_INCREMENT(PRInt32 *val)
-{
+{
#if defined(__GNUC__)
- PRInt32 result;
- asm volatile ("lock ; xadd %0, %1"
- : "=r"(result), "=m"(*val)
- : "0"(1), "m"(*val));
- return result + 1;
+ PRInt32 result;
+ asm volatile ("lock ; xadd %0, %1"
+ : "=r"(result), "=m"(*val)
+ : "0"(1), "m"(*val));
+ return result + 1;
#else
__asm
{
@@ -1058,12 +1064,12 @@ PRInt32 _PR_MD_ATOMIC_INCREMENT(PRInt32 *val)
PRInt32 _PR_MD_ATOMIC_DECREMENT(PRInt32 *val)
{
#if defined(__GNUC__)
- PRInt32 result;
- asm volatile ("lock ; xadd %0, %1"
- : "=r"(result), "=m"(*val)
- : "0"(-1), "m"(*val));
- //asm volatile("lock ; xadd %0, %1" : "=m" (val), "=a" (result) : "-1" (1));
- return result - 1;
+ PRInt32 result;
+ asm volatile ("lock ; xadd %0, %1"
+ : "=r"(result), "=m"(*val)
+ : "0"(-1), "m"(*val));
+ //asm volatile("lock ; xadd %0, %1" : "=m" (val), "=a" (result) : "-1" (1));
+ return result - 1;
#else
__asm
{
@@ -1080,12 +1086,12 @@ PRInt32 _PR_MD_ATOMIC_DECREMENT(PRInt32 *val)
PRInt32 _PR_MD_ATOMIC_ADD(PRInt32 *intp, PRInt32 val)
{
#if defined(__GNUC__)
- PRInt32 result;
- //asm volatile("lock ; xadd %1, %0" : "=m" (intp), "=a" (result) : "1" (val));
- asm volatile ("lock ; xadd %0, %1"
- : "=r"(result), "=m"(*intp)
- : "0"(val), "m"(*intp));
- return result + val;
+ PRInt32 result;
+ //asm volatile("lock ; xadd %1, %0" : "=m" (intp), "=a" (result) : "1" (val));
+ asm volatile ("lock ; xadd %0, %1"
+ : "=r"(result), "=m"(*intp)
+ : "0"(val), "m"(*intp));
+ return result + val;
#else
__asm
{
@@ -1102,96 +1108,101 @@ PRInt32 _PR_MD_ATOMIC_ADD(PRInt32 *intp, PRInt32 val)
#ifdef _PR_HAVE_ATOMIC_CAS
#pragma warning(disable: 4035)
-void
+void
PR_StackPush(PRStack *stack, PRStackElem *stack_elem)
{
#if defined(__GNUC__)
- void **tos = (void **) stack;
- void *tmp;
-
- retry:
- if (*tos == (void *) -1)
- goto retry;
-
- __asm__("xchg %0,%1"
- : "=r" (tmp), "=m"(*tos)
- : "0" (-1), "m"(*tos));
-
- if (tmp == (void *) -1)
- goto retry;
-
- *(void **)stack_elem = tmp;
- __asm__("" : : : "memory");
- *tos = stack_elem;
+ void **tos = (void **) stack;
+ void *tmp;
+
+retry:
+ if (*tos == (void *) -1) {
+ goto retry;
+ }
+
+ __asm__("xchg %0,%1"
+ : "=r" (tmp), "=m"(*tos)
+ : "0" (-1), "m"(*tos));
+
+ if (tmp == (void *) -1) {
+ goto retry;
+ }
+
+ *(void **)stack_elem = tmp;
+ __asm__("" : : : "memory");
+ *tos = stack_elem;
#else
__asm
{
- mov ebx, stack
- mov ecx, stack_elem
-retry: mov eax,[ebx]
- cmp eax,-1
- je retry
- mov eax,-1
- xchg dword ptr [ebx], eax
- cmp eax,-1
- je retry
- mov [ecx],eax
- mov [ebx],ecx
+ mov ebx, stack
+ mov ecx, stack_elem
+ retry: mov eax,[ebx]
+ cmp eax,-1
+ je retry
+ mov eax,-1
+ xchg dword ptr [ebx], eax
+ cmp eax,-1
+ je retry
+ mov [ecx],eax
+ mov [ebx],ecx
}
#endif /* __GNUC__ */
}
#pragma warning(default: 4035)
#pragma warning(disable: 4035)
-PRStackElem *
+PRStackElem *
PR_StackPop(PRStack *stack)
{
#if defined(__GNUC__)
- void **tos = (void **) stack;
- void *tmp;
-
- retry:
- if (*tos == (void *) -1)
- goto retry;
-
- __asm__("xchg %0,%1"
- : "=r" (tmp), "=m"(*tos)
- : "0" (-1), "m"(*tos));
-
- if (tmp == (void *) -1)
- goto retry;
-
- if (tmp != (void *) 0)
+ void **tos = (void **) stack;
+ void *tmp;
+
+retry:
+ if (*tos == (void *) -1) {
+ goto retry;
+ }
+
+ __asm__("xchg %0,%1"
+ : "=r" (tmp), "=m"(*tos)
+ : "0" (-1), "m"(*tos));
+
+ if (tmp == (void *) -1) {
+ goto retry;
+ }
+
+ if (tmp != (void *) 0)
{
- void *next = *(void **)tmp;
- *tos = next;
- *(void **)tmp = 0;
+ void *next = *(void **)tmp;
+ *tos = next;
+ *(void **)tmp = 0;
+ }
+ else {
+ *tos = tmp;
}
- else
- *tos = tmp;
-
- return tmp;
+
+ return tmp;
#else
__asm
{
- mov ebx, stack
-retry: mov eax,[ebx]
- cmp eax,-1
- je retry
- mov eax,-1
- xchg dword ptr [ebx], eax
- cmp eax,-1
- je retry
- cmp eax,0
- je empty
- mov ecx,[eax]
- mov [ebx],ecx
- mov [eax],0
- jmp done
-empty:
- mov [ebx],eax
-done:
- }
+ mov ebx, stack
+ retry: mov eax,[ebx]
+ cmp eax,-1
+ je retry
+ mov eax,-1
+ xchg dword ptr [ebx], eax
+ cmp eax,-1
+ je retry
+ cmp eax,0
+ je empty
+ mov ecx,[eax]
+ mov [ebx],ecx
+ mov [eax],0
+ jmp done
+ empty:
+ mov [ebx],eax
+ done:
+ }
#endif /* __GNUC__ */
}
#pragma warning(default: 4035)
diff --git a/nsprpub/pr/src/md/windows/ntsec.c b/nsprpub/pr/src/md/windows/ntsec.c
index c0682e454..0006e8399 100644
--- a/nsprpub/pr/src/md/windows/ntsec.c
+++ b/nsprpub/pr/src/md/windows/ntsec.c
@@ -47,7 +47,7 @@ void _PR_NT_InitSids(void)
* to force proper alignment */
PTOKEN_OWNER pTokenOwner = (PTOKEN_OWNER) infoBuffer;
PTOKEN_PRIMARY_GROUP pTokenPrimaryGroup
- = (PTOKEN_PRIMARY_GROUP) infoBuffer;
+ = (PTOKEN_PRIMARY_GROUP) infoBuffer;
DWORD dwLength;
BOOL rv;
@@ -67,13 +67,13 @@ void _PR_NT_InitSids(void)
* with the error code ERROR_ACCESS_DENIED.
*/
PR_LOG(_pr_io_lm, PR_LOG_DEBUG,
- ("_PR_NT_InitSids: OpenProcessToken() failed. Error: %d",
+ ("_PR_NT_InitSids: OpenProcessToken() failed. Error: %d",
GetLastError()));
return;
}
rv = GetTokenInformation(hToken, TokenOwner, infoBuffer,
- sizeof(infoBuffer), &dwLength);
+ sizeof(infoBuffer), &dwLength);
PR_ASSERT(rv != 0);
dwLength = GetLengthSid(pTokenOwner->Owner);
_pr_nt_sids.owner = (PSID) PR_Malloc(dwLength);
@@ -82,13 +82,13 @@ void _PR_NT_InitSids(void)
PR_ASSERT(rv != 0);
rv = GetTokenInformation(hToken, TokenPrimaryGroup, infoBuffer,
- sizeof(infoBuffer), &dwLength);
+ sizeof(infoBuffer), &dwLength);
PR_ASSERT(rv != 0);
dwLength = GetLengthSid(pTokenPrimaryGroup->PrimaryGroup);
_pr_nt_sids.group = (PSID) PR_Malloc(dwLength);
PR_ASSERT(_pr_nt_sids.group != NULL);
rv = CopySid(dwLength, _pr_nt_sids.group,
- pTokenPrimaryGroup->PrimaryGroup);
+ pTokenPrimaryGroup->PrimaryGroup);
PR_ASSERT(rv != 0);
rv = CloseHandle(hToken);
@@ -96,9 +96,9 @@ void _PR_NT_InitSids(void)
/* Create a well-known SID for the Everyone group. */
rv = AllocateAndInitializeSid(&SIDAuthWorld, 1,
- SECURITY_WORLD_RID,
- 0, 0, 0, 0, 0, 0, 0,
- &_pr_nt_sids.everyone);
+ SECURITY_WORLD_RID,
+ 0, 0, 0, 0, 0, 0, 0,
+ &_pr_nt_sids.everyone);
PR_ASSERT(rv != 0);
#endif
}
@@ -184,10 +184,10 @@ _PR_NT_MakeSecurityDescriptorACL(
*/
cbACL = sizeof(ACL)
- + 3 * (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD))
- + GetLengthSid(_pr_nt_sids.owner)
- + GetLengthSid(_pr_nt_sids.group)
- + GetLengthSid(_pr_nt_sids.everyone);
+ + 3 * (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD))
+ + GetLengthSid(_pr_nt_sids.owner)
+ + GetLengthSid(_pr_nt_sids.group)
+ + GetLengthSid(_pr_nt_sids.everyone);
pACL = (PACL) PR_Malloc(cbACL);
if (pACL == NULL) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
@@ -198,29 +198,47 @@ _PR_NT_MakeSecurityDescriptorACL(
goto failed;
}
accessMask = 0;
- if (mode & 00400) accessMask |= accessTable[0];
- if (mode & 00200) accessMask |= accessTable[1];
- if (mode & 00100) accessMask |= accessTable[2];
+ if (mode & 00400) {
+ accessMask |= accessTable[0];
+ }
+ if (mode & 00200) {
+ accessMask |= accessTable[1];
+ }
+ if (mode & 00100) {
+ accessMask |= accessTable[2];
+ }
if (accessMask && !AddAccessAllowedAce(pACL, ACL_REVISION, accessMask,
- _pr_nt_sids.owner)) {
+ _pr_nt_sids.owner)) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
goto failed;
}
accessMask = 0;
- if (mode & 00040) accessMask |= accessTable[0];
- if (mode & 00020) accessMask |= accessTable[1];
- if (mode & 00010) accessMask |= accessTable[2];
+ if (mode & 00040) {
+ accessMask |= accessTable[0];
+ }
+ if (mode & 00020) {
+ accessMask |= accessTable[1];
+ }
+ if (mode & 00010) {
+ accessMask |= accessTable[2];
+ }
if (accessMask && !AddAccessAllowedAce(pACL, ACL_REVISION, accessMask,
- _pr_nt_sids.group)) {
+ _pr_nt_sids.group)) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
goto failed;
}
accessMask = 0;
- if (mode & 00004) accessMask |= accessTable[0];
- if (mode & 00002) accessMask |= accessTable[1];
- if (mode & 00001) accessMask |= accessTable[2];
+ if (mode & 00004) {
+ accessMask |= accessTable[0];
+ }
+ if (mode & 00002) {
+ accessMask |= accessTable[1];
+ }
+ if (mode & 00001) {
+ accessMask |= accessTable[2];
+ }
if (accessMask && !AddAccessAllowedAce(pACL, ACL_REVISION, accessMask,
- _pr_nt_sids.everyone)) {
+ _pr_nt_sids.everyone)) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
goto failed;
}
diff --git a/nsprpub/pr/src/md/windows/ntsem.c b/nsprpub/pr/src/md/windows/ntsem.c
index f36a145a9..757bc839e 100644
--- a/nsprpub/pr/src/md/windows/ntsem.c
+++ b/nsprpub/pr/src/md/windows/ntsem.c
@@ -12,38 +12,40 @@
#include "primpl.h"
-void
+void
_PR_MD_NEW_SEM(_MDSemaphore *md, PRUintn value)
{
md->sem = CreateSemaphore(NULL, value, 0x7fffffff, NULL);
}
-void
+void
_PR_MD_DESTROY_SEM(_MDSemaphore *md)
{
CloseHandle(md->sem);
}
-PRStatus
+PRStatus
_PR_MD_TIMED_WAIT_SEM(_MDSemaphore *md, PRIntervalTime ticks)
{
int rv;
rv = WaitForSingleObject(md->sem, PR_IntervalToMilliseconds(ticks));
- if (rv == WAIT_OBJECT_0)
+ if (rv == WAIT_OBJECT_0) {
return PR_SUCCESS;
- else
+ }
+ else {
return PR_FAILURE;
+ }
}
-PRStatus
+PRStatus
_PR_MD_WAIT_SEM(_MDSemaphore *md)
{
return _PR_MD_TIMED_WAIT_SEM(md, PR_INTERVAL_NO_TIMEOUT);
}
-void
+void
_PR_MD_POST_SEM(_MDSemaphore *md)
{
ReleaseSemaphore(md->sem, 1, NULL);
diff --git a/nsprpub/pr/src/md/windows/ntthread.c b/nsprpub/pr/src/md/windows/ntthread.c
index 1fdf0e93b..395a80dcc 100644
--- a/nsprpub/pr/src/md/windows/ntthread.c
+++ b/nsprpub/pr/src/md/windows/ntthread.c
@@ -109,8 +109,8 @@ _PR_MD_EARLY_INIT()
if (hModule) {
sSetThreadDescription =
(SETTHREADDESCRIPTION) GetProcAddress(
- hModule,
- "SetThreadDescription");
+ hModule,
+ "SetThreadDescription");
}
}
@@ -147,13 +147,13 @@ _PR_MD_INIT_THREAD(PRThread *thread)
** the pseudo handle via DuplicateHandle(...)
*/
DuplicateHandle(
- GetCurrentProcess(), /* Process of source handle */
- GetCurrentThread(), /* Pseudo Handle to dup */
- GetCurrentProcess(), /* Process of handle */
- &(thread->md.handle), /* resulting handle */
- 0L, /* access flags */
- FALSE, /* Inheritable */
- DUPLICATE_SAME_ACCESS); /* Options */
+ GetCurrentProcess(), /* Process of source handle */
+ GetCurrentThread(), /* Pseudo Handle to dup */
+ GetCurrentProcess(), /* Process of handle */
+ &(thread->md.handle), /* resulting handle */
+ 0L, /* access flags */
+ FALSE, /* Inheritable */
+ DUPLICATE_SAME_ACCESS); /* Options */
}
/* Create the blocking IO semaphore */
@@ -161,13 +161,13 @@ _PR_MD_INIT_THREAD(PRThread *thread)
if (thread->md.blocked_sema == NULL) {
return PR_FAILURE;
}
- if (_native_threads_only) {
- /* Create the blocking IO semaphore */
- thread->md.thr_event = CreateEvent(NULL, TRUE, FALSE, NULL);
- if (thread->md.thr_event == NULL) {
- return PR_FAILURE;
- }
- }
+ if (_native_threads_only) {
+ /* Create the blocking IO semaphore */
+ thread->md.thr_event = CreateEvent(NULL, TRUE, FALSE, NULL);
+ if (thread->md.thr_event == NULL) {
+ return PR_FAILURE;
+ }
+ }
}
return PR_SUCCESS;
@@ -181,23 +181,23 @@ pr_root(void *arg)
return 0;
}
-PRStatus
-_PR_MD_CREATE_THREAD(PRThread *thread,
- void (*start)(void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+PRStatus
+_PR_MD_CREATE_THREAD(PRThread *thread,
+ void (*start)(void *),
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize)
{
thread->md.start = start;
thread->md.handle = (HANDLE) _beginthreadex(
- NULL,
- thread->stack->stackSize,
- pr_root,
- (void *)thread,
- CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION,
- &(thread->id));
+ NULL,
+ thread->stack->stackSize,
+ pr_root,
+ (void *)thread,
+ CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION,
+ &(thread->id));
if(!thread->md.handle) {
PRErrorCode prerror;
thread->md.fiber_last_error = GetLastError();
@@ -228,8 +228,9 @@ _PR_MD_CREATE_THREAD(PRThread *thread,
}
/* Activate the thread */
- if ( ResumeThread( thread->md.handle ) != -1)
+ if ( ResumeThread( thread->md.handle ) != -1) {
return PR_SUCCESS;
+ }
PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
return PR_FAILURE;
@@ -250,14 +251,14 @@ _PR_MD_END_THREAD(void)
_endthreadex(0);
}
-void
+void
_PR_MD_YIELD(void)
{
/* Can NT really yield at all? */
Sleep(0);
}
-void
+void
_PR_MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
{
int nativePri;
@@ -284,8 +285,8 @@ _PR_MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
rv = SetThreadPriority(thread->handle, nativePri);
PR_ASSERT(rv);
if (!rv) {
- PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("PR_SetThreadPriority: can't set thread priority\n"));
+ PR_LOG(_pr_thread_lm, PR_LOG_MIN,
+ ("PR_SetThreadPriority: can't set thread priority\n"));
}
return;
}
@@ -295,10 +296,10 @@ const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
- DWORD dwType; // Must be 0x1000.
- LPCSTR szName; // Pointer to name (in user addr space).
- DWORD dwThreadID; // Thread ID (-1=caller thread).
- DWORD dwFlags; // Reserved for future use, must be zero.
+ DWORD dwType; // Must be 0x1000.
+ LPCSTR szName; // Pointer to name (in user addr space).
+ DWORD dwThreadID; // Thread ID (-1=caller thread).
+ DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
#pragma pack(pop)
@@ -306,32 +307,33 @@ void
_PR_MD_SET_CURRENT_THREAD_NAME(const char *name)
{
#ifdef _MSC_VER
- THREADNAME_INFO info;
+ THREADNAME_INFO info;
#endif
- if (sSetThreadDescription) {
- WCHAR wideName[MAX_PATH];
- if (MultiByteToWideChar(CP_ACP, 0, name, -1, wideName, MAX_PATH)) {
- sSetThreadDescription(GetCurrentThread(), wideName);
- }
- }
+ if (sSetThreadDescription) {
+ WCHAR wideName[MAX_PATH];
+ if (MultiByteToWideChar(CP_ACP, 0, name, -1, wideName, MAX_PATH)) {
+ sSetThreadDescription(GetCurrentThread(), wideName);
+ }
+ }
#ifdef _MSC_VER
- if (!IsDebuggerPresent())
- return;
-
- info.dwType = 0x1000;
- info.szName = (char*) name;
- info.dwThreadID = -1;
- info.dwFlags = 0;
-
- __try {
- RaiseException(MS_VC_EXCEPTION,
- 0,
- sizeof(info) / sizeof(ULONG_PTR),
- (ULONG_PTR*)&info);
- } __except(EXCEPTION_CONTINUE_EXECUTION) {
- }
+ if (!IsDebuggerPresent()) {
+ return;
+ }
+
+ info.dwType = 0x1000;
+ info.szName = (char*) name;
+ info.dwThreadID = -1;
+ info.dwFlags = 0;
+
+ __try {
+ RaiseException(MS_VC_EXCEPTION,
+ 0,
+ sizeof(info) / sizeof(ULONG_PTR),
+ (ULONG_PTR*)&info);
+ } __except(EXCEPTION_CONTINUE_EXECUTION) {
+ }
#endif
}
@@ -353,13 +355,13 @@ _PR_MD_CLEAN_THREAD(PRThread *thread)
PR_ASSERT(rv);
thread->md.blocked_sema = 0;
}
- if (_native_threads_only) {
- if (thread->md.thr_event) {
- rv = CloseHandle(thread->md.thr_event);
- PR_ASSERT(rv);
- thread->md.thr_event = 0;
- }
- }
+ if (_native_threads_only) {
+ if (thread->md.thr_event) {
+ rv = CloseHandle(thread->md.thr_event);
+ PR_ASSERT(rv);
+ thread->md.thr_event = 0;
+ }
+ }
if (thread->md.handle) {
rv = CloseHandle(thread->md.handle);
@@ -399,13 +401,13 @@ _PR_MD_EXIT_THREAD(PRThread *thread)
thread->md.blocked_sema = 0;
}
- if (_native_threads_only) {
- if (thread->md.thr_event) {
- rv = CloseHandle(thread->md.thr_event);
- PR_ASSERT(rv);
- thread->md.thr_event = 0;
- }
- }
+ if (_native_threads_only) {
+ if (thread->md.thr_event) {
+ rv = CloseHandle(thread->md.thr_event);
+ PR_ASSERT(rv);
+ thread->md.thr_event = 0;
+ }
+ }
if (thread->md.handle) {
rv = CloseHandle(thread->md.handle);
@@ -428,7 +430,7 @@ _PR_MD_EXIT(PRIntn status)
#ifdef HAVE_FIBERS
void
-_pr_fiber_mainline(void *unused)
+_pr_fiber_mainline(void *unused)
{
PRThread *fiber = _PR_MD_CURRENT_THREAD();
@@ -445,7 +447,7 @@ PRThread *_PR_MD_CREATE_USER_THREAD(
if ( (thread = PR_NEW(PRThread)) == NULL ) {
return NULL;
}
-
+
memset(thread, 0, sizeof(PRThread));
thread->md.fiber_fn = start;
thread->md.fiber_arg = arg;
@@ -468,10 +470,11 @@ void
_PR_MD_INIT_CONTEXT(PRThread *thread, char *top, void (*start) (void), PRBool *status)
{
thread->md.fiber_fn = (void (*)(void *))start;
- thread->md.fiber_id = CreateFiber(thread->md.fiber_stacksize,
- (LPFIBER_START_ROUTINE)_pr_fiber_mainline, NULL);
- if (thread->md.fiber_id != 0)
+ thread->md.fiber_id = CreateFiber(thread->md.fiber_stacksize,
+ (LPFIBER_START_ROUTINE)_pr_fiber_mainline, NULL);
+ if (thread->md.fiber_id != 0) {
*status = PR_TRUE;
+ }
else {
DWORD oserror = GetLastError();
PRErrorCode prerror;
@@ -502,7 +505,7 @@ _PR_MD_RESTORE_CONTEXT(PRThread *thread)
PR_ASSERT( !_PR_IS_NATIVE_THREAD(thread) );
/* The user-level code for yielding will happily add ourselves to the runq
- * and then switch to ourselves; the NT fibers can't handle switching to
+ * and then switch to ourselves; the NT fibers can't handle switching to
* ourselves.
*/
if (thread != me) {
@@ -532,12 +535,12 @@ PRInt32 _PR_MD_GETTHREADAFFINITYMASK(PRThread *thread, PRUint32 *mask)
PRInt32 rv, system_mask;
rv = GetProcessAffinityMask(GetCurrentProcess(), mask, &system_mask);
-
+
return rv?0:-1;
}
-void
-_PR_MD_SUSPEND_CPU(_PRCPU *cpu)
+void
+_PR_MD_SUSPEND_CPU(_PRCPU *cpu)
{
_PR_MD_SUSPEND_THREAD(cpu->thread);
}
@@ -573,15 +576,15 @@ _PR_MD_RESUME_THREAD(PRThread *thread)
PRThread*
_MD_CURRENT_THREAD(void)
{
-PRThread *thread;
+ PRThread *thread;
- thread = _MD_GET_ATTACHED_THREAD();
+ thread = _MD_GET_ATTACHED_THREAD();
- if (NULL == thread) {
- thread = _PRI_AttachThread(
- PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL, 0);
- }
- PR_ASSERT(thread != NULL);
- return thread;
+ if (NULL == thread) {
+ thread = _PRI_AttachThread(
+ PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL, 0);
+ }
+ PR_ASSERT(thread != NULL);
+ return thread;
}
diff --git a/nsprpub/pr/src/md/windows/w32ipcsem.c b/nsprpub/pr/src/md/windows/w32ipcsem.c
index 954591002..500009352 100644
--- a/nsprpub/pr/src/md/windows/w32ipcsem.c
+++ b/nsprpub/pr/src/md/windows/w32ipcsem.c
@@ -18,17 +18,19 @@ static HANDLE OpenSemaphore(DWORD inDesiredAccess,
HANDLE retval = NULL;
HANDLE semaphore = NULL;
PRUnichar wideName[MAX_PATH]; /* name size is limited to MAX_PATH */
-
+
MultiByteToWideChar(CP_ACP, 0, inName, -1, wideName, MAX_PATH);
/* 0x7fffffff is the max count for our semaphore */
semaphore = CreateSemaphoreW(NULL, 0, 0x7fffffff, wideName);
if (NULL != semaphore) {
DWORD lastErr = GetLastError();
-
- if (ERROR_ALREADY_EXISTS != lastErr)
+
+ if (ERROR_ALREADY_EXISTS != lastErr) {
CloseHandle(semaphore);
- else
+ }
+ else {
retval = semaphore;
+ }
}
return retval;
}
@@ -97,8 +99,8 @@ static DWORD FiberSafeWaitForSingleObject(
warg.handle = hHandle;
warg.timeout = dwMilliseconds;
waitThread = PR_CreateThread(
- PR_USER_THREAD, WaitSingleThread, &warg,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, WaitSingleThread, &warg,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
if (waitThread == NULL) {
return WAIT_FAILED;
}
@@ -133,7 +135,7 @@ PRSem *_PR_MD_OPEN_SEMAPHORE(
}
if (flags & PR_SEM_CREATE) {
if (_PR_NT_MakeSecurityDescriptorACL(mode, semAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
@@ -142,7 +144,7 @@ PRSem *_PR_MD_OPEN_SEMAPHORE(
#ifdef WINCE
{
/* The size of a sem's name is limited to MAX_PATH. */
- PRUnichar wosname[MAX_PATH];
+ PRUnichar wosname[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, osname, -1, wosname, MAX_PATH);
sem->sem = CreateSemaphoreW(lpSA, value, 0x7fffffff, wosname);
}
@@ -165,7 +167,7 @@ PRSem *_PR_MD_OPEN_SEMAPHORE(
}
} else {
sem->sem = OpenSemaphore(
- SEMAPHORE_MODIFY_STATE|SYNCHRONIZE, FALSE, osname);
+ SEMAPHORE_MODIFY_STATE|SYNCHRONIZE, FALSE, osname);
if (sem->sem == NULL) {
DWORD err = GetLastError();
diff --git a/nsprpub/pr/src/md/windows/w32poll.c b/nsprpub/pr/src/md/windows/w32poll.c
index daf14dfe0..241c7e3e4 100644
--- a/nsprpub/pr/src/md/windows/w32poll.c
+++ b/nsprpub/pr/src/md/windows/w32poll.c
@@ -62,13 +62,17 @@ int _PR_NTFiberSafeSelect(
data.tv = timeout;
selectThread = PR_CreateThread(
- PR_USER_THREAD, _PR_MD_select_thread, &data,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
- if (selectThread == NULL) return -1;
+ PR_USER_THREAD, _PR_MD_select_thread, &data,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ if (selectThread == NULL) {
+ return -1;
+ }
PR_JoinThread(selectThread);
ready = data.status;
- if (ready == SOCKET_ERROR) WSASetLastError(data.error);
+ if (ready == SOCKET_ERROR) {
+ WSASetLastError(data.error);
+ }
}
return ready;
}
@@ -120,17 +124,17 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
if (pd->in_flags & PR_POLL_READ)
{
in_flags_read = (pd->fd->methods->poll)(
- pd->fd, (PRInt16)(pd->in_flags & ~PR_POLL_WRITE),
- &out_flags_read);
+ pd->fd, (PRInt16)(pd->in_flags & ~PR_POLL_WRITE),
+ &out_flags_read);
}
if (pd->in_flags & PR_POLL_WRITE)
{
in_flags_write = (pd->fd->methods->poll)(
- pd->fd, (PRInt16)(pd->in_flags & ~PR_POLL_READ),
- &out_flags_write);
+ pd->fd, (PRInt16)(pd->in_flags & ~PR_POLL_READ),
+ &out_flags_write);
}
if ((0 != (in_flags_read & out_flags_read))
- || (0 != (in_flags_write & out_flags_write)))
+ || (0 != (in_flags_write & out_flags_write)))
{
/* this one's ready right now (buffered input) */
if (0 == ready)
@@ -158,7 +162,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
/* ignore a socket without PR_NSPR_IO_LAYER available */
if ((NULL != bottom)
- && (_PR_FILEDESC_OPEN == bottom->secret->state))
+ && (_PR_FILEDESC_OPEN == bottom->secret->state))
{
if (0 == ready)
{
@@ -214,7 +218,9 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
}
}
- if (0 != ready) return ready; /* no need to block */
+ if (0 != ready) {
+ return ready; /* no need to block */
+ }
/*
* FD_SET does nothing if the fd_set's internal fd_array is full. If
@@ -271,22 +277,30 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
if (FD_ISSET(osfd, &rd))
{
- if (pd->out_flags & _PR_POLL_READ_SYS_READ)
+ if (pd->out_flags & _PR_POLL_READ_SYS_READ) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_READ)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_READ) {
out_flags |= PR_POLL_WRITE;
- }
+ }
+ }
if (FD_ISSET(osfd, &wt))
{
- if (pd->out_flags & _PR_POLL_READ_SYS_WRITE)
+ if (pd->out_flags & _PR_POLL_READ_SYS_WRITE) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE) {
out_flags |= PR_POLL_WRITE;
- }
- if (FD_ISSET(osfd, &ex)) out_flags |= PR_POLL_EXCEPT;
+ }
+ }
+ if (FD_ISSET(osfd, &ex)) {
+ out_flags |= PR_POLL_EXCEPT;
+ }
}
pd->out_flags = out_flags;
- if (out_flags) ready++;
+ if (out_flags) {
+ ready++;
+ }
}
PR_ASSERT(ready > 0);
}
@@ -306,7 +320,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
{
bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
if (getsockopt(bottom->secret->md.osfd, SOL_SOCKET,
- SO_TYPE, (char *) &optval, &optlen) == -1)
+ SO_TYPE, (char *) &optval, &optlen) == -1)
{
PR_ASSERT(WSAGetLastError() == WSAENOTSOCK);
if (WSAGetLastError() == WSAENOTSOCK)
@@ -319,7 +333,9 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
}
PR_ASSERT(ready > 0);
}
- else _PR_MD_MAP_SELECT_ERROR(err);
+ else {
+ _PR_MD_MAP_SELECT_ERROR(err);
+ }
}
return ready;
diff --git a/nsprpub/pr/src/md/windows/w32rng.c b/nsprpub/pr/src/md/windows/w32rng.c
index 633ae0da5..c07625ecc 100644
--- a/nsprpub/pr/src/md/windows/w32rng.c
+++ b/nsprpub/pr/src/md/windows/w32rng.c
@@ -16,8 +16,9 @@ CurrentClockTickTime(LPDWORD lpdwHigh, LPDWORD lpdwLow)
{
LARGE_INTEGER liCount;
- if (!QueryPerformanceCounter(&liCount))
+ if (!QueryPerformanceCounter(&liCount)) {
return FALSE;
+ }
*lpdwHigh = liCount.u.HighPart;
*lpdwLow = liCount.u.LowPart;
@@ -31,8 +32,9 @@ extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size )
size_t nBytes;
time_t sTime;
- if (size <= 0)
+ if (size <= 0) {
return 0;
+ }
CurrentClockTickTime(&dwHigh, &dwLow);
@@ -42,16 +44,18 @@ extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size )
n += nBytes;
size -= nBytes;
- if (size <= 0)
+ if (size <= 0) {
return n;
+ }
nBytes = sizeof(dwHigh) > size ? size : sizeof(dwHigh);
memcpy(((char *)buf) + n, &dwHigh, nBytes);
n += nBytes;
size -= nBytes;
- if (size <= 0)
+ if (size <= 0) {
return n;
+ }
// get the number of milliseconds that have elapsed since Windows started
dwVal = GetTickCount();
@@ -61,8 +65,9 @@ extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size )
n += nBytes;
size -= nBytes;
- if (size <= 0)
+ if (size <= 0) {
return n;
+ }
// get the time in seconds since midnight Jan 1, 1970
time(&sTime);
diff --git a/nsprpub/pr/src/md/windows/w32shm.c b/nsprpub/pr/src/md/windows/w32shm.c
index 8e8b1d684..b0d38b9d7 100644
--- a/nsprpub/pr/src/md/windows/w32shm.c
+++ b/nsprpub/pr/src/md/windows/w32shm.c
@@ -3,7 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include <private/primpl.h>
+#include <private/primpl.h>
#include <string.h>
#include <prshm.h>
#include <prerr.h>
@@ -23,15 +23,15 @@ extern PRLogModuleInfo *_pr_shm_lm;
*/
static DWORD filemapAccessTable[] = {
FILE_MAP_ALL_ACCESS & ~FILE_MAP_WRITE, /* read */
- FILE_MAP_ALL_ACCESS & ~FILE_MAP_READ, /* write */
+ FILE_MAP_ALL_ACCESS & ~FILE_MAP_READ, /* write */
0 /* execute */
};
-extern PRSharedMemory * _MD_OpenSharedMemory(
- const char *name,
- PRSize size,
- PRIntn flags,
- PRIntn mode
+extern PRSharedMemory * _MD_OpenSharedMemory(
+ const char *name,
+ PRSize size,
+ PRIntn flags,
+ PRIntn mode
)
{
char ipcname[PR_IPC_NAME_SIZE];
@@ -48,15 +48,15 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
if ( PR_FAILURE == rc )
{
PR_SetError(PR_UNKNOWN_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: name is invalid"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: name is invalid"));
return(NULL);
}
shm = PR_NEWZAP( PRSharedMemory );
- if ( NULL == shm )
+ if ( NULL == shm )
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory"));
return(NULL);
}
@@ -64,14 +64,14 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
if ( NULL == shm->ipcname )
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory"));
PR_DELETE(shm);
return(NULL);
}
/* copy args to struct */
strcpy( shm->ipcname, ipcname );
- shm->size = size;
+ shm->size = size;
shm->mode = mode;
shm->flags = flags;
shm->ident = _PR_SHM_IDENT;
@@ -81,7 +81,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
dwLo = (DWORD) (shm->size & 0xffffffff);
if (_PR_NT_MakeSecurityDescriptorACL(mode, filemapAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
@@ -97,48 +97,48 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
MultiByteToWideChar(CP_ACP, 0, shm->ipcname, -1,
wideIpcName, MAX_PATH);
shm->handle = CreateFileMappingW(
- (HANDLE)-1 ,
- lpSA,
- flProtect,
- dwHi,
- dwLo,
- wideIpcName);
+ (HANDLE)-1,
+ lpSA,
+ flProtect,
+ dwHi,
+ dwLo,
+ wideIpcName);
}
#else
shm->handle = CreateFileMappingA(
- (HANDLE)-1 ,
- lpSA,
- flProtect,
- dwHi,
- dwLo,
- shm->ipcname);
+ (HANDLE)-1,
+ lpSA,
+ flProtect,
+ dwHi,
+ dwLo,
+ shm->ipcname);
#endif
if (lpSA != NULL) {
_PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
}
if ( NULL == shm->handle ) {
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: CreateFileMapping() failed: %s",
- shm->ipcname ));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ( "PR_OpenSharedMemory: CreateFileMapping() failed: %s",
+ shm->ipcname ));
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
PR_FREEIF( shm->ipcname )
PR_DELETE( shm );
return(NULL);
} else {
if (( flags & PR_SHM_EXCL) && ( GetLastError() == ERROR_ALREADY_EXISTS )) {
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: Request exclusive & already exists",
- shm->ipcname ));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ( "PR_OpenSharedMemory: Request exclusive & already exists",
+ shm->ipcname ));
PR_SetError( PR_FILE_EXISTS_ERROR, ERROR_ALREADY_EXISTS );
CloseHandle( shm->handle );
PR_FREEIF( shm->ipcname )
PR_DELETE( shm );
return(NULL);
} else {
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: CreateFileMapping() success: %s, handle: %d",
- shm->ipcname, shm->handle ));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ( "PR_OpenSharedMemory: CreateFileMapping() success: %s, handle: %d",
+ shm->ipcname, shm->handle ));
return(shm);
}
}
@@ -151,17 +151,17 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
#endif
if ( NULL == shm->handle ) {
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: OpenFileMapping() failed: %s, error: %d",
- shm->ipcname, PR_GetOSError()));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ( "PR_OpenSharedMemory: OpenFileMapping() failed: %s, error: %d",
+ shm->ipcname, PR_GetOSError()));
PR_FREEIF( shm->ipcname );
PR_DELETE( shm );
return(NULL);
} else {
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: OpenFileMapping() success: %s, handle: %d",
- shm->ipcname, shm->handle ));
- return(shm);
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ( "PR_OpenSharedMemory: OpenFileMapping() success: %s, handle: %d",
+ shm->ipcname, shm->handle ));
+ return(shm);
}
}
/* returns from separate paths */
@@ -174,18 +174,19 @@ extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags )
PR_ASSERT( shm->ident == _PR_SHM_IDENT );
- if ( PR_SHM_READONLY & flags )
+ if ( PR_SHM_READONLY & flags ) {
access = FILE_MAP_READ;
+ }
addr = MapViewOfFile( shm->handle,
- access,
- 0, 0,
- shm->size );
+ access,
+ 0, 0,
+ shm->size );
if ( NULL == addr ) {
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
- PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
- ("_MD_AttachSharedMemory: MapViewOfFile() failed. OSerror: %d", PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
+ ("_MD_AttachSharedMemory: MapViewOfFile() failed. OSerror: %d", PR_GetOSError()));
}
return( addr );
@@ -200,11 +201,11 @@ extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr )
PR_ASSERT( shm->ident == _PR_SHM_IDENT );
wrc = UnmapViewOfFile( addr );
- if ( FALSE == wrc )
+ if ( FALSE == wrc )
{
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
- PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
- ("_MD_DetachSharedMemory: UnmapViewOfFile() failed. OSerror: %d", PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
+ ("_MD_DetachSharedMemory: UnmapViewOfFile() failed. OSerror: %d", PR_GetOSError()));
rc = PR_FAILURE;
}
@@ -223,8 +224,8 @@ extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm )
if ( FALSE == wrc )
{
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
- PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
- ("_MD_CloseSharedMemory: CloseHandle() failed. OSerror: %d", PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
+ ("_MD_CloseSharedMemory: CloseHandle() failed. OSerror: %d", PR_GetOSError()));
rc = PR_FAILURE;
}
PR_FREEIF( shm->ipcname );
@@ -236,7 +237,7 @@ extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm )
extern PRStatus _MD_DeleteSharedMemory( const char *name )
{
return( PR_SUCCESS );
-}
+}
/*
@@ -244,7 +245,7 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name )
*/
extern PRLogModuleInfo *_pr_shma_lm;
-extern PRFileMap* _md_OpenAnonFileMap(
+extern PRFileMap* _md_OpenAnonFileMap(
const char *dirName,
PRSize size,
PRFileMapProtect prot
@@ -256,7 +257,7 @@ extern PRFileMap* _md_OpenAnonFileMap(
fm = PR_CreateFileMap( (PRFileDesc*)-1, size, prot );
if ( NULL == fm ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): PR_CreateFileMap(): failed"));
+ ("_md_OpenAnonFileMap(): PR_CreateFileMap(): failed"));
goto Finished;
}
@@ -267,12 +268,12 @@ extern PRFileMap* _md_OpenAnonFileMap(
** ERROR_CALL_NOT_IMPLEMENTED on Win95.
*/
if (DuplicateHandle(GetCurrentProcess(), fm->md.hFileMap,
- GetCurrentProcess(), &hFileMap,
- 0, TRUE /* inheritable */,
- DUPLICATE_SAME_ACCESS) == FALSE) {
+ GetCurrentProcess(), &hFileMap,
+ 0, TRUE /* inheritable */,
+ DUPLICATE_SAME_ACCESS) == FALSE) {
PR_SetError( PR_UNKNOWN_ERROR, GetLastError() );
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): DuplicateHandle(): failed"));
+ ("_md_OpenAnonFileMap(): DuplicateHandle(): failed"));
PR_CloseFileMap( fm );
fm = NULL;
goto Finished;
@@ -280,7 +281,7 @@ extern PRFileMap* _md_OpenAnonFileMap(
CloseHandle(fm->md.hFileMap);
fm->md.hFileMap = hFileMap;
-Finished:
+Finished:
return(fm);
} /* end md_OpenAnonFileMap() */
@@ -297,12 +298,12 @@ extern PRStatus _md_ExportFileMapAsString(
PRIntn written;
written = PR_snprintf( buf, (PRUint32) bufSize, "%d:%" PR_PRIdOSFD ":%ld",
- (PRIntn)fm->prot, (PROsfd)fm->md.hFileMap, (PRInt32)fm->md.dwAccess );
+ (PRIntn)fm->prot, (PROsfd)fm->md.hFileMap, (PRInt32)fm->md.dwAccess );
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_ExportFileMapAsString(): prot: %x, hFileMap: %x, dwAccess: %x",
- fm->prot, fm->md.hFileMap, fm->md.dwAccess ));
-
+ ("_md_ExportFileMapAsString(): prot: %x, hFileMap: %x, dwAccess: %x",
+ fm->prot, fm->md.hFileMap, fm->md.dwAccess ));
+
return((written == -1)? PR_FAILURE : PR_SUCCESS);
} /* end _md_ExportFileMapAsString() */
@@ -321,12 +322,12 @@ extern PRFileMap * _md_ImportFileMapFromString(
PRFileMap *fm = NULL;
PR_sscanf( fmstring, "%d:%" PR_SCNdOSFD ":%ld",
- &prot, &hFileMap, &dwAccess );
+ &prot, &hFileMap, &dwAccess );
fm = PR_NEWZAP(PRFileMap);
if ( NULL == fm ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_ImportFileMapFromString(): PR_NEWZAP(): Failed"));
+ ("_md_ImportFileMapFromString(): PR_NEWZAP(): Failed"));
return(fm);
}
@@ -336,12 +337,12 @@ extern PRFileMap * _md_ImportFileMapFromString(
fm->fd = (PRFileDesc*)-1;
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_ImportFileMapFromString(): fm: %p, prot: %d, hFileMap: %8.8x, dwAccess: %8.8x, fd: %x",
- fm, prot, fm->md.hFileMap, fm->md.dwAccess, fm->fd));
+ ("_md_ImportFileMapFromString(): fm: %p, prot: %d, hFileMap: %8.8x, dwAccess: %8.8x, fd: %x",
+ fm, prot, fm->md.hFileMap, fm->md.dwAccess, fm->fd));
return(fm);
} /* end _md_ImportFileMapFromString() */
#else
-Error! Why is PR_HAVE_WIN32_NAMED_SHARED_MEMORY not defined?
+Error! Why is PR_HAVE_WIN32_NAMED_SHARED_MEMORY not defined?
#endif /* PR_HAVE_WIN32_NAMED_SHARED_MEMORY */
/* --- end w32shm.c --- */
diff --git a/nsprpub/pr/src/md/windows/w95cv.c b/nsprpub/pr/src/md/windows/w95cv.c
index 27b34e691..5cf2966ff 100644
--- a/nsprpub/pr/src/md/windows/w95cv.c
+++ b/nsprpub/pr/src/md/windows/w95cv.c
@@ -16,7 +16,7 @@
* until right after we unlock the lock. This way the awakened threads
* have a better chance to reaquire the lock.
*/
-
+
#include "primpl.h"
/*
@@ -30,7 +30,7 @@ static void
AddThreadToCVWaitQueueInternal(PRThread *thred, struct _MDCVar *cv)
{
PR_ASSERT((cv->waitTail != NULL && cv->waitHead != NULL)
- || (cv->waitTail == NULL && cv->waitHead == NULL));
+ || (cv->waitTail == NULL && cv->waitHead == NULL));
cv->nwait += 1;
thred->md.inCVWaitQueue = PR_TRUE;
thred->md.next = NULL;
@@ -78,7 +78,7 @@ md_UnlockAndPostNotifies(
lock->notified.link = NULL;
#endif
- /*
+ /*
* Figure out how many threads we need to wake up.
*/
notified = &post; /* this is where we start */
@@ -87,7 +87,7 @@ md_UnlockAndPostNotifies(
_MDCVar *cv = notified->cv[index].cv;
PRThread *thred;
int i;
-
+
/* Fast special case: no waiting threads */
if (cv->waitHead == NULL) {
notified->cv[index].notifyHead = NULL;
@@ -134,7 +134,7 @@ md_UnlockAndPostNotifies(
}
/* Release the lock before notifying */
- LeaveCriticalSection(&lock->mutex);
+ LeaveCriticalSection(&lock->mutex);
notified = &post; /* this is where we start */
do {
@@ -156,7 +156,9 @@ md_UnlockAndPostNotifies(
}
prev = notified;
notified = notified->link;
- if (&post != prev) PR_DELETE(prev);
+ if (&post != prev) {
+ PR_DELETE(prev);
+ }
} while (NULL != notified);
}
@@ -166,7 +168,7 @@ md_UnlockAndPostNotifies(
* MP systems don't contend for a lock that they can't have.
*/
static void md_PostNotifyToCvar(_MDCVar *cvar, _MDLock *lock,
- PRBool broadcast)
+ PRBool broadcast)
{
PRIntn index = 0;
_MDNotified *notified = &lock->notified;
@@ -183,7 +185,9 @@ static void md_PostNotifyToCvar(_MDCVar *cvar, _MDLock *lock,
}
}
/* if not full, enter new CV in this array */
- if (notified->length < _MD_CV_NOTIFIED_LENGTH) break;
+ if (notified->length < _MD_CV_NOTIFIED_LENGTH) {
+ break;
+ }
/* if there's no link, create an empty array and link it */
if (NULL == notified->link) {
@@ -207,7 +211,7 @@ static void md_PostNotifyToCvar(_MDCVar *cvar, _MDLock *lock,
* 0 when it succeeds.
*
*/
-PRInt32
+PRInt32
_PR_MD_NEW_CV(_MDCVar *cv)
{
cv->magic = _MD_MAGIC_CV;
@@ -216,7 +220,7 @@ _PR_MD_NEW_CV(_MDCVar *cv)
* when the PRCondVar structure is created.
*/
return 0;
-}
+}
void _PR_MD_FREE_CV(_MDCVar *cv)
{
@@ -232,7 +236,7 @@ void _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout )
PRThread *thred = _PR_MD_CURRENT_THREAD();
DWORD rv;
DWORD msecs = (timeout == PR_INTERVAL_NO_TIMEOUT) ?
- INFINITE : PR_IntervalToMilliseconds(timeout);
+ INFINITE : PR_IntervalToMilliseconds(timeout);
/*
* If we have pending notifies, post them now.
@@ -256,7 +260,7 @@ void _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout )
if (rv == WAIT_TIMEOUT) {
if (thred->md.inCVWaitQueue) {
PR_ASSERT((cv->waitTail != NULL && cv->waitHead != NULL)
- || (cv->waitTail == NULL && cv->waitHead == NULL));
+ || (cv->waitTail == NULL && cv->waitHead == NULL));
cv->nwait -= 1;
thred->md.inCVWaitQueue = PR_FALSE;
if (cv->waitHead == thred) {
@@ -325,7 +329,7 @@ void _PR_MD_INIT_LOCKS(void)
PR_ASSERT(hKernel32);
PR_ASSERT(!sInitializeCriticalSectionEx);
sInitializeCriticalSectionEx = (INITIALIZECRITICALSECTIONEX)
- GetProcAddress(hKernel32, "InitializeCriticalSectionEx");
+ GetProcAddress(hKernel32, "InitializeCriticalSectionEx");
}
/*
diff --git a/nsprpub/pr/src/md/windows/w95dllmain.c b/nsprpub/pr/src/md/windows/w95dllmain.c
index 73707a6e1..c9ab87aec 100644
--- a/nsprpub/pr/src/md/windows/w95dllmain.c
+++ b/nsprpub/pr/src/md/windows/w95dllmain.c
@@ -18,7 +18,7 @@ BOOL WINAPI DllMain(
DWORD fdwReason,
LPVOID lpvReserved)
{
-PRThread *me;
+ PRThread *me;
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
@@ -28,8 +28,9 @@ PRThread *me;
case DLL_THREAD_DETACH:
if (_pr_initialized) {
me = _MD_GET_ATTACHED_THREAD();
- if ((me != NULL) && (me->flags & _PR_ATTACHED))
+ if ((me != NULL) && (me->flags & _PR_ATTACHED)) {
_PRI_DetachThread();
+ }
}
break;
case DLL_PROCESS_DETACH:
diff --git a/nsprpub/pr/src/md/windows/w95io.c b/nsprpub/pr/src/md/windows/w95io.c
index 9bae6f8df..2ad52e19b 100644
--- a/nsprpub/pr/src/md/windows/w95io.c
+++ b/nsprpub/pr/src/md/windows/w95io.c
@@ -53,8 +53,8 @@ _PR_MD_INIT_IO()
{
SYSTEMTIME systime;
union {
- PRTime prt;
- FILETIME ft;
+ PRTime prt;
+ FILETIME ft;
} filetime;
BOOL rv;
@@ -84,16 +84,16 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
DWORD rv;
PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
- INFINITE : PR_IntervalToMilliseconds(ticks);
+ INFINITE : PR_IntervalToMilliseconds(ticks);
rv = WaitForSingleObject(thread->md.blocked_sema, msecs);
- switch(rv)
+ switch(rv)
{
case WAIT_OBJECT_0:
return PR_SUCCESS;
case WAIT_TIMEOUT:
_PR_THREAD_LOCK(thread);
if (thread->state == _PR_IO_WAIT) {
- ;
+ ;
} else {
if (thread->wait.cvar != NULL) {
thread->wait.cvar = NULL;
@@ -116,13 +116,15 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
PRStatus
_PR_MD_WAKEUP_WAITER(PRThread *thread)
{
- if ( _PR_IS_NATIVE_THREAD(thread) )
+ if ( _PR_IS_NATIVE_THREAD(thread) )
{
- if (ReleaseSemaphore(thread->md.blocked_sema, 1, NULL) == FALSE)
+ if (ReleaseSemaphore(thread->md.blocked_sema, 1, NULL) == FALSE) {
return PR_FAILURE;
- else
- return PR_SUCCESS;
- }
+ }
+ else {
+ return PR_SUCCESS;
+ }
+ }
}
@@ -135,7 +137,7 @@ _PR_MD_WAKEUP_WAITER(PRThread *thread)
* The NSPR open flags (osflags) are translated into flags for Win95
*
* Mode seems to be passed in as a unix style file permissions argument
- * as in 0666, in the case of opening the logFile.
+ * as in 0666, in the case of opening the logFile.
*
*/
PROsfd
@@ -145,26 +147,35 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
PRInt32 access = 0;
PRInt32 flags = 0;
PRInt32 flag6 = 0;
-
- if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
-
- if (osflags & PR_RDONLY || osflags & PR_RDWR)
+
+ if (osflags & PR_SYNC) {
+ flag6 = FILE_FLAG_WRITE_THROUGH;
+ }
+
+ if (osflags & PR_RDONLY || osflags & PR_RDWR) {
access |= GENERIC_READ;
- if (osflags & PR_WRONLY || osflags & PR_RDWR)
+ }
+ if (osflags & PR_WRONLY || osflags & PR_RDWR) {
access |= GENERIC_WRITE;
+ }
- if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
+ if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL ) {
flags = CREATE_NEW;
+ }
else if (osflags & PR_CREATE_FILE) {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = CREATE_ALWAYS;
- else
+ }
+ else {
flags = OPEN_ALWAYS;
+ }
} else {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = TRUNCATE_EXISTING;
- else
+ }
+ else {
flags = OPEN_EXISTING;
+ }
}
file = CreateFileA(name,
@@ -175,9 +186,9 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
flag6,
NULL);
if (file == INVALID_HANDLE_VALUE) {
- _PR_MD_MAP_OPEN_ERROR(GetLastError());
- return -1;
- }
+ _PR_MD_MAP_OPEN_ERROR(GetLastError());
+ return -1;
+ }
return (PROsfd)file;
}
@@ -196,33 +207,42 @@ _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, int mode)
if (osflags & PR_CREATE_FILE) {
if (_PR_NT_MakeSecurityDescriptorACL(mode, fileAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
lpSA = &sa;
}
}
-
- if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
-
- if (osflags & PR_RDONLY || osflags & PR_RDWR)
+
+ if (osflags & PR_SYNC) {
+ flag6 = FILE_FLAG_WRITE_THROUGH;
+ }
+
+ if (osflags & PR_RDONLY || osflags & PR_RDWR) {
access |= GENERIC_READ;
- if (osflags & PR_WRONLY || osflags & PR_RDWR)
+ }
+ if (osflags & PR_WRONLY || osflags & PR_RDWR) {
access |= GENERIC_WRITE;
+ }
- if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
+ if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL ) {
flags = CREATE_NEW;
+ }
else if (osflags & PR_CREATE_FILE) {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = CREATE_ALWAYS;
- else
+ }
+ else {
flags = OPEN_ALWAYS;
+ }
} else {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = TRUNCATE_EXISTING;
- else
+ }
+ else {
flags = OPEN_EXISTING;
+ }
}
file = CreateFileA(name,
@@ -236,9 +256,9 @@ _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, int mode)
_PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
}
if (file == INVALID_HANDLE_VALUE) {
- _PR_MD_MAP_OPEN_ERROR(GetLastError());
- return -1;
- }
+ _PR_MD_MAP_OPEN_ERROR(GetLastError());
+ return -1;
+ }
return (PROsfd)file;
}
@@ -250,22 +270,23 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
int rv, err;
rv = ReadFile((HANDLE)fd->secret->md.osfd,
- (LPVOID)buf,
- len,
- &bytes,
- NULL);
-
- if (rv == 0)
+ (LPVOID)buf,
+ len,
+ &bytes,
+ NULL);
+
+ if (rv == 0)
{
err = GetLastError();
/* ERROR_HANDLE_EOF can only be returned by async io */
PR_ASSERT(err != ERROR_HANDLE_EOF);
- if (err == ERROR_BROKEN_PIPE)
+ if (err == ERROR_BROKEN_PIPE) {
return 0;
- else {
- _PR_MD_MAP_READ_ERROR(err);
- return -1;
- }
+ }
+ else {
+ _PR_MD_MAP_READ_ERROR(err);
+ return -1;
+ }
}
return bytes;
}
@@ -276,16 +297,16 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
PROsfd f = fd->secret->md.osfd;
PRInt32 bytes;
int rv;
-
+
rv = WriteFile((HANDLE)f,
- buf,
- len,
- &bytes,
- NULL );
-
- if (rv == 0)
+ buf,
+ len,
+ &bytes,
+ NULL );
+
+ if (rv == 0)
{
- _PR_MD_MAP_WRITE_ERROR(GetLastError());
+ _PR_MD_MAP_WRITE_ERROR(GetLastError());
return -1;
}
return bytes;
@@ -348,7 +369,7 @@ _PR_MD_LSEEK64(PRFileDesc *fd, PROffset64 offset, PRSeekWhence whence)
li.QuadPart = offset;
li.LowPart = SetFilePointer((HANDLE)fd->secret->md.osfd,
- li.LowPart, &li.HighPart, moveMethod);
+ li.LowPart, &li.HighPart, moveMethod);
if (0xffffffff == li.LowPart && (err = GetLastError()) != NO_ERROR) {
_PR_MD_MAP_LSEEK_ERROR(err);
@@ -369,10 +390,10 @@ _PR_MD_FSYNC(PRFileDesc *fd)
/*
* From the documentation:
*
- * On Windows NT, the function FlushFileBuffers fails if hFile
- * is a handle to console output. That is because console
- * output is not buffered. The function returns FALSE, and
- * GetLastError returns ERROR_INVALID_HANDLE.
+ * On Windows NT, the function FlushFileBuffers fails if hFile
+ * is a handle to console output. That is because console
+ * output is not buffered. The function returns FALSE, and
+ * GetLastError returns ERROR_INVALID_HANDLE.
*
* On the other hand, on Win95, it returns without error. I cannot
* assume that 0, 1, and 2 are console, because if someone closes
@@ -386,11 +407,11 @@ _PR_MD_FSYNC(PRFileDesc *fd)
BOOL ok = FlushFileBuffers((HANDLE)fd->secret->md.osfd);
if (!ok) {
- DWORD err = GetLastError();
- if (err != ERROR_ACCESS_DENIED) { // from winerror.h
- _PR_MD_MAP_FSYNC_ERROR(err);
- return -1;
- }
+ DWORD err = GetLastError();
+ if (err != ERROR_ACCESS_DENIED) { // from winerror.h
+ _PR_MD_MAP_FSYNC_ERROR(err);
+ return -1;
+ }
}
return 0;
}
@@ -399,17 +420,18 @@ PRInt32
_MD_CloseFile(PROsfd osfd)
{
PRInt32 rv;
-
+
rv = (CloseHandle((HANDLE)osfd))?0:-1;
- if (rv == -1)
- _PR_MD_MAP_CLOSE_ERROR(GetLastError());
+ if (rv == -1) {
+ _PR_MD_MAP_CLOSE_ERROR(GetLastError());
+ }
return rv;
}
/* --- DIR IO ------------------------------------------------------------ */
#define GetFileFromDIR(d) (d)->d_entry.cFileName
-#define FileIsHidden(d) ((d)->d_entry.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
+#define FileIsHidden(d) ((d)->d_entry.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
static void FlipSlashes(char *cp, size_t len)
{
@@ -434,12 +456,12 @@ _PR_MD_CLOSE_DIR(_MDDir *d)
{
if ( d ) {
if (FindClose(d->d_hdl)) {
- d->magic = (PRUint32)-1;
- return 0;
- } else {
- _PR_MD_MAP_CLOSEDIR_ERROR(GetLastError());
- return -1;
- }
+ d->magic = (PRUint32)-1;
+ return 0;
+ } else {
+ _PR_MD_MAP_CLOSEDIR_ERROR(GetLastError());
+ return -1;
+ }
}
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return -1;
@@ -472,7 +494,7 @@ _PR_MD_OPEN_DIR(_MDDir *d, const char *name)
d->d_hdl = FindFirstFileA( filename, &(d->d_entry) );
if ( d->d_hdl == INVALID_HANDLE_VALUE ) {
- _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
+ _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
return PR_FAILURE;
}
d->firstEntry = PR_TRUE;
@@ -500,21 +522,24 @@ _PR_MD_READ_DIR(_MDDir *d, PRIntn flags)
}
fileName = GetFileFromDIR(d);
if ( (flags & PR_SKIP_DOT) &&
- (fileName[0] == '.') && (fileName[1] == '\0'))
- continue;
+ (fileName[0] == '.') && (fileName[1] == '\0')) {
+ continue;
+ }
if ( (flags & PR_SKIP_DOT_DOT) &&
(fileName[0] == '.') && (fileName[1] == '.') &&
- (fileName[2] == '\0'))
- continue;
- if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d))
- continue;
+ (fileName[2] == '\0')) {
+ continue;
+ }
+ if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d)) {
+ continue;
+ }
return fileName;
}
err = GetLastError();
PR_ASSERT(NO_ERROR != err);
- _PR_MD_MAP_READDIR_ERROR(err);
+ _PR_MD_MAP_READDIR_ERROR(err);
return NULL;
- }
+ }
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return NULL;
}
@@ -525,7 +550,7 @@ _PR_MD_DELETE(const char *name)
if (DeleteFileA(name)) {
return 0;
} else {
- _PR_MD_MAP_DELETE_ERROR(GetLastError());
+ _PR_MD_MAP_DELETE_ERROR(GetLastError());
return -1;
}
}
@@ -602,7 +627,7 @@ _PR_MD_STAT(const char *fn, struct stat *info)
size_t len = strlen(fn);
if (len > 0 && len <= _MAX_PATH
- && IsPrevCharSlash(fn, fn + len)) {
+ && IsPrevCharSlash(fn, fn + len)) {
char newfn[_MAX_PATH + 1];
strcpy(newfn, fn);
@@ -624,8 +649,9 @@ IsPrevCharSlash(const char *str, const char *current)
{
const char *prev;
- if (str >= current)
+ if (str >= current) {
return PR_FALSE;
+ }
prev = _mbsdec(str, current);
return (prev == current - 1) && _PR_IS_SLASH(*prev);
}
@@ -660,7 +686,7 @@ IsRootDirectory(char *fn, size_t buflen)
}
if (isalpha(fn[0]) && fn[1] == ':' && _PR_IS_SLASH(fn[2])
- && fn[3] == '\0') {
+ && fn[3] == '\0') {
rv = GetDriveType(fn) > 1 ? PR_TRUE : PR_FALSE;
return rv;
}
@@ -723,7 +749,7 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
{
WIN32_FILE_ATTRIBUTE_DATA findFileData;
BOOL rv;
-
+
if (NULL == fn || '\0' == *fn) {
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return -1;
@@ -747,11 +773,11 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
_PR_FileTimeToPRTime(&findFileData.ftLastWriteTime, &info->modifyTime);
if (0 == findFileData.ftCreationTime.dwLowDateTime &&
- 0 == findFileData.ftCreationTime.dwHighDateTime) {
+ 0 == findFileData.ftCreationTime.dwHighDateTime) {
info->creationTime = info->modifyTime;
} else {
_PR_FileTimeToPRTime(&findFileData.ftCreationTime,
- &info->creationTime);
+ &info->creationTime);
}
return 0;
@@ -781,14 +807,16 @@ _PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info)
rv = GetFileInformationByHandle((HANDLE)fd->secret->md.osfd, &hinfo);
if (rv == FALSE) {
- _PR_MD_MAP_FSTAT_ERROR(GetLastError());
+ _PR_MD_MAP_FSTAT_ERROR(GetLastError());
return -1;
- }
+ }
- if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_FILE;
+ }
info->size = hinfo.nFileSizeHigh;
info->size = (info->size << 32) + hinfo.nFileSizeLow;
@@ -824,15 +852,15 @@ _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable)
* ERROR_CALL_NOT_IMPLEMENTED error on Win95.
*/
rv = SetHandleInformation(
- (HANDLE)fd->secret->md.osfd,
- HANDLE_FLAG_INHERIT,
- inheritable ? HANDLE_FLAG_INHERIT : 0);
+ (HANDLE)fd->secret->md.osfd,
+ HANDLE_FLAG_INHERIT,
+ inheritable ? HANDLE_FLAG_INHERIT : 0);
if (0 == rv) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
return PR_FAILURE;
}
return PR_SUCCESS;
-}
+}
void
_PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported)
@@ -866,7 +894,7 @@ _PR_MD_RENAME(const char *from, const char *to)
if (MoveFileA(from, to)) {
return 0;
} else {
- _PR_MD_MAP_RENAME_ERROR(GetLastError());
+ _PR_MD_MAP_RENAME_ERROR(GetLastError());
return -1;
}
}
@@ -874,23 +902,24 @@ _PR_MD_RENAME(const char *from, const char *to)
PRInt32
_PR_MD_ACCESS(const char *name, PRAccessHow how)
{
-PRInt32 rv;
+ PRInt32 rv;
switch (how) {
- case PR_ACCESS_WRITE_OK:
- rv = _access(name, 02);
- break;
- case PR_ACCESS_READ_OK:
- rv = _access(name, 04);
- break;
- case PR_ACCESS_EXISTS:
- return _access(name, 00);
- break;
- default:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return -1;
- }
- if (rv < 0)
- _PR_MD_MAP_ACCESS_ERROR(errno);
+ case PR_ACCESS_WRITE_OK:
+ rv = _access(name, 02);
+ break;
+ case PR_ACCESS_READ_OK:
+ rv = _access(name, 04);
+ break;
+ case PR_ACCESS_EXISTS:
+ return _access(name, 00);
+ break;
+ default:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return -1;
+ }
+ if (rv < 0) {
+ _PR_MD_MAP_ACCESS_ERROR(errno);
+ }
return rv;
}
@@ -901,7 +930,7 @@ _PR_MD_MKDIR(const char *name, PRIntn mode)
if (CreateDirectoryA(name, NULL)) {
return 0;
} else {
- _PR_MD_MAP_MKDIR_ERROR(GetLastError());
+ _PR_MD_MAP_MKDIR_ERROR(GetLastError());
return -1;
}
}
@@ -916,7 +945,7 @@ _PR_MD_MAKE_DIR(const char *name, PRIntn mode)
PACL pACL = NULL;
if (_PR_NT_MakeSecurityDescriptorACL(mode, dirAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
@@ -940,7 +969,7 @@ _PR_MD_RMDIR(const char *name)
if (RemoveDirectoryA(name)) {
return 0;
} else {
- _PR_MD_MAP_RMDIR_ERROR(GetLastError());
+ _PR_MD_MAP_RMDIR_ERROR(GetLastError());
return -1;
}
}
@@ -949,16 +978,16 @@ PRStatus
_PR_MD_LOCKFILE(PROsfd f)
{
PRStatus rc = PR_SUCCESS;
- DWORD rv;
+ DWORD rv;
- rv = LockFile( (HANDLE)f,
- 0l, 0l,
- 0x0l, 0xffffffffl );
- if ( rv == 0 ) {
+ rv = LockFile( (HANDLE)f,
+ 0l, 0l,
+ 0x0l, 0xffffffffl );
+ if ( rv == 0 ) {
DWORD err = GetLastError();
_PR_MD_MAP_DEFAULT_ERROR(err);
PR_LOG( _pr_io_lm, PR_LOG_ERROR,
- ("_PR_MD_LOCKFILE() failed. Error: %d", err ));
+ ("_PR_MD_LOCKFILE() failed. Error: %d", err ));
rc = PR_FAILURE;
}
@@ -976,30 +1005,32 @@ _PR_MD_TLOCKFILE(PROsfd f)
PRStatus
_PR_MD_UNLOCKFILE(PROsfd f)
{
- PRInt32 rv;
-
+ PRInt32 rv;
+
rv = UnlockFile( (HANDLE) f,
- 0l, 0l,
- 0x0l, 0xffffffffl );
-
+ 0l, 0l,
+ 0x0l, 0xffffffffl );
+
if ( rv )
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
else
{
- _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
- return PR_FAILURE;
+ _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
+ return PR_FAILURE;
}
} /* end _PR_MD_UNLOCKFILE() */
PRInt32
_PR_MD_PIPEAVAILABLE(PRFileDesc *fd)
{
- if (NULL == fd)
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
- else
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ if (NULL == fd) {
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
+ }
+ else {
+ PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ }
return -1;
}
@@ -1045,7 +1076,7 @@ _PR_MD_OPEN_FILE_UTF16(const PRUnichar *name, PRIntn osflags, int mode)
if (osflags & PR_CREATE_FILE) {
if (_PR_NT_MakeSecurityDescriptorACL(mode, fileAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
@@ -1053,25 +1084,34 @@ _PR_MD_OPEN_FILE_UTF16(const PRUnichar *name, PRIntn osflags, int mode)
}
}
- if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
+ if (osflags & PR_SYNC) {
+ flag6 = FILE_FLAG_WRITE_THROUGH;
+ }
- if (osflags & PR_RDONLY || osflags & PR_RDWR)
+ if (osflags & PR_RDONLY || osflags & PR_RDWR) {
access |= GENERIC_READ;
- if (osflags & PR_WRONLY || osflags & PR_RDWR)
+ }
+ if (osflags & PR_WRONLY || osflags & PR_RDWR) {
access |= GENERIC_WRITE;
-
- if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
+ }
+
+ if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL ) {
flags = CREATE_NEW;
+ }
else if (osflags & PR_CREATE_FILE) {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = CREATE_ALWAYS;
- else
+ }
+ else {
flags = OPEN_ALWAYS;
+ }
} else {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = TRUNCATE_EXISTING;
- else
+ }
+ else {
flags = OPEN_EXISTING;
+ }
}
file = createFileW(name,
@@ -1088,10 +1128,10 @@ _PR_MD_OPEN_FILE_UTF16(const PRUnichar *name, PRIntn osflags, int mode)
_PR_MD_MAP_OPEN_ERROR(GetLastError());
return -1;
}
-
+
return (PROsfd)file;
}
-
+
PRStatus
_PR_MD_OPEN_DIR_UTF16(_MDDirUTF16 *d, const PRUnichar *name)
{
@@ -1146,14 +1186,17 @@ _PR_MD_READ_DIR_UTF16(_MDDirUTF16 *d, PRIntn flags)
}
fileName = GetFileFromDIR(d);
if ( (flags & PR_SKIP_DOT) &&
- (fileName[0] == L'.') && (fileName[1] == L'\0'))
+ (fileName[0] == L'.') && (fileName[1] == L'\0')) {
continue;
+ }
if ( (flags & PR_SKIP_DOT_DOT) &&
(fileName[0] == L'.') && (fileName[1] == L'.') &&
- (fileName[2] == L'\0'))
+ (fileName[2] == L'\0')) {
continue;
- if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d))
+ }
+ if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d)) {
continue;
+ }
return fileName;
}
err = GetLastError();
@@ -1164,7 +1207,7 @@ _PR_MD_READ_DIR_UTF16(_MDDirUTF16 *d, PRIntn flags)
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return NULL;
}
-
+
PRInt32
_PR_MD_CLOSE_DIR_UTF16(_MDDirUTF16 *d)
{
@@ -1213,7 +1256,7 @@ IsRootDirectoryW(PRUnichar *fn, size_t buflen)
}
if (iswalpha(fn[0]) && fn[1] == L':' && _PR_IS_W_SLASH(fn[2])
- && fn[3] == L'\0') {
+ && fn[3] == L'\0') {
rv = getDriveTypeW(fn) > 1 ? PR_TRUE : PR_FALSE;
return rv;
}
@@ -1312,9 +1355,9 @@ _PR_MD_GETFILEINFO64_UTF16(const PRUnichar *fn, PRFileInfo64 *info)
if (NULL == wcspbrk(fn, L".\\/")) {
_PR_MD_MAP_OPENDIR_ERROR(GetLastError());
return -1;
- }
+ }
len = getFullPathNameW(fn, sizeof(pathbuf)/sizeof(pathbuf[0]), pathbuf,
- &filePart);
+ &filePart);
if (0 == len) {
_PR_MD_MAP_OPENDIR_ERROR(GetLastError());
return -1;
@@ -1360,11 +1403,11 @@ _PR_MD_GETFILEINFO64_UTF16(const PRUnichar *fn, PRFileInfo64 *info)
_PR_FileTimeToPRTime(&findFileData.ftLastWriteTime, &info->modifyTime);
if (0 == findFileData.ftCreationTime.dwLowDateTime &&
- 0 == findFileData.ftCreationTime.dwHighDateTime) {
+ 0 == findFileData.ftCreationTime.dwHighDateTime) {
info->creationTime = info->modifyTime;
} else {
_PR_FileTimeToPRTime(&findFileData.ftCreationTime,
- &info->creationTime);
+ &info->creationTime);
}
return 0;
diff --git a/nsprpub/pr/src/md/windows/w95sock.c b/nsprpub/pr/src/md/windows/w95sock.c
index c6a3ec111..7d7362c60 100644
--- a/nsprpub/pr/src/md/windows/w95sock.c
+++ b/nsprpub/pr/src/md/windows/w95sock.c
@@ -14,7 +14,7 @@
#define CONNECT_FD 3
static PRInt32 socket_io_wait(
- PROsfd osfd,
+ PROsfd osfd,
PRInt32 fd_type,
PRIntervalTime timeout);
@@ -51,7 +51,7 @@ _PR_MD_SOCKET(int af, int type, int flags)
sock = socket(af, type, flags);
- if (sock == INVALID_SOCKET )
+ if (sock == INVALID_SOCKET )
{
_PR_MD_MAP_SOCKET_ERROR(WSAGetLastError());
return (PROsfd)sock;
@@ -101,8 +101,9 @@ _MD_CloseSocket(PROsfd osfd)
PRInt32 rv;
rv = closesocket((SOCKET) osfd );
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_CLOSE_ERROR(WSAGetLastError());
+ }
return rv;
}
@@ -120,8 +121,8 @@ _MD_SocketAvailable(PRFileDesc *fd)
}
PROsfd _MD_Accept(
- PRFileDesc *fd,
- PRNetAddr *raddr,
+ PRFileDesc *fd,
+ PRNetAddr *raddr,
PRUint32 *rlen,
PRIntervalTime timeout )
{
@@ -129,7 +130,7 @@ PROsfd _MD_Accept(
SOCKET sock;
PRInt32 rv, err;
- while ((sock = accept(osfd, (struct sockaddr *) raddr, rlen)) == -1)
+ while ((sock = accept(osfd, (struct sockaddr *) raddr, rlen)) == -1)
{
err = WSAGetLastError();
if ((err == WSAEWOULDBLOCK) && (!fd->secret->nonblocking))
@@ -149,14 +150,14 @@ PROsfd _MD_Accept(
} /* end _MD_accept() */
PRInt32
-_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
+_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
PRIntervalTime timeout)
{
PROsfd osfd = fd->secret->md.osfd;
PRInt32 rv;
int err;
- if ((rv = connect(osfd, (struct sockaddr *) addr, addrlen)) == -1)
+ if ((rv = connect(osfd, (struct sockaddr *) addr, addrlen)) == -1)
{
err = WSAGetLastError();
if ((!fd->secret->nonblocking) && (err == WSAEWOULDBLOCK))
@@ -171,7 +172,7 @@ _PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
PR_ASSERT(rv > 0);
/* it's connected */
return(0);
- }
+ }
}
_PR_MD_MAP_CONNECT_ERROR(err);
}
@@ -209,7 +210,7 @@ _PR_MD_LISTEN(PRFileDesc *fd, PRIntn backlog)
}
PRInt32
-_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
+_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PRIntervalTime timeout)
{
PROsfd osfd = fd->secret->md.osfd;
@@ -222,18 +223,18 @@ _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PR_ASSERT(PR_MSG_PEEK == flags);
osflags = MSG_PEEK;
}
- while ((rv = recv( osfd, buf, amount, osflags)) == -1)
+ while ((rv = recv( osfd, buf, amount, osflags)) == -1)
{
- if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
+ if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
&& (!fd->secret->nonblocking))
{
rv = socket_io_wait(osfd, READ_FD, timeout);
if ( rv < 0 )
{
return -1;
- }
- }
- else
+ }
+ }
+ else
{
_PR_MD_MAP_RECV_ERROR(err);
break;
@@ -250,11 +251,11 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
PRInt32 rv, err;
PRInt32 bytesSent = 0;
- while(bytesSent < amount )
+ while(bytesSent < amount )
{
- while ((rv = send( osfd, buf, amount, 0 )) == -1)
+ while ((rv = send( osfd, buf, amount, 0 )) == -1)
{
- if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
+ if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
&& (!fd->secret->nonblocking))
{
rv = socket_io_wait(osfd, WRITE_FD, timeout);
@@ -262,8 +263,8 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
{
return -1;
}
- }
- else
+ }
+ else
{
_PR_MD_MAP_SEND_ERROR(err);
return -1;
@@ -274,7 +275,7 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
{
break;
}
- if (bytesSent < amount)
+ if (bytesSent < amount)
{
rv = socket_io_wait(osfd, WRITE_FD, timeout);
if ( rv < 0 )
@@ -296,9 +297,9 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
do {
while ((rv = sendto( osfd, buf, amount, 0, (struct sockaddr *) addr,
- addrlen)) == -1)
+ addrlen)) == -1)
{
- if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
+ if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
&& (!fd->secret->nonblocking))
{
rv = socket_io_wait(osfd, WRITE_FD, timeout);
@@ -306,8 +307,8 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
{
return -1;
}
- }
- else
+ }
+ else
{
_PR_MD_MAP_SENDTO_ERROR(err);
return -1;
@@ -318,10 +319,10 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
{
break;
}
- if (bytesSent < amount)
+ if (bytesSent < amount)
{
rv = socket_io_wait(osfd, WRITE_FD, timeout);
- if (rv < 0)
+ if (rv < 0)
{
return -1;
}
@@ -361,8 +362,9 @@ static PRStatus PR_CALLBACK _pr_set_connectex(void)
/* Dummy socket needed for WSAIoctl */
sock = socket(AF_INET, SOCK_STREAM, 0);
- if (sock == INVALID_SOCKET)
+ if (sock == INVALID_SOCKET) {
return PR_SUCCESS;
+ }
GUID guid = WSAID_CONNECTEX;
rc = WSAIoctl(sock, SIO_GET_EXTENSION_FUNCTION_POINTER,
@@ -446,7 +448,7 @@ _PR_MD_TCPSENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
if (rv != 0) {
err = WSAGetLastError();
PR_LOG(_pr_io_lm, PR_LOG_MIN,
- ("_PR_MD_TCPSENDTO setting SO_UPDATE_CONNECT_CONTEXT failed %d\n", err));
+ ("_PR_MD_TCPSENDTO setting SO_UPDATE_CONNECT_CONTEXT failed %d\n", err));
_PR_MD_MAP_SETSOCKOPT_ERROR(err);
return -1;
}
@@ -472,7 +474,7 @@ _PR_MD_TCPSENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
* them during Fast Open or after connect. Therefore we can assumed
* this data already send. */
if (amount > 0) {
- return amount;
+ return amount;
}
_PR_MD_MAP_CONNECT_ERROR(WSAEWOULDBLOCK);
@@ -510,18 +512,18 @@ _PR_MD_RECVFROM(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PRInt32 rv, err;
while ((rv = recvfrom( osfd, buf, amount, 0, (struct sockaddr *) addr,
- addrlen)) == -1)
+ addrlen)) == -1)
{
- if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
+ if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
&& (!fd->secret->nonblocking))
{
rv = socket_io_wait(osfd, READ_FD, timeout);
if ( rv < 0)
{
return -1;
- }
- }
- else
+ }
+ }
+ else
{
_PR_MD_MAP_RECVFROM_ERROR(err);
break;
@@ -537,12 +539,13 @@ _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size, PRIntervalTi
int sent = 0;
int rv;
- for (index=0; index < iov_size; index++)
+ for (index=0; index < iov_size; index++)
{
rv = _PR_MD_SEND(fd, iov[index].iov_base, iov[index].iov_len, 0, timeout);
- if (rv > 0)
+ if (rv > 0) {
sent += rv;
- if ( rv != iov[index].iov_len )
+ }
+ if ( rv != iov[index].iov_len )
{
if (rv < 0)
{
@@ -568,11 +571,12 @@ _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size, PRIntervalTi
PRInt32
_PR_MD_SHUTDOWN(PRFileDesc *fd, PRIntn how)
{
-PRInt32 rv;
+ PRInt32 rv;
rv = shutdown(fd->secret->md.osfd, how);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_SHUTDOWN_ERROR(WSAGetLastError());
+ }
return rv;
}
@@ -651,7 +655,7 @@ _MD_MakeNonblock(PRFileDesc *f)
#define _PR_INTERRUPT_CHECK_INTERVAL_SECS 5
static PRInt32 socket_io_wait(
- PROsfd osfd,
+ PROsfd osfd,
PRInt32 fd_type,
PRIntervalTime timeout)
{
@@ -709,15 +713,17 @@ static PRInt32 socket_io_wait(
{
len = sizeof(err);
if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,
- (char *) &err, &len) == SOCKET_ERROR)
- {
+ (char *) &err, &len) == SOCKET_ERROR)
+ {
_PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
return -1;
}
- if (err != 0)
+ if (err != 0) {
_PR_MD_MAP_CONNECT_ERROR(err);
- else
+ }
+ else {
PR_SetError(PR_UNKNOWN_ERROR, 0);
+ }
return -1;
}
if (FD_ISSET((SOCKET)osfd, &rd_wr))
@@ -754,8 +760,8 @@ static PRInt32 socket_io_wait(
tv.tv_usec = 0;
} else {
tv.tv_usec = PR_IntervalToMicroseconds(
- remaining -
- PR_SecondsToInterval(tv.tv_sec));
+ remaining -
+ PR_SecondsToInterval(tv.tv_sec));
}
FD_SET(osfd, &rd_wr);
FD_SET(osfd, &ex);
@@ -789,15 +795,17 @@ static PRInt32 socket_io_wait(
{
len = sizeof(err);
if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,
- (char *) &err, &len) == SOCKET_ERROR)
- {
+ (char *) &err, &len) == SOCKET_ERROR)
+ {
_PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
return -1;
}
- if (err != 0)
+ if (err != 0) {
_PR_MD_MAP_CONNECT_ERROR(err);
- else
+ }
+ else {
PR_SetError(PR_UNKNOWN_ERROR, 0);
+ }
return -1;
}
if (FD_ISSET((SOCKET)osfd, &rd_wr))
@@ -822,8 +830,8 @@ static PRInt32 socket_io_wait(
if (wait_for_remaining) {
elapsed = remaining;
} else {
- elapsed = PR_SecondsToInterval(tv.tv_sec)
- + PR_MicrosecondsToInterval(tv.tv_usec);
+ elapsed = PR_SecondsToInterval(tv.tv_sec)
+ + PR_MicrosecondsToInterval(tv.tv_usec);
}
if (elapsed >= remaining) {
PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
diff --git a/nsprpub/pr/src/md/windows/w95thred.c b/nsprpub/pr/src/md/windows/w95thred.c
index a365411f5..fb9c457d7 100644
--- a/nsprpub/pr/src/md/windows/w95thred.c
+++ b/nsprpub/pr/src/md/windows/w95thred.c
@@ -25,7 +25,7 @@ DWORD _pr_currentThreadIndex;
DWORD _pr_lastThreadIndex;
DWORD _pr_currentCPUIndex;
#endif
-int _pr_intsOff = 0;
+int _pr_intsOff = 0;
_PRInterruptTable _pr_interruptTable[] = { { 0 } };
typedef HRESULT (WINAPI *SETTHREADDESCRIPTION)(HANDLE, PCWSTR);
@@ -51,8 +51,8 @@ _PR_MD_EARLY_INIT()
if (hModule) {
sSetThreadDescription =
(SETTHREADDESCRIPTION) GetProcAddress(
- hModule,
- "SetThreadDescription");
+ hModule,
+ "SetThreadDescription");
}
}
@@ -108,13 +108,13 @@ _PR_MD_INIT_THREAD(PRThread *thread)
** the pseudo handle via DuplicateHandle(...)
*/
BOOL ok = DuplicateHandle(
- GetCurrentProcess(), /* Process of source handle */
- GetCurrentThread(), /* Pseudo Handle to dup */
- GetCurrentProcess(), /* Process of handle */
- &(thread->md.handle), /* resulting handle */
- 0L, /* access flags */
- FALSE, /* Inheritable */
- DUPLICATE_SAME_ACCESS); /* Options */
+ GetCurrentProcess(), /* Process of source handle */
+ GetCurrentThread(), /* Pseudo Handle to dup */
+ GetCurrentProcess(), /* Process of handle */
+ &(thread->md.handle), /* resulting handle */
+ 0L, /* access flags */
+ FALSE, /* Inheritable */
+ DUPLICATE_SAME_ACCESS); /* Options */
if (!ok) {
return PR_FAILURE;
}
@@ -124,10 +124,12 @@ _PR_MD_INIT_THREAD(PRThread *thread)
/* Create the blocking IO semaphore */
thread->md.blocked_sema = CreateSemaphore(NULL, 0, 1, NULL);
- if (thread->md.blocked_sema == NULL)
+ if (thread->md.blocked_sema == NULL) {
return PR_FAILURE;
- else
- return PR_SUCCESS;
+ }
+ else {
+ return PR_SUCCESS;
+ }
}
static unsigned __stdcall
@@ -138,23 +140,23 @@ pr_root(void *arg)
return 0;
}
-PRStatus
-_PR_MD_CREATE_THREAD(PRThread *thread,
- void (*start)(void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+PRStatus
+_PR_MD_CREATE_THREAD(PRThread *thread,
+ void (*start)(void *),
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize)
{
thread->md.start = start;
thread->md.handle = (HANDLE) _beginthreadex(
- NULL,
- thread->stack->stackSize,
- pr_root,
- (void *)thread,
- CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION,
- &(thread->id));
+ NULL,
+ thread->stack->stackSize,
+ pr_root,
+ (void *)thread,
+ CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION,
+ &(thread->id));
if(!thread->md.handle) {
return PR_FAILURE;
}
@@ -169,20 +171,21 @@ _PR_MD_CREATE_THREAD(PRThread *thread,
}
/* Activate the thread */
- if ( ResumeThread( thread->md.handle ) != -1)
+ if ( ResumeThread( thread->md.handle ) != -1) {
return PR_SUCCESS;
+ }
return PR_FAILURE;
}
-void
+void
_PR_MD_YIELD(void)
{
/* Can NT really yield at all? */
Sleep(0);
}
-void
+void
_PR_MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
{
int nativePri;
@@ -209,8 +212,8 @@ _PR_MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
rv = SetThreadPriority(thread->handle, nativePri);
PR_ASSERT(rv);
if (!rv) {
- PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("PR_SetThreadPriority: can't set thread priority\n"));
+ PR_LOG(_pr_thread_lm, PR_LOG_MIN,
+ ("PR_SetThreadPriority: can't set thread priority\n"));
}
return;
}
@@ -220,10 +223,10 @@ const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
- DWORD dwType; // Must be 0x1000.
- LPCSTR szName; // Pointer to name (in user addr space).
- DWORD dwThreadID; // Thread ID (-1=caller thread).
- DWORD dwFlags; // Reserved for future use, must be zero.
+ DWORD dwType; // Must be 0x1000.
+ LPCSTR szName; // Pointer to name (in user addr space).
+ DWORD dwThreadID; // Thread ID (-1=caller thread).
+ DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
#pragma pack(pop)
@@ -231,32 +234,33 @@ void
_PR_MD_SET_CURRENT_THREAD_NAME(const char *name)
{
#ifdef _MSC_VER
- THREADNAME_INFO info;
+ THREADNAME_INFO info;
#endif
- if (sSetThreadDescription) {
- WCHAR wideName[MAX_PATH];
- if (MultiByteToWideChar(CP_ACP, 0, name, -1, wideName, MAX_PATH)) {
- sSetThreadDescription(GetCurrentThread(), wideName);
- }
- }
+ if (sSetThreadDescription) {
+ WCHAR wideName[MAX_PATH];
+ if (MultiByteToWideChar(CP_ACP, 0, name, -1, wideName, MAX_PATH)) {
+ sSetThreadDescription(GetCurrentThread(), wideName);
+ }
+ }
#ifdef _MSC_VER
- if (!IsDebuggerPresent())
- return;
-
- info.dwType = 0x1000;
- info.szName = (char*) name;
- info.dwThreadID = -1;
- info.dwFlags = 0;
-
- __try {
- RaiseException(MS_VC_EXCEPTION,
- 0,
- sizeof(info) / sizeof(ULONG_PTR),
- (ULONG_PTR*)&info);
- } __except(EXCEPTION_CONTINUE_EXECUTION) {
- }
+ if (!IsDebuggerPresent()) {
+ return;
+ }
+
+ info.dwType = 0x1000;
+ info.szName = (char*) name;
+ info.dwThreadID = -1;
+ info.dwFlags = 0;
+
+ __try {
+ RaiseException(MS_VC_EXCEPTION,
+ 0,
+ sizeof(info) / sizeof(ULONG_PTR),
+ (ULONG_PTR*)&info);
+ } __except(EXCEPTION_CONTINUE_EXECUTION) {
+ }
#endif
}
@@ -317,16 +321,17 @@ PRInt32 _PR_MD_GETTHREADAFFINITYMASK(PRThread *thread, PRUint32 *mask)
DWORD_PTR system_mask;
rv = GetProcessAffinityMask(GetCurrentProcess(),
- &process_mask, &system_mask);
- if (rv)
+ &process_mask, &system_mask);
+ if (rv) {
*mask = (PRUint32)process_mask;
+ }
return rv?0:-1;
#endif
}
-void
-_PR_MD_SUSPEND_CPU(_PRCPU *cpu)
+void
+_PR_MD_SUSPEND_CPU(_PRCPU *cpu)
{
_PR_MD_SUSPEND_THREAD(cpu->thread);
}
@@ -363,14 +368,14 @@ _PR_MD_RESUME_THREAD(PRThread *thread)
PRThread*
_MD_CURRENT_THREAD(void)
{
-PRThread *thread;
+ PRThread *thread;
- thread = _MD_GET_ATTACHED_THREAD();
+ thread = _MD_GET_ATTACHED_THREAD();
- if (NULL == thread) {
- thread = _PRI_AttachThread(
- PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL, 0);
- }
- PR_ASSERT(thread != NULL);
- return thread;
+ if (NULL == thread) {
+ thread = _PRI_AttachThread(
+ PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL, 0);
+ }
+ PR_ASSERT(thread != NULL);
+ return thread;
}
diff --git a/nsprpub/pr/src/md/windows/win32_errors.c b/nsprpub/pr/src/md/windows/win32_errors.c
index 275792187..b0118146b 100644
--- a/nsprpub/pr/src/md/windows/win32_errors.c
+++ b/nsprpub/pr/src/md/windows/win32_errors.c
@@ -13,7 +13,7 @@
* - GetLastError(): for Win32 functions
* - WSAGetLastError(): for Winsock functions
* - errno: for standard C library functions
- *
+ *
* GetLastError() and WSAGetLastError() return error codes in
* non-overlapping ranges, so their error codes (ERROR_* and
* WSAE*) can be mapped by the same function. On the other hand,
@@ -61,7 +61,7 @@ void _MD_win32_map_default_error(PRInt32 err)
prError = PR_NOT_IMPLEMENTED_ERROR;
break;
case ERROR_DISK_CORRUPT:
- prError = PR_IO_ERROR;
+ prError = PR_IO_ERROR;
break;
case ERROR_DISK_FULL:
prError = PR_NO_DEVICE_SPACE_ERROR;
@@ -518,7 +518,7 @@ void _MD_win32_map_gethostname_error(PRInt32 err)
}
/* Win32 select() only works on sockets. So in this
-** context, WSAENOTSOCK is equivalent to EBADF on Unix.
+** context, WSAENOTSOCK is equivalent to EBADF on Unix.
*/
void _MD_win32_map_select_error(PRInt32 err)
{