diff options
author | wtc%netscape.com <devnull@localhost> | 2002-03-14 23:21:20 +0000 |
---|---|---|
committer | wtc%netscape.com <devnull@localhost> | 2002-03-14 23:21:20 +0000 |
commit | ce4c2ac7676a8af91a6e3faef89a2d88d8148c59 (patch) | |
tree | da7676750650a85012799363c033f89f1daabbf7 | |
parent | be0aa4947eb823e4e22a653ac402a9993c7eac70 (diff) | |
download | nspr-hg-ce4c2ac7676a8af91a6e3faef89a2d88d8148c59.tar.gz |
Bugzilla bug 129902: sync up the NSPR_PRE_4_2_CLIENT_BRANCH with the NSPR
tip. a=dbaron on behalf of drivers@mozilla.org.
68 files changed, 783 insertions, 354 deletions
diff --git a/Makefile.in b/Makefile.in index f3efa393..ca5b0fc1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -110,12 +110,12 @@ ifeq ($(OS_ARCH),WINNT) @if test ! -d $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); then \ rm -rf $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); \ echo "making directory $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)"; \ - config/prmkdir.bat $(MDIST_DOS)\\$(MOD_NAME)\\$(BUILD_NUMBER); \ + $(topsrcdir)/config/prmkdir.bat $(MDIST_DOS)\\$(MOD_NAME)\\$(BUILD_NUMBER); \ fi @if test ! -d $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME); then \ rm -rf $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME); \ echo "making directory $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME)"; \ - config/prmkdir.bat $(MDIST_DOS)\\$(MOD_NAME)\\$(BUILD_NUMBER)\\$(RELEASE_OBJDIR_NAME); \ + $(topsrcdir)/config/prmkdir.bat $(MDIST_DOS)\\$(MOD_NAME)\\$(BUILD_NUMBER)\\$(RELEASE_OBJDIR_NAME); \ fi else @if test ! -d $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); then \ diff --git a/config/Linux.mk b/config/Linux.mk index eabdb5b1..810ca2c6 100644 --- a/config/Linux.mk +++ b/config/Linux.mk @@ -81,7 +81,7 @@ RANLIB = ranlib OS_INCLUDES = G++INCLUDES = -I/usr/include/g++ -PLATFORM_FLAGS = -ansi -Wall -pipe -DLINUX -Dlinux +PLATFORM_FLAGS = -ansi -Wall -pipe -DLINUX PORT_FLAGS = -D_POSIX_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -DHAVE_STRERROR -DHAVE_FCNTL_FILE_LOCKING OS_CFLAGS = $(DSO_CFLAGS) $(PLATFORM_FLAGS) $(PORT_FLAGS) diff --git a/config/prmkdir.bat b/config/prmkdir.bat index b0e00ca6..1f2d4290 100755 --- a/config/prmkdir.bat +++ b/config/prmkdir.bat @@ -1,18 +1,34 @@ -REM -REM The contents of this file are subject to the Netscape Public License -REM Version 1.1 (the "NPL"); you may not use this file except in -REM compliance with the NPL. You may obtain a copy of the NPL at -REM http://www.mozilla.org/NPL/ REM -REM Software distributed under the NPL is distributed on an "AS IS" basis, -REM WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL -REM for the specific language governing rights and limitations under the -REM NPL. +REM The contents of this file are subject to the Mozilla Public +REM License Version 1.1 (the "License"); you may not use this file +REM except in compliance with the License. You may obtain a copy of +REM the License at http://www.mozilla.org/MPL/ +REM +REM Software distributed under the License is distributed on an "AS +REM IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +REM implied. See the License for the specific language governing +REM rights and limitations under the License. +REM +REM The Original Code is the Netscape Portable Runtime (NSPR). +REM +REM The Initial Developer of the Original Code is Netscape +REM Communications Corporation. Portions created by Netscape are +REM Copyright (C) 1998-2000 Netscape Communications Corporation. All +REM Rights Reserved. +REM +REM Contributor(s): +REM +REM Alternatively, the contents of this file may be used under the +REM terms of the GNU General Public License Version 2 or later (the +REM "GPL"), in which case the provisions of the GPL are applicable +REM instead of those above. If you wish to allow use of your +REM version of this file only under the terms of the GPL and not to +REM allow others to use your version of this file under the MPL, +REM indicate your decision by deleting the provisions above and +REM replace them with the notice and other provisions required by +REM the GPL. If you do not delete the provisions above, a recipient +REM may use your version of this file under either the MPL or the +REM GPL. REM -REM The Initial Developer of this code under the NPL is Netscape -REM Communications Corporation. Portions created by Netscape are -REM Copyright (C) 1998 Netscape Communications Corporation. All Rights -REM Reserved. -REM mkdir %1 @@ -3315,7 +3315,9 @@ EOF DLL_SUFFIX=sl DSO_LDOPTS='-b +h $(notdir $@)' PR_MD_CSRCS=hpux.c - PR_MD_ASFILES=os_HPUX.s + if test "$OS_TEST" != "ia64"; then + PR_MD_ASFILES=os_HPUX.s + fi if test -n "$USE_64"; then MDCPUCFG_H=_hpux64.cfg else @@ -3369,7 +3371,7 @@ EOF fi - if echo "$OS_RELEASE" | egrep '^(B.10.30|B.11.00|B.11.11)' >/dev/null; then + if echo "$OS_RELEASE" | egrep '^(B.10.30|B.11.00|B.11.11|B.11.20)' >/dev/null; then cat >> confdefs.h <<\EOF #define HAVE_POINTER_LOCALTIME_R 1 EOF @@ -3428,7 +3430,7 @@ EOF DEFAULT_IMPL_STRATEGY=_PTH fi - if echo "$OS_RELEASE" | egrep '^(B.11.00|B.11.11)' >/dev/null; then + if echo "$OS_RELEASE" | egrep '^(B.11.00|B.11.11|B.11.20)' >/dev/null; then cat >> confdefs.h <<\EOF #define HPUX10 1 EOF @@ -3451,11 +3453,21 @@ EOF if test -z "$GNU_CC"; then if test -z "$USE_64"; then - CFLAGS="$CFLAGS +DAportable +DS2.0" - CXXFLAGS="$CXXFLAGS +DAportable +DS2.0" + if test "$OS_TEST" = "ia64"; then + CFLAGS="$CFLAGS +DD32" + CXXFLAGS="$CXXFLAGS +DD32" + else + CFLAGS="$CFLAGS +DAportable +DS2.0" + CXXFLAGS="$CXXFLAGS +DAportable +DS2.0" + fi else - CFLAGS="$CFLAGS +DA2.0W +DS2.0" - CXXFLAGS="$CXXFLAGS +DA2.0W +DS2.0" + if test "$OS_TEST" = "ia64"; then + CFLAGS="$CFLAGS +DD64" + CXXFLAGS="$CXXFLAGS +DD64" + else + CFLAGS="$CFLAGS +DA2.0W +DS2.0" + CXXFLAGS="$CXXFLAGS +DA2.0W +DS2.0" + fi fi fi DEFAULT_IMPL_STRATEGY=_PTH @@ -3637,10 +3649,6 @@ EOF #define LINUX 1 EOF - cat >> confdefs.h <<\EOF -#define linux 1 -EOF - CFLAGS="$CFLAGS -ansi -Wall" CXXFLAGS="$CXXFLAGS -ansi -Wall" MDCPUCFG_H=_linux.cfg @@ -4142,17 +4150,17 @@ EOF ac_safe=`echo "machine/builtins.h" | sed 'y%./+-%__p_%'` echo $ac_n "checking for machine/builtins.h""... $ac_c" 1>&6 -echo "configure:4146: checking for machine/builtins.h" >&5 +echo "configure:4154: checking for machine/builtins.h" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 4151 "configure" +#line 4159 "configure" #include "confdefs.h" #include <machine/builtins.h> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:4156: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:4164: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -4667,12 +4675,12 @@ esac if test -z "$SKIP_LIBRARY_CHECKS"; then echo $ac_n "checking for dlopen""... $ac_c" 1>&6 -echo "configure:4671: checking for dlopen" >&5 +echo "configure:4679: checking for dlopen" >&5 if eval "test \"`echo '$''{'ac_cv_func_dlopen'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 4676 "configure" +#line 4684 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char dlopen(); below. */ @@ -4695,7 +4703,7 @@ dlopen(); ; return 0; } EOF -if { (eval echo configure:4699: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:4707: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_dlopen=yes" else @@ -4714,7 +4722,7 @@ else echo "$ac_t""no" 1>&6 echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6 -echo "configure:4718: checking for dlopen in -ldl" >&5 +echo "configure:4726: checking for dlopen in -ldl" >&5 ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -4722,7 +4730,7 @@ else ac_save_LIBS="$LIBS" LIBS="-ldl $LIBS" cat > conftest.$ac_ext <<EOF -#line 4726 "configure" +#line 4734 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 @@ -4733,7 +4741,7 @@ int main() { dlopen() ; return 0; } EOF -if { (eval echo configure:4737: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:4745: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -4761,13 +4769,13 @@ fi if test $ac_cv_prog_gcc = yes; then echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6 -echo "configure:4765: checking whether ${CC-cc} needs -traditional" >&5 +echo "configure:4773: checking whether ${CC-cc} needs -traditional" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_pattern="Autoconf.*'x'" cat > conftest.$ac_ext <<EOF -#line 4771 "configure" +#line 4779 "configure" #include "confdefs.h" #include <sgtty.h> Autoconf TIOCGETP @@ -4785,7 +4793,7 @@ rm -f conftest* if test $ac_cv_prog_gcc_traditional = no; then cat > conftest.$ac_ext <<EOF -#line 4789 "configure" +#line 4797 "configure" #include "confdefs.h" #include <termio.h> Autoconf TCGETA @@ -4809,12 +4817,12 @@ fi for ac_func in lchown strerror do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:4813: checking for $ac_func" >&5 +echo "configure:4821: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 4818 "configure" +#line 4826 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -4837,7 +4845,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:4841: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:4849: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -4875,7 +4883,7 @@ fi echo $ac_n "checking for pthread_create in -lpthreads""... $ac_c" 1>&6 -echo "configure:4879: checking for pthread_create in -lpthreads" >&5 +echo "configure:4887: checking for pthread_create in -lpthreads" >&5 echo " #include <pthread.h> void *foo(void *v) { int a = 1; } @@ -4897,7 +4905,7 @@ echo " echo "$ac_t""no" 1>&6 echo $ac_n "checking for pthread_create in -lpthread""... $ac_c" 1>&6 -echo "configure:4901: checking for pthread_create in -lpthread" >&5 +echo "configure:4909: checking for pthread_create in -lpthread" >&5 echo " #include <pthread.h> void *foo(void *v) { int a = 1; } @@ -4919,7 +4927,7 @@ echo " echo "$ac_t""no" 1>&6 echo $ac_n "checking for pthread_create in -lc_r""... $ac_c" 1>&6 -echo "configure:4923: checking for pthread_create in -lc_r" >&5 +echo "configure:4931: checking for pthread_create in -lc_r" >&5 echo " #include <pthread.h> void *foo(void *v) { int a = 1; } @@ -4941,7 +4949,7 @@ echo " echo "$ac_t""no" 1>&6 echo $ac_n "checking for pthread_create in -lc""... $ac_c" 1>&6 -echo "configure:4945: checking for pthread_create in -lc" >&5 +echo "configure:4953: checking for pthread_create in -lc" >&5 echo " #include <pthread.h> void *foo(void *v) { int a = 1; } @@ -5091,7 +5099,7 @@ if test -n "$USE_PTHREADS"; then rm -f conftest* ac_cv_have_dash_pthread=no echo $ac_n "checking whether ${CC-cc} accepts -pthread""... $ac_c" 1>&6 -echo "configure:5095: checking whether ${CC-cc} accepts -pthread" >&5 +echo "configure:5103: checking whether ${CC-cc} accepts -pthread" >&5 echo 'int main() { return 0; }' | cat > conftest.c ${CC-cc} -pthread -o conftest conftest.c > conftest.out 2>&1 if test $? -eq 0; then @@ -5114,7 +5122,7 @@ echo "configure:5095: checking whether ${CC-cc} accepts -pthread" >&5 ac_cv_have_dash_pthreads=no if test "$ac_cv_have_dash_pthread" = "no"; then echo $ac_n "checking whether ${CC-cc} accepts -pthreads""... $ac_c" 1>&6 -echo "configure:5118: checking whether ${CC-cc} accepts -pthreads" >&5 +echo "configure:5126: checking whether ${CC-cc} accepts -pthreads" >&5 echo 'int main() { return 0; }' | cat > conftest.c ${CC-cc} -pthreads -o conftest conftest.c > conftest.out 2>&1 if test $? -eq 0; then diff --git a/configure.in b/configure.in index 4115dbf4..adb7e0d9 100644 --- a/configure.in +++ b/configure.in @@ -891,7 +891,9 @@ case "$target" in DLL_SUFFIX=sl DSO_LDOPTS='-b +h $(notdir $@)' PR_MD_CSRCS=hpux.c - PR_MD_ASFILES=os_HPUX.s + if test "$OS_TEST" != "ia64"; then + PR_MD_ASFILES=os_HPUX.s + fi if test -n "$USE_64"; then MDCPUCFG_H=_hpux64.cfg else @@ -930,7 +932,7 @@ case "$target" in AC_DEFINE(HAVE_INT_LOCALTIME_R) fi - if echo "$OS_RELEASE" | egrep '^(B.10.30|B.11.00|B.11.11)' >/dev/null; then + if echo "$OS_RELEASE" | egrep '^(B.10.30|B.11.00|B.11.11|B.11.20)' >/dev/null; then AC_DEFINE(HAVE_POINTER_LOCALTIME_R) fi @@ -965,7 +967,7 @@ case "$target" in DEFAULT_IMPL_STRATEGY=_PTH fi - if echo "$OS_RELEASE" | egrep '^(B.11.00|B.11.11)' >/dev/null; then + if echo "$OS_RELEASE" | egrep '^(B.11.00|B.11.11|B.11.20)' >/dev/null; then AC_DEFINE(HPUX10) AC_DEFINE(HPUX11) AC_DEFINE(_LARGEFILE64_SOURCE) @@ -973,11 +975,21 @@ case "$target" in AC_DEFINE(HAVE_FCNTL_FILE_LOCKING) if test -z "$GNU_CC"; then if test -z "$USE_64"; then - CFLAGS="$CFLAGS +DAportable +DS2.0" - CXXFLAGS="$CXXFLAGS +DAportable +DS2.0" + if test "$OS_TEST" = "ia64"; then + CFLAGS="$CFLAGS +DD32" + CXXFLAGS="$CXXFLAGS +DD32" + else + CFLAGS="$CFLAGS +DAportable +DS2.0" + CXXFLAGS="$CXXFLAGS +DAportable +DS2.0" + fi else - CFLAGS="$CFLAGS +DA2.0W +DS2.0" - CXXFLAGS="$CXXFLAGS +DA2.0W +DS2.0" + if test "$OS_TEST" = "ia64"; then + CFLAGS="$CFLAGS +DD64" + CXXFLAGS="$CXXFLAGS +DD64" + else + CFLAGS="$CFLAGS +DA2.0W +DS2.0" + CXXFLAGS="$CXXFLAGS +DA2.0W +DS2.0" + fi fi fi DEFAULT_IMPL_STRATEGY=_PTH @@ -1109,7 +1121,6 @@ case "$target" in AC_DEFINE(_LARGEFILE64_SOURCE) AC_DEFINE(HAVE_FCNTL_FILE_LOCKING) AC_DEFINE(LINUX) - AC_DEFINE(linux) CFLAGS="$CFLAGS -ansi -Wall" CXXFLAGS="$CXXFLAGS -ansi -Wall" MDCPUCFG_H=_linux.cfg diff --git a/lib/ds/plarena.c b/lib/ds/plarena.c index fa800190..7f144636 100644 --- a/lib/ds/plarena.c +++ b/lib/ds/plarena.c @@ -66,7 +66,7 @@ static PRCallOnceType once; ** ** InitializeArenas() is called exactly once and only once from ** LockArena(). This function creates the arena protection -** monitor: arenaLock. +** lock: arenaLock. ** ** Note: If the arenaLock cannot be created, InitializeArenas() ** fails quietly, returning only PR_FAILURE. This percolates up @@ -339,17 +339,20 @@ PR_IMPLEMENT(void) PL_CompactArenaPool(PLArenaPool *ap) #endif } -PR_IMPLEMENT(void) PL_ArenaFinish() +PR_IMPLEMENT(void) PL_ArenaFinish(void) { PLArena *a, *next; - LockArena(); for (a = arena_freelist; a; a = next) { next = a->next; PR_DELETE(a); } arena_freelist = NULL; - UnlockArena(); + + if (arenaLock) { + PR_DestroyLock(arenaLock); + arenaLock = NULL; + } } #ifdef PL_ARENAMETER diff --git a/lib/ds/plvrsion.c b/lib/ds/plvrsion.c index 372d68a5..65c33eff 100644 --- a/lib/ds/plvrsion.c +++ b/lib/ds/plvrsion.c @@ -84,7 +84,7 @@ PRVersionDescription VERSION_DESC_NAME = /* description */ "Portable runtime", /* what we are */ /* security */ "N/A", /* not applicable here */ /* copywrite */ "Copyright (c) 1998 Netscape Communications Corporation. All Rights Reserved", - /* comment */ "http://www.mozilla.org/NPL/", + /* comment */ "http://www.mozilla.org/MPL/", /* specialString */ "" }; diff --git a/lib/libc/src/plvrsion.c b/lib/libc/src/plvrsion.c index 60adc49d..9df97128 100644 --- a/lib/libc/src/plvrsion.c +++ b/lib/libc/src/plvrsion.c @@ -84,7 +84,7 @@ PRVersionDescription VERSION_DESC_NAME = /* description */ "Portable runtime", /* what we are */ /* security */ "N/A", /* not applicable here */ /* copywrite */ "Copyright (c) 1998 Netscape Communications Corporation. All Rights Reserved", - /* comment */ "http://www.mozilla.org/NPL/", + /* comment */ "http://www.mozilla.org/MPL/", /* specialString */ "" }; diff --git a/lib/libc/src/strchr.c b/lib/libc/src/strchr.c index fd31222f..9ccae9a9 100644 --- a/lib/libc/src/strchr.c +++ b/lib/libc/src/strchr.c @@ -70,11 +70,11 @@ PL_strnchr(const char *s, char c, PRUint32 n) { if( (const char *)0 == s ) return (char *)0; - for( ; *s && n; s++, n-- ) + for( ; n && *s; s++, n-- ) if( *s == c ) return (char *)s; - if( ((char)0 == c) && ((char)0 == *s) && (n > 0)) return (char *)s; + if( ((char)0 == c) && (n > 0) && ((char)0 == *s) ) return (char *)s; return (char *)0; } @@ -86,10 +86,10 @@ PL_strnrchr(const char *s, char c, PRUint32 n) if( (const char *)0 == s ) return (char *)0; - for( p = s; *p && n; p++, n-- ) + for( p = s; n && *p; p++, n-- ) ; - if( ((char)0 == c) && ((char)0 == *p) && (n > 0) ) return (char *)p; + if( ((char)0 == c) && (n > 0) && ((char)0 == *p) ) return (char *)p; for( p--; p >= s; p-- ) if( *p == c ) diff --git a/lib/libc/src/strcstr.c b/lib/libc/src/strcstr.c index 2cb14cc8..7bf7d67d 100644 --- a/lib/libc/src/strcstr.c +++ b/lib/libc/src/strcstr.c @@ -86,7 +86,7 @@ PL_strncasestr(const char *big, const char *little, PRUint32 max) max -= ll; max++; - for( ; *big && max; big++, max-- ) + for( ; max && *big; big++, max-- ) /* obvious improvement available here */ if( 0 == PL_strncasecmp(big, little, ll) ) return (char *)big; @@ -105,7 +105,7 @@ PL_strncaserstr(const char *big, const char *little, PRUint32 max) ll = PL_strlen(little); - for( p = big; *p && max; p++, max-- ) + for( p = big; max && *p; p++, max-- ) ; p -= ll; diff --git a/lib/libc/src/strlen.c b/lib/libc/src/strlen.c index 7a797d93..30ed4403 100644 --- a/lib/libc/src/strlen.c +++ b/lib/libc/src/strlen.c @@ -59,7 +59,7 @@ PL_strnlen(const char *str, PRUint32 max) register const char *s; if( (const char *)0 == str ) return 0; - for( s = str; *s && max; s++, max-- ) + for( s = str; max && *s; s++, max-- ) ; return (PRUint32)(s - str); diff --git a/lib/libc/src/strpbrk.c b/lib/libc/src/strpbrk.c index 4174fd30..513ed2f6 100644 --- a/lib/libc/src/strpbrk.c +++ b/lib/libc/src/strpbrk.c @@ -75,7 +75,7 @@ PL_strnpbrk(const char *s, const char *list, PRUint32 max) if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0; - for( ; *s && max; s++, max-- ) + for( ; max && *s; s++, max-- ) for( p = list; *p; p++ ) if( *s == *p ) return (char *)s; @@ -91,7 +91,7 @@ PL_strnprbrk(const char *s, const char *list, PRUint32 max) if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0; - for( r = s; *r && max; r++, max-- ) + for( r = s; max && *r; r++, max-- ) ; for( r--; r >= s; r-- ) diff --git a/lib/libc/src/strstr.c b/lib/libc/src/strstr.c index 7d40ed3b..3f38a34f 100644 --- a/lib/libc/src/strstr.c +++ b/lib/libc/src/strstr.c @@ -86,7 +86,7 @@ PL_strnstr(const char *big, const char *little, PRUint32 max) max -= ll; max++; - for( ; *big && max; big++, max-- ) + for( ; max && *big; big++, max-- ) if( *little == *big ) if( 0 == PL_strncmp(big, little, ll) ) return (char *)big; @@ -105,7 +105,7 @@ PL_strnrstr(const char *big, const char *little, PRUint32 max) ll = PL_strlen(little); - for( p = big; *p && max; p++, max-- ) + for( p = big; max && *p; p++, max-- ) ; p -= ll; diff --git a/lib/prstreams/plvrsion.c b/lib/prstreams/plvrsion.c index fdfb42e6..b07aa351 100644 --- a/lib/prstreams/plvrsion.c +++ b/lib/prstreams/plvrsion.c @@ -84,7 +84,7 @@ PRVersionDescription VERSION_DESC_NAME = /* description */ "Portable runtime", /* what we are */ /* security */ "N/A", /* not applicable here */ /* copywrite */ "Copyright (c) 1998 Netscape Communications Corporation. All Rights Reserved", - /* comment */ "http://www.mozilla.org/NPL/", + /* comment */ "http://www.mozilla.org/MPL/", /* specialString */ "" }; diff --git a/pr/include/md/_hpux.h b/pr/include/md/_hpux.h index c83e7c3c..b09b7aaa 100644 --- a/pr/include/md/_hpux.h +++ b/pr/include/md/_hpux.h @@ -55,7 +55,11 @@ #undef HAVE_WEAK_IO_SYMBOLS #undef HAVE_WEAK_MALLOC_SYMBOLS #define HAVE_DLL +#ifdef IS_64 +#define USE_DLFCN +#else #define USE_HPSHL +#endif #ifndef HAVE_STRERROR #define HAVE_STRERROR #endif diff --git a/pr/include/md/_hpux64.cfg b/pr/include/md/_hpux64.cfg index bacd0272..338e3016 100644 --- a/pr/include/md/_hpux64.cfg +++ b/pr/include/md/_hpux64.cfg @@ -82,8 +82,8 @@ #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_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 diff --git a/pr/include/md/_macos.h b/pr/include/md/_macos.h index 7d9d0302..d2c25d1d 100644 --- a/pr/include/md/_macos.h +++ b/pr/include/md/_macos.h @@ -122,7 +122,7 @@ struct _MDFileDesc { PRLock * miscLock; /* Server sockets: listen bit tells the notifier func what to do */ - PRBool doListen; + PRBool doListen; /* stored error for non-blocking connects, as a Unix-style error code */ OTReason disconnectError; diff --git a/pr/include/md/_os2.h b/pr/include/md/_os2.h index 799901e2..055ce261 100644 --- a/pr/include/md/_os2.h +++ b/pr/include/md/_os2.h @@ -289,7 +289,7 @@ extern void _MD_MakeNonblock(PRFileDesc *f); #define _MD_INIT_FD_INHERITABLE (_PR_MD_INIT_FD_INHERITABLE) #define _MD_QUERY_FD_INHERITABLE (_PR_MD_QUERY_FD_INHERITABLE) #define _MD_SHUTDOWN (_PR_MD_SHUTDOWN) -#define _MD_LISTEN(s, backlog) listen(s->secret->md.osfd,backlog) +#define _MD_LISTEN _PR_MD_LISTEN extern PRInt32 _MD_CloseSocket(PRInt32 osfd); #define _MD_CLOSE_SOCKET _MD_CloseSocket #define _MD_SENDTO (_PR_MD_SENDTO) diff --git a/pr/include/md/_os2_errors.h b/pr/include/md/_os2_errors.h index 6f742be8..f196a201 100644 --- a/pr/include/md/_os2_errors.h +++ b/pr/include/md/_os2_errors.h @@ -40,6 +40,9 @@ #include <assert.h> #endif +NSPR_API(void) _MD_os2_map_default_error(PRInt32 err); +#define _PR_MD_MAP_DEFAULT_ERROR _MD_os2_map_default_error + NSPR_API(void) _MD_os2_map_opendir_error(PRInt32 err); #define _PR_MD_MAP_OPENDIR_ERROR _MD_os2_map_opendir_error diff --git a/pr/include/md/_win16.h b/pr/include/md/_win16.h index 147ef77a..15edc7db 100644 --- a/pr/include/md/_win16.h +++ b/pr/include/md/_win16.h @@ -443,13 +443,6 @@ NSPR_API(void) _PR_UserDestroyThread(PRThread *thread); /* - * _PR_ShutdownLinker unloads all dlls loaded by the application via - * calls to PR_LoadLibrary - */ -void _PR_ShutdownLinker(void); - - -/* ** If thread emulation is used, then setjmp/longjmp stores the register ** state of each thread. ** diff --git a/pr/include/md/_win95.h b/pr/include/md/_win95.h index 6a9bb271..86b39d5d 100644 --- a/pr/include/md/_win95.h +++ b/pr/include/md/_win95.h @@ -243,7 +243,7 @@ extern void _MD_MakeNonblock(PRFileDesc *f); #define _MD_INIT_FD_INHERITABLE _PR_MD_INIT_FD_INHERITABLE #define _MD_QUERY_FD_INHERITABLE _PR_MD_QUERY_FD_INHERITABLE #define _MD_SHUTDOWN _PR_MD_SHUTDOWN -#define _MD_LISTEN(s, backlog) listen(s->secret->md.osfd,backlog) +#define _MD_LISTEN _PR_MD_LISTEN extern PRInt32 _MD_CloseSocket(PRInt32 osfd); #define _MD_CLOSE_SOCKET _MD_CloseSocket #define _MD_SENDTO _PR_MD_SENDTO diff --git a/pr/include/prinet.h b/pr/include/prinet.h index f5aea7eb..8dba5cd1 100644 --- a/pr/include/prinet.h +++ b/pr/include/prinet.h @@ -57,7 +57,7 @@ #define prinet_h__ #if defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS) -#ifdef linux +#ifdef LINUX #undef __STRICT_ANSI__ #define __STRICT_ANSI__ #endif diff --git a/pr/include/private/primpl.h b/pr/include/private/primpl.h index 7984ebbf..2501b700 100644 --- a/pr/include/private/primpl.h +++ b/pr/include/private/primpl.h @@ -740,10 +740,6 @@ extern void _PR_ClockInterrupt(void); extern void _PR_Schedule(void); extern void _PR_SetThreadPriority( PRThread* thread, PRThreadPriority priority); -NSPR_API(void) _PR_Unlock(PRLock *lock); - -NSPR_API(void) _PR_SuspendThread(PRThread *t); -NSPR_API(void) _PR_ResumeThread(PRThread *t); /*********************************************************************** ** FUNCTION: _PR_NewSegment() @@ -1745,6 +1741,16 @@ extern void _PR_InitMW(void); extern void _PR_InitRWLocks(void); extern void _PR_NotifyCondVar(PRCondVar *cvar, PRThread *me); extern void _PR_CleanupThread(PRThread *thread); +extern void _PR_CleanupCallOnce(void); +extern void _PR_CleanupMW(void); +extern void _PR_CleanupDtoa(void); +extern void _PR_ShutdownLinker(void); +extern void _PR_CleanupEnv(void); +extern void _PR_CleanupIO(void); +extern void _PR_CleanupNet(void); +extern void _PR_CleanupLayerCache(void); +extern void _PR_CleanupStacks(void); +extern void _PR_CleanupThreads(void); extern void _PR_CleanupTPD(void); extern void _PR_Cleanup(void); extern void _PR_LogCleanup(void); @@ -1799,7 +1805,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) +#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS) #define _PR_ZONE_ALLOCATOR #endif diff --git a/pr/src/io/prfdcach.c b/pr/src/io/prfdcach.c index 8803a419..82cbf058 100644 --- a/pr/src/io/prfdcach.c +++ b/pr/src/io/prfdcach.c @@ -73,7 +73,7 @@ static PRFileDesc **stack2fd = &(((PRFileDesc*)NULL)->higher); ** Get a FileDescriptor from the cache if one exists. If not allocate ** a new one from the heap. */ -PRFileDesc *_PR_Getfd() +PRFileDesc *_PR_Getfd(void) { PRFileDesc *fd; /* @@ -248,7 +248,7 @@ PR_IMPLEMENT(PRStatus) PR_SetFDCacheSize(PRIntn low, PRIntn high) return PR_SUCCESS; } /* PR_SetFDCacheSize */ -void _PR_InitFdCache() +void _PR_InitFdCache(void) { /* ** The fd caching is enabled by default for DEBUG builds, diff --git a/pr/src/io/prio.c b/pr/src/io/prio.c index 74336d1e..36c8df8a 100644 --- a/pr/src/io/prio.c +++ b/pr/src/io/prio.c @@ -75,6 +75,27 @@ void _PR_InitIO(void) _PR_MD_INIT_IO(); } +void _PR_CleanupIO(void) +{ + PR_FreeFileDesc(_pr_stdin); + _pr_stdin = NULL; + PR_FreeFileDesc(_pr_stdout); + _pr_stdout = NULL; + PR_FreeFileDesc(_pr_stderr); + _pr_stderr = NULL; + + if (_pr_flock_cv) { + PR_DestroyCondVar(_pr_flock_cv); + _pr_flock_cv = NULL; + } + if (_pr_flock_lock) { + PR_DestroyLock(_pr_flock_lock); + _pr_flock_lock = NULL; + } + + _PR_CleanupFdCache(); +} + PR_IMPLEMENT(PRFileDesc*) PR_GetSpecialFD(PRSpecialFD osfd) { PRFileDesc *result = NULL; diff --git a/pr/src/io/priometh.c b/pr/src/io/priometh.c index a2b8e9c8..b9279fad 100644 --- a/pr/src/io/priometh.c +++ b/pr/src/io/priometh.c @@ -76,21 +76,21 @@ PRIOMethods _pr_faulty_methods = { (PRReservedFN)_PR_InvalidInt }; -PRIntn _PR_InvalidInt() +PRIntn _PR_InvalidInt(void) { PR_ASSERT(!"I/O method is invalid"); PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; } /* _PR_InvalidInt */ -PRInt16 _PR_InvalidInt16() +PRInt16 _PR_InvalidInt16(void) { PR_ASSERT(!"I/O method is invalid"); PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; } /* _PR_InvalidInt */ -PRInt64 _PR_InvalidInt64() +PRInt64 _PR_InvalidInt64(void) { PRInt64 rv; LL_I2L(rv, -1); @@ -103,7 +103,7 @@ PRInt64 _PR_InvalidInt64() * An invalid method that returns PRStatus */ -PRStatus _PR_InvalidStatus() +PRStatus _PR_InvalidStatus(void) { PR_ASSERT(!"I/O method is invalid"); PR_SetError(PR_INVALID_METHOD_ERROR, 0); @@ -114,7 +114,7 @@ PRStatus _PR_InvalidStatus() * An invalid method that returns a pointer */ -PRFileDesc *_PR_InvalidDesc() +PRFileDesc *_PR_InvalidDesc(void) { PR_ASSERT(!"I/O method is invalid"); PR_SetError(PR_INVALID_METHOD_ERROR, 0); diff --git a/pr/src/io/prlayer.c b/pr/src/io/prlayer.c index 8cb5cda6..d377f546 100644 --- a/pr/src/io/prlayer.c +++ b/pr/src/io/prlayer.c @@ -459,7 +459,7 @@ static PRIOMethods pl_methods = { (PRReservedFN)_PR_InvalidInt }; -PR_IMPLEMENT(const PRIOMethods*) PR_GetDefaultIOMethods() +PR_IMPLEMENT(const PRIOMethods*) PR_GetDefaultIOMethods(void) { return &pl_methods; } /* PR_GetDefaultIOMethods */ @@ -736,11 +736,30 @@ PR_IMPLEMENT(PRFileDesc*) PR_GetIdentitiesLayer(PRFileDesc* fd, PRDescIdentity i return NULL; } /* PR_GetIdentitiesLayer */ -void _PR_InitLayerCache() +void _PR_InitLayerCache(void) { memset(&identity_cache, 0, sizeof(identity_cache)); identity_cache.ml = PR_NewLock(); PR_ASSERT(NULL != identity_cache.ml); } /* _PR_InitLayerCache */ +void _PR_CleanupLayerCache(void) +{ + if (identity_cache.ml) + { + PR_DestroyLock(identity_cache.ml); + identity_cache.ml = NULL; + } + + if (identity_cache.name) + { + PRDescIdentity ident; + + for (ident = 0; ident <= identity_cache.ident; ident++) + PR_DELETE(identity_cache.name[ident]); + + PR_DELETE(identity_cache.name); + } +} /* _PR_CleanupLayerCache */ + /* prlayer.c */ diff --git a/pr/src/io/prlog.c b/pr/src/io/prlog.c index 846b052b..334fddcc 100644 --- a/pr/src/io/prlog.c +++ b/pr/src/io/prlog.c @@ -277,11 +277,16 @@ void _PR_LogCleanup(void) while (lm != NULL) { PRLogModuleInfo *next = lm->next; - PR_Free((/*const*/ char *)lm->name); + free((/*const*/ char *)lm->name); PR_Free(lm); lm = next; } logModules = NULL; + + if (_pr_logLock) { + PR_DestroyLock(_pr_logLock); + _pr_logLock = NULL; + } } static void _PR_SetLogModuleLevel( PRLogModuleInfo *lm ) diff --git a/pr/src/io/prmwait.c b/pr/src/io/prmwait.c index a48fbc19..65ea1cd6 100644 --- a/pr/src/io/prmwait.c +++ b/pr/src/io/prmwait.c @@ -58,19 +58,8 @@ typedef struct TimerEvent { struct { PRLock *ml; PRCondVar *new_timer; - PRCondVar *cancel_timer; /* The cancel_timer condition variable is - * used to cancel a timer (i.e., remove a - * timer event from the timer queue). At - * startup I'm borrowing this condition - * variable for a different purpose (to - * tell the primordial thread that the - * timer manager thread has started) so - * that I don't need to create a new - * condition variable just for this one - * time use. - */ + PRCondVar *cancel_timer; PRThread *manager_thread; - PRBool manager_started; PRCList timer_queue; } tm_vars; @@ -88,11 +77,6 @@ static void TimerManager(void *arg) TimerEvent *timer; PR_Lock(tm_vars.ml); - /* tell the primordial thread that we have started */ - tm_vars.manager_started = PR_TRUE; - if (!_native_threads_only) { - PR_NotifyCondVar(tm_vars.cancel_timer); - } while (1) { if (PR_CLIST_IS_EMPTY(&tm_vars.timer_queue)) @@ -216,16 +200,6 @@ static PRStatus TimerInit(void) { goto failed; } - /* - * Need to wait until the timer manager thread starts - * if the timer manager thread is a local thread. - */ - if (!_native_threads_only) { - PR_Lock(tm_vars.ml); - while (!tm_vars.manager_started) - PR_WaitCondVar(tm_vars.cancel_timer, PR_INTERVAL_NO_TIMEOUT); - PR_Unlock(tm_vars.ml); - } return PR_SUCCESS; failed: @@ -269,6 +243,17 @@ void _PR_InitMW(void) max_polling_interval = PR_MillisecondsToInterval(MAX_POLLING_INTERVAL); } /* _PR_InitMW */ +void _PR_CleanupMW(void) +{ + PR_DestroyLock(mw_lock); + mw_lock = NULL; + if (mw_state->group) { + PR_DestroyWaitGroup(mw_state->group); + /* mw_state->group is set to NULL as a side effect. */ + } + PR_DELETE(mw_state); +} /* _PR_CleanupMW */ + static PRWaitGroup *MW_Init2(void) { PRWaitGroup *group = mw_state->group; /* it's the null group */ diff --git a/pr/src/io/prsocket.c b/pr/src/io/prsocket.c index d8968636..acbc0016 100644 --- a/pr/src/io/prsocket.c +++ b/pr/src/io/prsocket.c @@ -1395,7 +1395,7 @@ PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPair(PRFileDesc *f[]) */ SOCKET listenSock; SOCKET osfd[2]; - struct sockaddr_in selfAddr; + struct sockaddr_in selfAddr, peerAddr; int addrLen; if (!_pr_initialized) _PR_ImplicitInitialization(); @@ -1439,10 +1439,24 @@ PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPair(PRFileDesc *f[]) addrLen) == SOCKET_ERROR) { goto failed; } - osfd[1] = accept(listenSock, NULL, NULL); + /* + * 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 osfd[0]. + */ + if (getsockname(osfd[0], (struct sockaddr *) &selfAddr, + &addrLen) == SOCKET_ERROR) { + goto failed; + } + osfd[1] = accept(listenSock, (struct sockaddr *) &peerAddr, &addrLen); if (osfd[1] == INVALID_SOCKET) { goto failed; } + if (peerAddr.sin_port != selfAddr.sin_port) { + /* the connection we accepted is not from osfd[0] */ + PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0); + goto failed; + } closesocket(listenSock); f[0] = PR_AllocFileDesc(osfd[0], PR_GetTCPMethods()); @@ -1479,7 +1493,7 @@ failed: * default implementation */ PRFileDesc *listenSock; - PRNetAddr selfAddr; + PRNetAddr selfAddr, peerAddr; PRUint16 port; f[0] = f[1] = NULL; @@ -1517,10 +1531,23 @@ failed: == PR_FAILURE) { goto failed; } - f[1] = PR_Accept(listenSock, NULL, PR_INTERVAL_NO_TIMEOUT); + /* + * 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 f[0]. + */ + if (PR_GetSockName(f[0], &selfAddr) == PR_FAILURE) { + goto failed; + } + f[1] = PR_Accept(listenSock, &peerAddr, PR_INTERVAL_NO_TIMEOUT); if (f[1] == NULL) { goto failed; } + if (peerAddr.inet.port != selfAddr.inet.port) { + /* the connection we accepted is not from f[0] */ + PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0); + goto failed; + } PR_Close(listenSock); return PR_SUCCESS; @@ -1531,6 +1558,9 @@ failed: if (f[0]) { PR_Close(f[0]); } + if (f[1]) { + PR_Close(f[1]); + } return PR_FAILURE; #endif } diff --git a/pr/src/linking/prlink.c b/pr/src/linking/prlink.c index b3802055..24a15f8a 100644 --- a/pr/src/linking/prlink.c +++ b/pr/src/linking/prlink.c @@ -262,6 +262,10 @@ void _PR_InitLinker(void) } #if defined(WIN16) +/* + * _PR_ShutdownLinker unloads all dlls loaded by the application via + * calls to PR_LoadLibrary + */ void _PR_ShutdownLinker(void) { PR_EnterMonitor(pr_linker_lock); @@ -282,6 +286,32 @@ void _PR_ShutdownLinker(void) PR_DestroyMonitor(pr_linker_lock); pr_linker_lock = NULL; } +#else +/* + * _PR_ShutdownLinker was originally only used on WIN16 (see above), + * but I think it should also be used on other platforms. However, + * I disagree with the original implementation's unloading the dlls + * for the application. Any dlls that still remain on the pr_loadmap + * list when NSPR shuts down are application programming errors. The + * only exception is pr_exe_loadmap, which was added to the list by + * NSPR and hence should be cleaned up by NSPR. + */ +void _PR_ShutdownLinker(void) +{ + /* FIXME: pr_exe_loadmap should be destroyed. */ + + PR_DestroyMonitor(pr_linker_lock); + pr_linker_lock = NULL; + + if (_pr_currentLibPath) { + free(_pr_currentLibPath); + _pr_currentLibPath = NULL; + } + +#if !defined(USE_DLFCN) && !defined(HAVE_STRERROR) + PR_DELETE(errStrBuf); +#endif +} #endif /******************************************************************************/ @@ -292,7 +322,9 @@ PR_IMPLEMENT(PRStatus) PR_SetLibraryPath(const char *path) if (!_pr_initialized) _PR_ImplicitInitialization(); PR_EnterMonitor(pr_linker_lock); - PR_FREEIF(_pr_currentLibPath); + if (_pr_currentLibPath) { + free(_pr_currentLibPath); + } if (path) { _pr_currentLibPath = strdup(path); if (!_pr_currentLibPath) { @@ -310,7 +342,7 @@ PR_IMPLEMENT(PRStatus) PR_SetLibraryPath(const char *path) ** Return the library path for finding shared libraries. */ PR_IMPLEMENT(char *) -PR_GetLibraryPath() +PR_GetLibraryPath(void) { char *ev; char *copy = NULL; /* a copy of _pr_currentLibPath */ @@ -342,7 +374,7 @@ PR_GetLibraryPath() ev = ""; len = strlen(ev) + 1; /* +1 for the null */ - p = (char*) PR_MALLOC(len); + p = (char*) malloc(len); if (p) { strcpy(p, ev); } @@ -369,7 +401,7 @@ PR_GetLibraryPath() #endif len = strlen(ev) + 1; /* +1 for the null */ - p = (char*) PR_MALLOC(len); + p = (char*) malloc(len); if (p) { strcpy(p, ev); } /* if (p) */ @@ -1148,7 +1180,8 @@ PR_UnloadLibrary(PRLibrary *lib) freeLib: PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Unloaded library %s", lib->name)); - PR_DELETE(lib->name); + free(lib->name); + lib->name = NULL; PR_DELETE(lib); if (result == -1) { PR_SetError(PR_UNLOAD_LIBRARY_ERROR, _MD_ERRNO()); diff --git a/pr/src/malloc/prmem.c b/pr/src/malloc/prmem.c index 0a70b439..20cf7e99 100644 --- a/pr/src/malloc/prmem.c +++ b/pr/src/malloc/prmem.c @@ -97,20 +97,79 @@ _PR_DestroyZones(void) while (mz->head) { MemBlockHdr *hdr = mz->head; mz->head = hdr->s.next; /* unlink it */ - pr_ZoneFree(hdr); + free(hdr); mz->elements--; } } } + use_zone_allocator = PR_FALSE; } +/* +** pr_FindSymbolInProg +** +** Find the specified data symbol in the program and return +** its address. +*/ + +#ifdef USE_DLFCN + +#include <dlfcn.h> + +static void * +pr_FindSymbolInProg(const char *name) +{ + void *h; + void *sym; + + h = dlopen(0, RTLD_LAZY); + if (h == NULL) + return NULL; + sym = dlsym(h, name); + (void)dlclose(h); + return sym; +} + +#elif defined(USE_HPSHL) + +#include <dl.h> + +static void * +pr_FindSymbolInProg(const char *name) +{ + shl_t h = NULL; + void *sym; + + if (shl_findsym(&h, name, TYPE_DATA, &sym) == -1) + return NULL; + return sym; +} + +#elif defined(USE_MACH_DYLD) + +static void * +pr_FindSymbolInProg(const char *name) +{ + /* FIXME: not implemented */ + return NULL; +} + +#else + +#error "The zone allocator is not supported on this platform" + +#endif + void _PR_InitZones(void) { int i, j; char *envp; + PRBool *sym; - if (envp = getenv("NSPR_USE_ZONE_ALLOCATOR")) { + if ((sym = pr_FindSymbolInProg("nspr_use_zone_allocator")) != NULL) { + use_zone_allocator = *sym; + } else if ((envp = getenv("NSPR_USE_ZONE_ALLOCATOR")) != NULL) { use_zone_allocator = (atoi(envp) == 1); } @@ -275,6 +334,11 @@ pr_ZoneRealloc(void *oldptr, PRUint32 bytes) PR_ASSERT(mb->s.magic == ZONE_MAGIC); if (mb->s.magic != ZONE_MAGIC) { /* Maybe this just came from ordinary malloc */ +#ifdef DEBUG + fprintf(stderr, + "Warning: reallocing memory block %p from ordinary malloc\n", + oldptr); +#endif /* We don't know how big it is. But we can fix that. */ oldptr = realloc(oldptr, bytes); if (!oldptr) { @@ -329,6 +393,10 @@ pr_ZoneFree(void *ptr) if (mb->s.magic != ZONE_MAGIC) { /* maybe this came from ordinary malloc */ +#ifdef DEBUG + fprintf(stderr, + "Warning: freeing memory block %p from ordinary malloc\n", ptr); +#endif free(ptr); return; } @@ -342,7 +410,7 @@ pr_ZoneFree(void *ptr) if (!mz) { PR_ASSERT(blockSize > 65536); /* This block was not in any zone. Just free it. */ - free(ptr); + free(mb); return; } PR_ASSERT(mz->blockSize == blockSize); diff --git a/pr/src/md/mac/macio.c b/pr/src/md/mac/macio.c index b74c864d..ef404db5 100644 --- a/pr/src/md/mac/macio.c +++ b/pr/src/md/mac/macio.c @@ -1,3 +1,4 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file @@ -30,23 +31,6 @@ * may use your version of this file under either the MPL or the * GPL. */ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * The contents of this file are subject to the Netscape Public License - * Version 1.1 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ #include <string.h> @@ -97,8 +81,7 @@ static void AsyncIOCompletion (ExtendedParamBlock *pbAsyncPtr) if (_PR_MD_GET_INTSOFF()) { thread->md.missedIONotify = PR_TRUE; cpu->u.missed[cpu->where] |= _PR_MISSED_IO; - } - else { + } else { _PR_INTSOFF(is); thread->md.osErrCode = noErr; @@ -483,8 +466,6 @@ PROffset32 _MD_LSeek(PRFileDesc *fd, PROffset32 offset, PRSeekWhence how) OSErr err = noErr; long curPos, endPos; - PR_ASSERT(offset >= 0); - /* compute new mark */ switch (how) { case PR_SEEK_SET: diff --git a/pr/src/md/mac/macsockotpt.c b/pr/src/md/mac/macsockotpt.c index 79bd372b..7bbee039 100644 --- a/pr/src/md/mac/macsockotpt.c +++ b/pr/src/md/mac/macsockotpt.c @@ -173,9 +173,9 @@ static pascal void DNSNotifierRoutine(void * contextPtr, OTEventCode otEvent, O if (_PR_MD_GET_INTSOFF()) { dnsContext.thread->md.missedIONotify = PR_TRUE; cpu->u.missed[cpu->where] |= _PR_MISSED_IO; - } - else + } else { DoneWaitingOnThisThread(dnsContext.thread); + } break; case kOTProviderWillClose: @@ -189,8 +189,7 @@ static pascal void DNSNotifierRoutine(void * contextPtr, OTEventCode otEvent, O if (_PR_MD_GET_INTSOFF()) { dnsContext.thread->md.missedIONotify = PR_TRUE; cpu->u.missed[cpu->where] |= _PR_MISSED_IO; - } - else { + } else { DoneWaitingOnThisThread(dnsContext.thread); } break; @@ -299,8 +298,7 @@ WakeUpNotifiedThread(PRThread *thread, OTResult result) if (_PR_MD_GET_INTSOFF()) { thread->md.missedIONotify = PR_TRUE; cpu->u.missed[cpu->where] |= _PR_MISSED_IO; - } - else { + } else { DoneWaitingOnThisThread(thread); } } @@ -1177,8 +1175,7 @@ static pascal void RawEndpointNotifierRoutine(void * contextPtr, OTEventCode co if (_PR_MD_GET_INTSOFF()) { thread->md.asyncNotifyPending = PR_TRUE; cpu->u.missed[cpu->where] |= _PR_MISSED_IO; - } - else { + } else { DoneWaitingOnThisThread(thread); } } diff --git a/pr/src/md/os2/objs.mk b/pr/src/md/os2/objs.mk index 1cc6029f..7c0bb943 100644 --- a/pr/src/md/os2/objs.mk +++ b/pr/src/md/os2/objs.mk @@ -1,19 +1,35 @@ -# -# The contents of this file are subject to the Netscape Public License -# Version 1.1 (the "NPL"); you may not use this file except in -# compliance with the NPL. You may obtain a copy of the NPL at -# http://www.mozilla.org/NPL/ # -# Software distributed under the NPL is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL -# for the specific language governing rights and limitations under the -# NPL. +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Netscape Portable Runtime (NSPR). +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998-2000 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the +# terms of the GNU General Public License Version 2 or later (the +# "GPL"), in which case the provisions of the GPL are applicable +# instead of those above. If you wish to allow use of your +# version of this file only under the terms of the GPL and not to +# allow others to use your version of this file under the MPL, +# indicate your decision by deleting the provisions above and +# replace them with the notice and other provisions required by +# the GPL. If you do not delete the provisions above, a recipient +# may use your version of this file under either the MPL or the +# GPL. # -# The Initial Developer of this code under the NPL is Netscape -# Communications Corporation. Portions created by Netscape are -# Copyright (C) 1998 Netscape Communications Corporation. All Rights -# Reserved. -# # This makefile appends to the variable OBJS the platform-dependent # object modules that will be part of the nspr20 library. diff --git a/pr/src/md/os2/os2sock.c b/pr/src/md/os2/os2sock.c index 36ebd46b..c41ca7ca 100644 --- a/pr/src/md/os2/os2sock.c +++ b/pr/src/md/os2/os2sock.c @@ -358,6 +358,19 @@ _PR_MD_BIND(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen) PRInt32 +_PR_MD_LISTEN(PRFileDesc *fd, PRIntn backlog) +{ + PRInt32 rv, err; + rv = listen(fd->secret->md.osfd, backlog); + if (rv < 0) { + err = sock_errno(); + _PR_MD_MAP_DEFAULT_ERROR(err); + } + return(rv); +} + + +PRInt32 _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, PRIntervalTime timeout) { diff --git a/pr/src/md/unix/darwin.c b/pr/src/md/unix/darwin.c index c7c6ca5d..43988b8d 100644 --- a/pr/src/md/unix/darwin.c +++ b/pr/src/md/unix/darwin.c @@ -130,5 +130,5 @@ int sigtimedwait(const sigset_t *set, siginfo_t *info, #endif /* _PR_PTHREADS */ -/* rhapsody.c */ +/* darwin.c */ diff --git a/pr/src/md/unix/irix.c b/pr/src/md/unix/irix.c index 7ba079f8..f3d52f01 100644 --- a/pr/src/md/unix/irix.c +++ b/pr/src/md/unix/irix.c @@ -1451,7 +1451,7 @@ void _MD_EarlyInit(void) _MD_IrixIntervalInit(); } /* _MD_EarlyInit */ -void _MD_IrixInit() +void _MD_IrixInit(void) { #if !defined(_PR_PTHREADS) struct sigaction sigact; @@ -1567,7 +1567,7 @@ static PRUint32 pr_ticks_per_second = 0; extern PRIntervalTime _PR_UNIX_GetInterval(void); extern PRIntervalTime _PR_UNIX_TicksPerSecond(void); -static void _MD_IrixIntervalInit() +static void _MD_IrixIntervalInit(void) { /* * As much as I would like, the service available through this @@ -1634,12 +1634,12 @@ static void _MD_IrixIntervalInit() } } /* _MD_IrixIntervalInit */ -PRIntervalTime _MD_IrixIntervalPerSec() +PRIntervalTime _MD_IrixIntervalPerSec(void) { return pr_ticks_per_second; } -PRIntervalTime _MD_IrixGetInterval() +PRIntervalTime _MD_IrixGetInterval(void) { if (mmem_fd != -1) { diff --git a/pr/src/md/unix/uxproces.c b/pr/src/md/unix/uxproces.c index 58b5ab8a..d469f1c4 100644 --- a/pr/src/md/unix/uxproces.c +++ b/pr/src/md/unix/uxproces.c @@ -802,7 +802,7 @@ static void pr_InstallSigchldHandler() #endif /* !defined(_PR_NATIVE_THREADS) */ -static PRStatus _MD_InitProcesses() +static PRStatus _MD_InitProcesses(void) { #if !defined(_PR_NATIVE_THREADS) int rv; diff --git a/pr/src/md/unix/uxrng.c b/pr/src/md/unix/uxrng.c index 64358289..5cfeeefd 100644 --- a/pr/src/md/unix/uxrng.c +++ b/pr/src/md/unix/uxrng.c @@ -64,6 +64,18 @@ GetHighResClock(void *buf, size_t maxbytes) #elif defined(HPUX) +#ifdef __ia64 +#include <ia64/sys/inline.h> + +static size_t +GetHighResClock(void *buf, size_t maxbytes) +{ + PRUint64 t; + + t = _Asm_mov_from_ar(_AREG44); + return _pr_CopyLowBits(buf, maxbytes, &t, sizeof(t)); +} +#else static size_t GetHighResClock(void *buf, size_t maxbytes) { @@ -73,6 +85,7 @@ GetHighResClock(void *buf, size_t maxbytes) cr16val = ret_cr16(); return(_pr_CopyLowBits(buf, maxbytes, &cr16val, sizeof(cr16val))); } +#endif #elif defined(OSF1) @@ -210,7 +223,7 @@ static size_t GetHighResClock(void *buf, size_t maxbuf) } iotimer_addr = (unsigned *) mmap(0, pgoffmask, PROT_READ, MAP_PRIVATE, mfd, (int)raddr); - if (iotimer_addr == (void*)-1) { + if (iotimer_addr == (unsigned*)-1) { close(mfd); iotimer_addr = NULL; return 0; diff --git a/pr/src/md/unix/uxshm.c b/pr/src/md/unix/uxshm.c index 888cbe04..516ea855 100644 --- a/pr/src/md/unix/uxshm.c +++ b/pr/src/md/unix/uxshm.c @@ -311,7 +311,6 @@ extern PRSharedMemory * _MD_OpenSharedMemory( ) { PRStatus rc = PR_SUCCESS; - PRIntn id; PRInt32 end; PRSharedMemory *shm; char ipcname[PR_IPC_NAME_SIZE]; diff --git a/pr/src/md/windows/Makefile.in b/pr/src/md/windows/Makefile.in index 283fa4a4..d9dce1d0 100644 --- a/pr/src/md/windows/Makefile.in +++ b/pr/src/md/windows/Makefile.in @@ -105,3 +105,11 @@ include $(topsrcdir)/config/rules.mk export:: $(TARGETS) +# Bug 122433 workaround: disable global optimization (-Og-) on ntio.c. +ifdef BUILD_OPT +ifeq ($(OS_TARGET), WINNT) +$(OBJDIR)/ntio.$(OBJ_SUFFIX): ntio.c + @$(MAKE_OBJDIR) + $(CC) -Fo$@ -c $(CFLAGS) -Og- $< +endif +endif diff --git a/pr/src/md/windows/ntthread.c b/pr/src/md/windows/ntthread.c index 9c3e2baf..1c3fb531 100644 --- a/pr/src/md/windows/ntthread.c +++ b/pr/src/md/windows/ntthread.c @@ -238,6 +238,13 @@ _PR_MD_CREATE_THREAD(PRThread *thread, } thread->md.id = thread->id; + /* + * On windows, a thread is created with a thread priority of + * THREAD_PRIORITY_NORMAL. + */ + if (priority != PR_PRIORITY_NORMAL) { + _PR_MD_SET_PRIORITY(&(thread->md), priority); + } /* Activate the thread */ if ( ResumeThread( thread->md.handle ) != -1) diff --git a/pr/src/md/windows/w95sock.c b/pr/src/md/windows/w95sock.c index d36ffdcd..eaa870e3 100644 --- a/pr/src/md/windows/w95sock.c +++ b/pr/src/md/windows/w95sock.c @@ -168,7 +168,6 @@ PRInt32 _PR_MD_BIND(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen) { PRInt32 rv; - int one = 1; rv = bind(fd->secret->md.osfd, (const struct sockaddr *)&(addr->inet), addrlen); @@ -180,6 +179,20 @@ _PR_MD_BIND(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen) return 0; } +PRInt32 +_PR_MD_LISTEN(PRFileDesc *fd, PRIntn backlog) +{ + PRInt32 rv; + + rv = listen(fd->secret->md.osfd, backlog); + + if (rv == SOCKET_ERROR) { + _PR_MD_MAP_DEFAULT_ERROR(WSAGetLastError()); + return -1; + } + + return 0; +} PRInt32 _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, diff --git a/pr/src/md/windows/w95thred.c b/pr/src/md/windows/w95thred.c index a70f1620..f8a70043 100644 --- a/pr/src/md/windows/w95thred.c +++ b/pr/src/md/windows/w95thred.c @@ -131,7 +131,13 @@ _PR_MD_CREATE_THREAD(PRThread *thread, } thread->md.id = thread->id; - _PR_MD_SET_PRIORITY(&(thread->md), priority); + /* + * On windows, a thread is created with a thread priority of + * THREAD_PRIORITY_NORMAL. + */ + if (priority != PR_PRIORITY_NORMAL) { + _PR_MD_SET_PRIORITY(&(thread->md), priority); + } /* Activate the thread */ if ( ResumeThread( thread->md.handle ) != -1) diff --git a/pr/src/misc/pralarm.c b/pr/src/misc/pralarm.c index 488ce5a4..90c06442 100644 --- a/pr/src/misc/pralarm.c +++ b/pr/src/misc/pralarm.c @@ -180,7 +180,7 @@ static void PR_CALLBACK pr_alarmNotifier(void *arg) } /* pr_alarm_notifier */ -PR_IMPLEMENT(PRAlarm*) PR_CreateAlarm() +PR_IMPLEMENT(PRAlarm*) PR_CreateAlarm(void) { PRAlarm *alarm = PR_NEWZAP(PRAlarm); if (alarm != NULL) diff --git a/pr/src/misc/prdtoa.c b/pr/src/misc/prdtoa.c index e2e715fe..7f0b9cf6 100644 --- a/pr/src/misc/prdtoa.c +++ b/pr/src/misc/prdtoa.c @@ -1180,6 +1180,16 @@ void _PR_InitDtoa(void) p5s_lock = PR_NewLock(); } +void _PR_CleanupDtoa(void) +{ + PR_DestroyLock(freelist_lock); + freelist_lock = NULL; + PR_DestroyLock(p5s_lock); + p5s_lock = NULL; + + /* FIXME: deal with freelist and p5s. */ +} + #if defined(HAVE_WATCOM_BUG_1) PRFloat64 __pascal __loadds __export #else diff --git a/pr/src/misc/prenv.c b/pr/src/misc/prenv.c index 6ae069fc..fdcfb017 100644 --- a/pr/src/misc/prenv.c +++ b/pr/src/misc/prenv.c @@ -38,28 +38,37 @@ /* Lock used to lock the environment */ #if defined(_PR_NO_PREEMPT) #define _PR_NEW_LOCK_ENV() +#define _PR_DELETE_LOCK_ENV() #define _PR_LOCK_ENV() #define _PR_UNLOCK_ENV() #elif defined(_PR_LOCAL_THREADS_ONLY) extern _PRCPU * _pr_primordialCPU; static PRIntn _is; #define _PR_NEW_LOCK_ENV() +#define _PR_DELETE_LOCK_ENV() #define _PR_LOCK_ENV() if (_pr_primordialCPU) _PR_INTSOFF(_is); #define _PR_UNLOCK_ENV() if (_pr_primordialCPU) _PR_INTSON(_is); #else static PRLock *_pr_envLock = NULL; #define _PR_NEW_LOCK_ENV() {_pr_envLock = PR_NewLock();} +#define _PR_DELETE_LOCK_ENV() \ + { if (_pr_envLock) { PR_DestroyLock(_pr_envLock); _pr_envLock = NULL; } } #define _PR_LOCK_ENV() { if (_pr_envLock) PR_Lock(_pr_envLock); } #define _PR_UNLOCK_ENV() { if (_pr_envLock) PR_Unlock(_pr_envLock); } #endif /************************************************************************/ -void _PR_InitEnv() +void _PR_InitEnv(void) { _PR_NEW_LOCK_ENV(); } +void _PR_CleanupEnv(void) +{ + _PR_DELETE_LOCK_ENV(); +} + PR_IMPLEMENT(char*) PR_GetEnv(const char *var) { char *ev; diff --git a/pr/src/misc/prerr.c b/pr/src/misc/prerr.c index 68bcc6ce..be24aff7 100644 --- a/pr/src/misc/prerr.c +++ b/pr/src/misc/prerr.c @@ -119,6 +119,6 @@ static const struct PRErrorMessage text[] = { static const struct PRErrorTable et = { text, "prerr", -6000L, 75 }; -void nspr_InitializePRErrorTable() { +void nspr_InitializePRErrorTable(void) { PR_ErrorInstallTable(&et); } diff --git a/pr/src/misc/prerr.et b/pr/src/misc/prerr.et index c04440f0..e7e21305 100644 --- a/pr/src/misc/prerr.et +++ b/pr/src/misc/prerr.et @@ -1,17 +1,35 @@ -# The contents of this file are subject to the Netscape Public License -# Version 1.1 (the "NPL"); you may not use this file except in -# compliance with the NPL. You may obtain a copy of the NPL at -# http://www.mozilla.org/NPL/ -# -# Software distributed under the NPL is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL -# for the specific language governing rights and limitations under the -# NPL. -# -# The Initial Developer of this code under the NPL is Netscape -# Communications Corporation. Portions created by Netscape are -# Copyright (C) 1998 Netscape Communications Corporation. All Rights -# Reserved. +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Netscape Portable Runtime (NSPR). +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998-2000 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the +# terms of the GNU General Public License Version 2 or later (the +# "GPL"), in which case the provisions of the GPL are applicable +# instead of those above. If you wish to allow use of your +# version of this file only under the terms of the GPL and not to +# allow others to use your version of this file under the MPL, +# indicate your decision by deleting the provisions above and +# replace them with the notice and other provisions required by +# the GPL. If you do not delete the provisions above, a recipient +# may use your version of this file under either the MPL or the +# GPL. +# et nspr -6000 diff --git a/pr/src/misc/prerror.c b/pr/src/misc/prerror.c index 8456d9d2..6e0d5f19 100644 --- a/pr/src/misc/prerror.c +++ b/pr/src/misc/prerror.c @@ -37,13 +37,13 @@ #include <string.h> #include <stdlib.h> -PR_IMPLEMENT(PRErrorCode) PR_GetError() +PR_IMPLEMENT(PRErrorCode) PR_GetError(void) { PRThread *thread = PR_GetCurrentThread(); return thread->errorCode; } -PR_IMPLEMENT(PRInt32) PR_GetOSError() +PR_IMPLEMENT(PRInt32) PR_GetOSError(void) { PRThread *thread = PR_GetCurrentThread(); return thread->osErrorCode; diff --git a/pr/src/misc/prinit.c b/pr/src/misc/prinit.c index c8adb649..e512f1e0 100644 --- a/pr/src/misc/prinit.c +++ b/pr/src/misc/prinit.c @@ -161,7 +161,7 @@ static void _pr_SetNativeThreadsOnlyMode(void) #endif #if !defined(_PR_INET6) || defined(_PR_INET6_PROBE) -extern PRStatus _pr_init_ipv6(); +extern PRStatus _pr_init_ipv6(void); #endif static void _PR_InitStuff(void) @@ -169,6 +169,9 @@ static void _PR_InitStuff(void) if (_pr_initialized) return; _pr_initialized = PR_TRUE; +#ifdef _PR_ZONE_ALLOCATOR + _PR_InitZones(); +#endif #ifdef WINNT _pr_SetNativeThreadsOnlyMode(); #endif @@ -220,10 +223,6 @@ static void _PR_InitStuff(void) _PR_InitCPUs(); #endif -#ifdef _PR_ZONE_ALLOCATOR - _PR_InitZones(); -#endif - /* * XXX: call _PR_InitMem only on those platforms for which nspr implements * malloc, for now. @@ -251,7 +250,7 @@ static void _PR_InitStuff(void) _PR_MD_FINAL_INIT(); } -void _PR_ImplicitInitialization() +void _PR_ImplicitInitialization(void) { _PR_InitStuff(); @@ -417,9 +416,10 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup() PR_ASSERT((_PR_IS_NATIVE_THREAD(me)) || (me->cpu->id == 0)); #endif -#if defined(WIN16) + _PR_CleanupMW(); + _PR_CleanupDtoa(); + _PR_CleanupCallOnce(); _PR_ShutdownLinker(); -#endif /* Release the primordial thread's private data, etc. */ _PR_CleanupThread(me); @@ -428,7 +428,6 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup() PR_LOG(_pr_thread_lm, PR_LOG_MIN, ("PR_Cleanup: clean up before destroying thread")); _PR_LogCleanup(); - _PR_CleanupFdCache(); /* * This part should look like the end of _PR_NativeRunThread @@ -450,6 +449,14 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup() * Ideally, for each _PR_InitXXX(), there should be a corresponding * _PR_XXXCleanup() that we can call here. */ + _PR_CleanupNet(); + _PR_CleanupIO(); + _PR_CleanupThreads(); + PR_DestroyLock(_pr_sleeplock); + _pr_sleeplock = NULL; + _PR_CleanupLayerCache(); + _PR_CleanupEnv(); + _PR_CleanupStacks(); _PR_CleanupBeforeExit(); _pr_initialized = PR_FALSE; return PR_SUCCESS; @@ -770,13 +777,20 @@ static struct { PRCondVar *cv; } mod_init; -static void _PR_InitCallOnce() { +static void _PR_InitCallOnce(void) { mod_init.ml = PR_NewLock(); PR_ASSERT(NULL != mod_init.ml); mod_init.cv = PR_NewCondVar(mod_init.ml); PR_ASSERT(NULL != mod_init.cv); } +void _PR_CleanupCallOnce() +{ + PR_DestroyLock(mod_init.ml); + mod_init.ml = NULL; + PR_DestroyCondVar(mod_init.cv); + mod_init.cv = NULL; +} PR_IMPLEMENT(PRStatus) PR_CallOnce( PRCallOnceType *once, diff --git a/pr/src/misc/prinrval.c b/pr/src/misc/prinrval.c index d0af3977..a319e8cb 100644 --- a/pr/src/misc/prinrval.c +++ b/pr/src/misc/prinrval.c @@ -68,13 +68,13 @@ void _PR_InitClock(void) * 2) The units here are milliseconds. That's not appropriate for our use. */ -PR_IMPLEMENT(PRIntervalTime) PR_IntervalNow() +PR_IMPLEMENT(PRIntervalTime) PR_IntervalNow(void) { if (!_pr_initialized) _PR_ImplicitInitialization(); return _PR_MD_GET_INTERVAL(); } /* PR_IntervalNow */ -PR_EXTERN(PRUint32) PR_TicksPerSecond() +PR_EXTERN(PRUint32) PR_TicksPerSecond(void) { if (!_pr_initialized) _PR_ImplicitInitialization(); return _PR_MD_INTERVAL_PER_SEC(); diff --git a/pr/src/misc/prnetdb.c b/pr/src/misc/prnetdb.c index 03a84e7e..64006266 100644 --- a/pr/src/misc/prnetdb.c +++ b/pr/src/misc/prnetdb.c @@ -182,6 +182,22 @@ void _PR_InitNet(void) #endif } +void _PR_CleanupNet(void) +{ +#if !defined(_PR_NO_DNS_LOCK) + if (_pr_dnsLock) { + PR_DestroyLock(_pr_dnsLock); + _pr_dnsLock = NULL; + } +#endif +#if !defined(_PR_HAVE_GETPROTO_R) + if (_getproto_lock) { + PR_DestroyLock(_getproto_lock); + _getproto_lock = NULL; + } +#endif +} + /* ** Allocate space from the buffer, aligning it to "align" before doing ** the allocation. "align" must be a power of 2. @@ -520,7 +536,6 @@ PR_IMPLEMENT(PRStatus) PR_GetIPNodeByName( if (!_pr_initialized) _PR_ImplicitInitialization(); - PR_ASSERT(af == PR_AF_INET || af == PR_AF_INET6); if (af != PR_AF_INET && af != PR_AF_INET6) { PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); return PR_FAILURE; @@ -867,7 +882,6 @@ PR_IMPLEMENT(PRStatus) PR_GetProtoByName( } #endif /* defined(_PR_HAVE_GETPROTO_R_INT) */ - PR_ASSERT(PR_NETDB_BUF_SIZE <= buflen); if (PR_NETDB_BUF_SIZE > buflen) { PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); @@ -948,7 +962,6 @@ PR_IMPLEMENT(PRStatus) PR_GetProtoByNumber( } #endif /* defined(_PR_HAVE_GETPROTO_R_INT) */ - PR_ASSERT(PR_NETDB_BUF_SIZE <= buflen); if (PR_NETDB_BUF_SIZE > buflen) { PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); @@ -1488,8 +1501,6 @@ PR_IMPLEMENT(PRStatus) PR_NetAddrToString( } else { - PR_ASSERT(AF_INET == addr->raw.family); - PR_ASSERT(size >= 16); if (size < 16) goto failed; if (AF_INET != addr->raw.family) goto failed; else diff --git a/pr/src/misc/prsystem.c b/pr/src/misc/prsystem.c index bb786766..9d607d2d 100644 --- a/pr/src/misc/prsystem.c +++ b/pr/src/misc/prsystem.c @@ -58,7 +58,7 @@ #endif #if defined(HPUX) -#include <sys/mp.h> +#include <sys/mpctl.h> #endif #if defined(XP_UNIX) @@ -66,7 +66,7 @@ #include <sys/utsname.h> #endif -PR_IMPLEMENT(char) PR_GetDirectorySeparator() +PR_IMPLEMENT(char) PR_GetDirectorySeparator(void) { return PR_DIRECTORY_SEPARATOR; } /* PR_GetDirectorySeparator */ @@ -74,7 +74,7 @@ PR_IMPLEMENT(char) PR_GetDirectorySeparator() /* ** OBSOLETE -- the function name is misspelled. */ -PR_IMPLEMENT(char) PR_GetDirectorySepartor() +PR_IMPLEMENT(char) PR_GetDirectorySepartor(void) { #if defined(DEBUG) static PRBool warn = PR_TRUE; @@ -150,7 +150,6 @@ PR_IMPLEMENT(PRStatus) PR_GetSystemInfo(PRSysInfo cmd, char *buf, PRUint32 bufle default: PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); return PR_FAILURE; - break; } return PR_SUCCESS; } diff --git a/pr/src/misc/prtime.c b/pr/src/misc/prtime.c index e31ba74b..0aa6e46c 100644 --- a/pr/src/misc/prtime.c +++ b/pr/src/misc/prtime.c @@ -64,7 +64,7 @@ * each month, where index 1 is January, and day 0 is January 1. */ -static int lastDayOfMonth[2][13] = { +static const int lastDayOfMonth[2][13] = { {-1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364}, {-1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365} }; @@ -73,7 +73,7 @@ static int lastDayOfMonth[2][13] = { * The number of days in a month */ -static PRInt8 nDays[2][12] = { +static const PRInt8 nDays[2][12] = { {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} }; diff --git a/pr/src/misc/prtpool.c b/pr/src/misc/prtpool.c index 2f43c676..acf6ec77 100644 --- a/pr/src/misc/prtpool.c +++ b/pr/src/misc/prtpool.c @@ -166,7 +166,7 @@ struct PRJob { PR_END_MACRO static void delete_job(PRJob *jobp); -static PRThreadPool * alloc_threadpool(); +static PRThreadPool * alloc_threadpool(void); static PRJob * alloc_job(PRBool joinable, PRThreadPool *tp); static void notify_ioq(PRThreadPool *tp); static void notify_timerq(PRThreadPool *tp); @@ -599,7 +599,7 @@ delete_threadpool(PRThreadPool *tp) } static PRThreadPool * -alloc_threadpool() +alloc_threadpool(void) { PRThreadPool *tp; diff --git a/pr/src/prvrsion.c b/pr/src/prvrsion.c index bb6ea3ce..cbb07d76 100644 --- a/pr/src/prvrsion.c +++ b/pr/src/prvrsion.c @@ -86,7 +86,7 @@ PRVersionDescription VERSION_DESC_NAME = /* description */ "Portable runtime", /* what we are */ /* security */ "N/A", /* not applicable here */ /* copywrite */ "Copyright (c) 1998 Netscape Communications Corporation. All Rights Reserved", - /* comment */ "License information: http://www.mozilla.org/NPL/", + /* comment */ "License information: http://www.mozilla.org/MPL/", /* specialString */ "" }; diff --git a/pr/src/pthreads/ptio.c b/pr/src/pthreads/ptio.c index d62967f2..5bb7e321 100644 --- a/pr/src/pthreads/ptio.c +++ b/pr/src/pthreads/ptio.c @@ -1059,7 +1059,7 @@ static PRBool pt_solaris_sendfile_cont(pt_Continuation *op, PRInt16 revents) } #endif /* SOLARIS */ -void _PR_InitIO() +void _PR_InitIO(void) { #if defined(DEBUG) memset(&pt_debug, 0, sizeof(PTDebug)); @@ -1082,6 +1082,34 @@ void _PR_InitIO() } /* _PR_InitIO */ +void _PR_CleanupIO(void) +{ + _PR_Putfd(_pr_stdin); + _pr_stdin = NULL; + _PR_Putfd(_pr_stdout); + _pr_stdout = NULL; + _PR_Putfd(_pr_stderr); + _pr_stderr = NULL; + + _PR_CleanupFdCache(); + + if (_pr_flock_cv) + { + PR_DestroyCondVar(_pr_flock_cv); + _pr_flock_cv = NULL; + } + if (_pr_flock_lock) + { + PR_DestroyLock(_pr_flock_lock); + _pr_flock_lock = NULL; + } + if (_pr_rename_lock) + { + PR_DestroyLock(_pr_rename_lock); + _pr_rename_lock = NULL; + } +} /* _PR_CleanupIO */ + PR_IMPLEMENT(PRFileDesc*) PR_GetSpecialFD(PRSpecialFD osfd) { PRFileDesc *result = NULL; @@ -3058,27 +3086,27 @@ static PRFileDesc *pt_SetMethods( return fd; } /* pt_SetMethods */ -PR_IMPLEMENT(const PRIOMethods*) PR_GetFileMethods() +PR_IMPLEMENT(const PRIOMethods*) PR_GetFileMethods(void) { return &_pr_file_methods; } /* PR_GetFileMethods */ -PR_IMPLEMENT(const PRIOMethods*) PR_GetPipeMethods() +PR_IMPLEMENT(const PRIOMethods*) PR_GetPipeMethods(void) { return &_pr_pipe_methods; } /* PR_GetPipeMethods */ -PR_IMPLEMENT(const PRIOMethods*) PR_GetTCPMethods() +PR_IMPLEMENT(const PRIOMethods*) PR_GetTCPMethods(void) { return &_pr_tcp_methods; } /* PR_GetTCPMethods */ -PR_IMPLEMENT(const PRIOMethods*) PR_GetUDPMethods() +PR_IMPLEMENT(const PRIOMethods*) PR_GetUDPMethods(void) { return &_pr_udp_methods; } /* PR_GetUDPMethods */ -static const PRIOMethods* PR_GetSocketPollFdMethods() +static const PRIOMethods* PR_GetSocketPollFdMethods(void) { return &_pr_socketpollfd_methods; } /* PR_GetSocketPollFdMethods */ @@ -3989,14 +4017,14 @@ PR_IMPLEMENT(PRDirEntry*) PR_ReadDir(PRDir *dir, PRDirFlags flags) return &dir->d; } /* PR_ReadDir */ -PR_IMPLEMENT(PRFileDesc*) PR_NewUDPSocket() +PR_IMPLEMENT(PRFileDesc*) PR_NewUDPSocket(void) { PRIntn domain = PF_INET; return PR_Socket(domain, SOCK_DGRAM, 0); } /* PR_NewUDPSocket */ -PR_IMPLEMENT(PRFileDesc*) PR_NewTCPSocket() +PR_IMPLEMENT(PRFileDesc*) PR_NewTCPSocket(void) { PRIntn domain = PF_INET; @@ -4094,7 +4122,7 @@ PR_IMPLEMENT(PRStatus) PR_SetFDInheritable( { return PR_FAILURE; } - fd->secret->inheritable = inheritable; + fd->secret->inheritable = (_PRTriStateBool) inheritable; } return PR_SUCCESS; } diff --git a/pr/src/pthreads/ptsynch.c b/pr/src/pthreads/ptsynch.c index 4400e8df..bc714e6d 100644 --- a/pr/src/pthreads/ptsynch.c +++ b/pr/src/pthreads/ptsynch.c @@ -1041,7 +1041,7 @@ PR_IMPLEMENT(PRStatus) PRP_TryLock(PRLock *lock) return (PT_TRYLOCK_SUCCESS == rv) ? PR_SUCCESS : PR_FAILURE; } /* PRP_TryLock */ -PR_IMPLEMENT(PRCondVar*) PRP_NewNakedCondVar() +PR_IMPLEMENT(PRCondVar*) PRP_NewNakedCondVar(void) { PRCondVar *cv; diff --git a/pr/src/pthreads/ptthread.c b/pr/src/pthreads/ptthread.c index d2e8b3f4..ba61f7c1 100644 --- a/pr/src/pthreads/ptthread.c +++ b/pr/src/pthreads/ptthread.c @@ -607,9 +607,9 @@ PR_IMPLEMENT(PRStatus) PR_JoinThread(PRThread *thred) return (0 == rv) ? PR_SUCCESS : PR_FAILURE; } /* PR_JoinThread */ -PR_IMPLEMENT(void) PR_DetachThread() { } /* PR_DetachThread */ +PR_IMPLEMENT(void) PR_DetachThread(void) { } /* PR_DetachThread */ -PR_IMPLEMENT(PRThread*) PR_GetCurrentThread() +PR_IMPLEMENT(PRThread*) PR_GetCurrentThread(void) { void *thred; @@ -724,25 +724,25 @@ PR_IMPLEMENT(PRStatus) PR_Interrupt(PRThread *thred) return PR_SUCCESS; } /* PR_Interrupt */ -PR_IMPLEMENT(void) PR_ClearInterrupt() +PR_IMPLEMENT(void) PR_ClearInterrupt(void) { PRThread *me = PR_CurrentThread(); me->state &= ~PT_THREAD_ABORTED; } /* PR_ClearInterrupt */ -PR_IMPLEMENT(void) PR_BlockInterrupt() +PR_IMPLEMENT(void) PR_BlockInterrupt(void) { PRThread *me = PR_CurrentThread(); _PT_THREAD_BLOCK_INTERRUPT(me); } /* PR_BlockInterrupt */ -PR_IMPLEMENT(void) PR_UnblockInterrupt() +PR_IMPLEMENT(void) PR_UnblockInterrupt(void) { PRThread *me = PR_CurrentThread(); _PT_THREAD_UNBLOCK_INTERRUPT(me); } /* PR_UnblockInterrupt */ -PR_IMPLEMENT(PRStatus) PR_Yield() +PR_IMPLEMENT(PRStatus) PR_Yield(void) { static PRBool warning = PR_TRUE; if (warning) warning = _PR_Obsolete( @@ -908,7 +908,7 @@ void _PR_InitThreads( PR_SetThreadPriority(thred, priority); } /* _PR_InitThreads */ -PR_IMPLEMENT(PRStatus) PR_Cleanup() +PR_IMPLEMENT(PRStatus) PR_Cleanup(void) { PRThread *me = PR_CurrentThread(); PR_LOG(_pr_thread_lm, PR_LOG_MIN, ("PR_Cleanup: shutting down NSPR")); @@ -920,9 +920,14 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup() PR_WaitCondVar(pt_book.cv, PR_INTERVAL_NO_TIMEOUT); PR_Unlock(pt_book.ml); + _PR_CleanupMW(); + _PR_CleanupDtoa(); + _PR_CleanupCallOnce(); + _PR_ShutdownLinker(); _PR_LogCleanup(); - /* Close all the fd's before calling _PR_CleanupFdCache */ - _PR_CleanupFdCache(); + _PR_CleanupNet(); + /* Close all the fd's before calling _PR_CleanupIO */ + _PR_CleanupIO(); /* * I am not sure if it's safe to delete the cv and lock here, @@ -936,6 +941,10 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup() PR_DestroyLock(pt_book.ml); pt_book.ml = NULL; } _pt_thread_death(me); + PR_DestroyLock(_pr_sleeplock); + _pr_sleeplock = NULL; + _PR_CleanupLayerCache(); + _PR_CleanupEnv(); #ifdef _PR_ZONE_ALLOCATOR _PR_DestroyZones(); #endif @@ -1022,7 +1031,7 @@ static void null_signal_handler(PRIntn sig); * conflict with the use of these two signals in our GC support. * So we don't know how to support GC on Linux pthreads. */ -static void init_pthread_gc_support() +static void init_pthread_gc_support(void) { PRIntn rv; @@ -1033,7 +1042,7 @@ static void init_pthread_gc_support() PR_ASSERT(0 == rv); #else /* defined(_PR_DCETHREADS) */ { - struct sigaction sigact_usr2 = {0}; + struct sigaction sigact_usr2; sigact_usr2.sa_handler = suspend_signal_handler; sigact_usr2.sa_flags = SA_RESTART; @@ -1051,7 +1060,7 @@ static void init_pthread_gc_support() } #if defined(PT_NO_SIGTIMEDWAIT) { - struct sigaction sigact_null = {0}; + struct sigaction sigact_null; sigact_null.sa_handler = null_signal_handler; sigact_null.sa_flags = SA_RESTART; sigemptyset (&sigact_null.sa_mask); @@ -1062,14 +1071,14 @@ static void init_pthread_gc_support() #endif /* defined(_PR_DCETHREADS) */ } -PR_IMPLEMENT(void) PR_SetThreadGCAble() +PR_IMPLEMENT(void) PR_SetThreadGCAble(void) { PR_Lock(pt_book.ml); PR_CurrentThread()->state |= PT_THREAD_GCABLE; PR_Unlock(pt_book.ml); } -PR_IMPLEMENT(void) PR_ClearThreadGCAble() +PR_IMPLEMENT(void) PR_ClearThreadGCAble(void) { PR_Lock(pt_book.ml); PR_CurrentThread()->state &= (~PT_THREAD_GCABLE); @@ -1352,7 +1361,7 @@ PR_IMPLEMENT(void) PR_ResumeTest(PRThread *thred) static pthread_once_t pt_gc_support_control = PTHREAD_ONCE_INIT; -PR_IMPLEMENT(void) PR_SuspendAll() +PR_IMPLEMENT(void) PR_SuspendAll(void) { #ifdef DEBUG PRIntervalTime stime, etime; @@ -1398,7 +1407,7 @@ PR_IMPLEMENT(void) PR_SuspendAll() #endif } /* PR_SuspendAll */ -PR_IMPLEMENT(void) PR_ResumeAll() +PR_IMPLEMENT(void) PR_ResumeAll(void) { #ifdef DEBUG PRIntervalTime stime, etime; diff --git a/pr/src/threads/combined/prucpu.c b/pr/src/threads/combined/prucpu.c index d9159b52..be4203d6 100644 --- a/pr/src/threads/combined/prucpu.c +++ b/pr/src/threads/combined/prucpu.c @@ -59,7 +59,8 @@ static PRUintn _pr_cpuID; static void PR_CALLBACK _PR_CPU_Idle(void *); -static _PRCPU *_PR_CreateCPU(PRThread *thread, PRBool needQueue); +static _PRCPU *_PR_CreateCPU(void); +static PRStatus _PR_StartCPU(_PRCPU *cpu, PRThread *thread); #if !defined(_PR_LOCAL_THREADS_ONLY) static void _PR_RunCPU(void *arg); @@ -69,6 +70,9 @@ void _PR_InitCPUs() { PRThread *me = _PR_MD_CURRENT_THREAD(); + if (_native_threads_only) + return; + _pr_cpuID = 0; _MD_NEW_LOCK( &_pr_cpuLock); #if !defined(_PR_LOCAL_THREADS_ONLY) && !defined(_PR_GLOBAL_THREADS_ONLY) @@ -80,13 +84,13 @@ void _PR_InitCPUs() #ifdef _PR_LOCAL_THREADS_ONLY #ifdef HAVE_CUSTOM_USER_THREADS - if (!_native_threads_only) - _PR_MD_CREATE_PRIMORDIAL_USER_THREAD(me); + _PR_MD_CREATE_PRIMORDIAL_USER_THREAD(me); #endif /* Now start the first CPU. */ - _pr_primordialCPU = _PR_CreateCPU(me, PR_TRUE); + _pr_primordialCPU = _PR_CreateCPU(); _pr_numCPU = 1; + _PR_StartCPU(_pr_primordialCPU, me); _PR_MD_SET_CURRENT_CPU(_pr_primordialCPU); @@ -97,15 +101,16 @@ void _PR_InitCPUs() #else /* Combined MxN model */ + _pr_primordialCPU = _PR_CreateCPU(); + _pr_numCPU = 1; _PR_CreateThread(PR_SYSTEM_THREAD, _PR_RunCPU, - me, + _pr_primordialCPU, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0, _PR_IDLE_THREAD); - _PR_MD_WAIT(me, PR_INTERVAL_NO_TIMEOUT); #endif /* _PR_LOCAL_THREADS_ONLY */ @@ -137,89 +142,113 @@ static _PRCPUQueue *_PR_CreateCPUQueue(void) /* * Create a new CPU. + * + * This function initializes enough of the _PRCPU structure so + * that it can be accessed safely by a global thread or another + * CPU. This function does not create the native thread that + * will run the CPU nor does it initialize the parts of _PRCPU + * that must be initialized by that native thread. + * + * The reason we cannot simply have the native thread create + * and fully initialize a new CPU is that we need to be able to + * create a usable _pr_primordialCPU in _PR_InitCPUs without + * assuming that the primordial CPU thread we created can run + * during NSPR initialization. For example, on Windows while + * new threads can be created by DllMain, they won't be able + * to run during DLL initialization. If NSPR is initialized + * by DllMain, the primordial CPU thread won't run until DLL + * initialization is finished. */ -static _PRCPU *_PR_CreateCPU(PRThread *thread, PRBool needQueue) +static _PRCPU *_PR_CreateCPU(void) { _PRCPU *cpu; - /* - ** Create a new cpu. The assumption this code makes is that the - ** underlying operating system creates a stack to go with the new - ** native thread. That stack will be used by the cpu when pausing. - */ cpu = PR_NEWZAP(_PRCPU); if (cpu) { - cpu->last_clock = PR_IntervalNow(); - - if (needQueue == PR_TRUE) - cpu->queue = _PR_CreateCPUQueue(); - else - cpu->queue = _PR_MD_CURRENT_CPU()->queue; - + cpu->queue = _PR_CreateCPUQueue(); if (!cpu->queue) { PR_DELETE(cpu); return NULL; } - - /* Before we create any threads on this CPU we have to - * set the current CPU - */ - _PR_MD_SET_CURRENT_CPU(cpu); - _PR_MD_INIT_RUNNING_CPU(cpu); - thread->cpu = cpu; - - if (!_native_threads_only) { - - cpu->idle_thread = _PR_CreateThread(PR_SYSTEM_THREAD, - _PR_CPU_Idle, - (void *)cpu, - PR_PRIORITY_NORMAL, - PR_LOCAL_THREAD, - PR_UNJOINABLE_THREAD, - 0, - _PR_IDLE_THREAD); - - if (!cpu->idle_thread) { - /* didn't clean up CPU queue XXXMB */ - PR_DELETE(cpu); - return NULL; - } - cpu->idle_thread->cpu = cpu; - - cpu->idle_thread->no_sched = 0; - } - - cpu->thread = thread; - - if (_pr_cpu_affinity_mask) - PR_SetThreadAffinityMask(thread, _pr_cpu_affinity_mask); - - /* Created a new CPU */ - _PR_CPU_LIST_LOCK(); - cpu->id = _pr_cpuID++; - PR_APPEND_LINK(&cpu->links, &_PR_CPUQ()); - _PR_CPU_LIST_UNLOCK(); - } + } return cpu; } +/* + * Start a new CPU. + * + * 'cpu' is a _PRCPU structure created by _PR_CreateCPU(). + * 'thread' is the native thread that will run the CPU. + * + * If this function fails, 'cpu' is destroyed. + */ +static PRStatus _PR_StartCPU(_PRCPU *cpu, PRThread *thread) +{ + /* + ** Start a new cpu. The assumption this code makes is that the + ** underlying operating system creates a stack to go with the new + ** native thread. That stack will be used by the cpu when pausing. + */ + + PR_ASSERT(!_native_threads_only); + + cpu->last_clock = PR_IntervalNow(); + + /* Before we create any threads on this CPU we have to + * set the current CPU + */ + _PR_MD_SET_CURRENT_CPU(cpu); + _PR_MD_INIT_RUNNING_CPU(cpu); + thread->cpu = cpu; + + cpu->idle_thread = _PR_CreateThread(PR_SYSTEM_THREAD, + _PR_CPU_Idle, + (void *)cpu, + PR_PRIORITY_NORMAL, + PR_LOCAL_THREAD, + PR_UNJOINABLE_THREAD, + 0, + _PR_IDLE_THREAD); + + if (!cpu->idle_thread) { + /* didn't clean up CPU queue XXXMB */ + PR_DELETE(cpu); + return PR_FAILURE; + } + PR_ASSERT(cpu->idle_thread->cpu == cpu); + + cpu->idle_thread->no_sched = 0; + + cpu->thread = thread; + + if (_pr_cpu_affinity_mask) + PR_SetThreadAffinityMask(thread, _pr_cpu_affinity_mask); + + /* Created and started a new CPU */ + _PR_CPU_LIST_LOCK(); + cpu->id = _pr_cpuID++; + PR_APPEND_LINK(&cpu->links, &_PR_CPUQ()); + _PR_CPU_LIST_UNLOCK(); + + return PR_SUCCESS; +} + #if !defined(_PR_GLOBAL_THREADS_ONLY) && !defined(_PR_LOCAL_THREADS_ONLY) /* ** This code is used during a cpu's initial creation. */ static void _PR_RunCPU(void *arg) { - _PRCPU *cpu; + _PRCPU *cpu = (_PRCPU *)arg; PRThread *me = _PR_MD_CURRENT_THREAD(); - PRThread *waiter = (PRThread *) arg; PR_ASSERT(NULL != me); /* - * _PR_CreateCPU calls _PR_CreateThread to create the + * _PR_StartCPU calls _PR_CreateThread to create the * idle thread. Because _PR_CreateThread calls PR_Lock, * the current thread has to remain a global thread - * during the _PR_CreateCPU call so that it can wait for + * during the _PR_StartCPU call so that it can wait for * the lock if the lock is held by another thread. If * we clear the _PR_GLOBAL_SCOPE flag in * _PR_MD_CREATE_PRIMORDIAL_THREAD, the current thread @@ -227,7 +256,7 @@ static void _PR_RunCPU(void *arg) * waiting for the lock because the CPU is not fully * constructed yet. * - * After the CPU is created, it is safe to mark the + * After the CPU is started, it is safe to mark the * current thread as a local thread. */ @@ -236,7 +265,7 @@ static void _PR_RunCPU(void *arg) #endif me->no_sched = 1; - cpu = _PR_CreateCPU(me, PR_TRUE); + _PR_StartCPU(cpu, me); #ifdef HAVE_CUSTOM_USER_THREADS me->flags &= (~_PR_GLOBAL_SCOPE); @@ -246,12 +275,6 @@ static void _PR_RunCPU(void *arg) _PR_MD_SET_CURRENT_THREAD(cpu->thread); me->cpu = cpu; - if (waiter) { - _pr_primordialCPU = cpu; - _pr_numCPU = 1; - _PR_MD_WAKEUP_WAITER(waiter); - } - while(1) { PRInt32 is; if (!_PR_IS_NATIVE_THREAD(me)) _PR_INTSOFF(is); @@ -344,7 +367,8 @@ PR_IMPLEMENT(void) PR_SetConcurrency(PRUintn numCPUs) #else /* combined, MxN thread model */ PRUintn newCPU; - PRThread *cpu; + _PRCPU *cpu; + PRThread *thr; if (!_pr_initialized) _PR_ImplicitInitialization(); @@ -360,9 +384,10 @@ PR_IMPLEMENT(void) PR_SetConcurrency(PRUintn numCPUs) _PR_CPU_LIST_UNLOCK(); for (; newCPU; newCPU--) { - cpu = _PR_CreateThread(PR_SYSTEM_THREAD, + cpu = _PR_CreateCPU(); + thr = _PR_CreateThread(PR_SYSTEM_THREAD, _PR_RunCPU, - NULL, + cpu, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, diff --git a/pr/src/threads/combined/prustack.c b/pr/src/threads/combined/prustack.c index aa7d2bfa..3f12c568 100644 --- a/pr/src/threads/combined/prustack.c +++ b/pr/src/threads/combined/prustack.c @@ -58,6 +58,14 @@ void _PR_InitStacks(void) _pr_stackLock = PR_NewLock(); } +void _PR_CleanupStacks(void) +{ + if (_pr_stackLock) { + PR_DestroyLock(_pr_stackLock); + _pr_stackLock = NULL; + } +} + /* ** Allocate a stack for a thread. */ diff --git a/pr/src/threads/combined/pruthr.c b/pr/src/threads/combined/pruthr.c index ac7e9eb6..1329bb66 100644 --- a/pr/src/threads/combined/pruthr.c +++ b/pr/src/threads/combined/pruthr.c @@ -85,7 +85,6 @@ PRThread *suspendAllThread = NULL; extern PRCList _pr_active_global_threadQ; extern PRCList _pr_active_local_threadQ; -extern _PRCPU *_pr_primordialCPU; static void _PR_DecrActiveThreadCount(PRThread *thread); static PRThread *_PR_AttachThread(PRThreadType, PRThreadPriority, PRThreadStack *); @@ -179,6 +178,27 @@ void _PR_InitThreads(PRThreadType type, PRThreadPriority priority, PR_INIT_CLIST(&_pr_deadUserQ); } +void _PR_CleanupThreads(void) +{ + if (_pr_terminationCVLock) { + PR_DestroyLock(_pr_terminationCVLock); + _pr_terminationCVLock = NULL; + } + if (_pr_activeLock) { + PR_DestroyLock(_pr_activeLock); + _pr_activeLock = NULL; + } + if (_pr_primordialExitCVar) { + PR_DestroyCondVar(_pr_primordialExitCVar); + _pr_primordialExitCVar = NULL; + } + /* TODO _pr_dead{Native,User}Q need to be deleted */ + if (_pr_deadQLock) { + PR_DestroyLock(_pr_deadQLock); + _pr_deadQLock = NULL; + } +} + /* ** Initialize a stack for a native thread */ diff --git a/pr/src/threads/prtpd.c b/pr/src/threads/prtpd.c index 42139329..6d8fd416 100644 --- a/pr/src/threads/prtpd.c +++ b/pr/src/threads/prtpd.c @@ -88,7 +88,7 @@ static PRThreadPrivateDTOR *_pr_tpd_destructors = NULL; /* ** Initialize the thread private data manipulation */ -void _PR_InitTPD() +void _PR_InitTPD(void) { _pr_tpd_destructors = (PRThreadPrivateDTOR*) PR_CALLOC(_PR_TPD_LIMIT * sizeof(PRThreadPrivateDTOR*)); diff --git a/pr/tests/Makefile.in b/pr/tests/Makefile.in index 7e8dbaf7..f9dcff34 100644 --- a/pr/tests/Makefile.in +++ b/pr/tests/Makefile.in @@ -296,8 +296,10 @@ endif ifeq ($(OS_ARCH), HP-UX) LDOPTS += -z -Wl,+s,+b,$(ABSOLUTE_LIB_DIR) ifeq ($(USE_64),1) - LDOPTS += +DA2.0W - EXTRA_LIBS = -lpthread + LDOPTS += +DD64 + endif + ifeq ($(USE_PTHREADS),1) + EXTRA_LIBS = $(LIBPTHREAD) endif endif diff --git a/pr/tests/sigpipe.c b/pr/tests/sigpipe.c index 2c708e29..28e7e251 100644 --- a/pr/tests/sigpipe.c +++ b/pr/tests/sigpipe.c @@ -69,7 +69,7 @@ int main(void) #endif #include <errno.h> -int main(void) +static void Test(void *arg) { #ifdef XP_OS2 HFILE pipefd[2]; @@ -79,9 +79,6 @@ int main(void) int rv; char c = '\0'; - /* This initializes NSPR. */ - PR_SetError(0, 0); - #ifdef XP_OS2 if (DosCreatePipe(&pipefd[0], &pipefd[1], 4096) != 0) { #else @@ -103,6 +100,27 @@ int main(void) } close(pipefd[1]); printf("write to broken pipe failed with EPIPE, as expected\n"); +} + +int main(void) +{ + PRThread *thread; + + /* This initializes NSPR. */ + PR_SetError(0, 0); + + thread = PR_CreateThread(PR_USER_THREAD, Test, NULL, PR_PRIORITY_NORMAL, + PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0); + if (thread == NULL) { + fprintf(stderr, "PR_CreateThread failed\n"); + exit(1); + } + if (PR_JoinThread(thread) == PR_FAILURE) { + fprintf(stderr, "PR_JoinThread failed\n"); + exit(1); + } + Test(NULL); + printf("PASSED\n"); return 0; } diff --git a/pr/tests/vercheck.c b/pr/tests/vercheck.c index 49f6ea22..4235a832 100644 --- a/pr/tests/vercheck.c +++ b/pr/tests/vercheck.c @@ -49,12 +49,12 @@ #include <stdlib.h> /* - * This release (4.1) is backward compatible with the - * 4.0.x releases. It, of course, is compatible with - * itself. + * This release (4.2) is backward compatible with the + * 4.0.x and 4.1.x releases. It, of course, is compatible + * with itself. */ static char *compatible_version[] = { - "4.0", "4.0.1", "4.0.2", PR_VERSION + "4.0", "4.0.1", "4.1", "4.1.1", "4.1.2", "4.1.3", PR_VERSION }; /* @@ -69,8 +69,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.1.3", - "4.2", "4.2.1", + "4.2.3", + "4.3", "4.3.1", "10.0", "11.1", "12.14.20" }; |