1/* 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 30/* ANDROID support update. */ 31static int callback(const struct dl_phdr_info *info, size_t size, void *data) 32{ 33 struct map_info **map_list = (struct map_info **)data; 34 struct map_info *cur_map; 35 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; 39 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; 55 } 56 57 return 0; 58} 59 60struct map_info * 61map_create_list (pid_t pid) 62{ 63 struct map_info *map_list = NULL; 64 65 /* 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. 71 72 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(). 82 */ 83 84 if (pid != getpid()) 85 { 86 /* Return an error if an attempt is made to perform remote image lookup */ 87 return -1; 88 } 89 90 if (dl_iterate_phdr (callback, &map_list) != 0) 91 return map_list; 92 return NULL; 93} 94/* End of ANDROID update. */ 95