Bug 943170 - Fix Android mozglue for raise() to avoid pthread bug. r=glandium
authorJed Davis <jld@mozilla.com>
Mon, 02 Dec 2013 17:08:27 -0500
changeset 158435 02bb0a9faed6c2769702b57fcaaac82872fd42e9
parent 158434 14d1050e721b15be403c76676b57cafaebc4819d
child 158436 5ba7ac937c2ce63a23d0c7c4ed863e890977cf6a
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersglandium
bugs943170
milestone28.0a1
Bug 943170 - Fix Android mozglue for raise() to avoid pthread bug. r=glandium
mozglue/build/BionicGlue.cpp
--- a/mozglue/build/BionicGlue.cpp
+++ b/mozglue/build/BionicGlue.cpp
@@ -4,16 +4,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <pthread.h>
 #include <string.h>
 #include <stdlib.h>
 #include <time.h>
 #include <unistd.h>
 #include <android/log.h>
+#include <sys/syscall.h>
 
 #include "mozilla/Alignment.h"
 
 #include <vector>
 
 #define NS_EXPORT __attribute__ ((visibility("default")))
 
 #if ANDROID_VERSION < 17 || defined(MOZ_WIDGET_ANDROID)
@@ -123,17 +124,26 @@ WRAP(fork)(void)
   }
   return pid;
 }
 #endif
 
 extern "C" NS_EXPORT int
 WRAP(raise)(int sig)
 {
-  return pthread_kill(pthread_self(), sig);
+  // Bug 741272: Bionic incorrectly uses kill(), which signals the
+  // process, and thus could signal another thread (and let this one
+  // return "successfully" from raising a fatal signal).
+  //
+  // Bug 943170: POSIX specifies pthread_kill(pthread_self(), sig) as
+  // equivalent to raise(sig), but Bionic also has a bug with these
+  // functions, where a forked child will kill its parent instead.
+
+  extern pid_t gettid(void);
+  return syscall(__NR_tgkill, getpid(), gettid(), 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