forked from PojavLauncherTeam/PojavLauncher
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
105 additions
and
1 deletion.
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
22 changes: 22 additions & 0 deletions
22
app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/memory/MemoryHoleFinder.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,22 @@ | ||
package net.kdt.pojavlaunch.memory; | ||
|
||
import net.kdt.pojavlaunch.Architecture; | ||
|
||
public class MemoryHoleFinder implements SelfMapsParser.Callback { | ||
private long mPreviousEnd = 0; | ||
private long mLargestHole = -1; | ||
private final long mAddressingLimit = Architecture.getAddressSpaceLimit(); | ||
@Override | ||
public boolean process(long begin, long end, String wholeLine) { | ||
if(begin >= mAddressingLimit) begin = mAddressingLimit; | ||
long holeSize = begin - mPreviousEnd; | ||
if(mLargestHole < holeSize) mLargestHole = holeSize; | ||
if(begin == mAddressingLimit) return false; | ||
mPreviousEnd = end; | ||
return true; | ||
} | ||
|
||
public long getLargestHole() { | ||
return mLargestHole; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/memory/SelfMapsParser.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,35 @@ | ||
package net.kdt.pojavlaunch.memory; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.Scanner; | ||
|
||
public class SelfMapsParser { | ||
private final Callback mCallback; | ||
public SelfMapsParser(Callback callback) { | ||
mCallback = callback; | ||
} | ||
|
||
public void run() throws IOException, NumberFormatException { | ||
try (FileInputStream fileInputStream = new FileInputStream("/proc/self/maps")) { | ||
Scanner scanner = new Scanner(fileInputStream); | ||
while(scanner.hasNextLine()) { | ||
if(!forEachLine(scanner.nextLine())) break; | ||
} | ||
} | ||
} | ||
|
||
private boolean forEachLine(String line) throws NumberFormatException { | ||
int firstSpaceIndex = line.indexOf(' '); | ||
String addresses = line.substring(0, firstSpaceIndex); | ||
String[] addressArray = addresses.split("-"); | ||
if(addressArray.length < 2) return true; | ||
long begin = Long.parseLong(addressArray[0], 16); | ||
long end = Long.parseLong(addressArray[1], 16); | ||
return mCallback.process(begin, end, line); | ||
} | ||
|
||
public interface Callback { | ||
boolean process(long startAddress, long endAddress, String wholeLine); | ||
} | ||
} |
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