@@ -35,9 +35,6 @@ use libafl_bolts::{
35
35
use libafl_qemu_sys:: libafl_exit_request_timeout;
36
36
#[ cfg( emulation_mode = "usermode" ) ]
37
37
use libafl_qemu_sys:: libafl_qemu_handle_crash;
38
- #[ cfg( emulation_mode = "usermode" ) ]
39
- use libafl_qemu_sys:: siginfo_t;
40
- #[ cfg( emulation_mode = "systemmode" ) ]
41
38
use libc:: siginfo_t;
42
39
43
40
#[ cfg( emulation_mode = "usermode" ) ]
@@ -60,17 +57,26 @@ where
60
57
///
61
58
/// This should be used as a crash handler, and nothing else.
62
59
#[ cfg( emulation_mode = "usermode" ) ]
63
- unsafe fn inproc_qemu_crash_handler (
60
+ unsafe fn inproc_qemu_crash_handler < ET , S > (
64
61
signal : Signal ,
65
62
info : & mut siginfo_t ,
66
63
mut context : Option < & mut ucontext_t > ,
67
64
_data : & mut InProcessExecutorHandlerData ,
68
- ) {
65
+ ) where
66
+ ET : EmulatorModuleTuple < S > ,
67
+ S : UsesInput + Unpin ,
68
+ {
69
69
let puc = match & mut context {
70
70
Some ( v) => ptr:: from_mut :: < ucontext_t > ( * v) as * mut c_void ,
71
71
None => ptr:: null_mut ( ) ,
72
72
} ;
73
- libafl_qemu_handle_crash ( signal as i32 , ptr:: from_mut :: < siginfo_t > ( info) , puc) ;
73
+
74
+ // run modules' crash callback
75
+ if let Some ( emulator_modules) = EmulatorModules :: < ET , S > :: emulator_modules_mut ( ) {
76
+ emulator_modules. modules_mut ( ) . on_crash_all ( ) ;
77
+ }
78
+
79
+ libafl_qemu_handle_crash ( signal as i32 , info, puc) ;
74
80
}
75
81
76
82
#[ cfg( emulation_mode = "systemmode" ) ]
@@ -79,25 +85,44 @@ pub(crate) static BREAK_ON_TMOUT: AtomicBool = AtomicBool::new(false);
79
85
/// # Safety
80
86
/// Can call through the `unix_signal_handler::inproc_timeout_handler`.
81
87
/// Calling this method multiple times concurrently can lead to race conditions.
82
- #[ cfg( emulation_mode = "systemmode" ) ]
83
- pub unsafe fn inproc_qemu_timeout_handler < E , EM , OF , Z > (
88
+ pub unsafe fn inproc_qemu_timeout_handler < E , EM , ET , OF , S , Z > (
84
89
signal : Signal ,
85
90
info : & mut siginfo_t ,
86
91
context : Option < & mut ucontext_t > ,
87
92
data : & mut InProcessExecutorHandlerData ,
88
93
) where
89
94
E : HasObservers + HasInProcessHooks < E :: State > + Executor < EM , Z > ,
90
95
E :: Observers : ObserversTuple < E :: Input , E :: State > ,
96
+ E :: State : HasExecutions + HasSolutions + HasCorpus ,
91
97
EM : EventFirer < State = E :: State > + EventRestarter < State = E :: State > ,
98
+ ET : EmulatorModuleTuple < S > ,
92
99
OF : Feedback < EM , E :: Input , E :: Observers , E :: State > ,
93
- E :: State : HasExecutions + HasSolutions + HasCorpus ,
100
+ S : State + Unpin ,
94
101
Z : HasObjective < Objective = OF , State = E :: State > ,
95
102
<<E as UsesState >:: State as HasSolutions >:: Solutions : Corpus < Input = E :: Input > , //delete me
96
103
<<<E as UsesState >:: State as HasCorpus >:: Corpus as Corpus >:: Input : Clone , //delete me
97
104
{
98
- if BREAK_ON_TMOUT . load ( Ordering :: Acquire ) {
99
- libafl_exit_request_timeout ( ) ;
100
- } else {
105
+ #[ cfg( emulation_mode = "systemmode" ) ]
106
+ {
107
+ if BREAK_ON_TMOUT . load ( Ordering :: Acquire ) {
108
+ libafl_exit_request_timeout ( ) ;
109
+ } else {
110
+ libafl:: executors:: hooks:: unix:: unix_signal_handler:: inproc_timeout_handler :: <
111
+ E ,
112
+ EM ,
113
+ OF ,
114
+ Z ,
115
+ > ( signal, info, context, data) ;
116
+ }
117
+ }
118
+
119
+ #[ cfg( emulation_mode = "usermode" ) ]
120
+ {
121
+ // run modules' crash callback
122
+ if let Some ( emulator_modules) = EmulatorModules :: < ET , S > :: emulator_modules_mut ( ) {
123
+ emulator_modules. modules_mut ( ) . on_timeout_all ( ) ;
124
+ }
125
+
101
126
libafl:: executors:: hooks:: unix:: unix_signal_handler:: inproc_timeout_handler :: < E , EM , OF , Z > (
102
127
signal, info, context, data,
103
128
) ;
@@ -153,7 +178,8 @@ where
153
178
154
179
#[ cfg( emulation_mode = "usermode" ) ]
155
180
{
156
- inner. inprocess_hooks_mut ( ) . crash_handler = inproc_qemu_crash_handler as * const c_void ;
181
+ inner. inprocess_hooks_mut ( ) . crash_handler =
182
+ inproc_qemu_crash_handler :: < ET , S > as * const c_void ;
157
183
158
184
let handler = |emulator_modules : & mut EmulatorModules < ET , S > , host_sig| {
159
185
eprintln ! ( "Crashed with signal {host_sig}" ) ;
@@ -175,15 +201,14 @@ where
175
201
}
176
202
}
177
203
178
- #[ cfg( emulation_mode = "systemmode" ) ]
179
- {
180
- inner. inprocess_hooks_mut ( ) . timeout_handler = inproc_qemu_timeout_handler :: <
181
- StatefulInProcessExecutor < ' a , H , OT , S , Emulator < CM , ED , ET , S , SM > > ,
182
- EM ,
183
- OF ,
184
- Z ,
185
- > as * const c_void ;
186
- }
204
+ inner. inprocess_hooks_mut ( ) . timeout_handler = inproc_qemu_timeout_handler :: <
205
+ StatefulInProcessExecutor < ' a , H , OT , S , Emulator < CM , ED , ET , S , SM > > ,
206
+ EM ,
207
+ ET ,
208
+ OF ,
209
+ S ,
210
+ Z ,
211
+ > as * const c_void ;
187
212
188
213
Ok ( Self {
189
214
inner,
0 commit comments