Home | History | Annotate | Download | only in src
      1 /* libunwind - a platform-independent unwind library
      2    Copyright (C) 2003-2005 Hewlett-Packard Co
      3 	Contributed by David Mosberger-Tang <davidm (at) 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 
     26 #include <dlfcn.h>
     27 #include <string.h>
     28 #include <unistd.h>
     29 
     30 #include "libunwind_i.h"
     31 
     32 #include "elf64.h"
     33 
     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)
     48 {
     49   struct load_module_desc lmd;
     50   const char *path;
     51 
     52   if (pid != getpid ())
     53     {
     54       printf ("%s: remote case not implemented yet\n", __FUNCTION__);
     55       return -UNW_ENOINFO;
     56     }
     57 
     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. */
     72   if (!dlmodinfo (ip, &lmd, sizeof (lmd), NULL, 0, 0))
     73     goto release_lock;
     74 
     75   path = dlgetname (&lmd, sizeof (lmd), NULL, 0, 0);
     76   if (!path)
     77     goto release_lock;
     78 
     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)
     95     {
     96       free(map);
     97       map = NULL;
     98     }
     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);
    118 
    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;
    131 }
    132 
    133 PROTECTED int
    134 maps_is_local_readable(struct map_info *map_list, unw_word_t addr)
    135 {
    136   return 1;
    137 }
    138 
    139 PROTECTED int
    140 maps_is_local_writable(struct map_info *map_list, unw_word_t addr)
    141 {
    142   return 1;
    143 }
    144 /* End of ANDROID update. */
    145