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

Commit c207ba65 authored by Ryan Mitchell's avatar Ryan Mitchell Committed by Automerger Merge Worker
Browse files

Merge "Revert "Extract info on LoadedPackage crash"" into sc-dev am: 66d9c07d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15142899

Change-Id: I8593fca10f42cf790c42f15ff2d9bc1f377ab5e0
parents 4e81740f 66d9c07d
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));
}
}