Bug 453372 - Import NSPR_4_7_2_BETA3. r=kaie.
authorWan-Teh Chang <wtc@google.com>
Fri, 05 Sep 2008 11:03:20 -0700
changeset 18857 abe32503a1259eb18766ef52df3961b852e51e96
parent 18856 4ffc02f54b7f490e7d84bbf88bea9a0e558d7e7a
child 18858 a9f50bdece8b3b4265f6701127d552ed542f4853
push idunknown
push userunknown
push dateunknown
reviewerskaie
bugs453372
milestone1.9.1b1pre
Bug 453372 - Import NSPR_4_7_2_BETA3. r=kaie.
nsprpub/configure
nsprpub/configure.in
nsprpub/lib/libc/src/strcase.c
nsprpub/pr/include/md/_beos.h
nsprpub/pr/include/md/_os2.h
nsprpub/pr/include/md/_unixos.h
nsprpub/pr/include/prinit.h
nsprpub/pr/src/io/prlog.c
nsprpub/pr/src/io/prmapopt.c
nsprpub/pr/src/md/unix/unix_errors.c
nsprpub/pr/src/pthreads/ptio.c
--- a/nsprpub/configure
+++ b/nsprpub/configure
@@ -4766,20 +4766,20 @@ EOF
     LD=/usr/ccs/bin/ld
     MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
     RESOLVE_LINK_SYMBOLS=1
     if test -n "$GNU_CC"; then
         DSO_CFLAGS=-fPIC
         if `$CC -print-prog-name=ld` -v 2>&1 | grep -c GNU >/dev/null; then
             GCC_USE_GNU_LD=1
         fi
-        DSO_LDOPTS='-shared -Wl,-h,$(notdir $@),-z,combreloc,-z,defs,-z,ignore' 
+        DSO_LDOPTS='-shared -Wl,-h,$(notdir $@),-z,combreloc,-z,defs,-z,ignore,-Bdirect' 
     else
         DSO_CFLAGS=-KPIC
-        DSO_LDOPTS='-G -h $(notdir $@) -z combreloc -z defs -z ignore'
+        DSO_LDOPTS='-G -h $(notdir $@) -z combreloc -z defs -z ignore -Bdirect'
     fi
     if test -n "$GNU_CC"; then
         CFLAGS="$CFLAGS -Wall"
         CXXFLAGS="$CXXFLAGS -Wall"
         if test -n "$USE_MDUPDATE"; then
             CFLAGS="$CFLAGS -MDupdate \$(DEPENDENCIES)"
             CXXFLAGS="$CXXFLAGS -MDupdate \$(DEPENDENCIES)"
         fi
--- a/nsprpub/configure.in
+++ b/nsprpub/configure.in
@@ -1989,20 +1989,20 @@ mips-sony-newsos*)
     LD=/usr/ccs/bin/ld
     MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
     RESOLVE_LINK_SYMBOLS=1
     if test -n "$GNU_CC"; then
         DSO_CFLAGS=-fPIC
         if `$CC -print-prog-name=ld` -v 2>&1 | grep -c GNU >/dev/null; then
             GCC_USE_GNU_LD=1
         fi
-        DSO_LDOPTS='-shared -Wl,-h,$(notdir $@),-z,combreloc,-z,defs,-z,ignore' 
+        DSO_LDOPTS='-shared -Wl,-h,$(notdir $@),-z,combreloc,-z,defs,-z,ignore,-Bdirect' 
     else
         DSO_CFLAGS=-KPIC
-        DSO_LDOPTS='-G -h $(notdir $@) -z combreloc -z defs -z ignore'
+        DSO_LDOPTS='-G -h $(notdir $@) -z combreloc -z defs -z ignore -Bdirect'
     fi
     if test -n "$GNU_CC"; then
         CFLAGS="$CFLAGS -Wall"
         CXXFLAGS="$CXXFLAGS -Wall"
         if test -n "$USE_MDUPDATE"; then
             CFLAGS="$CFLAGS -MDupdate \$(DEPENDENCIES)"
             CXXFLAGS="$CXXFLAGS -MDupdate \$(DEPENDENCIES)"
         fi
--- a/nsprpub/lib/libc/src/strcase.c
+++ b/nsprpub/lib/libc/src/strcase.c
@@ -31,16 +31,17 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "plstr.h"
+#include <string.h>
 
 static const unsigned char uc[] =
 {
     '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
     '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
     '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
     '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
     ' ',    '!',    '"',    '#',    '$',    '%',    '&',    '\'',
--- a/nsprpub/pr/include/md/_beos.h
+++ b/nsprpub/pr/include/md/_beos.h
@@ -51,16 +51,17 @@
 #include <dirent.h>
 
 /*
  * Internal configuration macros
  */
 
 #ifdef BONE_VERSION
 #define _PR_HAVE_SOCKADDR_LEN
+#define HAVE_NETINET_TCP_H
 #endif
 
 #define PR_LINKER_ARCH	"beos"
 #define _PR_SI_SYSNAME  "BEOS"
 #ifdef __powerpc__
 #define _PR_SI_ARCHITECTURE "ppc"
 #else
 #define _PR_SI_ARCHITECTURE "x86"
--- a/nsprpub/pr/include/md/_os2.h
+++ b/nsprpub/pr/include/md/_os2.h
@@ -61,16 +61,17 @@
 #define _PR_SI_SYSNAME        "OS2"
 #define _PR_SI_ARCHITECTURE   "x86"    /* XXXMB hardcode for now */
 
 #define HAVE_DLL
 #define _PR_GLOBAL_THREADS_ONLY
 #undef  HAVE_THREAD_AFFINITY
 #define _PR_HAVE_THREADSAFE_GETHOST
 #define _PR_HAVE_ATOMIC_OPS
+#define HAVE_NETINET_TCP_H
 
 #define HANDLE unsigned long
 #define HINSTANCE HMODULE
 
 /* --- Common User-Thread/Native-Thread Definitions --------------------- */
 
 /* --- Globals --- */
 extern struct PRLock                      *_pr_schedLock;
--- a/nsprpub/pr/include/md/_unixos.h
+++ b/nsprpub/pr/include/md/_unixos.h
@@ -77,16 +77,20 @@
  * <sys/types.h>, so we include it explicitly.
  */
 #include <sys/time.h>
 #include <sys/types.h>
 #if defined(AIX) || defined(SYMBIAN)
 #include <sys/select.h>
 #endif
 
+#ifndef SYMBIAN
+#define HAVE_NETINET_TCP_H
+#endif
+
 #define _PR_HAVE_O_APPEND
 
 #define PR_DIRECTORY_SEPARATOR		'/'
 #define PR_DIRECTORY_SEPARATOR_STR	"/"
 #define PR_PATH_SEPARATOR		':'
 #define PR_PATH_SEPARATOR_STR		":"
 #define GCPTR
 typedef int (*FARPROC)();
--- a/nsprpub/pr/include/prinit.h
+++ b/nsprpub/pr/include/prinit.h
@@ -58,17 +58,17 @@ PR_BEGIN_EXTERN_C
 /*
 ** NSPR's version is used to determine the likelihood that the version you
 ** used to build your component is anywhere close to being compatible with
 ** what is in the underlying library.
 **
 ** The format of the version string is
 **     "<major version>.<minor version>[.<patch level>] [<Beta>]"
 */
-#define PR_VERSION  "4.7.2 Beta 2"
+#define PR_VERSION  "4.7.2 Beta 3"
 #define PR_VMAJOR   4
 #define PR_VMINOR   7
 #define PR_VPATCH   2
 #define PR_BETA     PR_TRUE
 
 /*
 ** PRVersionCheck
 **
--- a/nsprpub/pr/src/io/prlog.c
+++ b/nsprpub/pr/src/io/prlog.c
@@ -73,17 +73,16 @@ static PRLock *_pr_logLock;
     if (!_PR_IS_NATIVE_THREAD(_me)) \
         _PR_INTSON(_is); \
 }
 
 #endif
 
 #if defined(XP_PC)
 #define strcasecmp stricmp
-#define strncasecmp strnicmp
 #endif
 
 /*
  * On NT, we can't define _PUT_LOG as PR_Write or _PR_MD_WRITE,
  * because every asynchronous file io operation leads to a fiber context
  * switch.  So we define _PUT_LOG as fputs (from stdio.h).  A side
  * benefit is that fputs handles the LF->CRLF translation.  This
  * code can also be used on other platforms with file stream io.
--- a/nsprpub/pr/src/io/prmapopt.c
+++ b/nsprpub/pr/src/io/prmapopt.c
@@ -65,18 +65,17 @@
 
 #include "primpl.h"
 
 #if defined(NEXTSTEP)
 /* NEXTSTEP is special: this must come before netinet/tcp.h. */
 #include <netinet/in_systm.h>  /* n_short, n_long, n_time */
 #endif
 
-#if (defined(XP_UNIX) && !defined(SYMBIAN)) \
-    || defined(OS2) || (defined(XP_BEOS) && defined(BONE_VERSION))
+#ifdef HAVE_NETINET_TCP_H
 #include <netinet/tcp.h>  /* TCP_NODELAY, TCP_MAXSEG */
 #endif
 
 #ifndef _PR_PTHREADS
 
 PRStatus PR_CALLBACK _PR_SocketGetSocketOption(PRFileDesc *fd, PRSocketOptionData *data)
 {
     PRStatus rv;
--- a/nsprpub/pr/src/md/unix/unix_errors.c
+++ b/nsprpub/pr/src/md/unix/unix_errors.c
@@ -189,16 +189,19 @@ void _MD_unix_map_default_error(int err)
         case ENOSPC:
             prError = PR_NO_DEVICE_SPACE_ERROR;
             break;
 #ifdef ENOSR
         case ENOSR:
             prError = PR_INSUFFICIENT_RESOURCES_ERROR;
             break;
 #endif
+        case ENOSYS:
+            prError = PR_NOT_IMPLEMENTED_ERROR;
+            break;
         case ENOTCONN:
             prError = PR_NOT_CONNECTED_ERROR;
             break;
         case ENOTDIR:
             prError = PR_NOT_DIRECTORY_ERROR;
             break;
         case ENOTSOCK:
             prError = PR_NOT_SOCKET_ERROR;
--- a/nsprpub/pr/src/pthreads/ptio.c
+++ b/nsprpub/pr/src/pthreads/ptio.c
@@ -182,17 +182,20 @@ static ssize_t (*pt_aix_sendfile_fptr)()
 #endif /* AIX */
 
 #ifdef LINUX
 #include <sys/sendfile.h>
 #endif
 
 #include "primpl.h"
 
+#ifdef HAVE_NETINET_TCP_H
 #include <netinet/tcp.h>  /* TCP_NODELAY, TCP_MAXSEG */
+#endif
+
 #ifdef LINUX
 /* TCP_CORK is not defined in <netinet/tcp.h> on Red Hat Linux 6.0 */
 #ifndef TCP_CORK
 #define TCP_CORK 3
 #endif
 #endif
 
 #ifdef _PR_IPV6_V6ONLY_PROBE
@@ -204,17 +207,17 @@ static PRBool _pr_ipv6_v6only_on_by_defa
 #elif defined(AIX4_1)
 #define _PRSelectFdSetArg_t void *
 #elif defined(IRIX) || (defined(AIX) && !defined(AIX4_1)) \
     || defined(OSF1) || defined(SOLARIS) \
     || defined(HPUX10_30) || defined(HPUX11) \
     || defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \
     || defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) \
     || defined(BSDI) || defined(VMS) || defined(NTO) || defined(DARWIN) \
-    || defined(UNIXWARE) || defined(RISCOS)
+    || defined(UNIXWARE) || defined(RISCOS) || defined(SYMBIAN)
 #define _PRSelectFdSetArg_t fd_set *
 #else
 #error "Cannot determine architecture"
 #endif
 
 static PRFileDesc *pt_SetMethods(
     PRIntn osfd, PRDescType type, PRBool isAcceptedSocket, PRBool imported);
 
@@ -1651,19 +1654,28 @@ PR_IMPLEMENT(PRStatus) PR_GetConnectStat
 }  /* PR_GetConnectStatus */
 
 static PRFileDesc* pt_Accept(
     PRFileDesc *fd, PRNetAddr *addr, PRIntervalTime timeout)
 {
     PRFileDesc *newfd = NULL;
     PRIntn syserrno, osfd = -1;
     pt_SockLen addr_len = sizeof(PRNetAddr);
+#ifdef SYMBIAN
+    PRNetAddr dummy_addr;
+#endif
 
     if (pt_TestAbort()) return newfd;
 
+#ifdef SYMBIAN
+    /* On Symbian OS, accept crashes if addr is NULL. */
+    if (!addr)
+        addr = &dummy_addr;
+#endif
+
 #ifdef _PR_STRICT_ADDR_LEN
     if (addr)
     {
         /*
          * Set addr->raw.family just so that we can use the
          * PR_NETADDR_SIZE macro.
          */
         addr->raw.family = fd->secret->af;
@@ -1821,17 +1833,25 @@ static PRInt32 pt_Recv(
     PRIntn flags, PRIntervalTime timeout)
 {
     PRInt32 syserrno, bytes = -1;
     PRIntn osflags;
 
     if (0 == flags)
         osflags = 0;
     else if (PR_MSG_PEEK == flags)
+    {
+#ifdef SYMBIAN
+        /* MSG_PEEK doesn't work as expected. */
+        PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+        return bytes;
+#else
         osflags = MSG_PEEK;
+#endif
+    }
     else
     {
         PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
         return bytes;
     }
 
     if (pt_TestAbort()) return bytes;
 
@@ -3246,17 +3266,18 @@ static PRIOMethods _pr_socketpollfd_meth
     (PRReservedFN)_PR_InvalidInt, 
     (PRReservedFN)_PR_InvalidInt
 };
 
 #if defined(HPUX) || defined(OSF1) || defined(SOLARIS) || defined (IRIX) \
     || defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \
     || defined(AIX) || defined(FREEBSD) || defined(NETBSD) \
     || defined(OPENBSD) || defined(BSDI) || defined(VMS) || defined(NTO) \
-    || defined(DARWIN) || defined(UNIXWARE) || defined(RISCOS)
+    || defined(DARWIN) || defined(UNIXWARE) || defined(RISCOS) \
+    || defined(SYMBIAN)
 #define _PR_FCNTL_FLAGS O_NONBLOCK
 #else
 #error "Can't determine architecture"
 #endif
 
 /*
  * Put a Unix file descriptor in non-blocking mode.
  */
@@ -4349,16 +4370,94 @@ PR_IMPLEMENT(PRFileDesc*) PR_OpenUDPSock
 
 PR_IMPLEMENT(PRFileDesc*) PR_OpenTCPSocket(PRIntn af)
 {
     return PR_Socket(af, SOCK_STREAM, 0);
 }  /* PR_NewTCPSocket */
 
 PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPair(PRFileDesc *fds[2])
 {
+#ifdef SYMBIAN
+    /*
+     * For the platforms that don't have socketpair.
+     *
+     * Copied from prsocket.c, with the parameter f[] renamed fds[] and the
+     * _PR_CONNECT_DOES_NOT_BIND code removed.
+     */
+    PRFileDesc *listenSock;
+    PRNetAddr selfAddr, peerAddr;
+    PRUint16 port;
+
+    fds[0] = fds[1] = NULL;
+    listenSock = PR_NewTCPSocket();
+    if (listenSock == NULL) {
+        goto failed;
+    }
+    PR_InitializeNetAddr(PR_IpAddrLoopback, 0, &selfAddr); /* BugZilla: 35408 */
+    if (PR_Bind(listenSock, &selfAddr) == PR_FAILURE) {
+        goto failed;
+    }
+    if (PR_GetSockName(listenSock, &selfAddr) == PR_FAILURE) {
+        goto failed;
+    }
+    port = ntohs(selfAddr.inet.port);
+    if (PR_Listen(listenSock, 5) == PR_FAILURE) {
+        goto failed;
+    }
+    fds[0] = PR_NewTCPSocket();
+    if (fds[0] == NULL) {
+        goto failed;
+    }
+    PR_InitializeNetAddr(PR_IpAddrLoopback, port, &selfAddr);
+
+    /*
+     * Only a thread is used to do the connect and accept.
+     * I am relying on the fact that PR_Connect returns
+     * successfully as soon as the connect request is put
+     * into the listen queue (but before PR_Accept is called).
+     * This is the behavior of the BSD socket code.  If
+     * connect does not return until accept is called, we
+     * will need to create another thread to call connect.
+     */
+    if (PR_Connect(fds[0], &selfAddr, PR_INTERVAL_NO_TIMEOUT)
+            == PR_FAILURE) {
+        goto failed;
+    }
+    /*
+     * A malicious local process may connect to the listening
+     * socket, so we need to verify that the accepted connection
+     * is made from our own socket fds[0].
+     */
+    if (PR_GetSockName(fds[0], &selfAddr) == PR_FAILURE) {
+        goto failed;
+    }
+    fds[1] = PR_Accept(listenSock, &peerAddr, PR_INTERVAL_NO_TIMEOUT);
+    if (fds[1] == NULL) {
+        goto failed;
+    }
+    if (peerAddr.inet.port != selfAddr.inet.port) {
+        /* the connection we accepted is not from fds[0] */
+        PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
+        goto failed;
+    }
+    PR_Close(listenSock);
+    return PR_SUCCESS;
+
+failed:
+    if (listenSock) {
+        PR_Close(listenSock);
+    }
+    if (fds[0]) {
+        PR_Close(fds[0]);
+    }
+    if (fds[1]) {
+        PR_Close(fds[1]);
+    }
+    return PR_FAILURE;
+#else
     PRInt32 osfd[2];
 
     if (pt_TestAbort()) return PR_FAILURE;
 
     if (socketpair(AF_UNIX, SOCK_STREAM, 0, osfd) == -1) {
         pt_MapError(_PR_MD_MAP_SOCKETPAIR_ERROR, errno);
         return PR_FAILURE;
     }
@@ -4371,16 +4470,17 @@ PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPa
     }
     fds[1] = pt_SetMethods(osfd[1], PR_DESC_SOCKET_TCP, PR_FALSE, PR_FALSE);
     if (fds[1] == NULL) {
         PR_Close(fds[0]);
         close(osfd[1]);
         return PR_FAILURE;
     }
     return PR_SUCCESS;
+#endif
 }  /* PR_NewTCPSocketPair */
 
 PR_IMPLEMENT(PRStatus) PR_CreatePipe(
     PRFileDesc **readPipe,
     PRFileDesc **writePipe
 )
 {
     int pipefd[2];
@@ -4426,16 +4526,17 @@ PR_IMPLEMENT(PRStatus) PR_SetFDInheritab
         PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
         return PR_FAILURE;
     }
     if (fd->secret->inheritable != inheritable)
     {
         if (fcntl(fd->secret->md.osfd, F_SETFD,
         inheritable ? 0 : FD_CLOEXEC) == -1)
         {
+            _PR_MD_MAP_DEFAULT_ERROR(errno);
             return PR_FAILURE;
         }
         fd->secret->inheritable = (_PRTriStateBool) inheritable;
     }
     return PR_SUCCESS;
 }
 
 /*****************************************************************************/
@@ -4598,49 +4699,49 @@ PR_IMPLEMENT(PRStatus) PR_UnlockFile(PRF
 
 /*
  * The next two entry points should not be in the API, but they are
  * defined here for historical (or hysterical) reasons.
  */
 
 PR_IMPLEMENT(PRInt32) PR_GetSysfdTableMax(void)
 {
-#if defined(XP_UNIX) && !defined(AIX) && !defined(VMS)
+#if defined(AIX) || defined(VMS) || defined(SYMBIAN)
+    return sysconf(_SC_OPEN_MAX);
+#else
     struct rlimit rlim;
 
     if ( getrlimit(RLIMIT_NOFILE, &rlim) < 0) 
        return -1;
 
     return rlim.rlim_max;
-#elif defined(AIX) || defined(VMS)
-    return sysconf(_SC_OPEN_MAX);
 #endif
 }
 
 PR_IMPLEMENT(PRInt32) PR_SetSysfdTableSize(PRIntn table_size)
 {
-#if defined(XP_UNIX) && !defined(AIX) && !defined(VMS)
+#if defined(AIX) || defined(VMS) || defined(SYMBIAN)
+    return -1;
+#else
     struct rlimit rlim;
     PRInt32 tableMax = PR_GetSysfdTableMax();
 
     if (tableMax < 0) return -1;
     rlim.rlim_max = tableMax;
 
     /* Grow as much as we can; even if too big */
     if ( rlim.rlim_max < table_size )
         rlim.rlim_cur = rlim.rlim_max;
     else
         rlim.rlim_cur = table_size;
 
     if ( setrlimit(RLIMIT_NOFILE, &rlim) < 0) 
         return -1;
 
     return rlim.rlim_cur;
-#elif defined(AIX) || defined(VMS)
-    return -1;
 #endif
 }
 
 /*
  * PR_Stat is supported for backward compatibility; some existing Java
  * code uses it.  New code should use PR_GetFileInfo.
  */