fixed double free, pointers are weird with llvm because i dont know who

frees them...
colton
_xeroxz 3 years ago
parent 1bb5d7e399
commit b3bf2cd732

@ -0,0 +1,22 @@
#pragma once
#include <vmp_rtn.hpp>
#include <vmprofiler.hpp>
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Pass.h"
namespace vmp2::lifters
{
bool lift( vm::vmp_rtn_t *rtn, const vm::instrs::code_block_t &vm_code_block, const vm::instrs::virt_instr_t &vinstr,
llvm::IRBuilder<> *ir_builder );
}

@ -23,6 +23,7 @@ namespace vm
explicit vmp_rtn_t( llvm::LLVMContext *llvm_ctx, llvm::Module *llvm_module, std::uintptr_t rtn_begin,
std::vector< vm::instrs::code_block_t > vmp2_code_blocks );
~vmp_rtn_t();
llvm::Function *lift( void );
private:
@ -30,9 +31,10 @@ namespace vm
llvm::Module *llvm_module;
std::uintptr_t rtn_begin;
std::shared_ptr< llvm::Function > llvm_fptr;
llvm::Function* llvm_fptr;
std::shared_ptr< llvm::IRBuilder<> > ir_builder;
std::vector< std::shared_ptr< llvm::BasicBlock > > llvm_code_blocks;
llvm::AllocaInst *virutal_registers;
std::vector< llvm::BasicBlock * > llvm_code_blocks;
std::vector< vm::instrs::code_block_t > vmp2_code_blocks;
};
} // namespace vm

@ -4,20 +4,6 @@
#include <vmprofiler.hpp>
#include <xtils.hpp>
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
int main( int argc, const char *argv[] )

@ -1,3 +1,4 @@
#include <vm_lifters.hpp>
#include <vmp_rtn.hpp>
namespace vm
@ -13,12 +14,31 @@ namespace vm
// convert the rtn_begin address to a hex string and prepend "rtn_" to it...
std::stringstream rtn_name;
rtn_name << "rtn_" << std::hex << rtn_begin;
const llvm::Twine rtn_twine( rtn_name.str() );
llvm_fptr = std::shared_ptr< llvm::Function >( llvm::Function::Create(
func_ty, llvm::GlobalValue::LinkageTypes::ExternalLinkage, rtn_twine, *llvm_module ) );
llvm_fptr = llvm::Function::Create( func_ty, llvm::GlobalValue::LinkageTypes::ExternalLinkage,
rtn_name.str().c_str(), *llvm_module );
for ( const auto &vmp2_code_block : vmp2_code_blocks )
{
// create basic block name... block_xxxxxxxx format...
std::stringstream blk_name;
blk_name << "blk_" << std::hex << vmp2_code_block.vip_begin;
llvm_code_blocks.push_back( llvm::BasicBlock::Create( *llvm_ctx, blk_name.str().c_str(), llvm_fptr ) );
}
// set the insert point to the first code block...
ir_builder = std::make_shared< llvm::IRBuilder<> >( *llvm_ctx );
ir_builder->SetInsertPoint( llvm_code_blocks[ 0 ] );
// allocate virtual register space...
virutal_registers = ir_builder->CreateAlloca(
llvm::ArrayType::get( llvm::IntegerType::get( *llvm_ctx, 64 ), 24 ), nullptr, "vregs" );
llvm_fptr->print( llvm::outs() );
}
vmp_rtn_t::~vmp_rtn_t()
{
}
llvm::Function *vmp_rtn_t::lift( void )

Loading…
Cancel
Save