This commit is contained in:
Nikita Smith
2025-12-09 09:56:43 -08:00
parent c221286ab8
commit 962f0e30ae
5 changed files with 271 additions and 124 deletions
+34
View File
@@ -218,3 +218,37 @@ dmn_get_trap_inst(void)
return str8_array_fixed(inst);
}
internal DMN_ActiveTrap *
dmn_set_trap(Arena *arena, DMN_Trap *trap)
{
DMN_ActiveTrap *result = 0;
String8 trap_inst = dmn_get_trap_inst();
U8 *swap_bytes = push_array(arena, U8, trap_inst.size);
if(dmn_process_read(trap->process, r1u64(trap->vaddr, trap->vaddr + trap_inst.size), swap_bytes) == trap_inst.size)
{
if(dmn_process_write(trap->process, r1u64(trap->vaddr, trap->vaddr + trap_inst.size), trap_inst.str) == trap_inst.size)
{
result = push_array(arena, DMN_ActiveTrap, 1);
result->trap = trap;
result->swap_bytes = str8(swap_bytes, trap_inst.size);
}
else
{
Assert(0 && "failed to write trap instruction");
}
}
else
{
Assert(0 && "failed to read original byte");
}
return result;
}
internal B32
dmn_remove_trap(DMN_ActiveTrap *active_trap)
{
B32 is_removed = dmn_process_write(active_trap->trap->process, r1u64(active_trap->trap->vaddr, active_trap->trap->vaddr + active_trap->swap_bytes.size), active_trap->swap_bytes.str);
Assert(is_removed);
return is_removed;
}