OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(HOST_OS_FUCHSIA) | 6 #if defined(HOST_OS_FUCHSIA) |
7 | 7 |
8 #include "vm/thread_interrupter.h" | 8 #include "vm/thread_interrupter.h" |
9 | 9 |
10 #include <magenta/process.h> | 10 #include <magenta/process.h> |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 DECLARE_FLAG(bool, thread_interrupter); | 25 DECLARE_FLAG(bool, thread_interrupter); |
26 DECLARE_FLAG(bool, trace_thread_interrupter); | 26 DECLARE_FLAG(bool, trace_thread_interrupter); |
27 | 27 |
28 // TODO(MG-430): Currently, CPU profiling for Fuchsia is arranged very similarly | 28 // TODO(MG-430): Currently, CPU profiling for Fuchsia is arranged very similarly |
29 // to our Windows profiling. That is, the interrupter thread iterates over | 29 // to our Windows profiling. That is, the interrupter thread iterates over |
30 // all threads, suspends them, samples various things, and then resumes them. | 30 // all threads, suspends them, samples various things, and then resumes them. |
31 // When MG-430 is resolved, the code below should be rewritten to use whatever | 31 // When MG-430 is resolved, the code below should be rewritten to use whatever |
32 // feature is added for it. | 32 // feature is added for it. |
33 | 33 |
34 // TODO(zra): The profiler is currently off by default on Fuchsia because | 34 // TODO(MG-795): The profiler is currently off by default on Fuchsia because |
35 // suspending a thread that is in a call to pthread_cond_wait() causes | 35 // suspending a thread that is in a call to pthread_cond_wait() causes |
36 // pthread_cond_wait() to return ETIMEDOUT. | 36 // pthread_cond_wait() to return ETIMEDOUT. |
37 | 37 |
38 class ThreadInterrupterFuchsia : public AllStatic { | 38 class ThreadInterrupterFuchsia : public AllStatic { |
39 public: | 39 public: |
40 static bool GrabRegisters(mx_handle_t thread, InterruptedThreadState* state) { | 40 static bool GrabRegisters(mx_handle_t thread, InterruptedThreadState* state) { |
41 // TODO(zra): Enable this when mx_thread_read_state() works on suspended | 41 // TODO(zra): Enable this when mx_thread_read_state() works on suspended |
42 // threads. | 42 // threads. |
43 while (false) { | 43 while (false) { |
44 char buf[MX_MAX_THREAD_STATE_SIZE]; | 44 char buf[MX_MAX_THREAD_STATE_SIZE]; |
45 uint32_t regset_size = MX_MAX_THREAD_STATE_SIZE; | 45 uint32_t regset_size = MX_MAX_THREAD_STATE_SIZE; |
46 mx_status_t status = mx_thread_read_state( | 46 mx_status_t status = mx_thread_read_state( |
47 thread, MX_THREAD_STATE_REGSET0, &buf[0], regset_size, ®set_size); | 47 thread, MX_THREAD_STATE_REGSET0, &buf[0], regset_size, ®set_size); |
48 if (status != NO_ERROR) { | 48 if (status != NO_ERROR) { |
49 OS::PrintErr("ThreadInterrupter failed to get registers: %s\n", | 49 OS::PrintErr("ThreadInterrupter failed to get registers: %s\n", |
50 mx_status_get_string(status)); | 50 mx_status_get_string(status)); |
51 return false; | 51 return false; |
52 } | 52 } |
53 #if defined(TARGET_ARCH_X64) | 53 #if defined(TARGET_ARCH_X64) |
54 mx_x86_64_general_regs_t* regs = | 54 mx_x86_64_general_regs_t* regs = |
55 reinterpret_cast<mx_x86_64_general_regs_t*>(&buf[0]); | 55 reinterpret_cast<mx_x86_64_general_regs_t*>(&buf[0]); |
56 state->pc = static_cast<uintptr_t>(regs->rip); | 56 state->pc = static_cast<uintptr_t>(regs->rip); |
57 state->fp = static_cast<uintptr_t>(regs->rbp); | 57 state->fp = static_cast<uintptr_t>(regs->rbp); |
58 state->csp = static_cast<uintptr_t>(regs->rsp); | 58 state->csp = static_cast<uintptr_t>(regs->rsp); |
59 state->dsp = static_cast<uintptr_t>(regs->rsp); | 59 state->dsp = static_cast<uintptr_t>(regs->rsp); |
60 #elif defined(TARGET_ARCH_ARM64) | 60 #elif defined(TARGET_ARCH_ARM64) |
61 mx_aarch64_general_regs_t* regs = | 61 mx_arm64_general_regs_t* regs = |
62 reinterpret_cast<mx_aarch64_general_regs_t*>(&buf[0]); | 62 reinterpret_cast<mx_arm64_general_regs_t*>(&buf[0]); |
63 state->pc = static_cast<uintptr_t>(regs->pc); | 63 state->pc = static_cast<uintptr_t>(regs->pc); |
64 state->fp = static_cast<uintptr_t>(regs->r[FPREG]); | 64 state->fp = static_cast<uintptr_t>(regs->r[FPREG]); |
65 state->csp = static_cast<uintptr_t>(regs->sp); | 65 state->csp = static_cast<uintptr_t>(regs->sp); |
66 state->dsp = static_cast<uintptr_t>(regs->r[SPREG]); | 66 state->dsp = static_cast<uintptr_t>(regs->r[SPREG]); |
67 state->lr = static_cast<uintptr_t>(regs->lr); | 67 state->lr = static_cast<uintptr_t>(regs->lr); |
68 #else | 68 #else |
69 #error "Unsupported architecture" | 69 #error "Unsupported architecture" |
70 #endif | 70 #endif |
71 } | 71 } |
72 return true; | 72 return true; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 167 |
168 void ThreadInterrupter::RemoveSignalHandler() { | 168 void ThreadInterrupter::RemoveSignalHandler() { |
169 // Nothing to do on Fuchsia. | 169 // Nothing to do on Fuchsia. |
170 } | 170 } |
171 | 171 |
172 #endif // !PRODUCT | 172 #endif // !PRODUCT |
173 | 173 |
174 } // namespace dart | 174 } // namespace dart |
175 | 175 |
176 #endif // defined(HOST_OS_FUCHSIA) | 176 #endif // defined(HOST_OS_FUCHSIA) |
OLD | NEW |