[Mono-dev] Control-C handler

Jonathan Pryor jonpryor at vt.edu
Wed Jan 2 14:19:08 EST 2008

On Wed, 2008-01-02 at 13:08 -0500, Avery Pennarun wrote:
> How does Microsoft's .Net handle Windows-style "signals", such as
> memory-access errors?  Could we use a similar method in mono?

I'm not entirely sure, but I can guess intelligently. :-)

Win32 doesn't have signals either; instead, it uses Structured Exception
Handling (SEH) to report out-of-band error conditions such as invalid
memory access, etc.

.NET exceptions use SEH.

Consequently, I'll intelligently guess that .NET reports out-of-band
errors via exceptions, probably as a subclass of SEHException.

This obviously isn't an answer for Mono, as no Unix platform uses SEH
for anything, signals serving a similar (if less flexible) purpose.

That said, I think that there should be a way to use signals from C#.
Even if such use is severely limited -- e.g. only setting a volatile
variable within the signal handler -- signals are required for decent
integration with Unix platforms, so saying "don't use them" isn't an
adequate answer.  We need to have a well defined, supported, set of
things that signal handlers can do.

The alternative -- requiring that all signal handlers be written in C --
isn't as useful.  It would require that every Gnome Gtk# app (Tomboy,
Beagle, etc) have a C library to properly handle session ending (SIGTERM
followed by SIGKILL), which just sounds like severe overkill.

So why can't setting a volatile variable within a signal handler be
supported?  And/or use a Constrained Execution Region to *ensure* that
the signal handler is JITed before the signal is emitted (does mono even
support CERs yet?)?

 - Jon

More information about the Mono-devel-list mailing list