1 /* $NetBSD: msan.h,v 1.2 2020/09/09 16:29:59 maxv Exp $ */ 2 3 /* 4 * Copyright (c) 2019-2020 Maxime Villard, m00nbsd.net 5 * All rights reserved. 6 * 7 * This code is part of the KMSAN subsystem of the NetBSD kernel. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 #ifndef _SYS_MSAN_H_ 32 #define _SYS_MSAN_H_ 33 34 #ifdef _KERNEL_OPT 35 #include "opt_kmsan.h" 36 #endif 37 38 #ifdef KMSAN 39 #include <sys/types.h> 40 #include <sys/bus.h> 41 42 #define KMSAN_STATE_UNINIT 0xFF 43 #define KMSAN_STATE_INITED 0x00 44 45 #define KMSAN_TYPE_STACK 0 46 #define KMSAN_TYPE_KMEM 1 47 #define KMSAN_TYPE_MALLOC 2 48 #define KMSAN_TYPE_POOL 3 49 #define KMSAN_TYPE_UVM 4 50 51 #define KMSAN_DMA_LINEAR 1 52 #define KMSAN_DMA_MBUF 2 53 #define KMSAN_DMA_UIO 3 54 #define KMSAN_DMA_RAW 4 55 56 #define __RET_ADDR (uintptr_t)__builtin_return_address(0) 57 58 void kmsan_init(void *); 59 void kmsan_shadow_map(void *, size_t); 60 61 void kmsan_lwp_alloc(struct lwp *); 62 void kmsan_lwp_free(struct lwp *); 63 64 void kmsan_dma_sync(bus_dmamap_t, bus_addr_t, bus_size_t, int); 65 void kmsan_dma_load(bus_dmamap_t, void *, bus_size_t, int); 66 67 void kmsan_orig(void *, size_t, int, uintptr_t); 68 void kmsan_mark(void *, size_t, uint8_t); 69 void kmsan_check_mbuf(void *); 70 void kmsan_check_buf(void *); 71 #else 72 #define kmsan_init(u) __nothing 73 #define kmsan_shadow_map(a, s) __nothing 74 #define kmsan_lwp_alloc(l) __nothing 75 #define kmsan_lwp_free(l) __nothing 76 #define kmsan_dma_sync(m, a, s, o) __nothing 77 #define kmsan_dma_load(m, b, s, o) __nothing 78 #define kmsan_orig(p, l, c, a) __nothing 79 #define kmsan_mark(p, l, c) __nothing 80 #define kmsan_check_mbuf(m) __nothing 81 #define kmsan_check_buf(b) __nothing 82 #endif 83 84 #endif /* !_SYS_MSAN_H_ */ 85