@@ -100,31 +100,6 @@ GlobalRunnerState state __attribute__((init_priority(200)));
100
100
// This avoids calls to __tls_init() in hot functions that use `tls`.
101
101
__thread ThreadLocalRunnerState tls;
102
102
103
- // Tries to write `description` to `state.failure_description_path`.
104
- static void WriteFailureDescription (const char *description) {
105
- // TODO(b/264715830): Remove I/O error logging once the bug is fixed?
106
- if (state.failure_description_path == nullptr ) return ;
107
- // Make sure that the write is atomic and only happens once.
108
- [[maybe_unused]] static int write_once = [=] {
109
- FILE *f = fopen (state.failure_description_path , " w" );
110
- if (f == nullptr ) {
111
- perror (" FAILURE: fopen()" );
112
- return 0 ;
113
- }
114
- const auto len = strlen (description);
115
- if (fwrite (description, 1 , len, f) != len) {
116
- perror (" FAILURE: fwrite()" );
117
- }
118
- if (fflush (f) != 0 ) {
119
- perror (" FAILURE: fflush()" );
120
- }
121
- if (fclose (f) != 0 ) {
122
- perror (" FAILURE: fclose()" );
123
- }
124
- return 0 ;
125
- }();
126
- }
127
-
128
103
void ThreadLocalRunnerState::TraceMemCmp (uintptr_t caller_pc, const uint8_t *s1,
129
104
const uint8_t *s2, size_t n,
130
105
bool is_equal) {
@@ -279,7 +254,7 @@ static void CheckWatchdogLimits() {
279
254
" https://github.com/google/fuzztest/tree/main/doc/flags-reference.md"
280
255
" \n " ,
281
256
resource.what , resource.limit , resource.units , resource.value );
282
- WriteFailureDescription (resource.failure );
257
+ CentipedeSetFailureDescription (resource.failure );
283
258
std::abort ();
284
259
}
285
260
}
@@ -315,7 +290,7 @@ __attribute__((noinline)) void CheckStackLimit(uintptr_t sp) {
315
290
" > %zu"
316
291
" (byte); aborting\n " ,
317
292
tls.top_frame_sp - sp, stack_limit);
318
- fuzztest::internal::WriteFailureDescription (
293
+ CentipedeSetFailureDescription (
319
294
fuzztest::internal::kExecutionFailureStackLimitExceeded .data ());
320
295
std::abort ();
321
296
}
@@ -595,9 +570,6 @@ bool RunnerCallbacks::Mutate(
595
570
return true ;
596
571
}
597
572
598
- void RunnerCallbacks::OnFailure (
599
- std::function<void (std::string_view)> /* failure_description_callback*/ ) {}
600
-
601
573
class LegacyRunnerCallbacks : public RunnerCallbacks {
602
574
public:
603
575
LegacyRunnerCallbacks (FuzzerTestOneInputCallback test_one_input_cb,
@@ -1171,10 +1143,6 @@ int RunnerMain(int argc, char **argv, RunnerCallbacks &callbacks) {
1171
1143
return EXIT_SUCCESS;
1172
1144
}
1173
1145
1174
- callbacks.OnFailure ([](std::string_view failure_description) {
1175
- WriteFailureDescription (std::string (failure_description).c_str ());
1176
- });
1177
-
1178
1146
// Inputs / outputs from shmem.
1179
1147
if (state.HasFlag (" :shmem:" )) {
1180
1148
if (!state.arg1 || !state.arg2 ) return EXIT_FAILURE;
@@ -1319,3 +1287,27 @@ extern "C" void CentipedeSetExecutionResult(const uint8_t *data, size_t size) {
1319
1287
state.execution_result_override ->num_outputs_read () == 1 ,
1320
1288
" Failed to set execution result from CentipedeSetExecutionResult" );
1321
1289
}
1290
+
1291
+ extern " C" void CentipedeSetFailureDescription (const char *description) {
1292
+ using fuzztest::internal::state;
1293
+ if (state.failure_description_path == nullptr ) return ;
1294
+ // Make sure that the write is atomic and only happens once.
1295
+ [[maybe_unused]] static int write_once = [=] {
1296
+ FILE *f = fopen (state.failure_description_path , " w" );
1297
+ if (f == nullptr ) {
1298
+ perror (" FAILURE: fopen()" );
1299
+ return 0 ;
1300
+ }
1301
+ const auto len = strlen (description);
1302
+ if (fwrite (description, 1 , len, f) != len) {
1303
+ perror (" FAILURE: fwrite()" );
1304
+ }
1305
+ if (fflush (f) != 0 ) {
1306
+ perror (" FAILURE: fflush()" );
1307
+ }
1308
+ if (fclose (f) != 0 ) {
1309
+ perror (" FAILURE: fclose()" );
1310
+ }
1311
+ return 0 ;
1312
+ }();
1313
+ }
0 commit comments