aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2017-06-23 20:28:29 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-06-23 20:28:30 +0000
commit8c2847a54723abaa5cdc1fc57d5b10e453220393 (patch)
treeb60576a77e38fc184cd403bf07eda918aa4c3c85
parentedf64fc5f2c3fcfc028bbeed8f470a5dd1492e88 (diff)
parent8cef2f5e33d5a256c3e095c95cae6d8f3570d975 (diff)
downloadbionic-8c2847a54723abaa5cdc1fc57d5b10e453220393.tar.gz
Merge "Shave another uninteresting stack frame off aborts." into oc-dr1-dev
-rw-r--r--libc/bionic/abort.cpp25
-rw-r--r--libc/bionic/bionic_arc4random.cpp1
-rw-r--r--libc/bionic/clone.cpp1
-rw-r--r--libc/bionic/fork.cpp1
-rw-r--r--libc/bionic/gettid.cpp1
-rw-r--r--tests/dlext_test.cpp1
6 files changed, 25 insertions, 5 deletions
diff --git a/libc/bionic/abort.cpp b/libc/bionic/abort.cpp
index 3ba83d1f4..f401cab90 100644
--- a/libc/bionic/abort.cpp
+++ b/libc/bionic/abort.cpp
@@ -32,6 +32,26 @@
#include <sys/syscall.h>
#include <unistd.h>
+// We call tgkill(2) directly instead of raise (or even the libc tgkill wrapper), to reduce the
+// number of uninteresting stack frames at the top of a crash.
+static inline __always_inline void inline_tgkill(pid_t pid, pid_t tid, int sig) {
+#if defined(__arm__)
+ register int r0 __asm__("r0") = pid;
+ register int r1 __asm__("r1") = tid;
+ register int r2 __asm__("r2") = sig;
+ register int r7 __asm__("r7") = __NR_tgkill;
+ __asm__("swi #0" : "=r"(r0) : "r"(r0), "r"(r1), "r"(r2), "r"(r7) : "memory");
+#elif defined(__aarch64__)
+ register long x0 __asm__("x0") = pid;
+ register long x1 __asm__("x1") = tid;
+ register long x2 __asm__("x2") = sig;
+ register long x8 __asm__("x8") = __NR_tgkill;
+ __asm__("svc #0" : "=r"(x0) : "r"(x0), "r"(x1), "r"(x2), "r"(x8) : "memory");
+#else
+ syscall(__NR_tgkill, pid, tid, sig);
+#endif
+}
+
void abort() {
// Protect ourselves against stale cached PID/TID values by fetching them via syscall.
// http://b/37769298
@@ -45,8 +65,7 @@ void abort() {
sigdelset(&mask, SIGABRT);
sigprocmask(SIG_SETMASK, &mask, NULL);
- // Use tgkill directly instead of raise, to avoid inserting spurious stack frames.
- tgkill(pid, tid, SIGABRT);
+ inline_tgkill(pid, tid, SIGABRT);
// If SIGABRT ignored, or caught and the handler returns,
// remove the SIGABRT signal handler and raise SIGABRT again.
@@ -57,7 +76,7 @@ void abort() {
sigaction(SIGABRT, &sa, &sa);
sigprocmask(SIG_SETMASK, &mask, NULL);
- tgkill(pid, tid, SIGABRT);
+ inline_tgkill(pid, tid, SIGABRT);
// If we get this far, just exit.
_exit(127);
diff --git a/libc/bionic/bionic_arc4random.cpp b/libc/bionic/bionic_arc4random.cpp
index a4842f6f5..a33990020 100644
--- a/libc/bionic/bionic_arc4random.cpp
+++ b/libc/bionic/bionic_arc4random.cpp
@@ -32,7 +32,6 @@
#include <stdatomic.h>
#include <stdlib.h>
#include <sys/auxv.h>
-#include <syscall.h>
#include <unistd.h>
#include <async_safe/log.h>
diff --git a/libc/bionic/clone.cpp b/libc/bionic/clone.cpp
index 3a20aa93e..d7ce37f57 100644
--- a/libc/bionic/clone.cpp
+++ b/libc/bionic/clone.cpp
@@ -30,6 +30,7 @@
#include <sched.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <sys/syscall.h>
#include "pthread_internal.h"
diff --git a/libc/bionic/fork.cpp b/libc/bionic/fork.cpp
index 32ea255bb..efcbb8c7c 100644
--- a/libc/bionic/fork.cpp
+++ b/libc/bionic/fork.cpp
@@ -27,7 +27,6 @@
*/
#include <unistd.h>
-#include <sys/syscall.h>
#include "pthread_internal.h"
diff --git a/libc/bionic/gettid.cpp b/libc/bionic/gettid.cpp
index fe25a4d81..eb5cfd6ab 100644
--- a/libc/bionic/gettid.cpp
+++ b/libc/bionic/gettid.cpp
@@ -27,6 +27,7 @@
*/
#include <unistd.h>
+#include <sys/syscall.h>
#include "pthread_internal.h"
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index e3ee7d7d8..b264e536b 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -30,6 +30,7 @@
#include <linux/memfd.h>
#include <sys/mman.h>
+#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/vfs.h>
#include <sys/wait.h>