BazisLib STLPort exception handling disabled

BazisLib STLPort exception handling disabled

Postby airmax » Sun Feb 07, 2010 6:02 pm

BazisLib uses STLPort with exception handling disabled.
What happens if map::insert fails to allocate memory?
Last edited by airmax on Sun Feb 07, 2010 7:03 pm, edited 1 time in total.
airmax
 
Posts: 19
Joined: Thu Oct 01, 2009 9:13 pm

Re: BazisLib STLPort excetion handling disabled

Postby bazis » Sun Feb 07, 2010 6:07 pm

If I remember correctly, a call to exit(), that is equivalent to KeBugCheck(). You need to patch STLPort to handle such cases correctly.
bazis
Site Admin
 
Posts: 182
Joined: Sat Apr 04, 2009 10:15 pm

Re: BazisLib STLPort exception handling disabled

Postby airmax » Sun Feb 07, 2010 7:02 pm

Yes, you correct.
_alloc.h:
Code: Select all
#    define __THROW_BAD_ALLOC puts("out of memory\n"); exit(1)

stlsup.cpp:
Code: Select all
void _cdecl exit(int _Code)
{
   KeBugCheck(STATUS_INTERNAL_ERROR);
}


Also, i want to ask non BazisLib related question :)
I start using C++ and STLPort in NDIS driver, where most of calls on DISPATCH_LEVEL, so, memory must be allocated from NonPaged pool. When allocating memory from NonPaged pool frequently (for example, for packet modifying) chances to have out of memory are high.

Exception handling support will help in this case. Lets assume, that exceptions stack usage overhead isn't a problem.
What you think about this implementation http://code.google.com/p/ontl/source/browse/trunk/ntl/rtl/eh.cpp

Maybe another ideas?
airmax
 
Posts: 19
Joined: Thu Oct 01, 2009 9:13 pm

Re: BazisLib STLPort exception handling disabled

Postby bazis » Sun Feb 07, 2010 7:51 pm

Unfortunately, I don't have much time to look into details right now. However, I don't think that relying on undocumented _CxxThrowException(), that can be changed in future versions, is a good idea. Moreover, I don't explicitly see whether your example is compatible with x64.
I would suggest redefining __THROW_BAD_ALLOC using SEH. As SEH is already supported by WDK, that should not be a problem. We won't get a full equivalent of C++ exceptions, however, this particular problem (handle npagednew() for STL containers) will be solved smoothly.
bazis
Site Admin
 
Posts: 182
Joined: Sat Apr 04, 2009 10:15 pm

Re: BazisLib STLPort exception handling disabled

Postby airmax » Sun Feb 07, 2010 9:11 pm

bazis wrote:Unfortunately, I don't have much time to look into details right now. However, I don't think that relying on undocumented _CxxThrowException(), that can be changed in future versions, is a good idea.

Yes, but this is another question, lets assume this is not problem.

bazis wrote:Moreover, I don't explicitly see whether your example is compatible with x64.

Oh, i give incorrect link. Actual branch is x64. So, as i see from eh.cpp and ehsup.asm code, its will work on x64 too:
http://code.google.com/p/ontl/source/browse/branches/x64/ntl/rtl/eh.cpp
When you will have some time, plz have a look and tell your opinion.

bazis wrote:I would suggest redefining __THROW_BAD_ALLOC using SEH. As SEH is already supported by WDK, that should not be a problem. We won't get a full equivalent of C++ exceptions, however, this particular problem (handle npagednew() for STL containers) will be solved smoothly.

Thanks for suggestion! I like this idea too. Going to use it.
Also will research on EH implementation above. Support for local objects destruction very important, so RAII principles are not broken.
airmax
 
Posts: 19
Joined: Thu Oct 01, 2009 9:13 pm


Return to Programs & articles discussions

Who is online

Users browsing this forum: No registered users and 1 guest

cron