diff --git a/tools/transforms/PNMain.cpp b/tools/transforms/PNMain.cpp index d96b93df1cb570336fddafcc0c067c532168d273..5ec4f217673e6e1610e8f82f0f425ee282b658fa 100644 --- a/tools/transforms/PNMain.cpp +++ b/tools/transforms/PNMain.cpp @@ -69,7 +69,8 @@ enum MIN_STACK_PAD_OPTION, MAX_STACK_PAD_OPTION, RECURSIVE_MIN_STACK_PAD_OPTION, - RECURSIVE_MAX_STACK_PAD_OPTION + RECURSIVE_MAX_STACK_PAD_OPTION, + SHOULD_DOUBLE_FRAME_SIZE_OPTION }; @@ -92,6 +93,7 @@ static struct option const long_options[] = {"max_stack_padding",required_argument, NULL, MAX_STACK_PAD_OPTION}, {"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}, {NULL, 0, NULL, 0} }; @@ -326,6 +328,20 @@ int main(int argc, char **argv) pn_options->setRecursiveMaxStackPadding(recursive_max_stack_padding); break; } + case SHOULD_DOUBLE_FRAME_SIZE_OPTION: + { + if(strcasecmp("true",optarg)==0) + pn_options->setShouldDoubleFrameSize(true); + else if(strcasecmp("false",optarg)==0) + pn_options->setShouldDoubleFrameSize(false); + else + { + cout<<"Error: should_double_frame_size option needs to be 'true' or 'false': found "<<optarg<<endl; + usage(); + exit(1); + } + break; + } case '?': { //error message already printed by getopt_long diff --git a/tools/transforms/PNStackLayout.cpp b/tools/transforms/PNStackLayout.cpp index f94963482e3d61b58e8bcd843ab7ca5411cb57d9..98cd8afe29b08017824928202d8b2b8d2010089f 100644 --- a/tools/transforms/PNStackLayout.cpp +++ b/tools/transforms/PNStackLayout.cpp @@ -83,10 +83,15 @@ unsigned int PNStackLayout::GetRandomPadding(unsigned int obj_size) //align the original stack frame if not aligned, adding more bytes if necessary //TODO: should this be scaled down if the func is recursive? - //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. - pad += (ALIGNMENT_BYTE_SIZE - (stack_layout.frame_alloc_size % ALIGNMENT_BYTE_SIZE)); - pad += stack_layout.frame_alloc_size; + + + if(pn_options->getShouldDoubleFrameSize()) + { + //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. + pad += (ALIGNMENT_BYTE_SIZE - (stack_layout.frame_alloc_size % ALIGNMENT_BYTE_SIZE)); + pad += stack_layout.frame_alloc_size; + } return pad; } diff --git a/tools/transforms/globals.h b/tools/transforms/globals.h index 122ef2f244677ee97048fd9453019bd737a6c716..ff5c455425baec44d409112b2485818f304b6bfe 100644 --- a/tools/transforms/globals.h +++ b/tools/transforms/globals.h @@ -23,26 +23,31 @@ extern bool verbose_log; -class PNOptions { +class PNOptions +{ public: // default configuration parameters go here PNOptions() { + // specify defaults; min_stack_padding = 64; max_stack_padding = 64; recursive_min_stack_padding = 32; recursive_max_stack_padding = 64; do_canaries = true; + should_double_frame_size=true; } void setMinStackPadding(int val) { min_stack_padding = val; } void setMaxStackPadding(int val) { max_stack_padding = val; } void setRecursiveMinStackPadding(int val) { recursive_min_stack_padding = val; } void setRecursiveMaxStackPadding(int val) { recursive_max_stack_padding = val; } + void setShouldDoubleFrameSize(bool val) { should_double_frame_size = 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; } void setDoCanaries(bool canaries) { do_canaries = canaries; } bool getDoCanaries() const { return do_canaries; } @@ -53,6 +58,7 @@ class PNOptions { int recursive_min_stack_padding; int recursive_max_stack_padding; bool do_canaries; + bool should_double_frame_size; }; extern PNOptions *pn_options;