[fuchsia] do not try to suspend crashed thread

* a thread blocked in an exception is technically not suspended on Fuchsia
* this will take care of the spurious error message "thread failed to suspend: ZX_ERR_TIMED_OUT (-21)" introduced in https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1536268

Bug: fuchsia/ZX-3772
Tested: `fx run-test crashpad_test` on Fuchsia; verified with `fx shell crasher` no error message
Change-Id: I5306732ef7c5a4f2c0fe84bc072506d57a43931e
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1538558
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Francois Rousseau <frousseau@google.com>
This commit is contained in:
Francois Rousseau 2019-03-25 10:47:51 -07:00 committed by Commit Bot
parent 17d024e7df
commit 3cc7ceaac5

View File

@ -15,6 +15,9 @@
#include "util/fuchsia/scoped_task_suspend.h"
#include <lib/zx/time.h>
#include <zircon/errors.h>
#include <zircon/status.h>
#include <zircon/syscalls/object.h>
#include <vector>
@ -27,16 +30,30 @@ namespace crashpad {
ScopedTaskSuspend::ScopedTaskSuspend(const zx::process& process) {
DCHECK_NE(process.get(), zx::process::self()->get());
zx_status_t status = process.suspend(&suspend_token_);
if (status != ZX_OK) {
ZX_LOG(ERROR, status) << "zx_task_suspend";
} else {
for (const auto& thread : GetThreadHandles(process)) {
zx_signals_t observed = 0u;
status = thread.wait_one(
ZX_THREAD_SUSPENDED, zx::deadline_after(zx::msec(50)), &observed);
ZX_LOG_IF(ERROR, status != ZX_OK, status) << "thread failed to suspend";
const zx_status_t suspend_status = process.suspend(&suspend_token_);
if (suspend_status != ZX_OK) {
ZX_LOG(ERROR, suspend_status) << "zx_task_suspend";
return;
}
// suspend() is asynchronous so we now check that each thread is indeed
// suspended, up to some deadline.
for (const auto& thread : GetThreadHandles(process)) {
// We omit the crashed thread (blocked in an exception) as it is technically
// not suspended, cf. ZX-3772.
zx_info_thread info;
if (thread.get_info(
ZX_INFO_THREAD, &info, sizeof(info), nullptr, nullptr) == ZX_OK) {
if (info.state == ZX_THREAD_STATE_BLOCKED_EXCEPTION) {
continue;
}
}
zx_signals_t observed = 0u;
const zx_status_t wait_status = thread.wait_one(
ZX_THREAD_SUSPENDED, zx::deadline_after(zx::msec(50)), &observed);
ZX_LOG_IF(ERROR, wait_status != ZX_OK, wait_status)
<< "thread failed to suspend";
}
}