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(HOST_OS_LINUX)
7
8#include "platform/memory_sanitizer.h"
9#include "vm/native_symbol.h"
10#include "vm/os.h"
11
12#include <cxxabi.h> // NOLINT
13#include <dlfcn.h> // NOLINT
14
15namespace dart {
16
17void NativeSymbolResolver::Init() {}
18
19void NativeSymbolResolver::Cleanup() {}
20
21char* NativeSymbolResolver::LookupSymbolName(uword pc, uword* start) {
22 Dl_info info;
23 int r = dladdr(reinterpret_cast<void*>(pc), &info);
24 if (r == 0) {
25 return NULL;
26 }
27 if (info.dli_sname == NULL) {
28 return NULL;
29 }
30 if (start != NULL) {
31 *start = reinterpret_cast<uword>(info.dli_saddr);
32 }
33 int status = 0;
34 size_t len = 0;
35 char* demangled = abi::__cxa_demangle(info.dli_sname, NULL, &len, &status);
36 MSAN_UNPOISON(demangled, len);
37 if (status == 0) {
38 return demangled;
39 }
40 return strdup(info.dli_sname);
41}
42
43void NativeSymbolResolver::FreeSymbolName(char* name) {
44 free(name);
45}
46
47bool NativeSymbolResolver::LookupSharedObject(uword pc,
48 uword* dso_base,
49 char** dso_name) {
50 Dl_info info;
51 int r = dladdr(reinterpret_cast<void*>(pc), &info);
52 if (r == 0) {
53 return false;
54 }
55 if (dso_base != nullptr) {
56 *dso_base = reinterpret_cast<uword>(info.dli_fbase);
57 }
58 if (dso_name != nullptr) {
59 *dso_name = strdup(info.dli_fname);
60 }
61 return true;
62}
63
64void NativeSymbolResolver::AddSymbols(const char* dso_name,
65 void* buffer,
66 size_t size) {
67 OS::PrintErr("warning: Dart_AddSymbols has no effect on Linux\n");
68}
69
70} // namespace dart
71
72#endif // defined(HOST_OS_LINUX)
73