blob: 751c9d2a1c07cd5597b650b82522fc59fa547afd [file] [log] [blame]
Christopher Ferrisf4a8df52014-03-07 19:40:06 -08001/* libunwind - a platform-independent unwind library
2 Copyright (C) 2014 The Android Open Source Project
3
4This file is part of libunwind.
5
6Permission is hereby granted, free of charge, to any person obtaining
7a copy of this software and associated documentation files (the
8"Software"), to deal in the Software without restriction, including
9without limitation the rights to use, copy, modify, merge, publish,
10distribute, sublicense, and/or sell copies of the Software, and to
11permit persons to whom the Software is furnished to do so, subject to
12the following conditions:
13
14The above copyright notice and this permission notice shall be
15included in all copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
24
25
26#include "libunwind_i.h"
27#include "map_info.h"
28
Christopher Ferriscdf0d032015-05-04 11:01:39 -070029extern int local_get_elf_image (unw_addr_space_t as, struct elf_image *,
30 unw_word_t, unsigned long *, unsigned long *,
31 char **, void *);
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080032
33PROTECTED int
34tdep_get_elf_image (unw_addr_space_t as, struct elf_image *ei,
35 pid_t pid, unw_word_t ip,
Christopher Ferriscdf0d032015-05-04 11:01:39 -070036 unsigned long *segbase, unsigned long *mapoff, char **path,
37 void *as_arg)
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080038{
39 struct map_info *map;
40
41 if (pid == getpid())
Christopher Ferriscdf0d032015-05-04 11:01:39 -070042 return local_get_elf_image (as, ei, ip, segbase, mapoff, path, as_arg);
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080043
44 map = map_find_from_addr (as->map_list, ip);
45 if (!map)
46 return -UNW_ENOINFO;
47
Christopher Ferriscdf0d032015-05-04 11:01:39 -070048 if (!elf_map_cached_image (as, as_arg, map, ip))
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080049 return -UNW_ENOINFO;
50
51 *ei = map->ei;
52 *segbase = map->start;
Christopher Ferrisb025c422015-08-19 16:02:47 -070053 if (ei->mapped)
54 *mapoff = map->offset;
55 else
56 /* Always use zero as the map offset for in memory maps. The
57 * dlopen of a shared library from an APK will result in a
58 * non-zero offset so it won't match the elf data and cause
59 * unwinds to fail. Currently, only in memory unwinds of an APK
60 * are possible, so only modify this path.
61 */
62 *mapoff = 0;
63
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080064 if (path != NULL)
65 {
66 *path = strdup (map->path);
67 }
68 return 0;
69}