Skip to content

Reset CPU registers, EFLAGS, and stack memory between runs#315

Merged
williballenthin merged 1 commit into
masterfrom
fix/reset-run-context
Jul 24, 2026
Merged

Reset CPU registers, EFLAGS, and stack memory between runs#315
williballenthin merged 1 commit into
masterfrom
fix/reset-run-context

Conversation

@williballenthin

Copy link
Copy Markdown
Collaborator

Summary

  • Zero all general-purpose registers (EAX-EDI on x86, RAX-R15 on x64) and reset EFLAGS to 0x2 between runs
  • Clear stack memory contents between runs (not just the stack pointer)
  • Prevents state bleed across entry points/threads when using all_entrypoints=True

Previously, only ESP/EBP were reset between runs. The remaining CPU state (GP registers, EFLAGS, stack contents) was inherited from the prior run. This caused silent corruption (e.g., DF bleed breaking rep movs), order-dependent results, and non-reproducible reports.

Closes #304
Closes #305

Test plan

  • New test_registers_reset_between_runs (x86 + x64): hooks first instruction of each run, asserts GP registers are zeroed and DF is clear
  • New test_stack_cleared_between_runs: asserts 256 bytes below SP are zeroed at the start of each subsequent run
  • Full test suite passes (141 passed, 14 skipped; 2 pre-existing failures from missing capa-testfiles)

🤖 Generated with Claude Code

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@google-cla

google-cla Bot commented Jul 23, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@williballenthin
williballenthin force-pushed the fix/reset-run-context branch from e8b8bc0 to 2395d8a Compare July 24, 2026 10:15
@williballenthin
williballenthin merged commit f01d6b4 into master Jul 24, 2026
11 checks passed
@williballenthin
williballenthin deleted the fix/reset-run-context branch July 24, 2026 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stack contents are not cleared between runs CPU registers and EFLAGS are not reset between runs (state bleeds across entry points/threads)

1 participant