1d4e76214Sopenharmony_ci/* libunwind - a platform-independent unwind library 2d4e76214Sopenharmony_ci Copyright (C) 2003-2005 Hewlett-Packard Co 3d4e76214Sopenharmony_ci Contributed by David Mosberger-Tang <davidm@hpl.hp.com> 4d4e76214Sopenharmony_ci 5d4e76214Sopenharmony_ciThis file is part of libunwind. 6d4e76214Sopenharmony_ci 7d4e76214Sopenharmony_ciPermission is hereby granted, free of charge, to any person obtaining 8d4e76214Sopenharmony_cia copy of this software and associated documentation files (the 9d4e76214Sopenharmony_ci"Software"), to deal in the Software without restriction, including 10d4e76214Sopenharmony_ciwithout limitation the rights to use, copy, modify, merge, publish, 11d4e76214Sopenharmony_cidistribute, sublicense, and/or sell copies of the Software, and to 12d4e76214Sopenharmony_cipermit persons to whom the Software is furnished to do so, subject to 13d4e76214Sopenharmony_cithe following conditions: 14d4e76214Sopenharmony_ci 15d4e76214Sopenharmony_ciThe above copyright notice and this permission notice shall be 16d4e76214Sopenharmony_ciincluded in all copies or substantial portions of the Software. 17d4e76214Sopenharmony_ci 18d4e76214Sopenharmony_ciTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19d4e76214Sopenharmony_ciEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20d4e76214Sopenharmony_ciMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21d4e76214Sopenharmony_ciNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22d4e76214Sopenharmony_ciLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23d4e76214Sopenharmony_ciOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24d4e76214Sopenharmony_ciWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 25d4e76214Sopenharmony_ci 26d4e76214Sopenharmony_ci#include <limits.h> 27d4e76214Sopenharmony_ci#include <stdio.h> 28d4e76214Sopenharmony_ci 29d4e76214Sopenharmony_ci#include "libunwind_i.h" 30d4e76214Sopenharmony_ci#include "os-linux.h" // using linux header for map_iterator implementation 31d4e76214Sopenharmony_ci 32d4e76214Sopenharmony_ciint 33d4e76214Sopenharmony_citdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip, 34d4e76214Sopenharmony_ci unsigned long *segbase, unsigned long *mapoff, 35d4e76214Sopenharmony_ci char *path, size_t pathlen) 36d4e76214Sopenharmony_ci{ 37d4e76214Sopenharmony_ci struct map_iterator mi; 38d4e76214Sopenharmony_ci int found = 0, rc; 39d4e76214Sopenharmony_ci unsigned long hi; 40d4e76214Sopenharmony_ci 41d4e76214Sopenharmony_ci if (maps_init (&mi, pid) < 0) 42d4e76214Sopenharmony_ci return -1; 43d4e76214Sopenharmony_ci 44d4e76214Sopenharmony_ci while (maps_next (&mi, segbase, &hi, mapoff, NULL)) 45d4e76214Sopenharmony_ci if (ip >= *segbase && ip < hi) 46d4e76214Sopenharmony_ci { 47d4e76214Sopenharmony_ci found = 1; 48d4e76214Sopenharmony_ci break; 49d4e76214Sopenharmony_ci } 50d4e76214Sopenharmony_ci 51d4e76214Sopenharmony_ci if (!found) 52d4e76214Sopenharmony_ci { 53d4e76214Sopenharmony_ci maps_close (&mi); 54d4e76214Sopenharmony_ci return -1; 55d4e76214Sopenharmony_ci } 56d4e76214Sopenharmony_ci if (path) 57d4e76214Sopenharmony_ci { 58d4e76214Sopenharmony_ci strncpy(path, mi.path, pathlen); 59d4e76214Sopenharmony_ci } 60d4e76214Sopenharmony_ci rc = elf_map_image (ei, mi.path); 61d4e76214Sopenharmony_ci maps_close (&mi); 62d4e76214Sopenharmony_ci return rc; 63d4e76214Sopenharmony_ci} 64d4e76214Sopenharmony_ci 65d4e76214Sopenharmony_ci#ifndef UNW_REMOTE_ONLY 66d4e76214Sopenharmony_ci 67d4e76214Sopenharmony_civoid 68d4e76214Sopenharmony_citdep_get_exe_image_path (char *path) 69d4e76214Sopenharmony_ci{ 70d4e76214Sopenharmony_ci strcpy(path, getexecname()); 71d4e76214Sopenharmony_ci} 72d4e76214Sopenharmony_ci 73d4e76214Sopenharmony_ci#endif /* !UNW_REMOTE_ONLY */ 74