Index: lib/Fuzzer/FuzzerInternal.h =================================================================== --- lib/Fuzzer/FuzzerInternal.h +++ lib/Fuzzer/FuzzerInternal.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -125,7 +126,7 @@ int NumberOfCpuCores(); int GetPid(); -int SignalToMainThread(); +int SignalToMainThread(pthread_t MainThread); void SleepSeconds(int Seconds); class Random { @@ -458,6 +459,10 @@ // Maximum recorded coverage. Coverage MaxCoverage; + + // Used to allow other threads to communicate with + // the thread the fuzzer was created in. + pthread_t MainThread; }; }; // namespace fuzzer Index: lib/Fuzzer/FuzzerLoop.cpp =================================================================== --- lib/Fuzzer/FuzzerLoop.cpp +++ lib/Fuzzer/FuzzerLoop.cpp @@ -147,7 +147,7 @@ }; Fuzzer::Fuzzer(UserCallback CB, MutationDispatcher &MD, FuzzingOptions Options) - : CB(CB), MD(MD), Options(Options) { + : CB(CB), MD(MD), Options(Options), MainThread(pthread_self()) { SetDeathCallback(); InitializeTraceState(); assert(!F); @@ -258,9 +258,11 @@ void Fuzzer::RssLimitCallback() { InOOMState = true; - SignalToMainThread(); + if (SignalToMainThread(MainThread)) { + Printf("WARNING: Failed to signal main thread.\n"); + } SleepSeconds(5); - Printf("Signal to main thread failed (non-linux?). Exiting.\n"); + Printf("ERROR: Should have exited already. Forcing exit.\n"); _Exit(Options.ErrorExitCode); return; } Index: lib/Fuzzer/FuzzerUtil.cpp =================================================================== --- lib/Fuzzer/FuzzerUtil.cpp +++ lib/Fuzzer/FuzzerUtil.cpp @@ -248,12 +248,8 @@ } int GetPid() { return getpid(); } -int SignalToMainThread() { -#ifdef __linux__ - return syscall(SYS_tgkill, GetPid(), GetPid(), SIGALRM); -#else - return 0; -#endif +int SignalToMainThread(pthread_t MainThread) { + return pthread_kill(MainThread, SIGALRM); } std::string Base64(const Unit &U) {