Skip to content

Commit

Permalink
need to track the delta changes in the stack height when performing t…
Browse files Browse the repository at this point in the history
…he resumes
  • Loading branch information
matthewfl committed Aug 27, 2016
1 parent 6ee2f04 commit a62fcc0
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
12 changes: 7 additions & 5 deletions make
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ C_FLAGS = (
)
CXX_FLAGS = (
'-std=c++14 '
'-fno-exceptions '
)
CXX_FLAGS_UNIT = (
'-I ./deps/catch/ '
Expand Down Expand Up @@ -54,7 +55,7 @@ def release():
C_FLAGS = C_FLAGS.replace('-O0', '-O2')
C_FLAGS = C_FLAGS.replace('-ggdb', '')
C_FLAGS += ' -DNDEBUG -DRED_RELEASE -fdata-sections -ffunction-sections -flto '
LD_FLAGS += '-flto ' #-Wl,--gc-sections -Wl,--print-gc-sections '
LD_FLAGS += '-flto -O2 ' #-Wl,--gc-sections -Wl,--print-gc-sections '
clean()
build()
Run('mkdir -p release')
Expand Down Expand Up @@ -172,12 +173,13 @@ def deps():
if not os.path.isdir('build'):
Shell('mkdir -p build')
if not os.path.isfile('deps/udis86/libudis86/.libs/libudis86.so') or not os.path.isfile('deps/udis86/libudis86/itab.h'):
Shell('cd deps/udis86 && ./autogen.sh && PYTHON=`which python2` ./configure && '
#"sed -i '/^CFLAGS\ =/ s/$/\ \-mgeneral\-regs\-only/' Makefile &&"
'make V=1', shell=True)
Shell('cd deps/udis86 && ./autogen.sh && PYTHON=`which python2` ./configure && ' +
#("sed -i '/^CFLAGS\ =/ s/$/\ \-flto/' Makefile &&" if RELEASE else '') +
'make V=1 CFLAGS=' + ('"-Wall -O2 -flto"' if RELEASE else '"-Wall -ggdb"')
, shell=True)
if not os.path.isfile('build/asmjit/libasmjit.so'):
Shell('mkdir -p build/asmjit')
asm_flags = '' # -DASMJIT_ALLOC=test123
asm_flags = '\-fno-exceptions\ ' # -DASMJIT_ALLOC=test123
cm_args = '-DASMJIT_DISABLE_COMPILER=1 -DASMJIT_CFLAGS=\'==REPLACE_ME==\' -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc'
if RELEASE:
Shell('cd build/asmjit && cmake ../../deps/asmjit {} -DASMJIT_RELEASE=1'.format(cm_args), shell=True)
Expand Down
1 change: 0 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#endif

#ifdef CONF_RELEASE_BUILD
# define
# define CONF_BUILD_TOGGLE(debug, release) release
#else
// configure the system to perform more traces to attempt to debug
Expand Down
8 changes: 7 additions & 1 deletion src/cpp_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define REDMAGIC_CPP_ALLOCATOR_H_

#include <memory>
#include <cstdlib>

extern "C" void *__real_malloc(size_t size);
extern "C" void __real_free(void *ptr);
Expand Down Expand Up @@ -32,8 +33,13 @@ namespace redmagic {

pointer allocate(size_type n, const_pointer hint = 0) {
void* p = __real_malloc(n * sizeof(T));
if (!p)
if (!p) {
#ifdef __EXCEPTIONS
throw std::bad_alloc();
#else
std::abort();
#endif
}
return static_cast<pointer>(p);
}

Expand Down
12 changes: 12 additions & 0 deletions src/jit_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ namespace redmagic {
// >
RealMallocMap<void*, branch_info> branches;

struct merge_location_info {
RealMallocSet<mem_loc_t> rips;
#ifdef CONF_MERGE_BACK_ON_RET
bool is_method_return = false;
#endif

};

#ifdef CONF_CHECK_MERGE_RIP
// std::unordered_map<
// mem_loc_t,
Expand Down Expand Up @@ -205,6 +213,10 @@ namespace redmagic {
struct tracer_merge_block_stack_s {
mem_loc_t merge_head = 0; // head of linked list for this merge point

#ifdef CONF_MERGE_BACK_ON_RET
bool method_merge = false;
#endif

tracer_merge_block_stack_s() {}
};

Expand Down
1 change: 0 additions & 1 deletion src/manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,6 @@ namespace {
}

bool Manager::should_trace_method(void *id) {

if(no_trace_methods.find(id) != no_trace_methods.end())
return false;

Expand Down
5 changes: 3 additions & 2 deletions src/simple_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,9 @@ void SimpleCompiler::ResumeBlockJump(mem_loc_t resume_pc) {
// this will allow for it to easily write in a direct jump, as being designed now, we will have to redirect the jump through this indirection
// so first conditional jump followed by direct jump
// also, this will not work with concurrent threads
lea(x86::r9, x86::ptr(label));
mov(x86::r8, imm_u(0xfbfbfbfbfbfbfbfb));
lea(x86::r9, x86::ptr(label)); // patch address
mov(x86::r8, imm_u(0xfbfbfbfbfbfbfbfb)); // merge point


jmp(imm_ptr(&red_asm_restart_trace));

Expand Down
4 changes: 3 additions & 1 deletion src/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,9 @@ void Tracer::TempEnableTrace(void *resume_pc) {
set_pc((mem_loc_t)resume_pc);
SimpleCompiler compiler(buffer);
// the "normal" return address will be set to ris when this returns from the temp disabled region
compiler.TestRegister((mem_loc_t)&red_asm_jump_rsi, RSI, (register_t)resume_pc, &merge_block_stack.back());
auto wb = compiler.TestRegister((mem_loc_t)&red_asm_jump_rsi, RSI, (register_t)resume_pc, &merge_block_stack.back());
auto written = compiler.finalize();
wb.replace_stump<uint64_t>(0xfafafafafafafafa, written.getRawBuffer());
write_interrupt_block();
}

Expand Down Expand Up @@ -1766,6 +1767,7 @@ void Tracer::evaluate_instruction() {
#ifdef CONF_MERGE_BACK_ON_RET
merge_block_stack.push_back(tracer_merge_block_stack_s());
method_stack.back().corresponding_merge_block = merge_block_stack.size();
merge_block_stack.back().method_merge = true;
#endif
}

Expand Down

0 comments on commit a62fcc0

Please sign in to comment.