Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebase of PR 1/11: @Clementguidi: dynamic: Refactor logic to perform multiple updates (dynamic runtime init) #1851

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
11 changes: 10 additions & 1 deletion arch/aarch64/mcount-insn.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@
#include <capstone/capstone.h>
#include <capstone/platform.h>

/**
* mcount_disasm_init - initialize the capstone engine once
* @disasm - mcount disassembly engine
*/
void mcount_disasm_init(struct mcount_disasm_engine *disasm)
{
if (disasm->engine)
return;

pr_dbg2("initialize disassembly engine\n");

if (cs_open(CS_ARCH_ARM64, CS_MODE_ARM, &disasm->engine) != CS_ERR_OK) {
pr_dbg("failed to init Capstone disasm engine\n");
pr_dbg("failed to init capstone disasm engine\n");
return;
}

Expand Down
19 changes: 14 additions & 5 deletions arch/x86_64/mcount-insn.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ struct disasm_check_data {
uint32_t size;
};

/**
* mcount_disasm_init - initialize the capstone engine once
* @disasm - mcount disassembly engine
*/
void mcount_disasm_init(struct mcount_disasm_engine *disasm)
{
if (disasm->engine)
return;

pr_dbg2("initialize disassembly engine\n");

if (cs_open(CS_ARCH_X86, CS_MODE_64, &disasm->engine) != CS_ERR_OK) {
pr_dbg("failed to init capstone disasm engine\n");
return;
Expand Down Expand Up @@ -674,7 +683,7 @@ TEST_CASE(dynamic_x86_handle_lea)
.addr = 0x3000,
.size = 32,
};
struct mcount_disasm_engine disasm;
struct mcount_disasm_engine disasm = { 0 };
struct mcount_disasm_info info = {
.sym = &sym,
.addr = ORIGINAL_BASE + sym.addr,
Expand Down Expand Up @@ -745,7 +754,7 @@ TEST_CASE(dynamic_x86_handle_call)
.addr = 0x4000,
.size = 32,
};
struct mcount_disasm_engine disasm;
struct mcount_disasm_engine disasm = { 0 };
struct mcount_disasm_info info = {
.sym = &sym1,
.addr = ORIGINAL_BASE + sym1.addr,
Expand Down Expand Up @@ -823,7 +832,7 @@ TEST_CASE(dynamic_x86_handle_jmp)
.addr = 0x3000,
.size = 32,
};
struct mcount_disasm_engine disasm;
struct mcount_disasm_engine disasm = { 0 };
struct mcount_disasm_info info = {
.sym = &sym,
.addr = ORIGINAL_BASE + sym.addr,
Expand Down Expand Up @@ -927,7 +936,7 @@ TEST_CASE(dynamic_x86_handle_jcc)
.addr = 0x3000,
.size = 32,
};
struct mcount_disasm_engine disasm;
struct mcount_disasm_engine disasm = { 0 };
struct mcount_disasm_info info = {
.sym = &sym,
.addr = ORIGINAL_BASE + sym.addr,
Expand Down Expand Up @@ -1036,7 +1045,7 @@ TEST_CASE(dynamic_x86_handle_mov_load)
.addr = 0x3000,
.size = 32,
};
struct mcount_disasm_engine disasm;
struct mcount_disasm_engine disasm = { 0 };
struct mcount_disasm_info info = {
.sym = &sym,
.addr = ORIGINAL_BASE + sym.addr,
Expand Down
Loading