NetBSD-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
dlopen(), atexit() SEGV in NetBSD
Hi,
I am facing some issue with atexit handler in NetBSD.
The procedure to reproduce the problem i have explained below:
Step 1.
======
Create example.so using the following code
$ cat example.c
#include <stdlib.h>
#include <stdio.h>
void exithandler(void) {
printf("now exiting\n");
}
void register_handler(void) {
printf("Inside register handler\n");
atexit(exithandler);
}
Step 2.
=======
Use the following test case to which dlopens the libexample.so
$ cat test.c
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
int main (void) {
void *dlhandle = NULL;
void (*handler) (void);
dlhandle = dlopen("./libexample.so", RTLD_LAZY);
if (!dlhandle) {
printf("cannot open module\n");
exit(1);
}
handler = dlsym(dlhandle, "register_handler");
if (!handler) {
printf("cannot locate function\n");
exit(1);
}
handler();
dlclose(dlhandle);
exit(0);
}
Step 3. Execute the test case
$ ./test
Inside register handler
Segmentation fault
As explained above the program gives SEGV.
Because after a dlopened library that calls atexit() the libexample.so
is dlclosed, an executable can't
access a registered handler in the library and causes SEGV.
The same issue is discussed in the FreeBSD mailing list link given below
http://lists.freebsd.org/pipermail/freebsd-hackers/2007-December/022763.html
Could any one help me in finding a solution for the above issue?
Awaiting for your reply.
Thanks & Regards,
Channa
Home |
Main Index |
Thread Index |
Old Index