-
-
Notifications
You must be signed in to change notification settings - Fork 261
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
stalker: Fix recompile error in Stalker when processing the same real_address block with different insn multiple times. #995
base: main
Are you sure you want to change the base?
Conversation
…_address block with different insn multiple times.
7787a26
to
bf204fe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Sorry it took me so long to get to this.
gum/backend-arm64/gumstalker-arm64.c
Outdated
@@ -2586,11 +2588,12 @@ gum_exec_ctx_obtain_block_for (GumExecCtx * ctx, | |||
{ | |||
const gint trust_threshold = ctx->stalker->trust_threshold; | |||
gboolean still_up_to_date; | |||
GumExecBlock *active_block = gum_exec_block_get_active_block(block); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it's dealing with a symptom instead of the root cause -- isn't the root cause that ctx->mappings
should have been updated so it has the new block (storage_block
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it's dealing with a symptom instead of the root cause -- isn't the root cause that
ctx->mappings
should have been updated so it has the new block (storage_block
)?
Since my understanding of this project may not be very comprehensive, my previous commits made only minor modifications based on the original implementation approach — the fix works without updating ctx->mappings
while maintaining the original design.
However, after hearing your explanation, I re-evaluated the code, and you are right. If we consider a more thorough modification, we could indeed try discarding the original block
and updating ctx->mappings
with the newly recompiled new_block
, while also freeing the original block
.
By doing so, ctx->scratch_slab
and block->storage_block
can be deprecated, making the recompilation logic clearer and more concise. Additionally, the following two cases in the original gum_exec_ctx_recompile_block
implementation can be unified into a single approach (no need to use scratch
to calculate and reuse block
, generates a new block in any case):
- When the size of the recompiled
scratch_block
fits within the space of the originalblock
, the space inscratch_slab
is used as a draft to overwrite the originalblock
. - When the original
block
space is insufficient (the worst-case scenario requiring two compilations), ab
jump is written intoblock->code_start
to redirect execution tostorage_block->code_start
.
gum/backend-arm64/gumstalker-arm64.c
Outdated
@@ -3109,6 +3118,7 @@ gum_stalker_iterator_put_callout (GumStalkerIterator * self, | |||
GDestroyNotify data_destroy) | |||
{ | |||
GumExecBlock * block = self->exec_block; | |||
GumExecBlock * active_block = gum_exec_block_get_active_block(block); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also seems like a symptom and not the correct fix. It seems the code generation is happening on the wrong block. Maybe it's just another symptom of failing to update the mappings?
Problem Resolution:
gum_exec_ctx_obtain_block_for
, the instruction changes in the samereal_address
could not trigger a recompile, resulting in erroneous reuse of the first block whenblock->storage_block
branch.transform()
, the generatedjs_callback
was not destroyed, leading to an issue.Reproduction Scenario:
Test
gumstalker-arm64
has been tested, andgumstalker-arm
was fixed based on it but not tested.