/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2020 The FreeBSD Foundation4*5* This software was developed by Mark Johnston under sponsorship from the6* FreeBSD Foundation.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions are10* met:11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in15* the documentation and/or other materials provided with the distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND18* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE20* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE21* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT25* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY26* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF27* SUCH DAMAGE.28*/2930#ifndef _MACHINE_ASAN_H_31#define _MACHINE_ASAN_H_3233#ifdef KASAN3435#include <vm/vm.h>36#include <vm/pmap.h>37#include <vm/vm_page.h>38#include <machine/vmparam.h>3940static inline vm_offset_t41kasan_md_addr_to_shad(vm_offset_t addr)42{43return (((addr - VM_MIN_KERNEL_ADDRESS) >> KASAN_SHADOW_SCALE_SHIFT) +44KASAN_MIN_ADDRESS);45}4647static inline bool48kasan_md_unsupported(vm_offset_t addr)49{50vm_offset_t kernmin;5152/*53* The vm_page array is mapped at the beginning of the kernel map, but54* accesses to the array are not validated for now. Handle the fact55* that KASAN must validate accesses before the vm_page array is56* initialized.57*/58kernmin = vm_page_array == NULL ? VM_MIN_KERNEL_ADDRESS :59(vm_offset_t)(vm_page_array + vm_page_array_size);60return (addr < kernmin || addr >= VM_MAX_KERNEL_ADDRESS);61}6263static inline void64kasan_md_init(void)65{66}6768static inline void69kasan_md_init_early(vm_offset_t bootstack, size_t size)70{71kasan_shadow_map(bootstack, size);72}7374#endif /* KASAN */7576#endif /* !_MACHINE_ASAN_H_ */777879