Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e0695ebc authored by Ryan Mitchell's avatar Ryan Mitchell
Browse files

Revert "Extract info on LoadedPackage crash"

The issue has not been reproduced since the finalizer
synchronization changes were merged, so remove the signal handler and
the stopship.

Bug: 159041693
Test: boots
Change-Id: I43a590c70a397c5c7eabd0a891d008d4cbfe1f76
parent cfc8359f
Loading
Loading
Loading
Loading
+0 −65
Original line number Original line Diff line number Diff line
@@ -377,61 +377,8 @@ static jlong NativeLoadEmpty(JNIEnv* env, jclass /*clazz*/, jint flags, jobject
  return CreateGuardedApkAssets(std::move(apk_assets));
  return CreateGuardedApkAssets(std::move(apk_assets));
}
}


// STOPSHIP (b/159041693): Revert signal handler when reason for issue is found.
static thread_local std::stringstream destroy_info;
static struct sigaction old_handler_action;

static void DestroyErrorHandler(int sig, siginfo_t* info, void* ucontext) {
  if (sig != SIGSEGV) {
    return;
  }

  LOG(ERROR) << "(b/159041693) - Failed to destroy ApkAssets " << destroy_info.str();
  if (old_handler_action.sa_handler == SIG_DFL) {
      // reset the action to default and re-raise the signal. It will kill the process
      signal(sig, SIG_DFL);
      raise(sig);
      return;
  }
  if (old_handler_action.sa_handler == SIG_IGN) {
      // ignoring SIGBUS won't help us much, as we'll get back right here after retrying.
      return;
  }
  if (old_handler_action.sa_flags & SA_SIGINFO) {
      old_handler_action.sa_sigaction(sig, info, ucontext);
  } else {
      old_handler_action.sa_handler(sig);
  }
}

static void NativeDestroy(JNIEnv* /*env*/, jclass /*clazz*/, jlong ptr) {
static void NativeDestroy(JNIEnv* /*env*/, jclass /*clazz*/, jlong ptr) {
    {
        auto scoped_apk_assets = ScopedLock(ApkAssetsFromLong(ptr));
        auto apk_assets = scoped_apk_assets->get();
        destroy_info << "{ptr=" << apk_assets;
        if (apk_assets != nullptr) {
            destroy_info << ", name='" << apk_assets->GetDebugName() << "'"
                         << ", idmap=" << apk_assets->GetLoadedIdmap()
                         << ", {arsc=" << apk_assets->GetLoadedArsc();
            if (auto arsc = apk_assets->GetLoadedArsc()) {
                destroy_info << ", strings=" << arsc->GetStringPool()
                             << ", packages=" << &arsc->GetPackages() << " [";
                for (auto& package : arsc->GetPackages()) {
                    destroy_info << "{unique_ptr=" << &package << ", package=" << package.get()
                                 << "},";
                }
                destroy_info << "]";
            }
            destroy_info << "}";
        }
        destroy_info << "}";
    }

    DeleteGuardedApkAssets(ApkAssetsFromLong(ptr));
    DeleteGuardedApkAssets(ApkAssetsFromLong(ptr));

    // Deleting the apk assets did not lead to a crash.
    destroy_info.str("");
    destroy_info.clear();
}
}


static jstring NativeGetAssetPath(JNIEnv* env, jclass /*clazz*/, jlong ptr) {
static jstring NativeGetAssetPath(JNIEnv* env, jclass /*clazz*/, jlong ptr) {
@@ -591,18 +538,6 @@ int register_android_content_res_ApkAssets(JNIEnv* env) {


  jclass parcelFd = FindClassOrDie(env, "android/os/ParcelFileDescriptor");
  jclass parcelFd = FindClassOrDie(env, "android/os/ParcelFileDescriptor");
  gParcelFileDescriptorOffsets.detachFd = GetMethodIDOrDie(env, parcelFd, "detachFd", "()I");
  gParcelFileDescriptorOffsets.detachFd = GetMethodIDOrDie(env, parcelFd, "detachFd", "()I");

  // STOPSHIP (b/159041693): Revert signal handler when reason for issue is found.
  sigset_t allowed;
  sigemptyset(&allowed);
  sigaddset(&allowed, SIGSEGV);
  pthread_sigmask(SIG_UNBLOCK, &allowed, nullptr);
  struct sigaction action = {
          .sa_flags = SA_SIGINFO,
          .sa_sigaction = &DestroyErrorHandler,
  };
  sigaction(SIGSEGV, &action, &old_handler_action);

  return RegisterMethodsOrDie(env, "android/content/res/ApkAssets", gApkAssetsMethods,
  return RegisterMethodsOrDie(env, "android/content/res/ApkAssets", gApkAssetsMethods,
                              arraysize(gApkAssetsMethods));
                              arraysize(gApkAssetsMethods));
}
}