Commit 5511e760 authored by Henning Schild's avatar Henning Schild Committed by Philippe Gerum

boilerplate/setup: introduce destructors for __setup_call

Whit dlclose() we can actually invalidate the setup_list, it might end
up containing pointers to memory that got unmapped with dlclose(). The
next dlopen() will then cause a segfault.
Add destructors to that such referrences are remove from the setup_list
when calling dlclose().
The previous commit added a testcase that fails because of that issue,
with this commit the test runs fine.
Signed-off-by: Henning Schild's avatarHenning Schild <henning.schild@siemens.com>
parent c2d57c26
......@@ -78,10 +78,16 @@ struct setup_descriptor {
#define __early_ctor __attribute__ ((constructor(210)))
#define __bootstrap_ctor __attribute__ ((constructor(220)))
#define __setup_dtor __attribute__ ((destructor(200)))
#define __setup_call(__name, __id) \
static __setup_ctor void __declare_ ## __name(void) \
{ \
__register_setup_call(&(__name), __id); \
} \
static __setup_dtor void __undeclare_ ## __name(void) \
{ \
__unregister_setup_call(&(__name), __id); \
}
#define core_setup_call(__name) __setup_call(__name, 0)
......@@ -96,6 +102,7 @@ extern "C" {
#endif
void __register_setup_call(struct setup_descriptor *p, int id);
void __unregister_setup_call(struct setup_descriptor *p, int id);
extern pid_t __node_id;
......
......@@ -698,6 +698,12 @@ void __register_setup_call(struct setup_descriptor *p, int id)
pvlist_prepend(&p->__reserved.next, &setup_list);
}
void __unregister_setup_call(struct setup_descriptor *p, int id)
{
pvlist_remove(&p->__reserved.next);
}
const char *get_program_name(void)
{
return basename(__base_setup_data.arg0 ?: "program");
......
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