1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Clang Control Flow Integrity (CFI) support.
5 * Copyright (C) 2021 Google LLC
10 #ifdef CONFIG_CFI_CLANG
11 typedef void (*cfi_check_fn)(uint64_t id, void *ptr, void *diag);
13 /* Compiler-generated function in each module, and the kernel */
14 extern void __cfi_check(uint64_t id, void *ptr, void *diag);
17 * Force the compiler to generate a CFI jump table entry for a function
18 * and store the jump table address to __cfi_jt_<function>.
20 #define __CFI_ADDRESSABLE(fn, __attr) \
21 const void *__cfi_jt_ ## fn __visible __attr = (void *)&fn
23 #ifdef CONFIG_CFI_CLANG_SHADOW
25 extern void cfi_module_add(struct module *mod, unsigned long base_addr);
26 extern void cfi_module_remove(struct module *mod, unsigned long base_addr);
30 static inline void cfi_module_add(struct module *mod, unsigned long base_addr) {}
31 static inline void cfi_module_remove(struct module *mod, unsigned long base_addr) {}
33 #endif /* CONFIG_CFI_CLANG_SHADOW */
35 #else /* !CONFIG_CFI_CLANG */
37 #define __CFI_ADDRESSABLE(fn, __attr)
39 #endif /* CONFIG_CFI_CLANG */
41 #endif /* _LINUX_CFI_H */