> The following patch adds a Parrot_nosegfault() function
> to win32.c; after it is called, a segmentation fault will print
> "This process received a segmentation violation exception"
> instead of popping up a dialog. I think it might be useful
> for tinderbox clients.

Please notice, stdio is not signal/exception safe, you can not
use printf(), even sprintf() inside signal handler. On unix,
you have to write something like:

    write(2, msg, strlen(msg));

On win32, you have to write:
{
    DWORD dummy;
    WriteFile(GetStdHandle(STD_ERR_HANDLE), msg, strlen(msg), &dummy, NULL);
}

The reason for this is stdio uses mutex to protect internal buffers.
If the mutex is already acquired by someone, the printf will end up
deadlock. In some cases, it will just crash. The write() and WriteFile()
are system call. They are atomic on almost all systems, so it does not
need any lock in user space. On win32, the MSVCRT._open() is not atomic,
so it should not be used inside signal/exception handler too.

By the way, the SIGINT and SIGQUIT on win32 is running in its own thread,
so the restriction is less.

Hong

Reply via email to