blob: 2127c9485724298ef69e498ac1bed83b78657e65 [file] [log] [blame]
mostang.com!davidmb39b4342003-04-24 20:45:07 +00001/* libunwind - a platform-independent unwind library
hp.com!davidm07b01ad2005-05-20 09:48:08 +00002 Copyright (C) 2003-2005 Hewlett-Packard Co
mostang.com!davidmb39b4342003-04-24 20:45:07 +00003 Contributed by David Mosberger-Tang <davidm@hpl.hp.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
mostang.com!davidmb39b4342003-04-24 20:45:07 +000026#include <dlfcn.h>
Arun Sharma1787a2f2010-05-15 12:14:09 -070027#include <string.h>
mostang.com!davidmb39b4342003-04-24 20:45:07 +000028#include <unistd.h>
29
hp.com!davidm07b01ad2005-05-20 09:48:08 +000030#include "libunwind_i.h"
mostang.com!davidmb39b4342003-04-24 20:45:07 +000031
32#include "elf64.h"
33
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080034/* ANDROID support update. */
35extern struct map_info *local_map_list;
36HIDDEN define_lock(os_map_lock);
37
38HIDDEN struct map_info *
39maps_create_list (pid_t pid)
40{
41 return NULL;
42}
43
44PROTECTED int
45tdep_get_elf_image (unw_addr_space_t as, struct elf_image *ei,
46 pid_t pid, unw_word_t ip,
47 unsigned long *segbase, unsigned long *mapoff, char **path)
mostang.com!davidmb39b4342003-04-24 20:45:07 +000048{
49 struct load_module_desc lmd;
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080050 const char *path;
mostang.com!davidmb39b4342003-04-24 20:45:07 +000051
52 if (pid != getpid ())
53 {
54 printf ("%s: remote case not implemented yet\n", __FUNCTION__);
55 return -UNW_ENOINFO;
56 }
57
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080058 /* First check to see if this ip is in our cache. */
59 map = map_find_from_addr(as->map_list, ip);
60 if (map)
61 goto finish;
62
63 /* Lock while we update the list. */
64 lock_acquire (&os_map_lock, saved_mask);
65
66 /* Check again if ip is in the map. */
67 map = map_find_from_addr(as->map_list, ip);
68 if (map)
69 goto release_lock;
70
71 /* Not in the cache, try and find the data. */
mostang.com!davidmb39b4342003-04-24 20:45:07 +000072 if (!dlmodinfo (ip, &lmd, sizeof (lmd), NULL, 0, 0))
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080073 goto release_lock;
mostang.com!davidmb39b4342003-04-24 20:45:07 +000074
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080075 path = dlgetname (&lmd, sizeof (lmd), NULL, 0, 0);
76 if (!path)
77 goto release_lock;
mostang.com!davidmb39b4342003-04-24 20:45:07 +000078
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080079 map = mempool_alloc (&map_pool);
80 if (!map)
81 goto release_lock;
82
83 map->start = lmd.text_base;
84 map->end = cur_map->start + lmd.text_size;
85 map->offset = 0; /* XXX fix me? */
86 map->flags = ;
87 map->path = strdup(path2);
88 mutex_init (&cur_map->ei_lock);
89 map->ei.size = 0;
90 map->ei.image = NULL;
91 map->ei_shared = 0;
92 Debug(1, "segbase=%lx, mapoff=%lx, path=%s\n", map->start, map->offset, map->path);
93
94 if (elf_map_cached_image (map, ip) < 0)
Arun Sharma1787a2f2010-05-15 12:14:09 -070095 {
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080096 free(map);
97 map = NULL;
Arun Sharma1787a2f2010-05-15 12:14:09 -070098 }
Christopher Ferrisf4a8df52014-03-07 19:40:06 -080099 else
100 {
101 /* Add this element into list in descending order by start. */
102 struct map_info *map_list = as->map_list;
103 if (as->map_list == NULL || map->start > as->map_list->start)
104 {
105 map->next = as->map_list;
106 as->map_list = map;
107 }
108 else
109 {
110 while (map_list->next != NULL && map->start <= map_list->next->start)
111 map_list = map_list->next;
112 map->next = map_list->next;
113 map_list->next = map;
114 }
115 }
116release_lock:
117 lock_release (&os_map_lock, saved_mask);
mostang.com!davidmb39b4342003-04-24 20:45:07 +0000118
Christopher Ferrisf4a8df52014-03-07 19:40:06 -0800119finish:
120 if (map)
121 {
122 *ei = map->ei;
123 *segbase = map->start;
124 *mapoff = map->offset;
125 if (path != NULL)
126 {
127 *path = strdup (map->path);
128 }
129 }
130 return 0;
mostang.com!davidmb39b4342003-04-24 20:45:07 +0000131}
Christopher Ferris7d46a212013-11-14 14:03:33 -0800132
Christopher Ferrisf4a8df52014-03-07 19:40:06 -0800133PROTECTED int
134maps_is_local_readable(struct map_info *map_list, unw_word_t addr)
Christopher Ferris7d46a212013-11-14 14:03:33 -0800135{
Christopher Ferrisf4a8df52014-03-07 19:40:06 -0800136 return 1;
Christopher Ferris7d46a212013-11-14 14:03:33 -0800137}
138
Christopher Ferrisf4a8df52014-03-07 19:40:06 -0800139PROTECTED int
140maps_is_local_writable(struct map_info *map_list, unw_word_t addr)
Christopher Ferris7d46a212013-11-14 14:03:33 -0800141{
Christopher Ferrisf4a8df52014-03-07 19:40:06 -0800142 return 1;
Christopher Ferris7d46a212013-11-14 14:03:33 -0800143}
Christopher Ferrisf4a8df52014-03-07 19:40:06 -0800144/* End of ANDROID update. */