-
Notifications
You must be signed in to change notification settings - Fork 0
/
dl_iterate_phdr.c
70 lines (54 loc) · 1.45 KB
/
dl_iterate_phdr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright 2022-2024 Gaël PORTAY
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <dlfcn.h>
#include <link.h>
#include "iamroot.h"
static int (*sym)(int (*)(struct dl_phdr_info *, size_t, void *), void *);
hidden int next_dl_iterate_phdr(
int (*callback)(struct dl_phdr_info *, size_t, void *),
void *data)
{
if (!sym)
sym = dlsym(RTLD_NEXT, "dl_iterate_phdr");
if (!sym)
return __dl_set_errno_and_perror(ENOSYS, -1);
return sym(callback, data);
}
struct dl_iterate_phdr_args {
int (*callback)(struct dl_phdr_info *, size_t, void *);
void *data;
};
static int __dl_iterate_phdr_callback(struct dl_phdr_info *info, size_t size,
void *data)
{
struct dl_iterate_phdr_args *args;
char buf[PATH_MAX];
__strncpy(buf, info->dlpi_name);
__striprootdir(buf);
__debug("%s(info: %p { .info->dlpi_name: '%s' -> '%s'}, ...)\n",
__func__, info, info->dlpi_name, buf);
info->dlpi_name = buf;
args = (struct dl_iterate_phdr_args *)data;
return args->callback(info, size, args->data);
}
int dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *),
void *data)
{
struct dl_iterate_phdr_args args = {
.callback = callback,
.data = data,
};
int ret;
ret = next_dl_iterate_phdr(__dl_iterate_phdr_callback, &args);
__debug("%s(callback: %p, data: %p) -> %i\n", __func__, callback, data,
ret);
return ret;
}