Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK well generally speaking exception handling is highly operating system dependent. I am going to make some assumptions and try to provide some generic guidance. Please know that this is by no means an exhaustive reply, but should serve as a place to start.</p> <p>I will assume that:</p> <ol> <li><p>For the most part, you are interested in safeguarding against memory leaks.</p></li> <li><p>You are not interested in Windows (which is whole-other-ball-of-wax) since you mentioned dlopen (you would have said LoadLibrary otherwise)</p></li> <li><p>That you are aware of the nuances of linking against C++ symbols. If you are not read up on it at <a href="http://www.isotton.com/devel/docs/C++-dlopen-mini-HOWTO/C++-dlopen-mini-HOWTO.html#id303308" rel="nofollow noreferrer">mini howto on dlopen c++</a></p></li> </ol> <p><strong>Generally speaking</strong></p> <p>There is no general solution to the described problem without involving specialized operating systems that provide data and code segment sand-boxing there are Trusted Systems and specialty operating system kernels that can do this, but i assume that you want to do this on a good old *nix or windows environment.</p> <p>Compiler stuff further complicates issues (does your C++ compiler generate weak symbols by default? typically it would) This affects how exception handling happens in a try-catch.</p> <p>Simple operating system exception handling that raises signals (SIGSEGV, SIGFPE etc.):</p> <p><strong>Under POSIX system supporting <em>sigaction</em>...</strong></p> <p>Let's say you want to protect against generic things like bad memory addressing. Trap the SIGSEG using sigaction before dlopening a library (to protect against .init functions) and then also do a signal check before calling a function within the library. Consider using SA_STACK to ensure that your handler jumps into a stack you have good control over, and SA_SIGINFO to ensure that your handler gets info about the source.</p> <p>A good place to start on this is at the <a href="http://www.gnu.org/s/libc/manual/html_node/Signal-Handling.html#Signal-Handling" rel="nofollow noreferrer">Signal handling on GNU libc manual</a></p> <p><strong>Under C++: use wrappers and with try-catch to catch soft exceptions</strong></p> <p>try { foo(); } catch() { // do something }</p> <p>where foo is a weak symbol pointing to a function in your dll <a href="http://www.isotton.com/devel/docs/C++-dlopen-mini-HOWTO/C++-dlopen-mini-HOWTO.html#id303308" rel="nofollow noreferrer">see c++ dlopen mini-howto for a lot more examples and details on loading classes etc.</a></p> <p>If you have more specific needs, post them, i'll see if i can provide more info.</p> <p>Cheers</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload