mostang.com!davidm | b39b434 | 2003-04-24 20:45:07 +0000 | [diff] [blame] | 1 | /* libunwind - a platform-independent unwind library |
hp.com!davidm | 07b01ad | 2005-05-20 09:48:08 +0000 | [diff] [blame] | 2 | Copyright (C) 2003-2005 Hewlett-Packard Co |
mostang.com!davidm | b39b434 | 2003-04-24 20:45:07 +0000 | [diff] [blame] | 3 | Contributed by David Mosberger-Tang <davidm@hpl.hp.com> |
| 4 | |
| 5 | This file is part of libunwind. |
| 6 | |
| 7 | Permission is hereby granted, free of charge, to any person obtaining |
| 8 | a copy of this software and associated documentation files (the |
| 9 | "Software"), to deal in the Software without restriction, including |
| 10 | without limitation the rights to use, copy, modify, merge, publish, |
| 11 | distribute, sublicense, and/or sell copies of the Software, and to |
| 12 | permit persons to whom the Software is furnished to do so, subject to |
| 13 | the following conditions: |
| 14 | |
| 15 | The above copyright notice and this permission notice shall be |
| 16 | included in all copies or substantial portions of the Software. |
| 17 | |
| 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 22 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 24 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 25 | |
mostang.com!davidm | b39b434 | 2003-04-24 20:45:07 +0000 | [diff] [blame] | 26 | #include <dlfcn.h> |
Arun Sharma | 1787a2f | 2010-05-15 12:14:09 -0700 | [diff] [blame] | 27 | #include <string.h> |
mostang.com!davidm | b39b434 | 2003-04-24 20:45:07 +0000 | [diff] [blame] | 28 | #include <unistd.h> |
| 29 | |
hp.com!davidm | 07b01ad | 2005-05-20 09:48:08 +0000 | [diff] [blame] | 30 | #include "libunwind_i.h" |
mostang.com!davidm | b39b434 | 2003-04-24 20:45:07 +0000 | [diff] [blame] | 31 | |
| 32 | #include "elf64.h" |
| 33 | |
Christopher Ferris | f4a8df5 | 2014-03-07 19:40:06 -0800 | [diff] [blame^] | 34 | /* ANDROID support update. */ |
| 35 | extern struct map_info *local_map_list; |
| 36 | HIDDEN define_lock(os_map_lock); |
| 37 | |
| 38 | HIDDEN struct map_info * |
| 39 | maps_create_list (pid_t pid) |
| 40 | { |
| 41 | return NULL; |
| 42 | } |
| 43 | |
| 44 | PROTECTED int |
| 45 | tdep_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!davidm | b39b434 | 2003-04-24 20:45:07 +0000 | [diff] [blame] | 48 | { |
| 49 | struct load_module_desc lmd; |
Christopher Ferris | f4a8df5 | 2014-03-07 19:40:06 -0800 | [diff] [blame^] | 50 | const char *path; |
mostang.com!davidm | b39b434 | 2003-04-24 20:45:07 +0000 | [diff] [blame] | 51 | |
| 52 | if (pid != getpid ()) |
| 53 | { |
| 54 | printf ("%s: remote case not implemented yet\n", __FUNCTION__); |
| 55 | return -UNW_ENOINFO; |
| 56 | } |
| 57 | |
Christopher Ferris | f4a8df5 | 2014-03-07 19:40:06 -0800 | [diff] [blame^] | 58 | /* 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!davidm | b39b434 | 2003-04-24 20:45:07 +0000 | [diff] [blame] | 72 | if (!dlmodinfo (ip, &lmd, sizeof (lmd), NULL, 0, 0)) |
Christopher Ferris | f4a8df5 | 2014-03-07 19:40:06 -0800 | [diff] [blame^] | 73 | goto release_lock; |
mostang.com!davidm | b39b434 | 2003-04-24 20:45:07 +0000 | [diff] [blame] | 74 | |
Christopher Ferris | f4a8df5 | 2014-03-07 19:40:06 -0800 | [diff] [blame^] | 75 | path = dlgetname (&lmd, sizeof (lmd), NULL, 0, 0); |
| 76 | if (!path) |
| 77 | goto release_lock; |
mostang.com!davidm | b39b434 | 2003-04-24 20:45:07 +0000 | [diff] [blame] | 78 | |
Christopher Ferris | f4a8df5 | 2014-03-07 19:40:06 -0800 | [diff] [blame^] | 79 | 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 Sharma | 1787a2f | 2010-05-15 12:14:09 -0700 | [diff] [blame] | 95 | { |
Christopher Ferris | f4a8df5 | 2014-03-07 19:40:06 -0800 | [diff] [blame^] | 96 | free(map); |
| 97 | map = NULL; |
Arun Sharma | 1787a2f | 2010-05-15 12:14:09 -0700 | [diff] [blame] | 98 | } |
Christopher Ferris | f4a8df5 | 2014-03-07 19:40:06 -0800 | [diff] [blame^] | 99 | 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 | } |
| 116 | release_lock: |
| 117 | lock_release (&os_map_lock, saved_mask); |
mostang.com!davidm | b39b434 | 2003-04-24 20:45:07 +0000 | [diff] [blame] | 118 | |
Christopher Ferris | f4a8df5 | 2014-03-07 19:40:06 -0800 | [diff] [blame^] | 119 | finish: |
| 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!davidm | b39b434 | 2003-04-24 20:45:07 +0000 | [diff] [blame] | 131 | } |
Christopher Ferris | 7d46a21 | 2013-11-14 14:03:33 -0800 | [diff] [blame] | 132 | |
Christopher Ferris | f4a8df5 | 2014-03-07 19:40:06 -0800 | [diff] [blame^] | 133 | PROTECTED int |
| 134 | maps_is_local_readable(struct map_info *map_list, unw_word_t addr) |
Christopher Ferris | 7d46a21 | 2013-11-14 14:03:33 -0800 | [diff] [blame] | 135 | { |
Christopher Ferris | f4a8df5 | 2014-03-07 19:40:06 -0800 | [diff] [blame^] | 136 | return 1; |
Christopher Ferris | 7d46a21 | 2013-11-14 14:03:33 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Christopher Ferris | f4a8df5 | 2014-03-07 19:40:06 -0800 | [diff] [blame^] | 139 | PROTECTED int |
| 140 | maps_is_local_writable(struct map_info *map_list, unw_word_t addr) |
Christopher Ferris | 7d46a21 | 2013-11-14 14:03:33 -0800 | [diff] [blame] | 141 | { |
Christopher Ferris | f4a8df5 | 2014-03-07 19:40:06 -0800 | [diff] [blame^] | 142 | return 1; |
Christopher Ferris | 7d46a21 | 2013-11-14 14:03:33 -0800 | [diff] [blame] | 143 | } |
Christopher Ferris | f4a8df5 | 2014-03-07 19:40:06 -0800 | [diff] [blame^] | 144 | /* End of ANDROID update. */ |