Documentation Index
Fetch the complete documentation index at: https://mintlify.com/AFLplusplus/AFLplusplus/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Persistent mode is the most effective way to fuzz. All professional fuzzing uses this mode.
Key Concept
| Traditional Fuzzing | Persistent Mode |
|---|---|
| Fork new process for each test | Reuse single process |
| High OS overhead | Minimal overhead |
| 1x baseline speed | 10-20x faster |
Requirements
For persistent mode to work correctly:- Target must be callable as one or more functions
- State must be resettable between iterations
- No resource leaks across iterations
- Earlier runs must not affect future runs
Quick Start (TL;DR)
Complete Example
Compile and Run
Standalone Compilation
To compile the target without AFL++ (for testing):Deferred Initialization
AFL++ normally stops execution beforemain() and clones from there. For programs with expensive initialization, you can defer the forkserver to start later.
When to Use
Deferred initialization helps when your program:- Parses large configuration files
- Performs time-consuming setup
- Does expensive initialization before reading fuzzed input
Performance Gain
Can offer 10x+ performance gain for programs with slow initialization.How to Implement
- Find the right location - must be done with extreme care to avoid breaking the binary
- Add the macro:
- Recompile:
Example
Persistent Mode
The Persistent Loop
The core of persistent mode is the__AFL_LOOP() macro:
Loop Count Parameter
The number in__AFL_LOOP(1000) controls:
- Maximum iterations before AFL++ restarts the process
- Balance between performance and stability
- 1000 is a good starting point
Going much higher than 1000 increases the risk of issues from memory leaks without significant performance benefits.
Full Template
See examples in utils/persistent_mode.Important Considerations
Inherent Path Variation
Execution paths will vary slightly depending on whether the loop is entered for the first time or repeated. This is expected behavior.Shared Memory Fuzzing
For an additional ~2x speed multiplier, receive fuzzing data via shared memory instead of stdin/files.Setup
1. After includes, initialize:__AFL_INIT() if using deferred forkserver):
__AFL_LOOP:
Complete Example with Shared Memory
Advanced: Persistent Record and Replay
For stateful targets (e.g., network stacks) that need to keep state between iterations:Environment Variables
Replay a specific record number.
Directory containing record files (default:
./).Using Record/Replay
Argument Parsing Support
For harnesses using@@ argument:
-
Enable in
config.h: -
Rebuild AFL++:
Not all systems support passing arguments to initializers. Prefer using
__AFL_FUZZ_TESTCASE_BUF/__AFL_FUZZ_TESTCASE_LEN shared memory mechanism.Drop-in Persistent Loop Replay
To use replay functionality withoutafl-cc:
Performance Comparison
| Mode | Speed | Use Case |
|---|---|---|
| Traditional | 1x | Baseline |
| + Deferred init | 2-10x | Expensive initialization |
| + Persistent mode | 10-20x | Most targets |
| + Shared memory | 20-40x | Maximum performance |
Best Practices
State Reset Checklist
State Reset Checklist
- Free all allocated memory
- Close all file descriptors
- Reset global variables
- Clear caches and buffers
- Reset parser state machines
- Disconnect network connections
- Clear error states
Testing Your Implementation
Testing Your Implementation
Debugging Low Stability
Debugging Low Stability
If stability is low:
-
Check for memory leaks:
-
Check for uninitialized memory:
- Add more thorough state reset
-
Reduce loop count:
__AFL_LOOP(100)instead of__AFL_LOOP(1000)
Examples
Complete examples available in:Compatibility
Persistent mode works with:| Compiler Wrapper | Supported |
|---|---|
| afl-clang-fast | ✅ Yes |
| afl-clang-lto | ✅ Yes |
| afl-gcc-fast | ✅ Yes |
| afl-gcc (obsolete) | ❌ No |
| afl-clang (obsolete) | ❌ No |
Next Steps
CmpLog
Add Redqueen-style mutations for even better results
LTO Mode
Combine with collision-free instrumentation
LAF-Intel
Split complex comparisons for better coverage
Environment Variables
Configure persistent mode behavior

