diff options
Diffstat (limited to 'elf_info.c')
-rw-r--r-- | elf_info.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -691,6 +691,34 @@ get_max_paddr(void) return max_paddr; } +/* + * Find the LOAD segment which is closest to the requested + * physical address within a given distance. + * If there is no such segment, return a negative number. + */ +int +closest_pt_load(unsigned long long paddr, unsigned long distance) +{ + int i, bestidx; + struct pt_load_segment *pls; + unsigned long bestdist; + + bestdist = distance; + bestidx = -1; + for (i = 0; i < num_pt_loads; ++i) { + pls = &pt_loads[i]; + if (paddr >= pls->phys_end) + continue; + if (paddr >= pls->phys_start) + return i; /* Exact match */ + if (bestdist > pls->phys_start - paddr) { + bestdist = pls->phys_start - paddr; + bestidx = i; + } + } + return bestidx; +} + int get_elf64_ehdr(int fd, char *filename, Elf64_Ehdr *ehdr) { |