1212527Simp/* $NetBSD: msan.h,v 1.2 2020/09/09 16:29:59 maxv Exp $ */ 2212527Simp 3212527Simp/* 4212527Simp * 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 KMSAN 35#include <sys/_bus_dma.h> 36#include <sys/types.h> 37 38#define KMSAN_STATE_UNINIT 0xFF 39#define KMSAN_STATE_INITED 0x00 40 41#define KMSAN_TYPE_STACK 0 42#define KMSAN_TYPE_KMEM 1 43#define KMSAN_TYPE_MALLOC 2 44#define KMSAN_TYPE_UMA 3 45#define KMSAN_TYPE_MAX 3 46 47#define KMSAN_RET_ADDR (uintptr_t)__builtin_return_address(0) 48 49union ccb; 50struct bio; 51struct mbuf; 52struct memdesc; 53struct uio; 54 55void kmsan_init(void); 56 57void kmsan_shadow_map(vm_offset_t, size_t); 58 59void kmsan_thread_alloc(struct thread *); 60void kmsan_thread_free(struct thread *); 61 62void kmsan_bus_dmamap_sync(struct memdesc *, bus_dmasync_op_t); 63 64void kmsan_orig(const void *, size_t, int, uintptr_t); 65void kmsan_mark(const void *, size_t, uint8_t); 66void kmsan_mark_bio(const struct bio *, uint8_t); 67void kmsan_mark_mbuf(const struct mbuf *, uint8_t); 68 69void kmsan_check(const void *, size_t, const char *); 70void kmsan_check_bio(const struct bio *, const char *); 71void kmsan_check_ccb(const union ccb *, const char *); 72void kmsan_check_mbuf(const struct mbuf *, const char *); 73void kmsan_check_uio(const struct uio *, const char *); 74 75#else 76#define kmsan_init(u) 77#define kmsan_shadow_map(a, s) 78#define kmsan_thread_alloc(td) 79#define kmsan_thread_free(l) 80#define kmsan_dma_sync(m, a, s, o) 81#define kmsan_dma_load(m, b, s, o) 82#define kmsan_orig(p, l, c, a) 83#define kmsan_mark(p, l, c) 84#define kmsan_mark_bio(b, c) 85#define kmsan_mark_mbuf(m, c) 86#define kmsan_check(b, s, d) 87#define kmsan_check_bio(b, d) 88#define kmsan_check_ccb(c, d) 89#define kmsan_check_mbuf(m, d) 90#define kmsan_check_uio(u, d) 91#define kmsan_bus_dmamap_sync(d, op) 92#endif 93 94#endif /* !_SYS_MSAN_H_ */ 95