Skip to content

Commit

Permalink
Explicit dep resolution for DirectorySoSources when BackupSoSource is…
Browse files Browse the repository at this point in the history
… enabled

Reviewed By: michalgr

Differential Revision: D60834153

fbshipit-source-id: 6e66db5da2c73e2d1241aedbde6dc056e5641fb8
  • Loading branch information
adicatana authored and facebook-github-bot committed Aug 7, 2024
1 parent 9496e4c commit 3c73566
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion java/com/facebook/soloader/DirectorySoSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class DirectorySoSource extends SoSource {
public static final int ON_LD_LIBRARY_PATH = 2;

protected final File soDirectory;
protected final int flags;
protected int flags;
protected final List<String> denyList;

/**
Expand All @@ -47,6 +47,10 @@ public DirectorySoSource(File soDirectory, int flags) {
this(soDirectory, flags, new String[0]);
}

public void setExplicitDependencyResolution() {
flags |= RESOLVE_DEPENDENCIES;
}

/**
* This method is similar to {@link #DirectorySoSource(File, int)}, with the following
* differences:
Expand Down
21 changes: 20 additions & 1 deletion java/com/facebook/soloader/recovery/ReunpackBackupSoSources.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.facebook.soloader.recovery;

import com.facebook.soloader.BackupSoSource;
import com.facebook.soloader.DirectorySoSource;
import com.facebook.soloader.LogUtil;
import com.facebook.soloader.SoLoader;
import com.facebook.soloader.SoLoaderDSONotFoundError;
Expand Down Expand Up @@ -100,6 +101,7 @@ private boolean recoverDSONotFoundError(SoSource[] soSources, String soName, int
}

private boolean lazyPrepareBackupSoSource(SoSource[] soSources, String soName) {
boolean recovered = false;
for (SoSource soSource : soSources) {
if (!(soSource instanceof BackupSoSource)) {
// NonApk SoSources get reunpacked in ReunpackNonBackupSoSource recovery strategy
Expand All @@ -111,7 +113,8 @@ private boolean lazyPrepareBackupSoSource(SoSource[] soSources, String soName) {
SoLoader.TAG,
"Preparing BackupSoSource for the first time " + backupSoSource.getName());
backupSoSource.prepare(0);
return true;
recovered = true;
break;
} catch (Exception e) {
// Catch a general error and log it, rather than failing during recovery and crashing the
// app
Expand All @@ -128,6 +131,22 @@ private boolean lazyPrepareBackupSoSource(SoSource[] soSources, String soName) {
}
}

if (recovered) {
for (SoSource soSource : soSources) {
if (!(soSource instanceof DirectorySoSource)) {
continue;
}
if (soSource instanceof BackupSoSource) {
continue;
}
DirectorySoSource directorySoSource = (DirectorySoSource) soSource;
// We need to explicitly resolve dependencies, as dlopen() cannot do
// so for dependencies at non-standard locations.
directorySoSource.setExplicitDependencyResolution();
}
return true;
}

return false;
}

Expand Down

0 comments on commit 3c73566

Please sign in to comment.