[PATCH v1 24/26] perf inject: Use generic hashmap for aslr top_addresses

From: Ian Rogers

Date: Fri Nov 13 2026 - 16:52:05 EST


Convert aslr_tool::top_addresses in util/aslr.c to
DECLARE_HASHMAP(top_addresses_map, struct top_addresses_key *,
struct process_top_address *).

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/aslr.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/aslr.c b/tools/perf/util/aslr.c
index 068e0250b151..f9c961775e1d 100644
--- a/tools/perf/util/aslr.c
+++ b/tools/perf/util/aslr.c
@@ -71,7 +71,10 @@ struct process_top_address {
u64 remapped_max;
};

+struct top_addresses_key;
+
DECLARE_HASHMAP(remap_addresses_map, struct remap_addresses_key *, u64 *);
+DECLARE_HASHMAP(top_addresses_map, struct top_addresses_key *, struct process_top_address *);

struct aslr_tool {
/** @tool: The tool implemented here and a pointer to a delegate to process the data. */
@@ -83,7 +86,7 @@ struct aslr_tool {
/** @remap_addresses: mapping from remap_addresses_key to remapped address. */
struct remap_addresses_map remap_addresses;
/** @top_addresses: mapping from process to max remapped address. */
- struct hashmap top_addresses;
+ struct top_addresses_map top_addresses;
/**
* @evsel_orig_attrs: mapping from evsel pointer to its original
* unstripped sample_type and registers bitmasks.
@@ -383,8 +386,7 @@ static u64 aslr_tool__findnew_mapping(struct aslr_tool *aslr,
} else {
*tk = top_addr_key;
top_val->remapped_max = remap_addr + len;
- err = hashmap__insert(&aslr->top_addresses, tk, top_val,
- HASHMAP_ADD, NULL, NULL);
+ err = hashmap__add(&aslr->top_addresses, tk, top_val);
}
if (err) {
errno = -err;
@@ -1337,6 +1339,8 @@ void aslr_tool__delete(struct perf_tool *tool)
struct aslr_tool *aslr;
struct remap_addresses_key *rkey;
u64 *rval;
+ struct top_addresses_key *tkey;
+ struct process_top_address *tval;
struct hashmap_entry *cur;
size_t bkt;
struct rb_node *nd;
@@ -1353,9 +1357,9 @@ void aslr_tool__delete(struct perf_tool *tool)
free(rkey);
free(rval);
}
- hashmap__for_each_entry(&aslr->top_addresses, cur, bkt) {
- zfree(&cur->pkey);
- zfree(&cur->pvalue);
+ hashmap__for_each(&aslr->top_addresses, tkey, tval) {
+ free(tkey);
+ free(tval);
}
hashmap__for_each_entry(&aslr->evsel_orig_attrs, cur, bkt) {
zfree(&cur->pvalue);
--
2.56.1.703.gf848ed807c-goog