Skip to content

Commit d1d6f5f

Browse files
authored
Revert "[fuzzer][Fuchsia] Prevent deadlock from suspending threads (#154854)"
This reverts commit b998750.
1 parent 4028896 commit d1d6f5f

File tree

2 files changed

+3
-61
lines changed

2 files changed

+3
-61
lines changed

compiler-rt/lib/fuzzer/FuzzerDriver.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,6 @@ static int RunInMultipleProcesses(const std::vector<std::string> &Args,
306306
return HasErrors ? 1 : 0;
307307
}
308308

309-
// Fuchsia needs to do some book checking before starting the RssThread,
310-
// so it has its own implementation.
311-
#if !LIBFUZZER_FUCHSIA
312309
static void RssThread(Fuzzer *F, size_t RssLimitMb) {
313310
while (true) {
314311
SleepSeconds(1);
@@ -324,7 +321,6 @@ static void StartRssThread(Fuzzer *F, size_t RssLimitMb) {
324321
std::thread T(RssThread, F, RssLimitMb);
325322
T.detach();
326323
}
327-
#endif
328324

329325
int RunOneTest(Fuzzer *F, const char *InputFilePath, size_t MaxLen) {
330326
Unit U = FileToVector(InputFilePath);

compiler-rt/lib/fuzzer/FuzzerUtilFuchsia.cpp

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ void ExitOnErr(zx_status_t Status, const char *Syscall) {
6868
}
6969

7070
void AlarmHandler(int Seconds) {
71-
// Signal the alarm thread started.
72-
ExitOnErr(_zx_object_signal(SignalHandlerEvent, 0, ZX_USER_SIGNAL_0),
73-
"_zx_object_signal alarm");
7471
while (true) {
7572
SleepSeconds(Seconds);
7673
Fuzzer::StaticAlarmCallback();
@@ -285,7 +282,6 @@ void CrashHandler() {
285282
Self, ZX_EXCEPTION_CHANNEL_DEBUGGER, &Channel.Handle),
286283
"_zx_task_create_exception_channel");
287284

288-
// Signal the crash thread started.
289285
ExitOnErr(_zx_object_signal(SignalHandlerEvent, 0, ZX_USER_SIGNAL_0),
290286
"_zx_object_signal");
291287

@@ -389,49 +385,10 @@ void StopSignalHandler() {
389385
_zx_handle_close(SignalHandlerEvent);
390386
}
391387

392-
void RssThread(Fuzzer *F, size_t RssLimitMb) {
393-
// Signal the rss thread started.
394-
//
395-
// We must wait for this thread to start because we could accidentally suspend
396-
// it while the crash handler is attempting to handle the
397-
// ZX_EXCP_THREAD_STARTING exception. If the crash handler is suspended by the
398-
// lsan machinery, then there's no way for this thread to indicate it's
399-
// suspended because it's blocked on waiting for the exception to be handled.
400-
ExitOnErr(_zx_object_signal(SignalHandlerEvent, 0, ZX_USER_SIGNAL_0),
401-
"_zx_object_signal rss");
402-
while (true) {
403-
SleepSeconds(1);
404-
size_t Peak = GetPeakRSSMb();
405-
if (Peak > RssLimitMb)
406-
F->RssLimitCallback();
407-
}
408-
}
409-
410388
} // namespace
411389

412-
void StartRssThread(Fuzzer *F, size_t RssLimitMb) {
413-
// Set up the crash handler and wait until it is ready before proceeding.
414-
assert(SignalHandlerEvent == ZX_HANDLE_INVALID);
415-
ExitOnErr(_zx_event_create(0, &SignalHandlerEvent), "_zx_event_create");
416-
417-
if (!RssLimitMb)
418-
return;
419-
std::thread T(RssThread, F, RssLimitMb);
420-
T.detach();
421-
422-
// Wait for the rss thread to start.
423-
ExitOnErr(_zx_object_wait_one(SignalHandlerEvent, ZX_USER_SIGNAL_0,
424-
ZX_TIME_INFINITE, nullptr),
425-
"_zx_object_wait_one rss");
426-
ExitOnErr(_zx_object_signal(SignalHandlerEvent, ZX_USER_SIGNAL_0, 0),
427-
"_zx_object_signal rss clear");
428-
}
429-
430390
// Platform specific functions.
431391
void SetSignalHandler(const FuzzingOptions &Options) {
432-
assert(SignalHandlerEvent != ZX_HANDLE_INVALID &&
433-
"This should've been setup by StartRssThread.");
434-
435392
// Make sure information from libFuzzer and the sanitizers are easy to
436393
// reassemble. `__sanitizer_log_write` has the added benefit of ensuring the
437394
// DSO map is always available for the symbolizer.
@@ -447,20 +404,6 @@ void SetSignalHandler(const FuzzingOptions &Options) {
447404
if (Options.HandleAlrm && Options.UnitTimeoutSec > 0) {
448405
std::thread T(AlarmHandler, Options.UnitTimeoutSec / 2 + 1);
449406
T.detach();
450-
451-
// Wait for the alarm thread to start.
452-
//
453-
// We must wait for this thread to start because we could accidentally
454-
// suspend it while the crash handler is attempting to handle the
455-
// ZX_EXCP_THREAD_STARTING exception. If the crash handler is suspended by
456-
// the lsan machinery, then there's no way for this thread to indicate it's
457-
// suspended because it's blocked on waiting for the exception to be
458-
// handled.
459-
ExitOnErr(_zx_object_wait_one(SignalHandlerEvent, ZX_USER_SIGNAL_0,
460-
ZX_TIME_INFINITE, nullptr),
461-
"_zx_object_wait_one alarm");
462-
ExitOnErr(_zx_object_signal(SignalHandlerEvent, ZX_USER_SIGNAL_0, 0),
463-
"_zx_object_signal alarm clear");
464407
}
465408

466409
// Options.HandleInt and Options.HandleTerm are not supported on Fuchsia
@@ -470,6 +413,9 @@ void SetSignalHandler(const FuzzingOptions &Options) {
470413
!Options.HandleFpe && !Options.HandleAbrt && !Options.HandleTrap)
471414
return;
472415

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+
473419
SignalHandler = std::thread(CrashHandler);
474420
zx_status_t Status = _zx_object_wait_one(SignalHandlerEvent, ZX_USER_SIGNAL_0,
475421
ZX_TIME_INFINITE, nullptr);

0 commit comments

Comments
 (0)