os-common.c revision f4a8df5f4f338f1a12c25213227e98b34b42447f
1/* 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
29extern struct map_info *local_get_elf_image (unw_word_t, struct elf_image *,
30                                             unsigned long *, unsigned long *,
31                                             char **);
32
33PROTECTED int
34tdep_get_elf_image (unw_addr_space_t as, struct elf_image *ei,
35                    pid_t pid, unw_word_t ip,
36                    unsigned long *segbase, unsigned long *mapoff, char **path)
37{
38  struct map_info *map;
39
40  if (pid == getpid())
41    return local_get_elf_image (ei, ip, segbase, mapoff, path);
42
43  map = map_find_from_addr (as->map_list, ip);
44  if (!map)
45    return -UNW_ENOINFO;
46
47  if (elf_map_cached_image (map, ip) < 0)
48    return -UNW_ENOINFO;
49
50  *ei = map->ei;
51  *segbase = map->start;
52  *mapoff = map->offset;
53  if (path != NULL)
54    {
55      *path = strdup (map->path);
56    }
57  return 0;
58}
59