Bug 1500805 Part 5 - Fix handling when creating threads after diverging from the recording, r=mccr8.
authorBrian Hackett <bhackett1024@gmail.com>
Sun, 21 Oct 2018 15:05:00 -0600
changeset 491290 22e55baef1fc05c63ad96694f1b8c5915fd16e0d
parent 491289 9f6bb5ca3b3718a2e074077210fc60c6f5b9d0e8
child 491291 0b8359215f5b0e02a2ee693615a34c218662e7df
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersmccr8
bugs1500805
milestone65.0a1
Bug 1500805 Part 5 - Fix handling when creating threads after diverging from the recording, r=mccr8.
toolkit/recordreplay/ProcessRedirectDarwin.cpp
toolkit/recordreplay/Thread.cpp
--- a/toolkit/recordreplay/ProcessRedirectDarwin.cpp
+++ b/toolkit/recordreplay/ProcessRedirectDarwin.cpp
@@ -147,17 +147,17 @@ namespace recordreplay {
   MACRO(csops, RR_SaveRvalHadErrorNegative<RR_WriteBuffer<2, 3>>) \
   MACRO(__getlogin, RR_SaveRvalHadErrorNegative<RR_WriteBuffer<0, 1>>) \
   MACRO(__workq_kernreturn, nullptr, Preamble___workq_kernreturn) \
   MACRO(start_wqthread, nullptr, Preamble_start_wqthread)        \
   /* pthreads interface functions */                             \
   MACRO(pthread_cond_wait, nullptr, Preamble_pthread_cond_wait)  \
   MACRO(pthread_cond_timedwait, nullptr, Preamble_pthread_cond_timedwait) \
   MACRO(pthread_cond_timedwait_relative_np, nullptr, Preamble_pthread_cond_timedwait_relative_np) \
-  MACRO(pthread_create, nullptr, Preamble_pthread_create, nullptr, Preamble_SetError) \
+  MACRO(pthread_create, nullptr, Preamble_pthread_create)        \
   MACRO(pthread_join, nullptr, Preamble_pthread_join)            \
   MACRO(pthread_mutex_init, nullptr, Preamble_pthread_mutex_init) \
   MACRO(pthread_mutex_destroy, nullptr, Preamble_pthread_mutex_destroy) \
   MACRO(pthread_mutex_lock, nullptr, Preamble_pthread_mutex_lock) \
   MACRO(pthread_mutex_trylock, nullptr, Preamble_pthread_mutex_trylock) \
   MACRO(pthread_mutex_unlock, nullptr, Preamble_pthread_mutex_unlock) \
   /* C Library functions */                                      \
   MACRO(dlclose, nullptr, Preamble_Veto<0>)                      \
@@ -1208,16 +1208,22 @@ Preamble_pthread_create(CallArguments* a
   auto& startArg = aArguments->Arg<3, void*>();
 
   int detachState;
   int rv = pthread_attr_getdetachstate(attr, &detachState);
   MOZ_RELEASE_ASSERT(rv == 0);
 
   *token = Thread::StartThread((Thread::Callback) start, startArg,
                                detachState == PTHREAD_CREATE_JOINABLE);
+  if (!*token) {
+    // Don't create new threads after diverging from the recording.
+    MOZ_RELEASE_ASSERT(HasDivergedFromRecording());
+    return Preamble_SetError(aArguments);
+  }
+
   aArguments->Rval<ssize_t>() = 0;
   return PreambleResult::Veto;
 }
 
 static PreambleResult
 Preamble_pthread_join(CallArguments* aArguments)
 {
   if (AreThreadEventsPassedThrough()) {
--- a/toolkit/recordreplay/Thread.cpp
+++ b/toolkit/recordreplay/Thread.cpp
@@ -232,18 +232,17 @@ Thread::SpawnThread(Thread* aThread)
 }
 
 /* static */ NativeThreadId
 Thread::StartThread(Callback aStart, void* aArgument, bool aNeedsJoin)
 {
   Thread* thread = Thread::Current();
   RecordingEventSection res(thread);
   if (!res.CanAccessEvents()) {
-    EnsureNotDivergedFromRecording();
-    Unreachable();
+    return 0;
   }
 
   MonitorAutoLock lock(*gMonitor);
 
   size_t id = 0;
   if (IsRecording()) {
     // Look for an idle thread.
     for (id = MainThreadId + 1; id <= MaxRecordedThreadId; id++) {