summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtchang%redhat.com <devnull@localhost>2007-01-11 22:27:44 +0000
committerwtchang%redhat.com <devnull@localhost>2007-01-11 22:27:44 +0000
commit3e2aa7760f47486a8dc7ef6b85b62909f7c7f084 (patch)
treeac98e0cf7b7a723335911aba0e6bf3c5a097f95a
parent82d23664623999cdb07579c89aaea9ddd95f687e (diff)
downloadnspr-hg-3e2aa7760f47486a8dc7ef6b85b62909f7c7f084.tar.gz
Bug 362768: implemented NSPR shared library finalization function for major
Unix platforms. r=nelsonb Modified files: pr/src/Makefile.in ptthread.c
-rw-r--r--pr/src/Makefile.in5
-rw-r--r--pr/src/pthreads/ptthread.c61
2 files changed, 66 insertions, 0 deletions
diff --git a/pr/src/Makefile.in b/pr/src/Makefile.in
index 2d785bdc..f6fd8886 100644
--- a/pr/src/Makefile.in
+++ b/pr/src/Makefile.in
@@ -186,6 +186,11 @@ OS_LIBS += -ldld -L/lib/pa1.1 -lm
else
OS_LIBS += -ldld -lm -lc
endif
+ifneq ($(OS_TEST),ia64)
+ifndef USE_64
+DSO_LDOPTS += +I PR_HPUX10xInit
+endif
+endif
endif
ifeq ($(OS_ARCH),UNIXWARE)
diff --git a/pr/src/pthreads/ptthread.c b/pr/src/pthreads/ptthread.c
index deb798e7..1c499908 100644
--- a/pr/src/pthreads/ptthread.c
+++ b/pr/src/pthreads/ptthread.c
@@ -934,6 +934,67 @@ void _PR_InitThreads(
PR_SetThreadPriority(thred, priority);
} /* _PR_InitThreads */
+#ifdef __GNUC__
+/*
+ * GCC supports the constructor and destructor attributes as of
+ * version 2.5.
+ */
+static void _PR_Fini(void) __attribute__ ((destructor));
+#elif defined(__SUNPRO_C)
+#pragma fini(_PR_Fini)
+#elif defined(HPUX)
+#if defined(__ia64) || defined(_LP64)
+#pragma FINI "_PR_Fini"
+#else
+/*
+ * Only HP-UX 10.x style initializers are supported in 32-bit links.
+ * Need to use the +I PR_HPUX10xInit linker option.
+ */
+#include <dl.h>
+
+static void _PR_Fini(void);
+
+void PR_HPUX10xInit(shl_t handle, int loading)
+{
+ /*
+ * This function is called when a shared library is loaded as well
+ * as when the shared library is unloaded. Note that it may not
+ * be called when the user's program terminates.
+ *
+ * handle is the shl_load API handle for the shared library being
+ * initialized.
+ *
+ * loading is non-zero at startup and zero at termination.
+ */
+ if (loading) {
+ /* ... do some initializations ... */
+ } else {
+ _PR_Fini();
+ }
+}
+#endif
+#elif defined(AIX)
+/* Need to use the binitfini::_PR_Fini linker option. */
+#endif
+
+static void _PR_Fini(void)
+{
+ void *thred;
+ int rv;
+
+ if (!_pr_initialized) return;
+
+ _PT_PTHREAD_GETSPECIFIC(pt_book.key, thred);
+ if (NULL != thred)
+ {
+ _pt_thread_death(thred);
+ rv = pthread_setspecific(pt_book.key, NULL);
+ PR_ASSERT(0 == rv);
+ }
+ /* TODO: free other resources used by NSPR */
+ /* _pr_initialized = PR_FALSE; */
+} /* _PR_Fini */
+
PR_IMPLEMENT(PRStatus) PR_Cleanup(void)
{
PRThread *me = PR_GetCurrentThread();