From 35845e7e41872158e4ce9a33f04709f66194fe7b Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Tue, 6 Jul 2021 15:02:09 -0300 Subject: [PATCH] core: Provide a way to store per loader info in cus and an exit function So that loaders such as the DWARF one can store there the DWARF handler (Dwfl) that needs to stay live while tools use the core tags (struct class, struct union, struct tag, etc) because they point to strings that are managed by Dwfl, so we have to defer dwfl_end() to after tools are done processing the core tags. Signed-off-by: Arnaldo Carvalho de Melo --- dwarves.c | 24 +++++++++++++++++++++++- dwarves.h | 5 +++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/dwarves.c b/dwarves.c index 9417b13..58b4c59 100644 --- a/dwarves.c +++ b/dwarves.c @@ -393,6 +393,8 @@ struct cus { uint32_t nr_entries; struct list_head cus; pthread_mutex_t mutex; + void (*loader_exit)(struct cus *cus); + void *priv; // Used in dwarf_loader__exit() }; void cus__lock(struct cus *cus) @@ -2349,7 +2351,9 @@ struct cus *cus__new(void) struct cus *cus = malloc(sizeof(*cus)); if (cus != NULL) { - cus->nr_entries = 0; + cus->nr_entries = 0; + cus->priv = NULL; + cus->loader_exit = NULL; INIT_LIST_HEAD(&cus->cus); pthread_mutex_init(&cus->mutex, NULL); } @@ -2371,11 +2375,29 @@ void cus__delete(struct cus *cus) cu__delete(pos); } + if (cus->loader_exit) + cus->loader_exit(cus); + cus__unlock(cus); free(cus); } +void cus__set_priv(struct cus *cus, void *priv) +{ + cus->priv = priv; +} + +void *cus__priv(struct cus *cus) +{ + return cus->priv; +} + +void cus__set_loader_exit(struct cus *cus, void (*loader_exit)(struct cus *cus)) +{ + cus->loader_exit = loader_exit; +} + void dwarves__fprintf_init(uint16_t user_cacheline_size); int dwarves__init(uint16_t user_cacheline_size) diff --git a/dwarves.h b/dwarves.h index dde153f..257d7e8 100644 --- a/dwarves.h +++ b/dwarves.h @@ -148,6 +148,11 @@ uint32_t cus__nr_entries(const struct cus *cus); void cus__lock(struct cus *cus); void cus__unlock(struct cus *cus); +void *cus__priv(struct cus *cus); +void cus__set_priv(struct cus *cus, void *priv); + +void cus__set_loader_exit(struct cus *cus, void (*loader_exit)(struct cus *cus)); + struct ptr_table { void **entries; uint32_t nr_entries;