| 126 | static void CrashHandler(int) { Fuzzer::StaticCrashSignalCallback(); } |
| 127 | |
| 128 | void SetSignalHandler(const FuzzingOptions& Options) { |
| 129 | HandlerOpt = &Options; |
| 130 | |
| 131 | if (Options.HandleAlrm && Options.UnitTimeoutSec > 0) |
| 132 | Timer.SetTimer(Options.UnitTimeoutSec / 2 + 1); |
| 133 | |
| 134 | if (Options.HandleInt || Options.HandleTerm) |
| 135 | if (!SetConsoleCtrlHandler(CtrlHandler, TRUE)) { |
| 136 | DWORD LastError = GetLastError(); |
| 137 | Printf("libFuzzer: SetConsoleCtrlHandler failed (Error code: %lu).\n", |
| 138 | LastError); |
| 139 | exit(1); |
| 140 | } |
| 141 | |
| 142 | if (Options.HandleSegv || Options.HandleBus || Options.HandleIll || |
| 143 | Options.HandleFpe || Options.HandleWinExcept) |
| 144 | SetUnhandledExceptionFilter(ExceptionHandler); |
| 145 | |
| 146 | if (Options.HandleAbrt) |
| 147 | if (SIG_ERR == signal(SIGABRT, CrashHandler)) { |
| 148 | Printf("libFuzzer: signal failed with %d\n", errno); |
| 149 | exit(1); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | void SleepSeconds(int Seconds) { Sleep(Seconds * 1000); } |
| 154 | |