This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Calls to malloc during an exception


> 
> On Wed, Jan 18, 2006 at 11:41:39AM -0600, Perry Smith wrote:
> > In the course of doing my work last week to get exception handling  
> > working in my device driver, I learned that the exception processing  
> > code calls malloc during the exception.  This seems weak to me.  It  
> > seems like one of the most critical times to throw an exception is  
> > when malloc fails.
> > 
> > I did not study the code very much to see what happens if the malloc  
> > fails during the exception processing but I assume its not good.
> > 
> > It seems like a better approach would be to pre-allocate storage and  
> > use it during the exception handling.  The design objective, to me,  
> > would be to make the exception handling as bullet proof as possible.   
> > I understand that it is not known how many exceptions are going to  
> > stack up but I think taking a reasonable guess, pre-allocating that  
> > space, and then fall back to malloc when that space fills up would be  
> > much less likely to fail during a critical time.
> > 
> > Has this been considered?
> 
> It is a major flaw in the gcc exception handling. I'd like to see it
> get fixed.

I actually don't think it is that major, it has worked this way for
more than 5 years and this is the first time someone wrote about it.

Also when I looked into fixing it, it was a major issue to fix as it allocates
more than one buffer and also there is no guessing how many frames there are
and if you guess wrong, you would need to allocate more.

Also exceptions in a device driver seems like a very bad idea as it might
mean you crash the kernel if you don't handle the exception correctly.
The plain old setjmp/longjmp seems like a better idea anyways as at least
there you know a litle more information about where you are catching the
jump.

-- Pinski


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]