Bugzilla bug 266981: fixed NSPR support for FreeBSD and added additional
authorwchang0222%aol.com
Mon, 22 Nov 2004 21:24:53 +0000
changeset 3219 6317fcbff5e2a36fb99e57aa6ef4a929289b0926
parent 3218 873fa624e4af672a37111fa4237110883c7ab88b
child 3220 b9a0a689ae93938933818f37349f60091c96800b
push idunknown
push userunknown
push dateunknown
bugs266981
Bugzilla bug 266981: fixed NSPR support for FreeBSD and added additional FreeBSD platform (ia64 and amd64) support. The patch is contributed by Joe Marcus Clarke <marcus@freebsd.org>. r=wtc. Modified Files: _darwin.h, _freebsd.cfg, _freebsd.h, _pth.h, ptio.c, ptsynch.c
pr/include/md/_darwin.h
pr/include/md/_freebsd.cfg
pr/include/md/_freebsd.h
pr/include/md/_pth.h
pr/src/pthreads/ptio.c
pr/src/pthreads/ptsynch.c
--- a/pr/include/md/_darwin.h
+++ b/pr/include/md/_darwin.h
@@ -83,16 +83,21 @@
  */
 #if MACOS_DEPLOYMENT_TARGET < 100300
 #define _PR_INET6_PROBE
 #endif
 /* Mac OS X 10.2 has inet_ntop and inet_pton. */
 #if MACOS_DEPLOYMENT_TARGET >= 100200
 #define _PR_HAVE_INET_NTOP
 #endif
+#define _PR_IPV6_V6ONLY_PROBE
+/* The IPV6_V6ONLY socket option is not defined on Mac OS X 10.1. */
+#ifndef IPV6_V6ONLY
+#define IPV6_V6ONLY 27
+#endif
 
 #if defined(__ppc__)
 #define _PR_HAVE_ATOMIC_OPS
 #define _MD_INIT_ATOMIC()
 extern PRInt32 _PR_DarwinPPC_AtomicIncrement(PRInt32 *val);
 #define _MD_ATOMIC_INCREMENT(val)   _PR_DarwinPPC_AtomicIncrement(val)
 extern PRInt32 _PR_DarwinPPC_AtomicDecrement(PRInt32 *val);
 #define _MD_ATOMIC_DECREMENT(val)   _PR_DarwinPPC_AtomicDecrement(val)
--- a/pr/include/md/_freebsd.cfg
+++ b/pr/include/md/_freebsd.cfg
@@ -89,17 +89,17 @@
 #define PR_ALIGN_OF_SHORT   2
 #define PR_ALIGN_OF_INT     4
 #define PR_ALIGN_OF_LONG    4
 #define PR_ALIGN_OF_INT64   4
 #define PR_ALIGN_OF_FLOAT   4
 #define PR_ALIGN_OF_DOUBLE  4
 #define PR_ALIGN_OF_POINTER 4
 
-#elif defined(__alpha)
+#elif defined(__alpha__)
 
 #define IS_LITTLE_ENDIAN 1
 #undef  IS_BIG_ENDIAN
 #define	HAVE_LONG_LONG
 #define	HAVE_ALIGNED_DOUBLES
 #define	HAVE_ALIGNED_LONGLONGS
 #define IS_64
 
@@ -138,17 +138,17 @@
 #define PR_ALIGN_OF_LONG    8
 #define PR_ALIGN_OF_INT64   8
 #define PR_ALIGN_OF_FLOAT   4
 #define PR_ALIGN_OF_DOUBLE  8
 #define PR_ALIGN_OF_POINTER 8
 
 #elif defined(__sparc__)
 
-#undef IS_LITTLE_ENDIAN
+#undef  IS_LITTLE_ENDIAN
 #define IS_BIG_ENDIAN 1
 #define	HAVE_LONG_LONG
 #define	HAVE_ALIGNED_DOUBLES
 #define	HAVE_ALIGNED_LONGLONGS
 #define IS_64
 
 #define PR_BYTES_PER_BYTE   1
 #define PR_BYTES_PER_SHORT  2
@@ -183,16 +183,112 @@
 #define PR_ALIGN_OF_SHORT   2
 #define PR_ALIGN_OF_INT     4
 #define PR_ALIGN_OF_LONG    8
 #define PR_ALIGN_OF_INT64   8
 #define PR_ALIGN_OF_FLOAT   4
 #define PR_ALIGN_OF_DOUBLE  8
 #define PR_ALIGN_OF_POINTER 8
 
+#elif defined(__ia64__)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define	HAVE_LONG_LONG
+#define	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   3
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#elif defined(__amd64__)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define	HAVE_LONG_LONG
+#define	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   3
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
 #else
 
 #error "Unknown CPU architecture"
 
 #endif
 
 #ifndef NO_NSPR_10_SUPPORT
 
--- a/pr/include/md/_freebsd.h
+++ b/pr/include/md/_freebsd.h
@@ -44,20 +44,24 @@
 #include <osreldate.h>  /* for __FreeBSD_version */
 #endif
 #include <sys/syscall.h>
 
 #define PR_LINKER_ARCH	"freebsd"
 #define _PR_SI_SYSNAME  "FREEBSD"
 #if defined(__i386__)
 #define _PR_SI_ARCHITECTURE "x86"
-#elif defined(__alpha)
+#elif defined(__alpha__)
 #define _PR_SI_ARCHITECTURE "alpha"
 #elif defined(__sparc__)
 #define _PR_SI_ARCHITECTURE "sparc"
+#elif defined(__ia64__)
+#define _PR_SI_ARCHITECTURE "ia64"
+#elif defined(__amd64__)
+#define _PR_SI_ARCHITECTURE "amd64"
 #else
 #error "Unknown CPU architecture"
 #endif
 #if defined(__ELF__)
 #define PR_DLL_SUFFIX          ".so"
 #else
 #define PR_DLL_SUFFIX          ".so.1.0"
 #endif
@@ -94,16 +98,17 @@
 #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
 
 #if __FreeBSD_version >= 400014
 #define _PR_INET6
 #define _PR_HAVE_INET_NTOP
 #define _PR_HAVE_GETHOSTBYNAME2
 #define _PR_HAVE_GETADDRINFO
 #define _PR_INET6_PROBE
+#define _PR_IPV6_V6ONLY_PROBE
 #endif
 
 #define USE_SETJMP
 
 #ifndef _PR_PTHREADS
 #include <setjmp.h>
 
 #define PR_CONTEXT_TYPE	sigjmp_buf
--- a/pr/include/md/_pth.h
+++ b/pr/include/md/_pth.h
@@ -88,17 +88,21 @@
 #define _PT_PTHREAD_CONDATTR_INIT(x)      0
 #define _PT_PTHREAD_CONDATTR_DESTROY(x)   /* */
 #define _PT_PTHREAD_COND_INIT(m, a)       (memset(&(m), 0, sizeof(m)), \
                                       pthread_cond_init(&(m), NULL))
 #else
 #define _PT_PTHREAD_MUTEXATTR_INIT        pthread_mutexattr_init
 #define _PT_PTHREAD_MUTEXATTR_DESTROY     pthread_mutexattr_destroy
 #define _PT_PTHREAD_MUTEX_INIT(m, a)      pthread_mutex_init(&(m), &(a))
+#if defined(FREEBSD)
+#define _PT_PTHREAD_MUTEX_IS_LOCKED(m)    pt_pthread_mutex_is_locked(&(m))
+#else
 #define _PT_PTHREAD_MUTEX_IS_LOCKED(m)    (EBUSY == pthread_mutex_trylock(&(m)))
+#endif
 #if defined(DARWIN)
 #define _PT_PTHREAD_CONDATTR_INIT(x)      0
 #else
 #define _PT_PTHREAD_CONDATTR_INIT         pthread_condattr_init
 #endif
 #define _PT_PTHREAD_CONDATTR_DESTROY      pthread_condattr_destroy
 #define _PT_PTHREAD_COND_INIT(m, a)       pthread_cond_init(&(m), &(a))
 #endif
--- a/pr/src/pthreads/ptio.c
+++ b/pr/src/pthreads/ptio.c
@@ -190,22 +190,18 @@ static ssize_t (*pt_aix_sendfile_fptr)()
 #include <netinet/tcp.h>  /* TCP_NODELAY, TCP_MAXSEG */
 #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 DARWIN
+#ifdef _PR_IPV6_V6ONLY_PROBE
 static PRBool _pr_ipv6_v6only_on_by_default;
-/* The IPV6_V6ONLY socket option is not defined on Mac OS X 10.1. */
-#ifndef IPV6_V6ONLY
-#define IPV6_V6ONLY 27
-#endif
 #endif
 
 #if defined(SOLARIS)
 #define _PRSockOptVal_t char *
 #elif defined(IRIX) || defined(OSF1) || defined(AIX) || defined(HPUX) \
     || defined(LINUX) || defined(FREEBSD) || defined(BSDI) || defined(VMS) \
     || defined(NTO) || defined(OPENBSD) || defined(DARWIN) \
     || defined(UNIXWARE) || defined(NETBSD)
@@ -1155,17 +1151,17 @@ void _PR_InitIO(void)
 
     _PR_InitFdCache();  /* do that */   
 
     _pr_stdin = pt_SetMethods(0, PR_DESC_FILE, PR_FALSE, PR_TRUE);
     _pr_stdout = pt_SetMethods(1, PR_DESC_FILE, PR_FALSE, PR_TRUE);
     _pr_stderr = pt_SetMethods(2, PR_DESC_FILE, PR_FALSE, PR_TRUE);
     PR_ASSERT(_pr_stdin && _pr_stdout && _pr_stderr);
 
-#ifdef DARWIN
+#ifdef _PR_IPV6_V6ONLY_PROBE
     /* In Mac OS X v10.3 Panther Beta the IPV6_V6ONLY socket option
      * is turned on by default, contrary to what RFC 3493, Section
      * 5.3 says.  So we have to turn it off.  Find out whether we
      * are running on such a system.
      */
     {
         int osfd;
         osfd = socket(AF_INET6, SOCK_STREAM, 0);
@@ -3475,17 +3471,17 @@ PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRIn
 	if (PR_AF_INET6 == domain)
 		domain = AF_INET;
 #endif
 
     osfd = socket(domain, type, proto);
     if (osfd == -1) pt_MapError(_PR_MD_MAP_SOCKET_ERROR, errno);
     else
     {
-#ifdef DARWIN
+#ifdef _PR_IPV6_V6ONLY_PROBE
         if ((domain == AF_INET6) && _pr_ipv6_v6only_on_by_default)
         {
             int on = 0;
             (void)setsockopt(osfd, IPPROTO_IPV6, IPV6_V6ONLY,
                     &on, sizeof(on));
         }
 #endif
         fd = pt_SetMethods(osfd, ftype, PR_FALSE, PR_FALSE);
--- a/pr/src/pthreads/ptsynch.c
+++ b/pr/src/pthreads/ptsynch.c
@@ -57,16 +57,29 @@ static pthread_condattr_t _pt_cvar_attr;
 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)
+/*
+ * On older versions of FreeBSD, pthread_mutex_trylock returns EDEADLK.
+ * Newer versions return EBUSY.  We still need to support both.
+ */
+static int
+pt_pthread_mutex_is_locked(pthread_mutex_t *m)
+{
+    int rv = pthread_mutex_trylock(m);
+    return (EBUSY == rv || EDEADLK == rv);
+}
+#endif
+
 /**************************************************************/
 /**************************************************************/
 /*****************************LOCKS****************************/
 /**************************************************************/
 /**************************************************************/
 
 void _PR_InitLocks(void)
 {