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/. */
7 /* Additional definitions and implementation for fuzzing code */
9 #ifndef mozilla_Fuzzing_h
10 #define mozilla_Fuzzing_h
12 #ifdef FUZZING_SNAPSHOT
13 # include "mozilla/fuzzing/NyxWrapper.h"
16 # include "mozilla/fuzzing/Nyx.h"
17 # include "mozilla/ScopeExit.h"
19 # define MOZ_FUZZING_NYX_RELEASE(id) \
20 if (mozilla::fuzzing::Nyx::instance().is_enabled(id)) { \
21 mozilla::fuzzing::Nyx::instance().release(); \
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(); \
32 # define MOZ_FUZZING_HANDLE_CRASH_EVENT2(aType, aReason) \
34 if (nyx_handle_event) { \
35 nyx_handle_event(aType, __FILE__, __LINE__, aReason); \
39 # define MOZ_FUZZING_HANDLE_CRASH_EVENT4(aType, aFilename, aLine, aReason) \
41 if (nyx_handle_event) { \
42 nyx_handle_event(aType, aFilename, aLine, aReason); \
46 # define MOZ_FUZZING_NYX_PRINT(aMsg) \
51 fprintf(stderr, aMsg); \
55 # define MOZ_FUZZING_NYX_PRINTF(aFormat, ...) \
59 snprintf(msgbuf, sizeof(msgbuf) - 1, "" aFormat, __VA_ARGS__); \
62 fprintf(stderr, aFormat, __VA_ARGS__); \
67 # define MOZ_FUZZING_NYX_DEBUG(x) MOZ_FUZZING_NYX_PRINT(x)
69 # define MOZ_FUZZING_NYX_DEBUG(x)
71 # define MOZ_FUZZING_NYX_ABORT(aMsg) \
73 MOZ_FUZZING_NYX_PRINT(aMsg); \
74 MOZ_REALLY_CRASH(__LINE__); \
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) \
86 # define MOZ_FUZZING_HANDLE_CRASH_EVENT4(aType, aFilename, aLine, aReason) \
91 #endif /* mozilla_Fuzzing_h */