Catching a hot potato

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Sun Oct 16 21:54:31 PDT 2011


If the user tries to read unallocated memory, the memory can't
possibly get corrupted, since nothing is getting changed.
If the user tried to write to unallocated memory, the segfault should
_prevent_ it by throwing an OS-level exception (the sigsegv). Throwing
if _after_ the invalid write makes no sense. You can't save anything,
because your own data is not touched. Depending on the implementation,
either some other process's memory would be touched or nothing at all
(internally unmapped region).
I think the rumors of corrupted memory after sigsegv is boloney.
Otherwise the whole sigsegv idea is pointless (you could just as well
get terminated right away).

On Sun, Oct 16, 2011 at 8:49 PM, Norbert Nemec <Norbert at nemec-online.de> wrote:
> In fact, I have been wondering about the very same issue. Indeed, it seems
> to be possible to catch SIGSEGV in userspace, there even is a library for
> this
>
>        http://libsigsegv.sourceforge.net/
>
> I have never used it myself, but it would certainly be interesting to hear
> about any experience you might make.
>
> It is often argued that after a segfault the memory may be corrupt any you
> can't trust anything. True - after a fatal error, it is advisable to quit
> the program as soon as possible. However, in most cases, it should be
> possible to display a meaningful message, blame the most likely villain or
> maybe even try an emergency save.
>
>
>
> On 15.10.2011 14:18, Gor Gyolchanyan wrote:
>>
>> Thanks for the detailed answer.
>> Example of when i would like to recover from a segfault:
>> I have different independent parts of an app, which MAY cooperate. If,
>> however, one of them crashes (e.g. they come from different sources)
>> the other one will continue to work but without the cooperation
>> functionality.
>


More information about the Digitalmars-d mailing list