BazisLib STLPort exception handling disabled

Sysprogs forums Forums Other tools & products BazisLib STLPort exception handling disabled

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #158
    airmax
    Participant

    BazisLib uses STLPort with exception handling disabled.
    What happens if map::insert fails to allocate memory?

    #1322
    support
    Keymaster

    If I remember correctly, a call to exit(), that is equivalent to KeBugCheck(). You need to patch STLPort to handle such cases correctly.

    #1323
    airmax
    Participant

    Yes, you correct.
    _alloc.h:

    #    define __THROW_BAD_ALLOC puts("out of memoryn"); exit(1)

    stlsup.cpp:

    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?

    #1324
    support
    Keymaster

    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.

    #1325
    airmax
    Participant

    @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.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.