diff options
Diffstat (limited to 'linker')
-rw-r--r-- | linker/debugger.cpp | 21 | ||||
-rw-r--r-- | linker/dlfcn.cpp | 1 | ||||
-rw-r--r-- | linker/linker_allocator.cpp | 2 | ||||
-rw-r--r-- | linker/linker_environ.cpp | 1 | ||||
-rw-r--r-- | linker/linker_phdr.cpp | 1 |
5 files changed, 25 insertions, 1 deletions
diff --git a/linker/debugger.cpp b/linker/debugger.cpp index c889544d1..6fe9524e7 100644 --- a/linker/debugger.cpp +++ b/linker/debugger.cpp @@ -30,9 +30,11 @@ #include <errno.h> #include <inttypes.h> +#include <pthread.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <sys/mman.h> #include <sys/prctl.h> #include <sys/socket.h> @@ -212,6 +214,23 @@ static void send_debuggerd_packet(siginfo_t* info) { return; } + // Mutex to prevent multiple crashing threads from trying to talk + // to debuggerd at the same time. + static pthread_mutex_t crash_mutex = PTHREAD_MUTEX_INITIALIZER; + int ret = pthread_mutex_trylock(&crash_mutex); + if (ret != 0) { + if (ret == EBUSY) { + __libc_format_log(ANDROID_LOG_INFO, "libc", + "Another thread has contacted debuggerd first, stop and wait for process to die."); + // This will never complete since the lock is never released. + pthread_mutex_lock(&crash_mutex); + } else { + __libc_format_log(ANDROID_LOG_INFO, "libc", + "pthread_mutex_trylock failed: %s", strerror(ret)); + } + return; + } + int s = socket_abstract_client(DEBUGGER_SOCKET_NAME, SOCK_STREAM | SOCK_CLOEXEC); if (s == -1) { __libc_format_log(ANDROID_LOG_FATAL, "libc", "Unable to open connection to debuggerd: %s", @@ -228,7 +247,7 @@ static void send_debuggerd_packet(siginfo_t* info) { msg.tid = gettid(); msg.abort_msg_address = reinterpret_cast<uintptr_t>(g_abort_message); msg.original_si_code = (info != nullptr) ? info->si_code : 0; - int ret = TEMP_FAILURE_RETRY(write(s, &msg, sizeof(msg))); + ret = TEMP_FAILURE_RETRY(write(s, &msg, sizeof(msg))); if (ret == sizeof(msg)) { char debuggerd_ack; ret = TEMP_FAILURE_RETRY(read(s, &debuggerd_ack, 1)); diff --git a/linker/dlfcn.cpp b/linker/dlfcn.cpp index 7ef94c059..9a8dbc93f 100644 --- a/linker/dlfcn.cpp +++ b/linker/dlfcn.cpp @@ -20,6 +20,7 @@ #include <pthread.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <android/dlext.h> #include <bionic/pthread_internal.h> diff --git a/linker/linker_allocator.cpp b/linker/linker_allocator.cpp index 92220e8c4..ac11b979a 100644 --- a/linker/linker_allocator.cpp +++ b/linker/linker_allocator.cpp @@ -13,8 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "linker_allocator.h" #include <inttypes.h> +#include <string.h> #include <sys/mman.h> #include <unistd.h> diff --git a/linker/linker_environ.cpp b/linker/linker_environ.cpp index daee56f7e..7272f4e83 100644 --- a/linker/linker_environ.cpp +++ b/linker/linker_environ.cpp @@ -31,6 +31,7 @@ #include <linux/auxvec.h> #include <stddef.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> #include "private/KernelArgumentBlock.h" diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp index af4dc2567..91a2fb80d 100644 --- a/linker/linker_phdr.cpp +++ b/linker/linker_phdr.cpp @@ -29,6 +29,7 @@ #include "linker_phdr.h" #include <errno.h> +#include <string.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> |