c++ - Is there anyway I can prevent throw from calling malloc -


background

in c++ program have sigalrm handler in want convert signal exception doing throw (i understand in general not practice, in system working on it's option). problem here sigalrm handler invoked when doing malloc, while throw call __cxa_allocate_exception malloc. 2 malloc calls can hit deadlock in glibc 2.12. tried pre-allocating exception, call __cxa_allocate_exception still happened. checked source code of gcc , there doesn't seem condition of putting __cxa_allocate_exception call.

additional background

i install signal handler right before try block , uninstall after catch. i'm throwing signal handler , way think inside try block (let's not consider case signal received when in catch logic) , can caught correctly.

i think i'm hitting malloc deadlock described here: https://sourceware.org/bugzilla/show_bug.cgi?id=13699 , here https://sourceware.org/ml/libc-alpha/2012-02/msg00272.html .

question

my question is: there anyway can prevent throw calling malloc? (also, understand can block sigalrm signal when i'm doing malloc, i'm afraid there many places block).

thanks in advance. help/reference high appreciated.

the general problem if signal handler called while in async-unsafe library function (such malloc or printf), jumping out of signal handler (via longjmp or exception) leave glibc in inconsistent state, crash or otherwise misbehave next time call anything.

so if able avoid call malloc in exception setup, , throw exception , catch , handle it, program stiil crash next time called malloc afterwards.

the way avoid ensure signal handler cannot called while in async-unsafe library function. can using sigblock block , unblock signal around every call signal-unsafe function anywhere in program:

oldmask = sigblock(sigalrm); ...call malloc or printf or whatever... setsetmask(oldmask); 

this possible, not terribly practical.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -