[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::digital_unix

Title:DIGITAL UNIX(FORMERLY KNOWN AS DEC OSF/1)
Notice:Welcome to the Digital UNIX Conference
Moderator:SMURF::DENHAM
Created:Thu Mar 16 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:10068
Total number of notes:35879

8856.0. "When exception system gets ready?" by CADSYS::BOGDANOV () Mon Feb 17 1997 16:12

Hi,
	I'm trying to alter malloc routine. One thing it should do is gathering
info about call stack. I tried to use exc_capture_context(&ctx) and program died
at initialization time with

exception system: exiting dues to multiple internal errors:
        handler returned invalid disposition
        handler returned invalid disposition

I do not need context of calls from exception system. But how do I check if it
is initialized so that I can start doing a job?

>> Serge

T.RTitleUserPersonal
Name
DateLines
8856.1QUARRY::nethCraig NethMon Feb 17 1997 17:0720
I'm not sure I understand the question, but that's never stopped me before...
:-)

That error message is returned when the unwinder cannot find a code range
descriptor (crd) that describes the current pc.   

The code range descriptor lists are built using the __exc_add_pc_range_table()
routine.  That routine is called (indirectly) from a .init routine written
by the linker.   The linker adds that routine only if it sees that the
image needs exception handling - which will be true if the image is
a shareable object, or a -call_shared object, or if the non-shared 
executable includes a reference to the _FPDATA_SIZE special symbol.
crt0.s (__start) is what calls the init routines.

So, if you have an alternate crt0.s, or you are somehow inhibiting the
creation of the .init routines in the linker, or if you are adding code
on the fly and not calling the __exc_add_pc_range_table() routine, you 
can get that error...

Does that answer the question?    
8856.2The classic chicken and egg problem (gotta love malloc()!)WTFN::SCALESDespair is appropriate and inevitable.Mon Feb 17 1997 17:124
Any chance that __exc_add_pc_range_table() needs to call malloc()?  If so, then
the first call to exc_capture_context() would be issued before the first call to
__exc_add_pc_range_table() returned, in which case there would be no PC range
enclosing the current PC, and that error would result...
8856.3CADSYS::BOGDANOVMon Feb 17 1997 17:2712
>Any chance that __exc_add_pc_range_table() needs to call malloc()?  If so, then
>the first call to exc_capture_context() would be issued before the first call to
>__exc_add_pc_range_table() returned, in which case there would be no PC range
>enclosing the current PC, and that error would result...


The behavior which I see can be explained by the above message. I see at leas 7
mallocs befor the exc_capture_context() rtn can be called cleanly. How can one
figure out that __exc_add_pc_range_table() has been already called and code range
descriptor lists were built? Or should I call it myself?

>> Serge
8856.4QUARRY::nethCraig NethMon Feb 17 1997 17:403
>Any chance that __exc_add_pc_range_table() needs to call malloc()?

Duh.  Yes, it does.  I think Webb has hit the nail on the head. 
8856.5???CADSYS::BOGDANOVTue Feb 18 1997 09:471
So, how to solve the problem? Any documentation (man pages are not suficient)?
8856.6QUARRY::nethCraig NethTue Feb 18 1997 10:2916
The problem is that there aren't any 'hooks' in the exception system
that indicate it is 'ready to go' - it's an open ended process.   Things
can be added (and removed) at any time.  (for instance, dlopen() will cause
more calls to add_pc_range() for the text in the dlopen'ed library). 

I don't believe there is any general solution to this issue.   If you
'know' in some way that all of the code that your application is present,
then you could set a flag at that point.   (For instance, at the time
main() is called from __start, all of the libraries specified in the static
list (and their dependencies) will have been loaded and their init routines
run - if you application does not call dlopen() then you can be assured at
this point that any calls to your malloc can safely query the exception system.)

Does this help?


8856.7CADSYS::BOGDANOVTue Feb 18 1997 11:287
Thank you for the reply.

> Does this help?

Unfortunately it cannot solve all related problems. I'll try to figure out
something else.
8856.8You just have to detect -recursive- calls.WTFN::SCALESDespair is appropriate and inevitable.Tue Feb 18 1997 14:4211
Actually, I think (but my head is fuzzy) that all you need to do is catch
-recursive- calls to malloc().  (This is easier to do if you don't care about
threads, but you can also make it work for threads with thread-specific
data.)  So, if you get a recursive call to malloc() -- i.e., a call to
malloc() while you're in the process of generating a stack track for a
previous call -- skip over generating the trace of the recursive call.
You'll loose some calls this way, but you could note them, and I don't see
that you have much other choice.


					Webb
8856.9libexc sources?CADSYS::BOGDANOVTue Feb 18 1997 16:164
I think that it works in an opposit direction. There are no recurcive calls to
malloc. The exc_... is probably used recurcively but I cannot catch that. 

I need to create my own version of libexc. Can I get sources for libexc anywhere?
8856.10QUARRY::nethCraig NethTue Feb 18 1997 16:475
>I need to create my own version of libexc. Can I get sources for libexc 
>anywhere?

If you get a source kit, you should be able to, after some fiddling.   I'm
not sure how to get one - maybe someone else will pipe in...
8856.11COL01::LINNARTZTue Feb 18 1997 16:5325
    I've deleted my previous answer, as it wasn't (as always) totally
    correct.
    first, i wouldn't use your way unless you've got a specific reason.
    gathering data about the alloc family is a quite simple tasks 
    with ATOM. There was also some sample code about stackframes,
    at least in th eearly atom kits (i think it was called paltrace)
    on the other hand, if you want it, and you are just looking for
    a flag/var telling you the needed application initialization 
    I would append my only shared library as the last library on the
    link line, and set the flag in the libs __init routine. Due to th erules
    depicted in the programmers guide (section 4.2.3 if I remember right)
    the _init routines are called from left to right. so your lib is called
    last, but still before main gets invoked. (at least should be, I
    haven't tried to call exc routines out of the init routines, but its
    definitly before main).
    
    if you are interested in the loader activities,before your program
    is actual started, play around with _RLD_ARGS -debug option, but 
    that's only due to the malloc invocatons mentioned some replies 
    before. you won't see them all, but sometimes this option helped
    me debugging.
    
    good luck
     Pit