Commit 3b029e06 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

libbpf: Rename internal memory-management helpers

Rename btf_add_mem() and btf_ensure_mem() helpers that abstract away details
of dynamically resizable memory to use libbpf_ prefix, as they are not
BTF-specific. No functional changes.
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210318194036.3521577-4-andrii@kernel.org
parent f36e99a4
...@@ -142,8 +142,8 @@ static inline __u64 ptr_to_u64(const void *ptr) ...@@ -142,8 +142,8 @@ static inline __u64 ptr_to_u64(const void *ptr)
* On success, memory pointer to the beginning of unused memory is returned. * On success, memory pointer to the beginning of unused memory is returned.
* On error, NULL is returned. * On error, NULL is returned.
*/ */
void *btf_add_mem(void **data, size_t *cap_cnt, size_t elem_sz, void *libbpf_add_mem(void **data, size_t *cap_cnt, size_t elem_sz,
size_t cur_cnt, size_t max_cnt, size_t add_cnt) size_t cur_cnt, size_t max_cnt, size_t add_cnt)
{ {
size_t new_cnt; size_t new_cnt;
void *new_data; void *new_data;
...@@ -179,14 +179,14 @@ void *btf_add_mem(void **data, size_t *cap_cnt, size_t elem_sz, ...@@ -179,14 +179,14 @@ void *btf_add_mem(void **data, size_t *cap_cnt, size_t elem_sz,
/* Ensure given dynamically allocated memory region has enough allocated space /* Ensure given dynamically allocated memory region has enough allocated space
* to accommodate *need_cnt* elements of size *elem_sz* bytes each * to accommodate *need_cnt* elements of size *elem_sz* bytes each
*/ */
int btf_ensure_mem(void **data, size_t *cap_cnt, size_t elem_sz, size_t need_cnt) int libbpf_ensure_mem(void **data, size_t *cap_cnt, size_t elem_sz, size_t need_cnt)
{ {
void *p; void *p;
if (need_cnt <= *cap_cnt) if (need_cnt <= *cap_cnt)
return 0; return 0;
p = btf_add_mem(data, cap_cnt, elem_sz, *cap_cnt, SIZE_MAX, need_cnt - *cap_cnt); p = libbpf_add_mem(data, cap_cnt, elem_sz, *cap_cnt, SIZE_MAX, need_cnt - *cap_cnt);
if (!p) if (!p)
return -ENOMEM; return -ENOMEM;
...@@ -197,8 +197,8 @@ static int btf_add_type_idx_entry(struct btf *btf, __u32 type_off) ...@@ -197,8 +197,8 @@ static int btf_add_type_idx_entry(struct btf *btf, __u32 type_off)
{ {
__u32 *p; __u32 *p;
p = btf_add_mem((void **)&btf->type_offs, &btf->type_offs_cap, sizeof(__u32), p = libbpf_add_mem((void **)&btf->type_offs, &btf->type_offs_cap, sizeof(__u32),
btf->nr_types, BTF_MAX_NR_TYPES, 1); btf->nr_types, BTF_MAX_NR_TYPES, 1);
if (!p) if (!p)
return -ENOMEM; return -ENOMEM;
...@@ -1586,8 +1586,8 @@ static int btf_ensure_modifiable(struct btf *btf) ...@@ -1586,8 +1586,8 @@ static int btf_ensure_modifiable(struct btf *btf)
static void *btf_add_str_mem(struct btf *btf, size_t add_sz) static void *btf_add_str_mem(struct btf *btf, size_t add_sz)
{ {
return btf_add_mem(&btf->strs_data, &btf->strs_data_cap, 1, return libbpf_add_mem(&btf->strs_data, &btf->strs_data_cap, 1,
btf->hdr->str_len, BTF_MAX_STR_OFFSET, add_sz); btf->hdr->str_len, BTF_MAX_STR_OFFSET, add_sz);
} }
/* Find an offset in BTF string section that corresponds to a given string *s*. /* Find an offset in BTF string section that corresponds to a given string *s*.
...@@ -1683,8 +1683,8 @@ int btf__add_str(struct btf *btf, const char *s) ...@@ -1683,8 +1683,8 @@ int btf__add_str(struct btf *btf, const char *s)
static void *btf_add_type_mem(struct btf *btf, size_t add_sz) static void *btf_add_type_mem(struct btf *btf, size_t add_sz)
{ {
return btf_add_mem(&btf->types_data, &btf->types_data_cap, 1, return libbpf_add_mem(&btf->types_data, &btf->types_data_cap, 1,
btf->hdr->type_len, UINT_MAX, add_sz); btf->hdr->type_len, UINT_MAX, add_sz);
} }
static __u32 btf_type_info(int kind, int vlen, int kflag) static __u32 btf_type_info(int kind, int vlen, int kflag)
...@@ -3208,7 +3208,7 @@ static int strs_dedup_remap_str_off(__u32 *str_off_ptr, void *ctx) ...@@ -3208,7 +3208,7 @@ static int strs_dedup_remap_str_off(__u32 *str_off_ptr, void *ctx)
len = strlen(s) + 1; len = strlen(s) + 1;
new_off = d->strs_len; new_off = d->strs_len;
p = btf_add_mem(&d->strs_data, &d->strs_cap, 1, new_off, BTF_MAX_STR_OFFSET, len); p = libbpf_add_mem(&d->strs_data, &d->strs_cap, 1, new_off, BTF_MAX_STR_OFFSET, len);
if (!p) if (!p)
return -ENOMEM; return -ENOMEM;
...@@ -3264,7 +3264,7 @@ static int btf_dedup_strings(struct btf_dedup *d) ...@@ -3264,7 +3264,7 @@ static int btf_dedup_strings(struct btf_dedup *d)
} }
if (!d->btf->base_btf) { if (!d->btf->base_btf) {
s = btf_add_mem(&d->strs_data, &d->strs_cap, 1, d->strs_len, BTF_MAX_STR_OFFSET, 1); s = libbpf_add_mem(&d->strs_data, &d->strs_cap, 1, d->strs_len, BTF_MAX_STR_OFFSET, 1);
if (!s) if (!s)
return -ENOMEM; return -ENOMEM;
/* initial empty string */ /* initial empty string */
......
...@@ -166,11 +166,11 @@ static int btf_dump_resize(struct btf_dump *d) ...@@ -166,11 +166,11 @@ static int btf_dump_resize(struct btf_dump *d)
if (last_id <= d->last_id) if (last_id <= d->last_id)
return 0; return 0;
if (btf_ensure_mem((void **)&d->type_states, &d->type_states_cap, if (libbpf_ensure_mem((void **)&d->type_states, &d->type_states_cap,
sizeof(*d->type_states), last_id + 1)) sizeof(*d->type_states), last_id + 1))
return -ENOMEM; return -ENOMEM;
if (btf_ensure_mem((void **)&d->cached_names, &d->cached_names_cap, if (libbpf_ensure_mem((void **)&d->cached_names, &d->cached_names_cap,
sizeof(*d->cached_names), last_id + 1)) sizeof(*d->cached_names), last_id + 1))
return -ENOMEM; return -ENOMEM;
if (d->last_id == 0) { if (d->last_id == 0) {
......
...@@ -4867,8 +4867,8 @@ static int load_module_btfs(struct bpf_object *obj) ...@@ -4867,8 +4867,8 @@ static int load_module_btfs(struct bpf_object *obj)
goto err_out; goto err_out;
} }
err = btf_ensure_mem((void **)&obj->btf_modules, &obj->btf_module_cap, err = libbpf_ensure_mem((void **)&obj->btf_modules, &obj->btf_module_cap,
sizeof(*obj->btf_modules), obj->btf_module_cnt + 1); sizeof(*obj->btf_modules), obj->btf_module_cnt + 1);
if (err) if (err)
goto err_out; goto err_out;
......
...@@ -112,9 +112,9 @@ struct btf_type; ...@@ -112,9 +112,9 @@ struct btf_type;
struct btf_type *btf_type_by_id(struct btf *btf, __u32 type_id); struct btf_type *btf_type_by_id(struct btf *btf, __u32 type_id);
void *btf_add_mem(void **data, size_t *cap_cnt, size_t elem_sz, void *libbpf_add_mem(void **data, size_t *cap_cnt, size_t elem_sz,
size_t cur_cnt, size_t max_cnt, size_t add_cnt); size_t cur_cnt, size_t max_cnt, size_t add_cnt);
int btf_ensure_mem(void **data, size_t *cap_cnt, size_t elem_sz, size_t need_cnt); int libbpf_ensure_mem(void **data, size_t *cap_cnt, size_t elem_sz, size_t need_cnt);
static inline bool libbpf_validate_opts(const char *opts, static inline bool libbpf_validate_opts(const char *opts,
size_t opts_sz, size_t user_sz, size_t opts_sz, size_t user_sz,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment