10b24beccSAndrey Ryabinin #ifndef _LINUX_KASAN_H 20b24beccSAndrey Ryabinin #define _LINUX_KASAN_H 30b24beccSAndrey Ryabinin 40b24beccSAndrey Ryabinin #include <linux/types.h> 50b24beccSAndrey Ryabinin 60b24beccSAndrey Ryabinin struct kmem_cache; 70b24beccSAndrey Ryabinin struct page; 80b24beccSAndrey Ryabinin 90b24beccSAndrey Ryabinin #ifdef CONFIG_KASAN 100b24beccSAndrey Ryabinin 110b24beccSAndrey Ryabinin #define KASAN_SHADOW_SCALE_SHIFT 3 120b24beccSAndrey Ryabinin #define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL) 130b24beccSAndrey Ryabinin 140b24beccSAndrey Ryabinin #include <asm/kasan.h> 150b24beccSAndrey Ryabinin #include <linux/sched.h> 160b24beccSAndrey Ryabinin 170b24beccSAndrey Ryabinin static inline void *kasan_mem_to_shadow(const void *addr) 180b24beccSAndrey Ryabinin { 190b24beccSAndrey Ryabinin return (void *)((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT) 200b24beccSAndrey Ryabinin + KASAN_SHADOW_OFFSET; 210b24beccSAndrey Ryabinin } 220b24beccSAndrey Ryabinin 230b24beccSAndrey Ryabinin /* Enable reporting bugs after kasan_disable_current() */ 240b24beccSAndrey Ryabinin static inline void kasan_enable_current(void) 250b24beccSAndrey Ryabinin { 260b24beccSAndrey Ryabinin current->kasan_depth++; 270b24beccSAndrey Ryabinin } 280b24beccSAndrey Ryabinin 290b24beccSAndrey Ryabinin /* Disable reporting bugs for current task */ 300b24beccSAndrey Ryabinin static inline void kasan_disable_current(void) 310b24beccSAndrey Ryabinin { 320b24beccSAndrey Ryabinin current->kasan_depth--; 330b24beccSAndrey Ryabinin } 340b24beccSAndrey Ryabinin 350b24beccSAndrey Ryabinin void kasan_unpoison_shadow(const void *address, size_t size); 360b24beccSAndrey Ryabinin 37b8c73fc2SAndrey Ryabinin void kasan_alloc_pages(struct page *page, unsigned int order); 38b8c73fc2SAndrey Ryabinin void kasan_free_pages(struct page *page, unsigned int order); 39b8c73fc2SAndrey Ryabinin 400b24beccSAndrey Ryabinin #else /* CONFIG_KASAN */ 410b24beccSAndrey Ryabinin 420b24beccSAndrey Ryabinin static inline void kasan_unpoison_shadow(const void *address, size_t size) {} 430b24beccSAndrey Ryabinin 440b24beccSAndrey Ryabinin static inline void kasan_enable_current(void) {} 450b24beccSAndrey Ryabinin static inline void kasan_disable_current(void) {} 460b24beccSAndrey Ryabinin 47b8c73fc2SAndrey Ryabinin static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} 48b8c73fc2SAndrey Ryabinin static inline void kasan_free_pages(struct page *page, unsigned int order) {} 49b8c73fc2SAndrey Ryabinin 500b24beccSAndrey Ryabinin #endif /* CONFIG_KASAN */ 510b24beccSAndrey Ryabinin 520b24beccSAndrey Ryabinin #endif /* LINUX_KASAN_H */ 53