-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Recover from unpacked DSOs not found on disk
Reviewed By: simpleton Differential Revision: D61873053 fbshipit-source-id: e337d15104ec6cd77f3dfdbe5ae45c266bac23de
- Loading branch information
1 parent
217b0f5
commit 83be14a
Showing
8 changed files
with
202 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
java/com/facebook/soloader/recovery/CheckOnDiskStateDataApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.facebook.soloader.recovery; | ||
|
||
import android.content.Context; | ||
import com.facebook.soloader.BackupSoSource; | ||
import com.facebook.soloader.DirectorySoSource; | ||
import com.facebook.soloader.LogUtil; | ||
import com.facebook.soloader.SoLoader; | ||
import com.facebook.soloader.SoLoaderULError; | ||
import com.facebook.soloader.SoSource; | ||
import com.facebook.soloader.UnpackingSoSource.Dso; | ||
import java.io.File; | ||
import java.util.ArrayList; | ||
|
||
public class CheckOnDiskStateDataApp implements RecoveryStrategy { | ||
|
||
private final Context mContext; | ||
|
||
public CheckOnDiskStateDataApp(Context context) { | ||
mContext = context; | ||
} | ||
|
||
@Override | ||
public boolean recover(UnsatisfiedLinkError error, SoSource[] soSources) { | ||
if (!(error instanceof SoLoaderULError)) { | ||
// Only recover from SoLoaderULE errors | ||
return false; | ||
} | ||
|
||
LogUtil.e(SoLoader.TAG, "Checking /data/app missing libraries."); | ||
|
||
File nativeLibStandardDir = new File(mContext.getApplicationInfo().nativeLibraryDir); | ||
if (!nativeLibStandardDir.exists()) { | ||
LogUtil.e( | ||
SoLoader.TAG, | ||
"Native library directory " | ||
+ nativeLibStandardDir | ||
+ " does not exist, exiting /data/app recovery."); | ||
return false; | ||
} | ||
|
||
ArrayList<String> missingLibs = new ArrayList<>(); | ||
for (SoSource soSource : soSources) { | ||
if (!(soSource instanceof BackupSoSource)) { | ||
continue; | ||
} | ||
BackupSoSource uss = (BackupSoSource) soSource; | ||
try { | ||
Dso[] dsosFromArchive = uss.getDsosBaseApk(); | ||
for (Dso dso : dsosFromArchive) { | ||
File soFile = new File(nativeLibStandardDir, dso.name); | ||
if (soFile.exists()) { | ||
continue; | ||
} | ||
missingLibs.add(dso.name); | ||
} | ||
|
||
if (missingLibs.isEmpty()) { | ||
LogUtil.e(SoLoader.TAG, "No libraries missing from " + nativeLibStandardDir); | ||
return false; | ||
} | ||
|
||
LogUtil.e( | ||
SoLoader.TAG, | ||
"Missing libraries from " | ||
+ nativeLibStandardDir | ||
+ ": " | ||
+ missingLibs.toString() | ||
+ ", will run prepare on tbe backup so source"); | ||
uss.prepare(0); | ||
break; | ||
} catch (Exception e) { | ||
LogUtil.e( | ||
SoLoader.TAG, "Encountered an exception while recovering from /data/app failure ", e); | ||
return false; | ||
} | ||
} | ||
|
||
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(); | ||
} | ||
|
||
LogUtil.e(SoLoader.TAG, "Successfully recovered from /data/app disk failure."); | ||
return true; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
java/com/facebook/soloader/recovery/CheckOnDiskStateDataData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.facebook.soloader.recovery; | ||
|
||
import com.facebook.soloader.BackupSoSource; | ||
import com.facebook.soloader.LogUtil; | ||
import com.facebook.soloader.SoLoader; | ||
import com.facebook.soloader.SoLoaderULError; | ||
import com.facebook.soloader.SoSource; | ||
import com.facebook.soloader.UnpackingSoSource; | ||
import com.facebook.soloader.UnpackingSoSource.Dso; | ||
|
||
public class CheckOnDiskStateDataData implements RecoveryStrategy { | ||
@Override | ||
public boolean recover(UnsatisfiedLinkError error, SoSource[] soSources) { | ||
if (!(error instanceof SoLoaderULError)) { | ||
// Only recover from SoLoaderULE errors | ||
return false; | ||
} | ||
|
||
LogUtil.e(SoLoader.TAG, "Checking /data/data missing libraries."); | ||
|
||
boolean recovered = false; | ||
for (SoSource soSource : soSources) { | ||
if (!(soSource instanceof UnpackingSoSource)) { | ||
continue; | ||
} | ||
if (soSource instanceof BackupSoSource) { | ||
continue; | ||
} | ||
UnpackingSoSource uss = (UnpackingSoSource) soSource; | ||
try { | ||
Dso[] dsosFromArchive = uss.getDsosBaseApk(); | ||
for (Dso dso : dsosFromArchive) { | ||
if (uss.getSoFileByName(dso.name) == null) { | ||
LogUtil.e( | ||
SoLoader.TAG, | ||
"Missing " + dso.name + " from " + uss.getName() + ", will force prepare."); | ||
uss.prepare(SoSource.PREPARE_FLAG_FORCE_REFRESH); | ||
recovered = true; | ||
break; | ||
} | ||
} | ||
} catch (Exception e) { | ||
LogUtil.e( | ||
SoLoader.TAG, "Encountered an exception while recovering from /data/data failure ", e); | ||
return false; | ||
} | ||
} | ||
|
||
if (recovered) { | ||
LogUtil.e(SoLoader.TAG, "Successfully recovered from /data/data disk failure."); | ||
return true; | ||
} | ||
|
||
LogUtil.e( | ||
SoLoader.TAG, | ||
"No libraries missing from unpacking so paths while recovering /data/data failure"); | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters