FFmpeg
Loading...
Searching...
No Matches
sanitizer.h
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVUTIL_SANITIZER_H
20#define AVUTIL_SANITIZER_H
21
22#include "config.h"
23
24#if defined(__has_feature)
25#if __has_feature(address_sanitizer)
26#define HAVE_ASAN 1
27#endif
28#if __has_feature(memory_sanitizer)
29#define HAVE_MSAN 1
30#endif
31#if __has_feature(undefined_behavior_sanitizer)
32#define HAVE_UBSAN 1
33#endif
34#endif
35#if defined(__SANITIZE_ADDRESS__)
36#undef HAVE_ASAN
37#define HAVE_ASAN 1
38#endif
39#ifndef HAVE_ASAN
40#define HAVE_ASAN 0
41#endif
42#ifndef HAVE_MSAN
43#define HAVE_MSAN 0
44#endif
45#ifndef HAVE_UBSAN
46#define HAVE_UBSAN 0
47#endif
48
49/* Mark allocated memory that nothing may touch until it is unpoisoned. */
50#if HAVE_ASAN
51#include <sanitizer/asan_interface.h>
52#define FF_ASAN_POISON(ptr, size) __asan_poison_memory_region(ptr, size)
53#define FF_ASAN_UNPOISON(ptr, size) __asan_unpoison_memory_region(ptr, size)
54#else
55#define FF_ASAN_POISON(ptr, size) ((void)(ptr), (void)(size))
56#define FF_ASAN_UNPOISON(ptr, size) ((void)(ptr), (void)(size))
57#endif
58
59/* Mark memory as uninitialized. */
60#if HAVE_MSAN
61#include <sanitizer/msan_interface.h>
62#define FF_MEM_UNDEFINED(ptr, size) __msan_allocated_memory(ptr, size)
63#elif CONFIG_MEMORY_POISONING && HAVE_VALGRIND_MEMCHECK_H
64#include <valgrind/memcheck.h>
65#define FF_MEM_UNDEFINED(ptr, size) VALGRIND_MAKE_MEM_UNDEFINED(ptr, size)
66#else
67#define FF_MEM_UNDEFINED(ptr, size) ((void)(ptr), (void)(size))
68#endif
69
70#endif /* AVUTIL_SANITIZER_H */