|
44 | 44 | #include <sys/vfs.h>
|
45 | 45 | #include <sys/utsname.h>
|
46 | 46 | #include <sys/resource.h>
|
47 |
| -#include <tools/libc_compat.h> |
48 | 47 | #include <libelf.h>
|
49 | 48 | #include <gelf.h>
|
50 | 49 | #include <zlib.h>
|
@@ -567,7 +566,7 @@ bpf_object__add_program(struct bpf_object *obj, void *data, size_t size,
|
567 | 566 | progs = obj->programs;
|
568 | 567 | nr_progs = obj->nr_programs;
|
569 | 568 |
|
570 |
| - progs = reallocarray(progs, nr_progs + 1, sizeof(progs[0])); |
| 569 | + progs = libbpf_reallocarray(progs, nr_progs + 1, sizeof(progs[0])); |
571 | 570 | if (!progs) {
|
572 | 571 | /*
|
573 | 572 | * In this case the original obj->programs
|
@@ -1292,7 +1291,7 @@ static struct bpf_map *bpf_object__add_map(struct bpf_object *obj)
|
1292 | 1291 | return &obj->maps[obj->nr_maps++];
|
1293 | 1292 |
|
1294 | 1293 | new_cap = max((size_t)4, obj->maps_cap * 3 / 2);
|
1295 |
| - new_maps = realloc(obj->maps, new_cap * sizeof(*obj->maps)); |
| 1294 | + new_maps = libbpf_reallocarray(obj->maps, new_cap, sizeof(*obj->maps)); |
1296 | 1295 | if (!new_maps) {
|
1297 | 1296 | pr_warn("alloc maps for object failed\n");
|
1298 | 1297 | return ERR_PTR(-ENOMEM);
|
@@ -2721,8 +2720,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
|
2721 | 2720 | continue;
|
2722 | 2721 | }
|
2723 | 2722 |
|
2724 |
| - sects = reallocarray(sects, nr_sects + 1, |
2725 |
| - sizeof(*obj->efile.reloc_sects)); |
| 2723 | + sects = libbpf_reallocarray(sects, nr_sects + 1, |
| 2724 | + sizeof(*obj->efile.reloc_sects)); |
2726 | 2725 | if (!sects) {
|
2727 | 2726 | pr_warn("reloc_sects realloc failed\n");
|
2728 | 2727 | return -ENOMEM;
|
@@ -2925,7 +2924,7 @@ static int bpf_object__collect_externs(struct bpf_object *obj)
|
2925 | 2924 | continue;
|
2926 | 2925 |
|
2927 | 2926 | ext = obj->externs;
|
2928 |
| - ext = reallocarray(ext, obj->nr_extern + 1, sizeof(*ext)); |
| 2927 | + ext = libbpf_reallocarray(ext, obj->nr_extern + 1, sizeof(*ext)); |
2929 | 2928 | if (!ext)
|
2930 | 2929 | return -ENOMEM;
|
2931 | 2930 | obj->externs = ext;
|
@@ -4362,9 +4361,9 @@ static struct ids_vec *bpf_core_find_cands(const struct btf *local_btf,
|
4362 | 4361 | pr_debug("CO-RE relocating [%d] %s %s: found target candidate [%d] %s %s\n",
|
4363 | 4362 | local_type_id, btf_kind_str(local_t),
|
4364 | 4363 | local_name, i, targ_kind, targ_name);
|
4365 |
| - new_ids = reallocarray(cand_ids->data, |
4366 |
| - cand_ids->len + 1, |
4367 |
| - sizeof(*cand_ids->data)); |
| 4364 | + new_ids = libbpf_reallocarray(cand_ids->data, |
| 4365 | + cand_ids->len + 1, |
| 4366 | + sizeof(*cand_ids->data)); |
4368 | 4367 | if (!new_ids) {
|
4369 | 4368 | err = -ENOMEM;
|
4370 | 4369 | goto err_out;
|
@@ -5231,7 +5230,7 @@ bpf_program__reloc_text(struct bpf_program *prog, struct bpf_object *obj,
|
5231 | 5230 | return -LIBBPF_ERRNO__RELOC;
|
5232 | 5231 | }
|
5233 | 5232 | new_cnt = prog->insns_cnt + text->insns_cnt;
|
5234 |
| - new_insn = reallocarray(prog->insns, new_cnt, sizeof(*insn)); |
| 5233 | + new_insn = libbpf_reallocarray(prog->insns, new_cnt, sizeof(*insn)); |
5235 | 5234 | if (!new_insn) {
|
5236 | 5235 | pr_warn("oom in prog realloc\n");
|
5237 | 5236 | return -ENOMEM;
|
@@ -5473,7 +5472,7 @@ static int bpf_object__collect_map_relos(struct bpf_object *obj,
|
5473 | 5472 | moff /= bpf_ptr_sz;
|
5474 | 5473 | if (moff >= map->init_slots_sz) {
|
5475 | 5474 | new_sz = moff + 1;
|
5476 |
| - tmp = realloc(map->init_slots, new_sz * host_ptr_sz); |
| 5475 | + tmp = libbpf_reallocarray(map->init_slots, new_sz, host_ptr_sz); |
5477 | 5476 | if (!tmp)
|
5478 | 5477 | return -ENOMEM;
|
5479 | 5478 | map->init_slots = tmp;
|
|
0 commit comments