From 9515863355e3800c9369d13009f69ce6a10158c4 Mon Sep 17 00:00:00 2001
From: jdh8d <jdh8d@git.zephyr-software.com>
Date: Wed, 9 Aug 2017 15:16:56 +0000
Subject: [PATCH] Fix to properly build emt in build-all, but only once during
 fresh checkouts (as otherwise it's way too slow).  Re-release of broken
 package.  Fix to p1 to deal with doubling the size of huge stack frames (only
 does it above 32kb now).  Fix to VGT to mimic the input packages atd.class
 setting perfectly (omitted if omitted in the input package).  enabled polls
 for AWS.

Former-commit-id: 325eadd093e44d23538fd6a639ff187f80ee72d7
---
 tools/transforms/PNMain.cpp        | 9 +++++++++
 tools/transforms/PNStackLayout.cpp | 2 +-
 tools/transforms/globals.h         | 6 ++++++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/tools/transforms/PNMain.cpp b/tools/transforms/PNMain.cpp
index 0f095f97d..95ed2959c 100644
--- a/tools/transforms/PNMain.cpp
+++ b/tools/transforms/PNMain.cpp
@@ -71,6 +71,7 @@ enum
 	RECURSIVE_MIN_STACK_PAD_OPTION,
 	RECURSIVE_MAX_STACK_PAD_OPTION,
 	SHOULD_DOUBLE_FRAME_SIZE_OPTION,
+	DOUBLE_THRESHOLD_OPTION,
 	SELECTIVE_CANARIES_OPTION,
 	SET_RANDOM_SEED,
 	SET_CANARY_VALUE,
@@ -98,6 +99,7 @@ static struct option const long_options[] =
 	{"recursive_min_stack_padding",required_argument, NULL, RECURSIVE_MIN_STACK_PAD_OPTION},
 	{"recursive_max_stack_padding",required_argument, NULL, RECURSIVE_MAX_STACK_PAD_OPTION},
 	{"should_double_frame_size",required_argument, NULL, SHOULD_DOUBLE_FRAME_SIZE_OPTION},
+	{"double_threshold_size",required_argument, NULL, DOUBLE_THRESHOLD_OPTION,},
 	{"selective_canaries",required_argument, NULL, SELECTIVE_CANARIES_OPTION},
 	{"random_seed",required_argument, NULL, SET_RANDOM_SEED},
 	{"canary_value",required_argument, NULL, SET_CANARY_VALUE},
@@ -337,6 +339,13 @@ int main(int argc, char **argv)
 				pn_options->setRecursiveMaxStackPadding(recursive_max_stack_padding);
 			break;
 		}
+		case DOUBLE_THRESHOLD_OPTION:
+		{
+			const auto double_threshold = atoi(optarg);
+			pn_options->setDoubleThreshold(double_threshold);
+			break;	
+		}
+	
 		case SHOULD_DOUBLE_FRAME_SIZE_OPTION:
 		{
 			if(strcasecmp("true",optarg)==0)
diff --git a/tools/transforms/PNStackLayout.cpp b/tools/transforms/PNStackLayout.cpp
index 53390d49a..6ea04b836 100644
--- a/tools/transforms/PNStackLayout.cpp
+++ b/tools/transforms/PNStackLayout.cpp
@@ -85,7 +85,7 @@ unsigned int PNStackLayout::GetRandomPadding(unsigned int obj_size)
 
 
 
-	if(pn_options->getShouldDoubleFrameSize())
+	if(pn_options->getShouldDoubleFrameSize() && obj_size < pn_options->getDoubleThreshold())
 	{
 		//if the original frame size is not aligned, then add as many bytes as necessary to align it
 		//for example, if 3 bytes over alignment, and the alignment stride is 8, then add 8 - 3, or 5 bytes. 
diff --git a/tools/transforms/globals.h b/tools/transforms/globals.h
index 67292dadb..a43c585af 100644
--- a/tools/transforms/globals.h
+++ b/tools/transforms/globals.h
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <limits.h>
 
 
 
@@ -47,6 +48,7 @@ class PNOptions
 			random_seed=getpid();
 			canary_value=0;
 			canary_value_inited=false;
+			double_threshold=32*1024; // 32kb 
 		}
 
 		void setMinStackPadding(int val) { min_stack_padding = val; }
@@ -56,12 +58,14 @@ class PNOptions
 		void setShouldDoubleFrameSize(bool val) { should_double_frame_size = val; }
 		void setRandomSeed(int val) { random_seed = val; }
 		void setCanaryValue(int val) { canary_value = val; canary_value_inited=true; }
+		void setDoubleThreshold(int val) { double_threshold = val; }
 
 		int getMinStackPadding() const { return min_stack_padding; }
 		int getMaxStackPadding() const { return max_stack_padding; }
 		int getRecursiveMinStackPadding() const { return recursive_min_stack_padding; }
 		int getRecursiveMaxStackPadding() const { return recursive_max_stack_padding; }
 		bool getShouldDoubleFrameSize() const { return should_double_frame_size; }
+		int getDoubleThreshold() { return double_threshold; }
 		int getRandomSeed() { return random_seed; }
 		int getCanaryValue() 	
 		{ 
@@ -99,6 +103,8 @@ class PNOptions
 		int canary_value;
 		bool canary_value_inited;
 
+		int double_threshold;
+
 		std::set<std::string> canary_functions;
 };
 
-- 
GitLab