Skip to content

Commit

Permalink
Update upstream source from tag 'upstream/1.2.2'
Browse files Browse the repository at this point in the history
Update to upstream version '1.2.2'
with Debian dir 658ca3a4ccd50ef16b8665625362ff5545cea7ce
  • Loading branch information
sudipm-mukherjee committed Aug 2, 2023
2 parents 0f6ec14 + 7a455d6 commit e65aca0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ endif

LIBBPF_MAJOR_VERSION := 1
LIBBPF_MINOR_VERSION := 2
LIBBPF_PATCH_VERSION := 0
LIBBPF_PATCH_VERSION := 2
LIBBPF_VERSION := $(LIBBPF_MAJOR_VERSION).$(LIBBPF_MINOR_VERSION).$(LIBBPF_PATCH_VERSION)
LIBBPF_MAJMIN_VERSION := $(LIBBPF_MAJOR_VERSION).$(LIBBPF_MINOR_VERSION).0
LIBBPF_MAP_VERSION := $(shell grep -oE '^LIBBPF_([0-9.]+)' libbpf.map | sort -rV | head -n1 | cut -d'_' -f2)
Expand Down
42 changes: 31 additions & 11 deletions src/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6133,7 +6133,11 @@ static int append_subprog_relos(struct bpf_program *main_prog, struct bpf_progra
if (main_prog == subprog)
return 0;
relos = libbpf_reallocarray(main_prog->reloc_desc, new_cnt, sizeof(*relos));
if (!relos)
/* if new count is zero, reallocarray can return a valid NULL result;
* in this case the previous pointer will be freed, so we *have to*
* reassign old pointer to the new value (even if it's NULL)
*/
if (!relos && new_cnt)
return -ENOMEM;
if (subprog->nr_reloc)
memcpy(relos + main_prog->nr_reloc, subprog->reloc_desc,
Expand Down Expand Up @@ -8501,7 +8505,8 @@ int bpf_program__set_insns(struct bpf_program *prog,
return -EBUSY;

insns = libbpf_reallocarray(prog->insns, new_insn_cnt, sizeof(*insns));
if (!insns) {
/* NULL is a valid return from reallocarray if the new count is zero */
if (!insns && new_insn_cnt) {
pr_warn("prog '%s': failed to realloc prog code\n", prog->name);
return -ENOMEM;
}
Expand Down Expand Up @@ -8531,13 +8536,31 @@ enum bpf_prog_type bpf_program__type(const struct bpf_program *prog)
return prog->type;
}

static size_t custom_sec_def_cnt;
static struct bpf_sec_def *custom_sec_defs;
static struct bpf_sec_def custom_fallback_def;
static bool has_custom_fallback_def;
static int last_custom_sec_def_handler_id;

int bpf_program__set_type(struct bpf_program *prog, enum bpf_prog_type type)
{
if (prog->obj->loaded)
return libbpf_err(-EBUSY);

/* if type is not changed, do nothing */
if (prog->type == type)
return 0;

prog->type = type;
prog->sec_def = NULL;

/* If a program type was changed, we need to reset associated SEC()
* handler, as it will be invalid now. The only exception is a generic
* fallback handler, which by definition is program type-agnostic and
* is a catch-all custom handler, optionally set by the application,
* so should be able to handle any type of BPF program.
*/
if (prog->sec_def != &custom_fallback_def)
prog->sec_def = NULL;
return 0;
}

Expand Down Expand Up @@ -8712,13 +8735,6 @@ static const struct bpf_sec_def section_defs[] = {
SEC_DEF("sk_lookup", SK_LOOKUP, BPF_SK_LOOKUP, SEC_ATTACHABLE),
};

static size_t custom_sec_def_cnt;
static struct bpf_sec_def *custom_sec_defs;
static struct bpf_sec_def custom_fallback_def;
static bool has_custom_fallback_def;

static int last_custom_sec_def_handler_id;

int libbpf_register_prog_handler(const char *sec,
enum bpf_prog_type prog_type,
enum bpf_attach_type exp_attach_type,
Expand Down Expand Up @@ -8798,7 +8814,11 @@ int libbpf_unregister_prog_handler(int handler_id)

/* try to shrink the array, but it's ok if we couldn't */
sec_defs = libbpf_reallocarray(custom_sec_defs, custom_sec_def_cnt, sizeof(*sec_defs));
if (sec_defs)
/* if new count is zero, reallocarray can return a valid NULL result;
* in this case the previous pointer will be freed, so we *have to*
* reassign old pointer to the new value (even if it's NULL)
*/
if (sec_defs || custom_sec_def_cnt == 0)
custom_sec_defs = sec_defs;

return 0;
Expand Down
5 changes: 4 additions & 1 deletion src/usdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,11 @@ static int bpf_link_usdt_detach(struct bpf_link *link)
* system is so exhausted on memory, it's the least of user's
* concerns, probably.
* So just do our best here to return those IDs to usdt_manager.
* Another edge case when we can legitimately get NULL is when
* new_cnt is zero, which can happen in some edge cases, so we
* need to be careful about that.
*/
if (new_free_ids) {
if (new_free_ids || new_cnt == 0) {
memcpy(new_free_ids + man->free_spec_cnt, usdt_link->spec_ids,
usdt_link->spec_cnt * sizeof(*usdt_link->spec_ids));
man->free_spec_ids = new_free_ids;
Expand Down

0 comments on commit e65aca0

Please sign in to comment.