+ struct frame_hdr_cache_element *prev_cache_entry = NULL,
+ *last_cache_entry = NULL;
+
+ if (data->check_cache && size >= sizeof (struct ext_dl_phdr_info))
+ {
+ static unsigned long long adds = -1ULL, subs;
+ struct ext_dl_phdr_info *einfo = (struct ext_dl_phdr_info *) info;
+
+ /* We use a least recently used cache replacement policy. Also,
+ the most recently used cache entries are placed at the head
+ of the search chain. */
+
+ if (einfo->dlpi_adds == adds && einfo->dlpi_subs == subs)
+ {
+ /* Find data->pc in shared library cache.
+ Set load_base, p_eh_frame_hdr and p_dynamic
+ plus match from the cache and goto
+ "Read .eh_frame_hdr header." below. */
+
+ struct frame_hdr_cache_element *cache_entry;
+
+ for (cache_entry = frame_hdr_cache_head;
+ cache_entry;
+ cache_entry = cache_entry->link)
+ {
+ if (data->pc >= cache_entry->pc_low
+ && data->pc < cache_entry->pc_high)
+ {
+ load_base = cache_entry->load_base;
+ p_eh_frame_hdr = cache_entry->p_eh_frame_hdr;
+ p_dynamic = cache_entry->p_dynamic;
+
+ /* And move the entry we're using to the head. */
+ if (cache_entry != frame_hdr_cache_head)
+ {
+ prev_cache_entry->link = cache_entry->link;
+ cache_entry->link = frame_hdr_cache_head;
+ frame_hdr_cache_head = cache_entry;
+ }
+ goto found;
+ }
+
+ last_cache_entry = cache_entry;
+ /* Exit early if we found an unused entry. */
+ if ((cache_entry->pc_low | cache_entry->pc_high) == 0)
+ break;
+ if (cache_entry->link != NULL)
+ prev_cache_entry = cache_entry;
+ }
+ }
+ else
+ {
+ adds = einfo->dlpi_adds;
+ subs = einfo->dlpi_subs;
+ /* Initialize the cache. Create a chain of cache entries,
+ with the final one terminated by a NULL link. */
+ int i;
+ for (i = 0; i < FRAME_HDR_CACHE_SIZE; i++)
+ {
+ frame_hdr_cache[i].pc_low = 0;
+ frame_hdr_cache[i].pc_high = 0;
+ frame_hdr_cache[i].link = &frame_hdr_cache[i+1];
+ }
+ frame_hdr_cache[i-1].link = NULL;
+ frame_hdr_cache_head = &frame_hdr_cache[0];
+ data->check_cache = 0;
+ }
+ }
+
+ /* Make sure struct dl_phdr_info is at least as big as we need. */
+ if (size < offsetof (struct dl_phdr_info, dlpi_phnum)
+ + sizeof (info->dlpi_phnum))
+ return -1;
+