diff options
Diffstat (limited to 'nsprpub')
50 files changed, 1097 insertions, 633 deletions
diff --git a/nsprpub/TAG-INFO b/nsprpub/TAG-INFO deleted file mode 100644 index 34b02cffc..000000000 --- a/nsprpub/TAG-INFO +++ /dev/null @@ -1 +0,0 @@ -NSPR_4_13_1_RTM diff --git a/nsprpub/configure b/nsprpub/configure index fb3b3e2ab..19e9fa60f 100755 --- a/nsprpub/configure +++ b/nsprpub/configure @@ -2488,8 +2488,8 @@ test -n "$target_alias" && program_prefix=${target_alias}- MOD_MAJOR_VERSION=4 -MOD_MINOR_VERSION=13 -MOD_PATCH_VERSION=1 +MOD_MINOR_VERSION=18 +MOD_PATCH_VERSION=0 NSPR_MODNAME=nspr20 _HAVE_PTHREADS= USE_PTHREADS= @@ -5424,6 +5424,40 @@ $as_echo "no" >&6; } fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pragma diagnostic" >&5 +$as_echo_n "checking for pragma diagnostic... " >&6; } +if test "$GNU_CC" = "1"; then + cat >dummy-hello.c <<EOF +#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#endif +int main() { + char *dummy = ""; + return 0; +} +EOF + ${CC} -Werror=unused-but-set-variable -S dummy-hello.c -o dummy-hello.s 2>&5 + if test $? != 0; then + ${CC} -Werror=unused-but-set-variable -D_PR_HAS_PRAGMA_DIAGNOSTIC -S dummy-hello.c -o dummy-hello.s 2>&5 + if test $? = 0; then + CFLAGS="$CFLAGS -D_PR_HAS_PRAGMA_DIAGNOSTIC=1" + _res=yes + else + _res=no + fi + else + _res=no + fi + rm -f dummy-hello.c dummy-hello.s + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $_res" >&5 +$as_echo "$_res" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + _SAVE_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -fprofile-generate -fprofile-correction" @@ -6524,6 +6558,15 @@ fi $as_echo "#define HAVE_SOCKLEN_T 1" >>confdefs.h + $as_echo "#define HAVE_POINTER_LOCALTIME_R 1" >>confdefs.h + + + HOST_DARWIN_MAJOR=`echo "$build_os" | sed -E -e 's/^darwin([0-9]+).*$/\1/'` + + if test "$HOST_DARWIN_MAJOR" -ge 15 ; then + $as_echo "#define HAS_CONNECTX 1" >>confdefs.h + + fi AS='$(CC) -x assembler-with-cpp' CFLAGS="$CFLAGS -Wall -fno-common" case "${target_cpu}" in @@ -6673,6 +6716,8 @@ tools are selected during the Xcode/Developer Tools installation." "$LINENO" 5 $as_echo "#define HAVE_SOCKLEN_T 1" >>confdefs.h + $as_echo "#define HAVE_POINTER_LOCALTIME_R 1" >>confdefs.h + CFLAGS="$CFLAGS $(DSO_CFLAGS) -ansi -Wall" MOZ_OBJFORMAT=`test -x /usr/bin/objformat && /usr/bin/objformat || echo elf` if test "$MOZ_OBJFORMAT" = "elf"; then @@ -6975,6 +7020,8 @@ tools are selected during the Xcode/Developer Tools installation." "$LINENO" 5 $as_echo "#define HAVE_FCNTL_FILE_LOCKING 1" >>confdefs.h + $as_echo "#define HAVE_POINTER_LOCALTIME_R 1" >>confdefs.h + case "${target}" in *-android*|*-linuxandroid*) OS_TARGET=Android @@ -7281,6 +7328,8 @@ $as_echo "$as_me: WARNING: Unknown version of the Microsoft (R) Manifest Tool." $as_echo "#define HAVE_SOCKLEN_T 1" >>confdefs.h + $as_echo "#define HAVE_POINTER_LOCALTIME_R 1" >>confdefs.h + if test -z "$USE_NSPR_THREADS"; then USE_PTHREADS=1 fi @@ -7337,6 +7386,8 @@ $as_echo "$as_me: WARNING: Unknown version of the Microsoft (R) Manifest Tool." $as_echo "#define HAVE_SOCKLEN_T 1" >>confdefs.h + $as_echo "#define HAVE_POINTER_LOCALTIME_R 1" >>confdefs.h + CFLAGS="$CFLAGS -ansi -Wall" CXXFLAGS="$CXXFLAGS -ansi -Wall" DLL_SUFFIX=so.1.0 @@ -8423,19 +8474,12 @@ case "$target" in fi if test "$USE_PTHREADS"; then - if echo "$OS_RELEASE" | egrep '^(B.10.10|B.10.20)' >/dev/null; then - $as_echo "#define _REENTRANT 1" >>confdefs.h - - $as_echo "#define _PR_DCETHREADS 1" >>confdefs.h - - else - cat >>confdefs.h <<_ACEOF + cat >>confdefs.h <<_ACEOF #define _POSIX_C_SOURCE 199506L _ACEOF - $as_echo "#define _PR_HAVE_THREADSAFE_GETHOST 1" >>confdefs.h + $as_echo "#define _PR_HAVE_THREADSAFE_GETHOST 1" >>confdefs.h - fi fi if test "$USE_USER_PTHREADS"; then cat >>confdefs.h <<_ACEOF diff --git a/nsprpub/configure.in b/nsprpub/configure.in index 202158b79..7b0b8b395 100644 --- a/nsprpub/configure.in +++ b/nsprpub/configure.in @@ -15,8 +15,8 @@ dnl ======================================================== dnl = Defaults dnl ======================================================== MOD_MAJOR_VERSION=4 -MOD_MINOR_VERSION=13 -MOD_PATCH_VERSION=1 +MOD_MINOR_VERSION=18 +MOD_PATCH_VERSION=0 NSPR_MODNAME=nspr20 _HAVE_PTHREADS= USE_PTHREADS= @@ -716,6 +716,40 @@ else fi dnl ======================================================== +dnl Check for pragma diagnostic +dnl ======================================================== + +AC_MSG_CHECKING([for pragma diagnostic]) +if test "$GNU_CC" = "1"; then + cat >dummy-hello.c <<EOF +#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#endif +int main() { + char *dummy = ""; + return 0; +} +EOF + ${CC} -Werror=unused-but-set-variable -S dummy-hello.c -o dummy-hello.s 2>&5 + if test $? != 0; then + ${CC} -Werror=unused-but-set-variable -D_PR_HAS_PRAGMA_DIAGNOSTIC -S dummy-hello.c -o dummy-hello.s 2>&5 + if test $? = 0; then + CFLAGS="$CFLAGS -D_PR_HAS_PRAGMA_DIAGNOSTIC=1" + _res=yes + else + _res=no + fi + else + _res=no + fi + rm -f dummy-hello.c dummy-hello.s + AC_MSG_RESULT([$_res]) +else + AC_MSG_RESULT([no]) +fi + +dnl ======================================================== dnl Profile guided optimization dnl ======================================================== dnl Test for profiling options @@ -1349,6 +1383,13 @@ case "$target" in AC_DEFINE(DARWIN) AC_DEFINE(HAVE_BSD_FLOCK) AC_DEFINE(HAVE_SOCKLEN_T) + AC_DEFINE(HAVE_POINTER_LOCALTIME_R) + changequote(,) + HOST_DARWIN_MAJOR=`echo "$build_os" | sed -E -e 's/^darwin([0-9]+).*$/\1/'` + changequote([,]) + if test "$HOST_DARWIN_MAJOR" -ge 15 ; then + AC_DEFINE(HAS_CONNECTX) + fi AS='$(CC) -x assembler-with-cpp' CFLAGS="$CFLAGS -Wall -fno-common" case "${target_cpu}" in @@ -1519,6 +1560,7 @@ tools are selected during the Xcode/Developer Tools installation.]) AC_DEFINE(FREEBSD) AC_DEFINE(HAVE_BSD_FLOCK) AC_DEFINE(HAVE_SOCKLEN_T) + AC_DEFINE(HAVE_POINTER_LOCALTIME_R) CFLAGS="$CFLAGS $(DSO_CFLAGS) -ansi -Wall" MOZ_OBJFORMAT=`test -x /usr/bin/objformat && /usr/bin/objformat || echo elf` if test "$MOZ_OBJFORMAT" = "elf"; then @@ -1789,6 +1831,7 @@ tools are selected during the Xcode/Developer Tools installation.]) AC_DEFINE(XP_UNIX) AC_DEFINE(_GNU_SOURCE) AC_DEFINE(HAVE_FCNTL_FILE_LOCKING) + AC_DEFINE(HAVE_POINTER_LOCALTIME_R) case "${target}" in *-android*|*-linuxandroid*) OS_TARGET=Android @@ -2078,6 +2121,7 @@ tools are selected during the Xcode/Developer Tools installation.]) AC_DEFINE(NETBSD) AC_DEFINE(HAVE_BSD_FLOCK) AC_DEFINE(HAVE_SOCKLEN_T) + AC_DEFINE(HAVE_POINTER_LOCALTIME_R) if test -z "$USE_NSPR_THREADS"; then USE_PTHREADS=1 fi @@ -2126,6 +2170,7 @@ tools are selected during the Xcode/Developer Tools installation.]) AC_DEFINE(OPENBSD) AC_DEFINE(HAVE_BSD_FLOCK) AC_DEFINE(HAVE_SOCKLEN_T) + AC_DEFINE(HAVE_POINTER_LOCALTIME_R) CFLAGS="$CFLAGS -ansi -Wall" CXXFLAGS="$CXXFLAGS -ansi -Wall" DLL_SUFFIX=so.1.0 @@ -2844,13 +2889,8 @@ case "$target" in AC_DEFINE(_PR_LOCAL_THREADS_ONLY) fi if test "$USE_PTHREADS"; then - if echo "$OS_RELEASE" | egrep '^(B.10.10|B.10.20)' >/dev/null; then - AC_DEFINE(_REENTRANT) - AC_DEFINE(_PR_DCETHREADS) - else - AC_DEFINE_UNQUOTED(_POSIX_C_SOURCE,199506L) - AC_DEFINE(_PR_HAVE_THREADSAFE_GETHOST) - fi + AC_DEFINE_UNQUOTED(_POSIX_C_SOURCE,199506L) + AC_DEFINE(_PR_HAVE_THREADSAFE_GETHOST) fi if test "$USE_USER_PTHREADS"; then AC_DEFINE_UNQUOTED(_POSIX_C_SOURCE,199506L) diff --git a/nsprpub/lib/ds/plvrsion.c b/nsprpub/lib/ds/plvrsion.c index e251a5ac0..8b351b4db 100644 --- a/nsprpub/lib/ds/plvrsion.c +++ b/nsprpub/lib/ds/plvrsion.c @@ -74,6 +74,10 @@ static char sccsid[] = "@(#)NSPR " PR_VERSION _DEBUG_STRING #endif /* XP_UNIX */ +#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#endif PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint() { #ifdef XP_UNIX @@ -88,6 +92,9 @@ PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint() #endif return &VERSION_DESC_NAME; } /* versionEntryPointType */ +#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif /* plvrsion.c */ diff --git a/nsprpub/lib/libc/src/plvrsion.c b/nsprpub/lib/libc/src/plvrsion.c index b25be1e03..c4bc7a831 100644 --- a/nsprpub/lib/libc/src/plvrsion.c +++ b/nsprpub/lib/libc/src/plvrsion.c @@ -74,6 +74,10 @@ static char sccsid[] = "@(#)NSPR " PR_VERSION _DEBUG_STRING #endif /* XP_UNIX */ +#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#endif PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint() { #ifdef XP_UNIX @@ -88,6 +92,9 @@ PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint() #endif return &VERSION_DESC_NAME; } /* versionEntryPointType */ +#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif /* plvrsion.c */ diff --git a/nsprpub/lib/prstreams/plvrsion.c b/nsprpub/lib/prstreams/plvrsion.c index 511e4c4f6..27fd058d7 100644 --- a/nsprpub/lib/prstreams/plvrsion.c +++ b/nsprpub/lib/prstreams/plvrsion.c @@ -74,6 +74,10 @@ static char sccsid[] = "@(#)NSPR " PR_VERSION _DEBUG_STRING #endif /* XP_UNIX */ +#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#endif PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint() { #ifdef XP_UNIX @@ -88,6 +92,9 @@ PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint() #endif return &VERSION_DESC_NAME; } /* versionEntryPointType */ +#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif /* plvrsion.c */ diff --git a/nsprpub/pr/include/md/_linux.cfg b/nsprpub/pr/include/md/_linux.cfg index 8cbf0cb9b..b4c0ed427 100644 --- a/nsprpub/pr/include/md/_linux.cfg +++ b/nsprpub/pr/include/md/_linux.cfg @@ -498,6 +498,9 @@ #elif defined(__mips__) +/* For _ABI64 */ +#include <sgidefs.h> + #ifdef __MIPSEB__ #define IS_BIG_ENDIAN 1 #undef IS_LITTLE_ENDIAN diff --git a/nsprpub/pr/include/md/_pth.h b/nsprpub/pr/include/md/_pth.h index eeeef0438..5603223a0 100644 --- a/nsprpub/pr/include/md/_pth.h +++ b/nsprpub/pr/include/md/_pth.h @@ -14,29 +14,7 @@ #define _PR_MD_DISABLE_CLOCK_INTERRUPTS() #define _PR_MD_ENABLE_CLOCK_INTERRUPTS() -/* In good standards fashion, the DCE threads (based on posix-4) are not - * quite the same as newer posix implementations. These are mostly name - * changes and small differences, so macros usually do the trick - */ -#ifdef _PR_DCETHREADS -#define _PT_PTHREAD_MUTEXATTR_INIT pthread_mutexattr_create -#define _PT_PTHREAD_MUTEXATTR_DESTROY pthread_mutexattr_delete -#define _PT_PTHREAD_MUTEX_INIT(m, a) pthread_mutex_init(&(m), a) -#define _PT_PTHREAD_MUTEX_IS_LOCKED(m) (0 == pthread_mutex_trylock(&(m))) -#define _PT_PTHREAD_CONDATTR_INIT pthread_condattr_create -#define _PT_PTHREAD_COND_INIT(m, a) pthread_cond_init(&(m), a) -#define _PT_PTHREAD_CONDATTR_DESTROY pthread_condattr_delete - -/* Notes about differences between DCE threads and pthreads 10: - * 1. pthread_mutex_trylock returns 1 when it locks the mutex - * 0 when it does not. The latest pthreads has a set of errno-like - * return values. - * 2. return values from pthread_cond_timedwait are different. - * - * - * - */ -#elif defined(BSDI) +#if defined(BSDI) /* * Mutex and condition attributes are not supported. The attr * argument to pthread_mutex_init() and pthread_cond_init() must @@ -106,13 +84,7 @@ * PR_EnterMonitor calls any of these functions, infinite * recursion ensues. */ -#if defined(_PR_DCETHREADS) -#define _PT_PTHREAD_INVALIDATE_THR_HANDLE(t) \ - memset(&(t), 0, sizeof(pthread_t)) -#define _PT_PTHREAD_THR_HANDLE_IS_INVALID(t) \ - (!memcmp(&(t), &pt_zero_tid, sizeof(pthread_t))) -#define _PT_PTHREAD_COPY_THR_HANDLE(st, dt) (dt) = (st) -#elif defined(IRIX) || defined(OSF1) || defined(AIX) || defined(SOLARIS) \ +#if defined(IRIX) || defined(OSF1) || defined(AIX) || defined(SOLARIS) \ || defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \ || defined(HPUX) || defined(FREEBSD) \ || defined(NETBSD) || defined(OPENBSD) || defined(BSDI) \ @@ -125,17 +97,7 @@ #error "pthreads is not supported for this architecture" #endif -#if defined(_PR_DCETHREADS) -#define _PT_PTHREAD_ATTR_INIT pthread_attr_create -#define _PT_PTHREAD_ATTR_DESTROY pthread_attr_delete -#define _PT_PTHREAD_CREATE(t, a, f, r) pthread_create(t, a, f, r) -#define _PT_PTHREAD_KEY_CREATE pthread_keycreate -#define _PT_PTHREAD_ATTR_SETSCHEDPOLICY pthread_attr_setsched -#define _PT_PTHREAD_ATTR_GETSTACKSIZE(a, s) \ - (*(s) = pthread_attr_getstacksize(*(a)), 0) -#define _PT_PTHREAD_GETSPECIFIC(k, r) \ - pthread_getspecific((k), (pthread_addr_t *) &(r)) -#elif defined(_PR_PTHREADS) +#if defined(_PR_PTHREADS) #define _PT_PTHREAD_ATTR_INIT pthread_attr_init #define _PT_PTHREAD_ATTR_DESTROY pthread_attr_destroy #define _PT_PTHREAD_CREATE(t, a, f, r) pthread_create(t, &a, f, r) @@ -147,22 +109,6 @@ #error "Cannot determine pthread strategy" #endif -#if defined(_PR_DCETHREADS) -#define _PT_PTHREAD_EXPLICIT_SCHED _PT_PTHREAD_DEFAULT_SCHED -#endif - -/* - * pthread_mutex_trylock returns different values in DCE threads and - * pthreads. - */ -#if defined(_PR_DCETHREADS) -#define PT_TRYLOCK_SUCCESS 1 -#define PT_TRYLOCK_BUSY 0 -#else -#define PT_TRYLOCK_SUCCESS 0 -#define PT_TRYLOCK_BUSY EBUSY -#endif - /* * These platforms don't have sigtimedwait() */ @@ -190,16 +136,9 @@ #define PT_PRIO_MIN DEFAULT_PRIO #define PT_PRIO_MAX DEFAULT_PRIO #elif defined(HPUX) - -#if defined(_PR_DCETHREADS) -#define PT_PRIO_MIN PRI_OTHER_MIN -#define PT_PRIO_MAX PRI_OTHER_MAX -#else /* defined(_PR_DCETHREADS) */ #include <sys/sched.h> #define PT_PRIO_MIN sched_get_priority_min(SCHED_OTHER) #define PT_PRIO_MAX sched_get_priority_max(SCHED_OTHER) -#endif /* defined(_PR_DCETHREADS) */ - #elif defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \ || defined(FREEBSD) || defined(SYMBIAN) #define PT_PRIO_MIN sched_get_priority_min(SCHED_OTHER) @@ -238,9 +177,7 @@ * Needed for garbage collection -- Look at PR_Suspend/PR_Resume * implementation. */ -#if defined(_PR_DCETHREADS) -#define _PT_PTHREAD_YIELD() pthread_yield() -#elif defined(OSF1) +#if defined(OSF1) /* * sched_yield can't be called from a signal handler. Must use * the _np version. diff --git a/nsprpub/pr/include/md/_win95.h b/nsprpub/pr/include/md/_win95.h index d65e26437..04f811d37 100644 --- a/nsprpub/pr/include/md/_win95.h +++ b/nsprpub/pr/include/md/_win95.h @@ -290,6 +290,9 @@ extern void _MD_MakeNonblock(PRFileDesc *f); extern PRInt32 _MD_CloseSocket(PROsfd osfd); #define _MD_CLOSE_SOCKET _MD_CloseSocket #define _MD_SENDTO _PR_MD_SENDTO +#ifdef _WIN64 +#define _MD_TCPSENDTO _PR_MD_TCPSENDTO +#endif #define _MD_RECVFROM _PR_MD_RECVFROM #define _MD_SOCKETPAIR(s, type, proto, sv) -1 #define _MD_GETSOCKNAME _PR_MD_GETSOCKNAME diff --git a/nsprpub/pr/include/prinet.h b/nsprpub/pr/include/prinet.h index 15d229fe4..fc9f73918 100644 --- a/nsprpub/pr/include/prinet.h +++ b/nsprpub/pr/include/prinet.h @@ -54,7 +54,7 @@ struct sockaddr_dl; #endif /* XP_UNIX */ #include <netdb.h> -#if defined(FREEBSD) || defined(BSDI) || defined(QNX) +#if defined(BSDI) || defined(QNX) #include <rpc/types.h> /* the only place that defines INADDR_LOOPBACK */ #endif diff --git a/nsprpub/pr/include/prinit.h b/nsprpub/pr/include/prinit.h index e27fc34d0..c55788923 100644 --- a/nsprpub/pr/include/prinit.h +++ b/nsprpub/pr/include/prinit.h @@ -31,10 +31,10 @@ PR_BEGIN_EXTERN_C ** The format of the version string is ** "<major version>.<minor version>[.<patch level>] [<Beta>]" */ -#define PR_VERSION "4.13.1" +#define PR_VERSION "4.18" #define PR_VMAJOR 4 -#define PR_VMINOR 13 -#define PR_VPATCH 1 +#define PR_VMINOR 18 +#define PR_VPATCH 0 #define PR_BETA PR_FALSE /* diff --git a/nsprpub/pr/include/private/primpl.h b/nsprpub/pr/include/private/primpl.h index 63ba3ee46..a817c206c 100644 --- a/nsprpub/pr/include/private/primpl.h +++ b/nsprpub/pr/include/private/primpl.h @@ -6,14 +6,6 @@ #ifndef primpl_h___ #define primpl_h___ -/* - * HP-UX 10.10's pthread.h (DCE threads) includes dce/cma.h, which - * has: - * #define sigaction _sigaction_sys - * This macro causes chaos if signal.h gets included before pthread.h. - * To be safe, we include pthread.h first. - */ - #if defined(_PR_PTHREADS) #include <pthread.h> #endif @@ -1225,6 +1217,13 @@ extern PRInt32 _PR_MD_SENDTO( const PRNetAddr *addr, PRUint32 addrlen, PRIntervalTime timeout); #define _PR_MD_SENDTO _MD_SENDTO +#if defined(_WIN64) && defined(WIN95) +extern PRInt32 _PR_MD_TCPSENDTO( + PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, + const PRNetAddr *addr, PRUint32 addrlen, PRIntervalTime timeout); +#define _PR_MD_TCPSENDTO _MD_TCPSENDTO +#endif + extern PRInt32 _PR_MD_SOCKETPAIR(int af, int type, int flags, PROsfd *osfd); #define _PR_MD_SOCKETPAIR _MD_SOCKETPAIR @@ -1747,6 +1746,18 @@ struct PRFilePrivate { * requires knowing the address family of the * socket, we save the address family here. */ #endif + +#if defined(_WIN64) + /* This is necessary for TCP Fast Open. TCP Fast Open in windows must + * use ConnectEx function which uses OVERLAPPED. TCPSendTo will call + * ConnectEx to send fast open data. If ConnectEx returns + * ERROR_IO_PENDING we need to save OVERLAPPED structure and we will + * use it in ConnectContinue to get the final result of ConnectEx. + */ + PRBool alreadyConnected; + PRBool overlappedActive; + OVERLAPPED ol; +#endif }; #ifdef _WIN64 @@ -1858,7 +1869,7 @@ extern PRFileDesc *_pr_stderr; ** and functions with macros that expand to the native thread ** types and functions on each platform. */ -#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) +#if defined(_PR_PTHREADS) #define _PR_ZONE_ALLOCATOR #endif @@ -2146,6 +2157,18 @@ extern PRUint32 connectCount; #endif /* XP_BEOS */ +#if defined(_WIN64) && defined(WIN95) +typedef struct _PRFileDescList { + PRFileDesc *fd; + struct _PRFileDescList *next; +} PRFileDescList; + +extern PRLock *_fd_waiting_for_overlapped_done_lock; +extern PRFileDescList *_fd_waiting_for_overlapped_done; +extern void CheckOverlappedPendingSocketsAreDone(); +#endif + + PR_END_EXTERN_C #endif /* primpl_h___ */ diff --git a/nsprpub/pr/include/prtypes.h b/nsprpub/pr/include/prtypes.h index 52b3ab0b1..94bca3cfc 100644 --- a/nsprpub/pr/include/prtypes.h +++ b/nsprpub/pr/include/prtypes.h @@ -231,7 +231,7 @@ PR_BEGIN_EXTERN_C ** to use <stdint.h>. A patch to do that is in NSPR bug 634793. */ -#if defined(__APPLE__) || defined(__ANDROID__) || defined(__OpenBSD__) +#if defined(__APPLE__) || defined(__OpenBSD__) #define PR_ALTERNATE_INT64_TYPEDEF #endif @@ -245,16 +245,24 @@ PR_BEGIN_EXTERN_C #if PR_BYTES_PER_BYTE == 1 typedef unsigned char PRUint8; /* +** There are two scenarios that require us to define PRInt8 as type 'char'. +** (1) ** Some cfront-based C++ compilers do not like 'signed char' and ** issue the warning message: ** warning: "signed" not implemented (ignored) ** For these compilers, we have to define PRInt8 as plain 'char'. ** Make sure that plain 'char' is indeed signed under these compilers. +** (2) +** Mozilla C++ code expects the PRInt{N} and int{N}_t types to match (see bug +** 634793). If a platform defines int8_t as 'char', but NSPR defines it as +** 'signed char', it results in a type mismatch. +** On such platforms we define PRInt8 as 'char' to avoid the mismatch. */ -#if (defined(HPUX) && defined(__cplusplus) \ +#if (defined(HPUX) && defined(__cplusplus) /* reason 1*/ \ && !defined(__GNUC__) && __cplusplus < 199707L) \ - || (defined(SCO) && defined(__cplusplus) \ - && !defined(__GNUC__) && __cplusplus == 1L) + || (defined(SCO) && defined(__cplusplus) /* reason 1 */ \ + && !defined(__GNUC__) && __cplusplus == 1L) \ + || (defined(__sun) && defined(__cplusplus)) /* reason 2 */ typedef char PRInt8; #else typedef signed char PRInt8; diff --git a/nsprpub/pr/src/Makefile.in b/nsprpub/pr/src/Makefile.in index 48b6faed7..19c5a6987 100644 --- a/nsprpub/pr/src/Makefile.in +++ b/nsprpub/pr/src/Makefile.in @@ -138,12 +138,8 @@ endif ifeq ($(OS_ARCH),HP-UX) ifeq ($(USE_PTHREADS), 1) -ifeq (,$(filter-out B.10.10 B.10.20,$(OS_RELEASE))) -OS_LIBS = -ldce -else OS_LIBS = -lpthread -lrt endif -endif ifeq ($(PTHREADS_USER), 1) OS_LIBS = -lpthread endif diff --git a/nsprpub/pr/src/io/prio.c b/nsprpub/pr/src/io/prio.c index 78cbdf564..10ae5e098 100644 --- a/nsprpub/pr/src/io/prio.c +++ b/nsprpub/pr/src/io/prio.c @@ -119,6 +119,10 @@ PR_IMPLEMENT(PRFileDesc*) PR_AllocFileDesc( fd->methods = methods; fd->secret->state = _PR_FILEDESC_OPEN; fd->secret->md.osfd = osfd; +#if defined(_WIN64) + fd->secret->alreadyConnected = PR_FALSE; + fd->secret->overlappedActive = PR_FALSE; +#endif _PR_MD_INIT_FILEDESC(fd); } else { PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); @@ -133,11 +137,82 @@ PR_IMPLEMENT(void) PR_FreeFileDesc(PRFileDesc *fd) _PR_Putfd(fd); } +#if defined(_WIN64) && defined(WIN95) + +PRFileDescList *_fd_waiting_for_overlapped_done = NULL; +PRLock *_fd_waiting_for_overlapped_done_lock = NULL; + +void CheckOverlappedPendingSocketsAreDone() +{ + if (!_fd_waiting_for_overlapped_done_lock || + !_fd_waiting_for_overlapped_done) { + return; + } + + PR_Lock(_fd_waiting_for_overlapped_done_lock); + + PRFileDescList *cur = _fd_waiting_for_overlapped_done; + PRFileDescList *previous = NULL; + while (cur) { + PR_ASSERT(cur->fd->secret->overlappedActive); + PRFileDesc *fd = cur->fd; + DWORD rvSent; + if (GetOverlappedResult((HANDLE)fd->secret->md.osfd, &fd->secret->ol, &rvSent, FALSE) == TRUE) { + fd->secret->overlappedActive = PR_FALSE; + PR_LOG(_pr_io_lm, PR_LOG_MIN, + ("CheckOverlappedPendingSocketsAreDone GetOverlappedResult succeeded\n")); + } else { + DWORD err = WSAGetLastError(); + PR_LOG(_pr_io_lm, PR_LOG_MIN, + ("CheckOverlappedPendingSocketsAreDone GetOverlappedResult failed %d\n", err)); + if (err != ERROR_IO_INCOMPLETE) { + fd->secret->overlappedActive = PR_FALSE; + } + } + + if (!fd->secret->overlappedActive) { + + _PR_MD_CLOSE_SOCKET(fd->secret->md.osfd); + fd->secret->state = _PR_FILEDESC_CLOSED; +#ifdef _PR_HAVE_PEEK_BUFFER + if (fd->secret->peekBuffer) { + PR_ASSERT(fd->secret->peekBufSize > 0); + PR_DELETE(fd->secret->peekBuffer); + fd->secret->peekBufSize = 0; + fd->secret->peekBytes = 0; + } +#endif + + PR_FreeFileDesc(fd); + + if (previous) { + previous->next = cur->next; + } else { + _fd_waiting_for_overlapped_done = cur->next; + } + PRFileDescList *del = cur; + cur = cur->next; + PR_Free(del); + } else { + previous = cur; + cur = cur->next; + } + } + + PR_Unlock(_fd_waiting_for_overlapped_done_lock); +} +#endif + /* ** Wait for some i/o to finish on one or more more poll descriptors. */ PR_IMPLEMENT(PRInt32) PR_Poll(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout) { +#if defined(_WIN64) && defined(WIN95) + // For each iteration check if TFO overlapped IOs are down. + CheckOverlappedPendingSocketsAreDone(); +#endif + return(_PR_MD_PR_POLL(pds, npds, timeout)); } diff --git a/nsprpub/pr/src/io/prlayer.c b/nsprpub/pr/src/io/prlayer.c index cadb7ca3c..00da0287a 100644 --- a/nsprpub/pr/src/io/prlayer.c +++ b/nsprpub/pr/src/io/prlayer.c @@ -47,7 +47,8 @@ static PRStatus PR_CALLBACK pl_TopClose (PRFileDesc *fd) rv = fd->lower->methods->close(fd->lower); _PR_DestroyIOLayer(fd); return rv; - } else if ((fd->higher) && (PR_IO_LAYER_HEAD == fd->higher->identity)) { + } + if ((fd->higher) && (PR_IO_LAYER_HEAD == fd->higher->identity)) { /* * lower layers of new style stack */ @@ -201,16 +202,16 @@ static PRFileDesc* PR_CALLBACK pl_TopAccept ( return NULL; } - if (newstyle_stack) { - newstack->lower = newfd; - newfd->higher = newstack; - return newstack; - } else { - /* this PR_PushIOLayer call cannot fail */ - rv = PR_PushIOLayer(newfd, PR_TOP_IO_LAYER, newstack); - PR_ASSERT(PR_SUCCESS == rv); - return newfd; /* that's it */ - } + if (newstyle_stack) + { + newstack->lower = newfd; + newfd->higher = newstack; + return newstack; + } + /* this PR_PushIOLayer call cannot fail */ + rv = PR_PushIOLayer(newfd, PR_TOP_IO_LAYER, newstack); + PR_ASSERT(PR_SUCCESS == rv); + return newfd; /* that's it */ } static PRStatus PR_CALLBACK pl_DefBind (PRFileDesc *fd, const PRNetAddr *addr) @@ -326,12 +327,11 @@ static PRInt32 PR_CALLBACK pl_DefAcceptread ( (*nd)->higher = newstack; *nd = newstack; return nbytes; - } else { - /* this PR_PushIOLayer call cannot fail */ - rv = PR_PushIOLayer(*nd, PR_TOP_IO_LAYER, newstack); - PR_ASSERT(PR_SUCCESS == rv); - return nbytes; } + /* this PR_PushIOLayer call cannot fail */ + rv = PR_PushIOLayer(*nd, PR_TOP_IO_LAYER, newstack); + PR_ASSERT(PR_SUCCESS == rv); + return nbytes; } static PRInt32 PR_CALLBACK pl_DefTransmitfile ( @@ -494,10 +494,9 @@ static PRStatus _PR_DestroyIOLayer(PRFileDesc *stack) { if (NULL == stack) return PR_FAILURE; - else { - PR_DELETE(stack); - return PR_SUCCESS; - } + + PR_DELETE(stack); + return PR_SUCCESS; } /* _PR_DestroyIOLayer */ PR_IMPLEMENT(PRStatus) PR_PushIOLayer( @@ -652,9 +651,11 @@ retry: if ((NULL != names) && (identity < length)) { /* what we did is still okay */ - memcpy( - names, identity_cache.name, - identity_cache.length * sizeof(char*)); + if (identity_cache.length != 0) { + memcpy( + names, identity_cache.name, + identity_cache.length * sizeof(char*)); + } old = identity_cache.name; identity_cache.name = names; identity_cache.length = length; @@ -702,8 +703,8 @@ PR_IMPLEMENT(PRDescIdentity) PR_GetLayersIdentity(PRFileDesc* fd) if (PR_IO_LAYER_HEAD == fd->identity) { PR_ASSERT(NULL != fd->lower); return fd->lower->identity; - } else - return fd->identity; + } + return fd->identity; } /* PR_GetLayersIdentity */ PR_IMPLEMENT(PRFileDesc*) PR_GetIdentitiesLayer(PRFileDesc* fd, PRDescIdentity id) @@ -711,10 +712,10 @@ PR_IMPLEMENT(PRFileDesc*) PR_GetIdentitiesLayer(PRFileDesc* fd, PRDescIdentity i PRFileDesc *layer = fd; if (PR_TOP_IO_LAYER == id) { - if (PR_IO_LAYER_HEAD == fd->identity) - return fd->lower; - else - return fd; + if (PR_IO_LAYER_HEAD == fd->identity) { + return fd->lower; + } + return fd; } for (layer = fd; layer != NULL; layer = layer->lower) diff --git a/nsprpub/pr/src/io/prmmap.c b/nsprpub/pr/src/io/prmmap.c index 6ffc13305..64f7ed4e8 100644 --- a/nsprpub/pr/src/io/prmmap.c +++ b/nsprpub/pr/src/io/prmmap.c @@ -24,17 +24,16 @@ PR_IMPLEMENT(PRFileMap *) PR_CreateFileMap( || prot == PR_PROT_WRITECOPY); fmap = PR_NEWZAP(PRFileMap); if (NULL == fmap) { - PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); - return NULL; + PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); + return NULL; } fmap->fd = fd; fmap->prot = prot; if (_PR_MD_CREATE_FILE_MAP(fmap, size) == PR_SUCCESS) { - return fmap; - } else { + return fmap; + } PR_DELETE(fmap); return NULL; - } } PR_IMPLEMENT(PRInt32) PR_GetMemMapAlignment(void) diff --git a/nsprpub/pr/src/io/prscanf.c b/nsprpub/pr/src/io/prscanf.c index 9d75d824e..377a6e643 100644 --- a/nsprpub/pr/src/io/prscanf.c +++ b/nsprpub/pr/src/io/prscanf.c @@ -409,7 +409,8 @@ Convert(ScanfState *state, const char *fmt) ch = GET(state); if (ch == EOF) { return NULL; - } else if (state->assign) { + } + if (state->assign) { *cArg++ = ch; } } @@ -602,10 +603,9 @@ StringGetChar(void *stream) if (*cPtr == '\0') { return EOF; - } else { - *((char **) stream) = cPtr + 1; - return (unsigned char) *cPtr; } + *((char **) stream) = cPtr + 1; + return (unsigned char) *cPtr; } static void diff --git a/nsprpub/pr/src/io/prsocket.c b/nsprpub/pr/src/io/prsocket.c index be9702408..26f7a245d 100644 --- a/nsprpub/pr/src/io/prsocket.c +++ b/nsprpub/pr/src/io/prsocket.c @@ -7,6 +7,12 @@ #include <string.h> +#if defined(_WIN64) +#ifndef SO_UPDATE_CONNECT_CONTEXT +#define SO_UPDATE_CONNECT_CONTEXT 0x7010 +#endif +#endif + /************************************************************************/ /* These two functions are only used in assertions. */ @@ -298,12 +304,72 @@ static PRStatus PR_CALLBACK SocketConnectContinue( if (err != 0) { _PR_MD_MAP_CONNECT_ERROR(err); } else { +#if defined(_WIN64) + if (fd->secret->overlappedActive) { + PRInt32 rvSent; + if (GetOverlappedResult(osfd, &fd->secret->ol, &rvSent, FALSE) == FALSE) { + err = WSAGetLastError(); + PR_LOG(_pr_io_lm, PR_LOG_MIN, + ("SocketConnectContinue GetOverlappedResult failed %d\n", err)); + if (err != ERROR_IO_INCOMPLETE) { + _PR_MD_MAP_CONNECT_ERROR(err); + fd->secret->overlappedActive = PR_FALSE; + } + } + } + if (err == 0) { + PR_SetError(PR_UNKNOWN_ERROR, 0); + } +#else PR_SetError(PR_UNKNOWN_ERROR, 0); +#endif } return PR_FAILURE; } PR_ASSERT(out_flags & PR_POLL_WRITE); + +#if defined(_WIN64) + if (fd->secret->alreadyConnected) { + fd->secret->alreadyConnected = PR_FALSE; + } + /* TCP Fast Open on Windows must use ConnectEx, which uses overlapped + * input/output. + * To get result we need to use GetOverlappedResult. */ + if (fd->secret->overlappedActive) { + PR_ASSERT(fd->secret->nonblocking); + PRInt32 rvSent; + if (GetOverlappedResult(osfd, &fd->secret->ol, &rvSent, FALSE) == TRUE) { + fd->secret->overlappedActive = PR_FALSE; + PR_LOG(_pr_io_lm, PR_LOG_MIN, + ("SocketConnectContinue GetOverlappedResult succeeded\n")); + /* When ConnectEx is used, all previously set socket options and + * property are not enabled and to enable them + * SO_UPDATE_CONNECT_CONTEXT option need to be set. */ + if (setsockopt((SOCKET)osfd, SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, NULL, 0) != 0) { + err = WSAGetLastError(); + PR_LOG(_pr_io_lm, PR_LOG_MIN, + ("SocketConnectContinue setting SO_UPDATE_CONNECT_CONTEXT failed %d\n", err)); + _PR_MD_MAP_SETSOCKOPT_ERROR(err); + return PR_FAILURE; + } + return PR_SUCCESS; + } else { + err = WSAGetLastError(); + PR_LOG(_pr_io_lm, PR_LOG_MIN, + ("SocketConnectContinue GetOverlappedResult failed %d\n", err)); + if (err != ERROR_IO_INCOMPLETE) { + _PR_MD_MAP_CONNECT_ERROR(err); + fd->secret->overlappedActive = PR_FALSE; + return PR_FAILURE; + } else { + PR_SetError(PR_IN_PROGRESS_ERROR, 0); + return PR_FAILURE; + } + } + } +#endif + return PR_SUCCESS; #elif defined(XP_OS2) @@ -671,6 +737,56 @@ static PRStatus PR_CALLBACK SocketClose(PRFileDesc *fd) } if (fd->secret->state == _PR_FILEDESC_OPEN) { +#if defined(_WIN64) && defined(WIN95) + /* TCP Fast Open on Windows must use ConnectEx, which uses overlapped + * input/output. Before closing such a socket we must cancelIO. + */ + if (fd->secret->overlappedActive) { + PR_ASSERT(fd->secret->nonblocking); + if (CancelIo((HANDLE) fd->secret->md.osfd) == TRUE) { + PR_LOG(_pr_io_lm, PR_LOG_MIN, + ("SocketClose - CancelIo succeeded\n")); + } else { + DWORD err = WSAGetLastError(); + PR_LOG(_pr_io_lm, PR_LOG_MIN, + ("SocketClose - CancelIo failed err=%x\n", err)); + } + + DWORD rvSent; + if (GetOverlappedResult((HANDLE)fd->secret->md.osfd, &fd->secret->ol, &rvSent, FALSE) == TRUE) { + fd->secret->overlappedActive = PR_FALSE; + PR_LOG(_pr_io_lm, PR_LOG_MIN, + ("SocketClose GetOverlappedResult succeeded\n")); + } else { + DWORD err = WSAGetLastError(); + PR_LOG(_pr_io_lm, PR_LOG_MIN, + ("SocketClose GetOverlappedResult failed %d\n", err)); + if (err != ERROR_IO_INCOMPLETE) { + _PR_MD_MAP_CONNECT_ERROR(err); + fd->secret->overlappedActive = PR_FALSE; + } + } + } + + if (fd->secret->overlappedActive && + _fd_waiting_for_overlapped_done_lock) { + // Put osfd into the list to be checked later. + PRFileDescList *forWaiting = PR_NEW(PRFileDescList); + if (!forWaiting) { + PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); + return PR_FAILURE; + } + forWaiting->fd = fd; + + PR_Lock(_fd_waiting_for_overlapped_done_lock); + forWaiting->next = _fd_waiting_for_overlapped_done; + _fd_waiting_for_overlapped_done = forWaiting; + PR_Unlock(_fd_waiting_for_overlapped_done_lock); + + return PR_SUCCESS; + } +#endif + if (_PR_MD_CLOSE_SOCKET(fd->secret->md.osfd) < 0) { return PR_FAILURE; } @@ -751,7 +867,7 @@ static PRInt32 PR_CALLBACK SocketSendTo( #endif count = 0; - while (amount > 0) { + do { temp = _PR_MD_SENDTO(fd, buf, amount, flags, addrp, PR_NETADDR_SIZE(addr), timeout); if (temp < 0) { @@ -764,10 +880,60 @@ static PRInt32 PR_CALLBACK SocketSendTo( } buf = (const void*) ((const char*)buf + temp); amount -= temp; - } + } while (amount > 0); return count; } +#if defined(_WIN64) && defined(WIN95) +static PRInt32 PR_CALLBACK SocketTCPSendTo( + PRFileDesc *fd, const void *buf, PRInt32 amount, + PRIntn flags, const PRNetAddr *addr, PRIntervalTime timeout) +{ + PRInt32 temp, count; + const PRNetAddr *addrp = addr; +#if defined(_PR_INET6) + PRNetAddr addrCopy; +#endif + PRThread *me = _PR_MD_CURRENT_THREAD(); + + if (_PR_PENDING_INTERRUPT(me)) { + me->flags &= ~_PR_INTERRUPT; + PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0); + return -1; + } + if (_PR_IO_PENDING(me)) { + PR_SetError(PR_IO_PENDING_ERROR, 0); + return -1; + } + + PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE); +#if defined(_PR_INET6) + if (addr->raw.family == PR_AF_INET6) { + addrCopy = *addr; + addrCopy.raw.family = AF_INET6; + addrp = &addrCopy; + } +#endif + + count = 0; + while (amount > 0) { + temp = _PR_MD_TCPSENDTO(fd, buf, amount, flags, + addrp, PR_NETADDR_SIZE(addr), timeout); + if (temp < 0) { + count = -1; + break; + } + count += temp; + if (fd->secret->nonblocking) { + break; + } + buf = (const void*) ((const char*)buf + temp); + amount -= temp; + } + return count; +} +#endif + static PRInt32 PR_CALLBACK SocketRecvFrom(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout) { @@ -1066,6 +1232,15 @@ static PRInt16 PR_CALLBACK SocketPoll( PRFileDesc *fd, PRInt16 in_flags, PRInt16 *out_flags) { *out_flags = 0; + +#if defined(_WIN64) + if (in_flags & PR_POLL_WRITE) { + if (fd->secret->alreadyConnected) { + out_flags = PR_POLL_WRITE; + return PR_POLL_WRITE; + } + } +#endif return in_flags; } /* SocketPoll */ @@ -1090,7 +1265,11 @@ static PRIOMethods tcpMethods = { SocketRecv, SocketSend, (PRRecvfromFN)_PR_InvalidInt, +#if defined(_WIN64) && defined(WIN95) + SocketTCPSendTo, /* This is for fast open. We imitate Linux interface. */ +#else (PRSendtoFN)_PR_InvalidInt, +#endif SocketPoll, SocketAcceptRead, SocketTransmitFile, diff --git a/nsprpub/pr/src/md/unix/unix.c b/nsprpub/pr/src/md/unix/unix.c index fdae1199c..29e24e574 100644 --- a/nsprpub/pr/src/md/unix/unix.c +++ b/nsprpub/pr/src/md/unix/unix.c @@ -2854,28 +2854,11 @@ void _PR_UnixInit(void) #endif #endif /* !defined(_PR_PTHREADS) */ - /* - * Under HP-UX DCE threads, sigaction() installs a per-thread - * handler, so we use sigvector() to install a process-wide - * handler. - */ -#if defined(HPUX) && defined(_PR_DCETHREADS) - { - struct sigvec vec; - - vec.sv_handler = SIG_IGN; - vec.sv_mask = 0; - vec.sv_flags = 0; - rv = sigvector(SIGPIPE, &vec, NULL); - PR_ASSERT(0 == rv); - } -#else sigact.sa_handler = SIG_IGN; sigemptyset(&sigact.sa_mask); sigact.sa_flags = 0; rv = sigaction(SIGPIPE, &sigact, 0); PR_ASSERT(0 == rv); -#endif /* HPUX && _PR_DCETHREADS */ _pr_rename_lock = PR_NewLock(); PR_ASSERT(NULL != _pr_rename_lock); @@ -3316,11 +3299,11 @@ int _MD_unix_get_nonblocking_connect_error(int osfd) return errno; } else { return err; - } + } } } else { return ECONNREFUSED; - } + } #elif defined(UNIXWARE) /* * getsockopt() fails with EPIPE, so use getmsg() instead. @@ -3331,17 +3314,17 @@ 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 */ + 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; - } else { - 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 } diff --git a/nsprpub/pr/src/md/unix/uxproces.c b/nsprpub/pr/src/md/unix/uxproces.c index a3b35e540..18f23fde8 100644 --- a/nsprpub/pr/src/md/unix/uxproces.c +++ b/nsprpub/pr/src/md/unix/uxproces.c @@ -247,13 +247,14 @@ ForkAndExec( 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 (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 (attr) { @@ -498,10 +499,9 @@ ExtractExitStatus(int rawExitStatus) #endif if (WIFEXITED(rawExitStatus)) { return WEXITSTATUS(rawExitStatus); - } else { + } PR_ASSERT(WIFSIGNALED(rawExitStatus)); return _PR_SIGNALED_EXITSTATUS; - } } static void @@ -624,8 +624,8 @@ static void WaitPidDaemonThread(void *unused) } while (sizeof(buf) == rv || (-1 == rv && EINTR == errno)); #ifdef _PR_SHARE_CLONES - 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) { @@ -639,8 +639,8 @@ static void WaitPidDaemonThread(void *unused) } op->done = PR_TRUE; PR_NotifyCondVar(op->doneCV); - PR_Unlock(pr_wp.ml); } + PR_Unlock(pr_wp.ml); #endif while (1) { @@ -685,10 +685,6 @@ static void pr_SigchldHandler(int sig) static void pr_InstallSigchldHandler() { -#if defined(HPUX) && defined(_PR_DCETHREADS) -#error "HP-UX DCE threads have their own SIGCHLD handler" -#endif - struct sigaction act, oact; int rv; diff --git a/nsprpub/pr/src/md/unix/uxshm.c b/nsprpub/pr/src/md/unix/uxshm.c index dec4e3a7a..54e68191c 100644 --- a/nsprpub/pr/src/md/unix/uxshm.c +++ b/nsprpub/pr/src/md/unix/uxshm.c @@ -76,8 +76,8 @@ extern PRSharedMemory * _MD_OpenSharedMemory( /* copy args to struct */ strcpy( shm->ipcname, ipcname ); - shm->size = size; - shm->mode = mode; + shm->size = size; + shm->mode = mode; shm->flags = flags; shm->ident = _PR_SHM_IDENT; @@ -500,30 +500,32 @@ extern PRFileMap* _md_OpenAnonFileMap( ("_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 ) { - PR_smprintf_free( genName ); - continue; /* name exists, try again */ - } else { - _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; - } + osfd = open(genName, (O_CREAT | O_EXCL | O_RDWR), mode); + if (-1 == osfd) { + 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); + 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; + if (incr == maxTries) { + PR_ASSERT(-1 == osfd); + PR_ASSERT(EEXIST == errno); + _PR_MD_MAP_OPEN_ERROR(errno); + goto Finished; } urc = unlink( genName ); diff --git a/nsprpub/pr/src/md/windows/ntthread.c b/nsprpub/pr/src/md/windows/ntthread.c index fead1236d..1fdf0e93b 100644 --- a/nsprpub/pr/src/md/windows/ntthread.c +++ b/nsprpub/pr/src/md/windows/ntthread.c @@ -27,6 +27,9 @@ PRUint32 _nt_idleCount; extern __declspec(thread) PRThread *_pr_io_restarted_io; extern DWORD _pr_io_restartedIOIndex; +typedef HRESULT (WINAPI *SETTHREADDESCRIPTION)(HANDLE, PCWSTR); +static SETTHREADDESCRIPTION sSetThreadDescription = NULL; + /* Must check the restarted_io *before* decrementing no_sched to 0 */ #define POST_SWITCH_WORK() \ PR_BEGIN_MACRO \ @@ -79,6 +82,8 @@ _nt_handle_restarted_io(PRThread *restarted_io) void _PR_MD_EARLY_INIT() { + HMODULE hModule; + _MD_NEW_LOCK( &_nt_idleLock ); _nt_idleCount = 0; PR_INIT_CLIST(&_nt_idleList); @@ -98,6 +103,15 @@ _PR_MD_EARLY_INIT() _pr_intsOffIndex = TlsAlloc(); _pr_io_restartedIOIndex = TlsAlloc(); } + + // SetThreadDescription is Windows 10 build 1607+ + hModule = GetModuleHandleW(L"kernel32.dll"); + if (hModule) { + sSetThreadDescription = + (SETTHREADDESCRIPTION) GetProcAddress( + hModule, + "SetThreadDescription"); + } } void _PR_MD_CLEANUP_BEFORE_EXIT(void) @@ -293,7 +307,16 @@ _PR_MD_SET_CURRENT_THREAD_NAME(const char *name) { #ifdef _MSC_VER THREADNAME_INFO info; +#endif + + 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; diff --git a/nsprpub/pr/src/md/windows/w32poll.c b/nsprpub/pr/src/md/windows/w32poll.c index 84100763b..daf14dfe0 100644 --- a/nsprpub/pr/src/md/windows/w32poll.c +++ b/nsprpub/pr/src/md/windows/w32poll.c @@ -155,7 +155,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout) pd->out_flags = 0; /* pre-condition */ /* make sure this is an NSPR supported stack */ bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER); - // ignore a socket without PR_NSPR_IO_LAYER available. + /* ignore a socket without PR_NSPR_IO_LAYER available */ if ((NULL != bottom) && (_PR_FILEDESC_OPEN == bottom->secret->state)) diff --git a/nsprpub/pr/src/md/windows/w95sock.c b/nsprpub/pr/src/md/windows/w95sock.c index 1c3ddd911..c6a3ec111 100644 --- a/nsprpub/pr/src/md/windows/w95sock.c +++ b/nsprpub/pr/src/md/windows/w95sock.c @@ -294,8 +294,7 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, PRInt32 rv, err; PRInt32 bytesSent = 0; - while(bytesSent < amount) - { + do { while ((rv = sendto( osfd, buf, amount, 0, (struct sockaddr *) addr, addrlen)) == -1) { @@ -327,10 +326,182 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, return -1; } } - } + } while(bytesSent < amount); return bytesSent; } +#if defined(_WIN64) + +static PRCallOnceType _pr_has_connectex_once; +typedef BOOL (PASCAL FAR * _pr_win_connectex_ptr)(_In_ SOCKET s, _In_reads_bytes_(namelen) const struct sockaddr FAR *name, _In_ int namelen, _In_reads_bytes_opt_(dwSendDataLength) PVOID lpSendBuffer, _In_ DWORD dwSendDataLength, _Out_ LPDWORD lpdwBytesSent, _Inout_ LPOVERLAPPED lpOverlapped); + +#ifndef WSAID_CONNECTEX +#define WSAID_CONNECTEX \ + {0x25a207b9,0xddf3,0x4660,{0x8e,0xe9,0x76,0xe5,0x8c,0x74,0x06,0x3e}} +#endif +#ifndef SIO_GET_EXTENSION_FUNCTION_POINTER +#define SIO_GET_EXTENSION_FUNCTION_POINTER 0xC8000006 +#endif +#ifndef TCP_FASTOPEN +#define TCP_FASTOPEN 15 +#endif + +#ifndef SO_UPDATE_CONNECT_CONTEXT +#define SO_UPDATE_CONNECT_CONTEXT 0x7010 +#endif + +static _pr_win_connectex_ptr _pr_win_connectex = NULL; + +static PRStatus PR_CALLBACK _pr_set_connectex(void) +{ + _pr_win_connectex = NULL; + SOCKET sock; + PRInt32 dwBytes; + int rc; + + /* Dummy socket needed for WSAIoctl */ + sock = socket(AF_INET, SOCK_STREAM, 0); + if (sock == INVALID_SOCKET) + return PR_SUCCESS; + + GUID guid = WSAID_CONNECTEX; + rc = WSAIoctl(sock, SIO_GET_EXTENSION_FUNCTION_POINTER, + &guid, sizeof(guid), + &_pr_win_connectex, sizeof(_pr_win_connectex), + &dwBytes, NULL, NULL); + if (rc != 0) { + _pr_win_connectex = NULL; + return PR_SUCCESS; + } + + rc = closesocket(sock); + return PR_SUCCESS; +} + +PRInt32 +_PR_MD_TCPSENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, + const PRNetAddr *addr, PRUint32 addrlen, PRIntervalTime timeout) +{ + if (!_fd_waiting_for_overlapped_done_lock) { + PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0); + return PR_FAILURE; + } + + if (PR_CallOnce(&_pr_has_connectex_once, _pr_set_connectex) != PR_SUCCESS) { + PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0); + return PR_FAILURE; + } + + if (_pr_win_connectex == NULL) { + PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0); + return PR_FAILURE; + } + + PROsfd osfd = fd->secret->md.osfd; + PRInt32 rv, err; + PRInt32 bytesSent = 0; + DWORD rvSent; + + BOOL option = 1; + rv = setsockopt((SOCKET)osfd, IPPROTO_TCP, TCP_FASTOPEN, (char*)&option, sizeof(option)); + if (rv != 0) { + err = WSAGetLastError(); + PR_LOG(_pr_io_lm, PR_LOG_MIN, + ("_PR_MD_TCPSENDTO error set opt TCP_FASTOPEN failed %d\n", err)); + if (err == WSAENOPROTOOPT) { + PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0); + } else { + _PR_MD_MAP_SETSOCKOPT_ERROR(err); + } + return -1; + } + + /* ConnectEx requires the socket to be initially bound. We will use INADDR_ANY. */ + PRNetAddr bindAddr; + memset(&bindAddr, 0, sizeof(bindAddr)); + bindAddr.raw.family = addr->raw.family; + + rv = bind((SOCKET)osfd, (const struct sockaddr *)&(bindAddr.inet), PR_NETADDR_SIZE(&bindAddr)); + if (rv != 0) { + err = WSAGetLastError(); + PR_LOG(_pr_io_lm, PR_LOG_MIN, + ("_PR_MD_TCPSENDTO error bind failed %d\n", err)); + _PR_MD_MAP_SETSOCKOPT_ERROR(err); + return -1; + } + + PR_LOG(_pr_io_lm, PR_LOG_MIN, + ("_PR_MD_TCPSENDTO calling _pr_win_connectex %d %p\n", amount, (char*)buf)); + + rvSent = 0; + memset(&fd->secret->ol, 0, sizeof(fd->secret->ol)); + /* ConnectEx return TRUE on a success and FALSE on an error. */ + if (_pr_win_connectex( (SOCKET)osfd, (struct sockaddr *) addr, + addrlen, buf, amount, + &rvSent, &fd->secret->ol) == TRUE) { + /* When ConnectEx is used, all previously set socket options and + * property are not enabled and to enable them + * SO_UPDATE_CONNECT_CONTEXT option need to be set. */ + rv = setsockopt((SOCKET)osfd, SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, NULL, 0); + 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_MAP_SETSOCKOPT_ERROR(err); + return -1; + } + /* We imitate Linux here. SendTo will return number of bytes send but + * it can not return connection success at the same time, so we return + * number of bytes send and "connection success" will be return on the + * connectcontinue. */ + fd->secret->alreadyConnected = PR_TRUE; + return rvSent; + } else { + err = WSAGetLastError(); + PR_LOG(_pr_io_lm, PR_LOG_MIN, + ("_PR_MD_TCPSENDTO error _pr_win_connectex failed %d\n", err)); + if (err != ERROR_IO_PENDING) { + _PR_MD_MAP_CONNECT_ERROR(err); + return -1; + } else if (fd->secret->nonblocking) { + /* Remember that overlapped structure is set. We will need to get + * the final result of ConnectEx call. */ + fd->secret->overlappedActive = PR_TRUE; + + /* ConnectEx will copy supplied data to a internal buffer and send + * them during Fast Open or after connect. Therefore we can assumed + * this data already send. */ + if (amount > 0) { + return amount; + } + + _PR_MD_MAP_CONNECT_ERROR(WSAEWOULDBLOCK); + return -1; + } + // err is ERROR_IO_PENDING and socket is blocking, so query + // GetOverlappedResult. + err = ERROR_IO_INCOMPLETE; + while (err == ERROR_IO_INCOMPLETE) { + rv = socket_io_wait(osfd, WRITE_FD, timeout); + if ( rv < 0 ) { + return -1; + } + rv = GetOverlappedResult(osfd, &fd->secret->ol, &rvSent, FALSE); + if ( rv == TRUE ) { + return rvSent; + } else { + err = WSAGetLastError(); + if (err != ERROR_IO_INCOMPLETE) { + _PR_MD_MAP_CONNECT_ERROR(err); + return -1; + } + } + } + } + return -1; +} +#endif + PRInt32 _PR_MD_RECVFROM(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen, PRIntervalTime timeout) diff --git a/nsprpub/pr/src/md/windows/w95thred.c b/nsprpub/pr/src/md/windows/w95thred.c index c27d982a7..a365411f5 100644 --- a/nsprpub/pr/src/md/windows/w95thred.c +++ b/nsprpub/pr/src/md/windows/w95thred.c @@ -1,3 +1,4 @@ + /* -*- 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 @@ -27,14 +28,32 @@ DWORD _pr_currentCPUIndex; int _pr_intsOff = 0; _PRInterruptTable _pr_interruptTable[] = { { 0 } }; +typedef HRESULT (WINAPI *SETTHREADDESCRIPTION)(HANDLE, PCWSTR); +static SETTHREADDESCRIPTION sSetThreadDescription = NULL; + void _PR_MD_EARLY_INIT() { + HMODULE hModule; + #ifndef _PR_USE_STATIC_TLS _pr_currentThreadIndex = TlsAlloc(); _pr_lastThreadIndex = TlsAlloc(); _pr_currentCPUIndex = TlsAlloc(); #endif + +#if defined(_WIN64) && defined(WIN95) + _fd_waiting_for_overlapped_done_lock = PR_NewLock(); +#endif + + // SetThreadDescription is Windows 10 build 1607+ + hModule = GetModuleHandleW(L"kernel32.dll"); + if (hModule) { + sSetThreadDescription = + (SETTHREADDESCRIPTION) GetProcAddress( + hModule, + "SetThreadDescription"); + } } void _PR_MD_CLEANUP_BEFORE_EXIT(void) @@ -50,6 +69,29 @@ void _PR_MD_CLEANUP_BEFORE_EXIT(void) TlsFree(_pr_lastThreadIndex); TlsFree(_pr_currentCPUIndex); #endif + +#if defined(_WIN64) && defined(WIN95) + // For each iteration check if TFO overlapped IOs are down. + if (_fd_waiting_for_overlapped_done_lock) { + PRIntervalTime delay = PR_MillisecondsToInterval(1000); + PRFileDescList *cur; + do { + CheckOverlappedPendingSocketsAreDone(); + + PR_Lock(_fd_waiting_for_overlapped_done_lock); + cur = _fd_waiting_for_overlapped_done; + PR_Unlock(_fd_waiting_for_overlapped_done_lock); +#if defined(DO_NOT_WAIT_FOR_CONNECT_OVERLAPPED_OPERATIONS) + cur = NULL; +#endif + if (cur) { + PR_Sleep(delay); // wait another 1s. + } + } while (cur); + + PR_DestroyLock(_fd_waiting_for_overlapped_done_lock); + } +#endif } PRStatus @@ -190,7 +232,16 @@ _PR_MD_SET_CURRENT_THREAD_NAME(const char *name) { #ifdef _MSC_VER THREADNAME_INFO info; +#endif + + 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; diff --git a/nsprpub/pr/src/md/windows/win32_errors.c b/nsprpub/pr/src/md/windows/win32_errors.c index d26820a7a..275792187 100644 --- a/nsprpub/pr/src/md/windows/win32_errors.c +++ b/nsprpub/pr/src/md/windows/win32_errors.c @@ -166,21 +166,26 @@ void _MD_win32_map_default_error(PRInt32 err) prError = PR_ADDRESS_IN_USE_ERROR; break; case WSAEADDRNOTAVAIL: + case ERROR_INVALID_NETNAME: prError = PR_ADDRESS_NOT_AVAILABLE_ERROR; break; case WSAEAFNOSUPPORT: + case ERROR_INCORRECT_ADDRESS: prError = PR_ADDRESS_NOT_SUPPORTED_ERROR; break; case WSAEALREADY: + case ERROR_ALREADY_INITIALIZED: prError = PR_ALREADY_INITIATED_ERROR; break; case WSAEBADF: prError = PR_BAD_DESCRIPTOR_ERROR; break; case WSAECONNABORTED: + case ERROR_CONNECTION_ABORTED: prError = PR_CONNECT_ABORTED_ERROR; break; case WSAECONNREFUSED: + case ERROR_CONNECTION_REFUSED: prError = PR_CONNECT_REFUSED_ERROR; break; case WSAECONNRESET: @@ -193,6 +198,7 @@ void _MD_win32_map_default_error(PRInt32 err) prError = PR_ACCESS_FAULT_ERROR; break; case WSAEHOSTUNREACH: + case ERROR_HOST_UNREACHABLE: prError = PR_HOST_UNREACHABLE_ERROR; break; case WSAEINVAL: @@ -208,12 +214,14 @@ void _MD_win32_map_default_error(PRInt32 err) prError = PR_BUFFER_OVERFLOW_ERROR; break; case WSAENETDOWN: + case ERROR_NO_NETWORK: prError = PR_NETWORK_DOWN_ERROR; break; case WSAENETRESET: prError = PR_CONNECT_ABORTED_ERROR; break; case WSAENETUNREACH: + case ERROR_NETWORK_UNREACHABLE: prError = PR_NETWORK_UNREACHABLE_ERROR; break; case WSAENOBUFS: diff --git a/nsprpub/pr/src/misc/pratom.c b/nsprpub/pr/src/misc/pratom.c index 95bbee1d5..65e6f3cd8 100644 --- a/nsprpub/pr/src/misc/pratom.c +++ b/nsprpub/pr/src/misc/pratom.c @@ -23,7 +23,7 @@ #if !defined(_PR_HAVE_ATOMIC_OPS) -#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) +#if defined(_PR_PTHREADS) /* * PR_AtomicDecrement() is used in NSPR's thread-specific data * destructor. Because thread-specific data destructors may be @@ -190,7 +190,7 @@ _PR_MD_ATOMIC_SET(PRInt32 *val, PRInt32 newval) pthread_mutex_unlock(&atomic_locks[idx]); return rv; } -#else /* _PR_PTHREADS && !_PR_DCETHREADS */ +#else /* _PR_PTHREADS */ /* * We use a single lock for all the emulated atomic operations. * The lock contention should be acceptable. @@ -259,7 +259,7 @@ _PR_MD_ATOMIC_SET(PRInt32 *val, PRInt32 newval) PR_Unlock(atomic_lock); return rv; } -#endif /* _PR_PTHREADS && !_PR_DCETHREADS */ +#endif /* _PR_PTHREADS */ #endif /* !_PR_HAVE_ATOMIC_OPS */ diff --git a/nsprpub/pr/src/misc/praton.c b/nsprpub/pr/src/misc/praton.c index bff0cd151..80c0628cc 100644 --- a/nsprpub/pr/src/misc/praton.c +++ b/nsprpub/pr/src/misc/praton.c @@ -177,19 +177,21 @@ pr_inet_aton(const char *cp, PRUint32 *addr) case 2: /*%< a.b -- 8.24 bits */ if (val > 0xffffffU) return (0); - val |= parts[0] << 24; + val |= (unsigned int)parts[0] << 24; break; case 3: /*%< a.b.c -- 8.8.16 bits */ if (val > 0xffffU) return (0); - val |= (parts[0] << 24) | (parts[1] << 16); + val |= ((unsigned int)parts[0] << 24) | ((unsigned int)parts[1] << 16); break; case 4: /*%< a.b.c.d -- 8.8.8.8 bits */ if (val > 0xffU) return (0); - val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); + val |= ((unsigned int)parts[0] << 24) | + ((unsigned int)parts[1] << 16) | + ((unsigned int)parts[2] << 8); break; } *addr = PR_htonl(val); diff --git a/nsprpub/pr/src/misc/prnetdb.c b/nsprpub/pr/src/misc/prnetdb.c index b2f6e435b..affebf6ac 100644 --- a/nsprpub/pr/src/misc/prnetdb.c +++ b/nsprpub/pr/src/misc/prnetdb.c @@ -1405,7 +1405,7 @@ PR_IMPLEMENT(PRStatus) PR_InitializeNetAddr( PRStatus rv = PR_SUCCESS; if (!_pr_initialized) _PR_ImplicitInitialization(); - if (val != PR_IpAddrNull) memset(addr, 0, sizeof(addr->inet)); + if (val != PR_IpAddrNull) memset(addr, 0, sizeof(*addr)); addr->inet.family = AF_INET; addr->inet.port = htons(port); switch (val) @@ -1483,18 +1483,20 @@ PR_IsNetAddrType(const PRNetAddr *addr, PRNetAddrValue val) if (val == PR_IpAddrAny) { if (_PR_IN6_IS_ADDR_UNSPECIFIED((PRIPv6Addr *)&addr->ipv6.ip)) { return PR_TRUE; - } else if (_PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip) - && _PR_IN6_V4MAPPED_TO_IPADDR((PRIPv6Addr *)&addr->ipv6.ip) - == htonl(INADDR_ANY)) { - return PR_TRUE; + } + if (_PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip) + && _PR_IN6_V4MAPPED_TO_IPADDR((PRIPv6Addr *)&addr->ipv6.ip) + == htonl(INADDR_ANY)) { + return PR_TRUE; } } else if (val == PR_IpAddrLoopback) { if (_PR_IN6_IS_ADDR_LOOPBACK((PRIPv6Addr *)&addr->ipv6.ip)) { return PR_TRUE; - } else if (_PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip) - && _PR_IN6_V4MAPPED_TO_IPADDR((PRIPv6Addr *)&addr->ipv6.ip) - == htonl(INADDR_LOOPBACK)) { - return PR_TRUE; + } + if (_PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip) + && _PR_IN6_V4MAPPED_TO_IPADDR((PRIPv6Addr *)&addr->ipv6.ip) + == htonl(INADDR_LOOPBACK)) { + return PR_TRUE; } } else if (val == PR_IpAddrV4Mapped && _PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip)) { @@ -1504,8 +1506,9 @@ PR_IsNetAddrType(const PRNetAddr *addr, PRNetAddrValue val) if (addr->raw.family == AF_INET) { if (val == PR_IpAddrAny && addr->inet.ip == htonl(INADDR_ANY)) { return PR_TRUE; - } else if (val == PR_IpAddrLoopback - && addr->inet.ip == htonl(INADDR_LOOPBACK)) { + } + if (val == PR_IpAddrLoopback + && addr->inet.ip == htonl(INADDR_LOOPBACK)) { return PR_TRUE; } } @@ -1777,18 +1780,12 @@ PR_IMPLEMENT(PRUint64) PR_ntohll(PRUint64 n) #ifdef IS_BIG_ENDIAN return n; #else - PRUint64 tmp; PRUint32 hi, lo; - LL_L2UI(lo, n); - LL_SHR(tmp, n, 32); - LL_L2UI(hi, tmp); + lo = (PRUint32)n; + hi = (PRUint32)(n >> 32); hi = PR_ntohl(hi); lo = PR_ntohl(lo); - LL_UI2L(n, lo); - LL_SHL(n, n, 32); - LL_UI2L(tmp, hi); - LL_ADD(n, n, tmp); - return n; + return ((PRUint64)lo << 32) + (PRUint64)hi; #endif } /* ntohll */ @@ -1797,18 +1794,12 @@ PR_IMPLEMENT(PRUint64) PR_htonll(PRUint64 n) #ifdef IS_BIG_ENDIAN return n; #else - PRUint64 tmp; PRUint32 hi, lo; - LL_L2UI(lo, n); - LL_SHR(tmp, n, 32); - LL_L2UI(hi, tmp); + lo = (PRUint32)n; + hi = (PRUint32)(n >> 32); hi = htonl(hi); lo = htonl(lo); - LL_UI2L(n, lo); - LL_SHL(n, n, 32); - LL_UI2L(tmp, hi); - LL_ADD(n, n, tmp); - return n; + return ((PRUint64)lo << 32) + (PRUint64)hi; #endif } /* htonll */ diff --git a/nsprpub/pr/src/misc/prtime.c b/nsprpub/pr/src/misc/prtime.c index 6735805d8..f03786096 100644 --- a/nsprpub/pr/src/misc/prtime.c +++ b/nsprpub/pr/src/misc/prtime.c @@ -279,8 +279,7 @@ static int IsLeapYear(PRInt16 year) { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return 1; - else - return 0; + return 0; } /* @@ -495,6 +494,20 @@ PR_NormalizeTime(PRExplodedTime *time, PRTimeParamFn params) #define MT_safe_localtime localtime_r +#elif defined(_MSC_VER) + +/* Visual C++ has had localtime_s() since Visual C++ 2005. */ + +static struct tm *MT_safe_localtime(const time_t *clock, struct tm *result) +{ + errno_t err = localtime_s(result, clock); + if (err != 0) { + errno = err; + return NULL; + } + return result; +} + #else #define HAVE_LOCALTIME_MONITOR 1 /* We use 'monitor' to serialize our calls @@ -580,6 +593,7 @@ PR_LocalTimeParameters(const PRExplodedTime *gmt) PRTimeParameters retVal; struct tm localTime; + struct tm *localTimeResult; time_t secs; PRTime secs64; PRInt64 usecPerSec; @@ -606,7 +620,12 @@ PR_LocalTimeParameters(const PRExplodedTime *gmt) */ secs = 86400L; - (void) MT_safe_localtime(&secs, &localTime); + localTimeResult = MT_safe_localtime(&secs, &localTime); + PR_ASSERT(localTimeResult != NULL); + if (localTimeResult == NULL) { + /* Shouldn't happen. Use safe fallback for optimized builds. */ + return PR_GMTParameters(gmt); + } /* GMT is 00:00:00, 2nd of Jan. */ @@ -957,6 +976,7 @@ PR_ParseTimeStringToExplodedTime( int hour = -1; int min = -1; int sec = -1; + struct tm *localTimeResult; const char *rest = string; @@ -1215,7 +1235,7 @@ PR_ParseTimeStringToExplodedTime( if ((end - rest) > 2) /* it is [0-9][0-9][0-9]+: */ break; - else if ((end - rest) == 2) + if ((end - rest) == 2) tmp_hour = ((rest[0]-'0')*10 + (rest[1]-'0')); else @@ -1230,12 +1250,12 @@ PR_ParseTimeStringToExplodedTime( if (end == rest) /* no digits after first colon? */ break; - else if ((end - rest) > 2) + if ((end - rest) > 2) /* it is [0-9][0-9][0-9]+: */ break; - else if ((end - rest) == 2) + if ((end - rest) == 2) tmp_min = ((rest[0]-'0')*10 + - (rest[1]-'0')); + (rest[1]-'0')); else tmp_min = (rest[0]-'0'); @@ -1253,7 +1273,7 @@ PR_ParseTimeStringToExplodedTime( else if ((end - rest) > 2) /* it is [0-9][0-9][0-9]+: */ break; - else if ((end - rest) == 2) + if ((end - rest) == 2) tmp_sec = ((rest[0]-'0')*10 + (rest[1]-'0')); else @@ -1287,7 +1307,7 @@ PR_ParseTimeStringToExplodedTime( rest = end; break; } - else if ((*end == '/' || *end == '-') && + if ((*end == '/' || *end == '-') && end[1] >= '0' && end[1] <= '9') { /* Perhaps this is 6/16/95, 16/6/95, 6-16-95, or 16-6-95 @@ -1618,7 +1638,11 @@ PR_ParseTimeStringToExplodedTime( zone_offset for the date we are parsing is the same as the zone offset on 00:00:00 2 Jan 1970 GMT. */ secs = 86400; - (void) MT_safe_localtime(&secs, &localTime); + localTimeResult = MT_safe_localtime(&secs, &localTime); + PR_ASSERT(localTimeResult != NULL); + if (localTimeResult == NULL) { + return PR_FAILURE; + } zone_offset = localTime.tm_min + 60 * localTime.tm_hour + 1440 * (localTime.tm_mday - 2); @@ -1989,24 +2013,22 @@ pr_WeekOfYear(const PRExplodedTime* time, unsigned int firstDayOfWeek) dayOfWeek = time->tm_wday - firstDayOfWeek; if (dayOfWeek < 0) dayOfWeek += 7; - - dayOfYear = time->tm_yday - dayOfWeek; + dayOfYear = time->tm_yday - dayOfWeek; if( dayOfYear <= 0 ) { /* If dayOfYear is <= 0, it is in the first partial week of the year. */ return 0; } - else - { - /* Count the number of full weeks ( dayOfYear / 7 ) then add a week if there - * are any days left over ( dayOfYear % 7 ). Because we are only counting to - * the first day of the week containing the given time, rather than to the - * actual day representing the given time, any days in week 0 will be "absorbed" - * as extra days in the given week. - */ - return (dayOfYear / 7) + ( (dayOfYear % 7) == 0 ? 0 : 1 ); - } + + /* Count the number of full weeks ( dayOfYear / 7 ) then add a week if there + * are any days left over ( dayOfYear % 7 ). Because we are only counting to + * the first day of the week containing the given time, rather than to the + * actual day representing the given time, any days in week 0 will be "absorbed" + * as extra days in the given week. + */ + return (dayOfYear / 7) + ( (dayOfYear % 7) == 0 ? 0 : 1 ); + } diff --git a/nsprpub/pr/src/misc/prtpool.c b/nsprpub/pr/src/misc/prtpool.c index 0671cc19b..c2cc9c803 100644 --- a/nsprpub/pr/src/misc/prtpool.c +++ b/nsprpub/pr/src/misc/prtpool.c @@ -862,16 +862,16 @@ PR_QueueJob_Connect(PRThreadPool *tpool, PRJobIoDesc *iod, if ((rv == PR_FAILURE) && ((err = PR_GetError()) == PR_IN_PROGRESS_ERROR)){ /* connection pending */ return(queue_io_job(tpool, iod, fn, arg, joinable, JOB_IO_CONNECT)); - } else { - /* - * connection succeeded or failed; add to jobq right away - */ - if (rv == PR_FAILURE) - iod->error = err; - else - iod->error = 0; - return(PR_QueueJob(tpool, fn, arg, joinable)); } + /* + * connection succeeded or failed; add to jobq right away + */ + if (rv == PR_FAILURE) + iod->error = err; + else + iod->error = 0; + return(PR_QueueJob(tpool, fn, arg, joinable)); + } /* queue a job, when a timer expires */ diff --git a/nsprpub/pr/src/prvrsion.c b/nsprpub/pr/src/prvrsion.c index 67be53827..be43578ca 100644 --- a/nsprpub/pr/src/prvrsion.c +++ b/nsprpub/pr/src/prvrsion.c @@ -74,6 +74,10 @@ static char sccsid[] = "@(#)NSPR " PR_VERSION _DEBUG_STRING #endif /* XP_UNIX */ +#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#endif PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint(void) { #ifdef XP_UNIX @@ -88,6 +92,9 @@ PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint(void) #endif return &VERSION_DESC_NAME; } /* versionEntryPointType */ +#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif /* prvrsion.c */ diff --git a/nsprpub/pr/src/pthreads/ptio.c b/nsprpub/pr/src/pthreads/ptio.c index e4fe5198b..f6aa56741 100644 --- a/nsprpub/pr/src/pthreads/ptio.c +++ b/nsprpub/pr/src/pthreads/ptio.c @@ -164,6 +164,9 @@ static ssize_t (*pt_aix_sendfile_fptr)() = NULL; #ifndef TCP_CORK #define TCP_CORK 3 #endif +#ifndef MSG_FASTOPEN +#define MSG_FASTOPEN 0x20000000 +#endif #endif #ifdef _PR_IPV6_V6ONLY_PROBE @@ -821,7 +824,7 @@ retry: op->arg3.amount -= bytes; /* and reduce the required count */ return (0 == op->arg3.amount) ? PR_TRUE : PR_FALSE; } - else if ((EWOULDBLOCK != op->syserrno) && (EAGAIN != op->syserrno)) + if ((EWOULDBLOCK != op->syserrno) && (EAGAIN != op->syserrno)) { op->result.code = -1; return PR_TRUE; @@ -850,7 +853,7 @@ static PRBool pt_write_cont(pt_Continuation *op, PRInt16 revents) op->arg3.amount -= bytes; /* and reduce the required count */ return (0 == op->arg3.amount) ? PR_TRUE : PR_FALSE; } - else if ((EWOULDBLOCK != op->syserrno) && (EAGAIN != op->syserrno)) + if ((EWOULDBLOCK != op->syserrno) && (EAGAIN != op->syserrno)) { op->result.code = -1; return PR_TRUE; @@ -892,7 +895,7 @@ static PRBool pt_writev_cont(pt_Continuation *op, PRInt16 revents) op->arg3.amount -= iov_index; /* and array length */ return (0 == op->arg3.amount) ? PR_TRUE : PR_FALSE; } - else if ((EWOULDBLOCK != op->syserrno) && (EAGAIN != op->syserrno)) + if ((EWOULDBLOCK != op->syserrno) && (EAGAIN != op->syserrno)) { op->result.code = -1; return PR_TRUE; @@ -915,7 +918,7 @@ static PRBool pt_sendto_cont(pt_Continuation *op, PRInt16 revents) op->arg3.amount -= bytes; /* and reduce the required count */ return (0 == op->arg3.amount) ? PR_TRUE : PR_FALSE; } - else if ((EWOULDBLOCK != op->syserrno) && (EAGAIN != op->syserrno)) + if ((EWOULDBLOCK != op->syserrno) && (EAGAIN != op->syserrno)) { op->result.code = -1; return PR_TRUE; @@ -1542,23 +1545,26 @@ static PRStatus pt_Connect( pt_SockLen addr_len; const PRNetAddr *addrp = addr; #if defined(_PR_HAVE_SOCKADDR_LEN) || defined(_PR_INET6) - PRUint16 md_af = addr->raw.family; PRNetAddr addrCopy; #endif +#ifdef _PR_HAVE_SOCKADDR_LEN + PRUint16 md_af = addr->raw.family; +#endif if (pt_TestAbort()) return PR_FAILURE; PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE); addr_len = PR_NETADDR_SIZE(addr); -#if defined(_PR_INET6) - if (addr->raw.family == PR_AF_INET6) { - md_af = AF_INET6; -#ifndef _PR_HAVE_SOCKADDR_LEN - addrCopy = *addr; - addrCopy.raw.family = AF_INET6; - addrp = &addrCopy; +#ifdef _PR_INET6 + if (addr->raw.family == PR_AF_INET6) { +#ifdef _PR_HAVE_SOCKADDR_LEN + md_af = AF_INET6; +#else + addrCopy = *addr; + addrCopy.raw.family = AF_INET6; + addrp = &addrCopy; #endif - } + } #endif #ifdef _PR_HAVE_SOCKADDR_LEN @@ -1732,9 +1738,11 @@ static PRStatus pt_Bind(PRFileDesc *fd, const PRNetAddr *addr) pt_SockLen addr_len; const PRNetAddr *addrp = addr; #if defined(_PR_HAVE_SOCKADDR_LEN) || defined(_PR_INET6) - PRUint16 md_af = addr->raw.family; PRNetAddr addrCopy; #endif +#ifdef _PR_HAVE_SOCKADDR_LEN + PRUint16 md_af = addr->raw.family; +#endif if (pt_TestAbort()) return PR_FAILURE; @@ -1749,15 +1757,16 @@ static PRStatus pt_Bind(PRFileDesc *fd, const PRNetAddr *addr) } } -#if defined(_PR_INET6) - if (addr->raw.family == PR_AF_INET6) { - md_af = AF_INET6; -#ifndef _PR_HAVE_SOCKADDR_LEN - addrCopy = *addr; - addrCopy.raw.family = AF_INET6; - addrp = &addrCopy; +#ifdef _PR_INET6 + if (addr->raw.family == PR_AF_INET6) { +#ifdef _PR_HAVE_SOCKADDR_LEN + md_af = AF_INET6; +#else + addrCopy = *addr; + addrCopy.raw.family = AF_INET6; + addrp = &addrCopy; #endif - } + } #endif addr_len = PR_NETADDR_SIZE(addr); @@ -1886,19 +1895,6 @@ static PRInt32 pt_Send( PRInt32 tmp_amount = amount; #endif - /* - * Under HP-UX DCE threads, pthread.h includes dce/cma_ux.h, - * which has the following: - * # define send cma_send - * extern int cma_send (int , void *, int, int ); - * So we need to cast away the 'const' of argument #2 for send(). - */ -#if defined (HPUX) && defined(_PR_DCETHREADS) -#define PT_SENDBUF_CAST (void *) -#else -#define PT_SENDBUF_CAST -#endif - if (pt_TestAbort()) return bytes; /* @@ -1909,9 +1905,9 @@ static PRInt32 pt_Send( #if defined(SOLARIS) PR_ASSERT(0 == flags); retry: - bytes = write(fd->secret->md.osfd, PT_SENDBUF_CAST buf, tmp_amount); + bytes = write(fd->secret->md.osfd, buf, tmp_amount); #else - bytes = send(fd->secret->md.osfd, PT_SENDBUF_CAST buf, amount, flags); + bytes = send(fd->secret->md.osfd, buf, amount, flags); #endif syserrno = errno; @@ -1989,22 +1985,25 @@ static PRInt32 pt_SendTo( pt_SockLen addr_len; const PRNetAddr *addrp = addr; #if defined(_PR_HAVE_SOCKADDR_LEN) || defined(_PR_INET6) - PRUint16 md_af = addr->raw.family; PRNetAddr addrCopy; #endif +#ifdef _PR_HAVE_SOCKADDR_LEN + PRUint16 md_af = addr->raw.family; +#endif if (pt_TestAbort()) return bytes; PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE); -#if defined(_PR_INET6) - if (addr->raw.family == PR_AF_INET6) { - md_af = AF_INET6; -#ifndef _PR_HAVE_SOCKADDR_LEN - addrCopy = *addr; - addrCopy.raw.family = AF_INET6; - addrp = &addrCopy; +#ifdef _PR_INET6 + if (addr->raw.family == PR_AF_INET6) { +#ifdef _PR_HAVE_SOCKADDR_LEN + md_af = AF_INET6; +#else + addrCopy = *addr; + addrCopy.raw.family = AF_INET6; + addrp = &addrCopy; #endif - } + } #endif addr_len = PR_NETADDR_SIZE(addr); @@ -2044,6 +2043,101 @@ static PRInt32 pt_SendTo( return bytes; } /* pt_SendTo */ +#if defined(LINUX) || defined(DARWIN) +/* Linux uses SendTo to send data during TCP Fast Open. OSX uses connectx, but + * we will make it imitate the Linux's interface. */ +static PRInt32 pt_TCP_SendTo( + PRFileDesc *fd, const void *buf, + PRInt32 amount, PRIntn flags, const PRNetAddr *addr, + PRIntervalTime timeout) +{ +#if defined(LINUX) || HAS_CONNECTX + PRInt32 syserrno, bytes = -1; + PRBool fNeedContinue = PR_FALSE; + pt_SockLen addr_len; + const PRNetAddr *addrp = addr; +#if defined(_PR_HAVE_SOCKADDR_LEN) || defined(_PR_INET6) + PRNetAddr addrCopy; +#endif +#ifdef _PR_HAVE_SOCKADDR_LEN + PRUint16 md_af = addr->raw.family; +#endif + + if (pt_TestAbort()) return bytes; + + PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE); + addr_len = PR_NETADDR_SIZE(addr); +#if defined(_PR_INET6) + if (addr->raw.family == PR_AF_INET6) { +#ifdef _PR_HAVE_SOCKADDR_LEN + md_af = AF_INET6; +#else + /* If _PR_INET6 is defined and it is PR_AF_INET6 we set family + * to AF_INET6. */ + addrCopy = *addr; + addrCopy.raw.family = AF_INET6; + addrp = &addrCopy; +#endif + } +#endif + +#ifdef _PR_HAVE_SOCKADDR_LEN + /* if _PR_HAVE_SOCKADDR_LEN is defined and it is PR_AF_INET6 we set family + * to AF_INET6 and we set address length. */ + addrCopy = *addr; + ((struct sockaddr*)&addrCopy)->sa_len = addr_len; + ((struct sockaddr*)&addrCopy)->sa_family = md_af; + addrp = &addrCopy; +#endif + +#ifndef HAS_CONNECTX + bytes = sendto( + fd->secret->md.osfd, buf, amount, MSG_FASTOPEN, + (struct sockaddr*)addrp, addr_len); +#else + sa_endpoints_t endpoints; + endpoints.sae_srcif = 0; + endpoints.sae_srcaddr = NULL; + endpoints.sae_srcaddrlen = 0; + endpoints.sae_dstaddr = (struct sockaddr *)addrp; + endpoints.sae_dstaddrlen = addr_len; + struct iovec iov[1]; + iov[0].iov_base = buf; + iov[0].iov_len = amount; + PRInt32 rv = connectx(fd->secret->md.osfd, &endpoints, SAE_ASSOCID_ANY, + CONNECT_DATA_IDEMPOTENT, iov, 1, &bytes, NULL); +#endif + syserrno = errno; + if ( (bytes == -1) && (syserrno == EWOULDBLOCK || syserrno == EAGAIN) + && (!fd->secret->nonblocking) ) { + if (PR_INTERVAL_NO_WAIT == timeout) syserrno = ETIMEDOUT; + else fNeedContinue = PR_TRUE; + } + if (fNeedContinue == PR_TRUE) { + pt_Continuation op; + op.arg1.osfd = fd->secret->md.osfd; + op.arg2.buffer = (void*)buf; + op.arg3.amount = amount; + op.arg4.flags = flags; + op.arg5.addr = (PRNetAddr*)addrp; + op.timeout = timeout; + op.result.code = 0; /* initialize the number sent */ + op.function = pt_sendto_cont; + op.event = POLLOUT | POLLPRI; + bytes = pt_Continue(&op); + syserrno = op.syserrno; + } + if (bytes < 0) { + pt_MapError(_PR_MD_MAP_SENDTO_ERROR, syserrno); + } + return bytes; +#else /* !HAS_CONNECTX */ + PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0); + return -1; +#endif +} /* pt_TCP_SendTo */ +#endif /* LINUX || DARWIN */ + static PRInt32 pt_RecvFrom(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout) { @@ -2767,22 +2861,21 @@ static PRStatus pt_GetSockName(PRFileDesc *fd, PRNetAddr *addr) if (rv == -1) { pt_MapError(_PR_MD_MAP_GETSOCKNAME_ERROR, errno); return PR_FAILURE; - } else { + } #ifdef _PR_HAVE_SOCKADDR_LEN - /* ignore the sa_len field of struct sockaddr */ - if (addr) - { - addr->raw.family = ((struct sockaddr*)addr)->sa_family; - } + /* ignore the sa_len field of struct sockaddr */ + if (addr) + { + addr->raw.family = ((struct sockaddr*)addr)->sa_family; + } #endif /* _PR_HAVE_SOCKADDR_LEN */ #ifdef _PR_INET6 - if (AF_INET6 == addr->raw.family) - addr->raw.family = PR_AF_INET6; + if (AF_INET6 == addr->raw.family) + addr->raw.family = PR_AF_INET6; #endif - PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE); - PR_ASSERT(IsValidNetAddrLen(addr, addr_len) == PR_TRUE); - return PR_SUCCESS; - } + PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE); + PR_ASSERT(IsValidNetAddrLen(addr, addr_len) == PR_TRUE); + return PR_SUCCESS; } /* pt_GetSockName */ static PRStatus pt_GetPeerName(PRFileDesc *fd, PRNetAddr *addr) @@ -2798,22 +2891,21 @@ static PRStatus pt_GetPeerName(PRFileDesc *fd, PRNetAddr *addr) if (rv == -1) { pt_MapError(_PR_MD_MAP_GETPEERNAME_ERROR, errno); return PR_FAILURE; - } else { + } #ifdef _PR_HAVE_SOCKADDR_LEN - /* ignore the sa_len field of struct sockaddr */ - if (addr) - { - addr->raw.family = ((struct sockaddr*)addr)->sa_family; - } + /* ignore the sa_len field of struct sockaddr */ + if (addr) + { + addr->raw.family = ((struct sockaddr*)addr)->sa_family; + } #endif /* _PR_HAVE_SOCKADDR_LEN */ #ifdef _PR_INET6 - if (AF_INET6 == addr->raw.family) - addr->raw.family = PR_AF_INET6; + if (AF_INET6 == addr->raw.family) + addr->raw.family = PR_AF_INET6; #endif - PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE); - PR_ASSERT(IsValidNetAddrLen(addr, addr_len) == PR_TRUE); - return PR_SUCCESS; - } + PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE); + PR_ASSERT(IsValidNetAddrLen(addr, addr_len) == PR_TRUE); + return PR_SUCCESS; } /* pt_GetPeerName */ static PRStatus pt_GetSocketOption(PRFileDesc *fd, PRSocketOptionData *data) @@ -3155,7 +3247,11 @@ static PRIOMethods _pr_tcp_methods = { pt_Recv, pt_Send, (PRRecvfromFN)_PR_InvalidInt, +#if defined(LINUX) || defined(DARWIN) + pt_TCP_SendTo, /* This is for TCP Fast Open. Linux uses SendTo function for this. OSX uses connectx, but we imitate Linux. */ +#else (PRSendtoFN)_PR_InvalidInt, +#endif pt_Poll, pt_AcceptRead, pt_TransmitFile, @@ -3602,8 +3698,8 @@ PR_IMPLEMENT(PRStatus) PR_Delete(const char *name) if (rv == -1) { pt_MapError(_PR_MD_MAP_UNLINK_ERROR, errno); return PR_FAILURE; - } else - return PR_SUCCESS; + } + return PR_SUCCESS; } /* PR_Delete */ PR_IMPLEMENT(PRStatus) PR_Access(const char *name, PRAccessHow how) @@ -3727,11 +3823,10 @@ PR_IMPLEMENT(PRStatus) PR_RmDir(const char *name) rv = rmdir(name); if (0 == rv) { - return PR_SUCCESS; - } else { + return PR_SUCCESS; + } pt_MapError(_PR_MD_MAP_RMDIR_ERROR, errno); return PR_FAILURE; - } } /* PR_Rmdir */ @@ -3847,7 +3942,8 @@ static PRInt32 _pr_poll_with_poll( /* now locate the NSPR layer at the bottom of the stack */ PRFileDesc *bottom = PR_GetIdentitiesLayer( pds[index].fd, PR_NSPR_IO_LAYER); - PR_ASSERT(NULL != bottom); /* what to do about that? */ + /* ignore a socket without PR_NSPR_IO_LAYER available */ + pds[index].out_flags = 0; /* pre-condition */ if ((NULL != bottom) && (_PR_FILEDESC_OPEN == bottom->secret->state)) @@ -4105,7 +4201,8 @@ static PRInt32 _pr_poll_with_select( /* now locate the NSPR layer at the bottom of the stack */ PRFileDesc *bottom = PR_GetIdentitiesLayer( pds[index].fd, PR_NSPR_IO_LAYER); - PR_ASSERT(NULL != bottom); /* what to do about that? */ + /* ignore a socket without PR_NSPR_IO_LAYER available */ + pds[index].out_flags = 0; /* pre-condition */ if ((NULL != bottom) && (_PR_FILEDESC_OPEN == bottom->secret->state)) diff --git a/nsprpub/pr/src/pthreads/ptsynch.c b/nsprpub/pr/src/pthreads/ptsynch.c index 8663a4c71..a93b74795 100644 --- a/nsprpub/pr/src/pthreads/ptsynch.c +++ b/nsprpub/pr/src/pthreads/ptsynch.c @@ -23,11 +23,6 @@ static pthread_condattr_t _pt_cvar_attr; #if defined(DEBUG) extern PTDebug pt_debug; /* this is shared between several modules */ - -#if defined(_PR_DCETHREADS) -static pthread_t pt_zero_tid; /* a null pthread_t (pthread_t is a struct - * in DCE threads) to compare with */ -#endif /* defined(_PR_DCETHREADS) */ #endif /* defined(DEBUG) */ #if defined(FREEBSD) @@ -55,12 +50,11 @@ void _PR_InitLocks(void) rv = _PT_PTHREAD_MUTEXATTR_INIT(&_pt_mattr); PR_ASSERT(0 == rv); -#ifdef LINUX -#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) +#if (defined(LINUX) && (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) || \ + (defined(FREEBSD) && __FreeBSD_version > 700055) rv = pthread_mutexattr_settype(&_pt_mattr, PTHREAD_MUTEX_ADAPTIVE_NP); PR_ASSERT(0 == rv); #endif -#endif rv = _PT_PTHREAD_CONDATTR_INIT(&_pt_cvar_attr); PR_ASSERT(0 == rv); @@ -264,12 +258,7 @@ static PRIntn pt_TimedWait( rv = pthread_cond_timedwait(cv, ml, &tmo); /* NSPR doesn't report timeouts */ -#ifdef _PR_DCETHREADS - if (rv == -1) return (errno == EAGAIN) ? 0 : errno; - else return rv; -#else return (rv == ETIMEDOUT) ? 0 : rv; -#endif } /* pt_TimedWait */ @@ -1172,14 +1161,14 @@ PR_IMPLEMENT(PRStatus) PR_DeleteSemaphore(const char *name) PR_IMPLEMENT(PRStatus) PRP_TryLock(PRLock *lock) { PRIntn rv = pthread_mutex_trylock(&lock->mutex); - if (rv == PT_TRYLOCK_SUCCESS) + if (rv == 0) { PR_ASSERT(PR_FALSE == lock->locked); lock->locked = PR_TRUE; lock->owner = pthread_self(); } /* XXX set error code? */ - return (PT_TRYLOCK_SUCCESS == rv) ? PR_SUCCESS : PR_FAILURE; + return (0 == rv) ? PR_SUCCESS : PR_FAILURE; } /* PRP_TryLock */ PR_IMPLEMENT(PRCondVar*) PRP_NewNakedCondVar(void) diff --git a/nsprpub/pr/src/pthreads/ptthread.c b/nsprpub/pr/src/pthreads/ptthread.c index 9e12606ea..6046d5d8d 100644 --- a/nsprpub/pr/src/pthreads/ptthread.c +++ b/nsprpub/pr/src/pthreads/ptthread.c @@ -9,7 +9,7 @@ ** Exports: ptthread.h */ -#if defined(_PR_PTHREADS) || defined(_PR_DCETHREADS) +#if defined(_PR_PTHREADS) #include "prlog.h" #include "primpl.h" @@ -58,7 +58,7 @@ static struct _PT_Bookeeping pthread_key_t key; /* thread private data key */ PRBool keyCreated; /* whether 'key' should be deleted */ PRThread *first, *last; /* list of threads we know about */ -#if defined(_PR_DCETHREADS) || _POSIX_THREAD_PRIORITY_SCHEDULING > 0 +#if _POSIX_THREAD_PRIORITY_SCHEDULING > 0 PRInt32 minPrio, maxPrio; /* range of scheduling priorities */ #endif } pt_book = {0}; @@ -67,7 +67,7 @@ static void _pt_thread_death(void *arg); static void _pt_thread_death_internal(void *arg, PRBool callDestructors); static void init_pthread_gc_support(void); -#if defined(_PR_DCETHREADS) || _POSIX_THREAD_PRIORITY_SCHEDULING > 0 +#if _POSIX_THREAD_PRIORITY_SCHEDULING > 0 static PRIntn pt_PriorityMap(PRThreadPriority pri) { #ifdef NTO @@ -148,21 +148,6 @@ static void *_pt_root(void *arg) } #endif - /* - ** DCE Threads can't detach during creation, so do it late. - ** I would like to do it only here, but that doesn't seem - ** to work. - */ -#if defined(_PR_DCETHREADS) - if (detached) - { - /* pthread_detach() modifies its argument, so we must pass a copy */ - pthread_t self = id; - rv = pthread_detach(&self); - PR_ASSERT(0 == rv); - } -#endif /* defined(_PR_DCETHREADS) */ - /* Set up the thread stack information */ _PR_InitializeStack(thred->stack); @@ -329,7 +314,7 @@ static PRThread* _PR_CreateThread( if (EPERM != pt_schedpriv) { -#if !defined(_PR_DCETHREADS) && _POSIX_THREAD_PRIORITY_SCHEDULING > 0 +#if _POSIX_THREAD_PRIORITY_SCHEDULING > 0 struct sched_param schedule; #endif @@ -340,10 +325,7 @@ static PRThread* _PR_CreateThread( /* Use the default scheduling policy */ -#if defined(_PR_DCETHREADS) - rv = pthread_attr_setprio(&tattr, pt_PriorityMap(priority)); - PR_ASSERT(0 == rv); -#elif _POSIX_THREAD_PRIORITY_SCHEDULING > 0 +#if _POSIX_THREAD_PRIORITY_SCHEDULING > 0 rv = pthread_attr_getschedparam(&tattr, &schedule); PR_ASSERT(0 == rv); schedule.sched_priority = pt_PriorityMap(priority); @@ -353,19 +335,13 @@ static PRThread* _PR_CreateThread( rv = pthread_attr_setschedpolicy(&tattr, SCHED_RR); /* Round Robin */ PR_ASSERT(0 == rv); #endif -#endif /* !defined(_PR_DCETHREADS) */ +#endif /* _POSIX_THREAD_PRIORITY_SCHEDULING > 0 */ } - /* - * DCE threads can't set detach state before creating the thread. - * AIX can't set detach late. Why can't we all just get along? - */ -#if !defined(_PR_DCETHREADS) rv = pthread_attr_setdetachstate(&tattr, ((PR_JOINABLE_THREAD == state) ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED)); PR_ASSERT(0 == rv); -#endif /* !defined(_PR_DCETHREADS) */ /* * If stackSize is 0, we use the default pthread stack size. @@ -456,7 +432,6 @@ static PRThread* _PR_CreateThread( */ rv = _PT_PTHREAD_CREATE(&id, tattr, _pt_root, thred); -#if !defined(_PR_DCETHREADS) if (EPERM == rv) { #if defined(IRIX) @@ -482,15 +457,10 @@ static PRThread* _PR_CreateThread( #endif /* IRIX */ rv = _PT_PTHREAD_CREATE(&id, tattr, _pt_root, thred); } -#endif if (0 != rv) { -#if defined(_PR_DCETHREADS) - PRIntn oserr = errno; -#else PRIntn oserr = rv; -#endif PR_Lock(pt_book.ml); if (thred->state & PT_THREAD_SYSTEM) pt_book.system -= 1; @@ -602,10 +572,6 @@ PR_IMPLEMENT(PRStatus) PR_JoinThread(PRThread *thred) PR_ASSERT(rv == 0 && result == NULL); if (0 == rv) { -#ifdef _PR_DCETHREADS - rv = pthread_detach(&id); - PR_ASSERT(0 == rv); -#endif /* * PR_FALSE, because the thread already called the TPD * destructors before exiting _pt_root. @@ -693,10 +659,7 @@ PR_IMPLEMENT(void) PR_SetThreadPriority(PRThread *thred, PRThreadPriority newPri else if ((PRIntn)PR_PRIORITY_LAST < (PRIntn)newPri) newPri = PR_PRIORITY_LAST; -#if defined(_PR_DCETHREADS) - rv = pthread_setprio(thred->id, pt_PriorityMap(newPri)); - /* pthread_setprio returns the old priority */ -#elif _POSIX_THREAD_PRIORITY_SCHEDULING > 0 +#if _POSIX_THREAD_PRIORITY_SCHEDULING > 0 if (EPERM != pt_schedpriv) { int policy; @@ -927,7 +890,7 @@ void _PR_InitThreads( pthread_init(); #endif -#if defined(_PR_DCETHREADS) || _POSIX_THREAD_PRIORITY_SCHEDULING > 0 +#if _POSIX_THREAD_PRIORITY_SCHEDULING > 0 #if defined(FREEBSD) { pthread_attr_t attr; @@ -1161,11 +1124,7 @@ PR_IMPLEMENT(void) PR_ProcessExit(PRIntn status) PR_IMPLEMENT(PRUint32) PR_GetThreadID(PRThread *thred) { -#if defined(_PR_DCETHREADS) - return (PRUint32)&thred->id; /* this is really a sham! */ -#else return (PRUint32)thred->id; /* and I don't know what they will do with it */ -#endif } /* @@ -1197,18 +1156,6 @@ PR_SetThreadDumpProc(PRThread* thread, PRThreadDumpProc dump, void *arg) * Garbage collection support follows. */ -#if defined(_PR_DCETHREADS) - -/* - * statics for Garbage Collection support. We don't need to protect these - * signal masks since the garbage collector itself is protected by a lock - * and multiple threads will not be garbage collecting at the same time. - */ -static sigset_t javagc_vtalarm_sigmask; -static sigset_t javagc_intsoff_sigmask; - -#else /* defined(_PR_DCETHREADS) */ - /* a bogus signal mask for forcing a timed wait */ /* Not so bogus in AIX as we really do a sigwait */ static sigset_t sigwait_set; @@ -1224,8 +1171,6 @@ static void suspend_signal_handler(PRIntn sig); static void null_signal_handler(PRIntn sig); #endif -#endif /* defined(_PR_DCETHREADS) */ - /* * Linux pthreads use SIGUSR1 and SIGUSR2 internally, which * conflict with the use of these two signals in our GC support. @@ -1236,12 +1181,6 @@ static void init_pthread_gc_support(void) #ifndef SYMBIAN PRIntn rv; -#if defined(_PR_DCETHREADS) - rv = sigemptyset(&javagc_vtalarm_sigmask); - PR_ASSERT(0 == rv); - rv = sigaddset(&javagc_vtalarm_sigmask, SIGVTALRM); - PR_ASSERT(0 == rv); -#else /* defined(_PR_DCETHREADS) */ { struct sigaction sigact_usr2; @@ -1269,7 +1208,6 @@ static void init_pthread_gc_support(void) PR_ASSERT(0 ==rv); } #endif /* defined(PT_NO_SIGTIMEDWAIT) */ -#endif /* defined(_PR_DCETHREADS) */ #endif /* SYMBIAN */ } @@ -1300,10 +1238,8 @@ PR_IMPLEMENT(PRStatus) PR_EnumerateThreads(PREnumerator func, void *arg) PRThread* thred = pt_book.first; #if defined(DEBUG) || defined(FORCE_PR_ASSERT) -#if !defined(_PR_DCETHREADS) PRThread *me = PR_GetCurrentThread(); #endif -#endif PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, ("Begin PR_EnumerateThreads\n")); /* @@ -1331,9 +1267,7 @@ PR_IMPLEMENT(PRStatus) PR_EnumerateThreads(PREnumerator func, void *arg) if (_PT_IS_GCABLE_THREAD(thred)) { -#if !defined(_PR_DCETHREADS) PR_ASSERT((thred == me) || (thred->suspend & PT_THREAD_SUSPENDED)); -#endif PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, ("In PR_EnumerateThreads callback thread %p thid = %X\n", thred, thred->id)); @@ -1361,8 +1295,6 @@ PR_IMPLEMENT(PRStatus) PR_EnumerateThreads(PREnumerator func, void *arg) * proceed until the thread is suspended or resumed. */ -#if !defined(_PR_DCETHREADS) - /* * In the signal handler, we can not use condition variable notify or wait. * This does not work consistently across all pthread platforms. We also can not @@ -1661,78 +1593,6 @@ PR_IMPLEMENT(void *)PR_GetSP(PRThread *thred) return thred->sp; } /* PR_GetSP */ -#else /* !defined(_PR_DCETHREADS) */ - -static pthread_once_t pt_gc_support_control = pthread_once_init; - -/* - * For DCE threads, there is no pthread_kill or a way of suspending or resuming a - * particular thread. We will just disable the preemption (virtual timer alarm) and - * let the executing thread finish the garbage collection. This stops all other threads - * (GC able or not) and is very inefficient but there is no other choice. - */ -PR_IMPLEMENT(void) PR_SuspendAll() -{ - PRIntn rv; - - rv = pthread_once(&pt_gc_support_control, init_pthread_gc_support); - PR_ASSERT(0 == rv); /* returns -1 on failure */ -#ifdef DEBUG - suspendAllOn = PR_TRUE; -#endif - PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, ("Begin PR_SuspendAll\n")); - /* - * turn off preemption - i.e add virtual alarm signal to the set of - * blocking signals - */ - rv = sigprocmask( - SIG_BLOCK, &javagc_vtalarm_sigmask, &javagc_intsoff_sigmask); - PR_ASSERT(0 == rv); - suspendAllSuspended = PR_TRUE; - PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, ("End PR_SuspendAll\n")); -} /* PR_SuspendAll */ - -PR_IMPLEMENT(void) PR_ResumeAll() -{ - PRIntn rv; - - suspendAllSuspended = PR_FALSE; - PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, ("Begin PR_ResumeAll\n")); - /* turn on preemption - i.e re-enable virtual alarm signal */ - - rv = sigprocmask(SIG_SETMASK, &javagc_intsoff_sigmask, (sigset_t *)NULL); - PR_ASSERT(0 == rv); -#ifdef DEBUG - suspendAllOn = PR_FALSE; -#endif - - PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, ("End PR_ResumeAll\n")); -} /* PR_ResumeAll */ - -/* Return the stack pointer for the given thread- used by the GC */ -PR_IMPLEMENT(void*)PR_GetSP(PRThread *thred) -{ - pthread_t tid = thred->id; - char *thread_tcb, *top_sp; - - /* - * For HPUX DCE threads, pthread_t is a struct with the - * following three fields (see pthread.h, dce/cma.h): - * cma_t_address field1; - * short int field2; - * short int field3; - * where cma_t_address is typedef'd to be either void* - * or char*. - */ - PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, ("Begin PR_GetSP\n")); - thread_tcb = (char*)tid.field1; - top_sp = *(char**)(thread_tcb + 128); - PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, ("End PR_GetSP %p \n", top_sp)); - return top_sp; -} /* PR_GetSP */ - -#endif /* !defined(_PR_DCETHREADS) */ - PR_IMPLEMENT(PRStatus) PR_SetCurrentThreadName(const char *name) { PRThread *thread; @@ -1817,6 +1677,6 @@ PR_IMPLEMENT(const char *) PR_GetThreadName(const PRThread *thread) return thread->name; } -#endif /* defined(_PR_PTHREADS) || defined(_PR_DCETHREADS) */ +#endif /* defined(_PR_PTHREADS) */ /* ptthread.c */ diff --git a/nsprpub/pr/src/threads/prrwlock.c b/nsprpub/pr/src/threads/prrwlock.c index 2e0f9ea4e..1dd9e0a90 100644 --- a/nsprpub/pr/src/threads/prrwlock.c +++ b/nsprpub/pr/src/threads/prrwlock.c @@ -7,7 +7,7 @@ #include <string.h> -#if defined(HPUX) && defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) +#if defined(HPUX) && defined(_PR_PTHREADS) #include <pthread.h> #define HAVE_UNIX98_RWLOCK diff --git a/nsprpub/pr/tests/Makefile.in b/nsprpub/pr/tests/Makefile.in index df1f1f2dd..79a67f09c 100644 --- a/nsprpub/pr/tests/Makefile.in +++ b/nsprpub/pr/tests/Makefile.in @@ -373,9 +373,6 @@ endif ifeq (,$(filter-out FreeBSD OpenBSD BSD_OS QNX Darwin OpenUNIX,$(OS_ARCH))) LIBPTHREAD = endif -ifeq ($(OS_ARCH)$(basename $(OS_RELEASE)),HP-UXB.10) -LIBPTHREAD = -ldce -endif endif ifeq ($(OS_TARGET),Android) diff --git a/nsprpub/pr/tests/accept.c b/nsprpub/pr/tests/accept.c index 7ed2d9859..b327eb211 100644 --- a/nsprpub/pr/tests/accept.c +++ b/nsprpub/pr/tests/accept.c @@ -143,12 +143,13 @@ ClientThread(void *_action) if (action != CLIENT_TIMEOUT_SEND) { if ((rv = PR_Send(sock, buf, CLIENT_DATA, 0, timeoutTime))< 0) { - if (!debug_mode) + if (!debug_mode) { failed_already=1; - else - PR_fprintf(output, + } else { + PR_fprintf(output, "client: unable to send to server (%d, %ld, %ld)\n", CLIENT_DATA, rv, PR_GetError()); + } goto ErrorExit; } } else { @@ -200,8 +201,9 @@ int i; continue; } failed_already=1; - if (debug_mode) + if (debug_mode) { PR_fprintf(output,"accept: ERROR - PR_Bind failed\n"); + } return; } diff --git a/nsprpub/pr/tests/alarm.c b/nsprpub/pr/tests/alarm.c index b7b195801..e3dedb67f 100644 --- a/nsprpub/pr/tests/alarm.c +++ b/nsprpub/pr/tests/alarm.c @@ -411,15 +411,15 @@ static PRUint32 TimeThis( PRUint32 overhead, usecs; PRIntervalTime predicted, timein, timeout, ticks; - if (debug_mode) - printf("Testing %s ...", msg); + if (debug_mode) + printf("Testing %s ...", msg); timein = PR_IntervalNow(); predicted = func(loops); timeout = PR_IntervalNow(); - if (debug_mode) - printf(" done\n"); + if (debug_mode) + printf(" done\n"); ticks = timeout - timein; usecs = PR_IntervalToMicroseconds(ticks); @@ -491,17 +491,17 @@ int prmain(int argc, char** argv) for (cpu = 1; cpu <= cpus; ++cpu) { - if (debug_mode) + if (debug_mode) printf("\nAlarm: Using %d CPU(s)\n", cpu); - PR_SetConcurrency(cpu); - - /* some basic time test */ - (void)TimeThis("ConditionNotify", ConditionNotify, loops); - (void)TimeThis("ConditionTimeout", ConditionTimeout, loops); - (void)TimeThis("Alarms1", Alarms1, loops); - (void)TimeThis("Alarms2", Alarms2, loops); - (void)TimeThis("Alarms3", Alarms3, loops); + PR_SetConcurrency(cpu); + + /* some basic time test */ + (void)TimeThis("ConditionNotify", ConditionNotify, loops); + (void)TimeThis("ConditionTimeout", ConditionTimeout, loops); + (void)TimeThis("Alarms1", Alarms1, loops); + (void)TimeThis("Alarms2", Alarms2, loops); + (void)TimeThis("Alarms3", Alarms3, loops); } return 0; } diff --git a/nsprpub/pr/tests/attach.c b/nsprpub/pr/tests/attach.c index a5daf9d96..a1493b8ec 100644 --- a/nsprpub/pr/tests/attach.c +++ b/nsprpub/pr/tests/attach.c @@ -111,16 +111,6 @@ static int32 threadStartFunc(void *arg) static void * threadStartFunc(void *arg) #endif { -#ifdef _PR_DCETHREADS - { - int rv; - pthread_t self = pthread_self(); - rv = pthread_detach(&self); - if (debug_mode) PR_ASSERT(0 == rv); - else if (0 != rv) failed_already=1; - } -#endif - Measure(AttachDetach, "Attach/Detach"); #ifndef IRIX @@ -206,14 +196,12 @@ int main(int argc, char **argv) goto exit_now; } -#ifndef _PR_DCETHREADS rv = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); if (debug_mode) PR_ASSERT(0 == rv); else if (0 != rv) { failed_already=1; goto exit_now; } -#endif /* !_PR_DCETHREADS */ rv = _PT_PTHREAD_CREATE(&threadID, attr, threadStartFunc, NULL); if (rv != 0) { fprintf(stderr, "thread creation failed: error code %d\n", rv); diff --git a/nsprpub/pr/tests/dceemu.c b/nsprpub/pr/tests/dceemu.c index b06b49e3a..99fd6cb7c 100644 --- a/nsprpub/pr/tests/dceemu.c +++ b/nsprpub/pr/tests/dceemu.c @@ -29,8 +29,6 @@ #include <stdio.h> #include <stdlib.h> -#if defined(_PR_DCETHREADS) - PRIntn failed_already=0; PRIntn debug_mode=0; @@ -80,20 +78,13 @@ static PRIntn prmain(PRIntn argc, char **argv) } /* prmain */ -#endif /* #if defined(_PR_DCETHREADS) */ - int main(int argc, char **argv) { - -#if defined(_PR_DCETHREADS) PR_Initialize(prmain, argc, argv, 0); if(failed_already) return 1; else return 0; -#else - return 0; -#endif } /* main */ diff --git a/nsprpub/pr/tests/foreign.c b/nsprpub/pr/tests/foreign.c index 637f419d1..cfb2e56ef 100644 --- a/nsprpub/pr/tests/foreign.c +++ b/nsprpub/pr/tests/foreign.c @@ -52,7 +52,7 @@ static int _debug_on = 0; #define DPRINTF(arg) if (_debug_on) PR_fprintf arg -#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) +#if defined(_PR_PTHREADS) #include <pthread.h> #include "md/_pth.h" static void *pthread_start(void *arg) @@ -63,7 +63,7 @@ static void *pthread_start(void *arg) start(data); return NULL; } /* pthread_start */ -#endif /* defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) */ +#endif /* defined(_PR_PTHREADS) */ #if defined(IRIX) && !defined(_PR_PTHREADS) #include <sys/types.h> @@ -109,7 +109,7 @@ static PRStatus NSPRPUB_TESTS_CreateThread(StartFn start, void *arg) } break; case thread_pthread: -#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) +#if defined(_PR_PTHREADS) { int rv; pthread_t id; @@ -137,7 +137,7 @@ static PRStatus NSPRPUB_TESTS_CreateThread(StartFn start, void *arg) PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0); rv = PR_FAILURE; break; -#endif /* defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) */ +#endif /* defined(_PR_PTHREADS) */ case thread_sproc: #if defined(IRIX) && !defined(_PR_PTHREADS) diff --git a/nsprpub/pr/tests/forktest.c b/nsprpub/pr/tests/forktest.c index a389fa479..66dc64575 100644 --- a/nsprpub/pr/tests/forktest.c +++ b/nsprpub/pr/tests/forktest.c @@ -196,51 +196,6 @@ finish: return; } -#ifdef _PR_DCETHREADS - -#include <syscall.h> - -pid_t PR_UnixFork1(void) -{ - pid_t parent = getpid(); - int rv = syscall(SYS_fork); - - if (rv == -1) { - return (pid_t) -1; - } else { - /* For each process, rv is the pid of the other process */ - if (rv == parent) { - /* the child */ - return 0; - } else { - /* the parent */ - return rv; - } - } -} - -#elif defined(SOLARIS) - -/* - * It seems like that in Solaris 2.4 one must call fork1() if the - * the child process is going to use thread functions. Solaris 2.5 - * doesn't have this problem. Calling fork() also works. - */ - -pid_t PR_UnixFork1(void) -{ - return fork1(); -} - -#else - -pid_t PR_UnixFork1(void) -{ - return fork(); -} - -#endif /* PR_DCETHREADS */ - int main(int argc, char **argv) { pid_t pid; @@ -250,7 +205,7 @@ int main(int argc, char **argv) DoIO(); - pid = PR_UnixFork1(); + pid = fork(); if (pid == (pid_t) -1) { fprintf(stderr, "Fork failed: errno %d\n", errno); diff --git a/nsprpub/pr/tests/provider.c b/nsprpub/pr/tests/provider.c index 0e6569d66..932241ec3 100644 --- a/nsprpub/pr/tests/provider.c +++ b/nsprpub/pr/tests/provider.c @@ -606,7 +606,7 @@ typedef struct StartObject void *arg; } StartObject; -#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) +#if defined(_PR_PTHREADS) #include "md/_pth.h" #include <pthread.h> @@ -619,7 +619,7 @@ static void *pthread_start(void *arg) start(data); return NULL; } /* pthread_start */ -#endif /* defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) */ +#endif /* defined(_PR_PTHREADS) */ #if defined(IRIX) && !defined(_PR_PTHREADS) #include <sys/types.h> @@ -657,10 +657,10 @@ static PRStatus JoinThread(PRThread *thread) rv = PR_JoinThread(thread); break; case thread_pthread: -#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) +#if defined(_PR_PTHREADS) rv = PR_SUCCESS; break; -#endif /* defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) */ +#endif /* defined(_PR_PTHREADS) */ case thread_win32: #if defined(WIN32) rv = PR_SUCCESS; @@ -690,7 +690,7 @@ static PRStatus NewThread( } break; case thread_pthread: -#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) +#if defined(_PR_PTHREADS) { int rv; pthread_t id; @@ -717,7 +717,7 @@ static PRStatus NewThread( #else PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0); rv = PR_FAILURE; -#endif /* defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) */ +#endif /* defined(_PR_PTHREADS) */ break; case thread_sproc: diff --git a/nsprpub/pr/tests/socket.c b/nsprpub/pr/tests/socket.c index 5ee2b78f3..92f019d01 100644 --- a/nsprpub/pr/tests/socket.c +++ b/nsprpub/pr/tests/socket.c @@ -21,7 +21,7 @@ #ifdef XP_UNIX #include <sys/mman.h> #endif -#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) +#if defined(_PR_PTHREADS) #include <pthread.h> #endif @@ -313,7 +313,7 @@ PRThread* create_new_thread(PRThreadType type, PRInt32 native_thread = 0; PR_ASSERT(state == PR_UNJOINABLE_THREAD); -#if (defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS)) || defined(WIN32) +#if defined(_PR_PTHREADS) || defined(WIN32) switch(index % 4) { case 0: scope = (PR_LOCAL_THREAD); @@ -332,7 +332,7 @@ PRInt32 native_thread = 0; break; } if (native_thread) { -#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) +#if defined(_PR_PTHREADS) pthread_t tid; if (!pthread_create(&tid, NULL, (void * (*)(void *)) start, arg)) return((PRThread *) tid); diff --git a/nsprpub/pr/tests/testfile.c b/nsprpub/pr/tests/testfile.c index 23659876e..1191bfe94 100644 --- a/nsprpub/pr/tests/testfile.c +++ b/nsprpub/pr/tests/testfile.c @@ -13,7 +13,7 @@ #include <windows.h> #include <process.h> #endif -#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) +#if defined(_PR_PTHREADS) #include <pthread.h> #endif #ifdef SYMBIAN @@ -104,7 +104,7 @@ PRInt32 native_thread = 0; PR_ASSERT(state == PR_UNJOINABLE_THREAD); -#if (defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS)) || defined(WIN32) || defined(XP_OS2) +#if defined(_PR_PTHREADS) || defined(WIN32) || defined(XP_OS2) switch(index % 4) { case 0: @@ -124,7 +124,7 @@ PRInt32 native_thread = 0; break; } if (native_thread) { -#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) +#if defined(_PR_PTHREADS) pthread_t tid; if (!pthread_create(&tid, NULL, start, arg)) return((PRThread *) tid); diff --git a/nsprpub/pr/tests/thrpool_client.c b/nsprpub/pr/tests/thrpool_client.c index a0e1e4c24..7f3df3271 100644 --- a/nsprpub/pr/tests/thrpool_client.c +++ b/nsprpub/pr/tests/thrpool_client.c @@ -21,7 +21,7 @@ #ifdef XP_UNIX #include <sys/mman.h> #endif -#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) +#if defined(_PR_PTHREADS) #include <pthread.h> #endif diff --git a/nsprpub/pr/tests/thrpool_server.c b/nsprpub/pr/tests/thrpool_server.c index 9665829a1..ef09f23b5 100644 --- a/nsprpub/pr/tests/thrpool_server.c +++ b/nsprpub/pr/tests/thrpool_server.c @@ -21,7 +21,7 @@ #ifdef XP_UNIX #include <sys/mman.h> #endif -#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) +#if defined(_PR_PTHREADS) #include <pthread.h> #endif diff --git a/nsprpub/pr/tests/vercheck.c b/nsprpub/pr/tests/vercheck.c index 6cb4eb2db..da2f7b1de 100644 --- a/nsprpub/pr/tests/vercheck.c +++ b/nsprpub/pr/tests/vercheck.c @@ -39,7 +39,8 @@ static char *compatible_version[] = { "4.9.6", "4.10", "4.10.1", "4.10.2", "4.10.3", "4.10.4", "4.10.5", "4.10.6", "4.10.7", "4.10.8", "4.10.9", - "4.10.10", "4.11", "4.12", "4.13", + "4.10.10", "4.11", "4.12", "4.13", "4.14", "4.15", + "4.16", "4.17", PR_VERSION }; @@ -55,8 +56,8 @@ static char *incompatible_version[] = { "3.0", "3.0.1", "3.1", "3.1.1", "3.1.2", "3.1.3", "3.5", "3.5.1", - "4.13.2", - "4.14", "4.14.1", + "4.18.1", + "4.19", "4.19.1", "10.0", "11.1", "12.14.20" }; |