-
Notifications
You must be signed in to change notification settings - Fork 488
Description
Description
The UnicornResumeTest test suite hangs indefinitely when attempting to use Unicorn engine's emulate_until() function. The test times out and must be killed, indicating a deadlock or infinite loop in the Unicorn emulation layer.
Steps to Reproduce
Run any of the affected tests:
pytest tests/native/test_unicorn_concrete.py::UnicornResumeTest::test_integration_resume -xvsThe test will hang and require manual interruption (Ctrl+C or timeout).
Current Behavior
ResumeUnicornPlugin.will_run_callback()is invoked- Calls
state.cpu.emulate_until(0x402180)(MAIN address) - Emulation never completes - hangs indefinitely
- No output or progress indicators
- Test must be killed manually or times out in CI
Expected Behavior
- Emulation should complete and reach the target address
- Hooks should be triggered appropriately
- Test should complete within reasonable time (<10 seconds)
Root Cause Analysis
The hang occurs in the Unicorn emulation layer, likely due to one of:
- Missing Memory Mappings: Required memory regions not mapped for Unicorn
- Infinite Loop: Emulation stuck in a loop without reaching target
- Unsupported Instructions: Unicorn encountering instructions it can't handle
- Initialization Issues: Linux loader code not properly handled by Unicorn
Investigation Findings
Test Structure
class ResumeUnicornPlugin(Plugin):
def will_run_callback(self, ready_states):
for state in ready_states:
state.cpu.emulate_until(0x402180) # <-- Hangs hereBinary Information
- Binary: tests/native/binaries/rusticorn
- Type: ELF 64-bit LSB executable, x86-64, dynamically linked
- Target addresses:
- MAIN: 0x402180
- PRE_LOOP: 0x4022EE
- POST_LOOP: 0x402346
Debug Observations
- No output is produced during emulation
- Process appears to be in busy-wait or deadlock
- CPU usage remains high during hang
- No exceptions or errors are raised
Suggested Investigation Steps
-
Add Timeout and Logging:
- Wrap emulate_until with timeout
- Add progress callbacks to track emulation
- Log memory access patterns
-
Memory Analysis:
- Verify all required memory regions are mapped
- Check permissions on mapped regions
- Ensure stack and heap are properly initialized
-
Instruction Tracing:
- Enable Unicorn instruction tracing
- Identify last successfully executed instruction
- Check for problematic instruction patterns
-
Alternative Start Points:
- Try emulating from different addresses
- Skip problematic initialization code
- Use concrete execution for loader portions
Potential Fixes
Option 1: Timeout with Fallback
Add timeout to emulate_until and fall back to regular execution on timeout.
Option 2: Selective Emulation
Only use Unicorn for specific code regions, avoiding problematic areas.
Option 3: Fix Memory Mapping
Ensure all required memory is properly mapped before emulation.
Test Information
- Tests: All tests in
UnicornResumeTestclass - File: tests/native/test_unicorn_concrete.py
- Lines: 122-174
- Binary: tests/native/binaries/rusticorn
Impact
- Three test failures in CI
- Blocks Unicorn integration testing
- May affect performance optimization features
- Causes CI timeout issues
Environment
- Python 3.13.3
- Unicorn 2.1.3
- Linux 6.14.0-23-generic
- x86-64 architecture
Additional Context
This issue was discovered during CI failure investigation. The Unicorn API was recently updated to fix parameter passing issues (aux1 as keyword argument), but this hang issue persists. Tests have been temporarily disabled pending resolution.