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 174069 02bb0a9faed6c2769702b57fcaaac82872fd42e9
parent 174068 14d1050e721b15be403c76676b57cafaebc4819d
child 174070 5ba7ac937c2ce63a23d0c7c4ed863e890977cf6a
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs943170
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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