11d171f95SJens Wiklander /* 21d171f95SJens Wiklander * Copyright (c) 2016, Linaro Limited 31d171f95SJens Wiklander * All rights reserved. 41d171f95SJens Wiklander * 51d171f95SJens Wiklander * Redistribution and use in source and binary forms, with or without 61d171f95SJens Wiklander * modification, are permitted provided that the following conditions are met: 71d171f95SJens Wiklander * 81d171f95SJens Wiklander * 1. Redistributions of source code must retain the above copyright notice, 91d171f95SJens Wiklander * this list of conditions and the following disclaimer. 101d171f95SJens Wiklander * 111d171f95SJens Wiklander * 2. Redistributions in binary form must reproduce the above copyright notice, 121d171f95SJens Wiklander * this list of conditions and the following disclaimer in the documentation 131d171f95SJens Wiklander * and/or other materials provided with the distribution. 141d171f95SJens Wiklander * 151d171f95SJens Wiklander * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 161d171f95SJens Wiklander * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 171d171f95SJens Wiklander * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 181d171f95SJens Wiklander * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 191d171f95SJens Wiklander * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 201d171f95SJens Wiklander * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 211d171f95SJens Wiklander * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 221d171f95SJens Wiklander * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 231d171f95SJens Wiklander * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 241d171f95SJens Wiklander * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 251d171f95SJens Wiklander * POSSIBILITY OF SUCH DAMAGE. 261d171f95SJens Wiklander */ 271d171f95SJens Wiklander #ifndef __KERNEL_ASAN_H 281d171f95SJens Wiklander #define __KERNEL_ASAN_H 291d171f95SJens Wiklander 301d171f95SJens Wiklander 311d171f95SJens Wiklander #define ASAN_DATA_RED_ZONE -1 321d171f95SJens Wiklander #define ASAN_HEAP_RED_ZONE -2 331d171f95SJens Wiklander 341d171f95SJens Wiklander #define ASAN_BLOCK_SIZE 8 351d171f95SJens Wiklander #define ASAN_BLOCK_SHIFT 3 361d171f95SJens Wiklander #define ASAN_BLOCK_MASK (ASAN_BLOCK_SIZE - 1) 371d171f95SJens Wiklander 381d171f95SJens Wiklander #ifndef ASM 39abccd909SJens Wiklander #include <string.h> 401d171f95SJens Wiklander #include <types_ext.h> 411d171f95SJens Wiklander 42bce4951cSJens Wiklander void asan_set_shadowed(const void *va_begin, const void *va_end); 431d171f95SJens Wiklander void asan_start(void); 441d171f95SJens Wiklander 451d171f95SJens Wiklander #ifdef CFG_CORE_SANITIZE_KADDRESS 46bce4951cSJens Wiklander void asan_tag_no_access(const void *begin, const void *end); 47bce4951cSJens Wiklander void asan_tag_access(const void *begin, const void *end); 48bce4951cSJens Wiklander void asan_tag_heap_free(const void *begin, const void *end); 49abccd909SJens Wiklander void *asan_memset_unchecked(void *s, int c, size_t n); 50*06fe4216SJens Wiklander void *asan_memcpy_unchecked(void *__restrict s1, const void *__restrict s2, 51*06fe4216SJens Wiklander size_t n); 521d171f95SJens Wiklander #else 53bce4951cSJens Wiklander static inline void asan_tag_no_access(const void *begin __unused, 54bce4951cSJens Wiklander const void *end __unused) 551d171f95SJens Wiklander { 561d171f95SJens Wiklander } 57bce4951cSJens Wiklander static inline void asan_tag_access(const void *begin __unused, 58bce4951cSJens Wiklander const void *end __unused) 591d171f95SJens Wiklander { 601d171f95SJens Wiklander } 61bce4951cSJens Wiklander static inline void asan_tag_heap_free(const void *begin __unused, 62bce4951cSJens Wiklander const void *end __unused) 631d171f95SJens Wiklander { 641d171f95SJens Wiklander } 65abccd909SJens Wiklander 66abccd909SJens Wiklander static inline void *asan_memset_unchecked(void *s, int c, size_t n) 67abccd909SJens Wiklander { 68abccd909SJens Wiklander return memset(s, c, n); 69abccd909SJens Wiklander } 70abccd909SJens Wiklander 71*06fe4216SJens Wiklander static inline void *asan_memcpy_unchecked(void *__restrict s1, 72*06fe4216SJens Wiklander const void *__restrict s2, size_t n) 73*06fe4216SJens Wiklander { 74*06fe4216SJens Wiklander return memcpy(s1, s2, n); 75*06fe4216SJens Wiklander } 76*06fe4216SJens Wiklander 771d171f95SJens Wiklander #endif 781d171f95SJens Wiklander 791d171f95SJens Wiklander #endif /*ASM*/ 801d171f95SJens Wiklander #endif /*__KERNEL_ASAN_H*/ 81