Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
native_symbol_win.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 "vm/globals.h"
6#if defined(DART_HOST_OS_WINDOWS)
7
8#include "vm/lockers.h"
9#include "vm/native_symbol.h"
10#include "vm/os.h"
11#include "vm/os_thread.h"
12
13#include <dbghelp.h> // NOLINT
14
15namespace dart {
16
17static bool running_ = false;
18static Mutex* lock_ = nullptr;
19
21 ASSERT(running_ == false);
22 if (lock_ == nullptr) {
23 lock_ = new Mutex();
24 }
25 running_ = true;
26
27// Symbol resolution API's used in this file are not supported
28// when compiled in UWP.
29#ifndef DART_TARGET_OS_WINDOWS_UWP
30 SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS);
31 HANDLE hProcess = GetCurrentProcess();
32 if (!SymInitialize(hProcess, nullptr, TRUE)) {
34 OS::PrintErr("Failed to init NativeSymbolResolver (SymInitialize %" Pu32
35 ")\n",
36 error);
37 return;
38 }
39#endif
40}
41
43 MutexLocker lock(lock_);
44 if (!running_) {
45 return;
46 }
47 running_ = false;
48#ifndef DART_TARGET_OS_WINDOWS_UWP
49 HANDLE hProcess = GetCurrentProcess();
50 if (!SymCleanup(hProcess)) {
52 OS::PrintErr("Failed to shutdown NativeSymbolResolver (SymCleanup %" Pu32
53 ")\n",
54 error);
55 }
56#endif
57}
58
60#ifdef DART_TARGET_OS_WINDOWS_UWP
61 return nullptr;
62#else
63 const intptr_t kMaxNameLength = 2048;
64 const intptr_t kSymbolInfoSize = sizeof(SYMBOL_INFO); // NOLINT.
65 static char buffer[kSymbolInfoSize + kMaxNameLength];
66 static char name_buffer[kMaxNameLength];
67 MutexLocker lock(lock_);
68 if (!running_) {
69 return nullptr;
70 }
71 if (start != nullptr) {
72 *start = 0;
73 }
74 memset(&buffer[0], 0, sizeof(buffer));
75 HANDLE hProcess = GetCurrentProcess();
76 DWORD64 address = static_cast<DWORD64>(pc);
77 PSYMBOL_INFO pSymbol = reinterpret_cast<PSYMBOL_INFO>(&buffer[0]);
78 pSymbol->SizeOfStruct = kSymbolInfoSize;
79 pSymbol->MaxNameLen = kMaxNameLength;
80 DWORD64 displacement;
81 BOOL r = SymFromAddr(hProcess, address, &displacement, pSymbol);
82 if (r == FALSE) {
83 return nullptr;
84 }
85 if (start != nullptr) {
86 *start = pc - displacement;
87 }
88 return Utils::StrDup(pSymbol->Name);
89#endif // ifdef DART_TARGET_OS_WINDOWS_UWP
90}
91
93 free(name);
94}
95
97 uword* dso_base,
98 char** dso_name) {
99 return false;
100}
101
102void NativeSymbolResolver::AddSymbols(const char* dso_name,
103 void* buffer,
104 size_t size) {
105 OS::PrintErr("warning: Dart_AddSymbols has no effect on Windows\n");
106}
107
108} // namespace dart
109
110#endif // defined(DART_HOST_OS_WINDOWS)
static void AddSymbols(const char *dso_name, void *buffer, size_t size)
static void FreeSymbolName(char *name)
static bool LookupSharedObject(uword pc, uword *dso_base=nullptr, char **dso_name=nullptr)
static char * LookupSymbolName(uword pc, uword *start)
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static char * StrDup(const char *s)
#define ASSERT(E)
static const uint8_t buffer[]
const uint8_t uint32_t uint32_t GError ** error
return FALSE
const char *const name
uintptr_t uword
Definition globals.h:501
#define Pu32
Definition globals.h:413
int BOOL
WINBASEAPI _Check_return_ _Post_equals_last_error_ DWORD WINAPI GetLastError(VOID)
void * HANDLE
unsigned long DWORD