Skip to content

Commit

Permalink
added call offset to method prologue/epilogue
Browse files Browse the repository at this point in the history
  • Loading branch information
QDucasse committed Feb 13, 2024
1 parent e3e4bc7 commit ae83c7a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
1 change: 0 additions & 1 deletion gigue/fixer/fixer_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def __init__(

# Prologue/Epilogue offsets
self.call_size += 3
print(self.call_size)
self.method_epilogue_offset += 3

def build_interpreter_prologue(
Expand Down
4 changes: 4 additions & 0 deletions gigue/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def __init__(
# Prologue/Epilogue offsets
self.method_prologue_offset = 1 # Stack sizing
self.method_epilogue_offset = 2 # Stack sizing + ret
# TODO: Rename and dissociate prologue epilogue
self.method_call_offset = 1 # ra load/store

# Generation
self.weights: List[int] = weights
Expand Down Expand Up @@ -229,6 +231,7 @@ def generate_method(self, address: int, *args, **kwargs) -> Method:
builder=self.builder,
prologue_offset=self.method_prologue_offset,
epilogue_offset=self.method_epilogue_offset,
call_offset=self.method_call_offset,
)
logger.debug(
f"{self.log_jit_prefix()} {method.log_prefix()} Method added with size"
Expand Down Expand Up @@ -265,6 +268,7 @@ def generate_leaf_method(self, address: int) -> Method:
builder=self.builder,
prologue_offset=self.method_prologue_offset,
epilogue_offset=self.method_epilogue_offset,
call_offset=self.method_call_offset,
)
logger.debug(
f"{self.log_jit_prefix()} {method.log_prefix()} Leaf method added with"
Expand Down
5 changes: 3 additions & 2 deletions gigue/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(
local_vars_nb: int = 2,
prologue_offset: int = 1,
epilogue_offset: int = 2,
call_offset: int = 1,
):
self.address: int = address
self.body_size: int = body_size
Expand All @@ -49,11 +50,11 @@ def __init__(
self.is_leaf: bool = self.call_number == 0
self.prologue_size: int = (
# stack space + register saving + ra saving
prologue_offset + self.used_s_regs + (1 if not self.is_leaf else 0)
prologue_offset + self.used_s_regs + (call_offset if not self.is_leaf else 0)
)
self.epilogue_size: int = (
# register restoring + ra restoring + stack space + ret
self.used_s_regs + (1 if not self.is_leaf else 0) + epilogue_offset
self.used_s_regs + (call_offset if not self.is_leaf else 0) + epilogue_offset
)

self.builder: InstructionBuilder = builder
Expand Down
3 changes: 3 additions & 0 deletions gigue/rimi/rimi_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def __init__(

self.shadow_stack_size = shadow_stack_size

# Prologue/Epilogue offsets
self.method_call_offset += 1

def build_interpreter_prologue(
self, used_s_regs: int, local_var_nb: int, contains_call: bool
):
Expand Down
19 changes: 10 additions & 9 deletions tests/rimi/test_rimi_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
from tests.conftest import (
INTERPRETER_START_ADDRESS,
JIT_START_ADDRESS,
RET_ADDRESS,
TEST_DATA_REG,
TEST_DATA_SIZE,
cap_disasm_bytes,
check_size,
)
from tests.rimi.conftest import TEST_RIMI_SSP_REG
from tests.rimi.conftest import TEST_RIMI_SSP_REG, start_resumable_emulation

logger = logging.getLogger("gigue")

Expand Down Expand Up @@ -42,6 +43,7 @@ def test_execute_shadow_stack_trampoline_generated_binaries(
cap_disasm_custom_setup,
rimi_handler_setup,
rimi_uc_emul_full_setup,
log_trace,
):
generator = RIMIShadowStackTrampolineGenerator(
jit_start_address=JIT_START_ADDRESS,
Expand Down Expand Up @@ -90,12 +92,12 @@ def test_execute_shadow_stack_trampoline_generated_binaries(
# Handler
rimi_handler = rimi_handler_setup
rimi_handler.hook_instr_tracer(uc_emul)
rimi_handler.hook_reg_tracer(uc_emul)
rimi_handler.hook_handler(uc_emul)

# TODO: Something fishy!
# start_address = INTERPRETER_START_ADDRESS
# end_address = RET_ADDRESS
# start_resumable_emulation(uc_emul, start_address, end_address)
start_address = INTERPRETER_START_ADDRESS
end_address = RET_ADDRESS
start_resumable_emulation(uc_emul, start_address, end_address)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -173,7 +175,6 @@ def test_execute_full_trampoline_generated_binaries(
rimi_handler.hook_exception_tracer(uc_emul)
rimi_handler.hook_handler(uc_emul)

# TODO: Something fishy!
# start_address = INTERPRETER_START_ADDRESS
# end_address = RET_ADDRESS
# start_resumable_emulation(uc_emul, start_address, end_address)
start_address = INTERPRETER_START_ADDRESS
end_address = RET_ADDRESS
start_resumable_emulation(uc_emul, start_address, end_address)

0 comments on commit ae83c7a

Please sign in to comment.