Пример #1
0
  /**
   * Call this method just after loading all native shared libraries in this process. Note that when
   * in a service process, this will block until the RELRO bundle is received, i.e. when another
   * thread calls useSharedRelros().
   */
  public static void finishLibraryLoad() {
    if (DEBUG) Log.i(TAG, "finishLibraryLoad() called");
    synchronized (Linker.class) {
      if (DEBUG)
        Log.i(
            TAG,
            String.format(
                Locale.US,
                "sInBrowserProcess=%s sBrowserUsesSharedRelro=%s sWaitForSharedRelros=%s",
                sInBrowserProcess ? "true" : "false",
                sBrowserUsesSharedRelro ? "true" : "false",
                sWaitForSharedRelros ? "true" : "false"));

      if (sLoadedLibraries == null) {
        if (DEBUG) Log.i(TAG, "No libraries loaded");
      } else {
        if (sInBrowserProcess) {
          // Create new Bundle containing RELRO section information
          // for all loaded libraries. Make it available to getSharedRelros().
          sSharedRelros = createBundleFromLibInfoMap(sLoadedLibraries);
          if (DEBUG) {
            Log.i(TAG, "Shared RELRO created");
            dumpBundle(sSharedRelros);
          }

          if (sBrowserUsesSharedRelro) {
            useSharedRelrosLocked(sSharedRelros);
          }
        }

        if (sWaitForSharedRelros) {
          assert !sInBrowserProcess;

          // Wait until the shared relro bundle is received from useSharedRelros().
          while (sSharedRelros == null) {
            try {
              Linker.class.wait();
            } catch (InterruptedException ie) {
              // no-op
            }
          }
          useSharedRelrosLocked(sSharedRelros);
          // Clear the Bundle to ensure its file descriptor references can't be reused.
          sSharedRelros.clear();
          sSharedRelros = null;
        }
      }

      if (NativeLibraries.ENABLE_LINKER_TESTS && sTestRunnerClassName != null) {
        // The TestRunner implementation must be instantiated _after_
        // all libraries are loaded to ensure that its native methods
        // are properly registered.
        if (DEBUG) Log.i(TAG, "Instantiating " + sTestRunnerClassName);
        TestRunner testRunner = null;
        try {
          testRunner = (TestRunner) Class.forName(sTestRunnerClassName).newInstance();
        } catch (Exception e) {
          Log.e(TAG, "Could not extract test runner class name", e);
          testRunner = null;
        }
        if (testRunner != null) {
          if (!testRunner.runChecks(sMemoryDeviceConfig, sInBrowserProcess)) {
            Log.wtf(TAG, "Linker runtime tests failed in this process!!");
            assert false;
          } else {
            Log.i(TAG, "All linker tests passed!");
          }
        }
      }
    }
    if (DEBUG) Log.i(TAG, "finishLibraryLoad() exiting");
  }