[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: dlopen(), atexit() SEGV in NetBSD
With respect to the above issue i have worked out one solution but
facing issue in accessing the variable
'atexit_handler_stack'. I have given the details below , please help
me out to solve this issue.
I have written one function atexit_remove() which is called from
__dlclose() of rtld, to unregister the
exit handlers in the user defined library i.e to resolve the Issue
posted in the mail link below:
For this i added the atexit_remove function in the file
'src/lib/libc/atexit.c' which will be called
from the file src/libexec/ld.elf_so/rtld.c' during the dlclose of the library.
$ cat src/libexec/ld.elf_so/rtld.c
atexit_remove (obj->mapbase, obj->textsize)
Basically this function takes the text segment of the library being
unmapped in dlclose and
scans for any exit handlers present.
This is done by looking into the exit handler stack
'atexit_handler_stack' in the file 'src/lib/libc/atexit.c'
In the atexit_remove function is written in libc in the file
When i access the stack pointer 'atexit_handler_stack' as given in
stack is always NULL.
struct atexit_handler *prevp;
prevp = atexit_handler_stack;
if ((prevp) == NULL) <---------------- Here its NULL
The flow is as given below
RTLD : rtld.c file
LIBC : atexit.c file
dlclose() --> atexit_remove(obj->mapbase,obj->textsize)
'atexit_handler_stack' to scan the exit handlers
I am not able to understand why 'atexit_handler_stack' is coming as NULL.
And in my test code i have registered exit handlers using atexit().
Could anyone help me in this regard?
Thanks & Regards,
2009/7/8 Byron Servies <bservies%pacang.com@localhost>:
> On Jul 8, 2009, at 2:03 AM, Channa wrote:
>> 2009/7/8 Thor Lancelot Simon <tls%panix.com@localhost>:
>>> On Wed, Jul 08, 2009 at 01:10:50PM +0530, Channa wrote:
>>>> I am facing some issue with atexit handler in NetBSD.
>>>> The procedure to reproduce the problem i have explained below:
>>>> 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.
>>> Well, of course it does. The documentation is quite clear:
>>> dlclose() unlinks and removes the object referred to by handle from
>>> process address space.
>> Yes but while calling fini functions in the dynamic linker , the
>> __cxa_finalize is called during that time the atexit() handlers
>> registered in the library can be called?
>> Or is there a method to unregister the atexit() handlers registered
>> while dlclose()?
> There is not.
> This is why it is normal to use some sort of session handle when designing
> libraries that can be loaded and unloaded instead of library-internal state
> that needs to be cleaned up with an exit handler. Something like:
> int mylib_open (void **handle, args);
> int mylib_close (void *handle);
> int mylib_funcA(void *handle, .args);
> and so on. It can easily be argued that this is a failing in libc (and I
> believe it is), but those arguments are pointless: it is the way things are
> on all unix-like OS's and does not appear to be changing any time soon.
Main Index |
Thread Index |