xref: /freebsd/sys/sys/asan.h (revision 20e3b9d8bd778445bb80b2be28d2fdedf7bae37e)
138da497aSMark Johnston /*	$NetBSD: asan.h,v 1.15 2020/09/10 14:10:46 maxv Exp $	*/
238da497aSMark Johnston 
338da497aSMark Johnston /*
438da497aSMark Johnston  * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
538da497aSMark Johnston  * All rights reserved.
638da497aSMark Johnston  *
738da497aSMark Johnston  * This code is part of the KASAN subsystem of the NetBSD kernel.
838da497aSMark Johnston  *
938da497aSMark Johnston  * Redistribution and use in source and binary forms, with or without
1038da497aSMark Johnston  * modification, are permitted provided that the following conditions
1138da497aSMark Johnston  * are met:
1238da497aSMark Johnston  * 1. Redistributions of source code must retain the above copyright
1338da497aSMark Johnston  *    notice, this list of conditions and the following disclaimer.
1438da497aSMark Johnston  * 2. Redistributions in binary form must reproduce the above copyright
1538da497aSMark Johnston  *    notice, this list of conditions and the following disclaimer in the
1638da497aSMark Johnston  *    documentation and/or other materials provided with the distribution.
1738da497aSMark Johnston  *
1838da497aSMark Johnston  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1938da497aSMark Johnston  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2038da497aSMark Johnston  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2138da497aSMark Johnston  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2238da497aSMark Johnston  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2338da497aSMark Johnston  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2438da497aSMark Johnston  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2538da497aSMark Johnston  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2638da497aSMark Johnston  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2738da497aSMark Johnston  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2838da497aSMark Johnston  * SUCH DAMAGE.
2938da497aSMark Johnston  *
3038da497aSMark Johnston  * $FreeBSD$
3138da497aSMark Johnston  */
3238da497aSMark Johnston 
3338da497aSMark Johnston #ifndef _SYS_ASAN_H_
3438da497aSMark Johnston #define _SYS_ASAN_H_
3538da497aSMark Johnston 
3638da497aSMark Johnston #ifdef KASAN
3738da497aSMark Johnston #include <sys/types.h>
3838da497aSMark Johnston 
3938da497aSMark Johnston /* ASAN constants. Part of the compiler ABI. */
4038da497aSMark Johnston #define KASAN_SHADOW_SCALE		8
4138da497aSMark Johnston #define KASAN_SHADOW_SCALE_SHIFT	3
4238da497aSMark Johnston 
4338da497aSMark Johnston /* Stack redzone values. Part of the compiler ABI. */
4438da497aSMark Johnston #define KASAN_STACK_LEFT	0xF1
4538da497aSMark Johnston #define KASAN_STACK_MID		0xF2
4638da497aSMark Johnston #define KASAN_STACK_RIGHT	0xF3
4738da497aSMark Johnston #define KASAN_USE_AFTER_RET	0xF5
4838da497aSMark Johnston #define KASAN_USE_AFTER_SCOPE	0xF8
4938da497aSMark Johnston 
5038da497aSMark Johnston /* Our redzone values. */
5138da497aSMark Johnston #define KASAN_GENERIC_REDZONE	0xFA
5238da497aSMark Johnston #define KASAN_MALLOC_REDZONE	0xFB
5338da497aSMark Johnston #define KASAN_KMEM_REDZONE	0xFC
5438da497aSMark Johnston #define	KASAN_UMA_FREED		0xFD
5538da497aSMark Johnston #define	KASAN_KSTACK_FREED	0xFE
56f1c3adefSMark Johnston #define	KASAN_EXEC_ARGS_FREED	0xFF
5738da497aSMark Johnston 
5838da497aSMark Johnston void kasan_init(void);
59*20e3b9d8SMark Johnston void kasan_shadow_map(vm_offset_t, size_t);
6038da497aSMark Johnston 
6138da497aSMark Johnston void kasan_mark(const void *, size_t, size_t, uint8_t);
6238da497aSMark Johnston #else /* KASAN */
6338da497aSMark Johnston #define kasan_early_init(u)
6438da497aSMark Johnston #define kasan_init()
6538da497aSMark Johnston #define kasan_shadow_map(a, s)
6638da497aSMark Johnston #define kasan_mark(p, s, l, c)
6738da497aSMark Johnston #endif /* !KASAN */
6838da497aSMark Johnston 
6938da497aSMark Johnston #endif /* !_SYS_ASAN_H_ */
70