aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2019-12-14 18:18:51 -0300
committerGitHub <noreply@github.com>2019-12-14 18:18:51 -0300
commite5858e2c7d0a46b771e874e37efb77f69120c141 (patch)
tree8d75505e2cfcd7021e617072e2cd1c24d15c295b
parentd925de2d0e7f3a065020c63dc1274644284e4006 (diff)
Add a limit for the number of instructions in a function (#843)
-rw-r--r--ARMeilleure/Decoders/Decoder.cs14
1 files changed, 14 insertions, 0 deletions
diff --git a/ARMeilleure/Decoders/Decoder.cs b/ARMeilleure/Decoders/Decoder.cs
index 2311e9e9..8eb2a99d 100644
--- a/ARMeilleure/Decoders/Decoder.cs
+++ b/ARMeilleure/Decoders/Decoder.cs
@@ -10,6 +10,11 @@ namespace ARMeilleure.Decoders
{
static class Decoder
{
+ // We define a limit on the number of instructions that a function may have,
+ // this prevents functions being potentially too large, which would
+ // take too long to compile and use too much memory.
+ private const int MaxInstsPerFunction = 5000;
+
private delegate object MakeOp(InstDescriptor inst, ulong address, int opCode);
private static ConcurrentDictionary<Type, MakeOp> _opActivators;
@@ -36,10 +41,17 @@ namespace ARMeilleure.Decoders
Dictionary<ulong, Block> visited = new Dictionary<ulong, Block>();
+ int opsCount = 0;
+
Block GetBlock(ulong blkAddress)
{
if (!visited.TryGetValue(blkAddress, out Block block))
{
+ if (opsCount > MaxInstsPerFunction)
+ {
+ return null;
+ }
+
block = new Block(blkAddress);
workQueue.Enqueue(block);
@@ -92,6 +104,8 @@ namespace ARMeilleure.Decoders
FillBlock(memory, mode, currBlock, limitAddress);
+ opsCount += currBlock.OpCodes.Count;
+
if (currBlock.OpCodes.Count != 0)
{
// Set child blocks. "Branch" is the block the branch instruction