Fuzzing.h (3802B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 /* Additional definitions and implementation for fuzzing code */ 8 9 #ifndef mozilla_Fuzzing_h 10 #define mozilla_Fuzzing_h 11 12 #ifdef FUZZING_SNAPSHOT 13 # include "mozilla/fuzzing/NyxWrapper.h" 14 15 # ifdef __cplusplus 16 # include "mozilla/fuzzing/Nyx.h" 17 # include "mozilla/ScopeExit.h" 18 19 # define MOZ_FUZZING_NYX_RELEASE(id) \ 20 if (mozilla::fuzzing::Nyx::instance().is_enabled(id)) { \ 21 mozilla::fuzzing::Nyx::instance().release(); \ 22 } 23 24 # define MOZ_FUZZING_NYX_GUARD(id) \ 25 auto nyxGuard = mozilla::MakeScopeExit([&] { \ 26 if (mozilla::fuzzing::Nyx::instance().is_enabled(id)) { \ 27 mozilla::fuzzing::Nyx::instance().release(); \ 28 } \ 29 }); 30 # endif 31 32 # define MOZ_FUZZING_HANDLE_CRASH_EVENT2(aType, aReason) \ 33 do { \ 34 if (nyx_handle_event) { \ 35 nyx_handle_event(aType, __FILE__, __LINE__, aReason); \ 36 } \ 37 } while (false) 38 39 # define MOZ_FUZZING_HANDLE_CRASH_EVENT4(aType, aFilename, aLine, aReason) \ 40 do { \ 41 if (nyx_handle_event) { \ 42 nyx_handle_event(aType, aFilename, aLine, aReason); \ 43 } \ 44 } while (false) 45 46 # define MOZ_FUZZING_NYX_PRINT(aMsg) \ 47 do { \ 48 if (nyx_puts) { \ 49 nyx_puts(aMsg); \ 50 } else { \ 51 fprintf(stderr, aMsg); \ 52 } \ 53 } while (false) 54 55 # define MOZ_FUZZING_NYX_PRINTF(aFormat, ...) \ 56 do { \ 57 if (nyx_puts) { \ 58 char msgbuf[2048]; \ 59 snprintf(msgbuf, sizeof(msgbuf) - 1, "" aFormat, __VA_ARGS__); \ 60 nyx_puts(msgbuf); \ 61 } else { \ 62 fprintf(stderr, aFormat, __VA_ARGS__); \ 63 } \ 64 } while (false) 65 66 # ifdef FUZZ_DEBUG 67 # define MOZ_FUZZING_NYX_DEBUG(x) MOZ_FUZZING_NYX_PRINT(x) 68 # else 69 # define MOZ_FUZZING_NYX_DEBUG(x) 70 # endif 71 # define MOZ_FUZZING_NYX_ABORT(aMsg) \ 72 do { \ 73 MOZ_FUZZING_NYX_PRINT(aMsg); \ 74 MOZ_REALLY_CRASH(__LINE__); \ 75 } while (false); 76 #else 77 # define MOZ_FUZZING_NYX_RELEASE(id) 78 # define MOZ_FUZZING_NYX_GUARD(id) 79 # define MOZ_FUZZING_NYX_PRINT(aMsg) 80 # define MOZ_FUZZING_NYX_PRINTF(aFormat, ...) 81 # define MOZ_FUZZING_NYX_DEBUG(aMsg) 82 # define MOZ_FUZZING_NYX_ABORT(aMsg) 83 # define MOZ_FUZZING_HANDLE_CRASH_EVENT2(aType, aReason) \ 84 do { \ 85 } while (false) 86 # define MOZ_FUZZING_HANDLE_CRASH_EVENT4(aType, aFilename, aLine, aReason) \ 87 do { \ 88 } while (false) 89 #endif 90 91 #endif /* mozilla_Fuzzing_h */