Commit de99f6bf authored by Jason Hiser's avatar Jason Hiser 🚜

formatting updates

parent fddd1771
......@@ -12,7 +12,6 @@
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.
*/
#include <fstream>
......@@ -35,7 +34,7 @@ using namespace InitStack;
*/
InitStack_t::InitStack_t(FileIR_t *p_variantIR, const string& p_functionsFilename, int p_initValue, bool p_verbose)
:
Transform_t(p_variantIR), // initialize the Transform class so things like insertAssembly and getFileIR() can be used
Transform_t(p_variantIR), // initialize the Transform class so things like insertAssembly and getFileIR() can be used
m_initValue(p_initValue), // member variable inits, these will vary depending on your transform's objectives
m_verbose(p_verbose),
m_numTransformed(0)
......@@ -101,7 +100,7 @@ bool InitStack_t::execute()
// #ATTRIBUTE is a convention used to help find useful information in log files
cout << "#ATTRIBUTE InitStack::numTransformed=" << m_numTransformed << endl;
return m_numTransformed>0; // true means success
return m_numTransformed>0; // true means success
}
/*
......@@ -115,7 +114,7 @@ void InitStack_t::initStack(Function_t* f)
/* check that the frame size is in the area we care about */
const auto frame_size = f->getStackFrameSize();
const auto num_locs = static_cast<uint64_t> (ceil(frame_size / 4.0));
const auto num_locs = static_cast<uint64_t> (ceil(frame_size / 4.0));
// todo: remove this line
if (frame_size <= MIN_STACK_FRAME_SIZE || frame_size >= MAX_STACK_FRAME_SIZE) return;
......@@ -131,20 +130,20 @@ void InitStack_t::initStack(Function_t* f)
cout << "Function: " << f->getName() << " auto-initialize " << dec << num_locs << " stack memory locations (4 bytes at a time) with value = " << hex << m_initValue << endl;
/* determine the registers to use on x86-32 or x86-64 */
const auto sp_reg= getFileIR()->getArchitectureBitWidth()==64 ? "rsp" : "esp";
const auto scratch_reg= getFileIR()->getArchitectureBitWidth()==64 ? "r11" : "ecx";
const auto sp_reg = getFileIR()->getArchitectureBitWidth()==64 ? "rsp" : "esp";
const auto scratch_reg = getFileIR()->getArchitectureBitWidth()==64 ? "r11" : "ecx";
// assume: flags and scratch_reg are dead at function entry.
// insert these instructions at the start of the function (to initialize the stack frame before the function runs)
auto tmp=entry;
//todo: anh to comment assembly and explain -100 constant.
insertAssemblyBefore (tmp, string()+"mov ["+sp_reg+"+"+to_string(-f->getStackFrameSize()-100)+"], "+scratch_reg);
insertAssemblyBefore (tmp, string()+"mov ["+sp_reg+"+"+to_string(-f->getStackFrameSize()-100)+"], "+scratch_reg);
tmp = insertAssemblyAfter (tmp, string()+"mov "+scratch_reg+", -" + to_string(num_locs));
const auto L1 = tmp = insertAssemblyAfter (tmp, string()+"mov dword ["+sp_reg+"+"+scratch_reg+"*4-4], " + to_string(m_initValue));
tmp = insertAssemblyAfter (tmp, string()+"inc "+scratch_reg);
tmp = insertAssemblyAfter (tmp, string()+"jnz 0", L1); // jnz to L1
tmp = insertAssemblyAfter (tmp, string()+"mov "+scratch_reg+", ["+sp_reg+"+"+to_string(-f->getStackFrameSize()-100)+"] ");
tmp = insertAssemblyAfter (tmp, string()+"mov "+scratch_reg+", ["+sp_reg+"+"+to_string(-f->getStackFrameSize()-100)+"] ");
// bump stats
m_numTransformed++;
}
......@@ -99,8 +99,8 @@ bool KillDeads::execute()
// SELF_VALIDATE is used for nightly testing to make sure we are finding at least some dead registers.
// This construct is not likely necessary or useful in your own transforms.
//
assert(getenv("SELF_VALIDATE")==nullptr || killed_flags > 5);
assert(getenv("SELF_VALIDATE")==nullptr || killed_regs > 15);
assert(getenv("SELF_VALIDATE")==nullptr || killed_flags > 5);
assert(getenv("SELF_VALIDATE")==nullptr || killed_regs > 15);
//
// Output stats to log using #ATTRIBUTE convention
......
......@@ -545,19 +545,21 @@ int StackStamp_t::execute()
// calculate and output stats
const auto pct_transformed=((double)functionsTransformed/(double)((functionsTransformed+functionsNotTransformed)))*100.00;
const auto pct_not_transformed=((double)functionsNotTransformed/(double)(functionsTransformed+functionsNotTransformed))*100.00;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Instructions_added=" << dec << instructions_added << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Instructions_added=" << dec << instructions_added << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Total_number_of_functions=" << dec << functionsTransformed+functionsNotTransformed << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Functions_Transformed=" << dec << functionsTransformed << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Functions_Not_Transformed=" << dec << functionsNotTransformed << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Percent_Functions_Transformed=" << fixed << setprecision(1) << pct_transformed << "%" << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Functions_Transformed=" << dec << functionsTransformed << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Functions_Not_Transformed=" << dec << functionsNotTransformed << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Percent_Functions_Transformed=" << fixed << setprecision(1) << pct_transformed << "%" << endl;
cout << "# ATTRIBUTE ASSURANCE_Stack_Stamping::Percent_Functions_Not_Transformed=" << fixed << setprecision(1) << pct_not_transformed << "%" << endl;
// used in testing harness to verify that the stats are correct.
assert(getenv("SELF_VALIDATE")==nullptr || instructions_added > 10);
assert(getenv("SELF_VALIDATE")==nullptr || pct_transformed > 20); // can be kind of low for small files
assert(getenv("SELF_VALIDATE")==nullptr || functionsTransformed > 5);
assert(getenv("SELF_VALIDATE")==nullptr || instructions_added > 10);
assert(getenv("SELF_VALIDATE")==nullptr || pct_transformed > 20); // can be kind of low for small files
assert(getenv("SELF_VALIDATE")==nullptr || functionsTransformed > 5 );
return 1; // true means success
return 1; // true means success
}
//
......
......@@ -154,11 +154,11 @@ class StackStampDriver_t : public IRDB_SDK::TransformStep_t
void usage(const string& name)
{
cerr<<"Usage: "<<name<<endl;
cerr<<"\t--stamp-value <value> Set the stamp value that will be used. "<<endl;
cerr<<"\t-s <value> (as parsed by by strtoul) "<<endl;
cerr<<"\t--verbose Verbose mode. "<<endl;
cerr<<"\t-v "<<endl;
cerr<<"--help,--usage,-?,-h Display this message "<<endl;
cerr<<"\t--stamp-value <value> Set the stamp value that will be used. "<<endl;
cerr<<"\t-s <value> (as parsed by by strtoul) "<<endl;
cerr<<"\t--verbose Verbose mode. "<<endl;
cerr<<"\t-v "<<endl;
cerr<<"--help,--usage,-?,-h Display this message "<<endl;
}
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment