Platform specific functions.
| 389 | |
| 390 | // Platform specific functions. |
| 391 | void SetSignalHandler(const FuzzingOptions &Options) { |
| 392 | // Make sure information from libFuzzer and the sanitizers are easy to |
| 393 | // reassemble. `__sanitizer_log_write` has the added benefit of ensuring the |
| 394 | // DSO map is always available for the symbolizer. |
| 395 | // A uint64_t fits in 20 chars, so 64 is plenty. |
| 396 | char Buf[64]; |
| 397 | memset(Buf, 0, sizeof(Buf)); |
| 398 | snprintf(Buf, sizeof(Buf), "==%lu== INFO: libFuzzer starting.\n", GetPid()); |
| 399 | if (EF->__sanitizer_log_write) |
| 400 | __sanitizer_log_write(Buf, sizeof(Buf)); |
| 401 | Printf("%s", Buf); |
| 402 | |
| 403 | // Set up alarm handler if needed. |
| 404 | if (Options.HandleAlrm && Options.UnitTimeoutSec > 0) { |
| 405 | std::thread T(AlarmHandler, Options.UnitTimeoutSec / 2 + 1); |
| 406 | T.detach(); |
| 407 | } |
| 408 | |
| 409 | // Options.HandleInt and Options.HandleTerm are not supported on Fuchsia |
| 410 | |
| 411 | // Early exit if no crash handler needed. |
| 412 | if (!Options.HandleSegv && !Options.HandleBus && !Options.HandleIll && |
| 413 | !Options.HandleFpe && !Options.HandleAbrt) |
| 414 | return; |
| 415 | |
| 416 | // Set up the crash handler and wait until it is ready before proceeding. |
| 417 | ExitOnErr(_zx_event_create(0, &SignalHandlerEvent), "_zx_event_create"); |
| 418 | |
| 419 | SignalHandler = std::thread(CrashHandler); |
| 420 | zx_status_t Status = _zx_object_wait_one(SignalHandlerEvent, ZX_USER_SIGNAL_0, |
| 421 | ZX_TIME_INFINITE, nullptr); |
| 422 | ExitOnErr(Status, "_zx_object_wait_one"); |
| 423 | |
| 424 | std::atexit(StopSignalHandler); |
| 425 | } |
| 426 | |
| 427 | void SleepSeconds(int Seconds) { |
| 428 | _zx_nanosleep(_zx_deadline_after(ZX_SEC(Seconds))); |