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