From ac439d5827fd21cd2879c0e4ac5c98743ee4837d Mon Sep 17 00:00:00 2001 From: Cameron Kaiser Date: Wed, 22 Jan 2020 18:28:01 -0800 Subject: [PATCH] #369: just enough new NSPR --- nsprpub/104FX-README | 2 ++ nsprpub/TAG-INFO | 2 +- nsprpub/config/nsinstall.c | 2 +- nsprpub/pr/include/prinit.h | 6 ++-- nsprpub/pr/include/prlog.h | 4 +++ nsprpub/pr/src/io/pripv6.c | 6 ++-- nsprpub/pr/src/io/prsocket.c | 4 +-- nsprpub/pr/src/md/unix/unix.c | 46 ++++++++++++++++++------------ nsprpub/pr/src/misc/praton.c | 8 ++++-- nsprpub/pr/src/misc/prnetdb.c | 26 +++++------------ nsprpub/pr/src/pthreads/ptio.c | 6 ++-- nsprpub/pr/src/pthreads/ptthread.c | 16 +++++++++++ nsprpub/pr/tests/prfz.c | 1 + nsprpub/pr/tests/vercheck.c | 8 ++++-- 14 files changed, 81 insertions(+), 56 deletions(-) create mode 100644 nsprpub/104FX-README diff --git a/nsprpub/104FX-README b/nsprpub/104FX-README new file mode 100644 index 000000000..9179b4387 --- /dev/null +++ b/nsprpub/104FX-README @@ -0,0 +1,2 @@ +This version of NSPR is specific to TenFourFox and ABI-compatible with NSPR +4.24. It is not intended for other consumers; you should use mainline NSPR. diff --git a/nsprpub/TAG-INFO b/nsprpub/TAG-INFO index 34b02cffc..d9c3d4f54 100644 --- a/nsprpub/TAG-INFO +++ b/nsprpub/TAG-INFO @@ -1 +1 @@ -NSPR_4_13_1_RTM +NSPR_4_24_0_104FX diff --git a/nsprpub/config/nsinstall.c b/nsprpub/config/nsinstall.c index f1d2cff26..464f0304d 100644 --- a/nsprpub/config/nsinstall.c +++ b/nsprpub/config/nsinstall.c @@ -517,7 +517,7 @@ reversepath(char *inpath, char *name, int len, char *outpath) xchdir(".."); } else { cp -= 3; - strncpy(cp, "../", 3); + memcpy(cp, "../", 3); xchdir(buf); } } diff --git a/nsprpub/pr/include/prinit.h b/nsprpub/pr/include/prinit.h index e27fc34d0..0b7f61f27 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 ** ".[.] []" */ -#define PR_VERSION "4.13.1" +#define PR_VERSION "4.24" #define PR_VMAJOR 4 -#define PR_VMINOR 13 -#define PR_VPATCH 1 +#define PR_VMINOR 24 +#define PR_VPATCH 0 #define PR_BETA PR_FALSE /* diff --git a/nsprpub/pr/include/prlog.h b/nsprpub/pr/include/prlog.h index 4a291dc18..6e735f3af 100644 --- a/nsprpub/pr/include/prlog.h +++ b/nsprpub/pr/include/prlog.h @@ -207,12 +207,16 @@ NSPR_API(void) PR_Assert(const char *s, const char *file, PRIntn ln) #define PR_ASSERT(_expr) \ ((_expr)?((void)0):PR_Assert(# _expr,__FILE__,__LINE__)) +#define PR_ASSERT_ARG(_expr) PR_ASSERT(_expr) + #define PR_NOT_REACHED(_reasonStr) \ PR_Assert(_reasonStr,__FILE__,__LINE__) #else #define PR_ASSERT(expr) ((void) 0) +/* PR_ASSERT_ARG avoids compiler warning: unused variable */ +#define PR_ASSERT_ARG(expr) ((void)(0 && (expr))) #define PR_NOT_REACHED(reasonStr) #endif /* defined(DEBUG) || defined(FORCE_PR_ASSERT) */ diff --git a/nsprpub/pr/src/io/pripv6.c b/nsprpub/pr/src/io/pripv6.c index af7de49de..a164ae7c8 100644 --- a/nsprpub/pr/src/io/pripv6.c +++ b/nsprpub/pr/src/io/pripv6.c @@ -16,8 +16,8 @@ static PRIOMethods ipv6_to_v4_tcpMethods; static PRIOMethods ipv6_to_v4_udpMethods; static PRDescIdentity _pr_ipv6_to_ipv4_id; extern PRBool IsValidNetAddr(const PRNetAddr *addr); -extern PRIPv6Addr _pr_in6addr_any; -extern PRIPv6Addr _pr_in6addr_loopback; +extern const PRIPv6Addr _pr_in6addr_any; +extern const PRIPv6Addr _pr_in6addr_loopback; /* * convert an IPv4-mapped IPv6 addr to an IPv4 addr @@ -247,7 +247,7 @@ static PRInt32 PR_CALLBACK Ipv6ToIpv4SocketRecvFrom(PRFileDesc *fd, void *buf, #if defined(_PR_INET6_PROBE) static PRBool ipv6_is_present; -extern PRBool _pr_test_ipv6_socket(void); +PR_EXTERN(PRBool) _pr_test_ipv6_socket(void); #if !defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYNAME) extern PRStatus _pr_find_getipnodebyname(void); diff --git a/nsprpub/pr/src/io/prsocket.c b/nsprpub/pr/src/io/prsocket.c index be9702408..f9dc939cf 100644 --- a/nsprpub/pr/src/io/prsocket.c +++ b/nsprpub/pr/src/io/prsocket.c @@ -751,7 +751,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,7 +764,7 @@ static PRInt32 PR_CALLBACK SocketSendTo( } buf = (const void*) ((const char*)buf + temp); amount -= temp; - } + } while (amount > 0); return count; } diff --git a/nsprpub/pr/src/md/unix/unix.c b/nsprpub/pr/src/md/unix/unix.c index fdae1199c..1ee2a8e96 100644 --- a/nsprpub/pr/src/md/unix/unix.c +++ b/nsprpub/pr/src/md/unix/unix.c @@ -59,7 +59,7 @@ ** Global lock variable used to bracket calls into rusty libraries that ** aren't thread safe (like libc, libX, etc). */ -static PRLock *_pr_rename_lock = NULL; +static PRLock *_pr_unix_rename_lock = NULL; static PRMonitor *_pr_Xfe_mon = NULL; static PRInt64 minus_one; @@ -204,8 +204,8 @@ PRInt32 _MD_rename(const char *from, const char *to) ** of an existing file. Holding a lock across these two function ** and the open function is known to be a bad idea, but .... */ - if (NULL != _pr_rename_lock) - PR_Lock(_pr_rename_lock); + if (NULL != _pr_unix_rename_lock) + PR_Lock(_pr_unix_rename_lock); if (0 == access(to, F_OK)) PR_SetError(PR_FILE_EXISTS_ERROR, 0); else @@ -216,8 +216,8 @@ PRInt32 _MD_rename(const char *from, const char *to) _PR_MD_MAP_RENAME_ERROR(err); } } - if (NULL != _pr_rename_lock) - PR_Unlock(_pr_rename_lock); + if (NULL != _pr_unix_rename_lock) + PR_Unlock(_pr_unix_rename_lock); return rv; } @@ -260,15 +260,15 @@ int rv, err; ** This lock is used to enforce rename semantics as described ** in PR_Rename. Look there for more fun details. */ - if (NULL !=_pr_rename_lock) - PR_Lock(_pr_rename_lock); + if (NULL !=_pr_unix_rename_lock) + PR_Lock(_pr_unix_rename_lock); rv = mkdir(name, mode); if (rv < 0) { err = _MD_ERRNO(); _PR_MD_MAP_MKDIR_ERROR(err); } - if (NULL !=_pr_rename_lock) - PR_Unlock(_pr_rename_lock); + if (NULL !=_pr_unix_rename_lock) + PR_Unlock(_pr_unix_rename_lock); return rv; } @@ -2219,8 +2219,8 @@ PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode) if (flags & PR_CREATE_FILE) { osflags |= O_CREAT; - if (NULL !=_pr_rename_lock) - PR_Lock(_pr_rename_lock); + if (NULL !=_pr_unix_rename_lock) + PR_Lock(_pr_unix_rename_lock); } #if defined(ANDROID) @@ -2234,8 +2234,8 @@ PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode) _PR_MD_MAP_OPEN_ERROR(err); } - if ((flags & PR_CREATE_FILE) && (NULL !=_pr_rename_lock)) - PR_Unlock(_pr_rename_lock); + if ((flags & PR_CREATE_FILE) && (NULL !=_pr_unix_rename_lock)) + PR_Unlock(_pr_unix_rename_lock); return rv; } @@ -2877,8 +2877,8 @@ void _PR_UnixInit(void) PR_ASSERT(0 == rv); #endif /* HPUX && _PR_DCETHREADS */ - _pr_rename_lock = PR_NewLock(); - PR_ASSERT(NULL != _pr_rename_lock); + _pr_unix_rename_lock = PR_NewLock(); + PR_ASSERT(NULL != _pr_unix_rename_lock); _pr_Xfe_mon = PR_NewMonitor(); PR_ASSERT(NULL != _pr_Xfe_mon); @@ -2887,9 +2887,9 @@ void _PR_UnixInit(void) void _PR_UnixCleanup(void) { - if (_pr_rename_lock) { - PR_DestroyLock(_pr_rename_lock); - _pr_rename_lock = NULL; + if (_pr_unix_rename_lock) { + PR_DestroyLock(_pr_unix_rename_lock); + _pr_unix_rename_lock = NULL; } if (_pr_Xfe_mon) { PR_DestroyMonitor(_pr_Xfe_mon); @@ -3575,12 +3575,20 @@ PRStatus _MD_CreateFileMap(PRFileMap *fmap, PRInt64 size) } if (fmap->prot == PR_PROT_READONLY) { fmap->md.prot = PROT_READ; -#ifdef OSF1V4_MAP_PRIVATE_BUG +#if defined(OSF1V4_MAP_PRIVATE_BUG) || defined(DARWIN) || defined(ANDROID) /* * Use MAP_SHARED to work around a bug in OSF1 V4.0D * (QAR 70220 in the OSF_QAR database) that results in * corrupted data in the memory-mapped region. This * bug is fixed in V5.0. + * + * This is also needed on OS X because its implementation of + * POSIX shared memory returns an error for MAP_PRIVATE, even + * when the mapping is read-only. + * + * And this is needed on Android, because mapping ashmem with + * MAP_PRIVATE creates a mapping of zeroed memory instead of + * the shm contents. */ fmap->md.flags = MAP_SHARED; #else 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..1eb4348dc 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) @@ -1777,18 +1777,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 +1791,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/pthreads/ptio.c b/nsprpub/pr/src/pthreads/ptio.c index e4fe5198b..47848b702 100644 --- a/nsprpub/pr/src/pthreads/ptio.c +++ b/nsprpub/pr/src/pthreads/ptio.c @@ -3847,7 +3847,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 +4106,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/ptthread.c b/nsprpub/pr/src/pthreads/ptthread.c index 9e12606ea..19eef74a3 100644 --- a/nsprpub/pr/src/pthreads/ptthread.c +++ b/nsprpub/pr/src/pthreads/ptthread.c @@ -1015,7 +1015,23 @@ void _PR_InitThreads( * GCC supports the constructor and destructor attributes as of * version 2.5. */ +#if defined(DARWIN) +/* + * The dynamic linker on OSX doesn't execute __attribute__((destructor)) + * destructors in the right order wrt non-__attribute((destructor)) destructors + * in other libraries. So use atexit() instead, which does. + * See https://bugzilla.mozilla.org/show_bug.cgi?id=1399746#c99 + */ +static void _PR_Fini(void); + +__attribute__ ((constructor)) +static void _register_PR_Fini() { + atexit(_PR_Fini); +} +#else static void _PR_Fini(void) __attribute__ ((destructor)); +#endif + #elif defined(__SUNPRO_C) /* * Sun Studio compiler diff --git a/nsprpub/pr/tests/prfz.c b/nsprpub/pr/tests/prfz.c index 0c5a4324f..7179dbecd 100644 --- a/nsprpub/pr/tests/prfz.c +++ b/nsprpub/pr/tests/prfz.c @@ -10,6 +10,7 @@ #include #include #include +#include int main(int argc, char **argv) diff --git a/nsprpub/pr/tests/vercheck.c b/nsprpub/pr/tests/vercheck.c index 6cb4eb2db..2fc0fabee 100644 --- a/nsprpub/pr/tests/vercheck.c +++ b/nsprpub/pr/tests/vercheck.c @@ -39,7 +39,9 @@ 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", "4.18", "4.19", "4.20", "4.21", "4.22", + "4.23", "4.24", PR_VERSION }; @@ -55,8 +57,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.25.1", + "4.26", "4.26.1", "10.0", "11.1", "12.14.20" };