Commit eefad667 authored by Wez's avatar Wez Committed by Commit Bot

Prepare libsampler Fuchsia implementation for SDK roll.

The next Fuchsia SDK roll changes the signature and types associated
with the zx_thread_read_state() API, so we temporarily need backward-
compatibility shims while we roll the SDK/Chromium/V8.

Bug: chromium:707030
Change-Id: I419a65bbb631a1ef0d7d5044b07d4cbbac08970f
Reviewed-on: https://chromium-review.googlesource.com/914695
Commit-Queue: Wez <wez@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51256}
parent 7b27040e
......@@ -46,6 +46,21 @@
#include <zircon/syscalls/debug.h>
#include <zircon/types.h>
// TODO(wez): Remove this once the Fuchsia SDK has rolled.
#if defined(ZX_THREAD_STATE_REGSET0)
#define ZX_THREAD_STATE_GENERAL_REGS ZX_THREAD_STATE_REGSET0
zx_status_t zx_thread_read_state(zx_handle_t h, uint32_t k, void* b, size_t l) {
uint32_t dummy_out_len = 0;
return zx_thread_read_state(h, k, b, static_cast<uint32_t>(l),
&dummy_out_len);
}
#if defined(__x86_64__)
typedef zx_x86_64_general_regs_t zx_thread_state_general_regs_t;
#else
typedef zx_arm64_general_regs_t zx_thread_state_general_regs_t;
#endif
#endif // !defined(ZX_THREAD_STATE_GENERAL_REGS)
#endif
#include <algorithm>
......@@ -715,16 +730,10 @@ void Sampler::DoSample() {
return;
}
// Fetch a copy of its "general register" states.
#if V8_HOST_ARCH_X64
zx_x86_64_general_regs_t thread_state;
#elif V8_HOST_ARCH_ARM64
zx_arm64_general_regs_t thread_state;
#endif
uint32_t thread_state_size = 0;
if (zx_thread_read_state(profiled_thread, ZX_THREAD_STATE_REGSET0,
&thread_state, sizeof(thread_state),
&thread_state_size) == ZX_OK) {
// Fetch a copy of its "general register" states.
zx_thread_state_general_regs_t thread_state = {};
if (zx_thread_read_state(profiled_thread, ZX_THREAD_STATE_GENERAL_REGS,
&thread_state, sizeof(thread_state)) == ZX_OK) {
v8::RegisterState state;
#if V8_HOST_ARCH_X64
state.pc = reinterpret_cast<void*>(thread_state.rip);
......@@ -741,6 +750,11 @@ void Sampler::DoSample() {
zx_task_resume(profiled_thread, 0);
}
// TODO(wez): Remove this once the Fuchsia SDK has rolled.
#if defined(ZX_THREAD_STATE_REGSET0)
#undef ZX_THREAD_STATE_GENERAL_REGS
#endif
#endif // USE_SIGNALS
} // namespace sampler
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment