Bug 773414 - Add PR_DuplicateEnvironment function. r=cjones
authorDave Hylands <dhylands@gmail.com>
Thu, 12 Jul 2012 13:28:14 -0700
changeset 99703 497967ad20bfb30b0bfe0df11d072b82a93e70fb
parent 99702 5510df5fbe30e27b79ceaafd4eeb3b106d9049a7
child 99704 b54897b245b50e3bcfab2c9bf00b84fea78c4a1d
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerscjones
bugs773414
milestone17.0a1
Bug 773414 - Add PR_DuplicateEnvironment function. r=cjones From 2236c867cfc9b25bc1327206da8b4b29a91f65e0 Mon Sep 17 00:00:00 2001 Need to reimplement PR_GetEnv and PR_SetEnv so that we can access to the lock. This is needed by PR_DuplicateEnvironment, which was moved to ipc/chromium/src/base/process_util_linux.cc otherwise the alloc/frees don't get matched up properly. This is tempoarary until we can get PR_DuplicateEnvironment landed into NSPR. --- configure.in | 2 +- mozglue/build/BionicGlue.cpp | 44 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-)
configure.in
mozglue/build/BionicGlue.cpp
--- a/configure.in
+++ b/configure.in
@@ -7067,17 +7067,17 @@ AC_SUBST(DLLFLAGS)
 dnl We need to wrap dlopen and related functions on Android because we use
 dnl our own linker.
 if test "$OS_TARGET" = Android; then
     WRAP_LDFLAGS="${WRAP_LDFLAGS} -L$_objdir/dist/lib -lmozglue"
     if test -n "$MOZ_OLD_LINKER"; then
         WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=dlopen,--wrap=dlclose,--wrap=dlerror,--wrap=dlsym,--wrap=dladdr"
     fi
     WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=getaddrinfo,--wrap=freeaddrinfo,--wrap=gai_strerror"
-    WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=fork,--wrap=pthread_atfork,--wrap=raise"
+    WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=fork,--wrap=pthread_atfork,--wrap=raise,--wrap=PR_GetEnv,--wrap=PR_SetEnv"
 fi
 
 dnl ========================================================
 dnl = Use malloc wrapper lib
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(wrap-malloc,
 [  --enable-wrap-malloc    Wrap malloc calls (gnu linker only)],
     _WRAP_MALLOC=1,
--- a/mozglue/build/BionicGlue.cpp
+++ b/mozglue/build/BionicGlue.cpp
@@ -1,15 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include <pthread.h>
+#include <string.h>
 #include <unistd.h>
-#include <pthread.h>
+
 #include <vector>
 
 #define NS_EXPORT __attribute__ ((visibility("default")))
 
 /* Android doesn't have pthread_atfork(), so we need to use our own. */
 struct AtForkFuncs {
   void (*prepare)(void);
   void (*parent)(void);
@@ -54,8 +56,48 @@ extern "C" NS_EXPORT pid_t
 }
 
 extern "C" NS_EXPORT int
 __wrap_raise(int sig)
 {
   return pthread_kill(pthread_self(), sig);
 }
 
+/*
+ * The following wrappers for PR_Xxx are needed until we can get
+ * PR_DuplicateEnvironment landed in NSPR.
+ * See see bug 772734 and bug 773414.
+ *
+ * We can't #include the pr headers here, and we can't call any of the
+ * PR/PL functions either, so we just reimplemnt using native code.
+ */
+
+static pthread_mutex_t  _pr_envLock = PTHREAD_MUTEX_INITIALIZER;
+
+extern "C" NS_EXPORT char*
+__wrap_PR_GetEnv(const char *var)
+{
+    char *ev;
+
+    pthread_mutex_lock(&_pr_envLock);
+    ev = getenv(var);
+    pthread_mutex_unlock(&_pr_envLock);
+    return ev;
+}
+
+extern "C" NS_EXPORT int
+__wrap_PR_SetEnv(const char *string)
+{
+    int result;
+
+    if ( !strchr(string, '=')) return(-1);
+
+    pthread_mutex_lock(&_pr_envLock);
+    result = putenv(string);
+    pthread_mutex_unlock(&_pr_envLock);
+    return (result)? -1 : 0;
+}
+
+extern "C" NS_EXPORT pthread_mutex_t *
+PR_GetEnvLock(void)
+{
+  return &_pr_envLock;
+}