Flutter Engine
The Flutter Engine
thread_interrupter_linux.cc
Go to the documentation of this file.
1// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
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.
4
5#include "platform/globals.h"
6#if defined(DART_HOST_OS_LINUX)
7
8#include <errno.h> // NOLINT
9
10#include "vm/flags.h"
11#include "vm/os.h"
12#include "vm/profiler.h"
13#include "vm/signal_handler.h"
15
16namespace dart {
17
18#ifndef PRODUCT
19
20DECLARE_FLAG(bool, trace_thread_interrupter);
21
22class ThreadInterrupterLinux : public AllStatic {
23 public:
24 static void ThreadInterruptSignalHandler(int signal,
25 siginfo_t* info,
26 void* context_) {
27 if (signal != SIGPROF) {
28 return;
29 }
30 Thread* thread = Thread::Current();
31 if (thread == nullptr) {
32 return;
33 }
34 ThreadInterruptScope signal_handler_scope;
35 // Extract thread state.
36 ucontext_t* context = reinterpret_cast<ucontext_t*>(context_);
37 mcontext_t mcontext = context->uc_mcontext;
38 InterruptedThreadState its;
39 its.pc = SignalHandler::GetProgramCounter(mcontext);
40 its.fp = SignalHandler::GetFramePointer(mcontext);
41 its.csp = SignalHandler::GetCStackPointer(mcontext);
42 its.dsp = SignalHandler::GetDartStackPointer(mcontext);
43 its.lr = SignalHandler::GetLinkRegister(mcontext);
44 Profiler::SampleThread(thread, its);
45 }
46};
47
48void ThreadInterrupter::InterruptThread(OSThread* thread) {
49 if (FLAG_trace_thread_interrupter) {
50 OS::PrintErr("ThreadInterrupter interrupting %p\n",
51 reinterpret_cast<void*>(thread->id()));
52 }
53 int result = pthread_kill(thread->id(), SIGPROF);
54 ASSERT((result == 0) || (result == ESRCH));
55}
56
57void ThreadInterrupter::InstallSignalHandler() {
58 SignalHandler::Install(&ThreadInterrupterLinux::ThreadInterruptSignalHandler);
59}
60
61void ThreadInterrupter::RemoveSignalHandler() {
63}
64
65#endif // !PRODUCT
66
67} // namespace dart
68
69#endif // defined(DART_HOST_OS_LINUX)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static void SampleThread(Thread *thread, const InterruptedThreadState &state)
Definition: profiler.cc:1354
static void Remove()
static uintptr_t GetDartStackPointer(const mcontext_t &mcontext)
static uintptr_t GetCStackPointer(const mcontext_t &mcontext)
static uintptr_t GetFramePointer(const mcontext_t &mcontext)
static uintptr_t GetProgramCounter(const mcontext_t &mcontext)
static void Install(SignalAction action)
static uintptr_t GetLinkRegister(const mcontext_t &mcontext)
static void InterruptThread(OSThread *thread)
static Thread * Current()
Definition: thread.h:362
#define ASSERT(E)
GAsyncResult * result
Definition: dart_vm.cc:33
DECLARE_FLAG(bool, show_invisible_frames)