This change also adds the missing code for getting and restoring the thread's signal mask, since that's explicitly listed by the man page