selftests/bpf: Add {load,search}_kallsyms_custom_local()
These two functions allow selftests to do loading/searching kallsyms based on their specific compare functions. Signed-off-by: Yonghong Song <yonghong.song@linux.dev> Link: https://lore.kernel.org/r/20240326041513.1199440-1-yonghong.song@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
9475dacb75
commit
d1f0258105
@ -114,6 +114,11 @@ struct ksyms *load_kallsyms_local(void)
|
||||
return load_kallsyms_local_common(ksym_cmp);
|
||||
}
|
||||
|
||||
struct ksyms *load_kallsyms_custom_local(ksym_cmp_t cmp_cb)
|
||||
{
|
||||
return load_kallsyms_local_common(cmp_cb);
|
||||
}
|
||||
|
||||
int load_kallsyms(void)
|
||||
{
|
||||
pthread_mutex_lock(&ksyms_mutex);
|
||||
@ -153,6 +158,28 @@ struct ksym *ksym_search_local(struct ksyms *ksyms, long key)
|
||||
return &ksyms->syms[0];
|
||||
}
|
||||
|
||||
struct ksym *search_kallsyms_custom_local(struct ksyms *ksyms, const void *p,
|
||||
ksym_search_cmp_t cmp_cb)
|
||||
{
|
||||
int start = 0, mid, end = ksyms->sym_cnt;
|
||||
struct ksym *ks;
|
||||
int result;
|
||||
|
||||
while (start < end) {
|
||||
mid = start + (end - start) / 2;
|
||||
ks = &ksyms->syms[mid];
|
||||
result = cmp_cb(p, ks);
|
||||
if (result < 0)
|
||||
end = mid;
|
||||
else if (result > 0)
|
||||
start = mid + 1;
|
||||
else
|
||||
return ks;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct ksym *ksym_search(long key)
|
||||
{
|
||||
if (!ksyms)
|
||||
|
@ -14,6 +14,7 @@ struct ksym {
|
||||
struct ksyms;
|
||||
|
||||
typedef int (*ksym_cmp_t)(const void *p1, const void *p2);
|
||||
typedef int (*ksym_search_cmp_t)(const void *p1, const struct ksym *p2);
|
||||
|
||||
int load_kallsyms(void);
|
||||
struct ksym *ksym_search(long key);
|
||||
@ -24,6 +25,10 @@ struct ksym *ksym_search_local(struct ksyms *ksyms, long key);
|
||||
long ksym_get_addr_local(struct ksyms *ksyms, const char *name);
|
||||
void free_kallsyms_local(struct ksyms *ksyms);
|
||||
|
||||
struct ksyms *load_kallsyms_custom_local(ksym_cmp_t cmp_cb);
|
||||
struct ksym *search_kallsyms_custom_local(struct ksyms *ksyms, const void *p1,
|
||||
ksym_search_cmp_t cmp_cb);
|
||||
|
||||
/* open kallsyms and find addresses on the fly, faster than load + search. */
|
||||
int kallsyms_find(const char *sym, unsigned long long *addr);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user