blob: e1149c51f236a1be790d1d20ab995c544de29278 [file] [log] [blame]
Matt Fischereac65dc2013-04-15 09:53:29 -05001/* libunwind - a platform-independent unwind library
2 Copyright (C) 2013 Garmin International
3 Contributed by Matt Fischer <matt.fischer@garmin.com>
4
5This file is part of libunwind.
6
7Permission is hereby granted, free of charge, to any person obtaining
8a copy of this software and associated documentation files (the
9"Software"), to deal in the Software without restriction, including
10without limitation the rights to use, copy, modify, merge, publish,
11distribute, sublicense, and/or sell copies of the Software, and to
12permit persons to whom the Software is furnished to do so, subject to
13the following conditions:
14
15The above copyright notice and this permission notice shall be
16included in all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
25
26#include <string.h>
27
28#include "libunwind_i.h"
29
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080030/* ANDROID support update. */
Matt Fischereac65dc2013-04-15 09:53:29 -050031static int callback(const struct dl_phdr_info *info, size_t size, void *data)
32{
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080033 struct map_info **map_list = (struct map_info **)data;
34 struct map_info *cur_map;
Matt Fischereac65dc2013-04-15 09:53:29 -050035 int i;
36 struct cb_info *cbi = (struct cb_info*)data;
37 for(i=0; i<info->dlpi_phnum; i++) {
38 int segbase = info->dlpi_addr + info->dlpi_phdr[i].p_vaddr;
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080039
40 cur_map = map_alloc_info ();
41 if (cur_map == NULL)
42 break;
43
44 cur_map->next = *map_list;
45 cur_map->start = info->dlpi_addr + info->dlpi_phdr[i].p_vaddr;
46 cur_map->end = cur_map->start + info->dlpi_phdr[i].p_memsz;
47 cur_map->offset = info->dlpi_phdr[i].p_offset;
48 cur_map->path = strdup(info->dlpi_name);
49 mutex_init (&cur_map->ei_lock);
50 cur_map->ei.size = 0;
51 cur_map->ei.image = NULL;
52 cur_map->ei.shared = 0;
53
54 *map_list = cur_map;
Matt Fischereac65dc2013-04-15 09:53:29 -050055 }
56
57 return 0;
58}
59
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080060struct map_info *
61map_create_list (pid_t pid)
Matt Fischereac65dc2013-04-15 09:53:29 -050062{
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080063 struct map_info *map_list = NULL;
Matt Fischereac65dc2013-04-15 09:53:29 -050064
Arun Sharma5eba0f82013-05-18 23:20:03 -070065 /* QNX's support for accessing symbol maps is severely broken. There is
66 a devctl() call that can be made on a proc node (DCMD_PROC_MAPDEBUG)
67 which returns information similar to Linux's /proc/<pid>/maps
68 node, however the filename that is returned by this call is not an
69 absolute path, and there is no foolproof way to map the filename
70 back to the file that it came from.
Matt Fischereac65dc2013-04-15 09:53:29 -050071
Arun Sharma5eba0f82013-05-18 23:20:03 -070072 Therefore, the normal approach for implementing this function,
73 which works equally well for both local and remote unwinding,
74 will not work here. The only type of image lookup which works
75 reliably is locally, using dl_iterate_phdr(). However, the only
76 time that this function is required to look up a remote image is for
77 ptrace support, which doesn't work on QNX anyway. Local unwinding,
78 which is the main case that makes use of this function, will work
79 fine with dl_iterate_phdr(). Therefore, in lieu of any better
80 platform support for remote image lookup, this function has just
81 been implemented in terms of dl_iterate_phdr().
Matt Fischereac65dc2013-04-15 09:53:29 -050082 */
Arun Sharma5eba0f82013-05-18 23:20:03 -070083
Matt Fischereac65dc2013-04-15 09:53:29 -050084 if (pid != getpid())
Matt Fischereac65dc2013-04-15 09:53:29 -050085 {
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080086 /* Return an error if an attempt is made to perform remote image lookup */
87 return -1;
Matt Fischereac65dc2013-04-15 09:53:29 -050088 }
89
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080090 if (dl_iterate_phdr (callback, &map_list) != 0)
91 return map_list;
Christopher Ferris7d46a212013-11-14 14:03:33 -080092 return NULL;
93}
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080094/* End of ANDROID update. */