1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_KASAN_CHECKS_H
3#define _LINUX_KASAN_CHECKS_H
4
5#include <linux/types.h>
6
7/*
8 * The annotations present in this file are only relevant for the software
9 * KASAN modes that rely on compiler instrumentation, and will be optimized
10 * away for the hardware tag-based KASAN mode. Use kasan_check_byte() instead.
11 */
12
13/*
14 * __kasan_check_*: Always available when KASAN is enabled. This may be used
15 * even in compilation units that selectively disable KASAN, but must use KASAN
16 * to validate access to an address. Never use these in header files!
17 */
18#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
19bool __kasan_check_read(const volatile void *p, unsigned int size);
20bool __kasan_check_write(const volatile void *p, unsigned int size);
21#else
22static inline bool __kasan_check_read(const volatile void *p, unsigned int size)
23{
24 return true;
25}
26static inline bool __kasan_check_write(const volatile void *p, unsigned int size)
27{
28 return true;
29}
30#endif
31
32/*
33 * kasan_check_*: Only available when the particular compilation unit has KASAN
34 * instrumentation enabled. May be used in header files.
35 */
36#ifdef __SANITIZE_ADDRESS__
37#define kasan_check_read __kasan_check_read
38#define kasan_check_write __kasan_check_write
39#else
40static inline bool kasan_check_read(const volatile void *p, unsigned int size)
41{
42 return true;
43}
44static inline bool kasan_check_write(const volatile void *p, unsigned int size)
45{
46 return true;
47}
48#endif
49
50#endif
51

source code of linux/include/linux/kasan-checks.h