Bugzilla bug 97485: added support for the magic "nspr_use_zone_allocator"
authorwtc%netscape.com
Tue, 29 Jan 2002 03:01:45 +0000
changeset 2207 e19c5632dbfb503806cc44521ca746f1a98f2849
parent 2204 1521739827af30a7c8fb4ccae6e18201c942b1a2
child 2212 a9545bcf8e2fffefc873dcacf359f621e8082395
push idunknown
push userunknown
push dateunknown
bugs97485
Bugzilla bug 97485: added support for the magic "nspr_use_zone_allocator" global variable.
pr/src/malloc/prmem.c
--- a/pr/src/malloc/prmem.c
+++ b/pr/src/malloc/prmem.c
@@ -100,23 +100,72 @@ void
                 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;
+}
+
+#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")) != NULL) {
+    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);
     }
 
     if (!use_zone_allocator)
         return;
 
     for (j = 0; j < THREAD_POOLS; j++) { 
         for (i = 0; i < MEM_ZONES; i++) {