xref: /freebsd/sys/sys/asan.h (revision 38da497a4dfcf1979c8c2b0e9f3fa0564035c147)
1*38da497aSMark Johnston /*	$NetBSD: asan.h,v 1.15 2020/09/10 14:10:46 maxv Exp $	*/
2*38da497aSMark Johnston 
3*38da497aSMark Johnston /*
4*38da497aSMark Johnston  * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
5*38da497aSMark Johnston  * All rights reserved.
6*38da497aSMark Johnston  *
7*38da497aSMark Johnston  * This code is part of the KASAN subsystem of the NetBSD kernel.
8*38da497aSMark Johnston  *
9*38da497aSMark Johnston  * Redistribution and use in source and binary forms, with or without
10*38da497aSMark Johnston  * modification, are permitted provided that the following conditions
11*38da497aSMark Johnston  * are met:
12*38da497aSMark Johnston  * 1. Redistributions of source code must retain the above copyright
13*38da497aSMark Johnston  *    notice, this list of conditions and the following disclaimer.
14*38da497aSMark Johnston  * 2. Redistributions in binary form must reproduce the above copyright
15*38da497aSMark Johnston  *    notice, this list of conditions and the following disclaimer in the
16*38da497aSMark Johnston  *    documentation and/or other materials provided with the distribution.
17*38da497aSMark Johnston  *
18*38da497aSMark Johnston  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19*38da497aSMark Johnston  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20*38da497aSMark Johnston  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21*38da497aSMark Johnston  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22*38da497aSMark Johnston  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23*38da497aSMark Johnston  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24*38da497aSMark Johnston  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25*38da497aSMark Johnston  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26*38da497aSMark Johnston  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*38da497aSMark Johnston  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*38da497aSMark Johnston  * SUCH DAMAGE.
29*38da497aSMark Johnston  *
30*38da497aSMark Johnston  * $FreeBSD$
31*38da497aSMark Johnston  */
32*38da497aSMark Johnston 
33*38da497aSMark Johnston #ifndef _SYS_ASAN_H_
34*38da497aSMark Johnston #define _SYS_ASAN_H_
35*38da497aSMark Johnston 
36*38da497aSMark Johnston #ifdef KASAN
37*38da497aSMark Johnston #include <sys/types.h>
38*38da497aSMark Johnston 
39*38da497aSMark Johnston /* ASAN constants. Part of the compiler ABI. */
40*38da497aSMark Johnston #define KASAN_SHADOW_SCALE		8
41*38da497aSMark Johnston #define KASAN_SHADOW_SCALE_SHIFT	3
42*38da497aSMark Johnston 
43*38da497aSMark Johnston /* Stack redzone values. Part of the compiler ABI. */
44*38da497aSMark Johnston #define KASAN_STACK_LEFT	0xF1
45*38da497aSMark Johnston #define KASAN_STACK_MID		0xF2
46*38da497aSMark Johnston #define KASAN_STACK_RIGHT	0xF3
47*38da497aSMark Johnston #define KASAN_USE_AFTER_RET	0xF5
48*38da497aSMark Johnston #define KASAN_USE_AFTER_SCOPE	0xF8
49*38da497aSMark Johnston 
50*38da497aSMark Johnston /* Our redzone values. */
51*38da497aSMark Johnston #define KASAN_GENERIC_REDZONE	0xFA
52*38da497aSMark Johnston #define KASAN_MALLOC_REDZONE	0xFB
53*38da497aSMark Johnston #define KASAN_KMEM_REDZONE	0xFC
54*38da497aSMark Johnston #define	KASAN_UMA_FREED		0xFD
55*38da497aSMark Johnston #define	KASAN_KSTACK_FREED	0xFE
56*38da497aSMark Johnston 
57*38da497aSMark Johnston void kasan_init(void);
58*38da497aSMark Johnston void kasan_shadow_map(void *, size_t);
59*38da497aSMark Johnston 
60*38da497aSMark Johnston void kasan_mark(const void *, size_t, size_t, uint8_t);
61*38da497aSMark Johnston #else /* KASAN */
62*38da497aSMark Johnston #define kasan_early_init(u)
63*38da497aSMark Johnston #define kasan_init()
64*38da497aSMark Johnston #define kasan_shadow_map(a, s)
65*38da497aSMark Johnston #define kasan_mark(p, s, l, c)
66*38da497aSMark Johnston #endif /* !KASAN */
67*38da497aSMark Johnston 
68*38da497aSMark Johnston #endif /* !_SYS_ASAN_H_ */
69